ItemRentDialog.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 ItemRentDialog : MirImageControl
  9. {
  10. private readonly MirLabel _nameLabel, _rentalPriceLabel;
  11. private readonly MirButton _lockButton, _rentalPriceButton;
  12. public ItemRentDialog()
  13. {
  14. Index = 238;
  15. Library = Libraries.Prguse;
  16. Movable = true;
  17. Size = new Size(204, 109);
  18. Location = new Point(Settings.ScreenWidth - Size.Width - Size.Width / 2, Size.Height + Size.Height / 2);
  19. Sort = true;
  20. var closeButton = new MirButton
  21. {
  22. HoverIndex = 361,
  23. Index = 360,
  24. Location = new Point(180, 3),
  25. Library = Libraries.Prguse2,
  26. Parent = this,
  27. PressedIndex = 362,
  28. Sound = SoundList.ButtonA,
  29. };
  30. closeButton.Click += (sender, args) =>
  31. {
  32. CancelItemRental();
  33. };
  34. _lockButton = new MirButton
  35. {
  36. Index = 250,
  37. HoverIndex = 251,
  38. Location = new Point(22, 76),
  39. Size = new Size(28, 25),
  40. Library = Libraries.Prguse,
  41. Parent = this,
  42. PressedIndex = 252,
  43. Sound = SoundList.ButtonA,
  44. };
  45. _lockButton.Click += (o, e) =>
  46. {
  47. if (GameScene.User.RentalGoldAmount < 1)
  48. return;
  49. Network.Enqueue(new C.ItemRentalLockFee());
  50. };
  51. _rentalPriceButton = new MirButton
  52. {
  53. Index = 28,
  54. Location = new Point(18, 46),
  55. Size = new Size(32, 17),
  56. Library = Libraries.Prguse,
  57. Parent = this,
  58. Sound = SoundList.Gold,
  59. };
  60. _rentalPriceButton.Click += (o, e) =>
  61. {
  62. if (GameScene.SelectedCell != null || GameScene.Gold <= 0)
  63. return;
  64. var amountBox = new MirAmountBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.RentalFee), 116, GameScene.Gold);
  65. amountBox.OKButton.Click += (c, a) =>
  66. {
  67. if (amountBox.Amount <= 0)
  68. return;
  69. GameScene.User.RentalGoldAmount += amountBox.Amount;
  70. Network.Enqueue(new C.ItemRentalFee { Amount = GameScene.User.RentalGoldAmount });
  71. RefreshInterface();
  72. };
  73. amountBox.Show();
  74. GameScene.PickedUpGold = false;
  75. };
  76. _nameLabel = new MirLabel
  77. {
  78. Parent = this,
  79. Location = new Point(30, 8),
  80. Size = new Size(150, 14),
  81. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  82. NotControl = true,
  83. };
  84. _rentalPriceLabel = new MirLabel
  85. {
  86. Parent = this,
  87. Location = new Point(60, 42),
  88. Size = new Size(150, 14),
  89. DrawFormat = TextFormatFlags.Left | TextFormatFlags.VerticalCenter,
  90. };
  91. _rentalPriceLabel.Click += (o, e) =>
  92. {
  93. var clickEventArgs = e as MouseEventArgs;
  94. if (clickEventArgs == null)
  95. return;
  96. switch (clickEventArgs.Button)
  97. {
  98. case MouseButtons.Left:
  99. if (GameScene.SelectedCell != null || GameScene.Gold <= 0)
  100. return;
  101. var amountBox = new MirAmountBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.RentalFee), 116, GameScene.Gold);
  102. amountBox.OKButton.Click += (c, a) =>
  103. {
  104. if (amountBox.Amount <= 0)
  105. return;
  106. GameScene.User.RentalGoldAmount += amountBox.Amount;
  107. Network.Enqueue(new C.ItemRentalFee { Amount = GameScene.User.RentalGoldAmount });
  108. RefreshInterface();
  109. };
  110. amountBox.Show();
  111. GameScene.PickedUpGold = false;
  112. break;
  113. }
  114. };
  115. }
  116. public void RefreshInterface()
  117. {
  118. _nameLabel.Text = GameScene.User.Name;
  119. _rentalPriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.RentalFeeGoldAmount), GameScene.User.RentalGoldAmount);
  120. GameScene.Scene.GuestItemRentingDialog.RefreshInterface();
  121. GameScene.Scene.GuestItemRentDialog.RefreshInterface();
  122. Redraw();
  123. }
  124. public void OpenItemRentDialog()
  125. {
  126. GameScene.Scene.InventoryDialog.Show();
  127. Show();
  128. RefreshInterface();
  129. GameScene.Scene.GuestItemRentingDialog.Show();
  130. }
  131. public void Reset()
  132. {
  133. GameScene.User.RentalGoldAmount = 0;
  134. GameScene.Scene.GuestItemRentDialog.Reset();
  135. RefreshInterface();
  136. Unlock();
  137. Hide();
  138. }
  139. public void Lock()
  140. {
  141. _lockButton.Index = 253;
  142. _lockButton.Enabled = false;
  143. _rentalPriceButton.Enabled = false;
  144. RefreshInterface();
  145. }
  146. private void Unlock()
  147. {
  148. _lockButton.Index = 250;
  149. _lockButton.Enabled = true;
  150. _rentalPriceButton.Enabled = true;
  151. }
  152. private static void CancelItemRental()
  153. {
  154. Network.Enqueue(new C.CancelItemRental());
  155. }
  156. }
  157. public sealed class GuestItemRentDialog : MirImageControl
  158. {
  159. public string GuestName => _guestName;
  160. private readonly MirLabel _nameLabel, _rentalPriceLabel;
  161. private readonly MirButton _lockButton, _rentalPriceButton;
  162. private string _guestName;
  163. private uint _guestGold;
  164. private bool _guestGoldLocked;
  165. public GuestItemRentDialog()
  166. {
  167. Index = 238;
  168. Library = Libraries.Prguse;
  169. Movable = true;
  170. Size = new Size(204, 109);
  171. Location = new Point(Settings.ScreenWidth - Size.Width - Size.Width / 2, Size.Height + Size.Height / 2);
  172. Sort = true;
  173. _lockButton = new MirButton
  174. {
  175. Index = 250,
  176. Location = new Point(22, 76),
  177. Size = new Size(28, 25),
  178. Library = Libraries.Prguse,
  179. Parent = this,
  180. Enabled = false
  181. };
  182. _rentalPriceButton = new MirButton
  183. {
  184. Index = 28,
  185. Location = new Point(18, 46),
  186. Size = new Size(32, 17),
  187. Library = Libraries.Prguse,
  188. Parent = this,
  189. Enabled = false
  190. };
  191. _nameLabel = new MirLabel
  192. {
  193. Parent = this,
  194. Location = new Point(30, 8),
  195. Size = new Size(150, 14),
  196. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  197. NotControl = true,
  198. };
  199. _rentalPriceLabel = new MirLabel
  200. {
  201. Parent = this,
  202. Location = new Point(60, 42),
  203. Size = new Size(150, 14),
  204. DrawFormat = TextFormatFlags.Left | TextFormatFlags.VerticalCenter,
  205. NotControl = true,
  206. };
  207. }
  208. public void RefreshInterface()
  209. {
  210. _nameLabel.Text = _guestName;
  211. _rentalPriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.RentalFeeGoldAmount), _guestGold);
  212. Redraw();
  213. }
  214. public void SetGuestName(string name)
  215. {
  216. _guestName = name;
  217. }
  218. public void SetGuestFee(uint amount)
  219. {
  220. _guestGold = amount;
  221. }
  222. public void Reset()
  223. {
  224. Unlock();
  225. _guestName = string.Empty;
  226. _guestGold = 0;
  227. Hide();
  228. }
  229. public void Lock()
  230. {
  231. _lockButton.Index = 253;
  232. _guestGoldLocked = true;
  233. RefreshInterface();
  234. }
  235. private void Unlock()
  236. {
  237. _lockButton.Index = 250;
  238. _guestGoldLocked = false;
  239. }
  240. }
  241. }