StoreScreen.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. //-----------------------------------------------------------------------------
  2. // StoreScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. using Microsoft.Xna.Framework;
  10. using Microsoft.Xna.Framework.Graphics;
  11. using Microsoft.Xna.Framework.Content;
  12. using RolePlaying.Data;
  13. using System.IO;
  14. namespace RolePlaying
  15. {
  16. /// <summary>
  17. /// Draws the options available in a store - typically to buy or sell gear.
  18. /// </summary>
  19. class StoreScreen : GameScreen
  20. {
  21. private Store store = null;
  22. private Texture2D shopDrawScreen;
  23. private Texture2D selectButton;
  24. private Texture2D backButton;
  25. private Texture2D highlightItem;
  26. private Texture2D selectionArrow;
  27. private Texture2D conversationStrip;
  28. private Texture2D plankTexture;
  29. private Texture2D fadeTexture;
  30. private Texture2D goldIcon;
  31. private readonly Vector2 textPosition = new Vector2(620, 250);
  32. private readonly Vector2 backButtonPosition = new Vector2(80, 640);
  33. private readonly Vector2 selectButtonPosition = new Vector2(1150, 640);
  34. private readonly Vector2 partyGoldPosition = new Vector2(565, 648);
  35. private readonly Vector2 shopKeeperPosition = new Vector2(290, 370);
  36. private readonly Vector2 welcomeMessagePosition = new Vector2(470, 460);
  37. private readonly Vector2 conversationStripPosition = new Vector2(240, 405);
  38. private readonly Vector2 goldIconPosition = new Vector2(490, 640);
  39. private readonly Vector2 highlightItemOffset = new Vector2(400, 20);
  40. private readonly Vector2 selectionArrowOffset = new Vector2(100, 16);
  41. private Vector2 shopNamePosition;
  42. private Vector2 plankPosition;
  43. private Vector2 titleBarMidPosition;
  44. private Vector2 placeTextMid;
  45. private Rectangle screenRect;
  46. private int currentCursor;
  47. private const int interval = 50;
  48. /// <summary>
  49. /// Constructs a new StoreScreen object for the given store.
  50. /// </summary>
  51. public StoreScreen(Store store)
  52. {
  53. // check the parameter
  54. if (store == null)
  55. {
  56. throw new ArgumentNullException("store");
  57. }
  58. this.IsPopup = true;
  59. this.store = store;
  60. titleBarMidPosition = new Vector2(
  61. -Fonts.HeaderFont.MeasureString(store.Name).X / 2, 0f);
  62. placeTextMid = Fonts.ButtonNamesFont.MeasureString("Select");
  63. }
  64. /// <summary>
  65. /// Loads the graphics content from the content manager.
  66. /// </summary>
  67. public override void LoadContent()
  68. {
  69. ContentManager content = ScreenManager.Game.Content;
  70. shopDrawScreen =
  71. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "GameScreenBkgd"));
  72. backButton =
  73. content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "BButton"));
  74. selectButton =
  75. content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "AButton"));
  76. highlightItem =
  77. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "HighlightLarge"));
  78. selectionArrow =
  79. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "SelectionArrow"));
  80. fadeTexture =
  81. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "FadeScreen"));
  82. conversationStrip =
  83. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "ConversationStrip"));
  84. goldIcon =
  85. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "GoldIcon"));
  86. plankTexture =
  87. content.Load<Texture2D>(Path.Combine("Textures", "MainMenu", "MainMenuPlank03"));
  88. screenRect = new Rectangle(0, 0, Session.BACK_BUFFER_WIDTH, Session.BACK_BUFFER_HEIGHT);
  89. plankPosition = new Vector2(
  90. (Session.BACK_BUFFER_WIDTH - plankTexture.Width) / 2, 66f);
  91. shopNamePosition = new Vector2(
  92. (Session.BACK_BUFFER_WIDTH - Fonts.HeaderFont.MeasureString(store.Name).X) / 2,
  93. 95f);
  94. }
  95. /// <summary>
  96. /// Handles user input.
  97. /// </summary>
  98. public override void HandleInput()
  99. {
  100. // exits the screen
  101. if (InputManager.IsActionTriggered(InputManager.InputAction.Back))
  102. {
  103. ExitScreen();
  104. return;
  105. }
  106. // select one of the buttons
  107. else if (InputManager.IsActionTriggered(InputManager.InputAction.Ok))
  108. {
  109. if (currentCursor == 0)
  110. {
  111. ScreenManager.AddScreen(new StoreBuyScreen(store));
  112. }
  113. else if (currentCursor == 1)
  114. {
  115. ScreenManager.AddScreen(new StoreSellScreen(store));
  116. }
  117. else
  118. {
  119. ExitScreen();
  120. }
  121. return;
  122. }
  123. // move the cursor up
  124. else if (InputManager.IsActionTriggered(
  125. InputManager.InputAction.MoveCharacterUp))
  126. {
  127. currentCursor--;
  128. if (currentCursor < 0)
  129. {
  130. currentCursor = 0;
  131. }
  132. }
  133. // move the cursor down
  134. else if (InputManager.IsActionTriggered(
  135. InputManager.InputAction.MoveCharacterDown))
  136. {
  137. currentCursor++;
  138. if (currentCursor > 2)
  139. {
  140. currentCursor = 2;
  141. }
  142. }
  143. }
  144. /// <summary>
  145. /// Draw the screen.
  146. /// </summary>
  147. public override void Draw(GameTime gameTime)
  148. {
  149. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  150. // Draw Shop Main Menu
  151. spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
  152. // Draw Shop Main Menu Screen
  153. DrawMainMenu();
  154. // Draw Buttons
  155. if (IsActive)
  156. {
  157. DrawButtons();
  158. }
  159. // Measure Title of the Screen
  160. spriteBatch.Draw(plankTexture, plankPosition, Color.White);
  161. // Draw the Title of the Screen
  162. spriteBatch.DrawString(Fonts.HeaderFont, store.Name, shopNamePosition, Fonts.TitleColor, MathHelper.ToRadians(-3.0f), Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
  163. // Draw Conversation Strip
  164. spriteBatch.Draw(conversationStrip, conversationStripPosition,
  165. Color.White);
  166. // Draw Shop Keeper
  167. spriteBatch.Draw(store.ShopkeeperTexture, shopKeeperPosition, Color.White);
  168. // Draw Shop Info
  169. spriteBatch.DrawString(Fonts.DescriptionFont,
  170. Fonts.BreakTextIntoLines(store.WelcomeMessage, 55, 3),
  171. welcomeMessagePosition, Fonts.DescriptionColor);
  172. spriteBatch.End();
  173. }
  174. /// <summary>
  175. /// Draws the main menu for the store.
  176. /// </summary>
  177. private void DrawMainMenu()
  178. {
  179. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  180. Vector2 arrowPosition = Vector2.Zero;
  181. Vector2 highlightPosition = Vector2.Zero;
  182. Vector2 position = textPosition;
  183. // Draw faded screen
  184. spriteBatch.Draw(fadeTexture, screenRect, Color.White);
  185. spriteBatch.Draw(shopDrawScreen, screenRect, Color.White);
  186. arrowPosition.X = textPosition.X - selectionArrowOffset.X;
  187. arrowPosition.Y = textPosition.Y - selectionArrowOffset.Y;
  188. highlightPosition.X = textPosition.X - highlightItemOffset.X;
  189. highlightPosition.Y = textPosition.Y - highlightItemOffset.Y;
  190. // "Buy" is highlighted
  191. if (currentCursor == 0)
  192. {
  193. spriteBatch.Draw(highlightItem, highlightPosition, Color.White);
  194. spriteBatch.Draw(selectionArrow, arrowPosition, Color.White);
  195. spriteBatch.DrawString(Fonts.GearInfoFont, "Buy", position,
  196. Fonts.HighlightColor);
  197. position.Y += interval;
  198. spriteBatch.DrawString(Fonts.GearInfoFont, "Sell", position,
  199. Fonts.DisplayColor);
  200. position.Y += interval;
  201. spriteBatch.DrawString(Fonts.GearInfoFont, "Leave", position,
  202. Fonts.DisplayColor);
  203. }
  204. // "Sell" is highlighted
  205. else if (currentCursor == 1)
  206. {
  207. position = textPosition;
  208. spriteBatch.DrawString(Fonts.GearInfoFont, "Buy", position,
  209. Fonts.DisplayColor);
  210. highlightPosition.Y += interval;
  211. arrowPosition.Y += interval;
  212. position.Y += interval;
  213. spriteBatch.Draw(highlightItem, highlightPosition, Color.White);
  214. spriteBatch.Draw(selectionArrow, arrowPosition, Color.White);
  215. spriteBatch.DrawString(Fonts.GearInfoFont, "Sell", position,
  216. Fonts.HighlightColor);
  217. position.Y += interval;
  218. spriteBatch.DrawString(Fonts.GearInfoFont, "Leave", position,
  219. Fonts.DisplayColor);
  220. }
  221. // "Leave" is highlighted
  222. else if (currentCursor == 2)
  223. {
  224. position = textPosition;
  225. spriteBatch.DrawString(Fonts.GearInfoFont, "Buy", position,
  226. Fonts.DisplayColor);
  227. position.Y += interval;
  228. spriteBatch.DrawString(Fonts.GearInfoFont, "Sell", position,
  229. Fonts.DisplayColor);
  230. highlightPosition.Y += interval + interval;
  231. arrowPosition.Y += interval + interval;
  232. position.Y += interval;
  233. spriteBatch.Draw(highlightItem, highlightPosition, Color.White);
  234. spriteBatch.Draw(selectionArrow, arrowPosition, Color.White);
  235. spriteBatch.DrawString(Fonts.GearInfoFont, "Leave", position,
  236. Fonts.HighlightColor);
  237. }
  238. }
  239. /// <summary>
  240. /// Draws the buttons.
  241. /// </summary>
  242. private void DrawButtons()
  243. {
  244. if (!IsActive)
  245. {
  246. return;
  247. }
  248. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  249. Vector2 position = new Vector2();
  250. // Draw Back Button
  251. spriteBatch.Draw(backButton, backButtonPosition, Color.White);
  252. // Draw Back Text
  253. position = backButtonPosition;
  254. position.X += backButton.Width + 10;
  255. position.Y += 5;
  256. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Back", position, Color.White);
  257. // Draw Select Button
  258. spriteBatch.Draw(selectButton, selectButtonPosition, Color.White);
  259. // Draw Select Text
  260. position = selectButtonPosition;
  261. position.X -= placeTextMid.X + 10;
  262. position.Y += 5;
  263. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Select", position,
  264. Color.White);
  265. // Draw Gold Text
  266. spriteBatch.DrawString(Fonts.ButtonNamesFont,
  267. Fonts.GetGoldString(Session.Party.PartyGold), partyGoldPosition,
  268. Color.White);
  269. // Draw Gold Icon
  270. spriteBatch.Draw(goldIcon, goldIconPosition, Color.White);
  271. }
  272. }
  273. }