Search in sources :

Example 6 with UiContext

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();
        });
    }
}
Also used : LocalPlayers(games.strategy.engine.framework.LocalPlayers) ITripleADisplay(games.strategy.triplea.ui.display.ITripleADisplay) TripleADisplay(games.strategy.triplea.ui.display.TripleADisplay) HeadlessDisplay(games.strategy.triplea.ui.display.HeadlessDisplay) ServerGame(games.strategy.engine.framework.ServerGame) EditDelegate(games.strategy.triplea.delegate.EditDelegate) HeadlessUiContext(games.strategy.triplea.ui.HeadlessUiContext) HeadlessSoundChannel(games.strategy.sound.HeadlessSoundChannel) TripleAFrame(games.strategy.triplea.ui.TripleAFrame) DefaultSoundChannel(games.strategy.sound.DefaultSoundChannel) UiContext(games.strategy.triplea.ui.UiContext) HeadlessUiContext(games.strategy.triplea.ui.HeadlessUiContext)

Example 7 with UiContext

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()));
}
Also used : IntTextField(games.strategy.ui.IntTextField) ClientGame(games.strategy.engine.framework.ClientGame) Insets(java.awt.Insets) JTextField(javax.swing.JTextField) Action(javax.swing.Action) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) TripleAFrame(games.strategy.triplea.ui.TripleAFrame) JMenuItem(javax.swing.JMenuItem) UiContext(games.strategy.triplea.ui.UiContext) ClientSetting(games.strategy.triplea.settings.ClientSetting) BoxLayout(javax.swing.BoxLayout) KeyStroke(javax.swing.KeyStroke) PoliticalStateOverview(games.strategy.triplea.ui.PoliticalStateOverview) RandomStatsDetails(games.strategy.engine.random.RandomStatsDetails) JMenu(javax.swing.JMenu) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) KeyEvent(java.awt.event.KeyEvent) JOptionPane(javax.swing.JOptionPane) OddsCalculatorDialog(games.strategy.triplea.oddsCalculator.ta.OddsCalculatorDialog) MenuListener(javax.swing.event.MenuListener) VerifiedRandomNumbersDialog(games.strategy.triplea.ui.VerifiedRandomNumbersDialog) JScrollPane(javax.swing.JScrollPane) IRandomStats(games.strategy.engine.random.IRandomStats) GameData(games.strategy.engine.data.GameData) Dimension(java.awt.Dimension) JLabel(javax.swing.JLabel) IGame(games.strategy.engine.framework.IGame) SoundOptions(games.strategy.sound.SoundOptions) MenuEvent(javax.swing.event.MenuEvent) GridBagLayout(java.awt.GridBagLayout) PropertiesUi(games.strategy.engine.data.properties.PropertiesUi) JPanel(javax.swing.JPanel) Toolkit(java.awt.Toolkit) SwingAction(games.strategy.ui.SwingAction) JScrollPane(javax.swing.JScrollPane) PoliticalStateOverview(games.strategy.triplea.ui.PoliticalStateOverview) Dimension(java.awt.Dimension) JMenuItem(javax.swing.JMenuItem)

Aggregations

UiContext (games.strategy.triplea.ui.UiContext)7 GameData (games.strategy.engine.data.GameData)4 List (java.util.List)4 PlayerID (games.strategy.engine.data.PlayerID)3 UnitType (games.strategy.engine.data.UnitType)3 SwingAction (games.strategy.ui.SwingAction)3 KeyEvent (java.awt.event.KeyEvent)3 Set (java.util.Set)3 JMenu (javax.swing.JMenu)3 JMenuItem (javax.swing.JMenuItem)3 JOptionPane (javax.swing.JOptionPane)3 JPanel (javax.swing.JPanel)3 ClientContext (games.strategy.engine.ClientContext)2 ProductionRule (games.strategy.engine.data.ProductionRule)2 IGame (games.strategy.engine.framework.IGame)2 SystemProperties (games.strategy.engine.framework.system.SystemProperties)2 HistoryNode (games.strategy.engine.history.HistoryNode)2 Round (games.strategy.engine.history.Round)2 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)2 TripleAFrame (games.strategy.triplea.ui.TripleAFrame)2