IntelligentCreatureDialogs.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirNetwork;
  4. using Client.MirSounds;
  5. using System.Text.RegularExpressions;
  6. using C = ClientPackets;
  7. namespace Client.MirScenes.Dialogs
  8. {
  9. public sealed class IntelligentCreatureDialog : MirImageControl
  10. {
  11. public MirImageControl FullnessBG, FullnessFG, FullnessMin, FullnessNow;
  12. public MirImageControl PearlImage, BlackStoneImageBG, BlackStoneImageFG;
  13. public MirLabel CreatureName, CreatureDeadline, CreaturePearls, CreatureInfo, CreatureInfo1, CreatureInfo2, CreatureMaintainFoodBuff, HoverLabel;
  14. public MirButton CloseButton, HelpPetButton, CreatureRenameButton, SummonButton, DismissButton, ReleaseButton;
  15. public MirButton AutomaticModeButton, SemiAutoModeButton, OptionsMenuButton;
  16. public CreatureButton[] CreatureButtons;
  17. public int SelectedCreatureSlot = -1;
  18. public MirControl HoverLabelParent = null;
  19. private readonly Regex CreatureNameReg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinCharacterNameLength + "," + Globals.MaxCharacterNameLength + "}$");
  20. private MirAnimatedControl CreatureImage;
  21. public long SwitchAnimTime;
  22. public bool AnimSwitched = false;
  23. public bool AnimNeedSwitch = false;
  24. private const long blackstoneProduceTime = 10800;//3 hours in seconds
  25. private bool showing = false;
  26. public IntelligentCreatureDialog()
  27. {
  28. Index = 468;
  29. Library = Libraries.Title;
  30. Movable = true;
  31. Sort = true;
  32. Location = Center;
  33. BeforeDraw += IntelligentCreatureDialog_BeforeDraw;
  34. #region CreatureButtons
  35. CloseButton = new MirButton
  36. {
  37. HoverIndex = 361,
  38. Index = 360,
  39. Location = new Point(Size.Width - 25, 3),
  40. Library = Libraries.Prguse2,
  41. Parent = this,
  42. PressedIndex = 362,
  43. Sound = SoundList.ButtonA,
  44. };
  45. CloseButton.Click += (o, e) => Hide();
  46. HelpPetButton = new MirButton
  47. {
  48. HoverIndex = 258,
  49. Index = 257,
  50. Location = new Point(Size.Width - 48, 3),
  51. Library = Libraries.Prguse2,
  52. Parent = this,
  53. PressedIndex = 259,
  54. Sound = SoundList.ButtonA,
  55. };
  56. CreatureRenameButton = new MirButton
  57. {
  58. HoverIndex = 571,
  59. Index = 570,
  60. Location = new Point(344, 50),
  61. Library = Libraries.Title,
  62. Parent = this,
  63. PressedIndex = 572,
  64. Sound = SoundList.ButtonA,
  65. Visible = false,
  66. };
  67. CreatureRenameButton.Click += ButtonClick;
  68. SummonButton = new MirButton
  69. {
  70. Index = 576,
  71. HoverIndex = 577,
  72. PressedIndex = 578,
  73. Location = new Point(113, 217),
  74. Library = Libraries.Title,
  75. Parent = this,
  76. Sound = SoundList.ButtonA,
  77. };
  78. SummonButton.Click += ButtonClick;
  79. DismissButton = new MirButton//Dismiss the summoned pet
  80. {
  81. HoverIndex = 581,
  82. Index = 580,
  83. Location = new Point(113, 217),
  84. Library = Libraries.Title,
  85. Parent = this,
  86. PressedIndex = 582,
  87. Sound = SoundList.ButtonA,
  88. };
  89. DismissButton.Click += ButtonClick;
  90. ReleaseButton = new MirButton//Removes the selected pet
  91. {
  92. HoverIndex = 584,
  93. Index = 583,
  94. Location = new Point(255, 217),
  95. Library = Libraries.Title,
  96. Parent = this,
  97. PressedIndex = 585,
  98. Sound = SoundList.ButtonA,
  99. };
  100. ReleaseButton.Click += ButtonClick;
  101. OptionsMenuButton = new MirButton//Options
  102. {
  103. HoverIndex = 574,
  104. Index = 573,
  105. Location = new Point(375, 160),
  106. Library = Libraries.Title,
  107. Parent = this,
  108. PressedIndex = 575,
  109. Sound = SoundList.ButtonA,
  110. };
  111. OptionsMenuButton.Click += ButtonClick;
  112. AutomaticModeButton = new MirButton//image is wrongly translated should be "Auto" instaid of "Enable"
  113. {
  114. HoverIndex = 611,
  115. Index = 610,
  116. Location = new Point(375, 187),
  117. Library = Libraries.Title,
  118. Parent = this,
  119. PressedIndex = 612,
  120. Sound = SoundList.ButtonA,
  121. };
  122. AutomaticModeButton.Click += ButtonClick;
  123. SemiAutoModeButton = new MirButton//image is wrongly translated should be "SemiAuto" instaid of "Disable"
  124. {
  125. HoverIndex = 614,
  126. Index = 613,
  127. Location = new Point(375, 187),
  128. Library = Libraries.Title,
  129. Parent = this,
  130. PressedIndex = 615,
  131. Sound = SoundList.ButtonA,
  132. };
  133. SemiAutoModeButton.Click += ButtonClick;
  134. CreatureButtons = new CreatureButton[10];
  135. for (int i = 0; i < CreatureButtons.Length; i++)
  136. {
  137. int offsetX = i * 81;
  138. int offsetY = 259;
  139. if (i >= 5)
  140. {
  141. offsetX = (i - 5) * 81;
  142. offsetY += 40;
  143. }
  144. CreatureButtons[i] = new CreatureButton { idx = i, Parent = this, Visible = false, Location = new Point((44 + offsetX), offsetY) };
  145. }
  146. #endregion
  147. #region CreatureImage
  148. CreatureImage = new MirAnimatedControl
  149. {
  150. Animated = false,
  151. AnimationCount = 4,
  152. AnimationDelay = 250,
  153. Index = 0,
  154. Library = Libraries.Prguse2,
  155. Loop = true,
  156. Parent = this,
  157. NotControl = true,
  158. UseOffSet = true,
  159. Location = new Point(50, 110),
  160. };
  161. FullnessBG = new MirImageControl
  162. {
  163. Index = 530,
  164. Library = Libraries.Prguse2,
  165. Location = new Point(185, 129),
  166. Parent = this,
  167. NotControl = true,
  168. };
  169. FullnessBG.MouseEnter += Control_MouseEnter;
  170. FullnessBG.MouseLeave += Control_MouseLeave;
  171. FullnessFG = new MirImageControl
  172. {
  173. Index = 531,
  174. Library = Libraries.Prguse2,
  175. Location = new Point(185, 129),
  176. Parent = this,
  177. DrawImage = false,
  178. //NotControl = true,
  179. };
  180. FullnessFG.AfterDraw += FullnessForeGround_AfterDraw;
  181. FullnessFG.MouseEnter += Control_MouseEnter;
  182. FullnessFG.MouseLeave += Control_MouseLeave;
  183. FullnessMin = new MirImageControl
  184. {
  185. Index = 532,
  186. Library = Libraries.Prguse2,
  187. Location = new Point(179, 118),
  188. Parent = this,
  189. //Visible = false,
  190. //NotControl = true,
  191. };
  192. FullnessMin.MouseEnter += Control_MouseEnter;
  193. FullnessMin.MouseLeave += Control_MouseLeave;
  194. FullnessNow = new MirImageControl
  195. {
  196. Index = 533,
  197. Library = Libraries.Prguse2,
  198. Location = new Point(179, 143),
  199. Parent = this,
  200. //Visible = false,
  201. NotControl = true,
  202. };
  203. PearlImage = new MirImageControl
  204. {
  205. Index = 427,
  206. Library = Libraries.Prguse2,
  207. Location = new Point(29, 348),
  208. Parent = this,
  209. NotControl = true,
  210. };
  211. BlackStoneImageBG = new MirImageControl
  212. {
  213. Index = 428,
  214. Library = Libraries.Prguse2,
  215. Location = new Point(215, 348),
  216. Parent = this,
  217. Visible = true,
  218. NotControl = true,
  219. };
  220. BlackStoneImageBG.MouseEnter += Control_MouseEnter;
  221. BlackStoneImageBG.MouseLeave += Control_MouseLeave;
  222. BlackStoneImageFG = new MirImageControl
  223. {
  224. Index = 420,
  225. Library = Libraries.Prguse2,
  226. Location = new Point(242, 353),
  227. Parent = this,
  228. Visible = true,
  229. DrawImage = false,
  230. //NotControl = true,
  231. };
  232. BlackStoneImageFG.AfterDraw += BlackStoneImageFG_AfterDraw;
  233. BlackStoneImageFG.MouseEnter += Control_MouseEnter;
  234. BlackStoneImageFG.MouseLeave += Control_MouseLeave;
  235. #endregion
  236. #region CreatureLabels
  237. CreatureName = new MirLabel
  238. {
  239. Parent = this,
  240. Location = new Point(170, 50),
  241. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  242. Size = new Size(166, 21),
  243. NotControl = true,
  244. };
  245. CreatureDeadline = new MirLabel
  246. {
  247. Parent = this,
  248. Location = new Point(140, 85),
  249. DrawFormat = TextFormatFlags.VerticalCenter,
  250. Size = new Size(350, 21),
  251. NotControl = true,
  252. };
  253. CreaturePearls = new MirLabel
  254. {
  255. AutoSize = true,
  256. Parent = this,
  257. Location = new Point(53, 348),
  258. DrawFormat = TextFormatFlags.VerticalCenter,
  259. //Size = new Size(350, 21),
  260. Text = "0",
  261. NotControl = true,
  262. };
  263. CreatureInfo = new MirLabel
  264. {
  265. Parent = this,
  266. Location = new Point(19, 161),
  267. DrawFormat = TextFormatFlags.VerticalCenter,
  268. Size = new Size(350, 15),
  269. NotControl = true,
  270. };
  271. CreatureInfo1 = new MirLabel
  272. {
  273. Parent = this,
  274. Location = new Point(19, 176),
  275. DrawFormat = TextFormatFlags.VerticalCenter,
  276. Size = new Size(350, 15),
  277. NotControl = true,
  278. };
  279. CreatureInfo2 = new MirLabel
  280. {
  281. Parent = this,
  282. Location = new Point(19, 191),
  283. DrawFormat = TextFormatFlags.VerticalCenter,
  284. Size = new Size(350, 15),
  285. NotControl = true,
  286. };
  287. CreatureMaintainFoodBuff = new MirLabel
  288. {
  289. Parent = this,
  290. Location = new Point(25, 25),
  291. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  292. Size = new Size(166, 21),
  293. NotControl = true,
  294. Visible = false //FAR made invisible as position was wierd - not sure where it's meant to be displayed
  295. };
  296. HoverLabel = new MirLabel
  297. {
  298. Parent = this,
  299. Location = new Point(0, 0),
  300. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  301. Size = new Size(100, 15),
  302. NotControl = true,
  303. };
  304. #endregion
  305. }
  306. #region EventHandlers
  307. private void IntelligentCreatureDialog_BeforeDraw(object sender, EventArgs e)
  308. {
  309. RefreshDialog();
  310. }
  311. private void FullnessForeGround_AfterDraw(object sender, EventArgs e)
  312. {
  313. int selectedCreature = BeforeAfterDraw();
  314. if (selectedCreature < 0) return;
  315. double percent = GameScene.User.IntelligentCreatures[selectedCreature].Fullness / ((double)10000);
  316. if (percent > 1) percent = 1;
  317. if (percent <= 0)
  318. {
  319. FullnessNow.Location = new Point(179, 143);
  320. return;
  321. }
  322. if (HoverLabel.Visible && HoverLabelParent != null && HoverLabelParent == FullnessFG)
  323. HoverLabel.Text = GameScene.User.IntelligentCreatures[selectedCreature].Fullness.ToString() + " / 10000";
  324. Rectangle section = new Rectangle
  325. {
  326. Size = new Size((int)((FullnessFG.Size.Width) * percent), FullnessFG.Size.Height)
  327. };
  328. FullnessFG.Library.Draw(FullnessFG.Index, section, FullnessFG.DisplayLocation, Color.White, false);
  329. FullnessNow.Location = new Point(FullnessFG.Location.X + section.Size.Width - 8, FullnessNow.Location.Y);
  330. percent = GameScene.User.IntelligentCreatures[selectedCreature].CreatureRules.MinimalFullness / ((double)10000);
  331. Size size = new Size((int)((FullnessFG.Size.Width) * percent), FullnessFG.Size.Height);
  332. FullnessMin.Location = new Point(FullnessFG.Location.X + size.Width - 8, FullnessMin.Location.Y);
  333. }
  334. private void BlackStoneImageFG_AfterDraw(object sender, EventArgs e)
  335. {
  336. int selectedCreature = BeforeAfterDraw();
  337. if (selectedCreature < 0) return;
  338. double percent = GameScene.User.IntelligentCreatures[selectedCreature].BlackstoneTime / ((double)blackstoneProduceTime);
  339. if (percent > 1) percent = 1;
  340. if (percent <= 0) return;
  341. if (HoverLabel.Visible && HoverLabelParent != null && HoverLabelParent == BlackStoneImageFG)
  342. {
  343. if (GameScene.User.IntelligentCreatures[selectedCreature].CreatureRules.CanProduceBlackStone)
  344. HoverLabel.Text = string.Format("{0}", Functions.PrintTimeSpanFromSeconds(blackstoneProduceTime - GameScene.User.IntelligentCreatures[selectedCreature].BlackstoneTime));
  345. else
  346. HoverLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoProduction);
  347. }
  348. Rectangle section = new Rectangle
  349. {
  350. Size = new Size((int)((BlackStoneImageFG.Size.Width) * percent), BlackStoneImageFG.Size.Height)
  351. };
  352. BlackStoneImageFG.Library.Draw(BlackStoneImageFG.Index, section, BlackStoneImageFG.DisplayLocation, Color.White, false);
  353. }
  354. private void Control_MouseEnter(object sender, EventArgs e)
  355. {
  356. int selectedCreature = BeforeAfterDraw();
  357. if (selectedCreature < 0) return;
  358. if (sender == FullnessMin)
  359. {
  360. HoverLabel.Visible = true;
  361. HoverLabel.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.NeededBy), GameScene.User.IntelligentCreatures[selectedCreature].CreatureRules.MinimalFullness.ToString());
  362. HoverLabel.Size = new Size(150, 15);
  363. HoverLabel.Location = new Point((FullnessMin.Location.X + 8) - (HoverLabel.Size.Width / 2), FullnessFG.Location.Y - 18);
  364. }
  365. if (sender == FullnessFG || sender == FullnessBG)
  366. {
  367. HoverLabel.Visible = true;
  368. HoverLabel.Text = GameScene.User.IntelligentCreatures[selectedCreature].Fullness.ToString() + " / 10000";
  369. HoverLabel.Size = FullnessFG.Size;
  370. HoverLabel.Location = new Point(FullnessFG.Location.X, FullnessFG.Location.Y - 2);
  371. HoverLabelParent = FullnessFG;
  372. }
  373. if (sender == BlackStoneImageBG || sender == BlackStoneImageFG)
  374. {
  375. HoverLabel.Visible = true;
  376. HoverLabel.Text = string.Format("{0}", Functions.PrintTimeSpanFromSeconds(blackstoneProduceTime - GameScene.User.IntelligentCreatures[selectedCreature].BlackstoneTime));
  377. HoverLabel.Size = BlackStoneImageBG.Size;
  378. HoverLabel.Location = new Point(BlackStoneImageBG.Location.X + 5, BlackStoneImageBG.Location.Y - 2);
  379. HoverLabelParent = BlackStoneImageFG;
  380. }
  381. }
  382. private void Control_MouseLeave(object sender, EventArgs e)
  383. {
  384. HoverLabel.Text = "";
  385. HoverLabel.Visible = false;
  386. HoverLabel.Parent = this;
  387. HoverLabelParent = null;
  388. }
  389. private void ButtonClick(object sender, EventArgs e)
  390. {
  391. int selectedCreature = BeforeAfterDraw();
  392. if (selectedCreature < 0) return;
  393. bool needSummon = false, needDismiss = false, needRelease = false, needUpdate = false;
  394. if (sender == CreatureRenameButton)
  395. {
  396. MirInputBox inputBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PleaseEnterCreatureNewName));
  397. inputBox.InputTextBox.Text = GameScene.User.IntelligentCreatures[selectedCreature].CustomName;
  398. inputBox.OKButton.Click += (o1, e1) =>
  399. {
  400. if (!CreatureNameReg.IsMatch(inputBox.InputTextBox.Text))
  401. {
  402. MirMessageBox failedMessage = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.CreatureNameLengthRange), Globals.MinCharacterNameLength, Globals.MaxCharacterNameLength), MirMessageBoxButtons.OK);
  403. failedMessage.Show();
  404. }
  405. else
  406. {
  407. Update();//refresh changes
  408. GameScene.User.IntelligentCreatures[selectedCreature].CustomName = inputBox.InputTextBox.Text;
  409. Network.Enqueue(new C.UpdateIntelligentCreature { Creature = GameScene.User.IntelligentCreatures[selectedCreature] });
  410. inputBox.Dispose();
  411. }
  412. };
  413. inputBox.Show();
  414. CreatureRenameButton.Visible = false;
  415. return;
  416. }
  417. if (sender == SummonButton)
  418. {
  419. //if (GameScene.User.IntelligentCreatures[selectedCreature].Fullness == 0)
  420. //{
  421. // GameScene.Scene.ChatDialog.ReceiveChat((string.Format("Creature {0} is starving, revitalize first.", GameScene.User.IntelligentCreatures[selectedCreature].CustomName)), ChatType.System);
  422. //}
  423. needSummon = true;
  424. needUpdate = true;
  425. SummonButton.Enabled = false;
  426. DismissButton.Enabled = true;
  427. DismissButton.Visible = true;
  428. }
  429. if (sender == DismissButton)
  430. {
  431. needDismiss = true;
  432. needUpdate = true;
  433. SummonButton.Enabled = true;
  434. DismissButton.Enabled = false;
  435. DismissButton.Visible = false;
  436. }
  437. if (sender == ReleaseButton)
  438. {
  439. MirInputBox verificationBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EnterCreatureNameForVerification));
  440. verificationBox.OKButton.Click += (o1, e1) =>
  441. {
  442. if (String.Compare(verificationBox.InputTextBox.Text, GameScene.User.IntelligentCreatures[selectedCreature].CustomName, StringComparison.OrdinalIgnoreCase) != 0)
  443. {
  444. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.VerificationFailed), ChatType.System);
  445. }
  446. else
  447. {
  448. //clear all and get new info after server got update
  449. for (int i = 0; i < CreatureButtons.Length; i++) CreatureButtons[i].Clear();
  450. Hide();
  451. Network.Enqueue(new C.UpdateIntelligentCreature { Creature = GameScene.User.IntelligentCreatures[selectedCreature], ReleaseMe = true });
  452. }
  453. verificationBox.Dispose();
  454. };
  455. verificationBox.Show();
  456. return;
  457. }
  458. if (sender == SemiAutoModeButton)
  459. {
  460. //make sure rules allow Automatic Mode
  461. if (!GameScene.User.IntelligentCreatures[selectedCreature].CreatureRules.AutoPickupEnabled) return;
  462. //turn on automatic pickupmode
  463. SemiAutoModeButton.Visible = false;
  464. AutomaticModeButton.Visible = true;
  465. GameScene.User.IntelligentCreatures[selectedCreature].petMode = IntelligentCreaturePickupMode.Automatic;
  466. needUpdate = true;
  467. }
  468. if (sender == AutomaticModeButton)
  469. {
  470. //make sure rules allow SemiAutomatic Mode
  471. if (!GameScene.User.IntelligentCreatures[selectedCreature].CreatureRules.SemiAutoPickupEnabled) return;
  472. //turn on semiauto pickupmode
  473. AutomaticModeButton.Visible = false;
  474. SemiAutoModeButton.Visible = true;
  475. GameScene.User.IntelligentCreatures[selectedCreature].petMode = IntelligentCreaturePickupMode.SemiAutomatic;
  476. needUpdate = true;
  477. }
  478. if (sender == OptionsMenuButton)
  479. {
  480. //show ItemFilter
  481. if (!GameScene.Scene.IntelligentCreatureOptionsDialog.Visible) GameScene.Scene.IntelligentCreatureOptionsDialog.Show(GameScene.User.IntelligentCreatures[selectedCreature].Filter);
  482. if (!GameScene.Scene.IntelligentCreatureOptionsGradeDialog.Visible) GameScene.Scene.IntelligentCreatureOptionsGradeDialog.Show(GameScene.User.IntelligentCreatures[selectedCreature].Filter.PickupGrade);
  483. }
  484. if (needUpdate)
  485. {
  486. Update();//refresh changes
  487. Network.Enqueue(new C.UpdateIntelligentCreature { Creature = GameScene.User.IntelligentCreatures[selectedCreature], SummonMe = needSummon, UnSummonMe = needDismiss, ReleaseMe = needRelease });
  488. }
  489. }
  490. #endregion
  491. #region Process
  492. public void Update()
  493. {
  494. if (!Visible) return;
  495. RefreshDialog();
  496. }
  497. public void RefreshDialog()
  498. {
  499. RefreshInfo();
  500. RefreshUI();
  501. RefreshMode();
  502. BeforeAfterDraw();
  503. DrawCreatureAnimation();
  504. }
  505. private void RefreshInfo()
  506. {
  507. CreaturePearls.Text = GameScene.User.PearlCount.ToString();
  508. int SelectedButton = -1;
  509. for (int i = 0; i < CreatureButtons.Length; i++)
  510. {
  511. if (i >= GameScene.User.IntelligentCreatures.Count)
  512. {
  513. CreatureButtons[i].Clear();
  514. continue;
  515. }
  516. CreatureButtons[i].Visible = true;
  517. CreatureButtons[i].Update(GameScene.User.IntelligentCreatures[i], showing);
  518. //Check what creature is currently summoned if at all
  519. if (showing && GameScene.User.CreatureSummoned && CreatureButtons[i].PetType == GameScene.User.SummonedCreatureType) SelectedButton = i;
  520. }
  521. showing = false;
  522. if (SelectedButton < 0) return;
  523. CreatureButtons[SelectedButton].SelectButton();
  524. }
  525. private void RefreshUI()
  526. {
  527. bool error = false;
  528. int selectedCreature = -1;
  529. if (SelectedCreatureSlot < 0)
  530. {
  531. error = true;
  532. }
  533. else
  534. {
  535. selectedCreature = GetCreatureFromSlot(SelectedCreatureSlot);
  536. if (selectedCreature < 0) error = true;
  537. }
  538. if (error)
  539. {
  540. CreatureImage.Visible = false;
  541. CreatureName.Visible = false;
  542. CreatureDeadline.Visible = false;
  543. CreatureInfo.Visible = false;
  544. CreatureInfo1.Visible = false;
  545. CreatureInfo2.Visible = false;
  546. CreatureRenameButton.Enabled = false;
  547. SummonButton.Enabled = false;
  548. DismissButton.Enabled = false;
  549. DismissButton.Visible = false;
  550. ReleaseButton.Enabled = false;
  551. SemiAutoModeButton.Enabled = false;
  552. AutomaticModeButton.Enabled = false;
  553. OptionsMenuButton.Enabled = false;
  554. }
  555. else
  556. {
  557. CreatureImage.Visible = true;
  558. CreatureName.Visible = true;
  559. CreatureDeadline.Visible = true;
  560. CreatureInfo.Visible = true;
  561. CreatureInfo1.Visible = true;
  562. CreatureInfo2.Visible = true;
  563. CreatureRenameButton.Enabled = true;
  564. ReleaseButton.Enabled = true;
  565. OptionsMenuButton.Enabled = true;
  566. SemiAutoModeButton.Enabled = true;
  567. AutomaticModeButton.Enabled = true;
  568. //Check what creature is currently summoned
  569. if (GameScene.User.CreatureSummoned)
  570. {
  571. if (GameScene.User.IntelligentCreatures[selectedCreature].PetType == GameScene.User.SummonedCreatureType)
  572. {
  573. DismissButton.Enabled = true;
  574. DismissButton.Visible = true;
  575. ReleaseButton.Enabled = false;
  576. }
  577. else
  578. {
  579. SummonButton.Index = 593;
  580. SummonButton.HoverIndex = 594;
  581. SummonButton.PressedIndex = 595;
  582. SummonButton.Enabled = false;
  583. DismissButton.Enabled = false;
  584. DismissButton.Visible = false;
  585. }
  586. }
  587. else
  588. {
  589. DismissButton.Enabled = false;
  590. DismissButton.Visible = false;
  591. SummonButton.Index = 576;
  592. SummonButton.HoverIndex = 577;
  593. SummonButton.PressedIndex = 578;
  594. SummonButton.Enabled = true;
  595. }
  596. }
  597. }
  598. private void RefreshMode()
  599. {
  600. int selectedCreature = BeforeAfterDraw();
  601. if (selectedCreature < 0) return;
  602. if (GameScene.User.IntelligentCreatures[selectedCreature].petMode == IntelligentCreaturePickupMode.Automatic)
  603. {
  604. AutomaticModeButton.Visible = true;
  605. SemiAutoModeButton.Visible = false;
  606. }
  607. else
  608. {
  609. AutomaticModeButton.Visible = false;
  610. SemiAutoModeButton.Visible = true;
  611. }
  612. }
  613. public int BeforeAfterDraw()//No idea why.. but without this FullnessForeGround_AfterDraw wont work...
  614. {
  615. if (FullnessFG.Library == null) return -1;
  616. if (SelectedCreatureSlot < 0)
  617. {
  618. CreatureImage.Index = 0;
  619. CreatureImage.Animated = false;
  620. FullnessFG.Visible = false;
  621. FullnessMin.Visible = false;
  622. FullnessNow.Visible = false;
  623. return -1;
  624. }
  625. else
  626. {
  627. int selectedCreature = GetCreatureFromSlot(SelectedCreatureSlot);
  628. if (selectedCreature < 0)
  629. {
  630. CreatureImage.Index = 0;
  631. CreatureImage.Animated = false;
  632. FullnessFG.Visible = false;
  633. FullnessMin.Visible = false;
  634. FullnessNow.Visible = false;
  635. return -1;
  636. }
  637. FullnessFG.Visible = true;
  638. FullnessMin.Visible = true;
  639. FullnessNow.Visible = true;
  640. return selectedCreature;
  641. }
  642. }
  643. #region CreatureAnimation
  644. private void DrawCreatureAnimation()
  645. {
  646. int selectedCreature = BeforeAfterDraw();
  647. if (selectedCreature < 0) return;
  648. var rules = GameScene.User.IntelligentCreatures[selectedCreature].CreatureRules;
  649. var semi = rules.SemiAutoPickupEnabled ? string.Format("{0}x{0} {1}{2}{3}", rules.AutoPickupRange, rules.AutoPickupEnabled ? "auto/" : "", rules.SemiAutoPickupEnabled ? "semi-auto" : "", rules.MousePickupEnabled ? ", " : "") : "";
  650. var mouse = rules.SemiAutoPickupEnabled ? string.Format("{0}x{0} mouse", rules.MousePickupRange) : "";
  651. CreatureName.Text = GameScene.User.IntelligentCreatures[selectedCreature].CustomName;
  652. CreatureInfo.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.CanPickupItems), semi, mouse);
  653. CreatureInfo1.Text = rules.CanProduceBlackStone ? GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CanProduceBlackStones) : "";
  654. CreatureInfo2.Text = rules.CanProduceBlackStone ? GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CanProducePearlsBuyCreatureItems) : "";
  655. //Expire
  656. if (GameScene.User.IntelligentCreatures[selectedCreature].Expire == DateTime.MinValue)
  657. {
  658. CreatureDeadline.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ExpireNever);
  659. }
  660. else
  661. {
  662. var seconds = (GameScene.User.IntelligentCreatures[selectedCreature].Expire - CMain.Now).TotalSeconds;
  663. CreatureDeadline.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.Expire), Functions.PrintTimeSpanFromSeconds(seconds));
  664. }
  665. if (GameScene.User.IntelligentCreatures[selectedCreature].MaintainFoodTime == 0)
  666. CreatureMaintainFoodBuff.Text = "0";
  667. else
  668. CreatureMaintainFoodBuff.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.FoodBuff), Functions.PrintTimeSpanFromSeconds(GameScene.User.IntelligentCreatures[selectedCreature].MaintainFoodTime));
  669. int StartIndex = CreatureButtons[SelectedCreatureSlot].AnimDefaultIdx;
  670. int AnimCount = CreatureButtons[SelectedCreatureSlot].AnimDefaultCount;
  671. long AnimDelay = CreatureButtons[SelectedCreatureSlot].AnimDefaultDelay;
  672. if (AnimSwitched)
  673. {
  674. StartIndex = CreatureButtons[SelectedCreatureSlot].AnimExIdx;
  675. AnimCount = CreatureButtons[SelectedCreatureSlot].AnimExCount;
  676. AnimDelay = CreatureButtons[SelectedCreatureSlot].AnimExDelay;
  677. }
  678. if (SwitchAnimTime <= CMain.Time)//need switch
  679. if (!AnimSwitched) AnimNeedSwitch = true;
  680. bool AnimExFinished = false;
  681. if ((CreatureImage.Index - StartIndex) >= AnimCount - 1) AnimExFinished = true;
  682. CreatureImage.AnimationCount = AnimCount;
  683. CreatureImage.AnimationDelay = AnimDelay;
  684. CreatureImage.Index = StartIndex;//sets base.Index
  685. if (!CreatureImage.Animated) CreatureImage.Animated = true;
  686. if (AnimExFinished)
  687. {
  688. if (AnimNeedSwitch)
  689. {
  690. SwitchAnimTime = CMain.Time + 8000;
  691. AnimSwitched = true;
  692. }
  693. else if (AnimSwitched)
  694. {
  695. SwitchAnimTime = CMain.Time + 8000;
  696. AnimSwitched = false;
  697. }
  698. CreatureImage.OffSet = 0;
  699. AnimNeedSwitch = false;
  700. }
  701. }
  702. public int GetCreatureFromSlot(int slotidx)
  703. {
  704. for (int i = 0; i < GameScene.User.IntelligentCreatures.Count; i++)
  705. {
  706. if (GameScene.User.IntelligentCreatures[i].SlotIndex == slotidx) return i;
  707. }
  708. return -1;
  709. }
  710. #endregion
  711. #endregion
  712. public void SaveItemFilter(IntelligentCreatureItemFilter filter)
  713. {
  714. int selectedCreature = BeforeAfterDraw();
  715. if (selectedCreature < 0) return;
  716. GameScene.User.IntelligentCreatures[selectedCreature].Filter = filter;
  717. Network.Enqueue(new C.UpdateIntelligentCreature { Creature = GameScene.User.IntelligentCreatures[selectedCreature] });
  718. }
  719. public override void OnMouseDown(MouseEventArgs e)
  720. {
  721. base.OnMouseDown(e);
  722. if (GameScene.Scene.IntelligentCreatureOptionsGradeDialog.Visible) GameScene.Scene.IntelligentCreatureOptionsGradeDialog.BringToFront();
  723. if (GameScene.Scene.IntelligentCreatureOptionsDialog.Visible) GameScene.Scene.IntelligentCreatureOptionsDialog.BringToFront();
  724. }
  725. public override void Hide()
  726. {
  727. if (!Visible) return;
  728. if (GameScene.Scene.IntelligentCreatureOptionsGradeDialog.Visible) GameScene.Scene.IntelligentCreatureOptionsGradeDialog.Hide();
  729. if (GameScene.Scene.IntelligentCreatureOptionsDialog.Visible) GameScene.Scene.IntelligentCreatureOptionsDialog.Hide();
  730. AnimSwitched = false;
  731. AnimNeedSwitch = false;
  732. Visible = false;
  733. Network.Enqueue(new C.RequestIntelligentCreatureUpdates { Update = false });
  734. }
  735. public override void Show()
  736. {
  737. if (Visible) return;
  738. if (!GameScene.User.IntelligentCreatures.Any())
  739. {
  740. MirMessageBox messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoCreatures), MirMessageBoxButtons.OK);
  741. messageBox.Show();
  742. return;
  743. }
  744. if (!CreatureButtons.Any(x => x.Selected))
  745. {
  746. CreatureButtons[0].SelectButton();
  747. }
  748. Network.Enqueue(new C.RequestIntelligentCreatureUpdates { Update = true });
  749. Visible = true;
  750. showing = true;
  751. SwitchAnimTime = CMain.Time + 8000;
  752. AnimSwitched = false;
  753. AnimNeedSwitch = false;
  754. RefreshDialog();
  755. }
  756. }
  757. public sealed class CreatureButton : MirControl
  758. {
  759. public MirImageControl SelectionImage;
  760. public MirLabel NameLabel;
  761. public MirButton PetButton;
  762. public IntelligentCreatureType PetType = IntelligentCreatureType.None;
  763. public int idx;
  764. public bool Selected;
  765. public int AnimDefaultIdx = 540;
  766. public int AnimDefaultCount = 6;
  767. public long AnimDefaultDelay = 400;
  768. public int AnimExIdx = 550;
  769. public int AnimExCount = 5;
  770. public long AnimExDelay = 400;
  771. public CreatureButton()
  772. {
  773. Size = new Size(231, 33);
  774. PetButton = new MirButton
  775. {
  776. Index = 0,
  777. PressedIndex = 1,
  778. Library = Libraries.Prguse2,
  779. Parent = this,
  780. Location = new Point(0, 0),
  781. Sound = SoundList.ButtonA,
  782. };
  783. PetButton.Click += PetButtonClick;
  784. PetButton.MouseEnter += PetButtonMouseEnter;
  785. PetButton.MouseLeave += PetButtonMouseLeave;
  786. SelectionImage = new MirImageControl
  787. {
  788. Index = 535,
  789. Library = Libraries.Prguse2,
  790. Location = new Point(-2, -2),
  791. Parent = this,
  792. NotControl = true,
  793. Visible = false,
  794. };
  795. NameLabel = new MirLabel
  796. {
  797. Parent = this,
  798. Location = new Point(-22, -12),
  799. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  800. Size = new Size(80, 15),
  801. NotControl = true,
  802. Visible = false,
  803. };
  804. }
  805. private void SetButtonInfo(ClientIntelligentCreature pet)
  806. {
  807. if (pet == null) return;
  808. PetType = pet.PetType;
  809. NameLabel.Text = pet.CustomName.ToString();
  810. PetButton.Index = pet.Icon;
  811. PetButton.PressedIndex = pet.Icon;
  812. SetCreatureFrames();
  813. }
  814. public void Update(ClientIntelligentCreature pet, bool setnew = false)
  815. {
  816. if (pet == null) return;
  817. if (PetType == IntelligentCreatureType.None || PetType != pet.PetType) setnew = true;//force new
  818. if (setnew) SetButtonInfo(pet);
  819. else
  820. {
  821. NameLabel.Text = pet.CustomName.ToString();
  822. }
  823. }
  824. void PetButtonClick(object sender, EventArgs e)
  825. {
  826. SelectButton();
  827. }
  828. void PetButtonMouseEnter(object sender, EventArgs e)
  829. {
  830. NameLabel.Visible = true;
  831. }
  832. void PetButtonMouseLeave(object sender, EventArgs e)
  833. {
  834. NameLabel.Visible = false;
  835. }
  836. public void SelectButton()
  837. {
  838. if (Selected) return;
  839. for (int i = 0; i < GameScene.Scene.IntelligentCreatureDialog.CreatureButtons.Length; i++)
  840. {
  841. if (i == idx) continue;
  842. GameScene.Scene.IntelligentCreatureDialog.CreatureButtons[i].SelectButton(false);
  843. }
  844. SelectButton(true);
  845. GameScene.Scene.IntelligentCreatureDialog.SelectedCreatureSlot = idx;
  846. GameScene.Scene.IntelligentCreatureDialog.SwitchAnimTime = CMain.Time + 10000;
  847. GameScene.Scene.IntelligentCreatureDialog.AnimSwitched = false;
  848. GameScene.Scene.IntelligentCreatureDialog.AnimNeedSwitch = false;
  849. GameScene.Scene.IntelligentCreatureDialog.Update();
  850. }
  851. private void SelectButton(bool selection)
  852. {
  853. Selected = selection;
  854. SelectionImage.Visible = Selected;
  855. }
  856. public void Clear()
  857. {
  858. PetType = IntelligentCreatureType.None;
  859. Visible = false;
  860. SelectButton(false);
  861. }
  862. private void SetCreatureFrames()
  863. {
  864. switch (PetType)
  865. {
  866. case IntelligentCreatureType.BabyPig:
  867. AnimDefaultIdx = 540;
  868. AnimDefaultCount = 6;
  869. AnimDefaultDelay = 200;
  870. AnimExIdx = 550;
  871. AnimExCount = 5;
  872. AnimExDelay = 300;
  873. break;
  874. case IntelligentCreatureType.Chick:
  875. AnimDefaultIdx = 570;
  876. AnimDefaultCount = 4;
  877. AnimDefaultDelay = 350;
  878. AnimExIdx = 580;
  879. AnimExCount = 10;
  880. AnimExDelay = 200;
  881. break;
  882. case IntelligentCreatureType.Kitten:
  883. AnimDefaultIdx = 600;
  884. AnimDefaultCount = 6;
  885. AnimDefaultDelay = 250;
  886. AnimExIdx = 610;
  887. AnimExCount = 10;
  888. AnimExDelay = 200;
  889. break;
  890. case IntelligentCreatureType.BabySkeleton:
  891. AnimDefaultIdx = 630;
  892. AnimDefaultCount = 11;
  893. AnimDefaultDelay = 200;
  894. AnimExIdx = 650;
  895. AnimExCount = 7;
  896. AnimExDelay = 250;
  897. break;
  898. case IntelligentCreatureType.Baekdon:
  899. AnimDefaultIdx = 660;
  900. AnimDefaultCount = 6;
  901. AnimDefaultDelay = 250;
  902. AnimExIdx = 670;
  903. AnimExCount = 8;
  904. AnimExDelay = 250;
  905. break;
  906. case IntelligentCreatureType.Wimaen:
  907. AnimDefaultIdx = 690;
  908. AnimDefaultCount = 4;
  909. AnimDefaultDelay = 350;
  910. AnimExIdx = 700;
  911. AnimExCount = 6;
  912. AnimExDelay = 300;
  913. break;
  914. case IntelligentCreatureType.BlackKitten:
  915. AnimDefaultIdx = 720;
  916. AnimDefaultCount = 6;
  917. AnimDefaultDelay = 250;
  918. AnimExIdx = 730;
  919. AnimExCount = 10;
  920. AnimExDelay = 200;
  921. break;
  922. case IntelligentCreatureType.BabyDragon:
  923. AnimDefaultIdx = 750;
  924. AnimDefaultCount = 6;
  925. AnimDefaultDelay = 300;
  926. AnimExIdx = 760;
  927. AnimExCount = 7;
  928. AnimExDelay = 250;
  929. break;
  930. case IntelligentCreatureType.OlympicFlame:
  931. AnimDefaultIdx = 780;
  932. AnimDefaultCount = 6;
  933. AnimDefaultDelay = 300;
  934. AnimExIdx = 790;
  935. AnimExCount = 10;
  936. AnimExDelay = 200;
  937. break;
  938. case IntelligentCreatureType.BabySnowMan:
  939. AnimDefaultIdx = 810;
  940. AnimDefaultCount = 6;
  941. AnimDefaultDelay = 300;
  942. AnimExIdx = 820;
  943. AnimExCount = 6;
  944. AnimExDelay = 300;
  945. break;
  946. case IntelligentCreatureType.Frog:
  947. AnimDefaultIdx = 840;
  948. AnimDefaultCount = 6;
  949. AnimDefaultDelay = 300;
  950. AnimExIdx = 850;
  951. AnimExCount = 6;
  952. AnimExDelay = 300;
  953. break;
  954. case IntelligentCreatureType.BabyMonkey:
  955. AnimDefaultIdx = 870;
  956. AnimDefaultCount = 6;
  957. AnimDefaultDelay = 300;
  958. AnimExIdx = 880;
  959. AnimExCount = 9;
  960. AnimExDelay = 300;
  961. break;
  962. case IntelligentCreatureType.AngryBird:
  963. AnimDefaultIdx = 1400;
  964. AnimDefaultCount = 12;
  965. AnimDefaultDelay = 300;
  966. AnimExIdx = 1332;
  967. AnimExCount = 12;
  968. AnimExDelay = 300;
  969. break;
  970. case IntelligentCreatureType.Foxey:
  971. AnimDefaultIdx = 1430;
  972. AnimDefaultCount = 9;
  973. AnimDefaultDelay = 300;
  974. AnimExIdx = 1439;
  975. AnimExCount = 8;
  976. AnimExDelay = 300;
  977. break;
  978. case IntelligentCreatureType.MedicalRat:
  979. AnimDefaultIdx = 1550;
  980. AnimDefaultCount = 8;
  981. AnimDefaultDelay = 300;
  982. AnimExIdx = 1560;
  983. AnimExCount = 16;
  984. AnimExDelay = 300;
  985. break;
  986. case IntelligentCreatureType.None:
  987. AnimDefaultIdx = 539;
  988. AnimDefaultCount = 1;
  989. AnimDefaultDelay = 000;
  990. AnimExIdx = 539;
  991. AnimExCount = 1;
  992. AnimExDelay = 000;
  993. break;
  994. }
  995. }
  996. }
  997. public sealed class IntelligentCreatureOptionsDialog : MirImageControl
  998. {
  999. public readonly string[] OptionNames =
  1000. {
  1001. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AllItems),
  1002. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Gold),
  1003. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Weapons),
  1004. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Armours),
  1005. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Helmets),
  1006. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Boots),
  1007. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Belts),
  1008. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Jewelry),
  1009. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Others)
  1010. };
  1011. public IntelligentCreatureItemFilter Filter;
  1012. public Point locationOffset = new Point(450, 63);
  1013. public MirButton OptionsSaveButton, OptionsCancelButton;
  1014. public MirCheckBox[] CreatureOptions;
  1015. public IntelligentCreatureOptionsDialog()
  1016. {
  1017. Index = 469;
  1018. Library = Libraries.Title;
  1019. Movable = false;
  1020. Sort = true;
  1021. Location = new Point(GameScene.Scene.IntelligentCreatureDialog.Location.X + locationOffset.X, GameScene.Scene.IntelligentCreatureDialog.Location.Y + locationOffset.Y);
  1022. BeforeDraw += IntelligentCreatureOptionsDialog_BeforeDraw;
  1023. CreatureOptions = new MirCheckBox[9];
  1024. for (int i = 0; i < CreatureOptions.Length; i++)
  1025. {
  1026. int offsetY = i * 30;
  1027. CreatureOptions[i] = new MirCheckBox { Index = 2086, UnTickedIndex = 2086, TickedIndex = 2087, Parent = this, Location = new Point(16, (16 + offsetY)), Library = Libraries.Prguse };
  1028. CreatureOptions[i].LabelText = OptionNames[i];
  1029. CreatureOptions[i].Click += CheckBoxClick;
  1030. }
  1031. OptionsSaveButton = new MirButton
  1032. {
  1033. HoverIndex = 587,
  1034. Index = 586,
  1035. Location = new Point(10, 280),
  1036. Library = Libraries.Title,
  1037. Parent = this,
  1038. PressedIndex = 588,
  1039. Sound = SoundList.ButtonA,
  1040. };
  1041. OptionsSaveButton.Click += ButtonClick;
  1042. OptionsCancelButton = new MirButton
  1043. {
  1044. HoverIndex = 591,
  1045. Index = 590,
  1046. Location = new Point(60, 280),
  1047. Library = Libraries.Title,
  1048. Parent = this,
  1049. PressedIndex = 592,
  1050. Sound = SoundList.ButtonA,
  1051. };
  1052. OptionsCancelButton.Click += ButtonClick;
  1053. }
  1054. private void ButtonClick(object sender, EventArgs e)
  1055. {
  1056. if (sender == OptionsSaveButton)
  1057. {
  1058. Filter.PickupGrade = GameScene.Scene.IntelligentCreatureOptionsGradeDialog.GradeType;
  1059. GameScene.Scene.IntelligentCreatureOptionsGradeDialog.Hide();
  1060. GameScene.Scene.IntelligentCreatureDialog.SaveItemFilter(Filter);
  1061. Hide();
  1062. }
  1063. if (sender == OptionsCancelButton)
  1064. {
  1065. Filter = new IntelligentCreatureItemFilter();
  1066. GameScene.Scene.IntelligentCreatureOptionsGradeDialog.GradeType = ItemGrade.None;
  1067. GameScene.Scene.IntelligentCreatureOptionsGradeDialog.RefreshGradeFilter();
  1068. GameScene.Scene.IntelligentCreatureOptionsGradeDialog.Hide();
  1069. RefreshFilter();
  1070. Hide();
  1071. }
  1072. }
  1073. private void CheckBoxClick(object sender, EventArgs e)
  1074. {
  1075. for (int i = 0; i < CreatureOptions.Length; i++)
  1076. {
  1077. if (CreatureOptions[i] != sender) continue;
  1078. Filter.SetItemFilter(i);
  1079. break;
  1080. }
  1081. RefreshFilter();
  1082. }
  1083. void IntelligentCreatureOptionsDialog_BeforeDraw(object sender, EventArgs e)
  1084. {
  1085. if (!GameScene.Scene.IntelligentCreatureDialog.Visible)
  1086. {
  1087. Hide();
  1088. return;
  1089. }
  1090. Location = new Point(GameScene.Scene.IntelligentCreatureDialog.Location.X + locationOffset.X, GameScene.Scene.IntelligentCreatureDialog.Location.Y + locationOffset.Y);
  1091. }
  1092. private void RefreshFilter()
  1093. {
  1094. for (int i = 0; i < CreatureOptions.Length; i++)
  1095. {
  1096. switch (i)
  1097. {
  1098. case 0://all items
  1099. CreatureOptions[i].Checked = Filter.PetPickupAll;
  1100. break;
  1101. case 1://gold
  1102. CreatureOptions[i].Checked = Filter.PetPickupGold;
  1103. break;
  1104. case 2://weapons
  1105. CreatureOptions[i].Checked = Filter.PetPickupWeapons;
  1106. break;
  1107. case 3://armours
  1108. CreatureOptions[i].Checked = Filter.PetPickupArmours;
  1109. break;
  1110. case 4://helmets
  1111. CreatureOptions[i].Checked = Filter.PetPickupHelmets;
  1112. break;
  1113. case 5://boots
  1114. CreatureOptions[i].Checked = Filter.PetPickupBoots;
  1115. break;
  1116. case 6://belts
  1117. CreatureOptions[i].Checked = Filter.PetPickupBelts;
  1118. break;
  1119. case 7://jewelry
  1120. CreatureOptions[i].Checked = Filter.PetPickupAccessories;
  1121. break;
  1122. case 8://others
  1123. CreatureOptions[i].Checked = Filter.PetPickupOthers;
  1124. break;
  1125. }
  1126. }
  1127. }
  1128. public void Show(IntelligentCreatureItemFilter filter)
  1129. {
  1130. if (Visible) return;
  1131. Filter = filter;
  1132. Visible = true;
  1133. RefreshFilter();
  1134. }
  1135. }
  1136. public sealed class IntelligentCreatureOptionsGradeDialog : MirImageControl
  1137. {
  1138. private string[] GradeStrings =
  1139. {
  1140. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.All),
  1141. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Common),
  1142. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Rare),
  1143. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Mythical),
  1144. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Legendary),
  1145. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Heroic)
  1146. };
  1147. public MirButton NextButton, PrevButton;
  1148. public MirLabel GradeLabel;
  1149. public int SelectedGrade = 0;
  1150. public ItemGrade GradeType;
  1151. public Point locationOffset = new Point(449, 39);
  1152. public IntelligentCreatureOptionsGradeDialog()
  1153. {
  1154. Index = 237;
  1155. Library = Libraries.Prguse;
  1156. Movable = false;
  1157. Sort = true;
  1158. Location = new Point(GameScene.Scene.IntelligentCreatureDialog.Location.X + locationOffset.X, GameScene.Scene.IntelligentCreatureDialog.Location.Y + locationOffset.Y);
  1159. BeforeDraw += IntelligentCreatureOptionsGradeDialog_BeforeDraw;
  1160. NextButton = new MirButton()
  1161. {
  1162. HoverIndex = 396,
  1163. Index = 396,
  1164. Location = new Point(96, 5),
  1165. Library = Libraries.Prguse,
  1166. Parent = this,
  1167. PressedIndex = 397,
  1168. Sound = SoundList.ButtonA,
  1169. };
  1170. NextButton.Click += Button_Click;
  1171. PrevButton = new MirButton()
  1172. {
  1173. HoverIndex = 398,
  1174. Index = 398,
  1175. Location = new Point(76, 5),
  1176. Library = Libraries.Prguse,
  1177. Parent = this,
  1178. PressedIndex = 399,
  1179. Sound = SoundList.ButtonA,
  1180. };
  1181. PrevButton.Click += Button_Click;
  1182. GradeLabel = new MirLabel()
  1183. {
  1184. Parent = this,
  1185. Location = new Point(8, 0),
  1186. DrawFormat = TextFormatFlags.VerticalCenter,
  1187. Size = new Size(70, 21),
  1188. NotControl = true,
  1189. };
  1190. }
  1191. void Button_Click(object sender, EventArgs e)
  1192. {
  1193. if (sender == NextButton)
  1194. {
  1195. SelectedGrade++;
  1196. if (SelectedGrade >= GradeStrings.Length) SelectedGrade = GradeStrings.Length - 1;
  1197. }
  1198. if (sender == PrevButton)
  1199. {
  1200. SelectedGrade--;
  1201. if (SelectedGrade <= 0) SelectedGrade = 0;
  1202. }
  1203. GradeLabel.Text = GradeStrings[SelectedGrade];
  1204. GradeType = (ItemGrade)((byte)SelectedGrade);
  1205. GradeLabel.ForeColour = GradeNameColor(GradeType);
  1206. }
  1207. private Color GradeNameColor(ItemGrade grade)
  1208. {
  1209. switch (grade)
  1210. {
  1211. case ItemGrade.Common:
  1212. return Color.Yellow;
  1213. case ItemGrade.Rare:
  1214. return Color.DeepSkyBlue;
  1215. case ItemGrade.Legendary:
  1216. return Color.DarkOrange;
  1217. case ItemGrade.Mythical:
  1218. return Color.Plum;
  1219. case ItemGrade.Heroic:
  1220. return Color.Red;
  1221. default:
  1222. return Color.White;
  1223. }
  1224. }
  1225. // public override void OnMouseDown(MouseEventArgs e)
  1226. //{
  1227. // GameScene.Scene.IntelligentCreatureOptionsDialog.BringToFront();
  1228. // base.OnMouseDown(e);
  1229. // }
  1230. void IntelligentCreatureOptionsGradeDialog_BeforeDraw(object sender, EventArgs e)
  1231. {
  1232. if (!GameScene.Scene.IntelligentCreatureDialog.Visible)
  1233. {
  1234. Hide();
  1235. return;
  1236. }
  1237. Location = new Point(GameScene.Scene.IntelligentCreatureDialog.Location.X + locationOffset.X, GameScene.Scene.IntelligentCreatureDialog.Location.Y + locationOffset.Y);
  1238. }
  1239. public void RefreshGradeFilter()
  1240. {
  1241. SelectedGrade = (int)((byte)GradeType);
  1242. GradeLabel.Text = GradeStrings[SelectedGrade];
  1243. GradeLabel.ForeColour = GradeNameColor(GradeType);
  1244. }
  1245. public void Show(ItemGrade grade)
  1246. {
  1247. if (Visible) return;
  1248. Visible = true;
  1249. GradeType = grade;
  1250. RefreshGradeFilter();
  1251. }
  1252. }
  1253. }