Search in sources :

Example 6 with UserActionAttachment

use of games.strategy.triplea.attachments.UserActionAttachment in project triplea by triplea-game.

the class UserActionPanelTest method testCanPlayerAffordUserAction_ShouldReturnTrueWhenUserActionCostLessThanPlayerPUs.

@Test
public void testCanPlayerAffordUserAction_ShouldReturnTrueWhenUserActionCostLessThanPlayerPUs() {
    givenGameHasPuResource();
    final PlayerID player = createPlayer();
    final UserActionAttachment userAction = createUserActionWithCost(player.getResources().getQuantity(pus) - 1);
    final boolean canAffordUserAction = UserActionPanel.canPlayerAffordUserAction(player, userAction);
    assertThat(canAffordUserAction, is(true));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) UserActionAttachment(games.strategy.triplea.attachments.UserActionAttachment) Test(org.junit.jupiter.api.Test)

Example 7 with UserActionAttachment

use of games.strategy.triplea.attachments.UserActionAttachment in project triplea by triplea-game.

the class UserActionPanel method getUserActionButtonPanel.

private JPanel getUserActionButtonPanel(final JDialog parent) {
    final JPanel userActionButtonPanel = new JPanel();
    userActionButtonPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    userActionButtonPanel.setLayout(new GridBagLayout());
    final int firstRow = 0;
    final int lastRow = validUserActions.size() - 1;
    int row = 0;
    for (final UserActionAttachment uaa : validUserActions) {
        final int topInset = (row == firstRow) ? 0 : 4;
        final int bottomInset = (row == lastRow) ? 0 : 4;
        final boolean canPlayerAffordUserAction = canPlayerAffordUserAction(getCurrentPlayer(), uaa);
        userActionButtonPanel.add(getOtherPlayerFlags(uaa), new GridBagConstraints(0, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(topInset, 0, bottomInset, 4), 0, 0));
        final JButton button = new JButton(getActionButtonText(uaa));
        button.addActionListener(ae -> {
            selectUserActionButton.setEnabled(false);
            doneButton.setEnabled(false);
            validUserActions = Collections.emptyList();
            choice = uaa;
            parent.setVisible(false);
            release();
        });
        button.setEnabled(canPlayerAffordUserAction);
        userActionButtonPanel.add(button, new GridBagConstraints(1, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(topInset, 4, bottomInset, 4), 0, 0));
        final JLabel descriptionLabel = getActionDescriptionLabel(uaa);
        descriptionLabel.setEnabled(canPlayerAffordUserAction);
        userActionButtonPanel.add(descriptionLabel, new GridBagConstraints(2, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(topInset, 4, bottomInset, 0), 0, 0));
        row++;
    }
    return userActionButtonPanel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) UserActionAttachment(games.strategy.triplea.attachments.UserActionAttachment)

Aggregations

UserActionAttachment (games.strategy.triplea.attachments.UserActionAttachment)7 PlayerID (games.strategy.engine.data.PlayerID)4 Test (org.junit.jupiter.api.Test)4 Attachable (games.strategy.engine.data.Attachable)1 IUserActionDelegate (games.strategy.triplea.delegate.remote.IUserActionDelegate)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1