MountDialog.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirNetwork;
  4. using Client.MirObjects;
  5. using Client.MirSounds;
  6. using C = ClientPackets;
  7. namespace Client.MirScenes.Dialogs
  8. {
  9. public sealed class MountDialog : MirImageControl
  10. {
  11. public MirLabel MountName, MountLoyalty;
  12. public MirButton CloseButton, MountButton, HelpButton;
  13. private MirAnimatedControl MountImage;
  14. public MirItemCell[] Grid;
  15. public int StartIndex = 0;
  16. public MountDialog()
  17. {
  18. Index = 167;
  19. Library = Libraries.Prguse;
  20. Movable = true;
  21. Sort = true;
  22. Location = new Point(10, 30);
  23. BeforeDraw += MountDialog_BeforeDraw;
  24. MountName = new MirLabel
  25. {
  26. Location = new Point(30, 10),
  27. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  28. Parent = this,
  29. NotControl = true,
  30. };
  31. MountLoyalty = new MirLabel
  32. {
  33. Location = new Point(30, 30),
  34. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  35. Parent = this,
  36. NotControl = true,
  37. };
  38. MountButton = new MirButton
  39. {
  40. Library = Libraries.Prguse,
  41. Parent = this,
  42. Sound = SoundList.ButtonA,
  43. Location = new Point(262, 70)
  44. };
  45. MountButton.Click += (o, e) =>
  46. {
  47. if (CanRide())
  48. {
  49. Ride();
  50. }
  51. };
  52. CloseButton = new MirButton
  53. {
  54. HoverIndex = 361,
  55. Index = 360,
  56. Library = Libraries.Prguse2,
  57. Parent = this,
  58. PressedIndex = 362,
  59. Sound = SoundList.ButtonA,
  60. };
  61. CloseButton.Click += (o, e) => Hide();
  62. HelpButton = new MirButton
  63. {
  64. Index = 257,
  65. HoverIndex = 258,
  66. PressedIndex = 259,
  67. Library = Libraries.Prguse2,
  68. Parent = this,
  69. Sound = SoundList.ButtonA,
  70. };
  71. HelpButton.Click += (o, e) => GameScene.Scene.HelpDialog.DisplayPage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Mounts));
  72. MountImage = new MirAnimatedControl
  73. {
  74. Animated = false,
  75. AnimationCount = 16,
  76. AnimationDelay = 100,
  77. Index = 0,
  78. Library = Libraries.Prguse,
  79. Loop = true,
  80. Parent = this,
  81. NotControl = true,
  82. UseOffSet = true
  83. };
  84. Grid = new MirItemCell[Enum.GetNames(typeof(MountSlot)).Length];
  85. Grid[(int)MountSlot.Reins] = new MirItemCell
  86. {
  87. ItemSlot = (int)MountSlot.Reins,
  88. GridType = MirGridType.Mount,
  89. Parent = this,
  90. Size = new Size(34, 30)
  91. };
  92. Grid[(int)MountSlot.Bells] = new MirItemCell
  93. {
  94. ItemSlot = (int)MountSlot.Bells,
  95. GridType = MirGridType.Mount,
  96. Parent = this,
  97. Size = new Size(34, 30)
  98. };
  99. Grid[(int)MountSlot.Saddle] = new MirItemCell
  100. {
  101. ItemSlot = (int)MountSlot.Saddle,
  102. GridType = MirGridType.Mount,
  103. Parent = this,
  104. Size = new Size(34, 30)
  105. };
  106. Grid[(int)MountSlot.Ribbon] = new MirItemCell
  107. {
  108. ItemSlot = (int)MountSlot.Ribbon,
  109. GridType = MirGridType.Mount,
  110. Parent = this,
  111. Size = new Size(34, 30)
  112. };
  113. Grid[(int)MountSlot.Mask] = new MirItemCell
  114. {
  115. ItemSlot = (int)MountSlot.Mask,
  116. GridType = MirGridType.Mount,
  117. Parent = this,
  118. Size = new Size(34, 30)
  119. };
  120. }
  121. void MountDialog_BeforeDraw(object sender, EventArgs e)
  122. {
  123. RefreshDialog();
  124. }
  125. public void RefreshDialog()
  126. {
  127. SwitchType();
  128. DrawMountAnimation();
  129. }
  130. private void SwitchType()
  131. {
  132. UserItem MountItem = GameScene.User.Equipment[(int)EquipmentSlot.Mount];
  133. UserItem[] MountSlots = null;
  134. if (MountItem != null)
  135. {
  136. MountSlots = MountItem.Slots;
  137. }
  138. if (MountSlots == null) return;
  139. int x = 0, y = 0;
  140. switch (MountSlots.Length)
  141. {
  142. case 4:
  143. Index = 160;
  144. StartIndex = 1170;
  145. MountName.Size = new Size(208, 15);
  146. MountLoyalty.Size = new Size(208, 15);
  147. MountImage.Location = new Point(110, 250);
  148. MountButton.Index = 164;
  149. MountButton.HoverIndex = 165;
  150. MountButton.PressedIndex = 166;
  151. MountButton.Location = new Point(210, 70);
  152. CloseButton.Location = new Point(245, 3);
  153. HelpButton.Location = new Point(221, 3);
  154. Grid[(int)MountSlot.Mask].Visible = false;
  155. x = 1; y = 1;
  156. break;
  157. case 5:
  158. Index = 167;
  159. StartIndex = 1330;
  160. MountName.Size = new Size(260, 15);
  161. MountLoyalty.Size = new Size(260, 15);
  162. MountImage.Location = new Point(0, 70);
  163. MountButton.Index = 155;
  164. MountButton.HoverIndex = 156;
  165. MountButton.PressedIndex = 157;
  166. MountButton.Location = new Point(262, 70);
  167. CloseButton.Location = new Point(297, 3);
  168. HelpButton.Location = new Point(274, 3);
  169. Grid[(int)MountSlot.Mask].Visible = true;
  170. x = 0; y = 0;
  171. break;
  172. }
  173. Grid[(int)MountSlot.Reins].Location = new Point(36 + x, 323 + y);
  174. Grid[(int)MountSlot.Bells].Location = new Point(90 + x, 323 + y);
  175. Grid[(int)MountSlot.Saddle].Location = new Point(144 + x, 323 + y);
  176. Grid[(int)MountSlot.Ribbon].Location = new Point(198 + x, 323 + y);
  177. Grid[(int)MountSlot.Mask].Location = new Point(252 + x, 323 + y);
  178. }
  179. private void DrawMountAnimation()
  180. {
  181. if (GameScene.User.MountType < 0)
  182. {
  183. MountImage.Index = 0;
  184. MountImage.Animated = false;
  185. }
  186. else
  187. {
  188. MountImage.Index = StartIndex + (GameScene.User.MountType * 20);
  189. MountImage.Animated = true;
  190. UserItem item = MapObject.User.Equipment[(int)EquipmentSlot.Mount];
  191. if (item != null)
  192. {
  193. MountName.Text = item.FriendlyName;
  194. MountLoyalty.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.LoyaltyProgress), item.CurrentDura, item.MaxDura);
  195. }
  196. }
  197. }
  198. public bool CanRide()
  199. {
  200. if (GameScene.User.MountType < 0 || GameScene.User.MountTime + 500 > CMain.Time) return false;
  201. if (GameScene.User.CurrentAction != MirAction.Standing && GameScene.User.CurrentAction != MirAction.MountStanding) return false;
  202. return true;
  203. }
  204. public void Ride()
  205. {
  206. Network.Enqueue(new C.Chat { Message = "@ride" });
  207. }
  208. public override void Show()
  209. {
  210. if (Visible) return;
  211. if (GameScene.User.MountType < 0)
  212. {
  213. MirMessageBox messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoMount), MirMessageBoxButtons.OK);
  214. messageBox.Show();
  215. return;
  216. }
  217. Visible = true;
  218. }
  219. public MirItemCell GetCell(ulong id)
  220. {
  221. for (int i = 0; i < Grid.Length; i++)
  222. {
  223. if (Grid[i].Item == null || Grid[i].Item.UniqueID != id) continue;
  224. return Grid[i];
  225. }
  226. return null;
  227. }
  228. }
  229. }