/** Called when the observers detect change, to see if the game is in a startable state */ @Override public boolean canGameStart() { if (m_gameSelectorModel.getGameData() == null) { return false; } final boolean diceServerValid = m_diceServerEditor.isBeanValid(); final boolean summaryValid = m_forumPosterEditor.isBeanValid(); final boolean webSiteValid = m_webPosterEditor.isBeanValid(); final boolean emailValid = m_emailSenderEditor.isBeanValid(); final boolean pbemReady = diceServerValid && summaryValid && emailValid && webSiteValid && m_gameSelectorModel.getGameData() != null; if (!pbemReady) { return false; } // make sure at least 1 player is enabled for (final PBEMLocalPlayerComboBoxSelector player : m_playerTypes) { if (player.isPlayerEnabled()) { return true; } } return false; }
public String getPlayerType(final String playerName) { for (final PBEMLocalPlayerComboBoxSelector item : m_playerTypes) { if (item.getPlayerName().equals(playerName)) { return item.getPlayerType(); } } throw new IllegalStateException("No player found:" + playerName); }
/** Called when the user hits play */ @Override public ILauncher getLauncher() { // update local cache and write to disk before game starts final IForumPoster poster = (IForumPoster) m_forumPosterEditor.getBean(); if (poster != null) { LocalBeanCache.INSTANCE.storeSerializable(poster.getClass().getCanonicalName(), poster); } final IEmailSender sender = (IEmailSender) m_emailSenderEditor.getBean(); if (sender != null) { LocalBeanCache.INSTANCE.storeSerializable(sender.getClass().getCanonicalName(), sender); } final IWebPoster web = (IWebPoster) m_webPosterEditor.getBean(); if (web != null) { LocalBeanCache.INSTANCE.storeSerializable(web.getClass().getCanonicalName(), web); } final IRemoteDiceServer server = (IRemoteDiceServer) m_diceServerEditor.getBean(); LocalBeanCache.INSTANCE.storeSerializable(server.getDisplayName(), server); LocalBeanCache.INSTANCE.writeToDisk(); // create local launcher final String gameUUID = (String) m_gameSelectorModel.getGameData().getProperties().get(GameData.GAME_UUID); final PBEMDiceRoller randomSource = new PBEMDiceRoller((IRemoteDiceServer) m_diceServerEditor.getBean(), gameUUID); final Map<String, String> playerTypes = new HashMap<>(); final Map<String, Boolean> playersEnabled = new HashMap<>(); for (final PBEMLocalPlayerComboBoxSelector player : m_playerTypes) { playerTypes.put(player.getPlayerName(), player.getPlayerType()); playersEnabled.put(player.getPlayerName(), player.isPlayerEnabled()); } // we don't need the playerToNode list, the // disable-able players, or the alliances // list, for a local game final PlayerListing pl = new PlayerListing( null, playersEnabled, playerTypes, m_gameSelectorModel.getGameData().getGameVersion(), m_gameSelectorModel.getGameName(), m_gameSelectorModel.getGameRound(), null, null); return new LocalLauncher(m_gameSelectorModel, randomSource, pl); }
private void layoutPlayerPanel(final SetupPanel parent) { final GameData data = m_gameSelectorModel.getGameData(); m_localPlayerPanel.removeAll(); m_playerTypes.clear(); m_localPlayerPanel.setLayout(new GridBagLayout()); if (data == null) { m_localPlayerPanel.add(new JLabel("No game selected!")); return; } final Collection<String> disableable = data.getPlayerList().getPlayersThatMayBeDisabled(); final HashMap<String, Boolean> playersEnablementListing = data.getPlayerList().getPlayersEnabledListing(); final Map<String, String> reloadSelections = PlayerID.currentPlayers(data); final String[] playerTypes = data.getGameLoader().getServerPlayerTypes(); final String[] playerNames = data.getPlayerList().getNames(); // if the xml was created correctly, this list will be in turn order. we want to keep it that // way. int gridx = 0; int gridy = 0; if (!disableable.isEmpty() || playersEnablementListing.containsValue(Boolean.FALSE)) { final JLabel enableLabel = new JLabel("Use"); enableLabel.setForeground(Color.black); m_localPlayerPanel.add( enableLabel, new GridBagConstraints( gridx++, gridy, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 0), 0, 0)); } final JLabel nameLabel = new JLabel("Name"); nameLabel.setForeground(Color.black); m_localPlayerPanel.add( nameLabel, new GridBagConstraints( gridx++, gridy, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 0), 0, 0)); final JLabel typeLabel = new JLabel("Type"); typeLabel.setForeground(Color.black); m_localPlayerPanel.add( typeLabel, new GridBagConstraints( gridx++, gridy, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 0), 0, 0)); final JLabel allianceLabel = new JLabel("Alliance"); allianceLabel.setForeground(Color.black); m_localPlayerPanel.add( allianceLabel, new GridBagConstraints( gridx++, gridy, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 7, 5, 5), 0, 0)); for (final String playerName : playerNames) { final PBEMLocalPlayerComboBoxSelector selector = new PBEMLocalPlayerComboBoxSelector( playerName, reloadSelections, disableable, playersEnablementListing, data.getAllianceTracker() .getAlliancesPlayerIsIn(data.getPlayerList().getPlayerID(playerName)), playerTypes, parent); m_playerTypes.add(selector); selector.layout(++gridy, m_localPlayerPanel); } m_localPlayerPanel.validate(); m_localPlayerPanel.invalidate(); }