From 88649bb146a925287389abdc1c0acd9cc22342e7 Mon Sep 17 00:00:00 2001 From: ZouJin Date: Mon, 4 Sep 2023 16:45:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9API=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E8=AE=BE=E7=BD=AE=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IMainWindow.cs | 4 +-- .../TalkBox.xaml.cs | 21 ++++++++++-- VPet-Simulator.Windows/MainWindow.cs | 32 ++++++++++++++++--- VPet-Simulator.Windows/MainWindow.xaml.cs | 6 +++- .../WinDesign/winGameSetting.xaml.cs | 18 ++++++++--- 5 files changed, 67 insertions(+), 14 deletions(-) diff --git a/VPet-Simulator.Windows.Interface/IMainWindow.cs b/VPet-Simulator.Windows.Interface/IMainWindow.cs index afd867b..17df9fe 100644 --- a/VPet-Simulator.Windows.Interface/IMainWindow.cs +++ b/VPet-Simulator.Windows.Interface/IMainWindow.cs @@ -26,11 +26,11 @@ namespace VPet_Simulator.Windows.Interface /// /// 所有可用聊天API /// - List TalkAPI { get; } + List TalkAPI { get; } /// /// 当前正在使用的TalkBox /// - TalkBox TalkBoxCurr { get; } + ITalkAPI TalkBoxCurr { get; } /// /// 桌宠数据核心 /// diff --git a/VPet-Simulator.Windows.Interface/TalkBox.xaml.cs b/VPet-Simulator.Windows.Interface/TalkBox.xaml.cs index 9d82ec6..ee1dd6d 100644 --- a/VPet-Simulator.Windows.Interface/TalkBox.xaml.cs +++ b/VPet-Simulator.Windows.Interface/TalkBox.xaml.cs @@ -18,7 +18,7 @@ namespace VPet_Simulator.Windows.Interface /// /// 聊天API接口/显示类 /// - public abstract partial class TalkBox : UserControl + public abstract partial class TalkBox : UserControl, ITalkAPI { MainPlugin MainPlugin; public TalkBox(MainPlugin mainPlugin) @@ -49,7 +49,7 @@ namespace VPet_Simulator.Windows.Interface /// /// 聊天设置 /// - public abstract void Setting(); + public abstract void Setting(); private void tbTalk_KeyDown(object sender, KeyEventArgs e) { @@ -68,5 +68,22 @@ namespace VPet_Simulator.Windows.Interface MainPlugin.MW.Main.ToolBar.CloseTimer.Start(); } } + public UIElement This => this; + } + public interface ITalkAPI + { + /// + /// 显示的窗口 + /// + UIElement This { get; } + + /// + /// 该聊天接口名字 + /// + string APIName { get; } + /// + /// 聊天设置 + /// + void Setting(); } } diff --git a/VPet-Simulator.Windows/MainWindow.cs b/VPet-Simulator.Windows/MainWindow.cs index 299f1f9..91dd3ba 100644 --- a/VPet-Simulator.Windows/MainWindow.cs +++ b/VPet-Simulator.Windows/MainWindow.cs @@ -610,7 +610,7 @@ namespace VPet_Simulator.Windows if (obj.DisplayType.Name == "music") SteamFriends.SetRichPresence("steam_display", "#Status_Music"); else - SteamFriends.SetRichPresence("steam_display", "#Status_IDLE"); + SteamFriends.SetRichPresence("steam_display", "#Status_IDLE(test)"); break; } } @@ -809,7 +809,7 @@ namespace VPet_Simulator.Windows /// public bool CloseConfirm { get; private set; } = true; - public List TalkAPI { get; } = new List(); + public List TalkAPI { get; } = new List(); /// /// 当前选择的对话框index /// @@ -817,7 +817,7 @@ namespace VPet_Simulator.Windows /// /// 当前对话框 /// - public TalkBox TalkBoxCurr + public ITalkAPI TalkBoxCurr { get { @@ -826,7 +826,30 @@ namespace VPet_Simulator.Windows return TalkAPI[TalkAPIIndex]; } } - + /// + /// 移除所有聊天对话框 + /// + public void RemoveTalkBox() + { + if (TalkBox != null) + { + Main.ToolBar.MainGrid.Children.Remove(TalkBox); + TalkBox = null; + } + if (TalkAPIIndex == -1) + return; + Main.ToolBar.MainGrid.Children.Remove(TalkAPI[TalkAPIIndex].This); + } + /// + /// 加载自定义对话框 + /// + public void LoadTalkDIY() + { + RemoveTalkBox(); + if (TalkAPIIndex == -1) + return; + Main.ToolBar.MainGrid.Children.Add(TalkAPI[TalkAPIIndex].This); + } /// /// 超模工作检查 /// @@ -852,5 +875,6 @@ namespace VPet_Simulator.Windows } return true; } + } } diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index b7db9ae..cf13fe2 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -117,7 +117,7 @@ namespace VPet_Simulator.Windows } if (Set.TopMost) { - Topmost= true; + Topmost = true; } @@ -496,6 +496,10 @@ namespace VPet_Simulator.Windows LoadingText.Content = "正在加载CGPT".Translate(); switch (Set["CGPT"][(gstr)"type"]) { + case "DIY": + TalkAPIIndex = TalkAPI.FindIndex(x => x.APIName == Set["CGPT"][(gstr)"DIY"]); + LoadTalkDIY(); + break; //case "API": // TalkBox = new TalkBoxAPI(this); // Main.ToolBar.MainGrid.Children.Add(TalkBox); diff --git a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs index fb27e8e..5d75604 100644 --- a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs +++ b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml.cs @@ -878,7 +878,7 @@ namespace VPet_Simulator.Windows // new winCGPTSetting(mw).ShowDialog(); // break; case "DIY": - + mw.TalkBoxCurr?.Setting(); break; case "LB": //Task.Run(() => @@ -905,6 +905,10 @@ namespace VPet_Simulator.Windows { mw.Set["CGPT"][(gstr)"type"] = "LB"; } + else if (RBCGPTDIY.IsChecked == true) + { + mw.Set["CGPT"][(gstr)"type"] = "DIY"; + } //else if (RBCGPTUseAPI.IsChecked == true) //{ // mw.Set["CGPT"][(gstr)"type"] = "API"; @@ -925,18 +929,22 @@ namespace VPet_Simulator.Windows // mw.TalkBox = new TalkBoxAPI(mw); // mw.Main.ToolBar.MainGrid.Children.Add(mw.TalkBox); // break; + case "DIY": + BtnCGPTReSet.IsEnabled = true; + mw.RemoveTalkBox(); + BtnCGPTReSet.Content = "打开 {0} 设置".Translate(mw.TalkBoxCurr?.APIName ?? "Steam Workshop"); + mw.LoadTalkDIY(); + break; case "LB": + mw.RemoveTalkBox(); BtnCGPTReSet.IsEnabled = true; BtnCGPTReSet.Content = "初始化桌宠聊天程序".Translate(); - if (mw.TalkBox != null) - mw.Main.ToolBar.MainGrid.Children.Remove(mw.TalkBox); mw.TalkBox = new TalkSelect(mw); mw.Main.ToolBar.MainGrid.Children.Add(mw.TalkBox); break; case "OFF": default: - if (mw.TalkBox != null) - mw.Main.ToolBar.MainGrid.Children.Remove(mw.TalkBox); + mw.RemoveTalkBox(); BtnCGPTReSet.IsEnabled = false; BtnCGPTReSet.Content = "聊天框已关闭".Translate(); break;