@Override public UIState getUIState() { return connector.getUIState(); }
/** * Shuts down used threads. */ public void stop() { constructionMarksCalculator.cancel(); connector.removeListener(this); refreshSelectionTimer.cancel(); } }
/** * Sets the selection. * * @param selection * The selected items. Not null! */ private void setSelection(SelectionSet selection) { currentSelection.setSelected(false); selection.setSelected(true); connector.setSelection(selection); currentSelection = selection; }
@Override public void run() { try { EBuildingType type = askType(); definition = new BuildingDefinition(type); map = new BuildingtestMap(definition); for (int x = 0; x < map.getWidth(); x++) { for (int y = 0; y < map.getHeight(); y++) { reloadColor(new ShortPoint2D(x, y)); } } IMapInterfaceConnector connector = startMapWindow(); connector.addListener(this); JPanel menu = generateMenu(); window = new JFrame("Edit " + type.toString()); window.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); window.add(menu); window.pack(); window.setVisible(true); connector.fireAction(new Action(EActionType.TOGGLE_DEBUG)); } catch (JSettlersLookAndFeelExecption e) { throw new RuntimeException(e); } }
public GuiInterface(IMapInterfaceConnector connector, IGameClock clock, ITaskScheduler taskScheduler, IGuiInputGrid grid, IGameStoppable gameStoppable, byte playerId, boolean multiplayer) { this.connector = connector; this.clock = clock; this.taskScheduler = taskScheduler; this.grid = grid; this.gameStoppable = gameStoppable; this.playerId = playerId; this.multiplayer = multiplayer; this.constructionMarksCalculator = new ConstructionMarksThread(grid.getConstructionMarksGrid(), clock, playerId); this.refreshSelectionTimer = new Timer("refreshSelectionTimer"); this.refreshSelectionTimer.schedule(new TimerTask() { @Override public void run() { refreshSelection(); } }, 1000, 1000); Player player = grid.getPlayer(playerId); if (player != null) { player.setMessenger(connector); } clock.setTaskExecutor(new GuiTaskExecutor(grid, this, this.playerId)); connector.addListener(this); }
GuiInterface guiInterface = new GuiInterface(connector, MatchConstants.clock(), networkConnector.getTaskScheduler(), mainGrid.getGuiInputGrid(), this, playerId, multiplayer); connector.loadUIState(playerState.getUiState()); // This is required after the GuiInterface instantiation so that connector.shutdown(); guiInterface.stop(); clearState();
private void showSelection() { int x = 0; int y = 0; int count = 0; for (final ISelectable member : currentSelection) { if (member instanceof ILocatable) { x += ((ILocatable) member).getPosition().x; y += ((ILocatable) member).getPosition().y; count++; } } System.out.println("locatable: " + count); if (count > 0) { final ShortPoint2D point = new ShortPoint2D(x / count, y / count); connector.scrollTo(point, false); } }
public void setDock(ShortPoint2D requestedDockPosition) { final ISelectable selected = currentSelection.getSingle(); if (!(selected instanceof IDockBuilding)) { return; } IDockBuilding building = (IDockBuilding) selected; if (building.canDockBePlaced(requestedDockPosition)) { taskScheduler.scheduleTask(new SetDockGuiTask(playerId, building, requestedDockPosition)); } else { connector.playSound(116, 1); // this dock position is not at the coast } }