PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/MCQuai.Gui/SelectionWindow.cs

https://bitbucket.org/realquaisaq/mcrevive
C# | 163 lines | 147 code | 15 blank | 1 comment | 29 complexity | 58aabb7698e03356c69184d1bdb37950 MD5 | raw file
  1. using System;
  2. using System.Windows.Forms;
  3. namespace MCRevive.Gui
  4. {
  5. public partial class SelectionWindow : Form
  6. {
  7. public enum WindowKind { Rank, Achievement, MJS };
  8. public WindowKind WK = WindowKind.Rank;
  9. public SelectionWindow()
  10. {
  11. InitializeComponent();
  12. }
  13. private void SelectionWindow_Load(object sender, EventArgs e)
  14. {
  15. int i = 1;
  16. int newline = 6;
  17. int btnnum = 1;
  18. int oldposX = 0;
  19. int oldposY = 0;
  20. if (WK == WindowKind.Rank)
  21. {
  22. this.Text = "Select rank to give";
  23. Group.GroupList.ForEach((grp) =>
  24. {
  25. if (grp.name.ToLower() != "nobody" && grp.name.ToLower() != "banned")
  26. {
  27. if (btnnum + i > newline) { this.Height += 50; newline += 3; }
  28. CButton btn = new CButton();
  29. btn.Location = new System.Drawing.Point(12 + oldposX, 12 + oldposY);
  30. btn.Name = "btn" + grp.name;
  31. btn.Size = new System.Drawing.Size(100, 50);
  32. btn.TabIndex = i + btnnum;
  33. btn.Text = grp.name;
  34. btn.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  35. btn.UseVisualStyleBackColor = true;
  36. btn.Click += new System.EventHandler(this.btn_Click);
  37. this.Controls.Add(btn);
  38. if (i != 3) { oldposX += 100; i++; }
  39. else { oldposX = 0; oldposY += 50; i = 1; btnnum += 3; }
  40. }
  41. });
  42. }
  43. else if (WK == WindowKind.Achievement)
  44. {
  45. this.Width += 100;
  46. this.Text = "Click the achievements you would like";
  47. newline = 8;
  48. Server.allAchievements.ForEach((ach) =>
  49. {
  50. if (btnnum > newline) { this.Height += 65; newline += 4; }
  51. CheckBox chk = new CheckBox();
  52. chk.Appearance = Appearance.Button;
  53. chk.Location = new System.Drawing.Point(12 + oldposX, 12 + oldposY);
  54. chk.Name = "chk" + ach.realname + ((Server.allAchievements.Find(a => a.filename == ach.filename).allowed) ? "t" : "f");
  55. chk.Size = new System.Drawing.Size(100, 50);
  56. chk.TabIndex = i + btnnum;
  57. chk.Text = ach.realname;
  58. chk.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  59. chk.Checked = Server.allAchievements.Find(a => a.filename == ach.filename).allowed;
  60. chk.CheckedChanged += delegate { chk_CheckedChanged(chk.Checked, chk.Text); };
  61. chk.UseVisualStyleBackColor = true;
  62. this.Controls.Add(chk);
  63. if (i != 4) { oldposX += 100; i++; }
  64. else { oldposX = 0; oldposY += 50; i = 1; btnnum += 4; }
  65. });
  66. CButton btn = new CButton();
  67. btn.Location = new System.Drawing.Point(12, oldposY + 62);
  68. btn.Name = "btnSave";
  69. btn.Size = new System.Drawing.Size(180, 30);
  70. btn.TabIndex = i + btnnum + 1;
  71. btn.Text = "Save";
  72. btn.UseVisualStyleBackColor = true;
  73. btn.Click += new EventHandler(btnSave_Click);
  74. this.Controls.Add(btn);
  75. btn = new CButton();
  76. btn.Location = new System.Drawing.Point(Width - 208, oldposY + 62);
  77. btn.Name = "btnDiscard";
  78. btn.Size = new System.Drawing.Size(180, 30);
  79. btn.TabIndex = i + btnnum + 2;
  80. btn.Text = "Discard";
  81. btn.UseVisualStyleBackColor = true;
  82. btn.Click += new EventHandler(btnDiscard_Click);
  83. this.Controls.Add(btn);
  84. //this.Height += 20;
  85. }
  86. else if (WK == WindowKind.MJS)
  87. {
  88. Server.s.OnMJS += updateLog;
  89. this.Width += 100;
  90. this.Height += 200;
  91. this.Text = "MJS Log";
  92. TextBox txt = new TextBox();
  93. txt.Location = new System.Drawing.Point(12, 12);
  94. txt.Name = "txtMJSLog";
  95. txt.Multiline = true;
  96. txt.ReadOnly = true;
  97. txt.Size = new System.Drawing.Size(400,300);
  98. txt.TabIndex = 0;
  99. txt.Text = Program.MJSLog;
  100. txt.SelectedText = "";
  101. this.Controls.Add(txt);
  102. }
  103. }
  104. private void updateLog(string p)
  105. {
  106. foreach (Control c in this.Controls)
  107. if (c.Name == "txtMJSLog")
  108. c.Text = Program.MJSLog;
  109. }
  110. private void btn_Click(object sender, EventArgs e)
  111. {
  112. Command.all.Find("setrank").Use(null, Program.selected + " " + sender.ToString().Split(':')[1].Trim().ToLower());
  113. GuiWindow.RankWindowUse = false;
  114. this.Dispose();
  115. }
  116. private void chk_CheckedChanged(bool Checked, string ach)
  117. {
  118. foreach (Control tP in Controls)
  119. {
  120. if (tP is CheckBox)
  121. {
  122. if (tP.Text == ach) tP.Name = "chk" + tP.Name.Substring(3, tP.Name.Length - 4) + ((Checked) ? "t" : "f");
  123. }
  124. }
  125. }
  126. private void btnSave_Click(object sender, EventArgs e)
  127. {
  128. Server.allAchievements = new System.Collections.Generic.List<Server.achievements>();
  129. foreach (Control tP in Controls)
  130. {
  131. if (tP is CheckBox)
  132. {
  133. Server.achievements ds = new Server.achievements();
  134. ds.realname = tP.Name.Substring(3, tP.Name.Length - 4);
  135. ds.filename = tP.Name.Replace(" ", "-").Replace("'", "").ToLower().Substring(3, tP.Name.Length - 4);
  136. ds.allowed = (tP.Name.Remove(0, tP.Name.Length - 1) == "t");
  137. Server.allAchievements.Add(ds);
  138. }
  139. }
  140. MCRevive.Properties.Save("achievements");
  141. this.Dispose();
  142. }
  143. private void btnDiscard_Click(object sender, EventArgs e)
  144. {
  145. this.Dispose();
  146. }
  147. }
  148. }