MailDialogs.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirSounds;
  4. using Client.MirNetwork;
  5. using C = ClientPackets;
  6. namespace Client.MirScenes.Dialogs
  7. {
  8. public class MailListDialog : MirImageControl
  9. {
  10. MirImageControl TitleLabel;
  11. MirButton HelpButton, CloseButton;
  12. MirLabel TitleTypeLabel, TitleSenderLabel, TitleMessageLabel;
  13. //Send / Reply (Can only reply if index exists, button will disapear if not) / Read / Delete / Block List / Bug Report (new system??)
  14. MirLabel PageLabel;
  15. MirButton PreviousButton, NextButton;
  16. MirButton SendButton, ReplyButton, ReadButton, DeleteButton, BlockListButton, BugReportButton;
  17. public MailItemRow[] Rows = new MailItemRow[10];
  18. public ClientMail SelectedMail;
  19. public int SelectedIndex;
  20. private int StartIndex = 0;
  21. private int CurrentPage = 1, PageCount = 1;
  22. public MailListDialog()
  23. {
  24. Index = 670;
  25. Library = Libraries.Title;
  26. Size = new Size(312, 444);
  27. Movable = true;
  28. Sort = true;
  29. Location = new Point((Settings.ScreenWidth - Size.Width) - 150, 5);
  30. TitleLabel = new MirImageControl
  31. {
  32. Index = 7,
  33. Library = Libraries.Title,
  34. Location = new Point(18, 9),
  35. Parent = this
  36. };
  37. TitleTypeLabel = new MirLabel
  38. {
  39. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Type),
  40. Parent = this,
  41. Font = new Font(Settings.FontName, Settings.FontSize - 1, FontStyle.Italic),
  42. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  43. Size = new Size(37, 19),
  44. Location = new Point(8, 34)
  45. };
  46. TitleSenderLabel = new MirLabel
  47. {
  48. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Sender),
  49. Parent = this,
  50. Font = new Font(Settings.FontName, Settings.FontSize - 1, FontStyle.Italic),
  51. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  52. Size = new Size(132, 19),
  53. Location = new Point(47, 34)
  54. };
  55. TitleMessageLabel = new MirLabel
  56. {
  57. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Message),
  58. Parent = this,
  59. Font = new Font(Settings.FontName, Settings.FontSize - 1, FontStyle.Italic),
  60. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  61. Size = new Size(122, 19),
  62. Location = new Point(181, 34)
  63. };
  64. CloseButton = new MirButton
  65. {
  66. HoverIndex = 361,
  67. Index = 360,
  68. Location = new Point(Size.Width - 24, 3),
  69. Library = Libraries.Prguse2,
  70. Parent = this,
  71. PressedIndex = 362,
  72. Sound = SoundList.ButtonA,
  73. };
  74. CloseButton.Click += (o, e) => Hide();
  75. HelpButton = new MirButton
  76. {
  77. Index = 257,
  78. HoverIndex = 258,
  79. PressedIndex = 259,
  80. Library = Libraries.Prguse2,
  81. Parent = this,
  82. Location = new Point(Size.Width - 50, 3),
  83. Sound = SoundList.ButtonA,
  84. };
  85. HelpButton.Click += (o, e) => GameScene.Scene.HelpDialog.DisplayPage("");
  86. PreviousButton = new MirButton
  87. {
  88. Index = 240,
  89. HoverIndex = 241,
  90. PressedIndex = 242,
  91. Library = Libraries.Prguse2,
  92. Parent = this,
  93. Location = new Point(102, Size.Height - 55),
  94. Sound = SoundList.ButtonA,
  95. };
  96. PreviousButton.Click += (o, e) =>
  97. {
  98. if (CurrentPage <= 1) return;
  99. SelectedMail = null;
  100. CurrentPage--;
  101. StartIndex -= 10;
  102. UpdateInterface();
  103. };
  104. PageLabel = new MirLabel
  105. {
  106. Text = "",
  107. Parent = this,
  108. Location = new Point(120, Size.Height - 55),
  109. Size = new Size(67, 15),
  110. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  111. };
  112. NextButton = new MirButton
  113. {
  114. Index = 243,
  115. HoverIndex = 244,
  116. PressedIndex = 245,
  117. Library = Libraries.Prguse2,
  118. Parent = this,
  119. Location = new Point(192, Size.Height - 55),
  120. Sound = SoundList.ButtonA,
  121. };
  122. NextButton.Click += (o, e) =>
  123. {
  124. if (CurrentPage >= PageCount) return;
  125. SelectedMail = null;
  126. CurrentPage++;
  127. StartIndex += 10;
  128. UpdateInterface();
  129. };
  130. #region Action Buttons
  131. SendButton = new MirButton
  132. {
  133. Index = 563,
  134. HoverIndex = 564,
  135. PressedIndex = 565,
  136. Library = Libraries.Prguse,
  137. Parent = this,
  138. Location = new Point(75, 414),
  139. Sound = SoundList.ButtonA,
  140. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Send)
  141. };
  142. SendButton.Click += (o, e) =>
  143. {
  144. MirInputBox inputBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EnterMailToName));
  145. inputBox.OKButton.Click += (o1, e1) =>
  146. {
  147. //open letter dialog, pass in name
  148. GameScene.Scene.MailComposeLetterDialog.ComposeMail(inputBox.InputTextBox.Text);
  149. inputBox.Dispose();
  150. };
  151. inputBox.Show();
  152. };
  153. ReplyButton = new MirButton
  154. {
  155. Index = 569,
  156. HoverIndex = 570,
  157. PressedIndex = 571,
  158. Library = Libraries.Prguse,
  159. Parent = this,
  160. Location = new Point(102, 414),
  161. Sound = SoundList.ButtonA,
  162. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Reply)
  163. };
  164. ReplyButton.Click += (o, e) =>
  165. {
  166. if (SelectedMail == null) return;
  167. GameScene.Scene.MailComposeLetterDialog.ComposeMail(SelectedMail.SenderName);
  168. };
  169. ReadButton = new MirButton
  170. {
  171. Index = 572,
  172. HoverIndex = 573,
  173. PressedIndex = 574,
  174. Library = Libraries.Prguse,
  175. Parent = this,
  176. Location = new Point(129, 414),
  177. Sound = SoundList.ButtonA,
  178. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Read)
  179. };
  180. ReadButton.Click += (o, e) =>
  181. {
  182. if (SelectedMail == null) return;
  183. if(SelectedMail.Gold > 0 || SelectedMail.Items.Count > 0)
  184. {
  185. GameScene.Scene.MailReadParcelDialog.ReadMail(SelectedMail);
  186. }
  187. else
  188. {
  189. GameScene.Scene.MailReadLetterDialog.ReadMail(SelectedMail);
  190. }
  191. };
  192. DeleteButton = new MirButton
  193. {
  194. Index = 557,
  195. HoverIndex = 558,
  196. PressedIndex = 559,
  197. Library = Libraries.Prguse,
  198. Parent = this,
  199. Location = new Point(156, 414),
  200. Sound = SoundList.ButtonA,
  201. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Delete)
  202. };
  203. DeleteButton.Click += (o, e) =>
  204. {
  205. if (SelectedMail == null || SelectedMail.Locked) return;
  206. if (SelectedMail.Items.Count > 0 || SelectedMail.Gold > 0)
  207. {
  208. MirMessageBox messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ParcelContainsItemsOrGoldDeleteConfirm), MirMessageBoxButtons.YesNo);
  209. messageBox.YesButton.Click += (o1, e1) =>
  210. {
  211. Network.Enqueue(new C.DeleteMail { MailID = SelectedMail.MailID });
  212. SelectedMail = null;
  213. };
  214. messageBox.Show();
  215. }
  216. else
  217. {
  218. Network.Enqueue(new C.DeleteMail { MailID = SelectedMail.MailID });
  219. SelectedMail = null;
  220. }
  221. };
  222. BlockListButton = new MirButton
  223. {
  224. Index = 520,
  225. HoverIndex = 521,
  226. PressedIndex = 522,
  227. Library = Libraries.Prguse,
  228. Parent = this,
  229. Location = new Point(183, 414),
  230. Sound = SoundList.ButtonA,
  231. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BlockList),
  232. GrayScale = true,
  233. Enabled = false
  234. };
  235. BugReportButton = new MirButton
  236. {
  237. Index = 523,
  238. HoverIndex = 524,
  239. PressedIndex = 525,
  240. Library = Libraries.Prguse,
  241. Parent = this,
  242. Location = new Point(210, 414),
  243. Sound = SoundList.ButtonA,
  244. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ReportBug),
  245. GrayScale = true,
  246. Enabled = false
  247. };
  248. #endregion
  249. }
  250. public void Reset()
  251. {
  252. for (int i = 0; i < Rows.Length; i++)
  253. {
  254. if (Rows[i] != null) Rows[i].Dispose();
  255. Rows[i] = null;
  256. }
  257. }
  258. public void UpdateInterface()
  259. {
  260. Reset();
  261. PageCount = (int)Math.Ceiling((double)GameScene.User.Mail.Count / 10);
  262. if (PageCount < 1) PageCount = 1;
  263. PageLabel.Text = string.Format("{0} / {1}", CurrentPage, PageCount);
  264. for (int i = 0; i < Rows.Length; i++)
  265. {
  266. if (i + StartIndex >= GameScene.User.Mail.Count) break;
  267. if (Rows[i] != null)
  268. Rows[i].Dispose();
  269. Rows[i] = new MailItemRow
  270. {
  271. Mail = GameScene.User.Mail[i + StartIndex],
  272. Location = new Point(10, 55 + i * 33),
  273. Parent = this
  274. };
  275. Rows[i].Click += (o, e) =>
  276. {
  277. MailItemRow row = (MailItemRow)o;
  278. if (row.Mail != SelectedMail)
  279. {
  280. SelectedMail = row.Mail;
  281. SelectedIndex = FindSelectedIndex();
  282. UpdateRows();
  283. }
  284. else
  285. {
  286. if (SelectedMail.Gold > 0 || SelectedMail.Items.Count > 0)
  287. {
  288. GameScene.Scene.MailReadParcelDialog.ReadMail(SelectedMail);
  289. }
  290. else
  291. {
  292. GameScene.Scene.MailReadLetterDialog.ReadMail(SelectedMail);
  293. }
  294. }
  295. };
  296. if (SelectedMail != null)
  297. {
  298. if(SelectedMail.MailID == Rows[i].Mail.MailID)
  299. {
  300. SelectedMail = Rows[i].Mail;
  301. }
  302. }
  303. }
  304. UpdateRows();
  305. }
  306. public int FindSelectedIndex()
  307. {
  308. int selectedIndex = 0;
  309. if (SelectedMail != null)
  310. {
  311. for (int i = 0; i < Rows.Length; i++)
  312. {
  313. if (Rows[i] == null || SelectedMail != Rows[i].Mail) continue;
  314. selectedIndex = i;
  315. }
  316. }
  317. return selectedIndex;
  318. }
  319. public void UpdateRows()
  320. {
  321. for (int i = 0; i < Rows.Length; i++)
  322. {
  323. if (Rows[i] == null) continue;
  324. Rows[i].Selected = false;
  325. if (Rows[i].Mail == SelectedMail)
  326. {
  327. Rows[i].Selected = true;
  328. }
  329. Rows[i].UpdateInterface();
  330. }
  331. if(SelectedMail != null)
  332. {
  333. ReplyButton.Visible = SelectedMail.CanReply;
  334. }
  335. }
  336. public override void Show()
  337. {
  338. if (Visible) return;
  339. Visible = true;
  340. UpdateInterface();
  341. }
  342. public override void Hide()
  343. {
  344. if (!Visible) return;
  345. Visible = false;
  346. SelectedMail = null;
  347. SelectedIndex = -1;
  348. }
  349. public void Toggle()
  350. {
  351. if (!Visible)
  352. Show();
  353. else
  354. Hide();
  355. }
  356. }
  357. public class MailItemRow : MirControl
  358. {
  359. public ClientMail Mail = null;
  360. public MirLabel SenderLabel, MessageLabel;
  361. public MirImageControl IconImage, UnreadImage, ParcelImage, LockedImage, SelectedImage;
  362. public bool Selected = false;
  363. Size IconArea = new Size(34, 32);
  364. public MailItemRow()
  365. {
  366. Sound = SoundList.ButtonA;
  367. Size = new Size(290, 33);
  368. BeforeDraw += QuestRow_BeforeDraw;
  369. IconImage = new MirImageControl
  370. {
  371. Index = 0,
  372. Library = Libraries.Prguse,
  373. Location = new Point(0, 0),
  374. Parent = this
  375. };
  376. UnreadImage = new MirImageControl
  377. {
  378. Index = 550,
  379. Library = Libraries.Prguse,
  380. Location = new Point(5, 17),
  381. Parent = this,
  382. Visible = false
  383. };
  384. LockedImage = new MirImageControl
  385. {
  386. Index = 551,
  387. Library = Libraries.Prguse,
  388. Location = new Point(5, 17),
  389. Parent = this,
  390. Visible = false
  391. };
  392. ParcelImage = new MirImageControl
  393. {
  394. Index = 552,
  395. Library = Libraries.Prguse,
  396. Location = new Point(5, 17), //20
  397. Parent = this,
  398. Visible = false
  399. };
  400. SelectedImage = new MirImageControl
  401. {
  402. Index = 545,
  403. Library = Libraries.Prguse,
  404. Location = new Point(-5, -3),
  405. Parent = this,
  406. Visible = false,
  407. NotControl = true
  408. };
  409. SenderLabel = new MirLabel
  410. {
  411. Location = new Point(35, 0),
  412. Size = new Size(130, 31),
  413. DrawFormat = TextFormatFlags.VerticalCenter,
  414. Parent = this,
  415. NotControl = true,
  416. };
  417. MessageLabel = new MirLabel
  418. {
  419. Location = new Point(170, 0),
  420. Size = new Size(115, 31),
  421. DrawFormat = TextFormatFlags.VerticalCenter,
  422. Parent = this,
  423. NotControl = true,
  424. };
  425. UpdateInterface();
  426. }
  427. void QuestRow_BeforeDraw(object sender, EventArgs e)
  428. {
  429. UpdateInterface();
  430. }
  431. public void UpdateInterface()
  432. {
  433. if (Mail == null) return;
  434. IconImage.Visible = true;
  435. if (Mail.Items.Count > 0)
  436. {
  437. IconImage.Index = Mail.Items[0].Info.Image;
  438. IconImage.Library = Libraries.Items;
  439. }
  440. else if (Mail.Gold > 0)
  441. {
  442. IconImage.Index = 541;
  443. IconImage.Library = Libraries.Prguse;
  444. }
  445. else
  446. {
  447. IconImage.Index = 540;
  448. IconImage.Library = Libraries.Prguse;
  449. }
  450. IconImage.Location = new Point((IconArea.Width - IconImage.Size.Width) /2, (IconArea.Height - IconImage.Size.Height) / 2);
  451. if (!Mail.Opened)
  452. {
  453. UnreadImage.Visible = true;
  454. }
  455. if (Mail.Locked)
  456. {
  457. LockedImage.Visible = true;
  458. }
  459. if (!Mail.Collected)
  460. {
  461. ParcelImage.Visible = true;
  462. if (!Mail.Opened)
  463. {
  464. //move unread to second position if not collected parcel
  465. UnreadImage.Location = new Point(20, 17);
  466. }
  467. }
  468. else
  469. {
  470. if (Mail.Locked)
  471. {
  472. //move unread to second position if locked
  473. UnreadImage.Location = new Point(20, 17);
  474. }
  475. }
  476. SenderLabel.Text = Mail.SenderName;
  477. MessageLabel.Text = Mail.Locked ? "[*] " + Mail.Message.Replace("\r\n", " ") : Mail.Message.Replace("\r\n", " ");
  478. SelectedImage.Visible = Selected;
  479. }
  480. protected override void Dispose(bool disposing)
  481. {
  482. base.Dispose(disposing);
  483. Mail = null;
  484. SenderLabel = null;
  485. MessageLabel = null;
  486. SelectedImage = null;
  487. IconImage = null;
  488. Selected = false;
  489. }
  490. protected override void OnMouseEnter()
  491. {
  492. base.OnMouseEnter();
  493. GameScene.Scene.CreateMailLabel(Mail);
  494. }
  495. protected override void OnMouseLeave()
  496. {
  497. base.OnMouseLeave();
  498. GameScene.Scene.DisposeMailLabel();
  499. }
  500. }
  501. public class MailComposeLetterDialog : MirImageControl
  502. {
  503. MirLabel RecipientNameLabel;
  504. MirTextBox MessageTextBox;
  505. MirButton SendButton, CancelButton, CloseButton;
  506. public MailComposeLetterDialog()
  507. {
  508. Index = 671;
  509. Library = Libraries.Title;
  510. Size = new Size(236, 300);
  511. Movable = true;
  512. Sort = true;
  513. Location = new Point(100, 100);
  514. CloseButton = new MirButton
  515. {
  516. HoverIndex = 361,
  517. Index = 360,
  518. Location = new Point(Size.Width - 27, 3),
  519. Library = Libraries.Prguse2,
  520. Parent = this,
  521. PressedIndex = 362,
  522. Sound = SoundList.ButtonA,
  523. };
  524. CloseButton.Click += (o, e) => Hide();
  525. RecipientNameLabel = new MirLabel
  526. {
  527. Text = "",
  528. Parent = this,
  529. Font = new Font(Settings.FontName, 8F),
  530. ForeColour = Color.White,
  531. Location = new Point(70, 35),
  532. Size = new Size(150, 15),
  533. NotControl = true,
  534. };
  535. MessageTextBox = new MirTextBox
  536. {
  537. ForeColour = Color.White,
  538. Parent = this,
  539. Font = new Font(Settings.FontName, 8F),
  540. Location = new Point(15, 92),
  541. Size = new Size(202, 165),
  542. };
  543. MessageTextBox.MultiLine();
  544. SendButton = new MirButton
  545. {
  546. Index = 607,
  547. HoverIndex = 608,
  548. PressedIndex = 609,
  549. Parent = this,
  550. Library = Libraries.Title,
  551. Sound = SoundList.ButtonA,
  552. Location = new Point(30, 265)
  553. };
  554. SendButton.Click += (o, e) =>
  555. {
  556. Network.Enqueue(new C.SendMail { Name = RecipientNameLabel.Text, Message = MessageTextBox.Text });
  557. Hide();
  558. };
  559. CancelButton = new MirButton
  560. {
  561. Index = 193,
  562. HoverIndex = 194,
  563. PressedIndex = 195,
  564. Parent = this,
  565. Library = Libraries.Title,
  566. Sound = SoundList.ButtonA,
  567. Location = new Point(135, 265)
  568. };
  569. CancelButton.Click += (o, e) => Hide();
  570. }
  571. public void ComposeMail(string recipientName, string message = "")
  572. {
  573. if (string.IsNullOrEmpty(recipientName)) return;
  574. RecipientNameLabel.Text = recipientName;
  575. MessageTextBox.Text = message;
  576. MessageTextBox.SetFocus();
  577. Visible = true;
  578. }
  579. }
  580. public class MailComposeParcelDialog : MirImageControl
  581. {
  582. public MirLabel RecipientNameLabel, ParcelCostLabel, GoldSendLabel;
  583. MirTextBox MessageTextBox;
  584. MirButton StampButton, SendButton, CancelButton, CloseButton;
  585. MirImageControl ItemCover;
  586. private const uint _cellCount = 5;
  587. public MirItemCell[] Cells = new MirItemCell[_cellCount];
  588. public static UserItem[] Items = new UserItem[_cellCount];
  589. public static ulong[] ItemsIdx = new ulong[_cellCount];
  590. public uint GiftGoldAmount = 0;
  591. public bool Stamped = false;
  592. public MailComposeParcelDialog()
  593. {
  594. Index = 674;
  595. Library = Libraries.Title;
  596. Size = new Size(236, 384);
  597. Movable = true;
  598. Sort = true;
  599. Location = new Point(GameScene.Scene.InventoryDialog.Size.Width + 10, 0);
  600. CloseButton = new MirButton
  601. {
  602. HoverIndex = 361,
  603. Index = 360,
  604. Location = new Point(Size.Width - 27, 3),
  605. Library = Libraries.Prguse2,
  606. Parent = this,
  607. PressedIndex = 362,
  608. Sound = SoundList.ButtonA,
  609. };
  610. CloseButton.Click += (o, e) =>
  611. {
  612. ResetLockedCells();
  613. Hide();
  614. };
  615. RecipientNameLabel = new MirLabel
  616. {
  617. Text = "",
  618. Parent = this,
  619. Font = new Font(Settings.FontName, 8F),
  620. ForeColour = Color.White,
  621. Location = new Point(70, 35),
  622. Size = new Size(150, 15),
  623. NotControl = true,
  624. };
  625. MessageTextBox = new MirTextBox
  626. {
  627. ForeColour = Color.White,
  628. Parent = this,
  629. Font = new Font(Settings.FontName, 8F),
  630. Location = new Point(15, 98),
  631. Size = new Size(202, 165),
  632. };
  633. MessageTextBox.MultiLine();
  634. StampButton = new MirButton
  635. {
  636. Index = 203,
  637. HoverIndex = 203,
  638. PressedIndex = 203,
  639. Location = new Point(73, 56),
  640. Size = new Size(20,20),
  641. Library = Libraries.Prguse2,
  642. Parent = this,
  643. Sound = SoundList.ButtonA,
  644. };
  645. StampButton.Click += (o, e) =>
  646. {
  647. StampParcel();
  648. };
  649. ItemCover = new MirImageControl
  650. {
  651. Index = 676,
  652. Location = new Point(63, 310),
  653. Size = new Size(144, 33),
  654. Library = Libraries.Title,
  655. Parent = this
  656. };
  657. for (int i = 0; i < Cells.Length; i++)
  658. {
  659. Cells[i] = new MirItemCell
  660. {
  661. BorderColour = Color.Lime,
  662. Size = new Size(35, 31),
  663. GridType = MirGridType.Mail,
  664. Library = Libraries.Items,
  665. Parent = this,
  666. Location = new Point(27 + (i * 36), 311),
  667. ItemSlot = i
  668. };
  669. }
  670. ParcelCostLabel = new MirLabel
  671. {
  672. DrawFormat = TextFormatFlags.VerticalCenter,
  673. Font = new Font(Settings.FontName, 8F),
  674. Location = new Point(63, 269),
  675. Parent = this,
  676. Size = new Size(143, 15),
  677. };
  678. GoldSendLabel = new MirLabel
  679. {
  680. DrawFormat = TextFormatFlags.VerticalCenter,
  681. Font = new Font(Settings.FontName, 8F),
  682. Location = new Point(63, 290),
  683. Parent = this,
  684. Size = new Size(143, 15),
  685. Sound = SoundList.Gold,
  686. };
  687. GoldSendLabel.Click += (o, e) =>
  688. {
  689. if (GameScene.SelectedCell == null && GameScene.Gold > 0)
  690. {
  691. MirAmountBox amountBox = new MirAmountBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SendAmount), 116, GameScene.Gold);
  692. amountBox.OKButton.Click += (c, a) =>
  693. {
  694. if (amountBox.Amount > 0)
  695. {
  696. GiftGoldAmount += amountBox.Amount;
  697. GameScene.Gold -= amountBox.Amount;
  698. }
  699. GoldSendLabel.Text = GiftGoldAmount.ToString("###,###,##0");
  700. CalculatePostage();
  701. };
  702. amountBox.Show();
  703. GameScene.PickedUpGold = false;
  704. }
  705. };
  706. SendButton = new MirButton
  707. {
  708. Index = 607,
  709. HoverIndex = 608,
  710. PressedIndex = 609,
  711. Parent = this,
  712. Library = Libraries.Title,
  713. Sound = SoundList.ButtonA,
  714. Location = new Point(30, 350)
  715. };
  716. SendButton.Click += (o, e) =>
  717. {
  718. Network.Enqueue(new C.SendMail { Name = RecipientNameLabel.Text, Message = MessageTextBox.Text, Gold = GiftGoldAmount, ItemsIdx = ItemsIdx, Stamped = Stamped });
  719. };
  720. CancelButton = new MirButton
  721. {
  722. Index = 193,
  723. HoverIndex = 194,
  724. PressedIndex = 195,
  725. Parent = this,
  726. Library = Libraries.Title,
  727. Sound = SoundList.ButtonA,
  728. Location = new Point(135, 350)
  729. };
  730. CancelButton.Click += (o, e) =>
  731. {
  732. ResetLockedCells();
  733. Hide();
  734. };
  735. }
  736. public override void Hide()
  737. {
  738. if (!Visible) return;
  739. Visible = false;
  740. Reset();
  741. }
  742. public void Reset()
  743. {
  744. GameScene.Gold += GiftGoldAmount;
  745. GiftGoldAmount = 0;
  746. Stamped = false;
  747. ResetLockedCells();
  748. }
  749. public void ResetLockedCells()
  750. {
  751. for (int i = 0; i < _cellCount; i++)
  752. {
  753. MirItemCell cell = Cells[i];
  754. if (cell.Item != null)
  755. {
  756. Network.Enqueue(new C.MailLockedItem { UniqueID = cell.Item.UniqueID, Locked = false });
  757. cell.Item = null;
  758. }
  759. ItemsIdx[i] = 0;
  760. }
  761. }
  762. private void StampParcel()
  763. {
  764. if(!Stamped)
  765. {
  766. for (int i = 0; i < GameScene.User.Inventory.Length; i++)
  767. {
  768. UserItem item = GameScene.User.Inventory[i];
  769. if (item == null || item.Info.Type != ItemType.Nothing || item.Info.Shape != 1) continue;
  770. Stamped = true;
  771. break;
  772. }
  773. }
  774. else
  775. Stamped = false;
  776. CalculatePostage();
  777. UpdateParcel();
  778. ResetLockedCells();
  779. }
  780. private void UpdateParcel()
  781. {
  782. if (Stamped)
  783. {
  784. StampButton.Index = 204;
  785. StampButton.HoverIndex = 204;
  786. StampButton.PressedIndex = 204;
  787. for (int i = 1; i < Cells.Length; i++)
  788. {
  789. Cells[i].Enabled = true;
  790. }
  791. ItemCover.Visible = false;
  792. }
  793. else
  794. {
  795. StampButton.Index = 203;
  796. StampButton.HoverIndex = 203;
  797. StampButton.PressedIndex = 203;
  798. for (int i = 1; i < Cells.Length; i++)
  799. {
  800. Cells[i].Enabled = false;
  801. }
  802. ItemCover.Visible = true;
  803. }
  804. }
  805. public void CalculatePostage()
  806. {
  807. Network.Enqueue(new C.MailCost { Gold = GiftGoldAmount, ItemsIdx = ItemsIdx, Stamped = Stamped });
  808. }
  809. public void ComposeMail(string recipientName)
  810. {
  811. if (string.IsNullOrEmpty(recipientName)) return;
  812. RecipientNameLabel.Text = recipientName;
  813. MessageTextBox.Text = string.Empty;
  814. MessageTextBox.SetFocus();
  815. UpdateParcel();
  816. //Disable last 4 item slots
  817. for (int i = 1; i < Cells.Length; i++)
  818. {
  819. Cells[i].Enabled = false;
  820. }
  821. ParcelCostLabel.Text = "0";
  822. GoldSendLabel.Text = "0";
  823. ResetLockedCells();
  824. Visible = true;
  825. }
  826. }
  827. public class MailReadLetterDialog : MirImageControl
  828. {
  829. MirLabel SenderNameLabel, DateSentLabel, MessageLabel;
  830. MirButton DeleteButton, LockButton, CancelButton, CloseButton;
  831. public ClientMail Mail;
  832. public MailReadLetterDialog()
  833. {
  834. Index = 672;
  835. Library = Libraries.Title;
  836. Size = new Size(236, 300);
  837. Movable = true;
  838. Sort = true;
  839. Location = new Point(100, 100);
  840. CloseButton = new MirButton
  841. {
  842. HoverIndex = 361,
  843. Index = 360,
  844. Location = new Point(Size.Width - 27, 3),
  845. Library = Libraries.Prguse2,
  846. Parent = this,
  847. PressedIndex = 362,
  848. Sound = SoundList.ButtonA,
  849. };
  850. CloseButton.Click += (o, e) => Hide();
  851. SenderNameLabel = new MirLabel
  852. {
  853. Parent = this,
  854. Font = new Font(Settings.FontName, 8F),
  855. ForeColour = Color.White,
  856. Location = new Point(70, 35),
  857. Size = new Size(150, 15),
  858. NotControl = true,
  859. };
  860. DateSentLabel = new MirLabel
  861. {
  862. Parent = this,
  863. Font = new Font(Settings.FontName, 8F),
  864. ForeColour = Color.White,
  865. Location = new Point(70, 56),
  866. Size = new Size(150, 15),
  867. NotControl = true,
  868. };
  869. MessageLabel = new MirLabel
  870. {
  871. ForeColour = Color.White,
  872. Parent = this,
  873. Font = new Font(Settings.FontName, 8F),
  874. Location = new Point(15, 92),
  875. Size = new Size(202, 165),
  876. };
  877. DeleteButton = new MirButton
  878. {
  879. Index = 540,
  880. HoverIndex = 541,
  881. PressedIndex = 542,
  882. Parent = this,
  883. Library = Libraries.Title,
  884. Sound = SoundList.ButtonA,
  885. Location = new Point(12, 265)
  886. };
  887. DeleteButton.Click += (o, e) =>
  888. {
  889. if (Mail.Locked) return;
  890. Network.Enqueue(new C.DeleteMail { MailID = Mail.MailID });
  891. Mail = null;
  892. Hide();
  893. };
  894. LockButton = new MirButton
  895. {
  896. Index = 686,
  897. HoverIndex = 687,
  898. PressedIndex = 688,
  899. Parent = this,
  900. Library = Libraries.Title,
  901. Sound = SoundList.ButtonA,
  902. Location = new Point(81, 265)
  903. };
  904. LockButton.Click += (o, e) =>
  905. {
  906. Mail.Locked = !Mail.Locked;
  907. //GameScene.Scene.MailListDialog.SelectedMail = null;
  908. Network.Enqueue(new C.LockMail { MailID = Mail.MailID, Lock = Mail.Locked });
  909. };
  910. CancelButton = new MirButton
  911. {
  912. Index = 193,
  913. HoverIndex = 194,
  914. PressedIndex = 195,
  915. Parent = this,
  916. Library = Libraries.Title,
  917. Sound = SoundList.ButtonA,
  918. Location = new Point(154, 265)
  919. };
  920. CancelButton.Click += (o, e) => Hide();
  921. }
  922. public void ReadMail(ClientMail mail)
  923. {
  924. if (mail == null) return;
  925. Mail = mail;
  926. if (!Mail.Opened)
  927. {
  928. Network.Enqueue(new C.ReadMail { MailID = Mail.MailID });
  929. }
  930. SenderNameLabel.Text = Mail.SenderName;
  931. DateSentLabel.Text = Mail.DateSent.ToString("dd/MM/yy H:mm:ss");
  932. MessageLabel.Text = Mail.Message.Replace("\\r\\n", "\r\n");
  933. Visible = true;
  934. }
  935. }
  936. public class MailReadParcelDialog : MirImageControl
  937. {
  938. MirLabel SenderNameLabel, DateSentLabel, MessageLabel, GoldSendLabel;
  939. MirButton CollectButton, CancelButton, CloseButton;
  940. public MirItemCell[] Cells = new MirItemCell[5];
  941. public ClientMail Mail;
  942. public MailReadParcelDialog()
  943. {
  944. Index = 675;
  945. Library = Libraries.Title;
  946. Size = new Size(236, 300);
  947. Movable = true;
  948. Sort = true;
  949. Location = new Point(100, 100);
  950. CloseButton = new MirButton
  951. {
  952. HoverIndex = 361,
  953. Index = 360,
  954. Location = new Point(Size.Width - 27, 3),
  955. Library = Libraries.Prguse2,
  956. Parent = this,
  957. PressedIndex = 362,
  958. Sound = SoundList.ButtonA,
  959. };
  960. CloseButton.Click += (o, e) => Hide();
  961. SenderNameLabel = new MirLabel
  962. {
  963. Parent = this,
  964. Font = new Font(Settings.FontName, 8F),
  965. ForeColour = Color.White,
  966. Location = new Point(70, 35),
  967. Size = new Size(150, 15),
  968. NotControl = true,
  969. };
  970. DateSentLabel = new MirLabel
  971. {
  972. Parent = this,
  973. Font = new Font(Settings.FontName, 8F),
  974. ForeColour = Color.White,
  975. Location = new Point(70, 56),
  976. Size = new Size(150, 15),
  977. NotControl = true,
  978. };
  979. MessageLabel = new MirLabel
  980. {
  981. ForeColour = Color.White,
  982. Parent = this,
  983. Font = new Font(Settings.FontName, 8F),
  984. Location = new Point(15, 98),
  985. Size = new Size(202, 165),
  986. };
  987. GoldSendLabel = new MirLabel
  988. {
  989. DrawFormat = TextFormatFlags.VerticalCenter,
  990. Font = new Font(Settings.FontName, 8F),
  991. Location = new Point(63, 290),
  992. Parent = this,
  993. Size = new Size(143, 15),
  994. };
  995. CollectButton = new MirButton
  996. {
  997. Index = 370,
  998. HoverIndex = 371,
  999. PressedIndex = 372,
  1000. Parent = this,
  1001. Library = Libraries.Title,
  1002. Sound = SoundList.ButtonA,
  1003. Location = new Point(30, 350)
  1004. };
  1005. CollectButton.Click += (o, e) =>
  1006. {
  1007. Network.Enqueue(new C.CollectParcel { MailID = Mail.MailID });
  1008. };
  1009. CancelButton = new MirButton
  1010. {
  1011. Index = 193,
  1012. HoverIndex = 194,
  1013. PressedIndex = 195,
  1014. Parent = this,
  1015. Library = Libraries.Title,
  1016. Sound = SoundList.ButtonA,
  1017. Location = new Point(135, 350)
  1018. };
  1019. CancelButton.Click += (o, e) => Hide();
  1020. }
  1021. public void ReadMail(ClientMail mail)
  1022. {
  1023. if (mail == null) return;
  1024. Mail = mail;
  1025. if (!Mail.Opened)
  1026. {
  1027. Network.Enqueue(new C.ReadMail { MailID = Mail.MailID });
  1028. }
  1029. ResetCells();
  1030. SenderNameLabel.Text = Mail.SenderName;
  1031. DateSentLabel.Text = Mail.DateSent.ToString("dd/MM/yy H:mm:ss");
  1032. MessageLabel.Text = Mail.Message.Replace("\\r\\n", "\r\n");
  1033. GoldSendLabel.Text = Mail.Gold.ToString("###,###,##0");
  1034. if (Mail.Items.Count > 0)
  1035. {
  1036. for (int i = 0; i < Cells.Length; i++)
  1037. {
  1038. if (i >= Mail.Items.Count) break;
  1039. Cells[i] = new MirItemCell
  1040. {
  1041. BorderColour = Color.Lime,
  1042. Size = new Size(35, 31),
  1043. GridType = MirGridType.Mail,
  1044. Library = Libraries.Items,
  1045. Parent = this,
  1046. Location = new Point(27 + (i * 36), 311),
  1047. ItemSlot = i,
  1048. Item = Mail.Items[i]
  1049. };
  1050. }
  1051. }
  1052. if (!Mail.Collected)
  1053. {
  1054. CollectButton.Index = 683;
  1055. CollectButton.HoverIndex = 684;
  1056. CollectButton.PressedIndex = 685;
  1057. CollectButton.Enabled = false;
  1058. }
  1059. else
  1060. {
  1061. CollectButton.Index = 680;
  1062. CollectButton.HoverIndex = 681;
  1063. CollectButton.PressedIndex = 682;
  1064. CollectButton.Enabled = true;
  1065. }
  1066. Visible = true;
  1067. }
  1068. public void ResetCells()
  1069. {
  1070. foreach (var item in Cells)
  1071. {
  1072. if (item == null) continue;
  1073. if (item.Item != null)
  1074. {
  1075. item.Item = null;
  1076. }
  1077. }
  1078. }
  1079. }
  1080. }