use of games.strategy.triplea.ui.UiContext in project triplea by triplea-game.
the class TripleA method startGame.
@Override
public void startGame(final IGame game, final Set<IGamePlayer> players, final boolean headless) throws InterruptedException {
this.game = game;
if (game.getData().getDelegateList().getDelegate("edit") == null) {
// An evil hack: instead of modifying the XML, force an EditDelegate by adding one here
final EditDelegate delegate = new EditDelegate();
delegate.initialize("edit", "edit");
game.getData().getDelegateList().addDelegate(delegate);
if (game instanceof ServerGame) {
((ServerGame) game).addDelegateMessenger(delegate);
}
}
final LocalPlayers localPlayers = new LocalPlayers(players);
if (headless) {
final UiContext uiContext = new HeadlessUiContext();
uiContext.setDefaultMapDir(game.getData());
uiContext.setLocalPlayers(localPlayers);
display = new HeadlessDisplay();
soundChannel = new HeadlessSoundChannel();
game.addDisplay(display);
game.addSoundChannel(soundChannel);
// technically not needed because we won't have any "local human players" in a headless game.
connectPlayers(players, null);
} else {
SwingAction.invokeAndWait(() -> {
final TripleAFrame frame = new TripleAFrame(game, localPlayers);
LookAndFeelSwingFrameListener.register(frame);
display = new TripleADisplay(frame);
game.addDisplay(display);
soundChannel = new DefaultSoundChannel(localPlayers);
game.addSoundChannel(soundChannel);
frame.setSize(700, 400);
frame.setVisible(true);
ClipPlayer.play(SoundPath.CLIP_GAME_START);
connectPlayers(players, frame);
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.toFront();
});
}
}
use of games.strategy.triplea.ui.UiContext in project triplea by triplea-game.
the class GameMenu method addPoliticsMenu.
/**
* Add a Politics Panel button to the game menu, this panel will show the
* current political landscape as a reference, no actions on this panel.
*/
private void addPoliticsMenu() {
final JMenuItem politicsMenuItem = add(SwingAction.of("Show Politics Panel", e -> {
final PoliticalStateOverview ui = new PoliticalStateOverview(gameData, uiContext, false);
final JScrollPane scroll = new JScrollPane(ui);
scroll.setBorder(BorderFactory.createEmptyBorder());
final Dimension screenResolution = Toolkit.getDefaultToolkit().getScreenSize();
// not only do we have a start bar, but we also have the message dialog to account for
final int availHeight = screenResolution.height - 120;
// just the scroll bars plus the window sides
final int availWidth = screenResolution.width - 40;
scroll.setPreferredSize(new Dimension((scroll.getPreferredSize().width > availWidth ? availWidth : scroll.getPreferredSize().width), (scroll.getPreferredSize().height > availHeight ? availHeight : scroll.getPreferredSize().height)));
JOptionPane.showMessageDialog(frame, scroll, "Politics Panel", JOptionPane.PLAIN_MESSAGE);
}));
politicsMenuItem.setMnemonic(KeyEvent.VK_P);
politicsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
Aggregations