NewCharacterDialog.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. using System.Text.RegularExpressions;
  2. using Client.MirControls;
  3. using Client.MirGraphics;
  4. using Client.MirSounds;
  5. namespace Client.MirScenes.Dialogs
  6. {
  7. public sealed class NewCharacterDialog : MirImageControl
  8. {
  9. private static readonly Regex Reg = new Regex(@"^[A-Za-z0-9]|[\u4e00-\u9fa5]{" + Globals.MinCharacterNameLength + "," + Globals.MaxCharacterNameLength + "}$");
  10. public MirImageControl TitleLabel;
  11. public MirAnimatedControl CharacterDisplay;
  12. public MirButton OKButton,
  13. CancelButton,
  14. WarriorButton,
  15. WizardButton,
  16. TaoistButton,
  17. AssassinButton,
  18. ArcherButton,
  19. MaleButton,
  20. FemaleButton;
  21. public MirTextBox NameTextBox;
  22. public MirLabel Description;
  23. public MirClass Class;
  24. public MirGender Gender;
  25. #region Descriptions
  26. public readonly string WarriorDescription = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.WarriorsDescription);
  27. public readonly string WizardDescription = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.WizardsDescription);
  28. public readonly string TaoistDescription = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.TaoistsDescription);
  29. public readonly string AssassinDescription = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AssassinsDescription);
  30. public readonly string ArcherDescription = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ArchersDescription);
  31. #endregion
  32. public NewCharacterDialog()
  33. {
  34. Index = 73;
  35. Library = Libraries.Prguse;
  36. Location = new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2);
  37. Modal = true;
  38. TitleLabel = new MirImageControl
  39. {
  40. Index = 20,
  41. Library = Libraries.Title,
  42. Location = new Point(206, 11),
  43. Parent = this,
  44. };
  45. CancelButton = new MirButton
  46. {
  47. HoverIndex = 281,
  48. Index = 280,
  49. Library = Libraries.Title,
  50. Location = new Point(425, 425),
  51. Parent = this,
  52. PressedIndex = 282
  53. };
  54. CancelButton.Click += (o, e) => Hide();
  55. OKButton = new MirButton
  56. {
  57. Enabled = false,
  58. HoverIndex = 361,
  59. Index = 360,
  60. Library = Libraries.Title,
  61. Location = new Point(160, 425),
  62. Parent = this,
  63. PressedIndex = 362,
  64. };
  65. OKButton.Click += (o, e) => CreateCharacter();
  66. NameTextBox = new MirTextBox
  67. {
  68. Location = new Point(325, 268),
  69. Parent = this,
  70. Size = new Size(240, 20),
  71. MaxLength = Globals.MaxCharacterNameLength
  72. };
  73. NameTextBox.TextBox.KeyPress += TextBox_KeyPress;
  74. NameTextBox.TextBox.TextChanged += CharacterNameTextBox_TextChanged;
  75. NameTextBox.SetFocus();
  76. CharacterDisplay = new MirAnimatedControl
  77. {
  78. Animated = true,
  79. AnimationCount = 16,
  80. AnimationDelay = 250,
  81. Index = 20,
  82. Library = Libraries.ChrSel,
  83. Location = new Point(120, 250),
  84. Parent = this,
  85. UseOffSet = true,
  86. };
  87. CharacterDisplay.AfterDraw += (o, e) =>
  88. {
  89. if (Class == MirClass.Wizard)
  90. Libraries.ChrSel.DrawBlend(CharacterDisplay.Index + 560, CharacterDisplay.DisplayLocationWithoutOffSet, Color.White, true);
  91. };
  92. WarriorButton = new MirButton
  93. {
  94. HoverIndex = 2427,
  95. Index = 2427,
  96. Library = Libraries.Prguse,
  97. Location = new Point(323, 296),
  98. Parent = this,
  99. PressedIndex = 2428,
  100. Sound = SoundList.ButtonA,
  101. };
  102. WarriorButton.Click += (o, e) =>
  103. {
  104. Class = MirClass.Warrior;
  105. UpdateInterface();
  106. };
  107. WizardButton = new MirButton
  108. {
  109. HoverIndex = 2430,
  110. Index = 2429,
  111. Library = Libraries.Prguse,
  112. Location = new Point(373, 296),
  113. Parent = this,
  114. PressedIndex = 2431,
  115. Sound = SoundList.ButtonA,
  116. };
  117. WizardButton.Click += (o, e) =>
  118. {
  119. Class = MirClass.Wizard;
  120. UpdateInterface();
  121. };
  122. TaoistButton = new MirButton
  123. {
  124. HoverIndex = 2433,
  125. Index = 2432,
  126. Library = Libraries.Prguse,
  127. Location = new Point(423, 296),
  128. Parent = this,
  129. PressedIndex = 2434,
  130. Sound = SoundList.ButtonA,
  131. };
  132. TaoistButton.Click += (o, e) =>
  133. {
  134. Class = MirClass.Taoist;
  135. UpdateInterface();
  136. };
  137. AssassinButton = new MirButton
  138. {
  139. HoverIndex = 2436,
  140. Index = 2435,
  141. Library = Libraries.Prguse,
  142. Location = new Point(473, 296),
  143. Parent = this,
  144. PressedIndex = 2437,
  145. Sound = SoundList.ButtonA,
  146. };
  147. AssassinButton.Click += (o, e) =>
  148. {
  149. Class = MirClass.Assassin;
  150. UpdateInterface();
  151. };
  152. ArcherButton = new MirButton
  153. {
  154. HoverIndex = 2439,
  155. Index = 2438,
  156. Library = Libraries.Prguse,
  157. Location = new Point(523, 296),
  158. Parent = this,
  159. PressedIndex = 2440,
  160. Sound = SoundList.ButtonA,
  161. };
  162. ArcherButton.Click += (o, e) =>
  163. {
  164. Class = MirClass.Archer;
  165. UpdateInterface();
  166. };
  167. MaleButton = new MirButton
  168. {
  169. HoverIndex = 2421,
  170. Index = 2421,
  171. Library = Libraries.Prguse,
  172. Location = new Point(323, 343),
  173. Parent = this,
  174. PressedIndex = 2422,
  175. Sound = SoundList.ButtonA,
  176. };
  177. MaleButton.Click += (o, e) =>
  178. {
  179. Gender = MirGender.Male;
  180. UpdateInterface();
  181. };
  182. FemaleButton = new MirButton
  183. {
  184. HoverIndex = 2424,
  185. Index = 2423,
  186. Library = Libraries.Prguse,
  187. Location = new Point(373, 343),
  188. Parent = this,
  189. PressedIndex = 2425,
  190. Sound = SoundList.ButtonA,
  191. };
  192. FemaleButton.Click += (o, e) =>
  193. {
  194. Gender = MirGender.Female;
  195. UpdateInterface();
  196. };
  197. Description = new MirLabel
  198. {
  199. Border = true,
  200. Location = new Point(279, 70),
  201. Parent = this,
  202. Size = new Size(278, 170),
  203. Text = WarriorDescription,
  204. };
  205. }
  206. public override void Show()
  207. {
  208. base.Show();
  209. Class = MirClass.Warrior;
  210. Gender = MirGender.Male;
  211. NameTextBox.Text = string.Empty;
  212. UpdateInterface();
  213. }
  214. private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
  215. {
  216. if (sender == null) return;
  217. if (e.KeyChar != (char)Keys.Enter) return;
  218. e.Handled = true;
  219. if (OKButton.Enabled)
  220. OKButton.InvokeMouseClick(null);
  221. }
  222. private void CharacterNameTextBox_TextChanged(object sender, EventArgs e)
  223. {
  224. if (string.IsNullOrEmpty(NameTextBox.Text))
  225. {
  226. OKButton.Enabled = false;
  227. NameTextBox.Border = false;
  228. }
  229. else if (!Reg.IsMatch(NameTextBox.Text))
  230. {
  231. OKButton.Enabled = false;
  232. NameTextBox.Border = true;
  233. NameTextBox.BorderColour = Color.Red;
  234. }
  235. else
  236. {
  237. OKButton.Enabled = true;
  238. NameTextBox.Border = true;
  239. NameTextBox.BorderColour = Color.Green;
  240. }
  241. }
  242. public event EventHandler OnCreateCharacter;
  243. private void CreateCharacter()
  244. {
  245. OKButton.Enabled = false;
  246. if (OnCreateCharacter != null)
  247. OnCreateCharacter.Invoke(this, EventArgs.Empty);
  248. }
  249. private void UpdateInterface()
  250. {
  251. MaleButton.Index = 2420;
  252. FemaleButton.Index = 2423;
  253. WarriorButton.Index = 2426;
  254. WizardButton.Index = 2429;
  255. TaoistButton.Index = 2432;
  256. AssassinButton.Index = 2435;
  257. ArcherButton.Index = 2438;
  258. switch (Gender)
  259. {
  260. case MirGender.Male:
  261. MaleButton.Index = 2421;
  262. break;
  263. case MirGender.Female:
  264. FemaleButton.Index = 2424;
  265. break;
  266. }
  267. switch (Class)
  268. {
  269. case MirClass.Warrior:
  270. WarriorButton.Index = 2427;
  271. Description.Text = WarriorDescription;
  272. CharacterDisplay.Index = (byte)Gender == 0 ? 20 : 300; //220 : 500;
  273. break;
  274. case MirClass.Wizard:
  275. WizardButton.Index = 2430;
  276. Description.Text = WizardDescription;
  277. CharacterDisplay.Index = (byte)Gender == 0 ? 40 : 320; //240 : 520;
  278. break;
  279. case MirClass.Taoist:
  280. TaoistButton.Index = 2433;
  281. Description.Text = TaoistDescription;
  282. CharacterDisplay.Index = (byte)Gender == 0 ? 60 : 340; //260 : 540;
  283. break;
  284. case MirClass.Assassin:
  285. AssassinButton.Index = 2436;
  286. Description.Text = AssassinDescription;
  287. CharacterDisplay.Index = (byte)Gender == 0 ? 80 : 360; //280 : 560;
  288. break;
  289. case MirClass.Archer:
  290. ArcherButton.Index = 2439;
  291. Description.Text = ArcherDescription;
  292. CharacterDisplay.Index = (byte)Gender == 0 ? 100 : 140; //160 : 180;
  293. break;
  294. }
  295. //CharacterDisplay.Index = ((byte)_class + 1) * 20 + (byte)_gender * 280;
  296. }
  297. protected override void Dispose(bool disposing)
  298. {
  299. base.Dispose(disposing);
  300. OnCreateCharacter = null;
  301. }
  302. }
  303. }