KeyboardLayoutDialog.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirSounds;
  4. namespace Client.MirScenes.Dialogs
  5. {
  6. public sealed class KeyboardLayoutDialog : MirImageControl
  7. {
  8. public MirImageControl TitleLabel, EnforceButtonChecked;
  9. public MirLabel PageLabel, EnforceButtonLabel;
  10. public MirButton CloseButton;
  11. public MirButton ScrollUpButton, ScrollDownButton, PositionBar;
  12. public MirButton ResetButton, EnforceButton;
  13. public List<MirControl> Rows = new List<MirControl>();
  14. public bool Enforce = true;
  15. public int TopLine;
  16. public int LineCount = 16;
  17. public int PosX = 491, PosMinY = 101, PosMaxY = 344;
  18. public KeyBind WaitingForBind = null;
  19. public KeyboardLayoutDialog()
  20. {
  21. Index = 119;
  22. Library = Libraries.Title;
  23. Movable = true;
  24. Sort = true;
  25. Location = Center;
  26. TitleLabel = new MirImageControl
  27. {
  28. //Index = 7,
  29. Library = Libraries.Title,
  30. Location = new Point(18, 4),
  31. Parent = this
  32. };
  33. PageLabel = new MirLabel
  34. {
  35. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.KeyboardSettings),
  36. Font = new Font(Settings.FontName, Settings.FontSize + 2, FontStyle.Bold),
  37. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  38. Parent = this,
  39. Size = new System.Drawing.Size(242, 30),
  40. Location = new Point(135, 34)
  41. };
  42. CloseButton = new MirButton
  43. {
  44. HoverIndex = 361,
  45. Index = 360,
  46. Location = new Point(489, 3),
  47. Library = Libraries.Prguse2,
  48. Parent = this,
  49. PressedIndex = 362,
  50. Sound = SoundList.ButtonA,
  51. };
  52. CloseButton.Click += (o, e) =>
  53. {
  54. CMain.InputKeys.Save(CMain.InputKeys.Keylist);
  55. Hide();
  56. };
  57. ScrollUpButton = new MirButton
  58. {
  59. Index = 197,
  60. HoverIndex = 198,
  61. PressedIndex = 199,
  62. Library = Libraries.Prguse2,
  63. Parent = this,
  64. Size = new Size(16, 14),
  65. Location = new Point(491, 88),
  66. Sound = SoundList.ButtonA,
  67. Visible = true
  68. };
  69. ScrollUpButton.Click += (o, e) =>
  70. {
  71. if (TopLine <= 0) return;
  72. TopLine--;
  73. UpdateText();
  74. UpdatePositionBar();
  75. };
  76. ScrollDownButton = new MirButton
  77. {
  78. Index = 207,
  79. HoverIndex = 208,
  80. Library = Libraries.Prguse2,
  81. PressedIndex = 209,
  82. Parent = this,
  83. Size = new Size(16, 14),
  84. Location = new Point(491, 363),
  85. Sound = SoundList.ButtonA,
  86. Visible = true
  87. };
  88. ScrollDownButton.Click += (o, e) =>
  89. {
  90. if (TopLine + LineCount >= CMain.InputKeys.Keylist.Count + CMain.InputKeys.Keylist.GroupBy(x => x.Group).Select(y => y.First()).Count()) return;
  91. TopLine++;
  92. UpdateText();
  93. UpdatePositionBar();
  94. };
  95. PositionBar = new MirButton
  96. {
  97. Index = 205,
  98. HoverIndex = 206,
  99. PressedIndex = 206,
  100. Library = Libraries.Prguse2,
  101. Location = new Point(491, 101),
  102. Parent = this,
  103. Movable = true,
  104. Sound = SoundList.None,
  105. Visible = true
  106. };
  107. PositionBar.OnMoving += PositionBar_OnMoving;
  108. ResetButton = new MirButton
  109. {
  110. Index = 120,
  111. HoverIndex = 121,
  112. PressedIndex = 122,
  113. Library = Libraries.Title,
  114. Size = new Size(72, 25),
  115. Location = new Point(30, 400),
  116. Parent = this,
  117. Visible = true,
  118. };
  119. ResetButton.Click += (o, e) =>
  120. {
  121. for (int i = 0; i < CMain.InputKeys.Keylist.Count; i++)
  122. {
  123. KeyBind bind = CMain.InputKeys.Keylist[i];
  124. KeyBind defaultBind = CMain.InputKeys.DefaultKeylist[i];
  125. if (bind.Key != defaultBind.Key || bind.RequireAlt != defaultBind.RequireAlt || bind.RequireCtrl != defaultBind.RequireCtrl || bind.RequireShift != defaultBind.RequireShift || bind.RequireTilde != defaultBind.RequireTilde)
  126. {
  127. CMain.InputKeys.Keylist[i].Key = defaultBind.Key;
  128. CMain.InputKeys.Keylist[i].RequireAlt = defaultBind.RequireAlt;
  129. CMain.InputKeys.Keylist[i].RequireCtrl = defaultBind.RequireCtrl;
  130. CMain.InputKeys.Keylist[i].RequireShift = defaultBind.RequireShift;
  131. CMain.InputKeys.Keylist[i].RequireTilde = defaultBind.RequireTilde;
  132. //CMain.Profile.InputKeys.Save(CMain.Profile.InputKeys.Keylist[i]);
  133. }
  134. }
  135. UpdateText();
  136. MirMessageBox messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.KeyboardSettingsResetDefault), MirMessageBoxButtons.OK);
  137. messageBox.Show();
  138. };
  139. EnforceButton = new MirButton
  140. {
  141. Visible = true,
  142. Index = 1346,
  143. Library = Libraries.Prguse,
  144. Sound = SoundList.ButtonA,
  145. Parent = this,
  146. Location = new Point(105, 406)
  147. };
  148. EnforceButton.Click += EnforceButton_Click;
  149. EnforceButtonChecked = new MirImageControl()
  150. {
  151. Visible = Enforce,
  152. Index = 1347,
  153. Library = Libraries.Prguse,
  154. Parent = this,
  155. NotControl = true,
  156. Location = new Point(105, 406)
  157. };
  158. EnforceButtonLabel = new MirLabel
  159. {
  160. Visible = true,
  161. NotControl = true,
  162. Parent = this,
  163. Location = new Point(120, 404),
  164. AutoSize = true,
  165. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AssignRuleStrict)
  166. };
  167. UpdateText();
  168. }
  169. private void EnforceButton_Click(object sender, EventArgs e)
  170. {
  171. Enforce = !Enforce;
  172. EnforceButtonChecked.Visible = Enforce;
  173. if (Enforce) EnforceButtonLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AssignRuleStrict);
  174. else EnforceButtonLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AssignRuleRelaxed);
  175. }
  176. public void UpdateText()
  177. {
  178. foreach (MirControl t in Rows)
  179. t.Dispose();
  180. Rows.Clear();
  181. var orderedList = CMain.InputKeys.Keylist.OrderBy(x => x.Group).ThenBy(x => x.Description).ToList();
  182. string currentGroup = "";
  183. int groupCount = 0;
  184. for (int i = 0; i < orderedList.Count; i++)
  185. {
  186. if (i < TopLine) continue;
  187. int y = (18 * (i - TopLine)) + (groupCount * 30);
  188. if (y > 260) break;
  189. if (currentGroup != orderedList[i].Group)
  190. {
  191. Rows.Add(new KeybindHeadingRow(orderedList[i].Group)
  192. {
  193. Parent = this,
  194. Location = new Point(15, 90 + y),
  195. Visible = true,
  196. Size = new Size(400, 40)
  197. });
  198. groupCount++;
  199. currentGroup = orderedList[i].Group;
  200. }
  201. y = (18 * (i - TopLine)) + (groupCount * 30);
  202. if (y > 260) break;
  203. Rows.Add(new KeybindRow(orderedList[i].function)
  204. {
  205. Parent = this,
  206. Location = new Point(20, 90 + y),
  207. Visible = true,
  208. Size = new Size(460, 15)
  209. });
  210. }
  211. }
  212. private void UpdatePositionBar()
  213. {
  214. if (CMain.InputKeys.Keylist.Count <= LineCount)
  215. {
  216. PositionBar.Visible = false;
  217. return;
  218. }
  219. PositionBar.Visible = true;
  220. int interval = (PosMaxY - PosMinY) / (CMain.InputKeys.Keylist.Count - LineCount);
  221. int x = PosX;
  222. int y = PosMinY + (TopLine * interval);
  223. if (y >= PosMaxY) y = PosMaxY;
  224. if (y <= PosMinY) y = PosMinY;
  225. PositionBar.Location = new Point(x, y);
  226. }
  227. private void PositionBar_OnMoving(object sender, MouseEventArgs e)
  228. {
  229. int x = PosX;
  230. int y = PositionBar.Location.Y;
  231. if (y >= PosMaxY) y = PosMaxY;
  232. if (y <= PosMinY) y = PosMinY;
  233. int location = y - PosMinY;
  234. int interval = (PosMaxY - PosMinY) / (CMain.InputKeys.Keylist.Count - LineCount);
  235. double yPoint = (double)location / interval;
  236. TopLine = Convert.ToInt16(Math.Floor(yPoint));
  237. PositionBar.Location = new Point(x, y);
  238. UpdateText();
  239. }
  240. public void CheckNewInput(KeyEventArgs e)
  241. {
  242. if (e.KeyCode == Keys.ControlKey || e.KeyCode == Keys.Menu || e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.Oem8 || e.KeyCode == Keys.None) return;
  243. KeyBind bind = CMain.InputKeys.Keylist.Single(x => x.function == WaitingForBind.function);
  244. //if (CMain.Profile.InputKeys.Keylist.Any(x => x.Key == e.KeyCode && x.RequireAlt == (byte)(CMain.Alt ? 1 : 0) && x.RequireShift == (byte)(CMain.Shift ? 1 : 0) && x.RequireCtrl == (byte)(CMain.Ctrl ? 1 : 0) && x.RequireTilde == (byte)(CMain.Tilde ? 1 : 0)))
  245. //{
  246. // GameScene.Scene.ChatDialog.ReceiveChat("Another shortcut with this key bind already exists.", ChatType.System);
  247. // WaitingForBind = null;
  248. // UpdateText();
  249. // return;
  250. //}
  251. if (e.KeyCode == Keys.Delete)
  252. {
  253. bind.Key = Keys.None;
  254. bind.RequireAlt = bind.RequireShift = bind.RequireCtrl = bind.RequireTilde = 2;
  255. }
  256. else
  257. {
  258. bind.Key = e.KeyCode;
  259. bind.RequireAlt = (byte)(CMain.Alt ? 1 : Enforce ? 0 : 2);
  260. bind.RequireShift = (byte)(CMain.Shift ? 1 : Enforce ? 0 : 2);
  261. bind.RequireCtrl = (byte)(CMain.Ctrl ? 1 : Enforce ? 0 : 2);
  262. bind.RequireTilde = (byte)(CMain.Tilde ? 1 : Enforce ? 0 : 2);
  263. }
  264. //CMain.Profile.InputKeys.Save(WaitingForBind);
  265. WaitingForBind = null;
  266. UpdateText();
  267. }
  268. }
  269. public sealed class KeybindRow : MirControl
  270. {
  271. public MirLabel BindName, DefaultBind;
  272. public MirButton CurrentBindButton;
  273. public KeyBind KeyBind;
  274. public KeybindRow(KeybindOptions option)
  275. {
  276. KeyBind defaultBind = CMain.InputKeys.DefaultKeylist.Single(x => x.function == option);
  277. KeyBind currentBind = CMain.InputKeys.Keylist.Single(x => x.function == option);
  278. KeyBind = currentBind;
  279. BindName = new MirLabel
  280. {
  281. Parent = this,
  282. Size = new Size(200, 15),
  283. Location = new Point(0, 0),
  284. Text = defaultBind.Description,
  285. Visible = true
  286. };
  287. DefaultBind = new MirLabel
  288. {
  289. Parent = this,
  290. Size = new Size(100, 15),
  291. Location = new Point(200, 0),
  292. Text = CMain.InputKeys.GetKey(option, true),
  293. Visible = true
  294. };
  295. CurrentBindButton = new MirButton
  296. {
  297. Parent = this,
  298. Text = string.Format(" {0}", CMain.InputKeys.GetKey(option, false)),
  299. Location = new Point(340, 0),
  300. Size = new Size(120, 16),
  301. Visible = true,
  302. Index = 190,
  303. Library = Libraries.Prguse2,
  304. HoverIndex = 191,
  305. PressedIndex = 192
  306. };
  307. CurrentBindButton.Click += (o, e) =>
  308. {
  309. if (GameScene.Scene.KeyboardLayoutDialog.WaitingForBind != null)
  310. {
  311. GameScene.Scene.KeyboardLayoutDialog.WaitingForBind = null;
  312. GameScene.Scene.KeyboardLayoutDialog.UpdateText();
  313. return;
  314. }
  315. GameScene.Scene.KeyboardLayoutDialog.WaitingForBind = KeyBind;
  316. ((MirButton)o).Text = string.Format(" {0}", "????");
  317. ((MirButton)o).Index = 192;
  318. ((MirButton)o).HoverIndex = 192;
  319. ((MirButton)o).PressedIndex = 192;
  320. };
  321. }
  322. }
  323. public sealed class KeybindHeadingRow : MirControl
  324. {
  325. public MirImageControl BulletImage, SpacerImage;
  326. public MirLabel BulletLabel;
  327. public KeybindHeadingRow(string groupName)
  328. {
  329. BulletImage = new MirImageControl
  330. {
  331. Parent = this,
  332. Index = 201,
  333. Library = Libraries.Prguse2,
  334. Size = new Size(8, 6),
  335. Location = new Point(10, 10),
  336. Visible = true
  337. };
  338. BulletLabel = new MirLabel
  339. {
  340. Parent = this,
  341. Text = groupName,
  342. Size = new Size(100, 20),
  343. Location = new Point(20, 5),
  344. Font = new Font(Settings.FontName, Settings.FontSize + 1, FontStyle.Bold),
  345. Visible = true
  346. };
  347. SpacerImage = new MirImageControl
  348. {
  349. Parent = this,
  350. Index = 202,
  351. Library = Libraries.Prguse2,
  352. Size = new Size(3, 464),
  353. Location = new Point(0, 25),
  354. Visible = true
  355. };
  356. }
  357. }
  358. }