FishingDialog.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 FishingDialog : MirImageControl
  10. {
  11. public MirLabel TitleLabel;
  12. public MirButton CloseButton;
  13. public MirItemCell[] Grid;
  14. public MirControl FishingRod;
  15. public FishingDialog()
  16. {
  17. Index = 1340;
  18. Library = Libraries.Prguse;
  19. Movable = true;
  20. Sort = true;
  21. Location = Center;
  22. BeforeDraw += FishingDialog_BeforeDraw;
  23. TitleLabel = new MirLabel
  24. {
  25. Location = new Point(10, 4),
  26. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  27. Parent = this,
  28. NotControl = true,
  29. Size = new Size(180, 20),
  30. };
  31. FishingRod = new MirControl
  32. {
  33. Parent = this,
  34. Location = new Point(0, 30),
  35. NotControl = true,
  36. };
  37. FishingRod.BeforeDraw += FishingRod_BeforeDraw;
  38. CloseButton = new MirButton
  39. {
  40. HoverIndex = 361,
  41. Index = 360,
  42. Location = new Point(175, 3),
  43. Library = Libraries.Prguse2,
  44. Parent = this,
  45. PressedIndex = 362,
  46. Sound = SoundList.ButtonA,
  47. };
  48. CloseButton.Click += (o, e) => Hide();
  49. Grid = new MirItemCell[Enum.GetNames(typeof(FishingSlot)).Length];
  50. Grid[(int)FishingSlot.Hook] = new MirItemCell
  51. {
  52. ItemSlot = (int)FishingSlot.Hook,
  53. GridType = MirGridType.Fishing,
  54. Parent = this,
  55. Size = new Size(34, 30),
  56. Location = new Point(17, 203),
  57. };
  58. Grid[(int)FishingSlot.Float] = new MirItemCell
  59. {
  60. ItemSlot = (int)FishingSlot.Float,
  61. GridType = MirGridType.Fishing,
  62. Parent = this,
  63. Size = new Size(34, 30),
  64. Location = new Point(17, 241),
  65. };
  66. Grid[(int)FishingSlot.Bait] = new MirItemCell
  67. {
  68. ItemSlot = (int)FishingSlot.Bait,
  69. GridType = MirGridType.Fishing,
  70. Parent = this,
  71. Size = new Size(34, 30),
  72. Location = new Point(57, 241),
  73. };
  74. Grid[(int)FishingSlot.Finder] = new MirItemCell
  75. {
  76. ItemSlot = (int)FishingSlot.Finder,
  77. GridType = MirGridType.Fishing,
  78. Parent = this,
  79. Size = new Size(34, 30),
  80. Location = new Point(97, 241),
  81. };
  82. Grid[(int)FishingSlot.Reel] = new MirItemCell
  83. {
  84. ItemSlot = (int)FishingSlot.Reel,
  85. GridType = MirGridType.Fishing,
  86. Parent = this,
  87. Size = new Size(34, 30),
  88. Location = new Point(137, 241),
  89. };
  90. }
  91. void FishingDialog_BeforeDraw(object sender, EventArgs e)
  92. {
  93. UserItem item = MapObject.User.Equipment[(int)EquipmentSlot.Weapon];
  94. if (MapObject.User.HasFishingRod && item != null)
  95. {
  96. TitleLabel.Text = item.FriendlyName;
  97. }
  98. }
  99. void FishingRod_BeforeDraw(object sender, EventArgs e)
  100. {
  101. int FishingImage = 0;
  102. if (MapObject.User.HasFishingRod)
  103. {
  104. UserItem rod = MapObject.User.Equipment[(int)EquipmentSlot.Weapon];
  105. if (GameScene.User.Weapon == 49)
  106. FishingImage = 1333;
  107. else if (GameScene.User.Weapon == 50)
  108. FishingImage = 1335;
  109. if (rod != null && rod.Slots.Length >= 5 && rod.Slots[(int)FishingSlot.Hook] != null)
  110. {
  111. FishingImage++;
  112. }
  113. }
  114. Libraries.StateItems.Draw(FishingImage, new Point(Location.X + 10, Location.Y + 40), Color.White, false);
  115. }
  116. public override void Show()
  117. {
  118. if (Visible) return;
  119. if (!GameScene.User.HasFishingRod)
  120. {
  121. MirMessageBox messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoFishingRod), MirMessageBoxButtons.OK);
  122. messageBox.Show();
  123. return;
  124. }
  125. Visible = true;
  126. }
  127. public MirItemCell GetCell(ulong id)
  128. {
  129. for (int i = 0; i < Grid.Length; i++)
  130. {
  131. if (Grid[i].Item == null || Grid[i].Item.UniqueID != id) continue;
  132. return Grid[i];
  133. }
  134. return null;
  135. }
  136. }
  137. public sealed class FishingStatusDialog : MirImageControl
  138. {
  139. public MirImageControl TitleLabel, AutoCastBox, ESCTick, ESCExit, FishDisableButton;
  140. public MirControl ChanceBar, ProgressBar;
  141. public MirLabel ChanceLabel;
  142. public MirButton CloseButton, AutoCastButton, FishButton, ESCExitButton;
  143. public int ChancePercent = 0, ProgressPercent = 0;
  144. private bool _canAutoCast = false;
  145. private bool _autoCast = false;
  146. public bool bEscExit = false;
  147. public FishingStatusDialog()
  148. {
  149. Index = 1341;
  150. Library = Libraries.Prguse;
  151. Movable = true;
  152. Sort = true;
  153. Size = new Size(244, 128);
  154. Location = new Point((Settings.ScreenWidth - Size.Width) / 2, 300);
  155. BeforeDraw += FishingStatusDialog_BeforeDraw;
  156. ChanceBar = new MirControl
  157. {
  158. Parent = this,
  159. Location = new Point(14, 64),
  160. NotControl = true,
  161. };
  162. ChanceBar.BeforeDraw += ChanceBar_BeforeDraw;
  163. ChanceLabel = new MirLabel
  164. {
  165. Location = new Point(14, 62),
  166. Size = new Size(216, 12),
  167. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  168. Parent = this,
  169. NotControl = true,
  170. };
  171. ProgressBar = new MirControl
  172. {
  173. Parent = this,
  174. Location = new Point(14, 79),
  175. NotControl = true,
  176. };
  177. ProgressBar.BeforeDraw += ProgressBar_BeforeDraw;
  178. CloseButton = new MirButton
  179. {
  180. HoverIndex = 361,
  181. Index = 360,
  182. Location = new Point(216, 4),
  183. Library = Libraries.Prguse2,
  184. Parent = this,
  185. PressedIndex = 362,
  186. Sound = SoundList.ButtonA,
  187. };
  188. CloseButton.Click += (o, e) =>
  189. {
  190. Cancel();
  191. };
  192. FishDisableButton = new MirImageControl
  193. {
  194. Index = 149,
  195. Location = new Point(47, 95),
  196. Library = Libraries.Title,
  197. Parent = this,
  198. NotControl = true
  199. };
  200. FishButton = new MirAnimatedButton()
  201. {
  202. Animated = true,
  203. AnimationCount = 10,
  204. Loop = true,
  205. AnimationDelay = 130,
  206. Index = 170,
  207. PressedIndex = 142,
  208. Library = Libraries.Title,
  209. Parent = this,
  210. Location = new Point(47, 95),
  211. Sound = SoundList.ButtonA,
  212. Visible = false
  213. };
  214. FishButton.Click += (o, e) =>
  215. {
  216. Network.Enqueue(new C.FishingCast { CastOut = false });
  217. };
  218. AutoCastButton = new MirButton
  219. {
  220. Index = 180,
  221. HoverIndex = 181,
  222. PressedIndex = 182,
  223. Location = new Point(110, 95),
  224. Library = Libraries.Title,
  225. Parent = this,
  226. Sound = SoundList.ButtonA,
  227. };
  228. AutoCastButton.Click += (o, e) =>
  229. {
  230. if (_canAutoCast)
  231. {
  232. _autoCast = !_autoCast;
  233. //AutoCastTick.Visible = _autoCast;
  234. AutoCastBox.Index = _autoCast ? 1344 : 1343;
  235. Network.Enqueue(new C.FishingChangeAutocast { AutoCast = _autoCast });
  236. }
  237. };
  238. AutoCastBox = new MirImageControl
  239. {
  240. Index = 1343,
  241. Location = new Point(172, 95),
  242. Library = Libraries.Prguse,
  243. Parent = this
  244. };
  245. ESCExitButton = new MirButton
  246. {
  247. Index = 1346,
  248. HoverIndex = 1346,
  249. PressedIndex = 1346,
  250. Location = new Point(135, 41),
  251. Library = Libraries.Prguse,
  252. Parent = this,
  253. Sound = SoundList.ButtonA,
  254. };
  255. ESCExitButton.Click += (o, e) =>
  256. {
  257. bEscExit = !bEscExit;
  258. ESCTick.Visible = bEscExit;
  259. };
  260. ESCTick = new MirImageControl
  261. {
  262. Index = 1347,
  263. Location = new Point(135, 41),
  264. Library = Libraries.Prguse,
  265. Parent = this,
  266. Visible = false,
  267. NotControl = true,
  268. };
  269. ESCExit = new MirImageControl
  270. {
  271. Index = 45,
  272. Location = new Point(150, 40),
  273. Library = Libraries.Title,
  274. Parent = this,
  275. NotControl = true,
  276. };
  277. }
  278. void FishingStatusDialog_BeforeDraw(object sender, EventArgs e)
  279. {
  280. bool oldCanAutoCast = _canAutoCast;
  281. if (MapObject.User.HasFishingRod)
  282. {
  283. UserItem rod = MapObject.User.Equipment[(int)EquipmentSlot.Weapon];
  284. if (rod == null || rod.Slots.Length < 5 || rod.Slots[(int)FishingSlot.Reel] == null)
  285. {
  286. _canAutoCast = false;
  287. AutoCastBox.Visible = false;
  288. AutoCastButton.Visible = false;
  289. }
  290. else
  291. {
  292. _canAutoCast = true;
  293. AutoCastBox.Visible = true;
  294. AutoCastButton.Visible = true;
  295. }
  296. }
  297. if (_autoCast && !_canAutoCast)
  298. {
  299. _autoCast = false;
  300. Network.Enqueue(new C.FishingChangeAutocast { AutoCast = _autoCast });
  301. }
  302. }
  303. void ChanceBar_BeforeDraw(object sender, EventArgs e)
  304. {
  305. if (Libraries.Prguse == null) return;
  306. int width;
  307. width = (int)(2.16 * ChancePercent);
  308. if (width < 0) width = 0;
  309. if (width > 216) width = 216;
  310. Rectangle r = new Rectangle(0, 0, width, 12);
  311. Libraries.Prguse.Draw(1342, r, new Point(ChanceBar.DisplayLocation.X, ChanceBar.DisplayLocation.Y), Color.White, false);
  312. }
  313. void ProgressBar_BeforeDraw(object sender, EventArgs e)
  314. {
  315. if (Libraries.Prguse == null) return;
  316. int width;
  317. width = (int)(2.16 * ProgressPercent);
  318. if (width < 0) width = 0;
  319. if (width > 216) width = 216;
  320. Rectangle r = new Rectangle(0, 0, width, 8);
  321. Libraries.Prguse.Draw(1349, r, new Point(ProgressBar.DisplayLocation.X, ProgressBar.DisplayLocation.Y), Color.White, false);
  322. }
  323. public void Cancel()
  324. {
  325. if (Visible)
  326. Network.Enqueue(new C.FishingCast { CastOut = false });
  327. Hide();
  328. }
  329. }
  330. }