/// <summary> /// Static method for creating a DialogueScreen from the gameplay screen. /// </summary> /// <param name="id">The GUID of the <see cref="NPCPrompt"/>NPCPrompt</see> in the database.</param> /// <returns>A new instance of a DialogueScreen</returns> public static DialogueScreen InitializeDialogueBox(Guid id) { DialogueScreen openingPrompt = new DialogueScreen(id); openingPrompt.Responses = openingPrompt.FindResponses(id); return(openingPrompt); }
/// <summary> /// Event handler for when a <see cref="Response"/>Response</see> is selected. /// </summary> void ResponseSelected(object sender, ResponseEventArgs e) { // close the current screen and // InitializeDialogueBox on e.NextEntry ExitScreen(); ScreenManager.AddScreen(DialogueScreen.InitializeDialogueBox(e.NextEntry), null); }
/// <summary> /// Draws this Response. This can be overridden to customize the appearance. /// </summary> public virtual void Draw(DialogueScreen screen, bool isSelected, GameTime gameTime) { // Draw the selected entry in yellow, otherwise white. Color color = isSelected ? Color.Yellow : Color.White; String displayText = isSelected ? selectedText : text; // Pulsate the size of the selected menu entry. double time = gameTime.TotalGameTime.TotalSeconds; // float pulsate = (float)Math.Sin(time * 6) + 1; float scale = 1; // +pulsate * 0.05f * selectionFade; // Modify the alpha to fade text out during transitions. color *= screen.TransitionAlpha; // Draw text, centered on the middle of each line. ScreenManager screenManager = screen.ScreenManager; SpriteBatch spriteBatch = screenManager.SpriteBatch; SpriteFont font = screenManager.Font; Vector2 origin = new Vector2(0, font.LineSpacing / 2); String wrapped = screen.WrapText(font, displayText, screenManager.GraphicsDevice.Viewport.Width - (DialogueScreen.hPad * 3)); spriteBatch.DrawString(font, displayText, position, color, 0, origin, scale, SpriteEffects.None, 0); }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(GameTime gameTime, InputState input) { if (input == null) { throw new ArgumentNullException("input"); } // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; // The game pauses either if the user presses the pause button, or if // they unplug the active gamepad. This requires us to keep track of // whether a gamepad was ever plugged in, because we don't want to pause // on PC if they are playing with a keyboard and have no gamepad at all! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else if (startAction.Evaluate(input, ControllingPlayer, out player)) { ScreenManager.AddScreen(DialogueScreen.InitializeDialogueBox(new Guid("129cfb6c-32de-11e2-8539-109adda800ea")), null); } }
/// <summary> /// Updates this Response. /// </summary> public virtual void Update(DialogueScreen screen, bool isSelected, GameTime gameTime) { // When the menu selection changes, entries gradually fade between // their selected and deselected appearance, rather than instantly // popping to the new state. float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4; if (isSelected) { selectionFade = Math.Min(selectionFade + fadeSpeed, 1); } else { selectionFade = Math.Max(selectionFade - fadeSpeed, 0); } }
/// <summary> /// Updates this Response. /// </summary> public virtual void Update(DialogueScreen screen, bool isSelected, GameTime gameTime) { // When the menu selection changes, entries gradually fade between // their selected and deselected appearance, rather than instantly // popping to the new state. float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4; if (isSelected) selectionFade = Math.Min(selectionFade + fadeSpeed, 1); else selectionFade = Math.Max(selectionFade - fadeSpeed, 0); }
/// <summary> /// Queries how wide the response is, used for centering on the screen. /// </summary> public virtual int GetWidth(DialogueScreen screen) { return (int)screen.ScreenManager.Font.MeasureString(Text).X; }
/// <summary> /// Queries how much space this response requires. /// </summary> public virtual int GetHeight(DialogueScreen screen) { return screen.ScreenManager.Font.LineSpacing; }
/// <summary> /// Draws this Response. This can be overridden to customize the appearance. /// </summary> public virtual void Draw(DialogueScreen screen, bool isSelected, GameTime gameTime) { // Draw the selected entry in yellow, otherwise white. Color color = isSelected ? Color.Yellow : Color.White; String displayText = isSelected ? selectedText : text; // Pulsate the size of the selected menu entry. double time = gameTime.TotalGameTime.TotalSeconds; // float pulsate = (float)Math.Sin(time * 6) + 1; float scale = 1; // +pulsate * 0.05f * selectionFade; // Modify the alpha to fade text out during transitions. color *= screen.TransitionAlpha; // Draw text, centered on the middle of each line. ScreenManager screenManager = screen.ScreenManager; SpriteBatch spriteBatch = screenManager.SpriteBatch; SpriteFont font = screenManager.Font; Vector2 origin = new Vector2(0, font.LineSpacing / 2); String wrapped = screen.WrapText(font, displayText, screenManager.GraphicsDevice.Viewport.Width - (DialogueScreen.hPad * 3)); spriteBatch.DrawString(font, displayText, position, color, 0, origin, scale, SpriteEffects.None, 0); }
/// <summary> /// Static method for creating a DialogueScreen from the gameplay screen. /// </summary> /// <param name="id">The GUID of the <see cref="NPCPrompt"/>NPCPrompt</see> in the database.</param> /// <returns>A new instance of a DialogueScreen</returns> public static DialogueScreen InitializeDialogueBox(Guid id) { DialogueScreen openingPrompt = new DialogueScreen(id); if (openingPrompt.Prompt.ResponseRequired) { openingPrompt.Responses = openingPrompt.FindResponses(id); } else { openingPrompt.Prompt.IncludeUsageText(); } foreach (IDialogueAction action in openingPrompt.Prompt.PromptActions) { action.ExecuteAction(); } return openingPrompt; }
/// <summary> /// Static method for creating a DialogueScreen from the gameplay screen. /// </summary> /// <param name="id">The GUID of the <see cref="NPCPrompt"/>NPCPrompt</see> in the database.</param> /// <returns>A new instance of a DialogueScreen</returns> public static DialogueScreen InitializeDialogueBox(Guid id) { DialogueScreen openingPrompt = new DialogueScreen(id); openingPrompt.Responses = openingPrompt.FindResponses(id); return openingPrompt; }
/// <summary> /// Queries how wide the response is, used for centering on the screen. /// </summary> public virtual int GetWidth(DialogueScreen screen) { return((int)screen.ScreenManager.Font.MeasureString(Text).X); }
/// <summary> /// Queries how much space this response requires. /// </summary> public virtual int GetHeight(DialogueScreen screen) { return(screen.ScreenManager.Font.LineSpacing); }