GroupDialog.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirNetwork;
  4. using Client.MirObjects;
  5. using Client.MirSounds;
  6. using C = ClientPackets;
  7. namespace Client.MirScenes.Dialogs
  8. {
  9. public sealed class GroupDialog : MirImageControl
  10. {
  11. public static bool AllowGroup;
  12. public static List<string> GroupList = new List<string>();
  13. public static Dictionary<string, string> GroupMembersMap = new Dictionary<string, string>();
  14. public MirImageControl TitleLabel;
  15. public MirButton SwitchButton, CloseButton, AddButton, DelButton;
  16. public MirLabel[] GroupMembers;
  17. public GroupDialog()
  18. {
  19. Index = 120;
  20. Library = Libraries.Prguse;
  21. Movable = true;
  22. Sort = true;
  23. Location = Center;
  24. GroupMembers = new MirLabel[Globals.MaxGroup];
  25. GroupMembers[0] = new MirLabel
  26. {
  27. AutoSize = true,
  28. Location = new Point(16, 33),
  29. Parent = this,
  30. NotControl = false,
  31. };
  32. for (int i = 1; i < GroupMembers.Length; i++)
  33. {
  34. GroupMembers[i] = new MirLabel
  35. {
  36. AutoSize = true,
  37. Location = new Point(((i + 1) % 2) * 100 + 16, 55 + ((i - 1) / 2) * 20),
  38. Parent = this,
  39. NotControl = false,
  40. };
  41. }
  42. TitleLabel = new MirImageControl
  43. {
  44. Index = 5,
  45. Library = Libraries.Title,
  46. Location = new Point(18, 8),
  47. Parent = this
  48. };
  49. CloseButton = new MirButton
  50. {
  51. HoverIndex = 361,
  52. Index = 360,
  53. Location = new Point(206, 3),
  54. Library = Libraries.Prguse2,
  55. Parent = this,
  56. PressedIndex = 362,
  57. Sound = SoundList.ButtonA,
  58. };
  59. CloseButton.Click += (o, e) => Hide();
  60. SwitchButton = new MirButton
  61. {
  62. HoverIndex = 115,
  63. Index = 114,
  64. Location = new Point(25, 219),
  65. Library = Libraries.Prguse,
  66. Parent = this,
  67. PressedIndex = 116,
  68. Sound = SoundList.ButtonA,
  69. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupSwitch)
  70. };
  71. SwitchButton.Click += (o, e) => Network.Enqueue(new C.SwitchGroup { AllowGroup = !AllowGroup });
  72. AddButton = new MirButton
  73. {
  74. HoverIndex = 134,
  75. Index = 133,
  76. Location = new Point(70, 219),
  77. Library = Libraries.Title,
  78. Parent = this,
  79. PressedIndex = 135,
  80. Sound = SoundList.ButtonA,
  81. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupAdd)
  82. };
  83. AddButton.Click += (o, e) => AddMember();
  84. DelButton = new MirButton
  85. {
  86. HoverIndex = 137,
  87. Index = 136,
  88. Location = new Point(140, 219),
  89. Library = Libraries.Title,
  90. Parent = this,
  91. PressedIndex = 138,
  92. Sound = SoundList.ButtonA,
  93. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupRemove)
  94. };
  95. DelButton.Click += (o, e) => DelMember();
  96. BeforeDraw += GroupPanel_BeforeDraw;
  97. GroupList.Clear();
  98. }
  99. private void GroupPanel_BeforeDraw(object sender, EventArgs e)
  100. {
  101. if (GroupList.Count == 0)
  102. {
  103. AddButton.Index = 130;
  104. AddButton.HoverIndex = 131;
  105. AddButton.PressedIndex = 132;
  106. }
  107. else
  108. {
  109. AddButton.Index = 133;
  110. AddButton.HoverIndex = 134;
  111. AddButton.PressedIndex = 135;
  112. }
  113. if (GroupList.Count > 0 && GroupList[0] != MapObject.User.Name)
  114. {
  115. AddButton.Visible = false;
  116. DelButton.Visible = false;
  117. }
  118. else
  119. {
  120. AddButton.Visible = true;
  121. DelButton.Visible = true;
  122. }
  123. if (AllowGroup)
  124. {
  125. SwitchButton.Index = 117;
  126. SwitchButton.HoverIndex = 118;
  127. SwitchButton.PressedIndex = 119;
  128. }
  129. else
  130. {
  131. SwitchButton.Index = 114;
  132. SwitchButton.HoverIndex = 115;
  133. SwitchButton.PressedIndex = 116;
  134. }
  135. for (int i = 0; i < GroupMembers.Length; i++)
  136. GroupMembers[i].Text = i >= GroupList.Count ? string.Empty : GroupList[i];
  137. foreach (var player in GroupMembersMap)
  138. {
  139. for (int i = 0; i < GroupMembers.Length; i++)
  140. {
  141. string playersName = GroupMembers[i].Text;
  142. if (player.Key == playersName)
  143. GroupMembers[i].Hint = player.Value;
  144. }
  145. }
  146. }
  147. public void AddMember(string name)
  148. {
  149. if (GroupList.Count >= Globals.MaxGroup)
  150. {
  151. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupHasMaxMembers), ChatType.System);
  152. return;
  153. }
  154. if (GroupList.Count > 0 && GroupList[0] != MapObject.User.Name)
  155. {
  156. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouAreNotGroupLeader), ChatType.System);
  157. return;
  158. }
  159. Network.Enqueue(new C.AddMember { Name = name });
  160. }
  161. private void AddMember()
  162. {
  163. if (GroupList.Count >= Globals.MaxGroup)
  164. {
  165. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupHasMaxMembers), ChatType.System);
  166. return;
  167. }
  168. if (GroupList.Count > 0 && GroupList[0] != MapObject.User.Name)
  169. {
  170. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouAreNotGroupLeader), ChatType.System);
  171. return;
  172. }
  173. MirInputBox inputBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupAddEnterName));
  174. inputBox.OKButton.Click += (o, e) =>
  175. {
  176. Network.Enqueue(new C.AddMember { Name = inputBox.InputTextBox.Text });
  177. inputBox.Dispose();
  178. };
  179. inputBox.Show();
  180. }
  181. private void DelMember()
  182. {
  183. if (GroupList.Count > 0 && GroupList[0] != MapObject.User.Name)
  184. {
  185. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouAreNotGroupLeader), ChatType.System);
  186. return;
  187. }
  188. MirInputBox inputBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupRemoveEnterName));
  189. inputBox.OKButton.Click += (o, e) =>
  190. {
  191. Network.Enqueue(new C.DelMember { Name = inputBox.InputTextBox.Text });
  192. inputBox.Dispose();
  193. };
  194. inputBox.Show();
  195. }
  196. }
  197. }