TrustMerchantDialog.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirNetwork;
  4. using Client.MirSounds;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8. using C = ClientPackets;
  9. namespace Client.MirScenes.Dialogs
  10. {
  11. public sealed class TrustMerchantDialog : MirImageControl
  12. {
  13. public static bool UserMode = false;
  14. public static MarketPanelType MarketType;
  15. public uint Amount = 0,
  16. MinConsignAmount = Globals.MinConsignment, MaxConsignAmount = Globals.MaxConsignment,
  17. MinBidAmount = Globals.MinStartingBid, MaxBidAmount = Globals.MaxStartingBid;
  18. public static long SearchTime, MarketTime;
  19. public MirTextBox SearchTextBox, PriceTextBox;
  20. public MirButton FindButton, RefreshButton, MailButton, BuyButton, SellNowButton, CollectSoldButton, CloseButton, NextButton, BackButton;
  21. public MirImageControl TitleLabel;
  22. public MirLabel ItemLabel, PriceLabel, SellerLabel, PageLabel;
  23. public MirLabel DateLabel, ExpireLabel;
  24. public MirLabel NameLabel, TotalPriceLabel, SplitPriceLabel;
  25. public MirLabel HelpLabel;
  26. public MirLabel TitleSalePriceLabel, TitleSellLabel, TitleItemLabel, TitlePriceLabel, TitleExpiryLabel;
  27. public MirItemCell ItemCell, tempCell;
  28. public static UserItem SellItemSlot;
  29. public MirButton SellItemButton;
  30. public List<ClientAuction> Listings = new List<ClientAuction>();
  31. public List<ClientAuction> GameShopListings = new List<ClientAuction>();
  32. public int Page, PageCount;
  33. public static AuctionRow Selected;
  34. public AuctionRow[] Rows = new AuctionRow[10];
  35. public MirButton UpButton, DownButton, PositionBar;
  36. public MirButton MarketButton, ConsignmentButton, AuctionButton, GameShopButton;
  37. public MirImageControl FilterBox, FilterBackground;
  38. private MarketPriceFilter PriceFilter = MarketPriceFilter.Normal;
  39. private MirImageControl PriceFilterIcon;
  40. private readonly string consignmentText = string.Format(
  41. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ConsignmentRules),
  42. Globals.ConsignmentCost,
  43. Globals.ConsignmentLength,
  44. Globals.MinConsignment,
  45. Globals.MaxConsignment
  46. );
  47. private readonly string auctionText = string.Format(
  48. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AuctionRules),
  49. Globals.AuctionCost,
  50. Globals.MaxStartingBid,
  51. Globals.ConsignmentLength
  52. );
  53. private MirLabel TotalGold;
  54. public List<Filter> Filters = new List<Filter>();
  55. List<MirButton> FilterButtons = new List<MirButton>();
  56. List<MirLabel> FilterLabels = new List<MirLabel>();
  57. private int Skip = 0;
  58. private int MaxLines = 19;
  59. private int SelectedIndex = -1;
  60. private int SelectedSubIndex = -1;
  61. private int PossibleTotal = 0;
  62. private int PosX, PosMinY, PosMaxY;
  63. NumberFormatInfo nfi = new NumberFormatInfo
  64. {
  65. NumberGroupSeparator = ",",
  66. NumberGroupSizes = new[] { 3 },
  67. NumberDecimalDigits = 0
  68. };
  69. public TrustMerchantDialog()
  70. {
  71. Index = 786;
  72. Library = Libraries.Title;
  73. Sort = true;
  74. Movable = true;
  75. Size = new Size(492, 478);
  76. #region TrustMerchant Buttons
  77. MarketButton = new MirButton
  78. {
  79. Index = 789,
  80. PressedIndex = 788,
  81. Library = Libraries.Title,
  82. Location = new Point(9, 35),
  83. Parent = this,
  84. };
  85. MarketButton.Click += (o, e) =>
  86. {
  87. TMerchantDialog(MarketPanelType.Market);
  88. if (tempCell != null)
  89. {
  90. tempCell.Locked = false;
  91. SellItemSlot = null;
  92. tempCell = null;
  93. }
  94. };
  95. ConsignmentButton = new MirButton
  96. {
  97. Index = 791,
  98. PressedIndex = 790,
  99. Library = Libraries.Title,
  100. Location = new Point(104, 35),
  101. Parent = this,
  102. Visible = true,
  103. };
  104. ConsignmentButton.Click += (o, e) =>
  105. {
  106. TMerchantDialog(MarketPanelType.Consign);
  107. };
  108. AuctionButton = new MirButton
  109. {
  110. Index = 817,
  111. PressedIndex = 816,
  112. Library = Libraries.Title,
  113. Location = new Point(199, 35),
  114. Parent = this,
  115. Visible = true,
  116. };
  117. AuctionButton.Click += (o, e) =>
  118. {
  119. TMerchantDialog(MarketPanelType.Auction);
  120. };
  121. GameShopButton = new MirButton
  122. {
  123. Index = 819,
  124. PressedIndex = 818,
  125. Library = Libraries.Title,
  126. Location = new Point(389, 35),
  127. Parent = this,
  128. Visible = true,
  129. };
  130. GameShopButton.Click += (o, e) =>
  131. {
  132. TMerchantDialog(MarketPanelType.GameShop);
  133. };
  134. CloseButton = new MirButton
  135. {
  136. Index = 360,
  137. HoverIndex = 361,
  138. PressedIndex = 362,
  139. Location = new Point(465, 3),
  140. Library = Libraries.Prguse2,
  141. Sound = SoundList.ButtonA,
  142. Parent = this,
  143. };
  144. CloseButton.Click += (o, e) => Hide();
  145. #region Page Buttons & Label
  146. HelpLabel = new MirLabel
  147. {
  148. Text = consignmentText,
  149. Parent = this,
  150. Size = new Size(115, 205),
  151. Location = new Point(8, 237),
  152. Font = new Font(Settings.FontName, Settings.FontSize - 1),
  153. ForeColour = Color.White,
  154. Visible = false
  155. };
  156. BackButton = new MirButton
  157. {
  158. Index = 240,
  159. HoverIndex = 241,
  160. PressedIndex = 242,
  161. Library = Libraries.Prguse2,
  162. Location = new Point(251, 419),
  163. Sound = SoundList.ButtonA,
  164. Parent = this,
  165. };
  166. BackButton.Click += (o, e) =>
  167. {
  168. if (Page <= 0) return;
  169. Page--;
  170. UpdateInterface();
  171. };
  172. NextButton = new MirButton
  173. {
  174. Index = 243,
  175. HoverIndex = 244,
  176. PressedIndex = 245,
  177. Library = Libraries.Prguse2,
  178. Location = new Point(320, 419),
  179. Sound = SoundList.ButtonA,
  180. Parent = this,
  181. };
  182. NextButton.Click += (o, e) =>
  183. {
  184. if (Page >= PageCount - 1) return;
  185. if (Page < (Listings.Count - 1) / 10)
  186. {
  187. Page++;
  188. UpdateInterface();
  189. return;
  190. }
  191. Network.Enqueue(new C.MarketPage { Page = Page + 1 });
  192. };
  193. PageLabel = new MirLabel
  194. {
  195. Size = new Size(70, 18),
  196. Location = new Point(260, 419),
  197. DrawFormat = TextFormatFlags.HorizontalCenter,
  198. Text = "0/0",
  199. NotControl = true,
  200. Parent = this,
  201. };
  202. UpButton = new MirButton
  203. {
  204. Index = 197,
  205. HoverIndex = 198,
  206. PressedIndex = 199,
  207. Library = Libraries.Prguse2,
  208. Parent = this,
  209. Size = new Size(16, 14),
  210. Location = new Point(108, 60),
  211. Sound = SoundList.ButtonA,
  212. Visible = true
  213. };
  214. UpButton.Click += (o, e) =>
  215. {
  216. if (Skip <= 0) return;
  217. Skip--;
  218. UpdatePositionBar();
  219. DrawFilters(SelectedIndex, SelectedSubIndex);
  220. };
  221. DownButton = new MirButton
  222. {
  223. Index = 207,
  224. HoverIndex = 208,
  225. Library = Libraries.Prguse2,
  226. PressedIndex = 209,
  227. Parent = this,
  228. Size = new Size(16, 14),
  229. Location = new Point(108, 429),
  230. Sound = SoundList.ButtonA,
  231. Visible = true
  232. };
  233. DownButton.Click += (o, e) =>
  234. {
  235. if (Skip + MaxLines >= PossibleTotal) return;
  236. Skip++;
  237. UpdatePositionBar();
  238. DrawFilters(SelectedIndex, SelectedSubIndex);
  239. };
  240. PositionBar = new MirButton
  241. {
  242. Index = 205,
  243. HoverIndex = 206,
  244. PressedIndex = 206,
  245. Library = Libraries.Prguse2,
  246. Location = new Point(108, 73),
  247. Parent = this,
  248. Movable = true,
  249. Sound = SoundList.None,
  250. Visible = false
  251. };
  252. PosX = PositionBar.Location.X;
  253. PosMinY = UpButton.Location.Y + 13;
  254. PosMaxY = DownButton.Location.Y - 19;
  255. PositionBar.OnMoving += PositionBar_OnMoving;
  256. #endregion
  257. #endregion
  258. SetupFilters();
  259. #region Market Buttons
  260. MailButton = new MirButton
  261. {
  262. Index = 437,
  263. HoverIndex = 438,
  264. PressedIndex = 439,
  265. Library = Libraries.Prguse,
  266. Location = new Point(350, 448),
  267. Sound = SoundList.ButtonA,
  268. Parent = this,
  269. };
  270. MailButton.Click += (o, e) =>
  271. {
  272. if (Selected == null || CMain.Time < MarketTime) return;
  273. string message = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.InterestedInPurchase), Selected.Listing.Item.FriendlyName, Selected.Listing.Price);
  274. GameScene.Scene.MailComposeLetterDialog.ComposeMail(Selected.Listing.Seller, message);
  275. };
  276. RefreshButton = new MirButton
  277. {
  278. Index = 663,
  279. HoverIndex = 664,
  280. PressedIndex = 665,
  281. Library = Libraries.Prguse,
  282. Location = new Point(320, 448),
  283. Sound = SoundList.ButtonA,
  284. Parent = this,
  285. };
  286. RefreshButton.Click += (o, e) =>
  287. {
  288. if (CMain.Time < SearchTime)
  289. {
  290. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.YouCanSearchAgain), Math.Ceiling((SearchTime - CMain.Time) / 1000D)), ChatType.System);
  291. return;
  292. }
  293. SearchTime = CMain.Time + Globals.SearchDelay;
  294. SearchTextBox.Text = string.Empty;
  295. Network.Enqueue(new C.MarketRefresh());
  296. };
  297. BuyButton = new MirButton
  298. {
  299. Index = 703,
  300. HoverIndex = 704,
  301. PressedIndex = 705,
  302. Library = Libraries.Title,
  303. Location = new Point(380, 448),
  304. Sound = SoundList.ButtonA,
  305. Parent = this,
  306. };
  307. BuyButton.Click += (o, e) =>
  308. {
  309. if (Selected == null || CMain.Time < MarketTime) return;
  310. if (UserMode)
  311. {
  312. if (Selected.Listing.ItemType == MarketItemType.Consign)
  313. {
  314. if (Selected.Listing.Seller == "For Sale")
  315. {
  316. MirMessageBox box = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ItemNotSoldGetBack), Selected.Listing.Item.FriendlyName), MirMessageBoxButtons.YesNo);
  317. box.YesButton.Click += (o1, e2) =>
  318. {
  319. MarketTime = CMain.Time + 3000;
  320. Network.Enqueue(new C.MarketGetBack { AuctionID = Selected.Listing.AuctionID });
  321. };
  322. box.Show();
  323. }
  324. else
  325. {
  326. MarketTime = CMain.Time + 3000;
  327. Network.Enqueue(new C.MarketGetBack { AuctionID = Selected.Listing.AuctionID });
  328. }
  329. }
  330. else if (Selected.Listing.ItemType == MarketItemType.Auction)
  331. {
  332. if (Selected.Listing.Seller == "No Bid")
  333. {
  334. MirMessageBox box = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ItemNotSoldConfirmRetrieve), Selected.Listing.Item.FriendlyName), MirMessageBoxButtons.YesNo);
  335. box.YesButton.Click += (o1, e2) =>
  336. {
  337. MarketTime = CMain.Time + 3000;
  338. Network.Enqueue(new C.MarketGetBack { AuctionID = Selected.Listing.AuctionID });
  339. };
  340. box.Show();
  341. }
  342. else
  343. {
  344. MarketTime = CMain.Time + 3000;
  345. Network.Enqueue(new C.MarketGetBack { AuctionID = Selected.Listing.AuctionID });
  346. }
  347. }
  348. }
  349. else
  350. {
  351. switch (Selected.Listing.ItemType)
  352. {
  353. case MarketItemType.Consign:
  354. case MarketItemType.GameShop:
  355. {
  356. MirMessageBox box = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ConfirmBuyItemWithPrice), Selected.Listing.Item.FriendlyName, Selected.Listing.Price, MarketType == MarketPanelType.GameShop ? GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Credits) : GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Gold)), MirMessageBoxButtons.YesNo);
  357. box.YesButton.Click += (o1, e2) =>
  358. {
  359. MarketTime = CMain.Time + 3000;
  360. Network.Enqueue(new C.MarketBuy { AuctionID = Selected.Listing.AuctionID });
  361. };
  362. box.Show();
  363. }
  364. break;
  365. case MarketItemType.Auction:
  366. {
  367. MirAmountBox bidAmount = new MirAmountBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BidAmount), Selected.Listing.Item.Info.Image, uint.MaxValue, Selected.Listing.Price + 1, Selected.Listing.Price + 1);
  368. bidAmount.OKButton.Click += (o1, e1) =>
  369. {
  370. MirMessageBox box = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ConfirmBidGoldForItem), bidAmount.Amount, Selected.Listing.Item.FriendlyName), MirMessageBoxButtons.YesNo);
  371. box.YesButton.Click += (o2, e2) =>
  372. {
  373. MarketTime = CMain.Time + 3000;
  374. Network.Enqueue(new C.MarketBuy { AuctionID = Selected.Listing.AuctionID, BidPrice = bidAmount.Amount });
  375. };
  376. box.Show();
  377. };
  378. bidAmount.Show();
  379. }
  380. break;
  381. }
  382. }
  383. };
  384. SellNowButton = new MirButton
  385. {
  386. Index = 700,
  387. HoverIndex = 701,
  388. PressedIndex = 702,
  389. Library = Libraries.Title,
  390. Location = new Point(324, 448),
  391. Sound = SoundList.ButtonA,
  392. Parent = this,
  393. };
  394. SellNowButton.Click += (o, e) =>
  395. {
  396. if (Selected == null || CMain.Time < MarketTime) return;
  397. MarketTime = CMain.Time + 3000;
  398. Network.Enqueue(new C.MarketSellNow { AuctionID = Selected.Listing.AuctionID });
  399. };
  400. CollectSoldButton = new MirButton
  401. {
  402. Index = 680,
  403. HoverIndex = 681,
  404. PressedIndex = 682,
  405. Library = Libraries.Title,
  406. Location = new Point(300, 448),
  407. Sound = SoundList.ButtonA,
  408. Parent = this,
  409. };
  410. CollectSoldButton.Click += (o, e) =>
  411. {
  412. if (CMain.Time < MarketTime) return;
  413. if (UserMode)
  414. {
  415. MarketTime = CMain.Time + 3000;
  416. Network.Enqueue(new C.MarketGetBack { Mode = MarketCollectionMode.Sold, AuctionID = 0 });
  417. Network.Enqueue(new C.MarketRefresh());
  418. }
  419. };
  420. #endregion
  421. #region Search
  422. SearchTextBox = new MirTextBox
  423. {
  424. //Location = new Point(174, 452),
  425. //Location = new Point(240, 451),
  426. Location = new Point(11, 452),
  427. Size = new Size(110, 18),
  428. MaxLength = 20,
  429. Parent = this,
  430. CanLoseFocus = true,
  431. };
  432. SearchTextBox.TextBox.KeyPress += SearchTextBox_KeyPress;
  433. SearchTextBox.TextBox.KeyUp += SearchTextBox_KeyUp;
  434. SearchTextBox.TextBox.KeyDown += SearchTextBox_KeyDown;
  435. FindButton = new MirButton
  436. {
  437. Index = 480,
  438. HoverIndex = 481,
  439. PressedIndex = 482,
  440. Library = Libraries.Title,
  441. Location = new Point(124, 448),
  442. Sound = SoundList.ButtonA,
  443. Parent = this,
  444. };
  445. FindButton.Click += (o, e) =>
  446. {
  447. if (String.IsNullOrEmpty(SearchTextBox.Text)) return;
  448. if (CMain.Time < SearchTime)
  449. {
  450. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.SearchAgainAfterSeconds), Math.Ceiling((SearchTime - CMain.Time) / 1000D)), ChatType.System);
  451. return;
  452. }
  453. SearchTime = CMain.Time + Globals.SearchDelay;
  454. Network.Enqueue(new C.MarketSearch
  455. {
  456. Match = SearchTextBox.Text,
  457. MarketType = MarketType
  458. });
  459. };
  460. #endregion
  461. #region Gold Label
  462. TotalGold = new MirLabel
  463. {
  464. Size = new Size(120, 16),
  465. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  466. Location = new Point(6, 451),
  467. Parent = this,
  468. NotControl = true,
  469. Font = new Font(Settings.FontName, Settings.FontSize),
  470. Visible = false
  471. };
  472. #endregion
  473. #region ItemCell
  474. ItemCell = new MirItemCell
  475. {
  476. BorderColour = Color.Lime,
  477. GridType = MirGridType.TrustMerchant,
  478. Library = Libraries.Items,
  479. Parent = this,
  480. Location = new Point(47, 104),
  481. ItemSlot = 0,
  482. Visible = false
  483. };
  484. ItemCell.Click += (o, e) => ItemCell_Click();
  485. PriceTextBox = new MirTextBox
  486. {
  487. Location = new Point(15, 165),
  488. Size = new Size(100, 18),
  489. MaxLength = 20,
  490. Parent = this,
  491. CanLoseFocus = true,
  492. Visible = false,
  493. };
  494. PriceTextBox.TextBox.TextChanged += TextBox_TextChanged;
  495. PriceTextBox.TextBox.KeyPress += MirInputBox_KeyPress;
  496. SellItemButton = new MirButton
  497. {
  498. Index = 700,
  499. PressedIndex = 702,
  500. HoverIndex = 701,
  501. Library = Libraries.Title,
  502. Sound = SoundList.ButtonA,
  503. Location = new Point(39, 188),
  504. Parent = this,
  505. Visible = false,
  506. Enabled = false
  507. };
  508. SellItemButton.Click += (o, e) =>
  509. {
  510. Network.Enqueue(new C.ConsignItem { UniqueID = SellItemSlot.UniqueID, Price = Amount, Type = MarketType });
  511. SellItemSlot = null;
  512. PriceTextBox.Text = null;
  513. SellItemButton.Enabled = false;
  514. TMerchantDialog(MarketType);
  515. };
  516. #endregion
  517. #region Auction Rows
  518. for (int i = 0; i < Rows.Length; i++)
  519. {
  520. Rows[i] = new AuctionRow
  521. {
  522. Location = new Point(127, 82 + i * 33),
  523. Parent = this
  524. };
  525. Rows[i].Click += (o, e) =>
  526. {
  527. Selected = (AuctionRow)o;
  528. UpdateInterface();
  529. };
  530. }
  531. #endregion
  532. #region Labels
  533. TitleSalePriceLabel = new MirLabel
  534. {
  535. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SalePrice),
  536. Parent = this,
  537. Font = new Font(Settings.FontName, Settings.FontSize - 1, FontStyle.Italic),
  538. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  539. Size = new Size(100, 21),
  540. Location = new Point(15, 142)
  541. };
  542. TitleSellLabel = new MirLabel
  543. {
  544. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SellItem),
  545. Parent = this,
  546. Font = new Font(Settings.FontName, Settings.FontSize - 1, FontStyle.Italic),
  547. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  548. Size = new Size(110, 21),
  549. Location = new Point(10, 60)
  550. };
  551. TitleItemLabel = new MirLabel
  552. {
  553. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Item),
  554. Parent = this,
  555. Font = new Font(Settings.FontName, Settings.FontSize - 1, FontStyle.Italic),
  556. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  557. Size = new Size(166, 21),
  558. Location = new Point(127, 60)
  559. };
  560. TitlePriceLabel = new MirLabel
  561. {
  562. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Price),
  563. Parent = this,
  564. Font = new Font(Settings.FontName, Settings.FontSize - 1, FontStyle.Italic),
  565. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  566. Size = new Size(88, 21),
  567. Location = new Point(295, 60)
  568. };
  569. TitlePriceLabel.Click += (o, e) => CyclePriceFilter();
  570. PriceFilterIcon = new MirImageControl
  571. {
  572. Library = Libraries.Prguse2,
  573. Index = 926,
  574. Location = new Point(TitlePriceLabel.Location.X + TitlePriceLabel.Size.Width - 12, TitlePriceLabel.Location.Y + (TitlePriceLabel.Size.Height - 14) / 2 + 2),
  575. Parent = this,
  576. Visible = false
  577. };
  578. PriceFilterIcon.Click += (o, e) => CyclePriceFilter();
  579. TitleExpiryLabel = new MirLabel
  580. {
  581. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Expiry),
  582. Parent = this,
  583. Font = new Font(Settings.FontName, Settings.FontSize - 1, FontStyle.Italic),
  584. DrawFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter,
  585. Size = new Size(98, 21),
  586. Location = new Point(384, 60)
  587. };
  588. #endregion
  589. UpdatePriceFilterIcon();
  590. }
  591. private void SetupFilters()
  592. {
  593. var all = new Filter { Index = 0, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ShowAllItems), Type = ItemType.Nothing };
  594. var weapon = new Filter { Index = 1, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.WeaponItems), Type = ItemType.Weapon };
  595. var drapery = new Filter { Index = 2, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.DraperyItems), Type = null };
  596. var accessory = new Filter { Index = 3, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccessoryItems), Type = null };
  597. var consumable = new Filter { Index = 4, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ConsumableItems), Type = null };
  598. var enhancement = new Filter { Index = 5, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Enhancement), Type = null };
  599. var book = new Filter { Index = 6, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Books), Type = null };
  600. var crafting = new Filter { Index = 7, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CraftItems), Type = null };
  601. Filters.Add(all);
  602. Filters.Add(weapon);
  603. Filters.Add(drapery);
  604. Filters.Add(accessory);
  605. Filters.Add(consumable);
  606. Filters.Add(enhancement);
  607. Filters.Add(book);
  608. Filters.Add(crafting);
  609. drapery.SubFilters.Add(new Filter { Index = 201, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Armour), Type = ItemType.Armour });
  610. drapery.SubFilters.Add(new Filter { Index = 202, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Helmet), Type = ItemType.Helmet });
  611. drapery.SubFilters.Add(new Filter { Index = 203, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Belt), Type = ItemType.Belt });
  612. drapery.SubFilters.Add(new Filter { Index = 204, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Boots), Type = ItemType.Boots });
  613. drapery.SubFilters.Add(new Filter { Index = 205, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Stone), Type = ItemType.Stone });
  614. accessory.SubFilters.Add(new Filter { Index = 301, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Necklaces), Type = ItemType.Necklace });
  615. accessory.SubFilters.Add(new Filter { Index = 302, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Bracelets), Type = ItemType.Bracelet });
  616. accessory.SubFilters.Add(new Filter { Index = 303, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Rings), Type = ItemType.Ring });
  617. consumable.SubFilters.Add(new Filter { Index = 401, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.RecoveryPots), Type = ItemType.Potion, MaxShape = 2 });
  618. consumable.SubFilters.Add(new Filter { Index = 402, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BuffPots), Type = ItemType.Potion, MinShape = 3, MaxShape = 4 });
  619. consumable.SubFilters.Add(new Filter { Index = 403, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ScrollsOils), Type = ItemType.Scroll });
  620. consumable.SubFilters.Add(new Filter { Index = 404, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MiscItems), Type = ItemType.Script });
  621. enhancement.SubFilters.Add(new Filter { Index = 501, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Gems), Type = ItemType.Potion, MinShape = 3, MaxShape = 3 });
  622. enhancement.SubFilters.Add(new Filter { Index = 502, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Orbs), Type = ItemType.Potion, MinShape = 4, MaxShape = 4 });
  623. book.SubFilters.Add(new Filter { Index = 601, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Warrior), Type = ItemType.Book, MaxShape = 30 });
  624. book.SubFilters.Add(new Filter { Index = 602, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Wizard), Type = ItemType.Book, MinShape = 31, MaxShape = 60 });
  625. book.SubFilters.Add(new Filter { Index = 603, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Taoist), Type = ItemType.Book, MinShape = 61, MaxShape = 90 });
  626. book.SubFilters.Add(new Filter { Index = 604, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Assassin), Type = ItemType.Book, MinShape = 91, MaxShape = 120 });
  627. book.SubFilters.Add(new Filter { Index = 605, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Archer), Type = ItemType.Book, MinShape = 121, MaxShape = 150 });
  628. crafting.SubFilters.Add(new Filter { Index = 701, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Materials), Type = ItemType.CraftingMaterial });
  629. crafting.SubFilters.Add(new Filter { Index = 703, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Meat), Type = ItemType.Meat });
  630. crafting.SubFilters.Add(new Filter { Index = 704, Title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Ore), Type = ItemType.Ore });
  631. }
  632. private void DrawFilters(int index, int subIndex)
  633. {
  634. SelectedIndex = index;
  635. SelectedSubIndex = subIndex;
  636. int btnx = 7;
  637. int btny = 60;
  638. int current = 0;
  639. int skipped = Skip;
  640. //Dispose all buttons and labels
  641. foreach (var item in FilterButtons)
  642. item.Dispose();
  643. foreach (var item in FilterLabels)
  644. item.Dispose();
  645. FilterButtons.Clear();
  646. FilterLabels.Clear();
  647. PossibleTotal = Filters.Count;
  648. foreach (var item in Filters)
  649. {
  650. if (skipped > 0)
  651. {
  652. skipped--;
  653. continue;
  654. }
  655. if (current >= MaxLines)
  656. {
  657. break;
  658. }
  659. current++;
  660. var btn = new MirButton
  661. {
  662. Index = 920,
  663. PressedIndex = 921,
  664. HoverIndex = 921,
  665. Library = Libraries.Prguse2,
  666. Sound = SoundList.ButtonA,
  667. Location = new Point(btnx, btny),
  668. Parent = this,
  669. };
  670. btn.Click += (o, e) =>
  671. {
  672. if (item.SubFilters.Any())
  673. {
  674. DrawFilters(item.Index, -1);
  675. }
  676. else
  677. {
  678. DrawFilters(item.Index, -1);
  679. if (item.Type.HasValue)
  680. {
  681. Network.Enqueue(new C.MarketSearch { Match = SearchTextBox.Text, Type = item.Type.Value, Usermode = false, MinShape = item.MinShape, MaxShape = item.MaxShape, MarketType = MarketType });
  682. }
  683. }
  684. };
  685. var lbl = new MirLabel
  686. {
  687. Size = new Size(99, 18),
  688. Location = new Point(2, 1),
  689. Parent = btn,
  690. Text = item.Title,
  691. NotControl = true,
  692. };
  693. btny += 20;
  694. FilterButtons.Add(btn);
  695. FilterLabels.Add(lbl);
  696. if (item.Index == index)
  697. {
  698. PossibleTotal += item.SubFilters.Count;
  699. btn.Index = 921;
  700. //btny += 2;
  701. if (item.SubFilters.Any())
  702. {
  703. btny += 2;
  704. }
  705. foreach (var subItem in item.SubFilters)
  706. {
  707. if (skipped > 0)
  708. {
  709. skipped--;
  710. continue;
  711. }
  712. if (current >= MaxLines)
  713. {
  714. break;
  715. }
  716. current++;
  717. var subBtn = new MirButton
  718. {
  719. Index = 922,
  720. PressedIndex = 923,
  721. HoverIndex = 923,
  722. Library = Libraries.Prguse2,
  723. Sound = SoundList.ButtonA,
  724. Location = new Point(btnx, btny),
  725. Parent = this,
  726. };
  727. subBtn.Click += (o, e) =>
  728. {
  729. DrawFilters(item.Index, subItem.Index);
  730. if (subItem.Type.HasValue)
  731. {
  732. Network.Enqueue(new C.MarketSearch { Match = SearchTextBox.Text, Type = subItem.Type.Value, Usermode = false, MinShape = subItem.MinShape, MaxShape = subItem.MaxShape, MarketType = MarketType });
  733. }
  734. };
  735. var sublbl = new MirLabel
  736. {
  737. Size = new Size(99, 18),
  738. Location = new Point(10, 1),
  739. Parent = subBtn,
  740. Text = subItem.Title,
  741. NotControl = true,
  742. };
  743. if (subItem.Index == subIndex)
  744. {
  745. subBtn.Index = 923;
  746. }
  747. FilterButtons.Add(subBtn);
  748. FilterLabels.Add(sublbl);
  749. btny += 21;
  750. }
  751. }
  752. }
  753. UpdatePositionBar();
  754. }
  755. private void PositionBar_OnMoving(object sender, MouseEventArgs e)
  756. {
  757. int x = PosX;
  758. int y = PositionBar.Location.Y;
  759. if (y >= PosMaxY) y = PosMaxY;
  760. if (y <= PosMinY) y = PosMinY;
  761. int location = y - PosMinY;
  762. int interval = (PosMaxY - PosMinY) / (PossibleTotal - MaxLines);
  763. double yPoint = (double)location / interval;
  764. Skip = Convert.ToInt16(Math.Floor(yPoint));
  765. PositionBar.Location = new Point(x, y);
  766. DrawFilters(SelectedIndex, SelectedSubIndex);
  767. }
  768. private void UpdatePositionBar()
  769. {
  770. if (PossibleTotal <= MaxLines)
  771. {
  772. PositionBar.Visible = false;
  773. return;
  774. }
  775. PositionBar.Visible = true;
  776. int interval = (PosMaxY - PosMinY) / (PossibleTotal - MaxLines);
  777. int x = PosX;
  778. int y = PosMinY + (Skip * interval);
  779. if (y >= PosMaxY) y = PosMaxY;
  780. if (y <= PosMinY) y = PosMinY;
  781. PositionBar.Location = new Point(x, y);
  782. }
  783. private void UpdatePriceFilterIcon()
  784. {
  785. if (PriceFilterIcon == null) return;
  786. switch (PriceFilter)
  787. {
  788. case MarketPriceFilter.High:
  789. PriceFilterIcon.Index = 926;
  790. PriceFilterIcon.Visible = true;
  791. break;
  792. case MarketPriceFilter.Low:
  793. PriceFilterIcon.Index = 925;
  794. PriceFilterIcon.Visible = true;
  795. break;
  796. default:
  797. PriceFilterIcon.Visible = false;
  798. break;
  799. }
  800. }
  801. private void CyclePriceFilter()
  802. {
  803. switch (PriceFilter)
  804. {
  805. case MarketPriceFilter.Normal:
  806. PriceFilter = MarketPriceFilter.Low;
  807. break;
  808. case MarketPriceFilter.Low:
  809. PriceFilter = MarketPriceFilter.High;
  810. break;
  811. default:
  812. PriceFilter = MarketPriceFilter.Normal;
  813. break;
  814. }
  815. UpdatePriceFilterIcon();
  816. UpdateInterface();
  817. }
  818. private List<ClientAuction> GetOrderedListings()
  819. {
  820. switch (PriceFilter)
  821. {
  822. case MarketPriceFilter.High:
  823. return Listings.OrderByDescending(x => x?.Price ?? 0).ToList();
  824. case MarketPriceFilter.Low:
  825. return Listings.OrderBy(x => x?.Price ?? 0).ToList();
  826. default:
  827. return Listings;
  828. }
  829. }
  830. public void UpdateInterface()
  831. {
  832. var orderedListings = GetOrderedListings();
  833. PageLabel.Text = string.Format("{0}/{1}", Page + 1, PageCount);
  834. TotalGold.Text = MarketType == MarketPanelType.GameShop ? GameScene.Credit.ToString("###,###,##0") : GameScene.Gold.ToString("###,###,##0");
  835. for (int i = 0; i < 10; i++)
  836. {
  837. if (i + Page * 10 >= orderedListings.Count)
  838. {
  839. Rows[i].Clear();
  840. if (Rows[i] == Selected) Selected = null;
  841. }
  842. else
  843. {
  844. if (Rows[i] == Selected && Selected.Listing != orderedListings[i + Page * 10])
  845. {
  846. Selected.Border = false;
  847. Selected = null;
  848. }
  849. Rows[i].Update(orderedListings[i + Page * 10]);
  850. }
  851. }
  852. for (int i = 0; i < Rows.Length; i++)
  853. {
  854. Rows[i].Border = Rows[i] == Selected;
  855. }
  856. if (Selected != null)
  857. {
  858. BuyButton.Enabled = true;
  859. BuyButton.GrayScale = false;
  860. CollectSoldButton.Enabled = false;
  861. CollectSoldButton.GrayScale = true;
  862. MailButton.Enabled = true;
  863. MailButton.GrayScale = false;
  864. }
  865. else
  866. {
  867. BuyButton.Enabled = false;
  868. BuyButton.GrayScale = true;
  869. CollectSoldButton.Enabled = true;
  870. CollectSoldButton.GrayScale = false;
  871. MailButton.Enabled = false;
  872. MailButton.GrayScale = true;
  873. }
  874. if (Selected != null && Selected.Listing.Seller == "Bid Met")
  875. {
  876. SellNowButton.Enabled = true;
  877. SellNowButton.GrayScale = false;
  878. }
  879. else
  880. {
  881. SellNowButton.Enabled = false;
  882. SellNowButton.GrayScale = true;
  883. }
  884. }
  885. private void SearchTextBox_KeyPress(object sender, KeyPressEventArgs e)
  886. {
  887. if (CMain.Time < SearchTime)
  888. {
  889. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.YouCanSearchAfterSeconds), Math.Ceiling((SearchTime - CMain.Time) / 1000D)), ChatType.System);
  890. return;
  891. }
  892. switch (e.KeyChar)
  893. {
  894. case (char)Keys.Enter:
  895. e.Handled = true;
  896. if (string.IsNullOrEmpty(SearchTextBox.Text)) return;
  897. SearchTime = CMain.Time + Globals.SearchDelay;
  898. Network.Enqueue(new C.MarketSearch
  899. {
  900. Match = SearchTextBox.Text,
  901. MarketType = MarketType
  902. });
  903. Program.Form.ActiveControl = null;
  904. break;
  905. case (char)Keys.Escape:
  906. e.Handled = true;
  907. break;
  908. }
  909. }
  910. private void SearchTextBox_KeyUp(object sender, KeyEventArgs e)
  911. {
  912. CMain.Shift = e.Shift;
  913. CMain.Alt = e.Alt;
  914. CMain.Ctrl = e.Control;
  915. switch (e.KeyCode)
  916. {
  917. case Keys.F1:
  918. case Keys.F2:
  919. case Keys.F3:
  920. case Keys.F4:
  921. case Keys.F5:
  922. case Keys.F6:
  923. case Keys.F7:
  924. case Keys.F8:
  925. case Keys.F9:
  926. case Keys.F10:
  927. case Keys.F11:
  928. case Keys.F12:
  929. case Keys.Tab:
  930. case Keys.Escape:
  931. CMain.CMain_KeyUp(sender, e);
  932. break;
  933. }
  934. }
  935. private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
  936. {
  937. CMain.Shift = e.Shift;
  938. CMain.Alt = e.Alt;
  939. CMain.Ctrl = e.Control;
  940. switch (e.KeyCode)
  941. {
  942. case Keys.F1:
  943. case Keys.F2:
  944. case Keys.F3:
  945. case Keys.F4:
  946. case Keys.F5:
  947. case Keys.F6:
  948. case Keys.F7:
  949. case Keys.F8:
  950. case Keys.F9:
  951. case Keys.F10:
  952. case Keys.F11:
  953. case Keys.F12:
  954. case Keys.Tab:
  955. case Keys.Escape:
  956. CMain.CMain_KeyDown(sender, e);
  957. break;
  958. }
  959. }
  960. public void TMerchantDialog(MarketPanelType type)
  961. {
  962. MarketButton.Index = 789;
  963. ConsignmentButton.Index = 791;
  964. AuctionButton.Index = 817;
  965. GameShopButton.Index = 819;
  966. switch (type)
  967. {
  968. case MarketPanelType.Market:
  969. Index = 786;
  970. MarketButton.Index = 788;
  971. BuyButton.Index = 703;
  972. BuyButton.HoverIndex = 704;
  973. BuyButton.PressedIndex = 705;
  974. SellNowButton.Visible = false;
  975. CollectSoldButton.Visible = false;
  976. UpButton.Visible = true;
  977. DownButton.Visible = true;
  978. PositionBar.Visible = true;
  979. DrawFilters(0, -1);
  980. TitleSalePriceLabel.Visible = false;
  981. TitleSellLabel.Visible = false;
  982. TitleItemLabel.Visible = true;
  983. TitlePriceLabel.Visible = true;
  984. TitleExpiryLabel.Visible = true;
  985. TitleSalePriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SalePrice);
  986. TitleSellLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SellItem);
  987. TitleItemLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Item);
  988. TitlePriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PriceBid);
  989. TitleExpiryLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SellerExpiry);
  990. //TotalGold.Visible = true;
  991. PriceTextBox.Visible = false;
  992. ItemCell.Visible = false;
  993. MailButton.Visible = true;
  994. FindButton.Visible = true;
  995. SellItemButton.Visible = false;
  996. SearchTextBox.Visible = true;
  997. RefreshButton.Visible = true;
  998. HelpLabel.Visible = false;
  999. MarketType = MarketPanelType.Market;
  1000. Network.Enqueue(new C.MarketSearch
  1001. {
  1002. Match = "",
  1003. Type = ItemType.Nothing,
  1004. Usermode = false,
  1005. MarketType = MarketType
  1006. });
  1007. break;
  1008. case MarketPanelType.Consign:
  1009. Index = 787;
  1010. ConsignmentButton.Index = 790;
  1011. MailButton.Visible = false;
  1012. BuyButton.Index = 706;
  1013. BuyButton.HoverIndex = 707;
  1014. BuyButton.PressedIndex = 708;
  1015. SellNowButton.Visible = false;
  1016. CollectSoldButton.Visible = true;
  1017. UpButton.Visible = false;
  1018. DownButton.Visible = false;
  1019. PositionBar.Visible = false;
  1020. //TotalGold.Visible = false;
  1021. PriceTextBox.Visible = true;
  1022. PriceTextBox.Text = null;
  1023. ItemCell.Visible = true;
  1024. SellItemButton.Visible = true;
  1025. SellItemButton.Enabled = false;
  1026. FindButton.Visible = false;
  1027. SearchTextBox.Visible = false;
  1028. RefreshButton.Visible = false;
  1029. HelpLabel.Visible = true;
  1030. HelpLabel.Text = consignmentText;
  1031. TitleSalePriceLabel.Visible = true;
  1032. TitleSellLabel.Visible = true;
  1033. TitleItemLabel.Visible = true;
  1034. TitlePriceLabel.Visible = true;
  1035. TitleExpiryLabel.Visible = true;
  1036. TitleSalePriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SalePrice);
  1037. TitleSellLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SellItem);
  1038. TitleItemLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Item);
  1039. TitlePriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Price);
  1040. TitleExpiryLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Expiry);
  1041. foreach (var item in FilterButtons)
  1042. {
  1043. item.Visible = false;
  1044. }
  1045. MarketType = MarketPanelType.Consign;
  1046. Network.Enqueue(new C.MarketSearch
  1047. {
  1048. Match = "",
  1049. Type = ItemType.Nothing,
  1050. Usermode = true,
  1051. MarketType = MarketType
  1052. });
  1053. break;
  1054. case MarketPanelType.Auction:
  1055. Index = 787;
  1056. AuctionButton.Index = 816;
  1057. MailButton.Visible = false;
  1058. BuyButton.Index = 706;
  1059. BuyButton.HoverIndex = 707;
  1060. BuyButton.PressedIndex = 708;
  1061. SellNowButton.Visible = true;
  1062. CollectSoldButton.Visible = false;
  1063. UpButton.Visible = false;
  1064. DownButton.Visible = false;
  1065. PositionBar.Visible = false;
  1066. //TotalGold.Visible = false;
  1067. PriceTextBox.Visible = true;
  1068. PriceTextBox.Text = null;
  1069. ItemCell.Visible = true;
  1070. SellItemButton.Visible = true;
  1071. SellItemButton.Enabled = false;
  1072. FindButton.Visible = false;
  1073. SearchTextBox.Visible = false;
  1074. RefreshButton.Visible = false;
  1075. HelpLabel.Visible = true;
  1076. HelpLabel.Text = auctionText;
  1077. TitleSalePriceLabel.Visible = true;
  1078. TitleSellLabel.Visible = true;
  1079. TitleItemLabel.Visible = true;
  1080. TitlePriceLabel.Visible = true;
  1081. TitleExpiryLabel.Visible = true;
  1082. TitleSalePriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StartingBid);
  1083. TitleSellLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SellItem);
  1084. TitleItemLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Item);
  1085. TitlePriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.HighestBid);
  1086. TitleExpiryLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EndDate);
  1087. foreach (var item in FilterButtons)
  1088. {
  1089. item.Visible = false;
  1090. }
  1091. MarketType = MarketPanelType.Auction;
  1092. Network.Enqueue(new C.MarketSearch
  1093. {
  1094. Match = "",
  1095. Type = ItemType.Nothing,
  1096. Usermode = true,
  1097. MarketType = MarketType
  1098. });
  1099. break;
  1100. case MarketPanelType.GameShop:
  1101. Index = 786;
  1102. GameShopButton.Index = 818;
  1103. BuyButton.Index = 703;
  1104. BuyButton.HoverIndex = 704;
  1105. BuyButton.PressedIndex = 705;
  1106. SellNowButton.Visible = false;
  1107. CollectSoldButton.Visible = false;
  1108. UpButton.Visible = true;
  1109. DownButton.Visible = true;
  1110. PositionBar.Visible = true;
  1111. DrawFilters(0, -1);
  1112. //TotalGold.Visible = true;
  1113. PriceTextBox.Visible = false;
  1114. ItemCell.Visible = false;
  1115. MailButton.Visible = false;
  1116. FindButton.Visible = true;
  1117. SellItemButton.Visible = false;
  1118. SearchTextBox.Visible = true;
  1119. RefreshButton.Visible = false;
  1120. HelpLabel.Visible = false;
  1121. TitleSalePriceLabel.Visible = false;
  1122. TitleSellLabel.Visible = false;
  1123. TitleItemLabel.Visible = true;
  1124. TitlePriceLabel.Visible = true;
  1125. TitleExpiryLabel.Visible = true;
  1126. TitleSalePriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SalePrice);
  1127. TitleSellLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SellItem);
  1128. TitleItemLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Item);
  1129. TitlePriceLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Price);
  1130. TitleExpiryLabel.Text = "";
  1131. MarketType = MarketPanelType.GameShop;
  1132. Network.Enqueue(new C.MarketSearch
  1133. {
  1134. Match = "",
  1135. Type = ItemType.Nothing,
  1136. Usermode = false,
  1137. MarketType = MarketType
  1138. });
  1139. break;
  1140. }
  1141. UpdateInterface();
  1142. }
  1143. private void TextBox_TextChanged(object sender, EventArgs e)
  1144. {
  1145. string price = Regex.Replace(PriceTextBox.TextBox.Text, @"[^\d]", "");
  1146. if (uint.TryParse(price, NumberStyles.AllowThousands, nfi, out Amount))
  1147. {
  1148. if (MarketType == MarketPanelType.Consign)
  1149. {
  1150. if (Amount >= MinConsignAmount)
  1151. {
  1152. if (Amount > MaxConsignAmount)
  1153. {
  1154. Amount = MaxConsignAmount;
  1155. }
  1156. SellItemButton.Enabled = true;
  1157. PriceTextBox.BorderColour = (Amount == MaxConsignAmount) ? Color.Orange : Color.Lime;
  1158. }
  1159. else
  1160. {
  1161. PriceTextBox.BorderColour = Color.Red;
  1162. SellItemButton.Enabled = false;
  1163. }
  1164. }
  1165. else if (MarketType == MarketPanelType.Auction)
  1166. {
  1167. if (Amount >= MinBidAmount)
  1168. {
  1169. PriceTextBox.BorderColour = Color.Lime;
  1170. if (Amount > MaxBidAmount)
  1171. {
  1172. Amount = MaxBidAmount;
  1173. }
  1174. SellItemButton.Enabled = true;
  1175. if (Amount == MaxBidAmount)
  1176. PriceTextBox.BorderColour = Color.Orange;
  1177. }
  1178. else
  1179. {
  1180. PriceTextBox.BorderColour = Color.Red;
  1181. SellItemButton.Enabled = false;
  1182. }
  1183. }
  1184. PriceTextBox.Text = string.Format(nfi, "{0:N0}", Amount);
  1185. PriceTextBox.TextBox.SelectionStart = PriceTextBox.Text.Length;
  1186. }
  1187. }
  1188. private void MirInputBox_KeyPress(object sender, KeyPressEventArgs e)
  1189. {
  1190. if (!char.IsControl(e.KeyChar)
  1191. && !char.IsDigit(e.KeyChar))
  1192. {
  1193. e.Handled = true;
  1194. }
  1195. }
  1196. private void ItemCell_Click()
  1197. {
  1198. if (tempCell != null)
  1199. {
  1200. tempCell.Locked = false;
  1201. SellItemSlot = null;
  1202. tempCell = null;
  1203. }
  1204. if (GameScene.SelectedCell == null || GameScene.SelectedCell.GridType != MirGridType.Inventory ||
  1205. GameScene.SelectedCell.Item != null && GameScene.SelectedCell.Item.Info.Durability < 0)
  1206. return;
  1207. SellItemSlot = GameScene.SelectedCell.Item;
  1208. tempCell = GameScene.SelectedCell;
  1209. tempCell.Locked = true;
  1210. GameScene.SelectedCell = null;
  1211. PriceTextBox.SetFocus();
  1212. }
  1213. public override void Hide()
  1214. {
  1215. if (!Visible) return;
  1216. Visible = false;
  1217. Listings.Clear();
  1218. if (tempCell != null)
  1219. {
  1220. tempCell.Locked = false;
  1221. SellItemSlot = null;
  1222. tempCell = null;
  1223. }
  1224. GameScene.Scene.InventoryDialog.Location = new Point(0, 0);
  1225. }
  1226. public void Show(bool gameshop = false)
  1227. {
  1228. if (Visible) return;
  1229. Visible = true;
  1230. if (gameshop)
  1231. {
  1232. MarketButton.Visible = false;
  1233. ConsignmentButton.Visible = false;
  1234. AuctionButton.Visible = false;
  1235. GameShopButton.Visible = true;
  1236. TMerchantDialog(MarketPanelType.GameShop);
  1237. }
  1238. else
  1239. {
  1240. MarketButton.Visible = true;
  1241. ConsignmentButton.Visible = true;
  1242. AuctionButton.Visible = true;
  1243. GameShopButton.Visible = false;
  1244. TMerchantDialog(MarketPanelType.Market);
  1245. }
  1246. GameScene.Scene.InventoryDialog.Location = new Point(Size.Width + 5, Location.Y);
  1247. GameScene.Scene.InventoryDialog.Show();
  1248. }
  1249. #region AuctionRow
  1250. public sealed class AuctionRow : MirControl
  1251. {
  1252. public ClientAuction Listing = null;
  1253. public MirLabel NameLabel, PriceLabel, SellerLabel, ExpireLabel;
  1254. public MirImageControl IconImage, SelectedImage;
  1255. public bool Selected = false;
  1256. Size IconArea = new Size(34, 32);
  1257. public AuctionRow()
  1258. {
  1259. Size = new Size(354, 32);
  1260. Sound = SoundList.ButtonA;
  1261. BorderColour = Color.FromArgb(255, 200, 100, 0);
  1262. BeforeDraw += AuctionRow_BeforeDraw;
  1263. NameLabel = new MirLabel
  1264. {
  1265. AutoSize = true,
  1266. Size = new Size(140, 20),
  1267. Location = new Point(38, 8),
  1268. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  1269. NotControl = true,
  1270. Parent = this,
  1271. };
  1272. PriceLabel = new MirLabel
  1273. {
  1274. AutoSize = true,
  1275. Size = new Size(178, 20),
  1276. Location = new Point(170, 8),
  1277. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  1278. NotControl = true,
  1279. Parent = this,
  1280. };
  1281. SellerLabel = new MirLabel
  1282. {
  1283. AutoSize = true,
  1284. Size = new Size(148, 20),
  1285. Location = new Point(256, 0),
  1286. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  1287. NotControl = true,
  1288. Parent = this,
  1289. };
  1290. IconImage = new MirImageControl
  1291. {
  1292. Index = 0,
  1293. Library = Libraries.Prguse,
  1294. Location = new Point(0, 0),
  1295. Parent = this,
  1296. };
  1297. SelectedImage = new MirImageControl
  1298. {
  1299. Index = 545,
  1300. Library = Libraries.Prguse,
  1301. Location = new Point(-5, -3),
  1302. Parent = this,
  1303. Visible = false,
  1304. NotControl = true
  1305. };
  1306. ExpireLabel = new MirLabel
  1307. {
  1308. AutoSize = true,
  1309. Location = new Point(256, 14),
  1310. Size = new Size(110, 22),
  1311. DrawFormat = TextFormatFlags.Left | TextFormatFlags.VerticalCenter,
  1312. Parent = this,
  1313. NotControl = true,
  1314. };
  1315. UpdateInterface();
  1316. }
  1317. private void AuctionRow_BeforeDraw(object sender, EventArgs e)
  1318. {
  1319. UpdateInterface();
  1320. }
  1321. public void UpdateInterface()
  1322. {
  1323. if (Listing == null) return;
  1324. IconImage.Visible = true;
  1325. if (Listing.Item.Count > 0)
  1326. {
  1327. IconImage.Index = Listing.Item.Info.Image;
  1328. IconImage.Library = Libraries.Items;
  1329. }
  1330. else
  1331. {
  1332. IconImage.Index = 540;
  1333. IconImage.Library = Libraries.Prguse;
  1334. }
  1335. IconImage.Location = new Point((IconArea.Width - IconImage.Size.Width) / 2, (IconArea.Height - IconImage.Size.Height) / 2);
  1336. SellerLabel.Visible = Listing.ItemType == MarketItemType.Consign || Listing.ItemType == MarketItemType.Auction;
  1337. ExpireLabel.Visible = Listing != null && (Listing.ItemType == MarketItemType.Consign || Listing.ItemType == MarketItemType.Auction);
  1338. if (Listing == null) return;
  1339. ExpireLabel.Text = string.Format("{0:dd/MM/yy HH:mm:ss}", Listing.ConsignmentDate.AddDays(Globals.ConsignmentLength));
  1340. }
  1341. protected override void Dispose(bool disposing)
  1342. {
  1343. base.Dispose(disposing);
  1344. SelectedImage = null;
  1345. IconImage = null;
  1346. Selected = false;
  1347. }
  1348. public void Clear()
  1349. {
  1350. Visible = false;
  1351. NameLabel.Text = string.Empty;
  1352. PriceLabel.Text = string.Empty;
  1353. SellerLabel.Text = string.Empty;
  1354. }
  1355. public void Update(ClientAuction listing)
  1356. {
  1357. Listing = listing;
  1358. NameLabel.Text = Listing.Item.FriendlyName;
  1359. PriceLabel.Text = String.Format("{0:###,###,##0} {1}", Listing.Price, listing.ItemType == MarketItemType.Auction ? GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Bid) : "");
  1360. NameLabel.ForeColour = GameScene.Scene.GradeNameColor(Listing.Item.Info.Grade);
  1361. if (NameLabel.ForeColour == Color.Yellow)
  1362. NameLabel.ForeColour = Color.White;
  1363. if (Listing.Price > 10000000) //10Mil
  1364. PriceLabel.ForeColour = Color.Red;
  1365. else if (listing.Price > 1000000) //1Million
  1366. PriceLabel.ForeColour = Color.Orange;
  1367. else if (listing.Price > 100000) //1Million
  1368. PriceLabel.ForeColour = Color.LawnGreen;
  1369. else if (listing.Price > 10000) //1Million
  1370. PriceLabel.ForeColour = Color.DeepSkyBlue;
  1371. else
  1372. PriceLabel.ForeColour = Color.White;
  1373. SellerLabel.Text = Listing.Seller;
  1374. SellerLabel.ForeColour = Color.White;
  1375. if (UserMode)
  1376. {
  1377. switch (Listing.Seller)
  1378. {
  1379. case "Sold":
  1380. SellerLabel.ForeColour = Color.Gold;
  1381. break;
  1382. case "Expired":
  1383. SellerLabel.ForeColour = Color.Red;
  1384. break;
  1385. case "Bid Met":
  1386. SellerLabel.ForeColour = Color.LawnGreen;
  1387. break;
  1388. default:
  1389. SellerLabel.ForeColour = Color.White;
  1390. break;
  1391. }
  1392. }
  1393. Visible = true;
  1394. }
  1395. protected override void OnMouseEnter()
  1396. {
  1397. if (Listing == null) return;
  1398. base.OnMouseEnter();
  1399. GameScene.Scene.CreateItemLabel(Listing.Item);
  1400. }
  1401. protected override void OnMouseLeave()
  1402. {
  1403. if (Listing == null) return;
  1404. base.OnMouseLeave();
  1405. GameScene.Scene.DisposeItemLabel();
  1406. GameScene.HoverItem = null;
  1407. }
  1408. }
  1409. #endregion
  1410. public class Filter
  1411. {
  1412. public int Index { get; set; } = -1;
  1413. public string Title { get; set; } = "";
  1414. public ItemType? Type { get; set; } = ItemType.Nothing;
  1415. public short MinShape { get; set; } = 0;
  1416. public short MaxShape { get; set; } = short.MaxValue;
  1417. public List<Filter> SubFilters = new List<Filter>();
  1418. }
  1419. }
  1420. }