RankingDialog.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirSounds;
  4. namespace Client.MirScenes.Dialogs
  5. {
  6. public class RankingDialog : MirImageControl
  7. {
  8. public MirButton AllButton, WarButton, WizButton, TaoButton, SinButton, ArchButton, Tab7, NextButton, PrevButton, ScrollBar;
  9. public MirButton CloseButton;
  10. public MirLabel MyRank;
  11. public MirCheckBox OnlineOnlyButton;
  12. public byte RankType = 0;
  13. private int rowOffset;
  14. private int RowOffset
  15. {
  16. get { return rowOffset; }
  17. set
  18. {
  19. rowOffset = value;
  20. ScrollBar.Location = new Point(PrevButton.Location.X, (int)(PrevButton.Location.Y + 13 + rowOffset * GapPerRow));
  21. }
  22. }
  23. public int RankCount;
  24. public RankingRow[] Rows = new RankingRow[20];
  25. public List<RankCharacterInfo>[] RankList = new List<RankCharacterInfo>[6];
  26. public int[] Rank = new int[6];
  27. private bool OnlineOnly;
  28. public long[] LastRequest = new long[6];
  29. private float GapPerRow;
  30. private int ScrollHeight;
  31. private DateTime NextRequestTime = DateTime.MinValue;
  32. public RankingDialog()
  33. {
  34. Index = 728;
  35. Library = Libraries.Title;
  36. //Size = new Size(288, 324);
  37. Movable = true;
  38. Sort = true;
  39. Location = new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2);
  40. CloseButton = new MirButton
  41. {
  42. HoverIndex = 361,
  43. Index = 360,
  44. Location = new Point(300, 3),
  45. Library = Libraries.Prguse2,
  46. Parent = this,
  47. PressedIndex = 362,
  48. Sound = SoundList.ButtonA,
  49. };
  50. CloseButton.Click += (o, e) => Hide();
  51. AllButton = new MirButton
  52. {
  53. Index = 751,
  54. PressedIndex = 752,
  55. HoverIndex = 753,
  56. Library = Libraries.Title,
  57. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.OverallTop20),
  58. Location = new Point(10, 38),
  59. Parent = this,
  60. Sound = SoundList.ButtonA,
  61. };
  62. AllButton.Click += (o, e) => SelectRank(0);
  63. TaoButton = new MirButton
  64. {
  65. Index = 760,
  66. PressedIndex = 761,
  67. HoverIndex = 762,
  68. Library = Libraries.Title,
  69. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Top20Taoists),
  70. Location = new Point(40, 38),
  71. Parent = this,
  72. Sound = SoundList.ButtonA,
  73. };
  74. TaoButton.Click += (o, e) => SelectRank(3);
  75. WarButton = new MirButton
  76. {
  77. Index = 754,
  78. PressedIndex = 755,
  79. HoverIndex = 756,
  80. Library = Libraries.Title,
  81. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Top20Warriors),
  82. Location = new Point(60, 38),
  83. Parent = this,
  84. Sound = SoundList.ButtonA,
  85. };
  86. WarButton.Click += (o, e) => SelectRank(1);
  87. WizButton = new MirButton
  88. {
  89. Index = 763,
  90. PressedIndex = 764,
  91. HoverIndex = 765,
  92. Library = Libraries.Title,
  93. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Top20Wizards),
  94. Location = new Point(80, 38),
  95. Parent = this,
  96. Sound = SoundList.ButtonA,
  97. };
  98. WizButton.Click += (o, e) => SelectRank(2);
  99. SinButton = new MirButton
  100. {
  101. Index = 757,
  102. PressedIndex = 758,
  103. HoverIndex = 759,
  104. Library = Libraries.Title,
  105. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Top20Assasins),
  106. Location = new Point(100, 38),
  107. Parent = this,
  108. Sound = SoundList.ButtonA,
  109. };
  110. SinButton.Click += (o, e) => SelectRank(4);
  111. ArchButton = new MirButton
  112. {
  113. Index = 766,
  114. PressedIndex = 767,
  115. HoverIndex = 768,
  116. Library = Libraries.Title,
  117. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Top20Archers),
  118. Location = new Point(120, 38),
  119. Parent = this,
  120. Sound = SoundList.ButtonA,
  121. };
  122. ArchButton.Click += (o, e) => SelectRank(5);
  123. NextButton = new MirButton
  124. {
  125. Index = 207,
  126. HoverIndex = 208,
  127. PressedIndex = 209,
  128. Library = Libraries.Prguse2,
  129. Location = new Point(299, 386),
  130. Parent = this,
  131. Sound = SoundList.ButtonA,
  132. };
  133. NextButton.Click += (o, e) => Move(1);
  134. PrevButton = new MirButton
  135. {
  136. Index = 197,
  137. HoverIndex = 198,
  138. PressedIndex = 199,
  139. Library = Libraries.Prguse2,
  140. Location = new Point(299, 100),
  141. Parent = this,
  142. Sound = SoundList.ButtonA,
  143. };
  144. PrevButton.Click += (o, e) => Move(-1);
  145. ScrollHeight = NextButton.Location.Y - PrevButton.Location.Y - 32;
  146. ScrollBar = new MirButton
  147. {
  148. Index = 205,
  149. HoverIndex = 206,
  150. PressedIndex = 206,
  151. Location = new Point(299, PrevButton.Location.Y + 13),
  152. Library = Libraries.Prguse2,
  153. Parent = this,
  154. Movable = true,
  155. Sound = SoundList.ButtonA,
  156. };
  157. ScrollBar.OnMoving += (o, e) =>
  158. {
  159. var y = ScrollBar.Location.Y;
  160. if (y < 110)
  161. y = 110;
  162. if (y > 368)
  163. y = 368;
  164. ScrollBar.Location = new Point(ScrollBar.Location.X, y);
  165. var row = Math.Max(0, Math.Min(RankCount - 20, (y - PrevButton.Location.Y - 13) / GapPerRow));
  166. RowOffset = (int)row;
  167. NextRequestTime = CMain.Now + TimeSpan.FromSeconds(0.5);
  168. };
  169. OnlineOnlyButton = new MirCheckBox { Index = 2086, UnTickedIndex = 2086, TickedIndex = 2087, Parent = this, Location = new Point(190, Size.Height - 20), Library = Libraries.Prguse };
  170. OnlineOnlyButton.LabelText = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.OnlineOnly);
  171. OnlineOnlyButton.Click += (o, e) =>
  172. {
  173. OnlineOnly = OnlineOnlyButton.Checked;
  174. RowOffset = 0;
  175. NextRequestTime = CMain.Now;
  176. };
  177. MyRank = new MirLabel
  178. {
  179. Text = "",
  180. Parent = this,
  181. Font = new Font(Settings.FontName, 10F, FontStyle.Bold),
  182. ForeColour = Color.BurlyWood,
  183. Location = new Point(229, 36),
  184. Size = new Size(82, 22),
  185. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  186. //AutoSize = true
  187. };
  188. MyRank.Click += (o, e) => GoToMyRank();
  189. for (int i = 0; i < Rows.Count(); i++)
  190. {
  191. Rows[i] = new RankingRow()
  192. {
  193. Parent = this,
  194. Location = new Point(32, 98 + i * 15),
  195. Size = new Size(270, 15),
  196. };
  197. Rows[i].MouseWheel += (o, e) => Ranking_MouseWheel(o, e);
  198. }
  199. for (int i = 0; i < RankList.Length; i++)
  200. {
  201. RankList[i] = new List<RankCharacterInfo>();
  202. }
  203. }
  204. public void Process()
  205. {
  206. if (NextRequestTime != DateTime.MinValue && CMain.Now > NextRequestTime)
  207. {
  208. NextRequestTime = DateTime.MinValue;
  209. RequestRanks(RankType);
  210. }
  211. }
  212. public override void Show()
  213. {
  214. if (Visible) return;
  215. Visible = true;
  216. RequestRanks(RankType);
  217. }
  218. public override void Hide()
  219. {
  220. if (!Visible) return;
  221. Visible = false;
  222. }
  223. public void Ranking_MouseWheel(object sender, MouseEventArgs e)
  224. {
  225. int count = e.Delta / SystemInformation.MouseWheelScrollDelta;
  226. Move(-count);
  227. }
  228. public void Toggle()
  229. {
  230. if (!Visible)
  231. Show();
  232. else
  233. Hide();
  234. }
  235. public void GoToMyRank()
  236. {
  237. }
  238. public void Move(int distance)
  239. {
  240. if (distance > 0)
  241. {
  242. //go down
  243. RowOffset = RowOffset < RankCount - 20 ? ++RowOffset : RowOffset;
  244. }
  245. else
  246. {
  247. //go up
  248. RowOffset = RowOffset > 0 ? --RowOffset : RowOffset;
  249. }
  250. NextRequestTime = CMain.Now + TimeSpan.FromSeconds(0.5);
  251. }
  252. public void RequestRanks(byte RankType)
  253. {
  254. if (RankType > 6) return;
  255. MirNetwork.Network.Enqueue(new ClientPackets.GetRanking { RankType = RankType, RankIndex = RowOffset, OnlineOnly = OnlineOnly });
  256. }
  257. public void RecieveRanks(List<RankCharacterInfo> Ranking, byte rankType, int MyRank, int Count)
  258. {
  259. RankList[rankType].Clear();
  260. RankList[rankType] = Ranking;
  261. Rank[rankType] = MyRank;
  262. RankCount = Count;
  263. UpdateRanks();
  264. var extraRows = Count - 20;
  265. GapPerRow = ScrollHeight / (float)extraRows;
  266. }
  267. public void SelectRank(byte rankType)
  268. {
  269. RankType = rankType;
  270. for (int i = 0; i < Rows.Count(); i++)
  271. {
  272. Rows[i].Clear();
  273. }
  274. RowOffset = 0;
  275. RequestRanks(RankType);
  276. }
  277. public void UpdateRanks()
  278. {
  279. for (int i = 0; i < Rows.Count(); i++)
  280. {
  281. if (i >= RankCount)
  282. Rows[i].Clear();
  283. else
  284. Rows[i].Update(RankList[RankType][i], RowOffset + i + 1);
  285. }
  286. if (Rank[RankType] == 0)
  287. MyRank.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NotListed);
  288. else
  289. MyRank.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.Ranked), Rank[RankType]);
  290. }
  291. public sealed class RankingRow : MirControl
  292. {
  293. public RankCharacterInfo Listing;
  294. public MirLabel RankLabel, NameLabel, LevelLabel, ClassLabel;
  295. public long Index;
  296. public RankingRow()
  297. {
  298. Sound = SoundList.ButtonA;
  299. BorderColour = Color.Lime;
  300. Visible = false;
  301. Click += (o, e) => Inspect();
  302. RankLabel = new MirLabel
  303. {
  304. Location = new Point(0, 0),
  305. AutoSize = true,
  306. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  307. Parent = this,
  308. NotControl = true,
  309. };
  310. NameLabel = new MirLabel
  311. {
  312. Location = new Point(55, 0),
  313. AutoSize = true,
  314. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  315. Parent = this,
  316. NotControl = true,
  317. };
  318. ClassLabel = new MirLabel
  319. {
  320. Location = new Point(150, 0),
  321. AutoSize = true,
  322. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  323. Parent = this,
  324. NotControl = true,
  325. };
  326. LevelLabel = new MirLabel
  327. {
  328. Location = new Point(220, 0),
  329. AutoSize = true,
  330. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  331. Parent = this,
  332. NotControl = true,
  333. };
  334. }
  335. public void Inspect()
  336. {
  337. if (CMain.Time <= GameScene.InspectTime /* && Index == InspectDialog.InspectID*/) return;
  338. GameScene.InspectTime = CMain.Time + 500;
  339. InspectDialog.InspectID = (uint)Index;
  340. MirNetwork.Network.Enqueue(new ClientPackets.Inspect { ObjectID = (uint)Index, Ranking = true });
  341. }
  342. public void Clear()
  343. {
  344. Visible = false;
  345. NameLabel.Text = string.Empty;
  346. RankLabel.Text = string.Empty;
  347. LevelLabel.Text = string.Empty;
  348. ClassLabel.Text = string.Empty;
  349. }
  350. public void Update(RankCharacterInfo listing, int RankIndex)
  351. {
  352. Listing = listing;
  353. RankLabel.Text = RankIndex.ToString();
  354. LevelLabel.Text = Listing.level.ToString();
  355. ClassLabel.Text = Listing.Class.ToLocalizedString();
  356. NameLabel.Text = listing.Name;
  357. Index = listing.PlayerId;
  358. if (RankLabel.Text == "1")
  359. {
  360. RankLabel.ForeColour = Color.Gold;
  361. NameLabel.ForeColour = Color.Gold;
  362. LevelLabel.ForeColour = Color.Gold;
  363. ClassLabel.ForeColour = Color.Gold;
  364. }
  365. if (RankLabel.Text == "2")
  366. {
  367. RankLabel.ForeColour = Color.Silver;
  368. NameLabel.ForeColour = Color.Silver;
  369. LevelLabel.ForeColour = Color.Silver;
  370. ClassLabel.ForeColour = Color.Silver;
  371. }
  372. if (RankLabel.Text == "3")
  373. {
  374. RankLabel.ForeColour = Color.RosyBrown;
  375. NameLabel.ForeColour = Color.RosyBrown;
  376. LevelLabel.ForeColour = Color.RosyBrown;
  377. ClassLabel.ForeColour = Color.RosyBrown;
  378. }
  379. else if (NameLabel.Text == GameScene.User.Name)
  380. {
  381. RankLabel.ForeColour = Color.Green;
  382. NameLabel.ForeColour = Color.Green;
  383. LevelLabel.ForeColour = Color.Green;
  384. ClassLabel.ForeColour = Color.Green;
  385. }
  386. else if (Convert.ToInt32(RankLabel.Text) > 3)
  387. {
  388. RankLabel.ForeColour = Color.White;
  389. NameLabel.ForeColour = Color.White;
  390. LevelLabel.ForeColour = Color.White;
  391. ClassLabel.ForeColour = Color.White;
  392. }
  393. Visible = true;
  394. }
  395. }
  396. }
  397. }