From 21ffa8dfa217d259b682320036c57fc7b6e3ea18 Mon Sep 17 00:00:00 2001 From: milimoe <110188673+milimoe@users.noreply.github.com> Date: Mon, 11 Dec 2023 01:11:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9MainUI=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0Gaming=E6=8E=A5=E5=8F=A3=20(#25)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加Gaming接口 * 修改MainUI,预留了Gaming的相关接口 * Fix: ConnectEventArgs的参数不正确 * 新的AddonController构造方法 * 完善MainUI:添加了房间类型、模组、地图选择框 --------- Co-authored-by: yeziuku --- FunGame.Desktop/Controller/MainController.cs | 79 ++-- .../Controller/RunTimeController.cs | 34 +- FunGame.Desktop/Library/Other/Config.cs | 5 +- FunGame.Desktop/Library/Other/Constant.cs | 56 ++- FunGame.Desktop/Model/RunTime.cs | 1 + FunGame.Desktop/UI/Main/Main.Designer.cs | 194 ++++++---- FunGame.Desktop/UI/Main/Main.cs | 366 ++++++++++++------ FunGame.Desktop/UI/Main/Main.resx | 2 +- 8 files changed, 473 insertions(+), 264 deletions(-) diff --git a/FunGame.Desktop/Controller/MainController.cs b/FunGame.Desktop/Controller/MainController.cs index 741888b..b329f27 100644 --- a/FunGame.Desktop/Controller/MainController.cs +++ b/FunGame.Desktop/Controller/MainController.cs @@ -9,7 +9,7 @@ using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Controller { - public class MainController(Main main) + public class MainController(Main Main) { private readonly Session Usercfg = RunTime.Session; private readonly DataRequest ChatRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_Chat); @@ -19,6 +19,8 @@ namespace Milimoe.FunGame.Desktop.Controller private readonly DataRequest UpdateRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_UpdateRoom); private readonly DataRequest IntoRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_IntoRoom); private readonly DataRequest QuitRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_QuitRoom); + private readonly DataRequest SetReadyRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_Ready); + private readonly DataRequest CancelReadyRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_CancelReady); private readonly DataRequest StartGameRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_StartGame); #region 公开方法 @@ -31,6 +33,8 @@ namespace Milimoe.FunGame.Desktop.Controller UpdateRoomRequest.Dispose(); IntoRoomRequest.Dispose(); QuitRoomRequest.Dispose(); + SetReadyRequest.Dispose(); + CancelReadyRequest.Dispose(); StartGameRequest.Dispose(); } @@ -53,7 +57,7 @@ namespace Milimoe.FunGame.Desktop.Controller if (key == Usercfg.LoginKey) { Usercfg.LoginKey = Guid.Empty; - main.UpdateUI(MainInvokeType.LogOut, msg ?? ""); + Main.UpdateUI(MainInvokeType.LogOut, msg ?? ""); return true; } } @@ -62,8 +66,8 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - main.ShowMessage(ShowMessageType.Error, "无法登出您的账号,请联系服务器管理员。", "登出失败", 5); - main.GetMessage(e.GetErrorInfo()); + Main.ShowMessage(ShowMessageType.Error, "无法登出您的账号,请联系服务器管理员。", "登出失败", 5); + Main.GetMessage(e.GetErrorInfo()); } return false; } @@ -82,7 +86,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); return false; } } @@ -98,13 +102,13 @@ namespace Milimoe.FunGame.Desktop.Controller if (UpdateRoomRequest.Result == RequestResult.Success) { list = UpdateRoomRequest.GetResult>("rooms") ?? new(); - main.UpdateUI(MainInvokeType.UpdateRoom, list); + Main.UpdateUI(MainInvokeType.UpdateRoom, list); } else throw new CanNotIntoRoomException(); } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); } return result; @@ -120,7 +124,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); return 0; } } @@ -131,28 +135,26 @@ namespace Milimoe.FunGame.Desktop.Controller { bool result = true; - DataRequest request = RunTime.NewDataRequest(DataRequestType.Main_Ready); - request.AddRequestData("roomid", roomid); - await request.SendRequestAsync(); - if (request.Result == RequestResult.Success) + SetReadyRequest.AddRequestData("roomid", roomid); + await SetReadyRequest.SendRequestAsync(); + if (SetReadyRequest.Result == RequestResult.Success) { - result = request.GetResult("result"); + result = SetReadyRequest.GetResult("result"); if (result) { Config.FunGame_isInRoom = true; - main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 准备完毕。"); + Main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 准备完毕。"); } - List ReadyPlayerList = request.GetResult>("ready") ?? new(); - if (ReadyPlayerList.Count > 0) main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username))); - List NotReadyPlayerList = request.GetResult>("notready") ?? new(); - if (NotReadyPlayerList.Count > 0) main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username))); + List ReadyPlayerList = SetReadyRequest.GetResult>("ready") ?? new(); + if (ReadyPlayerList.Count > 0) Main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username))); + List NotReadyPlayerList = SetReadyRequest.GetResult>("notready") ?? new(); + if (NotReadyPlayerList.Count > 0) Main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username))); } - request.Dispose(); return result; } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); return false; } } @@ -163,28 +165,26 @@ namespace Milimoe.FunGame.Desktop.Controller { bool result = true; - DataRequest request = RunTime.NewDataRequest(DataRequestType.Main_CancelReady); - request.AddRequestData("roomid", roomid); - await request.SendRequestAsync(); - if (request.Result == RequestResult.Success) + CancelReadyRequest.AddRequestData("roomid", roomid); + await CancelReadyRequest.SendRequestAsync(); + if (CancelReadyRequest.Result == RequestResult.Success) { - result = request.GetResult("result"); + result = CancelReadyRequest.GetResult("result"); if (result) { Config.FunGame_isInRoom = false; - main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 已取消准备。"); + Main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 已取消准备。"); } - List ReadyPlayerList = request.GetResult>("ready") ?? new(); - if (ReadyPlayerList.Count > 0) main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username))); - List NotReadyPlayerList = request.GetResult>("notready") ?? new(); - if (NotReadyPlayerList.Count > 0) main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username))); + List ReadyPlayerList = CancelReadyRequest.GetResult>("ready") ?? new(); + if (ReadyPlayerList.Count > 0) Main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username))); + List NotReadyPlayerList = CancelReadyRequest.GetResult>("notready") ?? new(); + if (NotReadyPlayerList.Count > 0) Main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username))); } - request.Dispose(); return result; } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); return false; } } @@ -211,12 +211,12 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); return result; } } - public async Task CreateRoomAsync(string RoomType, string GameMode, string GameMap, string Password = "") + public async Task CreateRoomAsync(RoomType RoomType, string GameMode, string GameMap, bool IsRank, string Password = "") { Room room = General.HallInstance; @@ -227,6 +227,7 @@ namespace Milimoe.FunGame.Desktop.Controller CreateRoomRequest.AddRequestData("gamemap", GameMap); CreateRoomRequest.AddRequestData("master", Usercfg.LoginUser); CreateRoomRequest.AddRequestData("password", Password); + CreateRoomRequest.AddRequestData("isrank", IsRank); await CreateRoomRequest.SendRequestAsync(); if (CreateRoomRequest.Result == RequestResult.Success) { @@ -235,13 +236,13 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); } return room; } - public async Task MatchRoomAsync(string RoomType, bool isCancel = false) + public async Task MatchRoomAsync(RoomType RoomType, bool isCancel = false) { bool result = false; @@ -258,7 +259,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); } return result; @@ -278,7 +279,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); return false; } } @@ -297,7 +298,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - main.GetMessage(e.GetErrorInfo(), TimeType.None); + Main.GetMessage(e.GetErrorInfo(), TimeType.None); } return false; diff --git a/FunGame.Desktop/Controller/RunTimeController.cs b/FunGame.Desktop/Controller/RunTimeController.cs index 25467f1..bcb844b 100644 --- a/FunGame.Desktop/Controller/RunTimeController.cs +++ b/FunGame.Desktop/Controller/RunTimeController.cs @@ -28,11 +28,13 @@ namespace Milimoe.FunGame.Desktop.Controller { try { - RunTime.PluginLoader = PluginLoader.LoadPlugins( - new Action(WritelnSystemInfo), - new Func(NewDataRequest), - new Func(NewLongRunningDataRequest), - RunTime.Session, RunTime.Config); + // 构建AddonController + Hashtable delegates = []; + delegates.Add("WriteLine", new Action(WritelnSystemInfo)); + delegates.Add("Error", new Action(Error)); + delegates.Add("NewDataRequest", new Func(NewDataRequest)); + delegates.Add("NewLongRunningDataRequest", new Func(NewLongRunningDataRequest)); + RunTime.PluginLoader = PluginLoader.LoadPlugins( delegates, RunTime.Session, RunTime.Config); foreach (string name in RunTime.PluginLoader.Plugins.Keys) { Main.GetMessage("[ Plugin ] Loaded: " + name); @@ -48,11 +50,13 @@ namespace Milimoe.FunGame.Desktop.Controller { try { - RunTime.GameModeLoader = GameModeLoader.LoadGameModes( - new Action(WritelnSystemInfo), - new Func(NewDataRequest), - new Func(NewLongRunningDataRequest), - RunTime.Session, RunTime.Config); + // 构建AddonController + Hashtable delegates = []; + delegates.Add("WriteLine", new Action(WritelnSystemInfo)); + delegates.Add("Error", new Action(Error)); + delegates.Add("NewDataRequest", new Func(NewDataRequest)); + delegates.Add("NewLongRunningDataRequest", new Func(NewLongRunningDataRequest)); + RunTime.GameModeLoader = GameModeLoader.LoadGameModes(Constant.FunGameType, delegates, RunTime.Session, RunTime.Config); foreach (string name in RunTime.GameModeLoader.Modes.Keys) { Main.GetMessage("[ GameMode ] Loaded: " + name); @@ -88,7 +92,7 @@ namespace Milimoe.FunGame.Desktop.Controller string[] gamemodes = []; if (RunTime.GameModeLoader != null) { - gamemodes = RunTime.GameModeLoader.Modes.Keys.ToArray(); + gamemodes = [.. RunTime.GameModeLoader.Modes.Keys]; } ConnectArgs.Add(gamemodes); // 服务器检查是否拥有需要的模组 ConnectArgs.Add(FunGameInfo.FunGame_DebugMode); // 是否开启了debug模式 @@ -270,7 +274,7 @@ namespace Milimoe.FunGame.Desktop.Controller protected override void SocketHandler_EndGame(SocketObject ServerMessage) { Room room = General.HallInstance; - List users = new(); + List users = []; if (ServerMessage.Length > 0) room = ServerMessage.GetParam(0) ?? General.HallInstance; if (ServerMessage.Length > 1) users = ServerMessage.GetParam>(1) ?? users; Main.UpdateUI(MainInvokeType.EndGame, room, users); @@ -278,7 +282,11 @@ namespace Milimoe.FunGame.Desktop.Controller protected override void SocketHandler_Gaming(SocketObject ServerMessage) { - + GamingType gamingtype = GamingType.None; + Hashtable data = []; + if (ServerMessage.Length > 0) gamingtype = ServerMessage.GetParam(0); + if (ServerMessage.Length > 1) data = ServerMessage.GetParam(1) ?? data; + RunTime.Gaming?.GamingHandler(gamingtype, data); } } } diff --git a/FunGame.Desktop/Library/Other/Config.cs b/FunGame.Desktop/Library/Other/Config.cs index d837053..a1ffd99 100644 --- a/FunGame.Desktop/Library/Other/Config.cs +++ b/FunGame.Desktop/Library/Other/Config.cs @@ -1,4 +1,5 @@ -using Milimoe.FunGame.Desktop.Model; +using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Desktop.Model; namespace Milimoe.FunGame.Desktop.Library { @@ -70,7 +71,7 @@ namespace Milimoe.FunGame.Desktop.Library /// /// 当前游戏模式 /// - public static string FunGame_RoomType + public static RoomType FunGame_RoomType { get => RunTime.Config.FunGame_RoomType; set => RunTime.Config.FunGame_RoomType = value; diff --git a/FunGame.Desktop/Library/Other/Constant.cs b/FunGame.Desktop/Library/Other/Constant.cs index ed6cbe4..b970434 100644 --- a/FunGame.Desktop/Library/Other/Constant.cs +++ b/FunGame.Desktop/Library/Other/Constant.cs @@ -1,4 +1,8 @@ -using Milimoe.FunGame.Core.Library.Constant; +using System.Collections.Generic; +using Milimoe.FunGame.Core.Api.Utility; +using Milimoe.FunGame.Core.Library.Common.Addon; +using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Desktop.Model; namespace Milimoe.FunGame.Desktop.Library { @@ -7,7 +11,7 @@ namespace Milimoe.FunGame.Desktop.Library /** * Game Configs */ - public static int FunGameType { get; } = (int)FunGameInfo.FunGame.FunGame_Desktop; + public static FunGameInfo.FunGame FunGameType => FunGameInfo.FunGame.FunGame_Desktop; /** * FunGame Configs @@ -73,5 +77,53 @@ namespace Milimoe.FunGame.Desktop.Library FunGame_AutoRetryOn, FunGame_AutoRetryOff }; + public static readonly object[] AllComboItem = ["全部"]; + public static object[] SupportedRoomType() + { + List objs = []; + objs.Add(RoomSet.GetTypeString(RoomType.All)); + objs.Add(RoomSet.GetTypeString(RoomType.Mix)); + objs.Add(RoomSet.GetTypeString(RoomType.Team)); + objs.Add(RoomSet.GetTypeString(RoomType.Solo)); + objs.Add(RoomSet.GetTypeString(RoomType.FastAuto)); + objs.Add(RoomSet.GetTypeString(RoomType.Custom)); + return objs.ToArray(); + } + public static object[] SupportedGameMode(RoomType type) + { + if (RunTime.GameModeLoader != null) + { + IEnumerable list; + if (type == RoomType.All) + { + list = RunTime.GameModeLoader.Modes.Values.Select(mod => mod.Name).Distinct(); + } + else + { + list = RunTime.GameModeLoader.Modes.Values.Where(mod => mod.RoomType == type).Select(mod => mod.Name).Distinct(); + } + if (list.Any()) return AllComboItem.Union(list).ToArray(); + } + return ["- 缺少模组 -"]; + } + public static object[] SupportedGameMap() + { + List list = []; + if (RunTime.GameModeLoader != null) + { + foreach (GameMode mod in RunTime.GameModeLoader.Modes.Values) + { + list.AddRange(mod.Maps.Distinct()); + } + } + if (list.Count != 0) return AllComboItem.Union(list).ToArray(); + return ["- 缺少地图 -"]; + } + public static object[] SupportedGameMap(GameMode mod) + { + IEnumerable list = mod.Maps.Where(map => mod.Maps.Contains(map)).Distinct(); + if (list.Any()) return AllComboItem.Union(list).ToArray(); + return ["- 缺少地图 -"]; + } } } diff --git a/FunGame.Desktop/Model/RunTime.cs b/FunGame.Desktop/Model/RunTime.cs index 4a8f7c5..ecab392 100644 --- a/FunGame.Desktop/Model/RunTime.cs +++ b/FunGame.Desktop/Model/RunTime.cs @@ -11,6 +11,7 @@ namespace Milimoe.FunGame.Desktop.Model public static Core.Model.RoomList RoomList { get; } = new(); public static Core.Model.Session Session { get; } = new(); public static Core.Model.FunGameConfig Config { get; } = new(); + public static Core.Model.Gaming? Gaming { get; set; } = null; public static Core.Api.Utility.PluginLoader? PluginLoader { get; set; } = null; public static Core.Api.Utility.GameModeLoader? GameModeLoader { get; set; } = null; public static Core.Library.Common.Network.Socket? Socket { get; set; } = null; diff --git a/FunGame.Desktop/UI/Main/Main.Designer.cs b/FunGame.Desktop/UI/Main/Main.Designer.cs index d4aaf3c..97636f5 100644 --- a/FunGame.Desktop/UI/Main/Main.Designer.cs +++ b/FunGame.Desktop/UI/Main/Main.Designer.cs @@ -40,8 +40,6 @@ namespace Milimoe.FunGame.Desktop.UI SendTalkText = new Button(); TalkText = new TextBox(); StartMatch = new Button(); - CheckMix = new CheckBox(); - CheckTeam = new CheckBox(); RoomSetting = new Button(); Login = new Button(); NowAccount = new Label(); @@ -69,6 +67,10 @@ namespace Milimoe.FunGame.Desktop.UI Store = new Button(); Copyright = new LinkLabel(); StopMatch = new Button(); + CheckIsRank = new CheckBox(); + ComboRoomType = new ComboBox(); + ComboGameMode = new ComboBox(); + ComboGameMap = new ComboBox(); RoomBox.SuspendLayout(); Notice.SuspendLayout(); InfoBox.SuspendLayout(); @@ -78,11 +80,11 @@ namespace Milimoe.FunGame.Desktop.UI // Title // Title.BackColor = Color.Transparent; - Title.Font = new Font("LanaPixel", 26.25F, FontStyle.Bold, GraphicsUnit.Point); + Title.Font = new Font("LanaPixel", 26.25F, FontStyle.Bold); Title.Location = new Point(3, 3); Title.Size = new Size(689, 47); Title.TabIndex = 96; - Title.Text = "FunGame By Milimoe"; + Title.Text = "FunGame"; Title.TextAlign = ContentAlignment.MiddleLeft; // // Exit @@ -95,7 +97,7 @@ namespace Milimoe.FunGame.Desktop.UI Exit.FlatAppearance.MouseDownBackColor = Color.FromArgb(255, 128, 128); Exit.FlatAppearance.MouseOverBackColor = Color.FromArgb(255, 192, 192); Exit.FlatStyle = FlatStyle.Flat; - Exit.Font = new Font("LanaPixel", 36F, FontStyle.Bold, GraphicsUnit.Point); + Exit.Font = new Font("LanaPixel", 36F, FontStyle.Bold); Exit.ForeColor = Color.Red; Exit.Location = new Point(750, 3); Exit.Name = "Exit"; @@ -117,7 +119,7 @@ namespace Milimoe.FunGame.Desktop.UI MinForm.FlatAppearance.MouseDownBackColor = Color.Gray; MinForm.FlatAppearance.MouseOverBackColor = Color.DarkGray; MinForm.FlatStyle = FlatStyle.Flat; - MinForm.Font = new Font("LanaPixel", 36F, FontStyle.Bold, GraphicsUnit.Point); + MinForm.Font = new Font("LanaPixel", 36F, FontStyle.Bold); MinForm.ForeColor = Color.Red; MinForm.Location = new Point(698, 3); MinForm.Name = "MinForm"; @@ -130,7 +132,7 @@ namespace Milimoe.FunGame.Desktop.UI // Connection // Connection.BackColor = Color.Transparent; - Connection.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + Connection.Font = new Font("LanaPixel", 12F); Connection.Location = new Point(649, 424); Connection.Margin = new Padding(3); Connection.Name = "Connection"; @@ -158,7 +160,7 @@ namespace Milimoe.FunGame.Desktop.UI SendTalkText.FlatAppearance.MouseDownBackColor = Color.Teal; SendTalkText.FlatAppearance.MouseOverBackColor = Color.FromArgb(0, 192, 192); SendTalkText.FlatStyle = FlatStyle.Flat; - SendTalkText.Font = new Font("LanaPixel", 11.25F, FontStyle.Regular, GraphicsUnit.Point); + SendTalkText.Font = new Font("LanaPixel", 11.25F); SendTalkText.Location = new Point(608, 421); SendTalkText.Name = "SendTalkText"; SendTalkText.Size = new Size(51, 27); @@ -170,7 +172,7 @@ namespace Milimoe.FunGame.Desktop.UI // TalkText // TalkText.AllowDrop = true; - TalkText.Font = new Font("LanaPixel", 12.75F, FontStyle.Regular, GraphicsUnit.Point); + TalkText.Font = new Font("LanaPixel", 12.75F); TalkText.ForeColor = Color.DarkGray; TalkText.Location = new Point(317, 422); TalkText.Name = "TalkText"; @@ -185,8 +187,8 @@ namespace Milimoe.FunGame.Desktop.UI // // StartMatch // - StartMatch.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - StartMatch.Location = new Point(665, 184); + StartMatch.Font = new Font("LanaPixel", 12F); + StartMatch.Location = new Point(665, 214); StartMatch.Name = "StartMatch"; StartMatch.Size = new Size(132, 35); StartMatch.TabIndex = 9; @@ -194,36 +196,10 @@ namespace Milimoe.FunGame.Desktop.UI StartMatch.UseVisualStyleBackColor = true; StartMatch.Click += StartMatch_Click; // - // CheckMix - // - CheckMix.BackColor = Color.Transparent; - CheckMix.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - CheckMix.Location = new Point(675, 94); - CheckMix.Name = "CheckMix"; - CheckMix.Size = new Size(123, 24); - CheckMix.TabIndex = 7; - CheckMix.Text = "混战模式房间"; - CheckMix.TextAlign = ContentAlignment.BottomLeft; - CheckMix.UseVisualStyleBackColor = false; - CheckMix.CheckedChanged += CheckGameMode_CheckedChanged; - // - // CheckTeam - // - CheckTeam.BackColor = Color.Transparent; - CheckTeam.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - CheckTeam.Location = new Point(675, 124); - CheckTeam.Name = "CheckTeam"; - CheckTeam.Size = new Size(123, 24); - CheckTeam.TabIndex = 8; - CheckTeam.Text = "团队模式房间"; - CheckTeam.TextAlign = ContentAlignment.BottomLeft; - CheckTeam.UseVisualStyleBackColor = false; - CheckTeam.CheckedChanged += CheckGameMode_CheckedChanged; - // // RoomSetting // - RoomSetting.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - RoomSetting.Location = new Point(665, 225); + RoomSetting.Font = new Font("LanaPixel", 12F); + RoomSetting.Location = new Point(665, 254); RoomSetting.Name = "RoomSetting"; RoomSetting.Size = new Size(132, 35); RoomSetting.TabIndex = 11; @@ -234,7 +210,7 @@ namespace Milimoe.FunGame.Desktop.UI // // Login // - Login.Font = new Font("LanaPixel", 15.75F, FontStyle.Regular, GraphicsUnit.Point); + Login.Font = new Font("LanaPixel", 15.75F); Login.Location = new Point(665, 380); Login.Name = "Login"; Login.Size = new Size(132, 39); @@ -246,18 +222,18 @@ namespace Milimoe.FunGame.Desktop.UI // NowAccount // NowAccount.BackColor = Color.Transparent; - NowAccount.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - NowAccount.Location = new Point(659, 352); + NowAccount.Font = new Font("LanaPixel", 12F); + NowAccount.Location = new Point(551, 9); NowAccount.Name = "NowAccount"; - NowAccount.Size = new Size(141, 25); + NowAccount.Size = new Size(141, 41); NowAccount.TabIndex = 91; NowAccount.Text = "请登录账号"; NowAccount.TextAlign = ContentAlignment.MiddleCenter; // // AccountSetting // - AccountSetting.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - AccountSetting.Location = new Point(665, 317); + AccountSetting.Font = new Font("LanaPixel", 12F); + AccountSetting.Location = new Point(665, 342); AccountSetting.Name = "AccountSetting"; AccountSetting.Size = new Size(65, 32); AccountSetting.TabIndex = 12; @@ -266,8 +242,8 @@ namespace Milimoe.FunGame.Desktop.UI // // About // - About.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - About.Location = new Point(732, 317); + About.Font = new Font("LanaPixel", 12F); + About.Location = new Point(733, 341); About.Name = "About"; About.Size = new Size(65, 32); About.TabIndex = 13; @@ -277,8 +253,8 @@ namespace Milimoe.FunGame.Desktop.UI // Room // Room.BackColor = Color.Transparent; - Room.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - Room.Location = new Point(665, 263); + Room.Font = new Font("LanaPixel", 12F); + Room.Location = new Point(665, 293); Room.Name = "Room"; Room.Size = new Size(132, 45); Room.TabIndex = 90; @@ -288,7 +264,7 @@ namespace Milimoe.FunGame.Desktop.UI // RoomText // RoomText.AllowDrop = true; - RoomText.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + RoomText.Font = new Font("LanaPixel", 12F); RoomText.ForeColor = Color.DarkGray; RoomText.Location = new Point(6, 226); RoomText.Name = "RoomText"; @@ -305,7 +281,7 @@ namespace Milimoe.FunGame.Desktop.UI // PresetText.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; PresetText.DropDownStyle = ComboBoxStyle.DropDownList; - PresetText.Font = new Font("LanaPixel", 11.25F, FontStyle.Regular, GraphicsUnit.Point); + PresetText.Font = new Font("LanaPixel", 11.25F); PresetText.FormattingEnabled = true; PresetText.Items.AddRange(new object[] { "- 快捷消息 -" }); PresetText.Location = new Point(195, 422); @@ -323,7 +299,7 @@ namespace Milimoe.FunGame.Desktop.UI RoomBox.Controls.Add(RoomList); RoomBox.Controls.Add(RoomText); RoomBox.Controls.Add(QueryRoom); - RoomBox.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + RoomBox.Font = new Font("LanaPixel", 12F); RoomBox.Location = new Point(3, 56); RoomBox.Name = "RoomBox"; RoomBox.Size = new Size(186, 258); @@ -334,7 +310,7 @@ namespace Milimoe.FunGame.Desktop.UI // NowRoomID // NowRoomID.AllowDrop = true; - NowRoomID.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + NowRoomID.Font = new Font("LanaPixel", 12F); NowRoomID.ForeColor = Color.DarkGray; NowRoomID.Location = new Point(6, 226); NowRoomID.Name = "NowRoomID"; @@ -347,7 +323,7 @@ namespace Milimoe.FunGame.Desktop.UI // // CopyRoomID // - CopyRoomID.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + CopyRoomID.Font = new Font("LanaPixel", 12F); CopyRoomID.Location = new Point(126, 225); CopyRoomID.Name = "CopyRoomID"; CopyRoomID.Size = new Size(51, 27); @@ -371,7 +347,7 @@ namespace Milimoe.FunGame.Desktop.UI // // QueryRoom // - QueryRoom.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + QueryRoom.Font = new Font("LanaPixel", 12F); QueryRoom.Location = new Point(126, 225); QueryRoom.Name = "QueryRoom"; QueryRoom.Size = new Size(51, 27); @@ -382,7 +358,7 @@ namespace Milimoe.FunGame.Desktop.UI // // RefreshRoomList // - RefreshRoomList.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + RefreshRoomList.Font = new Font("LanaPixel", 12F); RefreshRoomList.Image = Properties.Resources.refresh; RefreshRoomList.Location = new Point(162, 248); RefreshRoomList.Name = "RefreshRoomList"; @@ -396,7 +372,7 @@ namespace Milimoe.FunGame.Desktop.UI Notice.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; Notice.BackColor = Color.Transparent; Notice.Controls.Add(NoticeText); - Notice.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + Notice.Font = new Font("LanaPixel", 12F); Notice.Location = new Point(3, 317); Notice.Name = "Notice"; Notice.Size = new Size(186, 110); @@ -420,7 +396,7 @@ namespace Milimoe.FunGame.Desktop.UI // InfoBox.BackColor = Color.Transparent; InfoBox.Controls.Add(TransparentRectControl); - InfoBox.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + InfoBox.Font = new Font("LanaPixel", 12F); InfoBox.Location = new Point(195, 56); InfoBox.Name = "InfoBox"; InfoBox.Size = new Size(464, 363); @@ -459,8 +435,8 @@ namespace Milimoe.FunGame.Desktop.UI // // QuitRoom // - QuitRoom.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - QuitRoom.Location = new Point(665, 184); + QuitRoom.Font = new Font("LanaPixel", 12F); + QuitRoom.Location = new Point(665, 212); QuitRoom.Name = "QuitRoom"; QuitRoom.Size = new Size(132, 35); QuitRoom.TabIndex = 9; @@ -471,8 +447,8 @@ namespace Milimoe.FunGame.Desktop.UI // // CreateRoom // - CreateRoom.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - CreateRoom.Location = new Point(665, 225); + CreateRoom.Font = new Font("LanaPixel", 12F); + CreateRoom.Location = new Point(666, 253); CreateRoom.Name = "CreateRoom"; CreateRoom.Size = new Size(132, 35); CreateRoom.TabIndex = 10; @@ -482,7 +458,7 @@ namespace Milimoe.FunGame.Desktop.UI // // Logout // - Logout.Font = new Font("LanaPixel", 15.75F, FontStyle.Regular, GraphicsUnit.Point); + Logout.Font = new Font("LanaPixel", 15.75F); Logout.Location = new Point(665, 380); Logout.Name = "Logout"; Logout.Size = new Size(132, 39); @@ -495,19 +471,18 @@ namespace Milimoe.FunGame.Desktop.UI // CheckHasPass // CheckHasPass.BackColor = Color.Transparent; - CheckHasPass.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - CheckHasPass.Location = new Point(675, 154); + CheckHasPass.Font = new Font("LanaPixel", 12F); + CheckHasPass.Location = new Point(737, 181); CheckHasPass.Name = "CheckHasPass"; - CheckHasPass.Size = new Size(123, 24); + CheckHasPass.Size = new Size(60, 24); CheckHasPass.TabIndex = 9; - CheckHasPass.Text = "带密码的房间"; - CheckHasPass.TextAlign = ContentAlignment.BottomLeft; + CheckHasPass.Text = "密码"; + CheckHasPass.TextAlign = ContentAlignment.MiddleCenter; CheckHasPass.UseVisualStyleBackColor = false; - CheckHasPass.CheckedChanged += CheckGameMode_CheckedChanged; // // Stock // - Stock.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + Stock.Font = new Font("LanaPixel", 12F); Stock.Location = new Point(661, 56); Stock.Name = "Stock"; Stock.Size = new Size(65, 32); @@ -517,7 +492,7 @@ namespace Milimoe.FunGame.Desktop.UI // // Store // - Store.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); + Store.Font = new Font("LanaPixel", 12F); Store.Location = new Point(732, 56); Store.Name = "Store"; Store.Size = new Size(65, 32); @@ -530,7 +505,7 @@ namespace Milimoe.FunGame.Desktop.UI Copyright.ActiveLinkColor = Color.FromArgb(0, 64, 64); Copyright.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; Copyright.BackColor = Color.Transparent; - Copyright.Font = new Font("LanaPixel", 10.5F, FontStyle.Regular, GraphicsUnit.Point); + Copyright.Font = new Font("LanaPixel", 10.5F); Copyright.LinkArea = new LinkArea(6, 8); Copyright.LinkBehavior = LinkBehavior.AlwaysUnderline; Copyright.LinkColor = Color.Teal; @@ -546,8 +521,8 @@ namespace Milimoe.FunGame.Desktop.UI // // StopMatch // - StopMatch.Font = new Font("LanaPixel", 12F, FontStyle.Regular, GraphicsUnit.Point); - StopMatch.Location = new Point(665, 184); + StopMatch.Font = new Font("LanaPixel", 12F); + StopMatch.Location = new Point(665, 213); StopMatch.Name = "StopMatch"; StopMatch.Size = new Size(132, 35); StopMatch.TabIndex = 10; @@ -555,8 +530,59 @@ namespace Milimoe.FunGame.Desktop.UI StopMatch.UseVisualStyleBackColor = true; StopMatch.Visible = false; StopMatch.Click += StopMatch_Click; - StopMatch.MouseHover += StopMatch_MouseHover; StopMatch.MouseLeave += StopMatch_MouseLeave; + StopMatch.MouseHover += StopMatch_MouseHover; + // + // CheckIsRank + // + CheckIsRank.BackColor = Color.Transparent; + CheckIsRank.Enabled = false; + CheckIsRank.Font = new Font("LanaPixel", 12F); + CheckIsRank.Location = new Point(671, 181); + CheckIsRank.Name = "CheckIsRank"; + CheckIsRank.Size = new Size(60, 24); + CheckIsRank.TabIndex = 98; + CheckIsRank.Text = "排位"; + CheckIsRank.TextAlign = ContentAlignment.MiddleCenter; + CheckIsRank.UseVisualStyleBackColor = false; + // + // ComboRoomType + // + ComboRoomType.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + ComboRoomType.DropDownStyle = ComboBoxStyle.DropDownList; + ComboRoomType.Font = new Font("LanaPixel", 11.25F); + ComboRoomType.FormattingEnabled = true; + ComboRoomType.Items.AddRange(new object[] { "- 房间类型 -" }); + ComboRoomType.Location = new Point(665, 94); + ComboRoomType.Name = "ComboRoomType"; + ComboRoomType.Size = new Size(130, 26); + ComboRoomType.TabIndex = 99; + ComboRoomType.SelectionChangeCommitted += ComboRoomType_SelectionChangeCommitted; + // + // ComboGameMode + // + ComboGameMode.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + ComboGameMode.DropDownStyle = ComboBoxStyle.DropDownList; + ComboGameMode.Font = new Font("LanaPixel", 11.25F); + ComboGameMode.FormattingEnabled = true; + ComboGameMode.Items.AddRange(new object[] { "- 请选择类型 -" }); + ComboGameMode.Location = new Point(665, 122); + ComboGameMode.Name = "ComboGameMode"; + ComboGameMode.Size = new Size(130, 26); + ComboGameMode.TabIndex = 100; + ComboGameMode.SelectionChangeCommitted += ComboGameMode_SelectionChangeCommitted; + // + // ComboGameMap + // + ComboGameMap.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + ComboGameMap.DropDownStyle = ComboBoxStyle.DropDownList; + ComboGameMap.Font = new Font("LanaPixel", 11.25F); + ComboGameMap.FormattingEnabled = true; + ComboGameMap.Items.AddRange(new object[] { "- 请选择类型 -" }); + ComboGameMap.Location = new Point(665, 150); + ComboGameMap.Name = "ComboGameMap"; + ComboGameMap.Size = new Size(130, 26); + ComboGameMap.TabIndex = 101; // // Main // @@ -564,6 +590,10 @@ namespace Milimoe.FunGame.Desktop.UI AutoScaleMode = AutoScaleMode.Font; BackgroundImage = Properties.Resources.back; ClientSize = new Size(800, 450); + Controls.Add(ComboGameMap); + Controls.Add(ComboGameMode); + Controls.Add(ComboRoomType); + Controls.Add(CheckIsRank); Controls.Add(RefreshRoomList); Controls.Add(StopMatch); Controls.Add(Copyright); @@ -585,8 +615,6 @@ namespace Milimoe.FunGame.Desktop.UI Controls.Add(NowAccount); Controls.Add(Login); Controls.Add(CheckHasPass); - Controls.Add(CheckTeam); - Controls.Add(CheckMix); Controls.Add(StartMatch); Controls.Add(Light); Controls.Add(Connection); @@ -602,8 +630,6 @@ namespace Milimoe.FunGame.Desktop.UI Controls.SetChildIndex(Connection, 0); Controls.SetChildIndex(Light, 0); Controls.SetChildIndex(StartMatch, 0); - Controls.SetChildIndex(CheckMix, 0); - Controls.SetChildIndex(CheckTeam, 0); Controls.SetChildIndex(CheckHasPass, 0); Controls.SetChildIndex(Login, 0); Controls.SetChildIndex(NowAccount, 0); @@ -625,6 +651,10 @@ namespace Milimoe.FunGame.Desktop.UI Controls.SetChildIndex(Copyright, 0); Controls.SetChildIndex(StopMatch, 0); Controls.SetChildIndex(RefreshRoomList, 0); + Controls.SetChildIndex(CheckIsRank, 0); + Controls.SetChildIndex(ComboRoomType, 0); + Controls.SetChildIndex(ComboGameMode, 0); + Controls.SetChildIndex(ComboGameMap, 0); RoomBox.ResumeLayout(false); RoomBox.PerformLayout(); Notice.ResumeLayout(false); @@ -641,8 +671,6 @@ namespace Milimoe.FunGame.Desktop.UI private Label Connection; private Label Light; private Button StartMatch; - private CheckBox CheckMix; - private CheckBox CheckTeam; private Button RoomSetting; private Button Login; private Label NowAccount; @@ -672,5 +700,9 @@ namespace Milimoe.FunGame.Desktop.UI private TextBox NowRoomID; private Button CopyRoomID; private Button RefreshRoomList; + private CheckBox CheckIsRank; + private ComboBox ComboGameMap; + private ComboBox ComboGameMode; + private ComboBox ComboRoomType; } } \ No newline at end of file diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs index 84252cf..f21b4a7 100644 --- a/FunGame.Desktop/UI/Main/Main.cs +++ b/FunGame.Desktop/UI/Main/Main.cs @@ -45,7 +45,7 @@ namespace Milimoe.FunGame.Desktop.UI public void Init() { RunTime.Main = this; - SetButtonEnableIfLogon(false, ClientState.WaitConnect); + SetButtonEnabled(false, ClientState.WaitConnect); SetRoomid(Usercfg.InRoom); // 房间号初始化 ShowFunGameInfo(); // 显示FunGame信息 GetFunGameConfig(); // 获取FunGame配置 @@ -65,6 +65,19 @@ namespace Milimoe.FunGame.Desktop.UI RunTime.Controller.LoadGameModes(); // 加载插件 RunTime.Controller.LoadPlugins(); + // 设置预设 + InvokeUpdateUI(() => + { + ComboRoomType.Items.Clear(); + ComboRoomType.Items.AddRange(Constant.SupportedRoomType()); + ComboRoomType.SelectedIndex = 0; + ComboGameMode.Items.Clear(); + ComboGameMode.Items.AddRange(Constant.SupportedGameMode(RoomType.All)); + ComboGameMode.SelectedIndex = 0; + ComboGameMap.Items.Clear(); + ComboGameMap.Items.AddRange(Constant.SupportedGameMap()); + ComboGameMap.SelectedIndex = 0; + }); // 自动连接服务器 if (Config.FunGame_isAutoConnect) InvokeController_Connect(); }); @@ -106,8 +119,8 @@ namespace Milimoe.FunGame.Desktop.UI case MainInvokeType.SetGreen: Config.FunGame_isRetrying = false; SetServerStatusLight(LightType.Green); - if (Usercfg.InRoom.Roomid != "-1") SetButtonEnableIfLogon(true, ClientState.InRoom); - else SetButtonEnableIfLogon(true, ClientState.Online); + if (Usercfg.InRoom.Roomid != "-1") SetButtonEnabled(true, ClientState.InRoom); + else SetButtonEnabled(true, ClientState.Online); Config.FunGame_isConnected = true; CurrentRetryTimes = 0; break; @@ -115,8 +128,8 @@ namespace Milimoe.FunGame.Desktop.UI case MainInvokeType.SetGreenAndPing: Config.FunGame_isRetrying = false; SetServerStatusLight(LightType.Green, ping: NetworkUtility.GetServerPing(RunTime.Session.Server_IP)); - if (Usercfg.InRoom.Roomid != "-1") SetButtonEnableIfLogon(true, ClientState.InRoom); - else SetButtonEnableIfLogon(true, ClientState.Online); + if (Usercfg.InRoom.Roomid != "-1") SetButtonEnabled(true, ClientState.InRoom); + else SetButtonEnabled(true, ClientState.Online); Config.FunGame_isConnected = true; CurrentRetryTimes = 0; break; @@ -124,7 +137,7 @@ namespace Milimoe.FunGame.Desktop.UI case MainInvokeType.SetYellow: Config.FunGame_isRetrying = false; SetServerStatusLight(LightType.Yellow); - SetButtonEnableIfLogon(false, ClientState.WaitConnect); + SetButtonEnabled(false, ClientState.WaitConnect); Config.FunGame_isConnected = true; CurrentRetryTimes = 0; break; @@ -132,7 +145,7 @@ namespace Milimoe.FunGame.Desktop.UI case MainInvokeType.WaitConnectAndSetYellow: Config.FunGame_isRetrying = false; SetServerStatusLight(LightType.Yellow); - SetButtonEnableIfLogon(false, ClientState.WaitConnect); + SetButtonEnabled(false, ClientState.WaitConnect); Config.FunGame_isConnected = true; CurrentRetryTimes = 0; if (MainController != null && Config.FunGame_isAutoConnect) @@ -145,14 +158,14 @@ namespace Milimoe.FunGame.Desktop.UI case MainInvokeType.WaitLoginAndSetYellow: Config.FunGame_isRetrying = false; SetServerStatusLight(LightType.Yellow, true); - SetButtonEnableIfLogon(false, ClientState.WaitLogin); + SetButtonEnabled(false, ClientState.WaitLogin); Config.FunGame_isConnected = true; CurrentRetryTimes = 0; break; case MainInvokeType.SetRed: SetServerStatusLight(LightType.Red); - SetButtonEnableIfLogon(false, ClientState.WaitConnect); + SetButtonEnabled(false, ClientState.WaitConnect); Config.FunGame_isConnected = false; break; @@ -162,7 +175,7 @@ namespace Milimoe.FunGame.Desktop.UI Config.FunGame_isRetrying = false; Config.FunGame_isConnected = false; SetServerStatusLight(LightType.Red); - SetButtonEnableIfLogon(false, ClientState.WaitConnect); + SetButtonEnabled(false, ClientState.WaitConnect); LogoutAccount(); MainController?.MainController_Disposed(); CloseConnectedWindows(); @@ -177,7 +190,7 @@ namespace Milimoe.FunGame.Desktop.UI Config.FunGame_isAutoLogin = false; Config.FunGame_isConnected = false; SetServerStatusLight(LightType.Yellow); - SetButtonEnableIfLogon(false, ClientState.WaitConnect); + SetButtonEnabled(false, ClientState.WaitConnect); LogoutAccount(); MainController?.MainController_Disposed(); break; @@ -189,7 +202,7 @@ namespace Milimoe.FunGame.Desktop.UI Config.FunGame_isRetrying = false; Config.FunGame_isAutoLogin = false; SetServerStatusLight(LightType.Yellow, true); - SetButtonEnableIfLogon(false, ClientState.WaitLogin); + SetButtonEnabled(false, ClientState.WaitLogin); LogoutAccount(); if (objs != null && objs.Length > 0) { @@ -223,11 +236,10 @@ namespace Milimoe.FunGame.Desktop.UI { if (r.Roomid != "-1") { - string item = r.Roomid; - if (r.Name.Trim() != "") - { - item += " [ " + r.Name + " ]"; - } + string item = r.Roomid + " [ "; + if (r.IsRank) item += "排位, "; + if (r.HasPass) item += "密码, "; + item += RoomSet.GetTypeString(r.RoomType) + " ] "; RoomList.Items.Add(item); } } @@ -354,7 +366,7 @@ namespace Milimoe.FunGame.Desktop.UI } else { - INIHelper.Init((FunGameInfo.FunGame)Constant.FunGameType); + INIHelper.Init(Constant.FunGameType); WritelnGameInfo(">> 首次启动,已自动为你创建配置文件。"); GetFunGameConfig(); } @@ -466,7 +478,7 @@ namespace Milimoe.FunGame.Desktop.UI NowRoomID.Visible = true; CopyRoomID.Visible = true; // 禁用和激活按钮,并切换预设快捷消息 - SetButtonEnableIfLogon(true, ClientState.InRoom); + SetButtonEnabled(true, ClientState.InRoom); } /// @@ -486,11 +498,15 @@ namespace Milimoe.FunGame.Desktop.UI WritelnGameInfo("房间 [ " + room.Roomid + " (" + PlayerCount + "人" + RoomSet.GetTypeString(room.RoomType) + ") ] 的游戏正式开始!"); if (RunTime.GameModeLoader?.Modes.ContainsKey(room.GameMode) ?? false) { - RunTime.GameModeLoader[room.GameMode].StartUI(); + RunTime.Gaming = Core.Model.Gaming.StartGame(RunTime.GameModeLoader[room.GameMode], room, users); Visible = false; // 隐藏主界面 } + else + { + WritelnGameInfo("缺少房间所需模组 [ " + room.GameMode + " ] 无法开始游戏,请检查模组是否正确安装。"); + } }); - SetButtonEnableIfLogon(false, ClientState.InRoom); + SetButtonEnabled(false, ClientState.InRoom); } /// @@ -501,36 +517,40 @@ namespace Milimoe.FunGame.Desktop.UI Visible = true; // test WritelnGameInfo("===== TEST ====="); - SetButtonEnableIfLogon(true, ClientState.InRoom); + SetButtonEnabled(true, ClientState.InRoom); _InGame = false; WritelnGameInfo("游戏结束!" + " [ " + users[new Random().Next(users.Count)] + " ] " + "是赢家!"); + RunTime.Controller?.EndGame(); } /// /// 未登录和离线时,停用按钮 /// 登录的时候要激活按钮 + /// 在游戏时,锁定部分按钮 /// - /// 是否登录 + /// 是否登录 /// 客户端状态 - private void SetButtonEnableIfLogon(bool isLogon, ClientState status) + private void SetButtonEnabled(bool isEnabled, ClientState status) { if (_InGame) { - AccountSetting.Enabled = isLogon; - Stock.Enabled = isLogon; - Store.Enabled = isLogon; - RoomBox.Enabled = isLogon; - RefreshRoomList.Enabled = isLogon; - CheckMix.Enabled = isLogon; - CheckTeam.Enabled = isLogon; - CheckHasPass.Enabled = isLogon; - QuitRoom.Enabled = isLogon; - RoomSetting.Enabled = isLogon; - PresetText.Enabled = isLogon; - TalkText.Enabled = isLogon; - SendTalkText.Enabled = isLogon; - Logout.Enabled = isLogon; - if (!isLogon) return; + AccountSetting.Enabled = isEnabled; + Stock.Enabled = isEnabled; + Store.Enabled = isEnabled; + RoomBox.Enabled = isEnabled; + RefreshRoomList.Enabled = isEnabled; + ComboRoomType.Enabled = isEnabled; + ComboGameMode.Enabled = isEnabled; + ComboGameMap.Enabled = isEnabled; + CheckIsRank.Enabled = isEnabled; + CheckHasPass.Enabled = isEnabled; + QuitRoom.Enabled = isEnabled; + RoomSetting.Enabled = isEnabled; + PresetText.Enabled = isEnabled; + TalkText.Enabled = isEnabled; + SendTalkText.Enabled = isEnabled; + Logout.Enabled = isEnabled; + if (!isEnabled) return; } switch (status) { @@ -552,48 +572,56 @@ namespace Milimoe.FunGame.Desktop.UI break; } this.PresetText.SelectedIndex = 0; - StartMatch.Enabled = isLogon; - AccountSetting.Enabled = isLogon; - Stock.Enabled = isLogon; - Store.Enabled = isLogon; + StartMatch.Enabled = isEnabled; + AccountSetting.Enabled = isEnabled; + Stock.Enabled = isEnabled; + Store.Enabled = isEnabled; if (!Config.FunGame_isMatching) { // 匹配中时不修改部分按钮状态 - RoomBox.Enabled = isLogon; - CreateRoom.Enabled = isLogon; - RefreshRoomList.Enabled = isLogon; - CheckMix.Enabled = isLogon; - CheckTeam.Enabled = isLogon; - CheckHasPass.Enabled = isLogon; + RoomBox.Enabled = isEnabled; + CreateRoom.Enabled = isEnabled; + RefreshRoomList.Enabled = isEnabled; + ComboRoomType.Enabled = isEnabled; + ComboGameMode.Enabled = isEnabled; + ComboGameMap.Enabled = isEnabled; + CheckIsRank.Enabled = isEnabled; + CheckHasPass.Enabled = isEnabled; } } /// /// 加入房间 /// - /// /// - private async Task JoinRoom(bool isDouble, string roomid) + private async Task JoinRoom(string roomid) { - if (!isDouble) - { - if (!RoomText.Text.Equals("") && !RoomText.ForeColor.Equals(Color.DarkGray)) - { - return await JoinRoom_Handler(roomid); - } - else - { - RoomText.Enabled = false; - ShowMessage(ShowMessageType.Tip, "请输入房间号。"); - RoomText.Enabled = true; - RoomText.Focus(); - return false; - } - } - else + if (!RoomText.Text.Equals("") && !RoomText.ForeColor.Equals(Color.DarkGray)) { return await JoinRoom_Handler(roomid); } + else + { + RoomText.Enabled = false; + ShowMessage(ShowMessageType.Tip, "请输入房间号。"); + RoomText.Enabled = true; + RoomText.Focus(); + return false; + } + } + + /// + /// 通过双击房间列表的房间号加入房间 + /// + /// + private async Task JoinRoom(int selectedindex) + { + if (selectedindex != -1 && RunTime.RoomList.Count > selectedindex) + { + string roomid = RunTime.RoomList.ListRoom[selectedindex]?.Roomid ?? ""; + return await JoinRoom_Handler(roomid); + } + return false; } /// @@ -714,15 +742,16 @@ namespace Milimoe.FunGame.Desktop.UI break; case StartMatchState.Enable: // 设置匹配过程中的各种按钮是否可用 - bool isEnabel = false; - if (objs != null) isEnabel = (bool)objs[0]; - CheckMix.Enabled = isEnabel; - CheckTeam.Enabled = isEnabel; - CheckHasPass.Enabled = isEnabel; - CreateRoom.Enabled = isEnabel; - RoomBox.Enabled = isEnabel; - RefreshRoomList.Enabled = isEnabel; - Logout.Enabled = isEnabel; + bool isEnabled = false; + if (objs != null) isEnabled = (bool)objs[0]; + ComboRoomType.Enabled = isEnabled; + ComboGameMode.Enabled = isEnabled; + ComboGameMap.Enabled = isEnabled; + CheckHasPass.Enabled = isEnabled; + CreateRoom.Enabled = isEnabled; + RoomBox.Enabled = isEnabled; + RefreshRoomList.Enabled = isEnabled; + Logout.Enabled = isEnabled; break; case StartMatchState.Cancel: Config.FunGame_isMatching = false; @@ -762,7 +791,7 @@ namespace Milimoe.FunGame.Desktop.UI } Usercfg.LoginUserName = Usercfg.LoginUser.Username; } - NowAccount.Text = "[ID] " + Usercfg.LoginUserName; + NowAccount.Text = "[当前登录]" + "\r\n" + Usercfg.LoginUserName; Login.Visible = false; Logout.Visible = true; UpdateUI(MainInvokeType.SetGreenAndPing); @@ -847,7 +876,7 @@ namespace Milimoe.FunGame.Desktop.UI /// /// /// - private async Task CreateRoom_Handler(string RoomType, string GameMode, string GameMap, string Password = "") + private async Task CreateRoom_Handler(RoomType RoomType, string GameMode, string GameMap, bool IsRank, string Password = "") { if (Usercfg.InRoom.Roomid != "-1") { @@ -860,7 +889,7 @@ namespace Milimoe.FunGame.Desktop.UI ShowMessage(ShowMessageType.Error, ">> 缺少" + Config.FunGame_RoomType + "所需的模组,无法创建房间。"); return; } - Room room = await InvokeController_CreateRoom(RoomType, GameMode, GameMap, Password); + Room room = await InvokeController_CreateRoom(RoomType, GameMode, GameMap, IsRank, Password); if (MainController is not null && room.Roomid != "-1") { await MainController.UpdateRoomAsync(); @@ -945,14 +974,16 @@ namespace Milimoe.FunGame.Desktop.UI /// private void ShowFunGameInfo() { - WritelnGameInfo(FunGameInfo.GetInfo((FunGameInfo.FunGame)Constant.FunGameType)); + WritelnGameInfo(FunGameInfo.GetInfo(Constant.FunGameType)); + Title.Text = FunGameInfo.FunGame_Desktop + " " + FunGameInfo.FunGame_Version + " " + FunGameInfo.FunGame_VersionPatch; } /// /// 关闭所有登录后才能访问的窗口 /// - private static void CloseConnectedWindows() + private void CloseConnectedWindows() { + Visible = true; RunTime.Login?.Close(); RunTime.Register?.Close(); RunTime.Store?.Close(); @@ -1008,13 +1039,36 @@ namespace Milimoe.FunGame.Desktop.UI /// private void StartMatch_Click(object sender, EventArgs e) { + if (ComboRoomType.SelectedIndex < 0 || ComboGameMode.SelectedIndex < 0 || ComboGameMap.SelectedIndex < 0) + { + ShowMessage(ShowMessageType.Warning, "未正确选择房间类型/游戏模组/游戏地图,请检查!"); + return; + } + if (!ComboRoomType.Items.Contains(RoomSet.GetTypeString(Config.FunGame_RoomType))) + { + ShowMessage(ShowMessageType.Error, "无效的房间类型!"); + return; + } + string all = Constant.AllComboItem[0].ToString() ?? "全部"; + string modname = ComboGameMode.SelectedItem?.ToString() ?? all; + string modmap = ComboGameMap.SelectedItem?.ToString() ?? all; + if (RunTime.GameModeLoader is null || (modname != all && !RunTime.GameModeLoader.Modes.ContainsKey(modname))) + { + ShowMessage(ShowMessageType.Error, ">> 模组未正确加载,无法创建房间。"); + return; + } + if (RunTime.GameModeLoader is null || (modmap != all && !RunTime.GameModeLoader.Maps.ContainsKey(modmap))) + { + ShowMessage(ShowMessageType.Error, ">> 地图未正确加载,无法创建房间。"); + return; + } // 开始匹配 _MatchSeconds = 0; SetMatchSecondsText(); WritelnGameInfo(DateTimeUtility.GetNowShortTime() + " 开始匹配"); WritelnGameInfo("[ " + Usercfg.LoginUserName + " ] 开始匹配"); WriteGameInfo(">> 匹配参数:"); - WritelnGameInfo(Config.FunGame_RoomType); + WritelnGameInfo(Config.FunGame_RoomType + " > " + modname + " > " + modmap); // 显示停止匹配按钮 StartMatch.Visible = false; StopMatch.Visible = true; @@ -1032,9 +1086,32 @@ namespace Milimoe.FunGame.Desktop.UI private void CreateRoom_Click(object sender, EventArgs e) { string password = ""; - if (CheckMix.Checked && CheckTeam.Checked) + if (Config.FunGame_RoomType == RoomType.All || ComboRoomType.SelectedIndex <= 0 || ComboGameMode.SelectedIndex <= 0 || ComboGameMap.SelectedIndex <= 0) { - ShowMessage(ShowMessageType.Warning, "创建房间不允许同时勾选混战和团队!"); + ShowMessage(ShowMessageType.Warning, "创建房间时不允许将房间类型/游戏模组/游戏地图的选项设置为[ 全部 ]。"); + return; + } + if (!ComboRoomType.Items.Contains(RoomSet.GetTypeString(Config.FunGame_RoomType))) + { + ShowMessage(ShowMessageType.Error, "无效的房间类型!"); + return; + } + string all = Constant.AllComboItem[0].ToString() ?? "全部"; + string modname = ComboGameMode.SelectedItem?.ToString() ?? all; + string modmap = ComboGameMap.SelectedItem?.ToString() ?? all; + if (modname == all || modmap == all) + { + ShowMessage(ShowMessageType.Warning, "创建房间时不允许将房间类型/游戏模组/游戏地图的选项设置为[ 全部 ]。"); + return; + } + if (RunTime.GameModeLoader is null || (modname != all && !RunTime.GameModeLoader.Modes.ContainsKey(modname))) + { + ShowMessage(ShowMessageType.Error, ">> 模组未正确加载,无法创建房间。"); + return; + } + if (RunTime.GameModeLoader is null || (modmap != all && !RunTime.GameModeLoader.Maps.ContainsKey(modmap))) + { + ShowMessage(ShowMessageType.Error, ">> 地图未正确加载,无法创建房间。"); return; } if (CheckHasPass.Checked) @@ -1046,18 +1123,7 @@ namespace Milimoe.FunGame.Desktop.UI return; } } - if (Config.FunGame_RoomType.Equals("")) - { - ShowMessage(ShowMessageType.Warning, "请勾选你要创建的房间类型!"); - return; - } - GameMode? mode = RunTime.GameModeLoader?.Modes.Values.FirstOrDefault() ?? default; - if (mode is null) - { - ShowMessage(ShowMessageType.Error, ">> 缺少" + Config.FunGame_RoomType + "所需的模组,无法创建房间。"); - return; - } - TaskUtility.NewTask(() => CreateRoom_Handler(Config.FunGame_RoomType, mode.Name, mode.DefaultMap, password)); + TaskUtility.NewTask(() => CreateRoom_Handler(Config.FunGame_RoomType, modname, modmap, CheckIsRank.Checked, password)); } /// @@ -1114,7 +1180,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void QueryRoom_Click(object sender, EventArgs e) { - TaskUtility.NewTask(async () => await JoinRoom(false, RoomText.Text)); + TaskUtility.NewTask(async () => await JoinRoom(RoomText.Text)); } /// @@ -1157,6 +1223,52 @@ namespace Milimoe.FunGame.Desktop.UI StopMatch_Click(); } + /// + /// 切换RoomType时,设置所有相关选项 + /// + /// + /// + private void ComboRoomType_SelectionChangeCommitted(object sender, EventArgs e) + { + if (ComboRoomType.SelectedIndex >= 0) + { + SetRoomTypeString(); + ComboGameMode.Items.Clear(); + ComboGameMode.Items.AddRange(Constant.SupportedGameMode(Config.FunGame_RoomType)); + ComboGameMode.SelectedIndex = 0; + ComboGameMap.Items.Clear(); + ComboGameMap.Items.Add("全部"); + ComboGameMap.SelectedIndex = 0; + } + } + + /// + /// 切换GameMode时,设置GameMap选项 + /// + /// + /// + private void ComboGameMode_SelectionChangeCommitted(object sender, EventArgs e) + { + if (ComboGameMode.SelectedIndex > 0) + { + string modname = ComboGameMode.SelectedItem?.ToString() ?? ""; + if (modname != "- 缺少模组 -" && RunTime.GameModeLoader != null && RunTime.GameModeLoader.Modes.ContainsKey(modname)) + { + GameMode mod = RunTime.GameModeLoader[modname]; + ComboRoomType.SelectedItem = RoomSet.GetTypeString(mod.RoomType); + SetRoomTypeString(); + ComboGameMap.Items.Clear(); + ComboGameMap.Items.AddRange(Constant.SupportedGameMap(mod)); + ComboGameMap.SelectedIndex = 0; + } + } + else + { + ComboGameMap.Items.AddRange(Constant.SupportedGameMap()); + ComboGameMap.SelectedIndex = 0; + } + } + /// /// 双击房间列表中的项可以加入房间 /// @@ -1166,7 +1278,7 @@ namespace Milimoe.FunGame.Desktop.UI { if (RoomList.SelectedItem != null) { - TaskUtility.NewTask(async () => await JoinRoom(true, RoomList.SelectedItem.ToString() ?? "")); + TaskUtility.NewTask(async () => await JoinRoom(RoomList.SelectedIndex)); } } @@ -1180,25 +1292,6 @@ namespace Milimoe.FunGame.Desktop.UI SendTalkText_Click(true); } - /// - /// 勾选任意模式选项 - /// - /// - /// - private void CheckGameMode_CheckedChanged(object sender, EventArgs e) - { - bool IsMix = CheckMix.Checked; - bool IsTeam = CheckTeam.Checked; - bool IsHasPass = CheckHasPass.Checked; - if (IsMix && IsTeam && !IsHasPass) Config.FunGame_RoomType = RoomSet.All; - else if (IsMix && IsTeam && IsHasPass) Config.FunGame_RoomType = RoomSet.All; - else if (IsMix && !IsTeam && !IsHasPass) Config.FunGame_RoomType = RoomSet.Mix; - else if (IsMix && !IsTeam && IsHasPass) Config.FunGame_RoomType = RoomSet.Mix; - else if (!IsMix && IsTeam && !IsHasPass) Config.FunGame_RoomType = RoomSet.Team; - else if (!IsMix && IsTeam && IsHasPass) Config.FunGame_RoomType = RoomSet.Team; - else Config.FunGame_RoomType = RoomSet.All; - } - /// /// 房间号输入框点击/焦点事件 /// @@ -1238,7 +1331,7 @@ namespace Milimoe.FunGame.Desktop.UI if (e.KeyCode.Equals(Keys.Enter)) { // 按下回车加入房间 - TaskUtility.NewTask(async () => await JoinRoom(false, RoomText.Text)); + TaskUtility.NewTask(async () => await JoinRoom(RoomText.Text)); } } @@ -1494,8 +1587,8 @@ namespace Milimoe.FunGame.Desktop.UI if (Usercfg.InRoom.Roomid == "-1") { GameMode? mode = RunTime.GameModeLoader?.Modes.Values.FirstOrDefault() ?? default; - if (mode != null) TaskUtility.NewTask(() => CreateRoom_Handler(RoomSet.Mix, mode.Name, mode.DefaultMap)); - else WritelnGameInfo(">> 缺少" + RoomSet.GetTypeString(RoomType.Mix) + "所需的模组,无法创建房间。"); + if (mode != null) TaskUtility.NewTask(() => CreateRoom_Handler(RoomType.Mix, mode.Name, mode.DefaultMap, false)); + else WritelnGameInfo(">> 缺少" + RoomSet.GetTypeString(RoomType.Mix) + "所需的模组,无法创建房间。此命令使用默认模组创建。"); } else WritelnGameInfo(">> 先退出当前房间才可以创建房间。"); break; @@ -1503,8 +1596,8 @@ namespace Milimoe.FunGame.Desktop.UI if (Usercfg.InRoom.Roomid == "-1") { GameMode? mode = RunTime.GameModeLoader?.Modes.Values.FirstOrDefault() ?? default; - if (mode != null) TaskUtility.NewTask(() => CreateRoom_Handler(RoomSet.Team, mode.Name, mode.DefaultMap)); - else WritelnGameInfo(">> 缺少" + RoomSet.GetTypeString(RoomType.Team) + "所需的模组,无法创建房间。"); + if (mode != null) TaskUtility.NewTask(() => CreateRoom_Handler(RoomType.Team, mode.Name, mode.DefaultMap, false)); + else WritelnGameInfo(">> 缺少" + RoomSet.GetTypeString(RoomType.Team) + "所需的模组,无法创建房间。此命令使用默认模组创建。"); } else WritelnGameInfo(">> 先退出当前房间才可以创建房间。"); break; @@ -1644,6 +1737,22 @@ namespace Milimoe.FunGame.Desktop.UI return false; } + /// + /// 设置当前的房间类型 + /// + private void SetRoomTypeString() + { + Config.FunGame_RoomType = ComboRoomType.SelectedIndex switch + { + 1 => RoomType.Mix, + 2 => RoomType.Team, + 3 => RoomType.Solo, + 4 => RoomType.FastAuto, + 5 => RoomType.Custom, + _ => RoomType.All, + }; + } + #endregion #region 调用控制器 @@ -1660,6 +1769,11 @@ namespace Milimoe.FunGame.Desktop.UI TaskUtility.NewTask(() => { + if (RunTime.Controller != null) + { + (RunTime.Session.Server_IP, RunTime.Session.Server_Port) = RunTime.Controller.GetServerAddress(); + } + (EventArgs.ServerIP, EventArgs.ServerPort) = (RunTime.Session.Server_IP, RunTime.Session.Server_Port); OnBeforeConnectEvent(this, EventArgs); RunTime.PluginLoader?.OnBeforeConnectEvent(this, EventArgs); if (EventArgs.Cancel) return; @@ -1831,7 +1945,7 @@ namespace Milimoe.FunGame.Desktop.UI /// /// /// - public async Task InvokeController_CreateRoom(string RoomType, string GameMode, string GameMap, string Password = "") + public async Task InvokeController_CreateRoom(RoomType RoomType, string GameMode, string GameMap, bool IsRank, string Password = "") { RoomEventArgs EventArgs = new(RoomType, Password); Room room = General.HallInstance; @@ -1842,7 +1956,7 @@ namespace Milimoe.FunGame.Desktop.UI RunTime.PluginLoader?.OnBeforeCreateRoomEvent(this, EventArgs); if (EventArgs.Cancel) return room; - room = MainController is null ? room : await MainController.CreateRoomAsync(RoomType, GameMode, GameMap, Password); + room = MainController is null ? room : await MainController.CreateRoomAsync(RoomType, GameMode, GameMap, IsRank, Password); if (room.Roomid != "-1") { @@ -1893,7 +2007,7 @@ namespace Milimoe.FunGame.Desktop.UI OnSucceedQuitRoomEvent(this, EventArgs); RunTime.PluginLoader?.OnSucceedQuitRoomEvent(this, EventArgs); // 禁用和激活按钮,并切换预设快捷消息 - SetButtonEnableIfLogon(true, ClientState.Online); + SetButtonEnabled(true, ClientState.Online); } else { @@ -1911,7 +2025,7 @@ namespace Milimoe.FunGame.Desktop.UI OnAfterQuitRoomEvent(this, EventArgs); RunTime.PluginLoader?.OnAfterQuitRoomEvent(this, EventArgs); // 禁用和激活按钮,并切换预设快捷消息 - SetButtonEnableIfLogon(true, ClientState.Online); + SetButtonEnabled(true, ClientState.Online); } return result; diff --git a/FunGame.Desktop/UI/Main/Main.resx b/FunGame.Desktop/UI/Main/Main.resx index 149e115..20fd9d4 100644 --- a/FunGame.Desktop/UI/Main/Main.resx +++ b/FunGame.Desktop/UI/Main/Main.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object]