/** * Requests the game to be started. This will only be successful if all players are ready to start * the game. */ public void requestLaunch() { if (freeColClient.getGame().isAllPlayersReadyToLaunch()) { gui.showStatusPanel(Messages.message("status.startingGame")); freeColClient.askServer().requestLaunch(); } else { gui.errorMessage("server.notAllReady"); } }
/** Starts the game. */ public void startGame() { ResourceMapping gameMapping = new ResourceMapping(); for (Player player : freeColClient.getGame().getPlayers()) { addPlayerResources(player.getNationID(), gameMapping); } // Unknown nation is not in getPlayers() list. addPlayerResources(Nation.UNKNOWN_NATION_ID, gameMapping); ResourceManager.addGameMapping(gameMapping); Player myPlayer = freeColClient.getMyPlayer(); if (!freeColClient.isHeadless()) { gui.closeMainPanel(); gui.closeMenus(); gui.closeStatusPanel(); gui.playSound(null); // Stop the long introduction sound gui.playSound("sound.intro." + myPlayer.getNationID()); } freeColClient.askServer().registerMessageHandler(freeColClient.getInGameInputHandler()); if (!freeColClient.isHeadless()) { freeColClient.setInGame(true); gui.setupInGameMenuBar(); } InGameController igc = freeColClient.getInGameController(); gui.setSelectedTile((Tile) myPlayer.getEntryLocation(), false); if (freeColClient.currentPlayerIsMyPlayer()) { igc.nextActiveUnit(); } gui.setUpMouseListenersForCanvas(); if (FreeColDebugger.isInDebugMode() && FreeColDebugger.getDebugRunTurns() > 0) { freeColClient.skipTurns(FreeColDebugger.getDebugRunTurns()); } else if (freeColClient.getGame().getTurn().getNumber() == 1) { ModelMessage message = new ModelMessage(ModelMessage.MessageType.TUTORIAL, "tutorial.startGame", myPlayer); String direction = myPlayer.getNation().startsOnEastCoast() ? "west" : "east"; message.add("%direction%", direction); myPlayer.addModelMessage(message); // force view of tutorial message igc.nextModelMessage(); } }
private boolean equipUnitIfPossible(UnitLabel unitLabel, AbstractGoods goods) { Unit unit = unitLabel.getUnit(); if (unit.hasAbility(Ability.CAN_BE_EQUIPPED)) { for (EquipmentType equipment : freeColClient.getGame().getSpecification().getEquipmentTypeList()) { if (unit.canBeEquippedWith(equipment) && equipment.getGoodsRequired().size() == 1) { AbstractGoods requiredGoods = equipment.getGoodsRequired().get(0); if (requiredGoods.getType().equals(goods.getType()) && requiredGoods.getAmount() <= goods.getAmount()) { int amount = Math.min( goods.getAmount() / requiredGoods.getAmount(), equipment.getMaximumCount()); freeColClient.getInGameController().equipUnit(unit, equipment, amount); unitLabel.updateIcon(); return true; } } } } return false; }
/** * Create a panel to define trade route cargos. * * @param freeColClient The <code>FreeColClient</code> for the game. * @param newRoute The <code>TradeRoute</code> to operate on. */ public TradeRouteInputPanel(FreeColClient freeColClient, TradeRoute newRoute) { super(freeColClient, new MigLayout("wrap 4, fill", "[]20[fill]rel")); final Game game = freeColClient.getGame(); final Player player = getMyPlayer(); final TradeRoute tradeRoute = newRoute.copy(game, TradeRoute.class); this.newRoute = newRoute; this.cargoHandler = new CargoHandler(); this.dragListener = new DragListener(freeColClient, this); this.dropListener = new DropListener(); this.stopListModel = new DefaultListModel<>(); for (TradeRouteStop stop : tradeRoute.getStops()) { this.stopListModel.addElement(stop); } this.stopList = new JList<>(this.stopListModel); this.stopList.setCellRenderer(new StopRenderer()); this.stopList.setFixedCellHeight(48); this.stopList.setDragEnabled(true); this.stopList.setTransferHandler(new StopListHandler()); this.stopList.addKeyListener( new KeyListener() { @Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_DELETE) { deleteCurrentlySelectedStops(); } } @Override public void keyPressed(KeyEvent e) {} // Ignore @Override public void keyReleased(KeyEvent e) {} // Ignore }); this.stopList.addListSelectionListener(this); JScrollPane tradeRouteView = new JScrollPane(stopList); JLabel nameLabel = Utility.localizedLabel("tradeRouteInputPanel.nameLabel"); this.tradeRouteName = new JTextField(tradeRoute.getName()); JLabel destinationLabel = Utility.localizedLabel("tradeRouteInputPanel.destinationLabel"); this.destinationSelector = new JComboBox<>(); this.destinationSelector.setRenderer(new DestinationCellRenderer()); StringTemplate template = StringTemplate.template("tradeRouteInputPanel.allColonies"); this.destinationSelector.addItem(Messages.message(template)); if (player.getEurope() != null) { this.destinationSelector.addItem(player.getEurope().getId()); } for (Colony colony : freeColClient.getMySortedColonies()) { this.destinationSelector.addItem(colony.getId()); } this.messagesBox = new JCheckBox(Messages.message("tradeRouteInputPanel.silence")); this.messagesBox.setSelected(tradeRoute.isSilent()); this.messagesBox.addActionListener( (ActionEvent ae) -> { tradeRoute.setSilent(messagesBox.isSelected()); }); this.addStopButton = Utility.localizedButton("tradeRouteInputPanel.addStop"); this.addStopButton.addActionListener( (ActionEvent ae) -> { addSelectedStops(); }); this.removeStopButton = Utility.localizedButton("tradeRouteInputPanel.removeStop"); this.removeStopButton.addActionListener( (ActionEvent ae) -> { deleteCurrentlySelectedStops(); }); this.goodsPanel = new GoodsPanel(); this.goodsPanel.setTransferHandler(this.cargoHandler); this.goodsPanel.setEnabled(false); this.cargoPanel = new CargoPanel(); this.cargoPanel.setTransferHandler(this.cargoHandler); JButton cancelButton = Utility.localizedButton("cancel"); cancelButton.setActionCommand(CANCEL); cancelButton.addActionListener(this); setCancelComponent(cancelButton); add(Utility.localizedHeader("tradeRouteInputPanel.editRoute", false), "span, align center"); add(tradeRouteView, "span 1 5, grow"); add(nameLabel); add(this.tradeRouteName, "span"); add(destinationLabel); add(this.destinationSelector, "span"); add(this.messagesBox); add(this.addStopButton); add(this.removeStopButton, "span"); add(this.goodsPanel, "span"); add(this.cargoPanel, "span, height 80:, growy"); add(okButton, "newline 20, span, split 2, tag ok"); add(cancelButton, "tag cancel"); // update cargo panel if stop is selected if (this.stopListModel.getSize() > 0) { this.stopList.setSelectedIndex(0); TradeRouteStop selectedStop = this.stopListModel.firstElement(); this.cargoPanel.initialize(selectedStop); } // update buttons according to selection updateButtons(); getGUI().restoreSavedSize(this, getPreferredSize()); }
/** * Sets a nation's state. * * @param nation The <code>Nation</code> to set. * @param state The <code>NationState</code> value to set. */ public void setAvailable(Nation nation, NationState state) { freeColClient.getGame().getNationOptions().getNations().put(nation, state); freeColClient.askServer().setAvailable(nation, state); }
/** * Sends the {@link MapGeneratorOptions} to the server. This method should be called after * updating that object. */ public void sendMapGeneratorOptions() { OptionGroup mapOptions = freeColClient.getGame().getMapGeneratorOptions(); freeColClient.askServer().updateMapGeneratorOption(mapOptions); }
/** * Sends the {@link GameOptions} to the server. This method should be called after updating that * object. */ public void sendGameOptions() { OptionGroup gameOptions = freeColClient.getGame().getSpecification().getOptionGroup("gameOptions"); freeColClient.askServer().updateGameOptions(gameOptions); }
/** * Gets the game. * * @return The <code>Game</code>. */ protected Game getGame() { return freeColClient.getGame(); }