From 0cb1481d3389c75bf872c373cc5828e022e006b3 Mon Sep 17 00:00:00 2001 From: milimoe <110188673+milimoe@users.noreply.github.com> Date: Fri, 24 Nov 2023 18:38:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84StartGame=E5=92=8CEndGame=20(?= =?UTF-8?q?#24)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 更换ShowMessageType引用 * 更新SocketHandler_System * ShowMessage时需要也显示在公屏上 * 完善开始游戏 * 添加EndGame --- FunGame.Desktop/Controller/LoginController.cs | 1 - FunGame.Desktop/Controller/MainController.cs | 8 +- .../Controller/RunTimeController.cs | 38 +++++- FunGame.Desktop/Library/Other/Config.cs | 2 +- FunGame.Desktop/Library/Other/Constant.cs | 14 --- FunGame.Desktop/UI/Login/ForgetPassword.cs | 1 - FunGame.Desktop/UI/Login/Login.cs | 1 - FunGame.Desktop/UI/Main/Main.cs | 110 ++++++++++++++---- FunGame.Desktop/UI/Register/Register.cs | 2 +- 9 files changed, 127 insertions(+), 50 deletions(-) diff --git a/FunGame.Desktop/Controller/LoginController.cs b/FunGame.Desktop/Controller/LoginController.cs index a8f1357..831ada2 100644 --- a/FunGame.Desktop/Controller/LoginController.cs +++ b/FunGame.Desktop/Controller/LoginController.cs @@ -6,7 +6,6 @@ using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Core.Library.SQLScript.Common; using Milimoe.FunGame.Core.Library.SQLScript.Entity; -using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library.Component; using Milimoe.FunGame.Desktop.Model; using Milimoe.FunGame.Desktop.UI; diff --git a/FunGame.Desktop/Controller/MainController.cs b/FunGame.Desktop/Controller/MainController.cs index e64eca3..d8ac075 100644 --- a/FunGame.Desktop/Controller/MainController.cs +++ b/FunGame.Desktop/Controller/MainController.cs @@ -138,7 +138,7 @@ namespace Milimoe.FunGame.Desktop.Controller return 0; } } - + public async Task SetReadyAsync(string roomid) { try @@ -252,7 +252,7 @@ namespace Milimoe.FunGame.Desktop.Controller return room; } - + public async Task MatchRoomAsync(string RoomType, bool isCancel = false) { bool result = false; @@ -294,7 +294,7 @@ namespace Milimoe.FunGame.Desktop.Controller return false; } } - + public async Task StartGameAsync(string roomid, bool isMaster) { try @@ -304,7 +304,7 @@ namespace Milimoe.FunGame.Desktop.Controller await StartGameRequest.SendRequestAsync(); if (StartGameRequest.Result == RequestResult.Success) { - return true; + return StartGameRequest.GetResult("result"); } } catch (Exception e) diff --git a/FunGame.Desktop/Controller/RunTimeController.cs b/FunGame.Desktop/Controller/RunTimeController.cs index 67c5bc8..6820f1c 100644 --- a/FunGame.Desktop/Controller/RunTimeController.cs +++ b/FunGame.Desktop/Controller/RunTimeController.cs @@ -150,14 +150,16 @@ namespace Milimoe.FunGame.Desktop.Controller protected override void SocketHandler_System(SocketObject ServerMessage) { // 收到系统消息,可输出消息或弹窗 - string msg = ""; ShowMessageType type = ShowMessageType.None; + string msg = ""; + string title = "系统消息"; int autoclose = 60; - if (ServerMessage.Parameters.Length > 0) msg = ServerMessage.GetParam(0) ?? ""; - if (ServerMessage.Parameters.Length > 1) type = ServerMessage.GetParam(1); - if (ServerMessage.Parameters.Length > 2) autoclose = ServerMessage.GetParam(2); - if (type == ShowMessageType.None) Main.GetMessage(msg); - else Main.ShowMessage(type, msg, "系统消息", autoclose); + if (ServerMessage.Parameters.Length > 0) type = ServerMessage.GetParam(0); + if (ServerMessage.Parameters.Length > 1) msg = ServerMessage.GetParam(1) ?? ""; + if (ServerMessage.Parameters.Length > 2) title = ServerMessage.GetParam(2) ?? title; + if (ServerMessage.Parameters.Length > 3) autoclose = ServerMessage.GetParam(3); + Main.GetMessage(msg); + if (type != ShowMessageType.None) Main.ShowMessage(type, msg, title, autoclose); } protected override void SocketHandler_HeartBeat(SocketObject ServerMessage) @@ -218,5 +220,29 @@ namespace Milimoe.FunGame.Desktop.Controller } Main.UpdateUI(MainInvokeType.MatchRoom, StartMatchState.Cancel); } + + protected override void SocketHandler_StartGame(SocketObject ServerMessage) + { + // 游戏即将开始 + Room room = General.HallInstance; + List users = new(); + if (ServerMessage.Length > 0) room = ServerMessage.GetParam(0) ?? General.HallInstance; + if (ServerMessage.Length > 1) users = ServerMessage.GetParam>(1) ?? users; + Main.UpdateUI(MainInvokeType.StartGame, room, users); + } + + protected override void SocketHandler_EndGame(SocketObject ServerMessage) + { + Room room = General.HallInstance; + List users = new(); + 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); + } + + protected override void SocketHandler_Gaming(SocketObject ServerMessage) + { + + } } } diff --git a/FunGame.Desktop/Library/Other/Config.cs b/FunGame.Desktop/Library/Other/Config.cs index f1cc35c..9698989 100644 --- a/FunGame.Desktop/Library/Other/Config.cs +++ b/FunGame.Desktop/Library/Other/Config.cs @@ -57,7 +57,7 @@ namespace Milimoe.FunGame.Desktop.Library get => RunTime.Config.FunGame_isAutoRetry; set => RunTime.Config.FunGame_isAutoRetry = value; } - + /// /// 是否在房间中 /// diff --git a/FunGame.Desktop/Library/Other/Constant.cs b/FunGame.Desktop/Library/Other/Constant.cs index 73cbd74..ed6cbe4 100644 --- a/FunGame.Desktop/Library/Other/Constant.cs +++ b/FunGame.Desktop/Library/Other/Constant.cs @@ -74,18 +74,4 @@ namespace Milimoe.FunGame.Desktop.Library FunGame_AutoRetryOff }; } - - public enum ShowMessageType - { - None, - General, - Tip, - Warning, - Error, - YesNo, - OKCancel, - RetryCancel, - Input, - InputCancel - } } diff --git a/FunGame.Desktop/UI/Login/ForgetPassword.cs b/FunGame.Desktop/UI/Login/ForgetPassword.cs index c26d2df..2b33058 100644 --- a/FunGame.Desktop/UI/Login/ForgetPassword.cs +++ b/FunGame.Desktop/UI/Login/ForgetPassword.cs @@ -2,7 +2,6 @@ using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Desktop.Controller; -using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Model; namespace Milimoe.FunGame.Desktop.UI diff --git a/FunGame.Desktop/UI/Login/Login.cs b/FunGame.Desktop/UI/Login/Login.cs index ed33a06..93c42d5 100644 --- a/FunGame.Desktop/UI/Login/Login.cs +++ b/FunGame.Desktop/UI/Login/Login.cs @@ -3,7 +3,6 @@ using Milimoe.FunGame.Core.Library.Common.Event; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Desktop.Controller; -using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library.Base; using Milimoe.FunGame.Desktop.Model; using Milimoe.FunGame.Desktop.Utility; diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs index 6abf0f5..fa0737b 100644 --- a/FunGame.Desktop/UI/Main/Main.cs +++ b/FunGame.Desktop/UI/Main/Main.cs @@ -30,6 +30,7 @@ namespace Milimoe.FunGame.Desktop.UI private readonly Core.Model.RoomList Rooms = RunTime.RoomList; private readonly Core.Model.Session Usercfg = RunTime.Session; private int _MatchSeconds = 0; // 记录匹配房间的秒数 + private bool _InGame = false; public Main() { @@ -116,7 +117,7 @@ namespace Milimoe.FunGame.Desktop.UI Config.FunGame_isConnected = true; CurrentRetryTimes = 0; break; - + case MainInvokeType.SetYellow: Config.FunGame_isRetrying = false; SetServerStatusLight(LightType.Yellow); @@ -252,6 +253,24 @@ namespace Milimoe.FunGame.Desktop.UI } break; + case MainInvokeType.StartGame: + if (objs != null && objs.Length > 0) + { + Room room = (Room)objs[0]; + List users = (List)objs[1]; + StartGame(room, users); + } + break; + + case MainInvokeType.EndGame: + if (objs != null && objs.Length > 0) + { + Room room = (Room)objs[0]; + List users = (List)objs[1]; + EndGame(room, users); + } + break; + default: break; } @@ -447,6 +466,37 @@ namespace Milimoe.FunGame.Desktop.UI SetButtonEnableIfLogon(true, ClientState.InRoom); } + /// + /// 开始游戏 + /// + private void StartGame(Room room, List users) + { + _InGame = true; + TaskUtility.NewTask(async () => + { + int PlayerCount = users.Count; + for (int i = 10; i > 0; i--) + { + WritelnGameInfo("房间 [ " + room.Roomid + " (" + PlayerCount + "人" + GameMode.GetTypeString(room.RoomType) + ") ] 的游戏将在" + i + "秒后开始..."); + await Task.Delay(1000); + } + WritelnGameInfo("房间 [ " + room.Roomid + " (" + PlayerCount + "人" + GameMode.GetTypeString(room.RoomType) + ") ] 的游戏正式开始!"); + }); + SetButtonEnableIfLogon(false, ClientState.InRoom); + } + + /// + /// 游戏结束,结算 + /// + private void EndGame(Room room, List users) + { + // test + WritelnGameInfo("===== TEST ====="); + SetButtonEnableIfLogon(true, ClientState.InRoom); + _InGame = false; + WritelnGameInfo("游戏结束!" + " [ " + users[new Random().Next(users.Count)] + " ] " + "是赢家!"); + } + /// /// 未登录和离线时,停用按钮 /// 登录的时候要激活按钮 @@ -455,6 +505,24 @@ namespace Milimoe.FunGame.Desktop.UI /// 客户端状态 private void SetButtonEnableIfLogon(bool isLogon, 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; + } switch (status) { case ClientState.WaitConnect: @@ -904,25 +972,6 @@ namespace Milimoe.FunGame.Desktop.UI }); } - /// - /// 鼠标离开停止匹配按钮时,恢复按钮文本为匹配时长 - /// - /// - /// - /// - private void StopMatch_MouseLeave(object? sender, EventArgs e) => SetMatchSecondsText(); - - /// - /// 鼠标轻触停止匹配按钮时,将文本从匹配时长转为停止匹配 - /// - /// - /// - /// - private void StopMatch_MouseHover(object? sender, EventArgs e) - { - StopMatch.Text = "停止匹配"; - } - #endregion #region 事件 @@ -1255,6 +1304,25 @@ namespace Milimoe.FunGame.Desktop.UI }); } + /// + /// 鼠标离开停止匹配按钮时,恢复按钮文本为匹配时长 + /// + /// + /// + /// + private void StopMatch_MouseLeave(object? sender, EventArgs e) => SetMatchSecondsText(); + + /// + /// 鼠标轻触停止匹配按钮时,将文本从匹配时长转为停止匹配 + /// + /// + /// + /// + private void StopMatch_MouseHover(object? sender, EventArgs e) + { + StopMatch.Text = "停止匹配"; + } + /// /// 关闭主界面 /// @@ -1683,7 +1751,7 @@ namespace Milimoe.FunGame.Desktop.UI return result; } - + /// /// 进入房间 /// diff --git a/FunGame.Desktop/UI/Register/Register.cs b/FunGame.Desktop/UI/Register/Register.cs index b35015a..2b09791 100644 --- a/FunGame.Desktop/UI/Register/Register.cs +++ b/FunGame.Desktop/UI/Register/Register.cs @@ -1,8 +1,8 @@ using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Library.Common.Event; +using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Desktop.Controller; -using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library.Base; using Milimoe.FunGame.Desktop.Model;