TradeDialogs.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirNetwork;
  4. using Client.MirSounds;
  5. using C = ClientPackets;
  6. namespace Client.MirScenes.Dialogs
  7. {
  8. public sealed class TradeDialog : MirImageControl
  9. {
  10. public MirItemCell[] Grid;
  11. public MirLabel NameLabel, GoldLabel;
  12. public MirButton ConfirmButton, CloseButton;
  13. public TradeDialog()
  14. {
  15. Index = 389;
  16. Library = Libraries.Prguse;
  17. Movable = true;
  18. Size = new Size(204, 152);
  19. Location = new Point((Settings.ScreenWidth / 2) - Size.Width - 10, Settings.ScreenHeight - 350);
  20. Sort = true;
  21. #region Buttons
  22. ConfirmButton = new MirButton
  23. {
  24. Index = 520,
  25. HoverIndex = 521,
  26. Location = new Point(135, 120),
  27. Size = new Size(48, 25),
  28. Library = Libraries.Title,
  29. Parent = this,
  30. PressedIndex = 522,
  31. Sound = SoundList.ButtonA,
  32. };
  33. ConfirmButton.Click += (o, e) =>
  34. {
  35. ChangeLockState(!GameScene.User.TradeLocked);
  36. Network.Enqueue(new C.TradeConfirm { Locked = GameScene.User.TradeLocked });
  37. };
  38. CloseButton = new MirButton
  39. {
  40. HoverIndex = 361,
  41. Index = 360,
  42. Location = new Point(Size.Width - 23, 3),
  43. Library = Libraries.Prguse2,
  44. Parent = this,
  45. PressedIndex = 362,
  46. Sound = SoundList.ButtonA,
  47. };
  48. CloseButton.Click += (o, e) =>
  49. {
  50. Hide();
  51. GameScene.Scene.GuestTradeDialog.Hide();
  52. TradeCancel();
  53. };
  54. #endregion
  55. #region Host labels
  56. NameLabel = new MirLabel
  57. {
  58. Parent = this,
  59. Location = new Point(20, 10),
  60. Size = new Size(150, 14),
  61. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  62. NotControl = true,
  63. };
  64. GoldLabel = new MirLabel
  65. {
  66. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  67. Font = new Font(Settings.FontName, 8F),
  68. Location = new Point(35, 123),
  69. Parent = this,
  70. Size = new Size(90, 15),
  71. Sound = SoundList.Gold,
  72. };
  73. GoldLabel.Click += (o, e) =>
  74. {
  75. if (GameScene.SelectedCell == null && GameScene.Gold > 0)
  76. {
  77. MirAmountBox amountBox = new MirAmountBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.TradeAmount), 116, GameScene.Gold);
  78. amountBox.OKButton.Click += (c, a) =>
  79. {
  80. if (amountBox.Amount > 0)
  81. {
  82. GameScene.User.TradeGoldAmount += amountBox.Amount;
  83. Network.Enqueue(new C.TradeGold { Amount = amountBox.Amount });
  84. RefreshInterface();
  85. }
  86. };
  87. amountBox.Show();
  88. GameScene.PickedUpGold = false;
  89. }
  90. };
  91. #endregion
  92. #region Grids
  93. Grid = new MirItemCell[5 * 2];
  94. for (int x = 0; x < 5; x++)
  95. {
  96. for (int y = 0; y < 2; y++)
  97. {
  98. Grid[2 * x + y] = new MirItemCell
  99. {
  100. ItemSlot = 2 * x + y,
  101. GridType = MirGridType.Trade,
  102. Parent = this,
  103. Location = new Point(x * 36 + 10 + x, y * 32 + 39 + y),
  104. };
  105. }
  106. }
  107. #endregion
  108. }
  109. public void ChangeLockState(bool lockState, bool cancelled = false)
  110. {
  111. GameScene.User.TradeLocked = lockState;
  112. if (GameScene.User.TradeLocked)
  113. {
  114. ConfirmButton.Index = 521;
  115. }
  116. else
  117. {
  118. ConfirmButton.Index = 520;
  119. }
  120. //if (!cancelled)
  121. //{
  122. // //Send lock info to server
  123. // Network.Enqueue(new C.TradeConfirm { Locked = lockState });
  124. //}
  125. }
  126. public void RefreshInterface()
  127. {
  128. NameLabel.Text = GameScene.User.Name;
  129. GoldLabel.Text = GameScene.User.TradeGoldAmount.ToString("###,###,##0");
  130. GameScene.Scene.GuestTradeDialog.RefreshInterface();
  131. Redraw();
  132. }
  133. public void TradeAccept()
  134. {
  135. GameScene.Scene.InventoryDialog.Location = new Point(Settings.ScreenWidth - GameScene.Scene.InventoryDialog.Size.Width, 0);
  136. GameScene.Scene.InventoryDialog.Show();
  137. RefreshInterface();
  138. Show();
  139. GameScene.Scene.GuestTradeDialog.Show();
  140. }
  141. public void TradeReset()
  142. {
  143. GameScene.Scene.GuestTradeDialog.TradeReset();
  144. for (int i = 0; i < GameScene.User.Trade.Length; i++)
  145. GameScene.User.Trade[i] = null;
  146. GameScene.User.TradeGoldAmount = 0;
  147. ChangeLockState(false, true);
  148. RefreshInterface();
  149. Hide();
  150. GameScene.Scene.GuestTradeDialog.Hide();
  151. }
  152. public void TradeCancel()
  153. {
  154. Network.Enqueue(new C.TradeCancel());
  155. }
  156. public MirItemCell GetCell(ulong id)
  157. {
  158. for (int i = 0; i < Grid.Length; i++)
  159. {
  160. if (Grid[i].Item == null || Grid[i].Item.UniqueID != id) continue;
  161. return Grid[i];
  162. }
  163. return null;
  164. }
  165. }
  166. public sealed class GuestTradeDialog : MirImageControl
  167. {
  168. public MirItemCell[] GuestGrid;
  169. public static UserItem[] GuestItems = new UserItem[10];
  170. public string GuestName;
  171. public uint GuestGold;
  172. public MirLabel GuestNameLabel, GuestGoldLabel;
  173. public MirButton ConfirmButton;
  174. public GuestTradeDialog()
  175. {
  176. Index = 390;
  177. Library = Libraries.Prguse;
  178. Movable = true;
  179. Size = new Size(204, 152);
  180. Location = new Point((Settings.ScreenWidth / 2) + 10, Settings.ScreenHeight - 350);
  181. Sort = true;
  182. #region Host labels
  183. GuestNameLabel = new MirLabel
  184. {
  185. Parent = this,
  186. Location = new Point(0, 10),
  187. Size = new Size(204, 14),
  188. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  189. NotControl = true,
  190. };
  191. GuestGoldLabel = new MirLabel
  192. {
  193. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  194. Font = new Font(Settings.FontName, 8F),
  195. Location = new Point(35, 123),
  196. Parent = this,
  197. Size = new Size(90, 15),
  198. Sound = SoundList.Gold,
  199. NotControl = true,
  200. };
  201. #endregion
  202. #region Grids
  203. GuestGrid = new MirItemCell[5 * 2];
  204. for (int x = 0; x < 5; x++)
  205. {
  206. for (int y = 0; y < 2; y++)
  207. {
  208. GuestGrid[2 * x + y] = new MirItemCell
  209. {
  210. ItemSlot = 2 * x + y,
  211. GridType = MirGridType.GuestTrade,
  212. Parent = this,
  213. Location = new Point(x * 36 + 10 + x, y * 32 + 39 + y),
  214. };
  215. }
  216. }
  217. #endregion
  218. }
  219. public void RefreshInterface()
  220. {
  221. GuestNameLabel.Text = GuestName;
  222. GuestGoldLabel.Text = string.Format("{0:###,###,##0}", GuestGold);
  223. for (int i = 0; i < GuestItems.Length; i++)
  224. {
  225. if (GuestItems[i] == null) continue;
  226. GameScene.Bind(GuestItems[i]);
  227. }
  228. Redraw();
  229. }
  230. public void TradeReset()
  231. {
  232. for (int i = 0; i < GuestItems.Length; i++)
  233. GuestItems[i] = null;
  234. GuestName = string.Empty;
  235. GuestGold = 0;
  236. Hide();
  237. }
  238. }
  239. }