MirGameShopCell.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. using Client.MirGraphics;
  2. using Client.MirNetwork;
  3. using Client.MirScenes;
  4. using Client.MirSounds;
  5. using C = ClientPackets;
  6. namespace Client.MirControls
  7. {
  8. public sealed class GameShopCell : MirImageControl
  9. {
  10. public MirLabel nameLabel, typeLabel, goldLabel, gpLabel, stockLabel, StockLabel, countLabel;
  11. public GameShopItem Item;
  12. public UserItem ShowItem;
  13. Rectangle ItemDisplayArea;
  14. public MirButton BuyItem, PreviewItem;
  15. public MirImageControl ViewerBackground;
  16. public byte Quantity = 1;
  17. public MirButton quantityUp, quantityDown;
  18. public MirLabel quantity;
  19. public GameShopViewer Viewer;
  20. public GameShopCell()
  21. {
  22. Size = new Size(125, 146);
  23. Index = 750;
  24. Library = Libraries.Title;
  25. MouseLeave += (o, e) =>
  26. {
  27. GameScene.Scene.DisposeItemLabel();
  28. GameScene.HoverItem = null;
  29. ShowItem = null;
  30. };
  31. nameLabel = new MirLabel
  32. {
  33. Size = new Size(125, 15),
  34. DrawFormat = TextFormatFlags.HorizontalCenter,
  35. Location = new Point(0, 13),
  36. Parent = this,
  37. NotControl = true,
  38. Font = new Font(Settings.FontName, 8F),
  39. };
  40. goldLabel = new MirLabel
  41. {
  42. Size = new Size(95, 20),
  43. DrawFormat = TextFormatFlags.RightToLeft | TextFormatFlags.Right,
  44. Location = new Point(2, 102),
  45. Parent = this,
  46. NotControl = true,
  47. Font = new Font(Settings.FontName, 8F)
  48. };
  49. gpLabel = new MirLabel
  50. {
  51. Size = new Size(95, 20),
  52. DrawFormat = TextFormatFlags.RightToLeft | TextFormatFlags.Right,
  53. Location = new Point(2, 81),
  54. Parent = this,
  55. NotControl = true,
  56. Font = new Font(Settings.FontName, 8F)
  57. };
  58. StockLabel = new MirLabel
  59. {
  60. Size = new Size(40, 20),
  61. Location = new Point(53, 37),
  62. Parent = this,
  63. NotControl = true,
  64. ForeColour = Color.Gray,
  65. Font = new Font(Settings.FontName, 7F),
  66. Text = "STOCK:"
  67. };
  68. stockLabel = new MirLabel
  69. {
  70. Size = new Size(20, 20),
  71. DrawFormat = TextFormatFlags.HorizontalCenter,
  72. Location = new Point(93, 37),
  73. Parent = this,
  74. NotControl = true,
  75. Font = new Font(Settings.FontName, 7F),
  76. };
  77. countLabel = new MirLabel
  78. {
  79. Size = new Size(30, 20),
  80. DrawFormat = TextFormatFlags.Right,
  81. Location = new Point(16, 60),
  82. Parent = this,
  83. NotControl = true,
  84. Font = new Font(Settings.FontName, 7F),
  85. };
  86. BuyItem = new MirButton
  87. {
  88. Index = 778,
  89. HoverIndex = 779,
  90. PressedIndex = 780,
  91. Location = new Point(42, 122),
  92. Library = Libraries.Title,
  93. Parent = this,
  94. Sound = SoundList.ButtonA,
  95. };
  96. BuyItem.Click += (o, e) =>
  97. {
  98. BuyProduct();
  99. };
  100. PreviewItem = new MirButton
  101. {
  102. Index = 781,
  103. HoverIndex = 782,
  104. PressedIndex = 783,
  105. Location = new Point(8, 122),
  106. Library = Libraries.Title,
  107. Parent = this,
  108. Sound = SoundList.ButtonA,
  109. Visible = false,
  110. };
  111. PreviewItem.Click += (o, e) =>
  112. {
  113. GameScene.Scene.GameShopDialog.Viewer.Dispose();
  114. GameScene.Scene.GameShopDialog.Viewer = new GameShopViewer
  115. {
  116. Parent = GameScene.Scene.GameShopDialog,
  117. Visible = true,
  118. Location = this.Location.X < 350 ? new Point(416, 115) : new Point(151, 115),
  119. };
  120. GameScene.Scene.GameShopDialog.Viewer.ViewerItem = Item;
  121. GameScene.Scene.GameShopDialog.Viewer.UpdateViewer();
  122. };
  123. quantityUp = new MirButton
  124. {
  125. Index = 243,
  126. HoverIndex = 244,
  127. PressedIndex = 245,
  128. Library = Libraries.Prguse2,
  129. Parent = this,
  130. Location = new Point(97, 56),
  131. Sound = SoundList.ButtonA,
  132. };
  133. quantityUp.Click += (o, e) =>
  134. {
  135. if (CMain.Shift) Quantity += 10;
  136. else Quantity++;
  137. if (((decimal)(Quantity * Item.Count) / Item.Info.StackSize) > 5) Quantity = ((5 * Item.Info.StackSize) / Item.Count) > 99 ? Quantity = 99 : Quantity = (byte)((5 * Item.Info.StackSize) / Item.Count);
  138. if (Quantity >= 99) Quantity = 99;
  139. if (Item.Stock != 0 && Quantity > Item.Stock) Quantity = (byte)Item.Stock;
  140. };
  141. quantityDown = new MirButton
  142. {
  143. Index = 240,
  144. HoverIndex = 241,
  145. PressedIndex = 242,
  146. Library = Libraries.Prguse2,
  147. Parent = this,
  148. Location = new Point(55, 56),
  149. Sound = SoundList.ButtonA,
  150. };
  151. quantityDown.Click += (o, e) =>
  152. {
  153. if (CMain.Shift) Quantity -= 10;
  154. else Quantity--;
  155. if (Quantity <= 1 || Quantity > 99) Quantity = 1;
  156. };
  157. quantity = new MirLabel
  158. {
  159. Size = new Size(20, 13),
  160. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  161. Location = new Point(74, 56),
  162. Parent = this,
  163. NotControl = true,
  164. Font = new Font(Settings.FontName, 8F),
  165. };
  166. }
  167. public void BuyProduct()
  168. {
  169. uint CreditCost;
  170. uint GoldCost;
  171. MirMessageBox messageBox;
  172. int pType = -1;
  173. if (GameScene.Scene.GameShopDialog.PaymentTypeCredit.Checked && Item.CanBuyCredit)
  174. {
  175. pType = 0;
  176. }
  177. else if (GameScene.Scene.GameShopDialog.PaymentTypeGold.Checked && Item.CanBuyGold)
  178. {
  179. pType = 1;
  180. }
  181. if (pType == -1)
  182. {
  183. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouMustSelectPaymentType), ChatType.System);
  184. return;
  185. }
  186. switch (pType)
  187. {
  188. case 0: // Credit
  189. if (Item.CreditPrice * Quantity <= GameScene.Credit)
  190. {
  191. CreditCost = Item.CreditPrice * Quantity;
  192. messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ConfirmBuyItemCredits), Item.Info.FriendlyName, Quantity, CreditCost, Item.Count), MirMessageBoxButtons.YesNo);
  193. messageBox.YesButton.Click += (o, e) => Network.Enqueue(new C.GameshopBuy { GIndex = Item.GIndex, Quantity = Quantity, PType = pType });
  194. messageBox.NoButton.Click += (o, e) => { };
  195. messageBox.Show();
  196. }
  197. else
  198. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouCantAffordSelectedItem), ChatType.System);
  199. break;
  200. case 1: // Gold
  201. if (Item.GoldPrice * Quantity <= GameScene.Gold)
  202. {
  203. GoldCost = Item.GoldPrice * Quantity;
  204. messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ConfirmPurchaseItemGold), Item.Info.FriendlyName, Quantity, GoldCost, Item.Count), MirMessageBoxButtons.YesNo);
  205. messageBox.YesButton.Click += (o, e) => Network.Enqueue(new C.GameshopBuy { GIndex = Item.GIndex, Quantity = Quantity, PType = pType });
  206. messageBox.NoButton.Click += (o, e) => { };
  207. messageBox.Show();
  208. }
  209. else
  210. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouCantAffordSelectedItem), ChatType.System);
  211. break;
  212. default:
  213. return;
  214. }
  215. }
  216. public override void OnMouseMove(MouseEventArgs e)
  217. {
  218. base.OnMouseMove(e);
  219. if (GameScene.HoverItem != null && (Item.Info.Index != GameScene.HoverItem.Info.Index))
  220. {
  221. GameScene.Scene.DisposeItemLabel();
  222. GameScene.HoverItem = null;
  223. ShowItem = null;
  224. }
  225. if (ShowItem == null && ItemDisplayArea.Contains(CMain.MPoint))
  226. {
  227. ShowItem = new UserItem(Item.Info) { MaxDura = Item.Info.Durability, CurrentDura = Item.Info.Durability, Count = Item.Count };
  228. GameScene.Scene.CreateItemLabel(ShowItem);
  229. }
  230. else if (ShowItem != null && !ItemDisplayArea.Contains(CMain.MPoint))
  231. {
  232. GameScene.Scene.DisposeItemLabel();
  233. GameScene.HoverItem = null;
  234. ShowItem = null;
  235. }
  236. }
  237. public void UpdateText()
  238. {
  239. nameLabel.Text = Item.Info.FriendlyName;
  240. nameLabel.Text = nameLabel.Text.Length > 17 ? nameLabel.Text.Substring(0, 17) : nameLabel.Text;
  241. nameLabel.ForeColour = GameScene.Scene.GradeNameColor(Item.Info.Grade);
  242. if (Item.CanBuyGold)
  243. goldLabel.Text = (Item.GoldPrice * Quantity).ToString("###,###,##0");
  244. if (Item.CanBuyCredit)
  245. gpLabel.Text = (Item.CreditPrice * Quantity).ToString("###,###,##0");
  246. if (Item.Stock >= 99) stockLabel.Text = "99+";
  247. if (Item.Stock == 0) stockLabel.Text = "∞";
  248. else stockLabel.Text = Item.Stock.ToString();
  249. countLabel.Text = Item.Count.ToString();
  250. if (Item.Info.Type == ItemType.Mount || Item.Info.Type == ItemType.Weapon || Item.Info.Type == ItemType.Armour || Item.Info.Type == ItemType.Transform)
  251. {
  252. PreviewItem.Visible = true;
  253. BuyItem.Location = new Point(75, 122);
  254. }
  255. }
  256. protected internal override void DrawControl()
  257. {
  258. base.DrawControl();
  259. if (Item == null) return;
  260. UpdateText();
  261. Size size = Libraries.Items.GetTrueSize(Item.Info.Image);
  262. Point offSet = new Point((32 - size.Width) / 2, (32 - size.Height) / 2);
  263. Libraries.Items.Draw(Item.Info.Image, offSet.X + DisplayLocation.X + 12, offSet.Y + DisplayLocation.Y + 40);
  264. ItemDisplayArea = new Rectangle(new Point(offSet.X + DisplayLocation.X + 12, offSet.Y + DisplayLocation.Y + 40), size);
  265. }
  266. protected override void Dispose(bool disposing)
  267. {
  268. base.Dispose(disposing);
  269. Item = null;
  270. GameScene.HoverItem = null;
  271. ShowItem = null;
  272. }
  273. }
  274. public sealed class GameShopViewer : MirImageControl
  275. {
  276. public MirAnimatedControl PreviewImage, WeaponImage, WeaponImage2, MountImage;
  277. public int StartIndex = 0;
  278. public int Direction = 6;
  279. public GameShopItem ViewerItem;
  280. public MirButton RightDirection, LeftDirection, CloseButton;
  281. public GameShopViewer()
  282. {
  283. Index = 785;// 314;
  284. Library = Libraries.Title;// Libraries.Prguse2;
  285. Location = new Point(405, 108);
  286. BeforeDraw += GameShopViewer_BeforeDraw;
  287. //Click += (o, e) =>
  288. //{
  289. //Visible = false;
  290. //};
  291. CloseButton = new MirButton
  292. {
  293. HoverIndex = 362,
  294. Index = 361,
  295. Location = new Point(230, 8),
  296. Library = Libraries.Prguse,
  297. Parent = this,
  298. PressedIndex = 363,
  299. Sound = SoundList.ButtonA,
  300. };
  301. CloseButton.Click += (o, e) =>
  302. {
  303. Visible = false;
  304. };
  305. WeaponImage = new MirAnimatedControl
  306. {
  307. Animated = false,
  308. Location = new Point(105, 160),
  309. AnimationCount = 6,
  310. AnimationDelay = 150,
  311. Index = 0,
  312. Library = Libraries.Prguse,
  313. Loop = true,
  314. Parent = this,
  315. UseOffSet = true,
  316. NotControl = true,
  317. };
  318. WeaponImage2 = new MirAnimatedControl
  319. {
  320. Animated = false,
  321. Location = new Point(105, 160),
  322. AnimationCount = 6,
  323. AnimationDelay = 150,
  324. Index = 0,
  325. Library = Libraries.Prguse,
  326. Loop = true,
  327. Parent = this,
  328. UseOffSet = true,
  329. NotControl = true,
  330. };
  331. MountImage = new MirAnimatedControl
  332. {
  333. Animated = false,
  334. Location = new Point(105, 160),
  335. AnimationCount = 8,
  336. AnimationDelay = 150,
  337. Index = 0,
  338. Library = Libraries.Prguse,
  339. Loop = true,
  340. Parent = this,
  341. UseOffSet = true,
  342. NotControl = true,
  343. };
  344. PreviewImage = new MirAnimatedControl
  345. {
  346. Animated = false,
  347. Location = new Point(105, 160),
  348. AnimationCount = 6,
  349. AnimationDelay = 150,
  350. Index = 0,
  351. Library = Libraries.Prguse,
  352. Loop = true,
  353. Parent = this,
  354. UseOffSet = true,
  355. NotControl = true,
  356. };
  357. RightDirection = new MirButton
  358. {
  359. Index = 243,
  360. HoverIndex = 244,
  361. PressedIndex = 245,
  362. Library = Libraries.Prguse2,
  363. Parent = this,
  364. Location = new Point(160, 282),
  365. Sound = SoundList.ButtonA,
  366. };
  367. RightDirection.Click += (o, e) =>
  368. {
  369. Direction++;
  370. if (Direction > 8) Direction = 1;
  371. UpdateViewer();
  372. };
  373. LeftDirection = new MirButton
  374. {
  375. Index = 240,
  376. HoverIndex = 241,
  377. PressedIndex = 242,
  378. Library = Libraries.Prguse2,
  379. Parent = this,
  380. Location = new Point(81, 282),
  381. Sound = SoundList.ButtonA,
  382. };
  383. LeftDirection.Click += (o, e) =>
  384. {
  385. Direction--;
  386. if (Direction == 0) Direction = 8;
  387. UpdateViewer();
  388. };
  389. }
  390. public void UpdateViewer()
  391. {
  392. this.Visible = true;
  393. if (ViewerItem.Info.Type == ItemType.Weapon) DrawWeapon();
  394. if (ViewerItem.Info.Type == ItemType.Armour) DrawArmour();
  395. if (ViewerItem.Info.Type == ItemType.Mount) DrawMount();
  396. if (ViewerItem.Info.Type == ItemType.Transform) DrawTransform();
  397. }
  398. private void GameShopViewer_BeforeDraw(object sender, EventArgs e)
  399. {
  400. BringToFront();
  401. }
  402. private void DrawMount()
  403. {
  404. WeaponImage.Visible = false;
  405. WeaponImage2.Visible = false;
  406. if (GameScene.User.Equipment[(int)EquipmentSlot.Armour] != null)
  407. PreviewImage.Library = Libraries.CArmours[GameScene.User.Equipment[(int)EquipmentSlot.Armour].Info.Shape];
  408. else
  409. PreviewImage.Library = Libraries.CArmours[0];
  410. if (GameScene.User.Gender == MirGender.Male)
  411. PreviewImage.Index = 448 + (8 * (Direction - 1));
  412. else
  413. PreviewImage.Index = 1256 + (8 * (Direction - 1));
  414. PreviewImage.AnimationCount = 8;
  415. MountImage.Library = Libraries.Mounts[ViewerItem.Info.Shape];
  416. MountImage.Index = 32 + (8 * (Direction - 1));
  417. PreviewImage.Animated = true;
  418. MountImage.Animated = true;
  419. MountImage.Visible = true;
  420. }
  421. private void DrawWeapon()
  422. {
  423. MountImage.Visible = false;
  424. if (GameScene.User.Equipment[(int)EquipmentSlot.Armour] != null)
  425. PreviewImage.Library = Libraries.CArmours[GameScene.User.Equipment[(int)EquipmentSlot.Armour].Info.Shape];
  426. else
  427. PreviewImage.Library = Libraries.CArmours[0];
  428. if (GameScene.User.Gender == MirGender.Male)
  429. PreviewImage.Index = 32 + (6 * (Direction - 1));
  430. else
  431. PreviewImage.Index = 840 + (6 * (Direction - 1));
  432. if (Direction > 1 && Direction < 5)
  433. WeaponImage.BringToFront();
  434. else
  435. PreviewImage.BringToFront();
  436. if (ViewerItem.Info.Shape >= 100 && ViewerItem.Info.Shape <= 199)
  437. {
  438. WeaponImage.Library = Libraries.AWeaponsR[ViewerItem.Info.Shape - 100];
  439. WeaponImage2.Library = Libraries.AWeaponsL[ViewerItem.Info.Shape - 100];
  440. WeaponImage2.Visible = true;
  441. WeaponImage2.Index = 32 + (6 * (Direction - 1));
  442. if (Direction >= 2 && Direction <= 3)
  443. {
  444. WeaponImage2.BringToFront();
  445. PreviewImage.BringToFront();
  446. WeaponImage.BringToFront();
  447. }
  448. else if (Direction == 8 || Direction == 7)
  449. {
  450. WeaponImage.BringToFront();
  451. PreviewImage.BringToFront();
  452. WeaponImage2.BringToFront();
  453. }
  454. else
  455. {
  456. WeaponImage.BringToFront();
  457. PreviewImage.BringToFront();
  458. }
  459. }
  460. else
  461. {
  462. WeaponImage2.Visible = false;
  463. }
  464. if (ViewerItem.Info.Shape >= 200)
  465. {
  466. WeaponImage.Library = Libraries.ARWeapons[ViewerItem.Info.Shape - 200];
  467. if (Direction >= 6 && Direction <= 8)
  468. {
  469. PreviewImage.BringToFront();
  470. WeaponImage.BringToFront();
  471. }
  472. }
  473. if (ViewerItem.Info.Shape < 100) WeaponImage.Library = Libraries.CWeapons[ViewerItem.Info.Shape];
  474. WeaponImage.Index = 32 + (6 * (Direction - 1));
  475. PreviewImage.AnimationCount = 6;
  476. PreviewImage.Animated = true;
  477. WeaponImage2.Animated = true;
  478. WeaponImage.Animated = true;
  479. WeaponImage.Visible = true;
  480. }
  481. private void DrawArmour()
  482. {
  483. WeaponImage.Visible = false;
  484. WeaponImage2.Visible = false;
  485. MountImage.Visible = false;
  486. if (ViewerItem.Info.RequiredGender == RequiredGender.Male)
  487. PreviewImage.Index = 32 + (6 * (Direction - 1));
  488. else
  489. PreviewImage.Index = 840 + (6 * (Direction - 1));
  490. PreviewImage.Library = Libraries.CArmours[ViewerItem.Info.Shape];
  491. PreviewImage.AnimationCount = 6;
  492. PreviewImage.Animated = true;
  493. }
  494. private void DrawTransform()
  495. {
  496. WeaponImage.Visible = false;
  497. WeaponImage2.Visible = false;
  498. MountImage.Visible = false;
  499. PreviewImage.Index = 32 + (6 * (Direction - 1));
  500. PreviewImage.Library = Libraries.Transform[ViewerItem.Info.Shape];
  501. PreviewImage.AnimationCount = 6;
  502. PreviewImage.Animated = true;
  503. }
  504. private void DrawMask()
  505. {
  506. }
  507. }
  508. }