PlayerNpcScreen.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // PlayerNpcScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using RolePlayingGameData;
  12. #endregion
  13. namespace RolePlaying
  14. {
  15. /// <summary>
  16. /// Displays the Player NPC screen, shown when encountering a player on the map.
  17. /// Typically, the user has an opportunity to invite the Player into the party.
  18. /// </summary>
  19. class PlayerNpcScreen : NpcScreen<Player>
  20. {
  21. /// <summary>
  22. /// If true, the NPC's introduction dialogue is shown.
  23. /// </summary>
  24. private bool isIntroduction = true;
  25. /// <summary>
  26. /// Constructs a new PlayerNpcScreen object.
  27. /// </summary>
  28. /// <param name="mapEntry"></param>
  29. public PlayerNpcScreen(MapEntry<Player> mapEntry)
  30. : base(mapEntry)
  31. {
  32. // assign and check the parameter
  33. Player playerNpc = character as Player;
  34. if (playerNpc == null)
  35. {
  36. throw new ArgumentException(
  37. "PlayerNpcScreen requires a MapEntry with a Player");
  38. }
  39. this.DialogueText = playerNpc.IntroductionDialogue;
  40. this.BackText = "Reject";
  41. this.SelectText = "Accept";
  42. isIntroduction = true;
  43. }
  44. /// <summary>
  45. /// Handles user input.
  46. /// </summary>
  47. public override void HandleInput()
  48. {
  49. // view the player's statistics
  50. if (InputManager.IsActionTriggered(InputManager.Action.TakeView))
  51. {
  52. ScreenManager.AddScreen(new StatisticsScreen(character as Player));
  53. return;
  54. }
  55. if (isIntroduction)
  56. {
  57. // accept the invitation
  58. if (InputManager.IsActionTriggered(InputManager.Action.Ok))
  59. {
  60. isIntroduction = false;
  61. Player player = character as Player;
  62. Session.Party.JoinParty(player);
  63. Session.RemovePlayerNpc(mapEntry);
  64. this.DialogueText = player.JoinAcceptedDialogue;
  65. this.BackText = "Back";
  66. this.SelectText = "Back";
  67. }
  68. // reject the invitation
  69. if (InputManager.IsActionTriggered(InputManager.Action.Back))
  70. {
  71. isIntroduction = false;
  72. Player player = character as Player;
  73. this.DialogueText = player.JoinRejectedDialogue;
  74. this.BackText = "Back";
  75. this.SelectText = "Back";
  76. }
  77. }
  78. else
  79. {
  80. // exit the screen
  81. if (InputManager.IsActionTriggered(InputManager.Action.Ok) ||
  82. InputManager.IsActionTriggered(InputManager.Action.Back))
  83. {
  84. ExitScreen();
  85. return;
  86. }
  87. }
  88. }
  89. }
  90. }