public void Update(bool pressedDialogButton, WorldObjectEntity worldEntityCollidingWith) { switch (currentDialogShownState) { case DialogShownState.Hidden: if (worldEntityCollidingWith != null) { bool shouldSkipConsumedDialog = worldEntityCollidingWith.IsConsumable && worldEntityCollidingWith.HasBeenConsumed; bool shouldShow = false; if (!shouldSkipConsumedDialog && worldEntityCollidingWith.Enabled) { if (worldEntityCollidingWith.AutomaticDialogDisplay) { shouldShow = true; currentDialogShownState = DialogShownState.AutomaticallyShown; } else if (pressedDialogButton) { shouldShow = true; currentDialogShownState = DialogShownState.ExplicitlyShown; } if (shouldShow) { DialogBox.Visible = true; //We will set HasBeenConsumed if it is marked as consumable. worldEntityCollidingWith.HasBeenConsumed = worldEntityCollidingWith.IsConsumable; DialogBox.Text = LocalizationManager.Translate(worldEntityCollidingWith.DialogKey); worldEntityCollidingWith.TimeDialogShown = ScreenManager.CurrentScreen.PauseAdjustedCurrentTime; entityShowingDialog = worldEntityCollidingWith; } } } break; case DialogShownState.AutomaticallyShown: bool shouldClose = false; if (entityShowingDialog.AutomaticDismissTime > 0) { shouldClose = ScreenManager.CurrentScreen.PauseAdjustedSecondsSince(entityShowingDialog.TimeDialogShown) > entityShowingDialog.AutomaticDismissTime; } else if (worldEntityCollidingWith != entityShowingDialog) { // user moved out of the collision area, so hide it shouldClose = true; } if (shouldClose) { CloseDialog(); } // Do we want the user to be able to automatically close out the dialog? break; case DialogShownState.ExplicitlyShown: if (pressedDialogButton) { CloseDialog(); } break; } }
private void CloseDialog() { entityShowingDialog = null; DialogBox.Visible = false; currentDialogShownState = DialogShownState.Hidden; }