private void closeDialogUnwrapped() { if (dialog != null) { dialog.close(); context.removePrototypeBean(dialog); getChildren().remove(dialog); dialog = null; dialogScope.closeScope(); } else { logger.warn("Tried to close the dialog but it was already null"); } }
/** * Execute after savegame was loaded triggered from the ClientViewState. */ public void postLoad() { List<INavigableVessel> ships = player.findShips(this.city); this.playersVessels.clear(); this.playersVessels.addAll(ships); if (!ships.isEmpty()) { this.activeShip.setValue(playersVessels.get(0)); } else { this.activeShip.setValue(null); } GameStatus gameStatus = context.getBean(GameStatus.class); gameStatus.bindToPlayer(player); ViewStatus viewStatus = context.getBean(ViewStatus.class); viewStatus.setCity(city.getName()); MiniMap miniMap = context.getBean(MiniMap.class); miniMap.initializeMapImage(player); }
@VisibleForTesting void removeFromFleet(IShip ship, IShipOwner owner) { if (owner instanceof IPlayer) { ((IPlayer) owner).getFleet().remove(ship); } if (owner instanceof ISeaPirate) { ISeaPirate pirate = (ISeaPirate) owner; IShipGroup oldGroup = pirate.getShip() instanceof IShipGroup ? (IShipGroup) pirate.getShip() : null; if (oldGroup != null) { oldGroup.removeShip(ship); if (oldGroup.getShips().size() == 1) { ((SeaPirate)pirate).setShip(oldGroup.getShips().get(0)); ((DependentAnnotationConfigApplicationContext)context).removePrototypeBean(oldGroup); } } else { piratesState.remove(pirate); ((DependentAnnotationConfigApplicationContext)context).removePrototypeBean(pirate); } } }
private void setUpSeamapImageView() { IHumanPlayer player = viewState.getPlayer(); Image mapImage = imageUtils.createMapWithCities(map, player); final Font openPatrician18 = Font.font("OpenPatrician", 18); mapImage = imageUtils.addCityNames(map, mapImage, openPatrician18); Dimension2D origDim = new Dimension2D(mapImage.getWidth(), mapImage.getHeight()); double scale = controlHeight/origDim.getHeight(); Dimension2D targetDim = new Dimension2D(origDim.getWidth()*scale, origDim.getHeight()*scale); mapImage = imageUtils.scale(mapImage, targetDim, scale); Point2D coordinates = viewState.getCurrentCityProxy().get().getCity().getCoordinates(); coordinates = new Point2D(coordinates.getX() * scale, coordinates.getY() * scale); if (seaMapView == null) { seaMapView = (SeamapImageView) context.getBean("seamapImageView", new Object[]{mapImage, controlWidth, controlHeight, coordinates, scale}); } else { seaMapView.resetImage(mapImage,controlWidth, controlHeight, scale); } imgView = seaMapView; viewState.setState(EViewState.MAP); }
@Subscribe public void handleWeeklyUpdate(PeriodicalTimeWeekEndUpdate event) { for (ICityHall cityHall : cityHalls) { updateTreasuryWeekly(cityHall); List<ICityHallNotice> newNotices = citiesInteractionService.createNotices(cityHall.getCity()); List<ICityHallNotice> noticesToBeRemoved = cityHall.getNotices(); noticesToBeRemoved.stream().forEach(notice -> { context.removePrototypeBean(notice.getContact()); context.removePrototypeBean(notice); }); noticesToBeRemoved.clear(); noticesToBeRemoved.addAll(newNotices); checkPetitions(cityHall); if (cityHall.getAldermanOffice().isPresent()) { checkTasksFinished(cityHall.getAldermanOffice().get()); checkViolations(cityHall.getAldermanOffice().get(), cityHall.getAlderman(), cityHall); } } }
/** * A non free pirate becomes free. * @param pirate non free pirate instance that is to be freed. */ public void free(INonFreeSeaPirate pirate) { ISeaPirate freePirate = createNewPirate(pirate.getName(), pirate.getShip()); ((DependentAnnotationConfigApplicationContext)context).removePrototypeBean(pirate); piratesState.replace(pirate, freePirate); }
private void handleWeeklyUpdates() { try { for (CityState cityState : citiesState.getCityEngineStates()) { productionAndConsumtionService.produceWares(cityState); ICity city = cityState.getCity(); List<ITradingOffice> offices = city.findBuilding(ITradingOffice.class, Optional.empty()); for (ITradingOffice office : offices) { IBalanceSheet discardableSheet = office.getCurrentWeek(); IBalanceSheet newWeek = interactionFactory.createBalanceSheetFromPreviousWeek((BalanceSheet) discardableSheet); office.replaceBalanceSheet(newWeek); ((DependentAnnotationConfigApplicationContext)context).removePrototypeBean(discardableSheet); } } } finally { scheduleNextWeekUpdate(); } }