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));
}
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;
}
Aggregations