@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageOne.title", new Object[]{informant.getName()}, locale.getCurrentLocal())); StringBuilder template = new StringBuilder(); HashMap<String, Object> parameters = new HashMap<>(); if (informant.getWareNeeded().isPresent()) { GenericPair<ICity, IWare> needed = informant.getWareNeeded().get(); template.append(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageTwo.dialog1", new Object[]{needed.getFirst().getName(), translator.getLocalDisplayName((EWare) needed.getSecond())}, locale.getCurrentLocal())); } if (informant.getWareSurplus().isPresent()) { GenericPair<ICity, IWare> surplus = informant.getWareSurplus().get(); template.append(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageTwo.dialog2", new Object[]{surplus.getFirst().getName(), translator.getLocalDisplayName((EWare) surplus.getSecond())}, locale.getCurrentLocal())); } final Optional<MapSegmentedImage> mapSectionPart = informant.getMapSectionPart(city.getPlayer()); mapSectionPart.ifPresent(mapSegmentedImage -> { List<Integer> visibleSegs = new ArrayList<>(mapSegmentedImage.getSegmentIndices()); parameters.put("visibleSegments", visibleSegs); template.append(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageTwo.dialog4", new Object[]{mapSegmentedImage.getImageName()}, locale.getCurrentLocal())); }); if (informant.getPirateLocation().isPresent()) { GenericPair<String, ICity> pirate = informant.getPirateLocation().get(); template.append(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageTwo.dialog3", new Object[]{pirate.getFirst(), pirate.getSecond().getName()}, locale.getCurrentLocal())); } DecoratedText dt = decoratedTextFactory.createDecoratedText(template.toString(), parameters); getContent().addAll(dt); }
@Override protected EventHandler<MouseEvent> createAcceptHandler() { return mouseEvent -> { try { removeDecoratedContent(); removeAcceptButton(); MapSegmentedImage imageMap = segmentFactory.getRandomTreasureNest(); String loadedText = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernTreasureMapOwnerDialog.acceptMessage", new Object[]{imageMap.getImageName()}, locale.getCurrentLocal()); HashMap<String, Object> parameters = new HashMap<>(); List<Integer> visibleSegs = new ArrayList<>(imageMap.getSegmentIndices()); parameters.put("visibleSegments", visibleSegs); final DecoratedText dt = decoratedTextFactory.createDecoratedText(loadedText, parameters); Platform.runLater(() -> getContent().add(dt)); IHumanPlayer player = city.getPlayer(); player.setSegmentedMap(imageMap); locationDetector.addSegment(imageMap); ITreasureMapOwner mapOwner = (ITreasureMapOwner) currentPerson.get(); player.getCompany().updateCash(-mapOwner.getPrice()); mapOwner.leave(); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to add treasure map owners offer", e); } }; }
@Override protected EventHandler<MouseEvent> createAcceptHandler() { return mouseEvent -> { try { removeDecoratedContent(); removeAcceptButton(); MapSegmentedImage imageMap = segmentFactory.getRandomPirateNest(); String loadedText = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernPirateHunterDialog.acceptMessage", new Object[]{imageMap.getImageName()}, locale.getCurrentLocal()); HashMap<String, Object> parameters = new HashMap<>(); List<Integer> visibleSegs = new ArrayList<>(imageMap.getSegmentIndices()); parameters.put("visibleSegments", visibleSegs); final DecoratedText dt = decoratedTextFactory.createDecoratedText(loadedText, parameters); Platform.runLater(() -> getContent().add(dt)); IPirateHunter pirateHunter = (IPirateHunter) currentPerson.get(); final IHumanPlayer player = city.getPlayer(); player.getCompany().updateCash(-pirateHunter.getPremium()); player.setSegmentedMap(imageMap); locationDetector.addSegment(imageMap); city.getPlayer().updateCrimialDrive(-1); pirateHunter.leave(); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to accept pirate hunter offer", e); } }; }