ItemRentalDialog.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirSounds;
  4. using System.Globalization;
  5. using Client.MirNetwork;
  6. using C = ClientPackets;
  7. namespace Client.MirScenes.Dialogs
  8. {
  9. public sealed class ItemRentalDialog : MirImageControl
  10. {
  11. private readonly ItemRow[] _itemRows = new ItemRow[3];
  12. private DateTime _lastRequestTime = CMain.Now;
  13. public ItemRentalDialog()
  14. {
  15. Index = 1;
  16. Library = Libraries.Prguse3;
  17. Movable = true;
  18. Size = new Size(400, 174);
  19. Location = new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2);
  20. Sort = true;
  21. // Title
  22. var windowTitle = new MirImageControl
  23. {
  24. Index = 0,
  25. Library = Libraries.Prguse3,
  26. Location = new Point(22, 8),
  27. Parent = this
  28. };
  29. // Rented Tab
  30. var rentedTabButton = new MirButton
  31. {
  32. Index = 2,
  33. HoverIndex = 2,
  34. Location = new Point(8, 32),
  35. Size = new Size(72, 23),
  36. Library = Libraries.Prguse3,
  37. Parent = this,
  38. PressedIndex = 2,
  39. Sound = SoundList.ButtonA,
  40. Enabled = false
  41. };
  42. // Borrowed Tab
  43. var borrowedTabButton = new MirButton
  44. {
  45. Index = 3,
  46. Location = new Point(81, 32),
  47. Size = new Size(84, 23),
  48. Library = Libraries.Prguse3,
  49. Parent = this,
  50. Sound = SoundList.ButtonA,
  51. Enabled = false
  52. };
  53. // Rent Item Button
  54. var rentItemButton = new MirButton
  55. {
  56. Index = 4,
  57. HoverIndex = 5,
  58. Location = new Point(295, 144),
  59. Size = new Size(85, 29),
  60. Library = Libraries.Prguse3,
  61. Parent = this,
  62. PressedIndex = 6,
  63. Sound = SoundList.ButtonA,
  64. };
  65. rentItemButton.Click += (o, e) =>
  66. {
  67. Network.Enqueue(new C.ItemRentalRequest());
  68. };
  69. // Close Button
  70. var closeButton = new MirButton
  71. {
  72. HoverIndex = 361,
  73. Index = 360,
  74. Location = new Point(375, 3),
  75. Library = Libraries.Prguse2,
  76. Parent = this,
  77. PressedIndex = 362,
  78. Sound = SoundList.ButtonA,
  79. };
  80. closeButton.Click += (o, e) => Toggle();
  81. // Item Rows
  82. for (var i = 0; i < _itemRows.Length; i++)
  83. {
  84. _itemRows[i] = new ItemRow
  85. {
  86. Parent = this,
  87. Location = new Point(0, 78 + i * 21),
  88. Size = new Size(383, 21)
  89. };
  90. }
  91. }
  92. public void Toggle()
  93. {
  94. Visible = !Visible;
  95. if (Visible)
  96. RequestRentedItems();
  97. }
  98. public void ReceiveRentedItems(List<ItemRentalInformation> rentedItems)
  99. {
  100. for (var i = 0; i < _itemRows.Length; i++)
  101. {
  102. _itemRows[i].Clear();
  103. if (i < rentedItems.Count && rentedItems[i] != null)
  104. _itemRows[i].Update(rentedItems[i].ItemName,
  105. rentedItems[i].RentingPlayerName,
  106. rentedItems[i].ItemReturnDate.ToString(CultureInfo.InvariantCulture));
  107. }
  108. }
  109. private void RequestRentedItems()
  110. {
  111. if (_lastRequestTime > CMain.Now)
  112. return;
  113. _lastRequestTime = CMain.Now.AddSeconds(60);
  114. Network.Enqueue(new ClientPackets.GetRentedItems());
  115. }
  116. private sealed class ItemRow : MirControl
  117. {
  118. private readonly MirLabel _itemNameLabel, _rentingPlayerLabel, _returnDateLabel;
  119. public ItemRow()
  120. {
  121. _itemNameLabel = new MirLabel
  122. {
  123. Size = new Size(128, 20),
  124. Location = new Point(5, 0),
  125. DrawFormat = TextFormatFlags.HorizontalCenter,
  126. Parent = this,
  127. NotControl = true,
  128. };
  129. _rentingPlayerLabel = new MirLabel
  130. {
  131. Size = new Size(128, 20),
  132. Location = new Point(137, 0),
  133. DrawFormat = TextFormatFlags.HorizontalCenter,
  134. Parent = this,
  135. NotControl = true,
  136. };
  137. _returnDateLabel = new MirLabel
  138. {
  139. Size = new Size(128, 20),
  140. Location = new Point(264, 0),
  141. DrawFormat = TextFormatFlags.HorizontalCenter,
  142. Parent = this,
  143. NotControl = true,
  144. };
  145. }
  146. public void Clear()
  147. {
  148. Visible = false;
  149. _itemNameLabel.Text = string.Empty;
  150. _rentingPlayerLabel.Text = string.Empty;
  151. _returnDateLabel.Text = string.Empty;
  152. }
  153. public void Update(string itemName, string rentingPlayerName, string returnDate)
  154. {
  155. _itemNameLabel.Text = itemName;
  156. _rentingPlayerLabel.Text = rentingPlayerName;
  157. _returnDateLabel.Text = returnDate;
  158. Visible = true;
  159. }
  160. }
  161. }
  162. }