| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- using Client.MirControls;
- using Client.MirGraphics;
- using Client.MirNetwork;
- using Client.MirObjects;
- using Client.MirSounds;
- using C = ClientPackets;
- namespace Client.MirScenes.Dialogs
- {
- public sealed class GroupDialog : MirImageControl
- {
- public static bool AllowGroup;
- public static List<string> GroupList = new List<string>();
- public static Dictionary<string, string> GroupMembersMap = new Dictionary<string, string>();
- public MirImageControl TitleLabel;
- public MirButton SwitchButton, CloseButton, AddButton, DelButton;
- public MirLabel[] GroupMembers;
- public GroupDialog()
- {
- Index = 120;
- Library = Libraries.Prguse;
- Movable = true;
- Sort = true;
- Location = Center;
- GroupMembers = new MirLabel[Globals.MaxGroup];
- GroupMembers[0] = new MirLabel
- {
- AutoSize = true,
- Location = new Point(16, 33),
- Parent = this,
- NotControl = false,
- };
- for (int i = 1; i < GroupMembers.Length; i++)
- {
- GroupMembers[i] = new MirLabel
- {
- AutoSize = true,
- Location = new Point(((i + 1) % 2) * 100 + 16, 55 + ((i - 1) / 2) * 20),
- Parent = this,
- NotControl = false,
- };
- }
- TitleLabel = new MirImageControl
- {
- Index = 5,
- Library = Libraries.Title,
- Location = new Point(18, 8),
- Parent = this
- };
- CloseButton = new MirButton
- {
- HoverIndex = 361,
- Index = 360,
- Location = new Point(206, 3),
- Library = Libraries.Prguse2,
- Parent = this,
- PressedIndex = 362,
- Sound = SoundList.ButtonA,
- };
- CloseButton.Click += (o, e) => Hide();
- SwitchButton = new MirButton
- {
- HoverIndex = 115,
- Index = 114,
- Location = new Point(25, 219),
- Library = Libraries.Prguse,
- Parent = this,
- PressedIndex = 116,
- Sound = SoundList.ButtonA,
- Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupSwitch)
- };
- SwitchButton.Click += (o, e) => Network.Enqueue(new C.SwitchGroup { AllowGroup = !AllowGroup });
- AddButton = new MirButton
- {
- HoverIndex = 134,
- Index = 133,
- Location = new Point(70, 219),
- Library = Libraries.Title,
- Parent = this,
- PressedIndex = 135,
- Sound = SoundList.ButtonA,
- Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupAdd)
- };
- AddButton.Click += (o, e) => AddMember();
- DelButton = new MirButton
- {
- HoverIndex = 137,
- Index = 136,
- Location = new Point(140, 219),
- Library = Libraries.Title,
- Parent = this,
- PressedIndex = 138,
- Sound = SoundList.ButtonA,
- Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupRemove)
- };
- DelButton.Click += (o, e) => DelMember();
- BeforeDraw += GroupPanel_BeforeDraw;
- GroupList.Clear();
- }
- private void GroupPanel_BeforeDraw(object sender, EventArgs e)
- {
- if (GroupList.Count == 0)
- {
- AddButton.Index = 130;
- AddButton.HoverIndex = 131;
- AddButton.PressedIndex = 132;
- }
- else
- {
- AddButton.Index = 133;
- AddButton.HoverIndex = 134;
- AddButton.PressedIndex = 135;
- }
- if (GroupList.Count > 0 && GroupList[0] != MapObject.User.Name)
- {
- AddButton.Visible = false;
- DelButton.Visible = false;
- }
- else
- {
- AddButton.Visible = true;
- DelButton.Visible = true;
- }
- if (AllowGroup)
- {
- SwitchButton.Index = 117;
- SwitchButton.HoverIndex = 118;
- SwitchButton.PressedIndex = 119;
- }
- else
- {
- SwitchButton.Index = 114;
- SwitchButton.HoverIndex = 115;
- SwitchButton.PressedIndex = 116;
- }
- for (int i = 0; i < GroupMembers.Length; i++)
- GroupMembers[i].Text = i >= GroupList.Count ? string.Empty : GroupList[i];
- foreach (var player in GroupMembersMap)
- {
- for (int i = 0; i < GroupMembers.Length; i++)
- {
- string playersName = GroupMembers[i].Text;
- if (player.Key == playersName)
- GroupMembers[i].Hint = player.Value;
- }
- }
- }
- public void AddMember(string name)
- {
- if (GroupList.Count >= Globals.MaxGroup)
- {
- GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupHasMaxMembers), ChatType.System);
- return;
- }
- if (GroupList.Count > 0 && GroupList[0] != MapObject.User.Name)
- {
- GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouAreNotGroupLeader), ChatType.System);
- return;
- }
- Network.Enqueue(new C.AddMember { Name = name });
- }
- private void AddMember()
- {
- if (GroupList.Count >= Globals.MaxGroup)
- {
- GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupHasMaxMembers), ChatType.System);
- return;
- }
- if (GroupList.Count > 0 && GroupList[0] != MapObject.User.Name)
- {
- GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouAreNotGroupLeader), ChatType.System);
- return;
- }
- MirInputBox inputBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupAddEnterName));
- inputBox.OKButton.Click += (o, e) =>
- {
- Network.Enqueue(new C.AddMember { Name = inputBox.InputTextBox.Text });
- inputBox.Dispose();
- };
- inputBox.Show();
- }
- private void DelMember()
- {
- if (GroupList.Count > 0 && GroupList[0] != MapObject.User.Name)
- {
- GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouAreNotGroupLeader), ChatType.System);
- return;
- }
- MirInputBox inputBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GroupRemoveEnterName));
- inputBox.OKButton.Click += (o, e) =>
- {
- Network.Enqueue(new C.DelMember { Name = inputBox.InputTextBox.Text });
- inputBox.Dispose();
- };
- inputBox.Show();
- }
- }
- }
|