InnScreen.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // InnScreen.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 System.Collections.Generic;
  12. using Microsoft.Xna.Framework;
  13. using Microsoft.Xna.Framework.Graphics;
  14. using Microsoft.Xna.Framework.Content;
  15. using RolePlayingGameData;
  16. #endregion
  17. namespace RolePlaying
  18. {
  19. /// <summary>
  20. /// Displays the options for an inn that the party can stay at.
  21. /// </summary>
  22. class InnScreen : GameScreen
  23. {
  24. private Inn inn;
  25. #region Graphics Data
  26. private Texture2D backgroundTexture;
  27. private Texture2D plankTexture;
  28. private Texture2D selectIconTexture;
  29. private Texture2D backIconTexture;
  30. private Texture2D highlightTexture;
  31. private Texture2D arrowTexture;
  32. private Texture2D conversationTexture;
  33. private Texture2D fadeTexture;
  34. private Texture2D goldIcon;
  35. #endregion
  36. #region Position Data
  37. private readonly Vector2 stayPosition = new Vector2(620f, 250f);
  38. private readonly Vector2 leavePosition = new Vector2(620f, 300f);
  39. private readonly Vector2 costPosition = new Vector2(470, 450);
  40. private readonly Vector2 informationPosition = new Vector2(470, 490);
  41. private readonly Vector2 selectIconPosition = new Vector2(1150, 640);
  42. private readonly Vector2 backIconPosition = new Vector2(80, 640);
  43. private readonly Vector2 goldStringPosition = new Vector2(565, 648);
  44. private readonly Vector2 stayArrowPosition = new Vector2(520f, 234f);
  45. private readonly Vector2 leaveArrowPosition = new Vector2(520f, 284f);
  46. private readonly Vector2 stayHighlightPosition = new Vector2(180f, 230f);
  47. private readonly Vector2 leaveHighlightPosition = new Vector2(180f, 280f);
  48. private readonly Vector2 innKeeperPosition = new Vector2(290, 370);
  49. private readonly Vector2 conversationStripPosition = new Vector2(210f, 405f);
  50. private readonly Vector2 goldIconPosition = new Vector2(490, 640);
  51. private Vector2 plankPosition;
  52. private Vector2 backgroundPosition;
  53. private Vector2 namePosition;
  54. private Vector2 selectTextPosition;
  55. private Vector2 backTextPosition;
  56. private Rectangle screenRectangle;
  57. #endregion
  58. #region Dialog Text
  59. private List<string> welcomeMessage;
  60. private List<string> serviceRenderedMessage;
  61. private List<string> noGoldMessage;
  62. private List<string> currentDialogue;
  63. private const int maxWidth = 570;
  64. private const int maxLines = 3;
  65. private string costString;
  66. private readonly string stayString = "Stay";
  67. private readonly string leaveString = "Leave";
  68. private readonly string selectString = "Select";
  69. private readonly string backString = "Leave";
  70. #endregion
  71. #region Selection Data
  72. private int selectionMark;
  73. private int endIndex;
  74. #endregion
  75. #region Initialization
  76. /// <summary>
  77. /// Creates a new InnScreen object.
  78. /// </summary>
  79. public InnScreen(Inn inn)
  80. : base()
  81. {
  82. // check the parameter
  83. if (inn == null)
  84. {
  85. throw new ArgumentNullException("inn");
  86. }
  87. this.IsPopup = true;
  88. this.inn = inn;
  89. welcomeMessage = Fonts.BreakTextIntoList(inn.WelcomeMessage,
  90. Fonts.DescriptionFont, maxWidth);
  91. serviceRenderedMessage = Fonts.BreakTextIntoList(inn.PaidMessage,
  92. Fonts.DescriptionFont, maxWidth);
  93. noGoldMessage = Fonts.BreakTextIntoList(inn.NotEnoughGoldMessage,
  94. Fonts.DescriptionFont, maxWidth);
  95. selectionMark = 1;
  96. ChangeDialogue(welcomeMessage);
  97. }
  98. /// <summary>
  99. /// Load the graphics content
  100. /// </summary>
  101. /// <param name="batch">SpriteBatch object</param>
  102. /// <param name="screenWidth">Width of screen</param>
  103. /// <param name="screenHeight">Height of the screen</param>
  104. public override void LoadContent()
  105. {
  106. Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
  107. ContentManager content = ScreenManager.Game.Content;
  108. backgroundTexture =
  109. content.Load<Texture2D>(@"Textures\GameScreens\GameScreenBkgd");
  110. plankTexture =
  111. content.Load<Texture2D>(@"Textures\MainMenu\MainMenuPlank03");
  112. selectIconTexture =
  113. content.Load<Texture2D>(@"Textures\Buttons\AButton");
  114. backIconTexture =
  115. content.Load<Texture2D>(@"Textures\Buttons\BButton");
  116. highlightTexture =
  117. content.Load<Texture2D>(@"Textures\GameScreens\HighlightLarge");
  118. arrowTexture =
  119. content.Load<Texture2D>(@"Textures\GameScreens\SelectionArrow");
  120. conversationTexture =
  121. content.Load<Texture2D>(@"Textures\GameScreens\ConversationStrip");
  122. goldIcon = content.Load<Texture2D>(@"Textures\GameScreens\GoldIcon");
  123. fadeTexture = content.Load<Texture2D>(@"Textures\GameScreens\FadeScreen");
  124. screenRectangle = new Rectangle(viewport.X, viewport.Y,
  125. viewport.Width, viewport.Height);
  126. plankPosition = new Vector2((viewport.Width - plankTexture.Width) / 2, 67f);
  127. backgroundPosition = new Vector2(
  128. (viewport.Width - backgroundTexture.Width) / 2,
  129. (viewport.Height - backgroundTexture.Height) / 2);
  130. namePosition = new Vector2(
  131. (viewport.Width - Fonts.HeaderFont.MeasureString(inn.Name).X) / 2, 90f);
  132. selectTextPosition = selectIconPosition;
  133. selectTextPosition.X -=
  134. Fonts.ButtonNamesFont.MeasureString(selectString).X + 10;
  135. selectTextPosition.Y += 5;
  136. backTextPosition = backIconPosition;
  137. backTextPosition.X += backIconTexture.Width + 10;
  138. backTextPosition.Y += 5;
  139. }
  140. #endregion
  141. #region Updating
  142. /// <summary>
  143. /// Handle user input.
  144. /// </summary>
  145. public override void HandleInput()
  146. {
  147. // exit the screen
  148. if (InputManager.IsActionTriggered(InputManager.Action.Back))
  149. {
  150. ExitScreen();
  151. return;
  152. }
  153. // move the cursor up
  154. else if (InputManager.IsActionTriggered(InputManager.Action.CursorUp))
  155. {
  156. if (selectionMark == 2)
  157. {
  158. selectionMark = 1;
  159. }
  160. }
  161. // move the cursor down
  162. else if (InputManager.IsActionTriggered(InputManager.Action.CursorDown))
  163. {
  164. if (selectionMark == 1)
  165. {
  166. selectionMark = 2;
  167. }
  168. }
  169. // select an option
  170. else if (InputManager.IsActionTriggered(InputManager.Action.Ok))
  171. {
  172. if (selectionMark == 1)
  173. {
  174. int partyCharge = GetChargeForParty(Session.Party);
  175. if (Session.Party.PartyGold >= partyCharge)
  176. {
  177. AudioManager.PlayCue("Money");
  178. Session.Party.PartyGold -= partyCharge;
  179. selectionMark = 2;
  180. ChangeDialogue(serviceRenderedMessage);
  181. HealParty(Session.Party);
  182. }
  183. else
  184. {
  185. selectionMark = 2;
  186. ChangeDialogue(noGoldMessage);
  187. }
  188. }
  189. else
  190. {
  191. ExitScreen();
  192. return;
  193. }
  194. }
  195. }
  196. /// <summary>
  197. /// Change the current dialogue.
  198. /// </summary>
  199. private void ChangeDialogue(List<string> newDialogue)
  200. {
  201. currentDialogue = newDialogue;
  202. endIndex = maxLines;
  203. if (endIndex > currentDialogue.Count)
  204. {
  205. endIndex = currentDialogue.Count;
  206. }
  207. }
  208. /// <summary>
  209. /// Calculate the charge for the party's stay at the inn.
  210. /// </summary>
  211. private int GetChargeForParty(Party party)
  212. {
  213. // check the parameter
  214. if (party == null)
  215. {
  216. throw new ArgumentNullException("party");
  217. }
  218. return inn.ChargePerPlayer * party.Players.Count;
  219. }
  220. /// <summary>
  221. /// Heal the party back to their correct values for level + gear.
  222. /// </summary>
  223. private void HealParty(Party party)
  224. {
  225. // check the parameter
  226. if (party == null)
  227. {
  228. throw new ArgumentNullException("party");
  229. }
  230. // reset the statistics for each player
  231. foreach (Player player in party.Players)
  232. {
  233. player.StatisticsModifiers = new StatisticsValue();
  234. }
  235. }
  236. #endregion
  237. #region Drawing
  238. /// <summary>
  239. /// Draw the screen.
  240. /// </summary>
  241. public override void Draw(GameTime gameTime)
  242. {
  243. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  244. Vector2 dialogPosition = informationPosition;
  245. spriteBatch.Begin();
  246. // Draw fade screen
  247. spriteBatch.Draw(fadeTexture, screenRectangle, Color.White);
  248. // Draw the background
  249. spriteBatch.Draw(backgroundTexture, backgroundPosition, Color.White);
  250. // Draw the wooden plank
  251. spriteBatch.Draw(plankTexture, plankPosition, Color.White);
  252. // Draw the select icon
  253. spriteBatch.Draw(selectIconTexture, selectIconPosition, Color.White);
  254. // Draw the back icon
  255. spriteBatch.Draw(backIconTexture, backIconPosition, Color.White);
  256. // Draw the inn name on the wooden plank
  257. spriteBatch.DrawString(Fonts.HeaderFont, inn.Name, namePosition,
  258. Fonts.DisplayColor);
  259. // Draw the stay and leave option texts based on the current selection
  260. if (selectionMark == 1)
  261. {
  262. spriteBatch.Draw(highlightTexture, stayHighlightPosition, Color.White);
  263. spriteBatch.Draw(arrowTexture, stayArrowPosition, Color.White);
  264. spriteBatch.DrawString(
  265. Fonts.GearInfoFont, stayString, stayPosition, Fonts.HighlightColor);
  266. spriteBatch.DrawString(
  267. Fonts.GearInfoFont, leaveString, leavePosition, Fonts.DisplayColor);
  268. }
  269. else
  270. {
  271. spriteBatch.Draw(highlightTexture, leaveHighlightPosition, Color.White);
  272. spriteBatch.Draw(arrowTexture, leaveArrowPosition, Color.White);
  273. spriteBatch.DrawString(Fonts.GearInfoFont, stayString, stayPosition,
  274. Fonts.DisplayColor);
  275. spriteBatch.DrawString(Fonts.GearInfoFont, leaveString, leavePosition,
  276. Fonts.HighlightColor);
  277. }
  278. // Draw the amount of gold
  279. spriteBatch.DrawString(Fonts.ButtonNamesFont,
  280. Fonts.GetGoldString(Session.Party.PartyGold), goldStringPosition,
  281. Color.White);
  282. // Draw the select button text
  283. spriteBatch.DrawString(
  284. Fonts.ButtonNamesFont, selectString, selectTextPosition, Color.White);
  285. // Draw the back button text
  286. spriteBatch.DrawString(Fonts.ButtonNamesFont, backString, backTextPosition,
  287. Color.White);
  288. // Draw Conversation Strip
  289. spriteBatch.Draw(conversationTexture, conversationStripPosition,
  290. Color.White);
  291. // Draw Shop Keeper
  292. spriteBatch.Draw(inn.ShopkeeperTexture, innKeeperPosition, Color.White);
  293. // Draw the cost to stay
  294. costString = "Cost: " + GetChargeForParty(Session.Party) + " Gold";
  295. spriteBatch.DrawString(Fonts.DescriptionFont, costString, costPosition,
  296. Color.DarkRed);
  297. // Draw the innkeeper dialog
  298. for (int i = 0; i < endIndex; i++)
  299. {
  300. spriteBatch.DrawString(Fonts.DescriptionFont, currentDialogue[i],
  301. dialogPosition, Color.Black);
  302. dialogPosition.Y += Fonts.DescriptionFont.LineSpacing;
  303. }
  304. // Draw Gold Icon
  305. spriteBatch.Draw(goldIcon, goldIconPosition, Color.White);
  306. spriteBatch.End();
  307. }
  308. #endregion
  309. }
  310. }