/** * 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)); } } }
/** * 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); }
/** * 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
@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(); }
/** * 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); } } } }
Platform.runLater(() -> addMenu(newMenu)); } else { ENoticeBoardType type = noticeBoardMenu.getLast().getType(); if (type == newType) {