private void disableNavigationItems() { noticeBoardMenu.getLast().disableAll(); }
private void enableNavigationItems() { noticeBoardMenu.getLast().enableAll(); }
Platform.runLater(() -> addMenu(newMenu)); } else { ENoticeBoardType type = noticeBoardMenu.getLast().getType(); if (type == newType) { if (dialog != null) { EDialogType dialogType = dialog.getDialogType(); for (NoticeBoardMenuEntry entry : updatedMenu.getMenuEntries()) { if (entry.getDialogType() != null && entry.getDialogType() == dialogType) { updatedMenu.deselctAll(); entry.setSelected(true); break;
public void setContent(Optional<NoticeBoardMenu> optMenu) { getChildren().clear(); //noinspection OptionalIsPresent if (optMenu.isPresent()) { NoticeBoardMenu menu = optMenu.get(); final Label title = menu.getTitle(); title.getStyleClass().add("scrollPaneContent-title"); getChildren().add(title); for (NoticeBoardMenuEntry menuItem : menu.getMenuEntries()) { final DecoratedText label = menuItem.getLabel(); getChildren().add(label); if (menuItem.getDisabled()) { applyStyle(label, DISABLED_LABEL_STYLE); } else if (menuItem.getSelected()) { applyStyle(label, ACTIVE_LABEL_STYLE); } else { applyStyle(label, DEFAULT_LABEL_STYLE); } menuItem.selectedProperty().addListener((observable, oldValue, newValue) -> setSelectedStyle(label, newValue)); menuItem.disabledProperty().addListener((observable, oldValue, newValue) -> setDisabledStyle(label, newValue)); } } } private void applyStyle(DecoratedText text, String styleClass) {
public NoticeBoardMenu createMenu(ENoticeBoardType type, ICityPlayerProxyJFX proxy) { NoticeBoardMenu menu = new NoticeBoardMenu(type); menu.setTitle(titleProvider.createTitle(type, proxy.getCity())); LinkedHashSet<NoticeBoardMenuEntry> entries = null; switch (type) { break; menu.setMenuEntries(entries); for (NoticeBoardMenuEntry entry : entries) { entry.setMenu(menu);
public void setLabel(DecoratedText label) { this.label = label; this.label.setLayoutX(inset); label.setOnMouseReleased(evt -> { if (!getDisabled()) { menu.deselctAll(); selected.setValue(true); if (onMouseSelect != null) { // There might be simple messages that have no handle defined. onMouseSelect.handle(evt); } } }); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof NoticeBoardMenu)) { return false; } NoticeBoardMenu that = (NoticeBoardMenu) o; if (getTitle() != null ? !getTitle().getText().equals(that.getTitle().getText()) : that.getTitle() != null) { return false; } return getType() == that.getType(); }
/** * Clean out all menu entries that are tied to a scene. * @param proxy city proxy */ private void clearNoticeBoardOfSceneTiedMenu(ViewChangeCityPlayerProxyJFX proxy) { boolean needsUpdate = false; for (Iterator<NoticeBoardMenu> iterator = noticeBoardMenu.iterator(); iterator.hasNext(); ) { NoticeBoardMenu menu = iterator.next(); if (menu.getType().isTiedToScene()) { iterator.remove(); needsUpdate = true; } } updateAfterStackClearing(proxy, needsUpdate); }
/** * Handle the day change event to update the notice board. * Actually this happens on the tick after the day change to ensure that all events * that happen on the day change are accounted for and executed. * @param event when the day has changed. */ @Subscribe public void handleDayChange(ClockTickPostDayChange event) { if (!noticeBoardMenu.isEmpty()) { ENoticeBoardType type = noticeBoardMenu.getLast().getType(); if (lastProxy != null && type == ENoticeBoardType.TAVERN) { Platform.runLater(() -> updateNoticeBoard((ViewChangeCityPlayerProxyJFX) lastProxy, type)); } } }
/** * Update the view of the notice board after the menu stack was cleared. * @param proxy city proxy * @param needsUpdate flag to indicate if an update is required */ private void updateAfterStackClearing(ViewChangeCityPlayerProxyJFX proxy, boolean needsUpdate) { if (needsUpdate) { if (noticeBoardMenu.isEmpty()) { closeNoticeBoard(); } else { ENoticeBoardType type = noticeBoardMenu.getLast().getType(); Platform.runLater(() -> updateNoticeBoard(proxy, type)); } } }
@Subscribe public void handleNoticeBoardClosePersistent(NoticeBoardPersistentClose event) { boolean needsUpdate = false; switch (event.getBoardToBeClosed()) { case MESSAGES: for (Iterator<NoticeBoardMenu> iterator = noticeBoardMenu.iterator(); iterator.hasNext(); ) { NoticeBoardMenu menu = iterator.next(); if (menu.getType() == ENoticeBoardType.MESSAGE) { iterator.remove(); needsUpdate = true; break; } } break; default: throw new IllegalArgumentException("The persistent closing for "+event.getBoardToBeClosed()+" is not implemented"); } ViewChangeCityPlayerProxyJFX proxy = (ViewChangeCityPlayerProxyJFX) event.getProxy(); updateAfterStackClearing(proxy, needsUpdate); } @Subscribe
/** * Update the notice board when a person leaves * @param event for a person leaving the tavern */ @Subscribe public void handlePersonLeaves(PersonLeavesTavernEvent event) { // last proxy might be null if the tavern dialog is not open, which is correct synchronized (noticeBoardMenu){ if (!noticeBoardMenu.isEmpty() && lastProxy.getCity().equals(event.getCity())) { ENoticeBoardType type = noticeBoardMenu.getLast().getType(); if (lastProxy != null && lastProxy instanceof ViewChangeCityPlayerProxyJFX && type == ENoticeBoardType.TAVERN) { if (mainGameView != null) { Dialog dialog = mainGameView.getDialog(); final EDialogType mappedDialogType = map(event.getPerson()); if (dialog != null && dialog.getDialogType() == mappedDialogType) { ((CloseButtonDialog)dialog).executeOnCloseButtonClicked(); } } updateNoticeBoard((ViewChangeCityPlayerProxyJFX) lastProxy, type); } } } }