SelectScene.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirNetwork;
  4. using Client.MirScenes.Dialogs;
  5. using Client.MirSounds;
  6. using C = ClientPackets;
  7. using S = ServerPackets;
  8. namespace Client.MirScenes
  9. {
  10. public class SelectScene : MirScene
  11. {
  12. public MirImageControl Background, Title;
  13. private NewCharacterDialog _character;
  14. public MirLabel ServerLabel;
  15. public MirAnimatedControl CharacterDisplay;
  16. public MirButton StartGameButton, NewCharacterButton, DeleteCharacterButton, CreditsButton, ExitGame;
  17. public CharacterButton[] CharacterButtons;
  18. public MirLabel LastAccessLabel, LastAccessLabelLabel;
  19. public List<SelectInfo> Characters = new List<SelectInfo>();
  20. private int _selected;
  21. public SelectScene(List<SelectInfo> characters)
  22. {
  23. SoundManager.PlayMusic(SoundList.SelectMusic, true);
  24. Disposing += (o, e) => SoundManager.StopMusic();
  25. Characters = characters;
  26. SortList();
  27. KeyPress += SelectScene_KeyPress;
  28. Background = new MirImageControl
  29. {
  30. Index = 65,
  31. Library = Libraries.Prguse,
  32. Parent = this,
  33. };
  34. Title = new MirImageControl
  35. {
  36. Index = 40,
  37. Library = Libraries.Title,
  38. Parent = this,
  39. Location = new Point(468, 20)
  40. };
  41. ServerLabel = new MirLabel
  42. {
  43. Location = new Point(432, 60),
  44. // Location = new Point(322, 44),
  45. Parent = Background,
  46. Size = new Size(155, 17),
  47. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GameName),
  48. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter
  49. };
  50. var xPoint = ((Settings.ScreenWidth - 200) / 5);
  51. StartGameButton = new MirButton
  52. {
  53. Enabled = false,
  54. HoverIndex = 341,
  55. Index = 340,
  56. Library = Libraries.Title,
  57. Location = new Point(100 + (xPoint * 1) - (xPoint / 2) - 50, Settings.ScreenHeight - 32),
  58. Parent = Background,
  59. PressedIndex = 342
  60. };
  61. StartGameButton.Click += (o, e) => StartGame();
  62. NewCharacterButton = new MirButton
  63. {
  64. HoverIndex = 344,
  65. Index = 343,
  66. Library = Libraries.Title,
  67. Location = new Point(100 + (xPoint * 2) - (xPoint / 2) - 50, Settings.ScreenHeight - 32),
  68. Parent = Background,
  69. PressedIndex = 345,
  70. };
  71. NewCharacterButton.Click += (o, e) => OpenNewCharacterDialog();
  72. DeleteCharacterButton = new MirButton
  73. {
  74. HoverIndex = 347,
  75. Index = 346,
  76. Library = Libraries.Title,
  77. Location = new Point(100 + (xPoint * 3) - (xPoint / 2) - 50, Settings.ScreenHeight - 32),
  78. Parent = Background,
  79. PressedIndex = 348
  80. };
  81. DeleteCharacterButton.Click += (o, e) => DeleteCharacter();
  82. CreditsButton = new MirButton
  83. {
  84. HoverIndex = 350,
  85. Index = 349,
  86. Library = Libraries.Title,
  87. Location = new Point(100 + (xPoint * 4) - (xPoint / 2) - 50, Settings.ScreenHeight - 32),
  88. Parent = Background,
  89. PressedIndex = 351
  90. };
  91. CreditsButton.Click += (o, e) =>
  92. {
  93. };
  94. ExitGame = new MirButton
  95. {
  96. HoverIndex = 353,
  97. Index = 352,
  98. Library = Libraries.Title,
  99. Location = new Point(100 + (xPoint * 5) - (xPoint / 2) - 50, Settings.ScreenHeight - 32),
  100. Parent = Background,
  101. PressedIndex = 354
  102. };
  103. ExitGame.Click += (o, e) => Program.Form.Close();
  104. CharacterDisplay = new MirAnimatedControl
  105. {
  106. Animated = true,
  107. AnimationCount = 16,
  108. AnimationDelay = 250,
  109. FadeIn = true,
  110. FadeInDelay = 75,
  111. FadeInRate = 0.1F,
  112. Index = 220,
  113. Library = Libraries.ChrSel,
  114. Location = new Point(260, 420),
  115. Parent = Background,
  116. UseOffSet = true,
  117. Visible = false
  118. };
  119. CharacterDisplay.AfterDraw += (o, e) =>
  120. {
  121. // if (_selected >= 0 && _selected < Characters.Count && characters[_selected].Class == MirClass.Wizard)
  122. Libraries.ChrSel.DrawBlend(CharacterDisplay.Index + 560, CharacterDisplay.DisplayLocationWithoutOffSet, Color.White, true);
  123. };
  124. CharacterButtons = new CharacterButton[4];
  125. CharacterButtons[0] = new CharacterButton
  126. {
  127. Location = new Point(637, 194),
  128. Parent = Background,
  129. Sound = SoundList.ButtonA,
  130. };
  131. CharacterButtons[0].Click += (o, e) =>
  132. {
  133. if (characters.Count <= 0) return;
  134. _selected = 0;
  135. UpdateInterface();
  136. };
  137. CharacterButtons[1] = new CharacterButton
  138. {
  139. Location = new Point(637, 298),
  140. Parent = Background,
  141. Sound = SoundList.ButtonA,
  142. };
  143. CharacterButtons[1].Click += (o, e) =>
  144. {
  145. if (characters.Count <= 1) return;
  146. _selected = 1;
  147. UpdateInterface();
  148. };
  149. CharacterButtons[2] = new CharacterButton
  150. {
  151. Location = new Point(637, 402),
  152. Parent = Background,
  153. Sound = SoundList.ButtonA,
  154. };
  155. CharacterButtons[2].Click += (o, e) =>
  156. {
  157. if (characters.Count <= 2) return;
  158. _selected = 2;
  159. UpdateInterface();
  160. };
  161. CharacterButtons[3] = new CharacterButton
  162. {
  163. Location = new Point(637, 506),
  164. Parent = Background,
  165. Sound = SoundList.ButtonA,
  166. };
  167. CharacterButtons[3].Click += (o, e) =>
  168. {
  169. if (characters.Count <= 3) return;
  170. _selected = 3;
  171. UpdateInterface();
  172. };
  173. LastAccessLabel = new MirLabel
  174. {
  175. Location = new Point(265, 609),
  176. Parent = Background,
  177. Size = new Size(180, 21),
  178. DrawFormat = TextFormatFlags.Left | TextFormatFlags.VerticalCenter,
  179. Border = true,
  180. };
  181. LastAccessLabelLabel = new MirLabel
  182. {
  183. Location = new Point(-65, 0),
  184. Parent = LastAccessLabel,
  185. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.LastOnlineTitle),
  186. Size = new Size(100, 21),
  187. DrawFormat = TextFormatFlags.Left | TextFormatFlags.VerticalCenter,
  188. Border = true,
  189. };
  190. UpdateInterface();
  191. }
  192. private void SelectScene_KeyPress(object sender, KeyPressEventArgs e)
  193. {
  194. if (e.KeyChar != (char)Keys.Enter) return;
  195. if (StartGameButton.Enabled)
  196. StartGame();
  197. e.Handled = true;
  198. }
  199. public void SortList()
  200. {
  201. if (Characters != null)
  202. Characters.Sort((c1, c2) => c2.LastAccess.CompareTo(c1.LastAccess));
  203. }
  204. private void OpenNewCharacterDialog()
  205. {
  206. if (_character == null || _character.IsDisposed)
  207. {
  208. _character = new NewCharacterDialog { Parent = this };
  209. _character.OnCreateCharacter += (o, e) =>
  210. {
  211. Network.Enqueue(new C.NewCharacter
  212. {
  213. Name = _character.NameTextBox.Text,
  214. Class = _character.Class,
  215. Gender = _character.Gender
  216. });
  217. };
  218. }
  219. _character.Show();
  220. }
  221. public void StartGame()
  222. {
  223. if (!Libraries.Loaded)
  224. {
  225. MirAnimatedControl loadProgress = new MirAnimatedControl
  226. {
  227. Library = Libraries.Prguse,
  228. Index = 940,
  229. Visible = true,
  230. Parent = this,
  231. Location = new Point(470, 680),
  232. Animated = true,
  233. AnimationCount = 9,
  234. AnimationDelay = 100,
  235. Loop = true,
  236. };
  237. loadProgress.AfterDraw += (o, e) =>
  238. {
  239. if (!Libraries.Loaded) return;
  240. loadProgress.Dispose();
  241. StartGame();
  242. };
  243. return;
  244. }
  245. StartGameButton.Enabled = false;
  246. Network.Enqueue(new C.StartGame
  247. {
  248. CharacterIndex = Characters[_selected].Index
  249. });
  250. }
  251. public override void Process()
  252. {
  253. }
  254. public override void ProcessPacket(Packet p)
  255. {
  256. switch (p.Index)
  257. {
  258. case (short)ServerPacketIds.NewCharacter:
  259. NewCharacter((S.NewCharacter)p);
  260. break;
  261. case (short)ServerPacketIds.NewCharacterSuccess:
  262. NewCharacter((S.NewCharacterSuccess)p);
  263. break;
  264. case (short)ServerPacketIds.DeleteCharacter:
  265. DeleteCharacter((S.DeleteCharacter)p);
  266. break;
  267. case (short)ServerPacketIds.DeleteCharacterSuccess:
  268. DeleteCharacter((S.DeleteCharacterSuccess)p);
  269. break;
  270. case (short)ServerPacketIds.StartGame:
  271. StartGame((S.StartGame)p);
  272. break;
  273. case (short)ServerPacketIds.StartGameBanned:
  274. StartGame((S.StartGameBanned)p);
  275. break;
  276. case (short)ServerPacketIds.StartGameDelay:
  277. StartGame((S.StartGameDelay)p);
  278. break;
  279. default:
  280. base.ProcessPacket(p);
  281. break;
  282. }
  283. }
  284. private void NewCharacter(S.NewCharacter p)
  285. {
  286. _character.OKButton.Enabled = true;
  287. switch (p.Result)
  288. {
  289. case 0:
  290. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CreatingNewCharactersDisabled));
  291. _character.Dispose();
  292. break;
  293. case 1:
  294. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YourCharacterNameNotAcceptable));
  295. _character.NameTextBox.SetFocus();
  296. break;
  297. case 2:
  298. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GenderNotExistContactGM));
  299. break;
  300. case 3:
  301. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ClassNotExistContactGM));
  302. break;
  303. case 4:
  304. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.YouCannotMakeMoreCharacters), Globals.MaxCharacterCount));
  305. _character.Dispose();
  306. break;
  307. case 5:
  308. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CharacterNameExists));
  309. _character.NameTextBox.SetFocus();
  310. break;
  311. }
  312. }
  313. private void NewCharacter(S.NewCharacterSuccess p)
  314. {
  315. _character.Dispose();
  316. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YourCharacterCreatedSuccessfully));
  317. Characters.Insert(0, p.CharInfo);
  318. _selected = 0;
  319. UpdateInterface();
  320. }
  321. private void DeleteCharacter()
  322. {
  323. if (_selected < 0 || _selected >= Characters.Count) return;
  324. MirMessageBox message = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ConfirmDeleteCharacter), Characters[_selected].Name), MirMessageBoxButtons.YesNo);
  325. int index = Characters[_selected].Index;
  326. message.YesButton.Click += (o1, e1) =>
  327. {
  328. MirInputBox inputBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PleaseEnterCharacterName));
  329. inputBox.OKButton.Click += (o, e) =>
  330. {
  331. string name = Characters[_selected].Name.ToString();
  332. if (inputBox.InputTextBox.Text == name)
  333. {
  334. DeleteCharacterButton.Enabled = false;
  335. Network.Enqueue(new C.DeleteCharacter { CharacterIndex = index });
  336. }
  337. else
  338. {
  339. MirMessageBox failedMessage = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.IncorrectEntry), MirMessageBoxButtons.OK);
  340. failedMessage.Show();
  341. }
  342. inputBox.Dispose();
  343. };
  344. inputBox.Show();
  345. };
  346. message.Show();
  347. }
  348. private void DeleteCharacter(S.DeleteCharacter p)
  349. {
  350. DeleteCharacterButton.Enabled = true;
  351. switch (p.Result)
  352. {
  353. case 0:
  354. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.DeletingCharactersDisabled));
  355. break;
  356. case 1:
  357. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SelectedCharacterNotExist));
  358. break;
  359. }
  360. }
  361. private void DeleteCharacter(S.DeleteCharacterSuccess p)
  362. {
  363. DeleteCharacterButton.Enabled = true;
  364. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YourCharacterDeletedSuccessfully));
  365. for (int i = 0; i < Characters.Count; i++)
  366. if (Characters[i].Index == p.CharacterIndex)
  367. {
  368. Characters.RemoveAt(i);
  369. break;
  370. }
  371. UpdateInterface();
  372. }
  373. private void StartGame(S.StartGameDelay p)
  374. {
  375. StartGameButton.Enabled = true;
  376. long time = CMain.Time + p.Milliseconds;
  377. MirMessageBox message = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.CannotLoginCharacterSeconds), Math.Ceiling(p.Milliseconds / 1000M)));
  378. message.BeforeDraw += (o, e) => message.Label.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.CannotLoginCharacterSeconds), Math.Ceiling((time - CMain.Time) / 1000M));
  379. message.AfterDraw += (o, e) =>
  380. {
  381. if (CMain.Time <= time) return;
  382. message.Dispose();
  383. StartGame();
  384. };
  385. message.Show();
  386. }
  387. public void StartGame(S.StartGameBanned p)
  388. {
  389. StartGameButton.Enabled = true;
  390. TimeSpan d = p.ExpiryDate - CMain.Now;
  391. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AccountBannedReasonExpiryDuration), p.Reason,
  392. p.ExpiryDate, Math.Floor(d.TotalHours), d.Minutes, d.Seconds));
  393. }
  394. public void StartGame(S.StartGame p)
  395. {
  396. StartGameButton.Enabled = true;
  397. switch (p.Result)
  398. {
  399. case 0:
  400. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StartingGameDisabled));
  401. break;
  402. case 1:
  403. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouNotLoggedIn));
  404. break;
  405. case 2:
  406. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YourCharacterNotFound));
  407. break;
  408. case 3:
  409. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoActiveMapOrStartPointFound));
  410. break;
  411. case 4:
  412. if (p.Resolution < Settings.Resolution || Settings.Resolution == 0) Settings.Resolution = p.Resolution;
  413. switch (Settings.Resolution)
  414. {
  415. default:
  416. case 1024:
  417. Settings.Resolution = 1024;
  418. CMain.SetResolution(1024, 768);
  419. break;
  420. case 1280:
  421. CMain.SetResolution(1280, 800);
  422. break;
  423. case 1366:
  424. CMain.SetResolution(1366, 768);
  425. break;
  426. case 1920:
  427. CMain.SetResolution(1920, 1080);
  428. break;
  429. }
  430. ActiveScene = new GameScene();
  431. Dispose();
  432. break;
  433. }
  434. }
  435. private void UpdateInterface()
  436. {
  437. for (int i = 0; i < CharacterButtons.Length; i++)
  438. {
  439. CharacterButtons[i].Selected = i == _selected;
  440. CharacterButtons[i].Update(i >= Characters.Count ? null : Characters[i]);
  441. }
  442. if (_selected >= 0 && _selected < Characters.Count)
  443. {
  444. CharacterDisplay.Visible = true;
  445. //CharacterDisplay.Index = ((byte)Characters[_selected].Class + 1) * 20 + (byte)Characters[_selected].Gender * 280;
  446. switch ((MirClass)Characters[_selected].Class)
  447. {
  448. case MirClass.Warrior:
  449. CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 20 : 300; //220 : 500;
  450. break;
  451. case MirClass.Wizard:
  452. CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 40 : 320; //240 : 520;
  453. break;
  454. case MirClass.Taoist:
  455. CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 60 : 340; //260 : 540;
  456. break;
  457. case MirClass.Assassin:
  458. CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 80 : 360; //280 : 560;
  459. break;
  460. case MirClass.Archer:
  461. CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 100 : 140; //160 : 180;
  462. break;
  463. }
  464. LastAccessLabel.Text = Characters[_selected].LastAccess == DateTime.MinValue ? GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Never) : Characters[_selected].LastAccess.ToString("yyyy/MM/dd HH:mm:ss");
  465. LastAccessLabel.Visible = true;
  466. LastAccessLabelLabel.Visible = true;
  467. StartGameButton.Enabled = true;
  468. }
  469. else
  470. {
  471. CharacterDisplay.Visible = false;
  472. LastAccessLabel.Visible = false;
  473. LastAccessLabelLabel.Visible = false;
  474. StartGameButton.Enabled = false;
  475. }
  476. }
  477. #region Disposable
  478. protected override void Dispose(bool disposing)
  479. {
  480. if (disposing)
  481. {
  482. Background = null;
  483. _character = null;
  484. ServerLabel = null;
  485. CharacterDisplay = null;
  486. StartGameButton = null;
  487. NewCharacterButton = null;
  488. DeleteCharacterButton = null;
  489. CreditsButton = null;
  490. ExitGame = null;
  491. CharacterButtons = null;
  492. LastAccessLabel = null; LastAccessLabelLabel = null;
  493. Characters = null;
  494. _selected = 0;
  495. }
  496. base.Dispose(disposing);
  497. }
  498. #endregion
  499. public sealed class CharacterButton : MirImageControl
  500. {
  501. public MirLabel NameLabel, LevelLabel, ClassLabel;
  502. public bool Selected;
  503. public CharacterButton()
  504. {
  505. Index = 44; //45 locked
  506. Library = Libraries.Prguse;
  507. Sound = SoundList.ButtonA;
  508. NameLabel = new MirLabel
  509. {
  510. Location = new Point(107, 9),
  511. Parent = this,
  512. NotControl = true,
  513. Size = new Size(170, 18)
  514. };
  515. LevelLabel = new MirLabel
  516. {
  517. Location = new Point(107, 28),
  518. Parent = this,
  519. NotControl = true,
  520. Size = new Size(30, 18)
  521. };
  522. ClassLabel = new MirLabel
  523. {
  524. Location = new Point(178, 28),
  525. Parent = this,
  526. NotControl = true,
  527. Size = new Size(100, 18)
  528. };
  529. }
  530. public void Update(SelectInfo info)
  531. {
  532. if (info == null)
  533. {
  534. Index = 44;
  535. Library = Libraries.Prguse;
  536. NameLabel.Text = string.Empty;
  537. LevelLabel.Text = string.Empty;
  538. ClassLabel.Text = string.Empty;
  539. NameLabel.Visible = false;
  540. LevelLabel.Visible = false;
  541. ClassLabel.Visible = false;
  542. return;
  543. }
  544. Library = Libraries.Title;
  545. Index = 660 + (byte)info.Class;
  546. if (Selected) Index += 5;
  547. NameLabel.Text = info.Name;
  548. LevelLabel.Text = info.Level.ToString();
  549. ClassLabel.Text = info.Class.ToLocalizedString();
  550. NameLabel.Visible = true;
  551. LevelLabel.Visible = true;
  552. ClassLabel.Visible = true;
  553. }
  554. }
  555. }
  556. }