ItemRentingDialog.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 ItemRentingDialog : MirImageControl
  9. {
  10. public static UserItem RentalItem;
  11. public readonly MirItemCell ItemCell;
  12. public uint RentalPeriod;
  13. private readonly MirLabel _nameLabel, _rentalPeriodLabel;
  14. private readonly MirButton _lockButton, _setRentalPeriodButton, _confirmButton;
  15. public ItemRentingDialog()
  16. {
  17. Index = 238;
  18. Library = Libraries.Prguse;
  19. Movable = true;
  20. Size = new Size(204, 109);
  21. Location = new Point(Settings.ScreenWidth - Size.Width - Size.Width / 2, Size.Height * 2 + Size.Height / 2 + 15);
  22. Sort = true;
  23. // Confirm Button
  24. _confirmButton = new MirButton
  25. {
  26. Index = 10,
  27. HoverIndex = 11,
  28. Location = new Point(130, 76),
  29. Size = new Size(58, 28),
  30. Library = Libraries.Prguse3,
  31. Parent = this,
  32. PressedIndex = 12,
  33. Sound = SoundList.ButtonA,
  34. Enabled = false
  35. };
  36. _confirmButton.Click += (o, e) =>
  37. {
  38. Network.Enqueue(new C.ConfirmItemRental());
  39. };
  40. // Close Button
  41. var closeButton = new MirButton
  42. {
  43. HoverIndex = 361,
  44. Index = 360,
  45. Location = new Point(180, 3),
  46. Library = Libraries.Prguse2,
  47. Parent = this,
  48. PressedIndex = 362,
  49. Sound = SoundList.ButtonA,
  50. };
  51. closeButton.Click += (sender, args) =>
  52. {
  53. CancelItemRental();
  54. };
  55. // Lock Button
  56. _lockButton = new MirButton
  57. {
  58. Index = 250,
  59. HoverIndex = 251,
  60. Location = new Point(18, 76),
  61. Size = new Size(28, 25),
  62. Library = Libraries.Prguse,
  63. Parent = this,
  64. PressedIndex = 252,
  65. Sound = SoundList.ButtonA,
  66. };
  67. _lockButton.Click += (o, e) =>
  68. {
  69. if (RentalPeriod < 1 || RentalPeriod > 30)
  70. return;
  71. Network.Enqueue(new C.ItemRentalLockItem());
  72. };
  73. // Set Rental Period Button
  74. _setRentalPeriodButton = new MirButton
  75. {
  76. Index = 7,
  77. HoverIndex = 8,
  78. Location = new Point(46, 76),
  79. Size = new Size(84, 28),
  80. Library = Libraries.Prguse3,
  81. Parent = this,
  82. PressedIndex = 9,
  83. Sound = SoundList.ButtonA,
  84. };
  85. _setRentalPeriodButton.Click += (o, e) =>
  86. {
  87. InputRentalPeroid();
  88. };
  89. // Name Label
  90. _nameLabel = new MirLabel
  91. {
  92. Parent = this,
  93. Location = new Point(30, 8),
  94. Size = new Size(150, 14),
  95. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  96. NotControl = true,
  97. };
  98. // Rental Period Label
  99. _rentalPeriodLabel = new MirLabel
  100. {
  101. Parent = this,
  102. Location = new Point(60, 42),
  103. Size = new Size(150, 14),
  104. DrawFormat = TextFormatFlags.Left | TextFormatFlags.VerticalCenter,
  105. NotControl = true,
  106. };
  107. // Item Cell
  108. ItemCell = new MirItemCell
  109. {
  110. BorderColour = Color.Lime,
  111. GridType = MirGridType.Renting,
  112. Library = Libraries.Items,
  113. Parent = this,
  114. Location = new Point(16, 35),
  115. ItemSlot = 0,
  116. };
  117. }
  118. private static void CancelItemRental()
  119. {
  120. Network.Enqueue(new C.CancelItemRental());
  121. }
  122. public void EnableConfirmButton()
  123. {
  124. _confirmButton.Enabled = true;
  125. }
  126. public void InputRentalPeroid()
  127. {
  128. var inputBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.RentItemDurationQuestion), RentalItem.FriendlyName, GameScene.Scene.GuestItemRentDialog.GuestName));
  129. inputBox.OKButton.Click += (o1, e1) =>
  130. {
  131. if (!uint.TryParse(inputBox.InputTextBox.Text, out RentalPeriod))
  132. return;
  133. if (RentalPeriod < 1 || RentalPeriod > 30)
  134. return;
  135. RefreshInterface();
  136. inputBox.Dispose();
  137. Network.Enqueue(new C.ItemRentalPeriod { Days = RentalPeriod });
  138. };
  139. inputBox.Show();
  140. }
  141. public void RefreshInterface()
  142. {
  143. _nameLabel.Text = GameScene.User.Name;
  144. _rentalPeriodLabel.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.RentalPeriodDays), RentalPeriod);
  145. GameScene.Scene.GuestItemRentDialog.RefreshInterface();
  146. GameScene.Scene.GuestItemRentingDialog.RefreshInterface();
  147. Redraw();
  148. }
  149. public void OpenItemRentalDialog()
  150. {
  151. GameScene.Scene.InventoryDialog.Show();
  152. Show();
  153. RefreshInterface();
  154. GameScene.Scene.GuestItemRentDialog.Show();
  155. }
  156. public void Reset()
  157. {
  158. RentalItem = null;
  159. RentalPeriod = 0;
  160. _confirmButton.Enabled = false;
  161. GameScene.User.RentalGoldAmount = 0;
  162. GameScene.Scene.GuestItemRentingDialog.Reset();
  163. Unlock();
  164. RefreshInterface();
  165. Hide();
  166. }
  167. public void Lock()
  168. {
  169. _lockButton.Index = 253;
  170. _lockButton.Enabled = false;
  171. _setRentalPeriodButton.Enabled = false;
  172. RefreshInterface();
  173. }
  174. private void Unlock()
  175. {
  176. _lockButton.Index = 250;
  177. _lockButton.Enabled = true;
  178. _setRentalPeriodButton.Enabled = true;
  179. }
  180. }
  181. public sealed class GuestItemRentingDialog : MirImageControl
  182. {
  183. public static UserItem GuestLoanItem;
  184. public uint GuestRentalPeriod;
  185. private readonly MirLabel _nameLabel, _rentalPeriodLabel;
  186. private readonly MirButton _lockButton, _setRentalPeriodButton, _confirmButton;
  187. private string _guestName;
  188. private MirItemCell _guestItemCell;
  189. public GuestItemRentingDialog()
  190. {
  191. Index = 238;
  192. Library = Libraries.Prguse;
  193. Movable = true;
  194. Size = new Size(204, 109);
  195. Location = new Point(Settings.ScreenWidth - Size.Width - Size.Width / 2, Size.Height * 2 + Size.Height / 2 + 15);
  196. Sort = true;
  197. _lockButton = new MirButton
  198. {
  199. Index = 250,
  200. Location = new Point(18, 76),
  201. Size = new Size(28, 25),
  202. Library = Libraries.Prguse,
  203. Parent = this,
  204. Enabled = false
  205. };
  206. _setRentalPeriodButton = new MirButton
  207. {
  208. Index = 7,
  209. Location = new Point(46, 76),
  210. Size = new Size(84, 28),
  211. Library = Libraries.Prguse3,
  212. Parent = this,
  213. Enabled = false
  214. };
  215. _confirmButton = new MirButton
  216. {
  217. Index = 10,
  218. Location = new Point(130, 76),
  219. Size = new Size(58, 28),
  220. Library = Libraries.Prguse3,
  221. Parent = this,
  222. Enabled = false
  223. };
  224. _nameLabel = new MirLabel
  225. {
  226. Parent = this,
  227. Location = new Point(30, 8),
  228. Size = new Size(150, 14),
  229. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  230. NotControl = true,
  231. };
  232. _rentalPeriodLabel = new MirLabel
  233. {
  234. Parent = this,
  235. Location = new Point(60, 42),
  236. Size = new Size(150, 14),
  237. DrawFormat = TextFormatFlags.Left | TextFormatFlags.VerticalCenter,
  238. NotControl = true,
  239. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.RentalPeriodZeroDays)
  240. };
  241. _guestItemCell = new MirItemCell
  242. {
  243. BorderColour = Color.Lime,
  244. GridType = MirGridType.GuestRenting,
  245. Library = Libraries.Items,
  246. Parent = this,
  247. Location = new Point(16, 35),
  248. ItemSlot = 0,
  249. };
  250. }
  251. public void RefreshInterface()
  252. {
  253. _nameLabel.Text = _guestName;
  254. _rentalPeriodLabel.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.RentalPeriodDays), GuestRentalPeriod);
  255. if (GuestLoanItem != null)
  256. GameScene.Bind(GuestLoanItem);
  257. Redraw();
  258. }
  259. public void Reset()
  260. {
  261. Unlock();
  262. GuestLoanItem = null;
  263. _guestName = string.Empty;
  264. Hide();
  265. }
  266. public void SetGuestName(string name)
  267. {
  268. _guestName = name;
  269. }
  270. public void Lock()
  271. {
  272. _lockButton.Index = 253;
  273. RefreshInterface();
  274. }
  275. private void Unlock()
  276. {
  277. _lockButton.Index = 250;
  278. }
  279. }
  280. }