use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class AiUtilsTest method testCost.
@Test
public void testCost() {
final UnitType infantry = GameDataTestUtil.infantry(gameData);
final PlayerID british = GameDataTestUtil.british(gameData);
assertEquals(3, AiUtils.getCost(infantry, british, gameData));
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class ParserTest method testPlayerProduction.
@Test
public void testPlayerProduction() {
final ProductionFrontier cf = gameData.getProductionFrontierList().getProductionFrontier("canProd");
final PlayerID can = gameData.getPlayerList().getPlayerId("chretian");
assertEquals(cf, can.getProductionFrontier());
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class PlayerChooser method createComponents.
private void createComponents() {
final Collection<PlayerID> players = new ArrayList<>(this.players.getPlayers());
if (allowNeutral) {
players.add(PlayerID.NULL_PLAYERID);
}
list = new JList<>(players.toArray(new PlayerID[0]));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedValue(defaultPlayer, true);
list.setFocusable(false);
list.setCellRenderer(new PlayerChooserRenderer(uiContext));
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent evt) {
if (evt.getClickCount() == 2) {
// set OK_OPTION on DoubleClick, this fires a property change which causes the dialog to close()
setValue(OK_OPTION);
}
}
});
setMessage(SwingComponents.newJScrollPane(list));
final int maxSize = 700;
final int suggestedSize = this.players.size() * 40;
final int actualSize = suggestedSize > maxSize ? maxSize : suggestedSize;
setPreferredSize(new Dimension(300, actualSize));
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class PlayersPanel method showPlayers.
public static void showPlayers(final IGame game, final Component parent) {
final JPanel panel = JPanelBuilder.builder().verticalBoxLayout().build();
for (final String player : game.getPlayerManager().getPlayers()) {
final PlayerID playerId = game.getData().getPlayerList().getPlayerId(player);
if (playerId.isAi()) {
panel.add(new JLabel(playerId.getWhoAmI().split(":")[1] + " is " + playerId.getName(), JLabel.RIGHT));
} else {
panel.add(new JLabel(game.getPlayerManager().getNode(player).getName() + " is " + playerId.getName(), JLabel.RIGHT));
}
}
JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(parent), panel, "Players", JOptionPane.PLAIN_MESSAGE);
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class PoliticalStateOverview method getRelationshipLabel.
/**
* Gets a label showing the coloured relationshipName between these two
* players.
*/
private JPanel getRelationshipLabel(final PlayerID player1, final PlayerID player2) {
RelationshipType relType = null;
for (final Triple<PlayerID, PlayerID, RelationshipType> changesSoFar : editChanges) {
if ((player1.equals(changesSoFar.getFirst()) && player2.equals(changesSoFar.getSecond())) || (player2.equals(changesSoFar.getFirst()) && player1.equals(changesSoFar.getSecond()))) {
relType = changesSoFar.getThird();
}
}
if (relType == null) {
data.acquireReadLock();
try {
relType = data.getRelationshipTracker().getRelationshipType(player1, player2);
} finally {
data.releaseReadLock();
}
}
final JComponent relationshipLabel = getRelationshipComponent(player1, player2, relType);
final JPanel relationshipLabelPanel = new JPanel();
relationshipLabelPanel.add(relationshipLabel);
relationshipLabelPanel.setBackground(getRelationshipTypeColor(relType));
return relationshipLabelPanel;
}
Aggregations