From 03f96651e44aea82771bd7573d13fb1bfe57e64d Mon Sep 17 00:00:00 2001 From: ZouJin Date: Sun, 2 Apr 2023 05:31:28 +1000 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=A3=E7=A0=81=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet-Simulator.Core/Display/MainLogic.cs | 8 +++ .../IMainWindow.cs | 61 ++++++++++++++++- VPet-Simulator.Windows.Interface/ITalkBox.cs | 17 ----- .../MainPlugin.cs | 58 ++++++++++++++++ .../VPet-Simulator.Windows.Interface.csproj | 66 ++++++++++++++++++- VPet-Simulator.Windows/Function/CoreMOD.cs | 41 ++++++++++++ VPet-Simulator.Windows/MainWindow.cs | 34 ++++++++-- VPet-Simulator.Windows/MainWindow.xaml.cs | 37 +++++++++-- .../VPet-Simulator.Windows.csproj | 6 +- .../WinDesign/TalkBox.xaml.cs | 4 +- .../WinDesign/TalkBoxAPI.xaml.cs | 5 +- .../WinDesign/winGameSetting.xaml | 4 ++ .../WinDesign/winGameSetting.xaml.cs | 22 +++++-- VPet.sln | 8 +-- 14 files changed, 321 insertions(+), 50 deletions(-) delete mode 100644 VPet-Simulator.Windows.Interface/ITalkBox.cs create mode 100644 VPet-Simulator.Windows.Interface/MainPlugin.cs diff --git a/VPet-Simulator.Core/Display/MainLogic.cs b/VPet-Simulator.Core/Display/MainLogic.cs index a11f26a..b63e12b 100644 --- a/VPet-Simulator.Core/Display/MainLogic.cs +++ b/VPet-Simulator.Core/Display/MainLogic.cs @@ -19,6 +19,12 @@ namespace VPet_Simulator.Core public const int LoopMin = 5; public const int TreeRND = 5; + /// + /// 处理说话内容 + /// + public event Action OnSay; + + public Timer EventTimer = new Timer(15000) { AutoReset = true, @@ -30,6 +36,7 @@ namespace VPet_Simulator.Core /// 说话内容 public void Say(string text, GraphCore.Helper.SayType type = GraphCore.Helper.SayType.Shining) { + OnSay.Invoke(text); if (type != GraphCore.Helper.SayType.None && DisplayType == GraphCore.GraphType.Default) Display(GraphCore.Helper.Convert(type, GraphCore.Helper.AnimatType.A_Start), () => { @@ -41,6 +48,7 @@ namespace VPet_Simulator.Core Dispatcher.Invoke(() => MsgBar.Show(Core.Save.Name, text, type)); } } + public void Saying(GraphCore.Helper.SayType type) { Display(GraphCore.Helper.Convert(type, GraphCore.Helper.AnimatType.B_Loop), () => Saying(type)); diff --git a/VPet-Simulator.Windows.Interface/IMainWindow.cs b/VPet-Simulator.Windows.Interface/IMainWindow.cs index 9d2a0c7..ff4668f 100644 --- a/VPet-Simulator.Windows.Interface/IMainWindow.cs +++ b/VPet-Simulator.Windows.Interface/IMainWindow.cs @@ -3,11 +3,70 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; +using System.Windows.Threading; +using VPet_Simulator.Core; namespace VPet_Simulator.Windows.Interface { public interface IMainWindow { - + /// + /// 是否为Steam用户 + /// + bool IsSteamUser { get; } + /// + /// 游戏设置 + /// + Setting Set { get; set; } + /// + /// 宠物加载器列表 + /// + List Pets { get; set; } + /// + /// 桌宠数据核心 + /// + GameCore Core { get; set; } + /// + /// 桌宠主要部件 + /// + Main Main { get; set; } + /// + /// 版本号 + /// + int verison { get; } + /// + /// 版本号 + /// + string Verison { get; } + /// + /// 上次点击时间 (Tick) + /// + long lastclicktime { get; set; } + /// + /// 所有三方插件 + /// + List Plugins { get; } + + Dispatcher Dispatcher { get; } + + /// + /// 设置游戏缩放倍率 + /// + /// 缩放倍率 范围0.1-10 + void SetZoomLevel(double zl); + /// + /// 保存设置 + /// + void Save(); + /// + /// 加载DIY内容 + /// + void LoadDIY(); + /// + /// 运行动作 + /// + /// 动作名称 + void RunAction(string action); } } diff --git a/VPet-Simulator.Windows.Interface/ITalkBox.cs b/VPet-Simulator.Windows.Interface/ITalkBox.cs deleted file mode 100644 index ec82f2b..0000000 --- a/VPet-Simulator.Windows.Interface/ITalkBox.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace VPet_Simulator.Windows.Interface -{ - public interface ITalkBox - { - /// - /// 当前UI - /// - UIElement This { get; } - } -} diff --git a/VPet-Simulator.Windows.Interface/MainPlugin.cs b/VPet-Simulator.Windows.Interface/MainPlugin.cs new file mode 100644 index 0000000..d31f4ff --- /dev/null +++ b/VPet-Simulator.Windows.Interface/MainPlugin.cs @@ -0,0 +1,58 @@ +using LinePutScript; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace VPet_Simulator.Windows.Interface +{ + /// + /// 这是插件的主体内容 请继承这个类 + /// + public abstract class MainPlugin + { + /// + /// 主窗体, 主程序提供的各种功能和设置等 大部分参数和调用均在这里 + /// + public IMainWindow MW; + /// + /// MOD插件初始化 + /// + /// 主窗体 + /// 请不要加载游戏和玩家数据,仅用作初始化 + /// 加载数据(CORE)/游戏(SAVE),请使用 StartGame + public MainPlugin(IMainWindow mainwin) + { + //此处主窗体玩家,Core等信息均为空,请不要加载游戏和玩家数据 + MW = mainwin; + } + ///// //TODO + ///// 加载游戏主题 + ///// + ///// 主题 + //public virtual void LoadTheme(Theme theme) { } + /// + /// 游戏开始 (可以读取Save存档) (如果玩家登出后重新开始游戏,将会被再次调用) + /// + public virtual void StartGame() { } + + /// + /// 游戏结束 (可以保存或清空等,不过保存有专门的Save()) + /// + public virtual void EndGame() { } + + /// + /// 储存游戏 (可以写 Save.Other 储存设置和数据等) + /// + public virtual void Save() { } + + /// + /// 打开代码插件设置 + /// + public virtual void Setting() { } + /// + /// 重载DIY按钮, 如需添加自定义按钮可在此处添加 + /// + public virtual void LoadDIY() { } + } +} diff --git a/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj b/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj index 6ff885a..ea4919b 100644 --- a/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj +++ b/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj @@ -21,6 +21,7 @@ DEBUG;TRACE prompt 4 + AnyCPU pdbonly @@ -30,10 +31,65 @@ prompt 4 + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + + + true + bin\ARM64\Debug\ + DEBUG;TRACE + full + ARM64 + 7.3 + prompt + + + bin\ARM64\Release\ + TRACE + true + pdbonly + ARM64 + 7.3 + prompt + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + 7.3 + prompt + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + 7.3 + prompt + ..\packages\LinePutScript.1.6.1\lib\net462\LinePutScript.dll + @@ -42,14 +98,22 @@ + - + + + + + {7BD4CB1D-C8F3-4349-9BF0-CD11789130BA} + VPet-Simulator.Core + + \ No newline at end of file diff --git a/VPet-Simulator.Windows/Function/CoreMOD.cs b/VPet-Simulator.Windows/Function/CoreMOD.cs index 9bc3d0e..75d7e19 100644 --- a/VPet-Simulator.Windows/Function/CoreMOD.cs +++ b/VPet-Simulator.Windows/Function/CoreMOD.cs @@ -10,12 +10,19 @@ using System.Threading.Tasks; using System.Windows.Controls.Primitives; using System.Windows.Media; using VPet_Simulator.Core; +using VPet_Simulator.Windows.Interface; using static VPet_Simulator.Core.GraphCore; namespace VPet_Simulator.Windows { public class CoreMOD { + public static List LoadedDLL { get; } = new List() + { + "ChatGPT.API.Framework.dll","Panuon.WPF.dll","steam_api.dll","Panuon.WPF.UI.dll","steam_api64.dll", + "LinePutScript.dll","Newtonsoft.Json.dll","Facepunch.Steamworks.Win32.dll", "Facepunch.Steamworks.Win64.dll", + "VPet-Simulator.Core.dll","VPet-Simulator.Windows.Interface.dll" + }; public static string NowLoading = null; public string Name; public string Author; @@ -82,6 +89,40 @@ namespace VPet_Simulator.Windows } } break; + case "plugin": + Content += "代码插件\n"; + SuccessLoad = false; + if (!IsPassMOD(mw)) + {//不是通过模组,不加载 + break; + } + + foreach (FileInfo tmpfi in di.EnumerateFiles("*.dll")) + { + try + { + var path = tmpfi.FullName; + if (LoadedDLL.Contains(path)) + continue; + LoadedDLL.Add(path); + Assembly dll = Assembly.LoadFrom(path); + var v = dll.GetExportedTypes(); + foreach (Type exportedType in v) + { + if (exportedType.BaseType == typeof(MainPlugin)) + { + mw.Plugins.Add((MainPlugin)Activator.CreateInstance(exportedType, mw)); + } + } + } + catch + { + + } + } + + SuccessLoad = true; + break; } } } diff --git a/VPet-Simulator.Windows/MainWindow.cs b/VPet-Simulator.Windows/MainWindow.cs index f7f17ef..b0bf63e 100644 --- a/VPet-Simulator.Windows/MainWindow.cs +++ b/VPet-Simulator.Windows/MainWindow.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Controls; using VPet_Simulator.Core; using VPet_Simulator.Windows.Interface; @@ -17,17 +18,23 @@ namespace VPet_Simulator.Windows public partial class MainWindow : IMainWindow { public readonly string ModPath = Environment.CurrentDirectory + @"\mod"; - public readonly bool IsSteamUser; - public Setting Set; - public List Pets = new List(); + public bool IsSteamUser { get; } + public Setting Set { get; set; } + public List Pets { get; set; } = new List(); public List CoreMODs = new List(); - public GameCore Core = new GameCore(); - public winGameSetting winSetting; + public GameCore Core { get; set; } = new GameCore(); + public Main Main { get; set; } + public UIElement TalkBox; + public winGameSetting winSetting { get; set; } public ChatGPTClient CGPTClient; /// + /// 所有三方插件 + /// + public List Plugins { get; } = new List(); + /// /// 版本号 /// - public readonly int verison = 10; + public int verison { get; } = 10; /// /// 版本号 /// @@ -44,6 +51,8 @@ namespace VPet_Simulator.Windows /// public void Save() { + foreach (MainPlugin mp in Plugins) + mp.Save(); //游戏存档 if (Set != null) File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Setting.lps", Set.ToString()); @@ -52,11 +61,24 @@ namespace VPet_Simulator.Windows if (CGPTClient != null) File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\ChatGPTSetting.json", CGPTClient.Save()); } + /// + /// 重载DIY按钮区域 + /// public void LoadDIY() { Main.ToolBar.MenuDIY.Items.Clear(); foreach (Sub sub in Set["diy"]) Main.ToolBar.AddMenuButton(ToolBar.MenuType.DIY, sub.Name, () => RunDIY(sub.Info)); + try + { + //加载游戏创意工坊插件 + foreach (MainPlugin mp in Plugins) + mp.StartGame(); + } + catch (Exception e) + { + new winReport(this, "由于插件引起的自定按钮加载错误\n" + e.ToString()); + } } public static void RunDIY(string content) { diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index 015063f..4c9859f 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -28,7 +28,6 @@ namespace VPet_Simulator.Windows { private NotifyIcon notifyIcon; public System.Timers.Timer AutoSaveTimer = new System.Timers.Timer(); - public ITalkBox TalkBox; public MainWindow() { //判断是不是Steam用户,因为本软件会发布到Steam @@ -36,7 +35,7 @@ namespace VPet_Simulator.Windows try { #if DEMO - SteamClient.Init(2293870, true); + SteamClient.Init(2293870, true); #else SteamClient.Init(1920960, true); #endif @@ -108,6 +107,13 @@ namespace VPet_Simulator.Windows private void Restart_Closed(object sender, EventArgs e) { Save(); + try + { + //关闭所有插件 + foreach (MainPlugin mp in Plugins) + mp.EndGame(); + } + catch { } Main?.Dispose(); notifyIcon?.Dispose(); System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); @@ -127,7 +133,7 @@ namespace VPet_Simulator.Windows new Tuple("长按脑袋拖动桌宠到你喜欢的任意位置", Helper.SayType.Serious), new Tuple("欢迎加入 虚拟主播模拟器群 430081239", Helper.SayType.Shining), }; - private long lastclicktime; + public long lastclicktime { get; set; } public void GameLoad() { //加载所有MOD @@ -187,18 +193,28 @@ namespace VPet_Simulator.Windows LoadingText.Content = "正在加载CGPT"; winSetting = new winGameSetting(this); - Main = new Main(Core) { }; + Main = new Main(Core) { }; if (!Set["CGPT"][(gbol)"enable"] && IsSteamUser) { TalkBox = new TalkBox(this); - Main.ToolBar.MainGrid.Children.Add(TalkBox.This); + Main.ToolBar.MainGrid.Children.Add(TalkBox); } else if (Set["CGPT"][(gbol)"enable"]) { TalkBox = new TalkBoxAPI(this); - Main.ToolBar.MainGrid.Children.Add(TalkBox.This); + Main.ToolBar.MainGrid.Children.Add(TalkBox); } LoadingText.Content = "正在加载游戏"; + try + { + //加载游戏创意工坊插件 + foreach (MainPlugin mp in Plugins) + mp.StartGame(); + } + catch (Exception e) + { + new winReport(this, "由于插件引起的游戏启动错误\n" + e.ToString()); + } Main.DefaultClickAction = () => { if (new TimeSpan(DateTime.Now.Ticks - lastclicktime).TotalSeconds > 20) @@ -294,16 +310,23 @@ namespace VPet_Simulator.Windows Save(); } - public Main Main; private void Window_Closed(object sender, EventArgs e) { Save(); + try + { + //关闭所有插件 + foreach (MainPlugin mp in Plugins) + mp.EndGame(); + } + catch { } Main?.Dispose(); notifyIcon?.Dispose(); System.Environment.Exit(0); } + //public void DEBUGValue() //{ // Dispatcher.Invoke(() => diff --git a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj index 0547df6..e3f1e53 100644 --- a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj +++ b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj @@ -116,7 +116,6 @@ MSBuild:Compile Designer - TalkBoxAPI.xaml @@ -127,7 +126,6 @@ DIYViewer.xaml - TalkBox.xaml @@ -237,6 +235,10 @@ {7bd4cb1d-c8f3-4349-9bf0-cd11789130ba} VPet-Simulator.Core + + {DCAD838A-1A02-4BDF-962C-FD47C6006D28} + VPet-Simulator.Windows.Interface + diff --git a/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs b/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs index 0488fef..4eb9db2 100644 --- a/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs +++ b/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs @@ -31,13 +31,11 @@ namespace VPet_Simulator.Windows /// /// MessageBar.xaml 的交互逻辑 /// - public partial class TalkBox : UserControl, ITalkBox + public partial class TalkBox : UserControl { Main m; Setting set; - public UIElement This => this; - public TalkBox(MainWindow mw) { InitializeComponent(); diff --git a/VPet-Simulator.Windows/WinDesign/TalkBoxAPI.xaml.cs b/VPet-Simulator.Windows/WinDesign/TalkBoxAPI.xaml.cs index dca55f9..50ef3a1 100644 --- a/VPet-Simulator.Windows/WinDesign/TalkBoxAPI.xaml.cs +++ b/VPet-Simulator.Windows/WinDesign/TalkBoxAPI.xaml.cs @@ -31,13 +31,10 @@ namespace VPet_Simulator.Windows /// /// MessageBar.xaml 的交互逻辑 /// - public partial class TalkBoxAPI : UserControl, ITalkBox + public partial class TalkBoxAPI : UserControl { Main m; MainWindow mw; - - public UIElement This => this; - public TalkBoxAPI(MainWindow mw) { InitializeComponent(); diff --git a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml index 98f230f..791e1ec 100644 --- a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml +++ b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml @@ -525,6 +525,10 @@ BorderBrush="{DynamicResource PrimaryDarker}" pu:ProgressBarHelper.IsPercentVisible="True" Foreground="{DynamicResource DARKPrimary}" BorderThickness="2" /> +