HeroDialogs.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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 HeroInventoryDialog : MirImageControl
  9. {
  10. public MirImageControl[] LockBar = new MirImageControl[4];
  11. public MirImageControl HPLockBar, MPLockBar;
  12. public MirItemCell[] Grid;
  13. public MirButton HPButton, MPButton;
  14. public MirLabel AutoHPPercentLabel, AutoMPPercentLabel;
  15. public MirItemCell HPItem, MPItem;
  16. private bool AutoPot => GameScene.Hero.AutoPot;
  17. private uint AutoHPPercent => GameScene.Hero.AutoHPPercent;
  18. private uint AutoMPPercent => GameScene.Hero.AutoMPPercent;
  19. public MirButton CloseButton;
  20. public HeroInventoryDialog()
  21. {
  22. Index = 1422;
  23. Library = Libraries.Prguse;
  24. Movable = true;
  25. Sort = true;
  26. Visible = false;
  27. CloseButton = new MirButton
  28. {
  29. HoverIndex = 361,
  30. Index = 360,
  31. Location = new Point(299, 2),
  32. Library = Libraries.Prguse2,
  33. Parent = this,
  34. PressedIndex = 362,
  35. Sound = SoundList.ButtonA,
  36. };
  37. CloseButton.Click += (o, e) => Hide();
  38. Grid = new MirItemCell[8 * 5];
  39. for (int x = 0; x < 8; x++)
  40. {
  41. for (int y = 0; y < 5; y++)
  42. {
  43. int idx = 8 * y + x;
  44. Grid[idx] = new MirItemCell
  45. {
  46. ItemSlot = 2 + idx,
  47. GridType = MirGridType.HeroInventory,
  48. Library = Libraries.Items,
  49. Parent = this,
  50. Location = new Point(x * 36 + 14 + x, y % 5 * 32 + 23 + y % 5),
  51. };
  52. if (idx >= 40)
  53. Grid[idx].Visible = false;
  54. }
  55. }
  56. for (int i = 0; i < LockBar.Length; i++)
  57. {
  58. LockBar[i] = new MirImageControl
  59. {
  60. Index = 1423,
  61. Library = Libraries.Prguse,
  62. Location = new Point(14, 56 + i * 33),
  63. Parent = this,
  64. DrawImage = true,
  65. NotControl = true,
  66. Visible = false,
  67. };
  68. }
  69. HPLockBar = new MirImageControl
  70. {
  71. Index = 1428,
  72. Library = Libraries.Prguse,
  73. Location = new Point(57, 196),
  74. Parent = this,
  75. DrawImage = true,
  76. NotControl = true,
  77. Visible = false,
  78. };
  79. MPLockBar = new MirImageControl
  80. {
  81. Index = 1429,
  82. Library = Libraries.Prguse,
  83. Location = new Point(162, 196),
  84. Parent = this,
  85. DrawImage = true,
  86. NotControl = true,
  87. Visible = false,
  88. };
  89. HPButton = new MirButton
  90. {
  91. Index = 560,
  92. HoverIndex = 561,
  93. PressedIndex = 562,
  94. Library = Libraries.Title,
  95. Location = new Point(58, Size.Height - 60),
  96. Parent = this,
  97. Size = new Size(60, 25),
  98. Sound = SoundList.ButtonA,
  99. Visible = false,
  100. };
  101. HPButton.Click += (o1, e) =>
  102. {
  103. MirAmountBox amountBox = new MirAmountBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EnterValue), 116, 99);
  104. amountBox.OKButton.Click += (o, a) => Network.Enqueue(new C.SetAutoPotValue { Stat = Stat.HP, Value = amountBox.Amount });
  105. amountBox.Show();
  106. };
  107. MPButton = new MirButton
  108. {
  109. Index = 563,
  110. HoverIndex = 564,
  111. PressedIndex = 565,
  112. Library = Libraries.Title,
  113. Location = new Point(206, Size.Height - 60),
  114. Parent = this,
  115. Size = new Size(60, 25),
  116. Sound = SoundList.ButtonA,
  117. Visible = false,
  118. };
  119. MPButton.Click += (o1, e) =>
  120. {
  121. MirAmountBox amountBox = new MirAmountBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EnterValue), 116, 99);
  122. amountBox.OKButton.Click += (o, a) => Network.Enqueue(new C.SetAutoPotValue { Stat = Stat.MP, Value = amountBox.Amount });
  123. amountBox.Show();
  124. };
  125. AutoHPPercentLabel = new MirLabel
  126. {
  127. Parent = this,
  128. Location = new Point(HPButton.Location.X, HPButton.Location.Y + 27),
  129. AutoSize = false,
  130. Size = new Size(60, 25),
  131. DrawFormat = TextFormatFlags.HorizontalCenter,
  132. Visible = false
  133. };
  134. AutoMPPercentLabel = new MirLabel
  135. {
  136. Parent = this,
  137. Location = new Point(MPButton.Location.X, MPButton.Location.Y + 27),
  138. AutoSize = false,
  139. Size = new Size(60, 25),
  140. DrawFormat = TextFormatFlags.HorizontalCenter,
  141. Visible = false
  142. };
  143. HPItem = new MirItemCell
  144. {
  145. ItemSlot = 0,
  146. GridType = MirGridType.HeroHPItem,
  147. Library = Libraries.Items,
  148. Parent = this,
  149. Location = new Point(HPButton.Location.X + 64, HPButton.Location.Y + 5),
  150. Visible = false
  151. };
  152. MPItem = new MirItemCell
  153. {
  154. ItemSlot = 0,
  155. GridType = MirGridType.HeroMPItem,
  156. Library = Libraries.Items,
  157. Parent = this,
  158. Location = new Point(MPButton.Location.X - 40, MPButton.Location.Y + 5),
  159. Visible = false
  160. };
  161. RefreshInterface();
  162. }
  163. public void RefreshInterface()
  164. {
  165. foreach (MirItemCell grid in Grid)
  166. {
  167. grid.Enabled = grid.ItemSlot < GameScene.Hero.Inventory.Length;
  168. }
  169. for (int i = 0; i < LockBar.Length; i++)
  170. {
  171. LockBar[i].Visible = GameScene.Hero.Inventory.Length < 11 + 8 * i;
  172. }
  173. HPLockBar.Visible = !AutoPot;
  174. MPLockBar.Visible = !AutoPot;
  175. HPButton.Visible = AutoPot;
  176. MPButton.Visible = AutoPot;
  177. AutoHPPercentLabel.Visible = AutoPot;
  178. AutoMPPercentLabel.Visible = AutoPot;
  179. HPItem.Visible = AutoPot;
  180. MPItem.Visible = AutoPot;
  181. AutoHPPercentLabel.Text = AutoHPPercent.ToString() + '%';
  182. AutoMPPercentLabel.Text = AutoMPPercent.ToString() + '%';
  183. }
  184. public MirItemCell GetCell(ulong id)
  185. {
  186. for (int i = 0; i < Grid.Length; i++)
  187. {
  188. if (Grid[i].Item == null || Grid[i].Item.UniqueID != id) continue;
  189. return Grid[i];
  190. }
  191. return null;
  192. }
  193. public void DisplayItemGridEffect(ulong id, int type = 0)
  194. {
  195. MirItemCell cell = GetCell(id);
  196. if (cell.Item == null) return;
  197. MirAnimatedControl animEffect = null;
  198. switch (type)
  199. {
  200. case 0:
  201. animEffect = new MirAnimatedControl
  202. {
  203. Animated = true,
  204. AnimationCount = 9,
  205. AnimationDelay = 150,
  206. Index = 410,
  207. Library = Libraries.Prguse,
  208. Location = cell.Location,
  209. Parent = this,
  210. Loop = false,
  211. NotControl = true,
  212. UseOffSet = true,
  213. Blending = true,
  214. BlendingRate = 1F
  215. };
  216. animEffect.AfterAnimation += (o, e) => animEffect.Dispose();
  217. SoundManager.PlaySound(20000 + (ushort)Spell.MagicShield * 10);
  218. break;
  219. }
  220. }
  221. }
  222. public sealed class HeroBeltDialog : MirImageControl
  223. {
  224. public MirLabel[] Key = new MirLabel[2];
  225. public MirButton CloseButton, RotateButton;
  226. public MirItemCell[] Grid;
  227. public HeroBeltDialog()
  228. {
  229. Index = 1921;
  230. Library = Libraries.Prguse;
  231. Movable = true;
  232. Sort = true;
  233. Visible = true;
  234. Location = new Point(GameScene.Scene.MainDialog.Location.X + 475, Settings.ScreenHeight - 150);
  235. BeforeDraw += BeltPanel_BeforeDraw;
  236. for (int i = 0; i < Key.Length; i++)
  237. {
  238. Key[i] = new MirLabel
  239. {
  240. Parent = this,
  241. Size = new Size(26, 14),
  242. Location = new Point(8 + i * 35, 2),
  243. Text = (i + 7).ToString()
  244. };
  245. }
  246. RotateButton = new MirButton
  247. {
  248. HoverIndex = 1927,
  249. Index = 1926,
  250. Location = new Point(82, 3),
  251. Library = Libraries.Prguse,
  252. Parent = this,
  253. PressedIndex = 1928,
  254. Sound = SoundList.ButtonA,
  255. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Rotate)
  256. };
  257. RotateButton.Click += (o, e) => Flip();
  258. CloseButton = new MirButton
  259. {
  260. HoverIndex = 1924,
  261. Index = 1923,
  262. Location = new Point(82, 19),
  263. Library = Libraries.Prguse,
  264. Parent = this,
  265. PressedIndex = 1925,
  266. Sound = SoundList.ButtonA,
  267. Hint = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.CloseKey), CMain.InputKeys.GetKey(KeybindOptions.Belt))
  268. };
  269. CloseButton.Click += (o, e) => Hide();
  270. Grid = new MirItemCell[2];
  271. for (int x = 0; x < 2; x++)
  272. {
  273. Grid[x] = new MirItemCell
  274. {
  275. ItemSlot = x,
  276. Size = new Size(32, 32),
  277. GridType = MirGridType.HeroInventory,
  278. Library = Libraries.Items,
  279. Parent = this,
  280. Location = new Point(x * 35 + 12, 3),
  281. };
  282. }
  283. }
  284. private void BeltPanel_BeforeDraw(object sender, EventArgs e)
  285. {
  286. //if Transparent return
  287. if (Libraries.Prguse != null)
  288. Libraries.Prguse.Draw(Index == 1921 ? 1934 : 1946, DisplayLocation, Color.White, false, 0.5F);
  289. }
  290. public void Flip()
  291. {
  292. //0,70 LOCATION
  293. if (Index == 1921)
  294. {
  295. Index = 1943;
  296. Location = new Point(0, 446);
  297. for (int x = 0; x < 2; x++)
  298. Grid[x].Location = new Point(3, x * 35 + 12);
  299. CloseButton.Index = 1935;
  300. CloseButton.HoverIndex = 1936;
  301. CloseButton.Location = new Point(3, 82);
  302. CloseButton.PressedIndex = 1937;
  303. RotateButton.Index = 1938;
  304. RotateButton.HoverIndex = 1939;
  305. RotateButton.Location = new Point(19, 82);
  306. RotateButton.PressedIndex = 1940;
  307. }
  308. else
  309. {
  310. Index = 1921;
  311. Location = new Point(GameScene.Scene.MainDialog.Location.X + 475, Settings.ScreenHeight - 150);
  312. for (int x = 0; x < 2; x++)
  313. Grid[x].Location = new Point(x * 35 + 12, 3);
  314. CloseButton.Index = 1923;
  315. CloseButton.HoverIndex = 1924;
  316. CloseButton.Location = new Point(82, 19);
  317. CloseButton.PressedIndex = 1925;
  318. RotateButton.Index = 1926;
  319. RotateButton.HoverIndex = 1927;
  320. RotateButton.Location = new Point(82, 3);
  321. RotateButton.PressedIndex = 1928;
  322. }
  323. for (int i = 0; i < Key.Length; i++)
  324. {
  325. Key[i].Location = (Index != 1921) ? new Point(-1, 11 + i * 35) : new Point(8 + i * 35, 2);
  326. }
  327. }
  328. public MirItemCell GetCell(ulong id)
  329. {
  330. for (int i = 0; i < Grid.Length; i++)
  331. {
  332. if (Grid[i].Item == null || Grid[i].Item.UniqueID != id) continue;
  333. return Grid[i];
  334. }
  335. return null;
  336. }
  337. }
  338. public sealed class HeroMenuPanel : MirImageControl
  339. {
  340. public MirButton HeroMagicsButton, HeroInventoryButton, HeroEquipmentButton;
  341. public HeroMenuPanel(MirControl parent)
  342. {
  343. Index = 2179;
  344. Library = Libraries.Prguse;
  345. Size = new Size(24, 61);
  346. Parent = parent;
  347. Location = new Point(((Settings.ScreenWidth / 2) - (Size.Width / 2)) + 362, Settings.ScreenHeight - Size.Height - 77);
  348. HeroMagicsButton = new MirButton
  349. {
  350. Index = 2173,
  351. HoverIndex = 2174,
  352. PressedIndex = 2175,
  353. Library = Libraries.Prguse,
  354. Parent = this,
  355. Size = new Size(16, 16),
  356. Location = new Point(3, 3),
  357. Hint = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.HeroSkills), CMain.InputKeys.GetKey(KeybindOptions.HeroSkills))
  358. };
  359. HeroMagicsButton.Click += (o, e) =>
  360. {
  361. if (GameScene.Scene.HeroDialog.Visible && GameScene.Scene.HeroDialog.SkillPage.Visible)
  362. GameScene.Scene.HeroDialog.Hide();
  363. else
  364. {
  365. GameScene.Scene.HeroDialog.Show();
  366. GameScene.Scene.HeroDialog.ShowSkillPage();
  367. }
  368. };
  369. HeroInventoryButton = new MirButton
  370. {
  371. Index = 2170,
  372. HoverIndex = 2171,
  373. PressedIndex = 2172,
  374. Library = Libraries.Prguse,
  375. Parent = this,
  376. Size = new Size(16, 16),
  377. Location = new Point(3, 20),
  378. Hint = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.HeroInventory), CMain.InputKeys.GetKey(KeybindOptions.HeroInventory))
  379. };
  380. HeroInventoryButton.Click += (o, e) =>
  381. {
  382. GameScene.Scene.HeroInventoryDialog.Visible = !GameScene.Scene.HeroInventoryDialog.Visible;
  383. };
  384. HeroEquipmentButton = new MirButton
  385. {
  386. Index = 2176,
  387. HoverIndex = 2177,
  388. PressedIndex = 2178,
  389. Library = Libraries.Prguse,
  390. Parent = this,
  391. Size = new Size(16, 16),
  392. Location = new Point(3, 37),
  393. Hint = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.HeroCharacter), CMain.InputKeys.GetKey(KeybindOptions.HeroEquipment))
  394. };
  395. HeroEquipmentButton.Click += (o, e) =>
  396. {
  397. if (GameScene.Scene.HeroDialog.Visible && GameScene.Scene.HeroDialog.CharacterPage.Visible)
  398. GameScene.Scene.HeroDialog.Hide();
  399. else
  400. {
  401. GameScene.Scene.HeroDialog.Show();
  402. GameScene.Scene.HeroDialog.ShowCharacterPage();
  403. }
  404. };
  405. }
  406. public void Toggle()
  407. {
  408. Visible = !Visible;
  409. }
  410. }
  411. public sealed class HeroInfoPanel : MirImageControl
  412. {
  413. private MirImageControl Avatar, NameContainer, HealthContainer, HealthBar, ManaBar, ExperienceBar, DangerAvatar, DeadAvatar;
  414. private MirLabel NameLabel, LevelLabel, Hplabel, Mplabel, ExLabel;
  415. private DateTime NextAvatarChange;
  416. private HeroAutoPotPreview HPItem, MPItem;
  417. private string Name => GameScene.Hero.Name;
  418. private int Level => GameScene.Hero.Level;
  419. private MirClass Class => GameScene.Hero.Class;
  420. private MirGender Gender => GameScene.Hero.Gender;
  421. private long Experience => GameScene.Hero.Experience;
  422. private long MaxExperience => GameScene.Hero.MaxExperience;
  423. private byte PercentHealth => GameScene.Hero.PercentHealth;
  424. private byte PercentMana => GameScene.Hero.PercentMana;
  425. private bool Dead => GameScene.Scene.HeroSpawnState == HeroSpawnState.Dead;
  426. public HeroInfoPanel()
  427. {
  428. Index = 14;
  429. Library = Libraries.Prguse;
  430. Location = new Point(95, 48);
  431. Avatar = new MirImageControl
  432. {
  433. Index = 1400,
  434. Library = Libraries.Prguse,
  435. Location = new Point(14, 19),
  436. Parent = this,
  437. Visible = true
  438. };
  439. Avatar.BeforeDraw += Avatar_BeforeDraw;
  440. DangerAvatar = new MirImageControl
  441. {
  442. Index = 1750,
  443. Library = Libraries.Prguse,
  444. Location = new Point(14, 19),
  445. Parent = this,
  446. Visible = false
  447. };
  448. DeadAvatar = new MirImageControl
  449. {
  450. Index = 1379,
  451. Library = Libraries.Prguse,
  452. Location = new Point(14, 19),
  453. Parent = this,
  454. Visible = false
  455. };
  456. NameContainer = new MirImageControl
  457. {
  458. Index = 10,
  459. Library = Libraries.Prguse,
  460. Location = new Point(26, 60),
  461. Parent = this,
  462. Visible = true
  463. };
  464. LevelLabel = new MirLabel
  465. {
  466. AutoSize = false,
  467. Size = new Size(17, 14),
  468. Location = new Point(3, -1),
  469. DrawFormat = TextFormatFlags.HorizontalCenter,
  470. Parent = NameContainer,
  471. };
  472. NameLabel = new MirLabel
  473. {
  474. AutoSize = false,
  475. Size = new Size(97, 14),
  476. Location = new Point(2, 14),
  477. DrawFormat = TextFormatFlags.HorizontalCenter,
  478. Parent = NameContainer,
  479. };
  480. HealthContainer = new MirImageControl
  481. {
  482. Index = 11,
  483. Library = Libraries.Prguse,
  484. Location = new Point(57, 26),
  485. Parent = this,
  486. Visible = true
  487. };
  488. HealthBar = new MirImageControl
  489. {
  490. Index = 1951,
  491. Library = Libraries.Prguse,
  492. Location = new Point(18, 6),
  493. Parent = HealthContainer,
  494. Visible = true,
  495. DrawImage = false,
  496. NotControl = true
  497. };
  498. HealthBar.BeforeDraw += HealthBar_BeforeDraw;
  499. Hplabel = new MirLabel
  500. {
  501. AutoSize = false,
  502. Size = new Size(55, 18),
  503. Location = new Point(71, 28),
  504. DrawFormat = TextFormatFlags.Default,
  505. Parent = this,
  506. };
  507. ManaBar = new MirImageControl
  508. {
  509. Index = 1952,
  510. Library = Libraries.Prguse,
  511. Location = new Point(18, 19),
  512. Parent = HealthContainer,
  513. Visible = true,
  514. DrawImage = false,
  515. NotControl = true
  516. };
  517. ManaBar.BeforeDraw += ManaBar_BeforeDraw;
  518. Mplabel = new MirLabel
  519. {
  520. AutoSize = false,
  521. Size = new Size(55, 18),
  522. Location = new Point(71, 41),
  523. DrawFormat = TextFormatFlags.Default,
  524. Parent = this,
  525. };
  526. ExperienceBar = new MirImageControl
  527. {
  528. Index = 1953,
  529. Library = Libraries.Prguse,
  530. Location = new Point(18, 32),
  531. Parent = HealthContainer,
  532. Visible = true,
  533. DrawImage = false,
  534. NotControl = true
  535. };
  536. ExperienceBar.BeforeDraw += ExperienceBar_BeforeDraw;
  537. ExLabel = new MirLabel
  538. {
  539. AutoSize = false,
  540. Size = new Size(65, 18),
  541. Location = new Point(71, 54),
  542. DrawFormat = TextFormatFlags.Default,
  543. Parent = this,
  544. };
  545. HPItem = new HeroAutoPotPreview()
  546. {
  547. Parent = this,
  548. Location = new Point(86, 5),
  549. GetInfo = () => { return GameScene.Hero?.HPItem[0]?.Info; }
  550. };
  551. MPItem = new HeroAutoPotPreview()
  552. {
  553. Parent = this,
  554. Location = new Point(106, 5),
  555. GetInfo = () => { return GameScene.Hero?.MPItem[0]?.Info; }
  556. };
  557. }
  558. public void Update()
  559. {
  560. Avatar.Index = GameScene.Scene.HeroAvatar(Class, Gender);
  561. DangerAvatar.Index = Avatar.Index + 350;
  562. NameLabel.Text = Name;
  563. LevelLabel.Text = Level.ToString();
  564. }
  565. private void Avatar_BeforeDraw(object sender, EventArgs e)
  566. {
  567. DeadAvatar.Visible = Dead;
  568. if (PercentHealth > 20)
  569. {
  570. DangerAvatar.Visible = false;
  571. return;
  572. }
  573. if (CMain.Now < NextAvatarChange) return;
  574. NextAvatarChange = CMain.Now.AddMilliseconds(400);
  575. DangerAvatar.Visible = !DangerAvatar.Visible;
  576. }
  577. private void ExperienceBar_BeforeDraw(object sender, EventArgs e)
  578. {
  579. if (ExperienceBar.Library == null) return;
  580. //cast MaxExperience to double to force division to 2 decimal place
  581. double percent = Experience / (double)MaxExperience * 100;
  582. int sectionWidth = (int)(ExperienceBar.Size.Width * (percent / 100));
  583. Rectangle section = new Rectangle
  584. {
  585. Size = new Size(sectionWidth, ExperienceBar.Size.Height)
  586. };
  587. ExperienceBar.Library.Draw(ExperienceBar.Index, section, ExperienceBar.DisplayLocation, Color.White, false);
  588. ExLabel.Text = string.Format("{0:F2}%", percent);
  589. }
  590. private void HealthBar_BeforeDraw(object sender, EventArgs e)
  591. {
  592. if (HealthBar.Library == null) return;
  593. double percent = PercentHealth / 100F;
  594. if (percent > 1) percent = 1;
  595. if (percent <= 0) return;
  596. Rectangle section = new Rectangle
  597. {
  598. Size = new Size((int)(HealthBar.Size.Width * percent), HealthBar.Size.Height)
  599. };
  600. HealthBar.Library.Draw(HealthBar.Index, section, HealthBar.DisplayLocation, Color.White, false);
  601. Hplabel.Text = GameScene.Hero?.HP.ToString() + "/" + GameScene.Hero?.Stats[Stat.HP].ToString();
  602. }
  603. private void ManaBar_BeforeDraw(object sender, EventArgs e)
  604. {
  605. if (ManaBar.Library == null) return;
  606. double percent = PercentMana / 100F;
  607. if (percent > 1) percent = 1;
  608. if (percent <= 0) return;
  609. Rectangle section = new Rectangle
  610. {
  611. Size = new Size((int)(ManaBar.Size.Width * percent), ManaBar.Size.Height)
  612. };
  613. ManaBar.Library.Draw(ManaBar.Index, section, ManaBar.DisplayLocation, Color.White, false);
  614. Mplabel.Text = GameScene.Hero?.MP.ToString() + "/" + GameScene.Hero?.Stats[Stat.MP].ToString();
  615. }
  616. }
  617. public sealed class HeroAutoPotPreview : MirImageControl
  618. {
  619. public Func<ItemInfo> GetInfo;
  620. private ItemInfo Info => GetInfo();
  621. public MirLabel AmountLabel;
  622. public HeroAutoPotPreview()
  623. {
  624. Index = 1392;
  625. Library = Libraries.Prguse;
  626. NotControl = true;
  627. AutoSize = false;
  628. Size = new Size(19, 15);
  629. AmountLabel = new MirLabel
  630. {
  631. Parent = this,
  632. Location = new Point(0, 6),
  633. AutoSize = false,
  634. Size = new Size(22, 17),
  635. DrawFormat = TextFormatFlags.Right,
  636. ForeColour = Color.Yellow,
  637. Visible = false
  638. };
  639. AfterDraw += AutoPotPreview_AfterDraw;
  640. }
  641. void AutoPotPreview_AfterDraw(object sender, EventArgs e)
  642. {
  643. AmountLabel.Visible = Info != null;
  644. if (Info == null) return;
  645. AmountLabel.Text = CountItem(Info).ToString();
  646. Libraries.Items.Draw(Info.Image, DisplayLocation.Add(2, 3), Size, Color.White);
  647. AmountLabel.Draw();
  648. }
  649. int CountItem(ItemInfo info)
  650. {
  651. var count = 0;
  652. if (GameScene.Hero == null) return count;
  653. for (int i = 0; i < GameScene.Hero.Inventory.Length; i++)
  654. {
  655. UserItem item = GameScene.Hero.Inventory[i];
  656. if (item == null) continue;
  657. if (item.Info.Index != info.Index) continue;
  658. count += item.Count;
  659. }
  660. return count;
  661. }
  662. }
  663. public sealed class HeroBehaviourPanel : MirImageControl
  664. {
  665. private MirButton[] BehaviourButtons;
  666. public HeroBehaviourPanel()
  667. {
  668. AutoSize = false;
  669. Size = new Size(64, 17);
  670. DrawImage = false;
  671. Location = new Point(GameScene.Scene.MainDialog.Location.X + 165, GameScene.Scene.MainDialog.Location.Y + 37);
  672. BehaviourButtons = new MirButton[4];
  673. for (int i = 0; i < BehaviourButtons.Length; i++)
  674. {
  675. HeroBehaviour hb = (HeroBehaviour)i;
  676. BehaviourButtons[i] = new MirButton
  677. {
  678. Index = 1840 + i,
  679. DisabledIndex = 1844 + i,
  680. Location = new Point(16 * i, 0),
  681. Library = Libraries.Prguse,
  682. Parent = this,
  683. Sound = SoundList.ButtonA,
  684. Hint = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.HeroBehaviourFormat), Enum.Parse<HeroBehaviour>(i.ToString()).ToLocalizedString()),
  685. AllowDisabledMouseOver = true
  686. };
  687. BehaviourButtons[i].Click += (o, e) =>
  688. {
  689. SetBehaviour(hb);
  690. };
  691. }
  692. }
  693. private void SetBehaviour(HeroBehaviour behaviour)
  694. {
  695. Network.Enqueue(new C.SetHeroBehaviour { Behaviour = behaviour });
  696. }
  697. public void UpdateBehaviour(HeroBehaviour behaviour)
  698. {
  699. for (int i = 0; i < BehaviourButtons.Length; i++)
  700. BehaviourButtons[i].Enabled = (byte)behaviour != i;
  701. }
  702. }
  703. public sealed class HeroManageDialog : MirImageControl
  704. {
  705. public HeroManageAvatar CurrentAvatar;
  706. public HeroManageAvatar[] Avatars = new HeroManageAvatar[8];
  707. public MirButton CloseButton;
  708. public HeroManageDialog()
  709. {
  710. Index = 1688;
  711. Library = Libraries.Prguse;
  712. Movable = true;
  713. Sort = true;
  714. Location = new Point(350, 350);
  715. CloseButton = new MirButton
  716. {
  717. HoverIndex = 361,
  718. Index = 360,
  719. Location = new Point(Size.Width - 24, 4),
  720. Library = Libraries.Prguse2,
  721. Parent = this,
  722. PressedIndex = 362,
  723. Sound = SoundList.ButtonA,
  724. };
  725. CloseButton.Click += (o, e) => Hide();
  726. CurrentAvatar = new HeroManageAvatar() { Parent = this };
  727. for (int i = 0; i < Avatars.Length; i++)
  728. {
  729. int index = i;
  730. Avatars[i] = new HeroManageAvatar() { Parent = this };
  731. Avatars[i].Click += (o, e) =>
  732. {
  733. MirMessageBox messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.MakeActiveHero), Avatars[index].Info.Name), MirMessageBoxButtons.YesNo);
  734. messageBox.YesButton.Click += (o, e) => Network.Enqueue(new C.ChangeHero { ListIndex = index + 1 });
  735. messageBox.Show();
  736. };
  737. }
  738. }
  739. public void RefreshInterface()
  740. {
  741. for (int i = 0; i < Avatars.Length; i++)
  742. {
  743. Avatars[i].Location = new Point(98 + 60 * (i % 4), 61 + 40 * (int)(i / 4));
  744. if (i > GameScene.MaximumHeroCount - 2)
  745. {
  746. Avatars[i].Info = null;
  747. Avatars[i].Visible = i > GameScene.MaximumHeroCount - 2;
  748. Avatars[i].NotControl = true;
  749. continue;
  750. }
  751. Avatars[i].Info = GameScene.HeroStorage[i];
  752. Avatars[i].Visible = GameScene.HeroStorage[i] != null;
  753. Avatars[i].NotControl = false;
  754. }
  755. }
  756. public void SetCurrentHero(ClientHeroInformation hero)
  757. {
  758. CurrentAvatar.Location = new Point(15, 61);
  759. CurrentAvatar.Info = hero;
  760. }
  761. public override void Show()
  762. {
  763. RefreshInterface();
  764. base.Show();
  765. }
  766. }
  767. public sealed class HeroManageAvatar : MirImageControl
  768. {
  769. const int DefaultIndex = 1689;
  770. private ClientHeroInformation info;
  771. public ClientHeroInformation Info
  772. {
  773. get { return info; }
  774. set
  775. {
  776. info = value;
  777. if (info == null)
  778. {
  779. Visible = false;
  780. }
  781. else
  782. {
  783. Location = new Point(Location.X + 5, Location.Y + 5);
  784. Index = GameScene.Scene.HeroAvatar(info.Class, info.Gender) + 370;
  785. Hint = info.ToString();
  786. Visible = true;
  787. }
  788. }
  789. }
  790. public HeroManageAvatar()
  791. {
  792. Index = DefaultIndex;
  793. Library = Libraries.Prguse;
  794. }
  795. }
  796. }