diff --git a/VPet-Simulator.Core/Display/Main.xaml.cs b/VPet-Simulator.Core/Display/Main.xaml.cs index 638a3af..112010d 100644 --- a/VPet-Simulator.Core/Display/Main.xaml.cs +++ b/VPet-Simulator.Core/Display/Main.xaml.cs @@ -21,16 +21,30 @@ namespace VPet_Simulator.Core /// public partial class Main : UserControl { + /// + /// 游戏核心 + /// public GameCore Core; + /// + /// 菜单栏 + /// public ToolBar Bar; + /// + /// 刷新时间时会调用该方法 + /// + public event Action
TimeHandle; + /// + /// 刷新时间时会调用该方法,在所有任务处理完之后 + /// + public event Action
TimeUIHandle; public Main(GameCore core) { InitializeComponent(); Core = core; Bar = new ToolBar(this); - UIGrid.Children.Add(Bar); Bar.Visibility = Visibility.Collapsed; + UIGrid.Children.Add(Bar); //TODO:锚定设置 Core.TouchEvent.Add(new TouchArea(new Point(138, 12), new Size(224, 176), DisplayTouchHead)); Core.TouchEvent.Add(new TouchArea(new Point(0, 0), new Size(500, 180), DisplayRaised, true)); @@ -58,7 +72,7 @@ namespace VPet_Simulator.Core } Task.Run(() => { - Thread.Sleep(Core.Setting.PressLength); + Thread.Sleep(Core.Controller.PressLength); Point mp = default; Dispatcher.BeginInvoke(new Action(() => mp = Mouse.GetPosition(MainGrid))).Wait(); if (isPress) diff --git a/VPet-Simulator.Core/Display/MainLogic.cs b/VPet-Simulator.Core/Display/MainLogic.cs index 02bb179c..ccf6538 100644 --- a/VPet-Simulator.Core/Display/MainLogic.cs +++ b/VPet-Simulator.Core/Display/MainLogic.cs @@ -23,8 +23,14 @@ namespace VPet_Simulator.Core private void EventTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { + //所有Handle + TimeHandle?.Invoke(this); + //TODO:饮食等乱七八糟的消耗 + //UIHandle + Dispatcher.Invoke(() => TimeUIHandle.Invoke(this)); + if (IsNomal) switch (1)//Function.Rnd.Next(10)) { @@ -34,7 +40,7 @@ namespace VPet_Simulator.Core break; case 1: DisplayClimb_Left_UP(); - break; + break; case 2: DisplayClimb_Left_DOWN(); break; @@ -45,7 +51,7 @@ namespace VPet_Simulator.Core DisplayClimb_Right_DOWN(); break; case 10: - DisplayClimb_Top_Right(); + DisplayClimb_Top_Right(); break; default: break; diff --git a/VPet-Simulator.Core/Display/ToolBar.xaml b/VPet-Simulator.Core/Display/ToolBar.xaml index 688b6b4..a1d6a0f 100644 --- a/VPet-Simulator.Core/Display/ToolBar.xaml +++ b/VPet-Simulator.Core/Display/ToolBar.xaml @@ -8,8 +8,8 @@ - @@ -29,62 +29,79 @@ - - - + - + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + diff --git a/VPet-Simulator.Core/Display/ToolBar.xaml.cs b/VPet-Simulator.Core/Display/ToolBar.xaml.cs index 6032808..dd89532 100644 --- a/VPet-Simulator.Core/Display/ToolBar.xaml.cs +++ b/VPet-Simulator.Core/Display/ToolBar.xaml.cs @@ -45,6 +45,23 @@ namespace VPet_Simulator.Core Interval = TimeSpan.FromSeconds(0.1), }; closePanelTimer.Tick += ClosePanelTimer_Tick; + m.TimeUIHandle += M_TimeUIHandle; + } + + private void M_TimeUIHandle(Main m) + { + if (BdrPanel.Visibility == Visibility.Visible) + { + Tlv.Text = "Lv " + m.Core.Save.Level.ToString(); + tMoney.Text = "$ " + m.Core.Save.Money.ToString("N2"); + till.Visibility = m.Core.Save.Mode == Save.ModeType.Ill ? Visibility.Visible : Visibility.Collapsed; + pExp.Maximum = m.Core.Save.LevelUpNeed(); + pExp.Value = m.Core.Save.Exp; + pStrength.Value = m.Core.Save.Strength; + pFeeling.Value = m.Core.Save.Feeling; + pStrengthFood.Value = m.Core.Save.StrengthFood; + pStrengthDrink.Value = m.Core.Save.StrengthDrink; + } } private void ClosePanelTimer_Tick(object sender, EventArgs e) @@ -120,7 +137,7 @@ namespace VPet_Simulator.Core private void PgbExperience_GeneratingPercentText(object sender, GeneratingPercentTextRoutedEventArgs e) { - e.Text = $"{e.Value * 10} / {100 * 10}"; + e.Text = $"{e.Value} / {pExp.Maximum}"; } private void PgbStrength_GeneratingPercentText(object sender, GeneratingPercentTextRoutedEventArgs e) @@ -147,10 +164,10 @@ namespace VPet_Simulator.Core var progressBar = (ProgressBar)sender; progressBar.Foreground = GetForeground(e.Value); e.Text = $"{e.Value} / 100"; - if (e.Value <= 20) - { - txtHearth.Visibility = Visibility.Visible; - } + //if (e.Value <= 20) + //{ + // tHearth.Visibility = Visibility.Visible; + //} } private Brush GetForeground(double value) @@ -172,6 +189,7 @@ namespace VPet_Simulator.Core private void MenuPanel_MouseEnter(object sender, MouseEventArgs e) { BdrPanel.Visibility = Visibility.Visible; + M_TimeUIHandle(m); } private void MenuPanel_MouseLeave(object sender, MouseEventArgs e) diff --git a/VPet-Simulator.Core/Handle/GameCore.cs b/VPet-Simulator.Core/Handle/GameCore.cs index 8bb56e1..87d2a2b 100644 --- a/VPet-Simulator.Core/Handle/GameCore.cs +++ b/VPet-Simulator.Core/Handle/GameCore.cs @@ -19,11 +19,7 @@ namespace VPet_Simulator.Core /// /// 触摸范围和事件列表 /// - public List TouchEvent = new List(); - /// - /// 游戏设置 - /// - public Setting Setting; + public List TouchEvent = new List(); /// /// 图形核心 /// diff --git a/VPet-Simulator.Core/Handle/IController.cs b/VPet-Simulator.Core/Handle/IController.cs index 4638f26..1ad9e48 100644 --- a/VPet-Simulator.Core/Handle/IController.cs +++ b/VPet-Simulator.Core/Handle/IController.cs @@ -48,6 +48,10 @@ namespace VPet_Simulator.Core /// double ZoomRatio { get; } /// + /// 按多久视为长按 单位毫秒 + /// + int PressLength { get; } + /// /// 显示设置窗体 /// void ShowSetting(); @@ -55,5 +59,6 @@ namespace VPet_Simulator.Core /// 显示面板窗体 /// void ShowPanel(); + } } diff --git a/VPet-Simulator.Core/Handle/Save.cs b/VPet-Simulator.Core/Handle/Save.cs index 4d232b9..68a70d5 100644 --- a/VPet-Simulator.Core/Handle/Save.cs +++ b/VPet-Simulator.Core/Handle/Save.cs @@ -30,7 +30,7 @@ namespace VPet_Simulator.Core /// 升级所需经验值 /// /// - public int LevelUpNeed() => (int)(Math.Pow((Level - 1) * 5, 2)); + public int LevelUpNeed() => (int)(Math.Pow((Level) * 5, 2)); /// /// 体力 0-100 /// @@ -93,7 +93,7 @@ namespace VPet_Simulator.Core /// /// 计算宠物当前状态 /// - public void CalMode() + public ModeType CalMode() { int realhel = 60 - (Feeling >= 80 ? 20 : 0) - (Likability >= 80 ? 20 : (Likability >= 40 ? 10 : 0)); //先从最次的开始 @@ -102,21 +102,21 @@ namespace VPet_Simulator.Core //可以确认从状态不佳和生病二选一 if (Health <= realhel / 2) {//生病 - Mode = ModeType.Ill; + return ModeType.Ill; } else { - Mode = ModeType.PoorCondition; + return ModeType.PoorCondition; } } //然后判断是高兴还是普通 else if (Feeling >= 80 - (Likability >= 80 ? 20 : (Likability >= 40 ? 10 : 0))) { - Mode = ModeType.Happy; + return ModeType.Happy; } else { - Mode = ModeType.Nomal; + return ModeType.Nomal; } } /// @@ -132,7 +132,7 @@ namespace VPet_Simulator.Core Feeling = 60; Health = 100; Likability = 0; - CalMode(); + Mode = CalMode(); } /// /// 读档 @@ -147,7 +147,7 @@ namespace VPet_Simulator.Core Feeling = line.GetFloat("feeling"); Health = line.GetFloat("health"); Likability = line.GetFloat("likability"); - CalMode(); + Mode = CalMode(); } /// /// 存档 diff --git a/VPet-Simulator.Core/Handle/Setting.cs b/VPet-Simulator.Core/Handle/Setting.cs deleted file mode 100644 index 15407a5..0000000 --- a/VPet-Simulator.Core/Handle/Setting.cs +++ /dev/null @@ -1,47 +0,0 @@ -using LinePutScript; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VPet_Simulator.Core -{ - /// - /// 游戏设置,例如窗体大小等 - /// - public class Setting : LpsDocument - { - public Setting(string lps) : base(lps) - { - } - public Setting() : base() - { - } - - /// - /// 窗体宽度 - /// - public double Width - { - get => this["windows"].GetDouble("width", 250); - set => this["windows"].SetDouble("width", value); - } - /// - /// 窗体高度 - /// - public double Heigh - { - get => this["windows"].GetDouble("heigh", 250); - set => this["windows"].SetDouble("heigh", value); - } - /// - /// 按多久视为长按 单位毫秒 - /// - public int PressLength - { - get => this["windows"].GetInt("presslength", 500); - set => this["windows"].SetInt("presslength", value); - } - } -} diff --git a/VPet-Simulator.Core/VPet-Simulator.Core.csproj b/VPet-Simulator.Core/VPet-Simulator.Core.csproj index 083c7ab..8cffc80 100644 --- a/VPet-Simulator.Core/VPet-Simulator.Core.csproj +++ b/VPet-Simulator.Core/VPet-Simulator.Core.csproj @@ -154,7 +154,6 @@ - diff --git a/VPet-Simulator.Windows/Function/CoreMOD.cs b/VPet-Simulator.Windows/Function/CoreMOD.cs new file mode 100644 index 0000000..ca4170b --- /dev/null +++ b/VPet-Simulator.Windows/Function/CoreMOD.cs @@ -0,0 +1,96 @@ +using LinePutScript; +using Steamworks.Ugc; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls.Primitives; +using System.Windows.Media; +using VPet_Simulator.Core; +using static VPet_Simulator.Core.GraphCore; + +namespace VPet_Simulator.Windows +{ + public class CoreMOD + { + public static string NowLoading = null; + public string Name; + public string Author; + /// + /// 如果是上传至Steam,则为SteamUserID + /// + public long AuthorID; + /// + /// 上传至Steam的ItemID + /// + public ulong ItemID; + public string Intro; + public DirectoryInfo Path; + public int GameVer; + public int Ver; + public string Content = ""; + public bool SuccessLoad = true; + public static string INTtoVER(int ver) => $"{ver / 100}.{ver % 100:00}"; + public CoreMOD(DirectoryInfo directory, MainWindow mw) + { + Path = directory; + LpsDocument modlps = new LpsDocument(File.ReadAllText(directory.FullName + @"\info.lps")); + Name = modlps.FindLine("vupmod").Info; + NowLoading = Name; + Intro = modlps.FindLine("intro").Info; + GameVer = modlps.FindSub("gamever").InfoToInt; + Ver = modlps.FindSub("ver").InfoToInt; + Author = modlps.FindSub("author").Info; + if (modlps.FindLine("authorid") != null) + AuthorID = modlps.FindLine("authorid").InfoToInt64; + else + AuthorID = 0; + if (modlps.FindLine("itemid") != null) + ItemID = Convert.ToUInt64(modlps.FindLine("itemid").info); + else + ItemID = 0; + if (IsBanMOD(mw)) + { + Content = "该模组已停用"; + return; + } + + foreach (DirectoryInfo di in Path.EnumerateDirectories()) + { + switch (di.Name.ToLower()) + { + case "pet": + //宠物模型 + Content += "宠物形象\n"; + foreach (FileInfo fi in di.EnumerateFiles("*.lps")) + { + LpsDocument lps = new LpsDocument(File.ReadAllText(fi.FullName)); + if (lps.First().Name.ToLower() == "pet") + { + mw.Pets.Add(new CorePet(lps, di)); + } + } + break; + } + } + } + public bool IsBanMOD(MainWindow mw) => mw.Set.IsBanMod(Name); + public bool IsPassMOD(MainWindow mw) => mw.Set.IsPassMOD(Name); + + public void WriteFile() + { + LpsDocument modlps = new LpsDocument(File.ReadAllText(Path.FullName + @"\info.lps")); + modlps.FindLine("vupmod").Info = Name; + modlps.FindLine("intro").Info = Intro; + modlps.FindSub("gamever").InfoToInt = GameVer; + modlps.FindSub("ver").InfoToInt = Ver; + modlps.FindSub("author").Info = Author; + modlps.FindorAddLine("authorid").InfoToInt64 = AuthorID; + modlps.FindorAddLine("itemid").info = ItemID.ToString(); + File.WriteAllText(Path.FullName + @"\info.lps", modlps.ToString()); + } + } +} diff --git a/VPet-Simulator.Windows/Function/CorePet.cs b/VPet-Simulator.Windows/Function/CorePet.cs new file mode 100644 index 0000000..cd30f77 --- /dev/null +++ b/VPet-Simulator.Windows/Function/CorePet.cs @@ -0,0 +1,97 @@ +using LinePutScript; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Threading; +using VPet_Simulator.Core; +using static VPet_Simulator.Core.GraphCore; + +namespace VPet_Simulator.Windows +{ + /// + /// 宠物 + /// + public class CorePet + { + /// + /// 宠物图像 + /// + public GraphCore Graph + { + get + { + var g = new GraphCore(); + LoadGraph(g, new DirectoryInfo(path), ""); + return g; + } + } + public string path; + /// + /// 宠物名字 + /// + public string Name; + /// + /// 宠物介绍 + /// + public string Intor; + public Line GraphSetting; + public CorePet(LpsDocument lps, DirectoryInfo directory) + { + Name = lps.First().Info; + Intor = lps.First()["intor"].Info; + path = directory.FullName + "\\" + lps.First()["path"].Info; + GraphSetting = lps["graph"]; + } + + public static void LoadGraph(GraphCore graph, DirectoryInfo di, string path_name) + { + var list = di.EnumerateDirectories(); + if (list.Count() == 0) + { + if (File.Exists(di.FullName + @"\info.lps")) + {//如果自带描述信息,则手动加载 + //TODO: + } + else + {//自动加载 PNG ANMIN + path_name = path_name.Trim('_').ToLower(); + for (int i = 0; i < GraphTypeValue.Length; i++) + { + if (path_name.StartsWith(GraphTypeValue[i][0])) + { + + if (path_name.Contains("happy")) + { + graph.AddGraph(new PNGAnimation(di.FullName, Save.ModeType.Happy, (GraphType)i, GraphTypeValue[i][1], GraphTypeValue[i][2]), (GraphType)i); + } + if (path_name.Contains("nomal")) + { + graph.AddGraph(new PNGAnimation(di.FullName, Save.ModeType.Nomal, (GraphType)i, GraphTypeValue[i][1], GraphTypeValue[i][2]), (GraphType)i); + } + if (path_name.Contains("poorcondition")) + { + graph.AddGraph(new PNGAnimation(di.FullName, Save.ModeType.PoorCondition, (GraphType)i, GraphTypeValue[i][1], GraphTypeValue[i][2]), (GraphType)i); + } + if (path_name.Contains("ill")) + { + graph.AddGraph(new PNGAnimation(di.FullName, Save.ModeType.Ill, (GraphType)i, GraphTypeValue[i][1], GraphTypeValue[i][2]), (GraphType)i); + } + return; + } + } +#if DEBUG + throw new Exception("未知的图像类型: " + path_name); +#endif + } + } + else + foreach (var p in list) + { + LoadGraph(graph, p, path_name + "_" + p.Name); + } + } + } +} diff --git a/VPet-Simulator.Windows/MWController.cs b/VPet-Simulator.Windows/Function/MWController.cs similarity index 97% rename from VPet-Simulator.Windows/MWController.cs rename to VPet-Simulator.Windows/Function/MWController.cs index 5080baa..900ef19 100644 --- a/VPet-Simulator.Windows/MWController.cs +++ b/VPet-Simulator.Windows/Function/MWController.cs @@ -64,5 +64,7 @@ namespace VPet_Simulator.Windows } public double ZoomRatio => 0.5; + + public int PressLength => 500; } } diff --git a/VPet-Simulator.Windows/Function/Setting.cs b/VPet-Simulator.Windows/Function/Setting.cs new file mode 100644 index 0000000..4f63eb5 --- /dev/null +++ b/VPet-Simulator.Windows/Function/Setting.cs @@ -0,0 +1,273 @@ +using LinePutScript; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VPet_Simulator.Windows +{ + public class Setting : LpsDocument + { + public Setting(string lps) : base(lps) + { + + } + + public void Save() + { + File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Setting.lps", ToString()); + } + + //public Size WindowsSize + //{ + // get + // { + // var line = FindLine("windowssize"); + // if (line == null) + // return new Size(1366, 799); + // var strs = line.GetInfos(); + // if (int.TryParse(strs[0], out int x)) + // x = 1366; + // if (int.TryParse(strs[0], out int y)) + // y = 799; + // return new Size(x, y); + // } + // set + // { + // FindorAddLine("windowssize").info = $"{value.Width},{value.Height}"; + // } + //} + public ResolutionType Resolution + { + get + { + var line = FindLine("windowssize"); + if (line == null) + return ResolutionType.q1280x720; + return (ResolutionType)line.InfoToInt; + } + set + { + FindorAddLine("windowssize").InfoToInt = (int)value; + } + } + public int ZoomLevel + { + get + { + var line = FindLine("zoomlevel"); + if (line == null) + return 75; + int zl = line.InfoToInt; + if (zl < 25 || zl > 100) + { + return 75; + } + return zl; + } + set + { + FindorAddLine("zoomlevel").InfoToInt = value; + } + } + /// + /// 分辨率类型,仅支持以下分辨率 q:1.77 l:1.6 s:1.33 + /// + public enum ResolutionType + { + q1280x720,// = 128000720, + l1280x800,// = 128000800, + s1280x960,// = 128000960, + q1440x810,// = 144000810, + l1440x900,// = 144000900, + s1440x1080,// = 144001080, + q1600x900,// = 160000900, + l1600x1000,// = 160001000, + s1600x1200,// = 160001200, + q1680x945,// = 160000945, + l1680x1050,// = 160001050, + s1680x1260,// = 160001260, + q1920x1080,// = 192001080, + l1920x1200,// = 192001200, + s1920x1440,// = 192001440, + q2048x1152,// = 204801152, + l2048x1260,// = 204801260, + s2048x1536,// = 204801536, + q2560x1440,// = 256001440, + l2560x1600,// = 256001600, + s2560x1920,// = 256001920, + q3840x2160,// = 384002160, + l3840x2400,// = 384002400, + s3840x2880,// = 384002880, + } + /// + /// 分辨率表,快速查询分辨率 + /// + public static readonly int[] ResolutionList = { + 128000720, + 128000800, + 128000960, + 144000810, + 144000900, + 144001080, + 160000900, + 160001000, + 160001200, + 160000945, + 160001050, + 160001260, + 192001080, + 192001200, + 192001440, + 204801152, + 204801260, + 204801536, + 256001440, + 256001600, + 256001920, + 384002160, + 384002400, + 384002880 + }; + //public static readonly Dictionary ResolutionList = new Dictionary() + //{ + // {1, 128000720 }, + // 128000800, + // 128000960, + // 144000810, + // 144000900, + // 144001080, + // 160000900, + // 160001000, + // 160001200, + // 160000945, + // 160001050, + // 160001260, + // 192001080, + // 192001200, + // 192001440, + // 204801152, + // 204801260, + // 204801536, + // 256001440, + // 256001600, + // 256001920, + // 384002160, + // 384002400, + // 384002880, + //}; + public bool IsFullScreen + { + get => FindLine("fullscreen") != null; + set + { + if (value) + FindorAddLine("fullscreen"); + else + RemoveAll("fullscreen"); + } + } + /// + /// 是否启用数据收集 //TODO:判断游戏是否是原版的 + /// + public bool Diagnosis + { + get => !this["diagnosis"].GetBool("disable"); + set => this["diagnosis"].SetBool("disable", !value); + } + /// + /// 数据收集频率 + /// + public int DiagnosisInterval + { + get => Math.Max(this["diagnosis"].GetInt("interval", 14), 7); + set => this["diagnosis"].SetInt("interval", value); + } + /// + /// 自动保存频率 + /// + public int AutoSaveInterval + { + get => Math.Max(GetInt("autosave", 7), 0); + set => SetInt("autosave", value); + } + /// + /// 桌面图标是否自动对齐 + /// + public bool ShortcutAlignment + { + get => !GetBool("shortcut_alignment"); + set => SetBool("shortcut_alignment", !value); + } + /// + /// 数据收集是否被禁止(当日) + /// + public bool DiagnosisDayEnable = true; + + + + + public string Font + { + get => GetString("font", "OPPOSans R"); + set => this[(gstr)"font"] = value; + } + public string Theme + { + get + { + var line = FindLine("theme"); + if (line == null) + return "default"; + return line.Info; + } + set + { + FindorAddLine("theme").Info = value; + } + } + public bool IsBanMod(string ModName) + { + var line = FindLine("banmod"); + if (line == null) + return false; + return line.Find(ModName.ToLower()) != null; + } + public bool IsPassMOD(string ModName) + { + var line = FindLine("passmod"); + if (line == null) + return false; + return line.Find(ModName.ToLower()) != null; + } + public void BanMod(string ModName) + { + if (string.IsNullOrWhiteSpace(ModName)) + return; + FindorAddLine("banmod").AddorReplaceSub(new Sub(ModName.ToLower())); + } + public void BanModRemove(string ModName) + { + FindorAddLine("banmod").Remove(ModName.ToLower()); + } + public void PassMod(string ModName) + { + FindorAddLine("passmod").AddorReplaceSub(new Sub(ModName.ToLower())); + } + public void PassModRemove(string ModName) + { + FindorAddLine("passmod").Remove(ModName.ToLower()); + } + + /// + /// 按多久视为长按 单位毫秒 + /// + public int PressLength + { + get => this["windows"].GetInt("presslength", 500); + set => this["windows"].SetInt("presslength", value); + } + } +} diff --git a/VPet-Simulator.Windows/MainWindow.xaml b/VPet-Simulator.Windows/MainWindow.xaml index ce170e1..65a0cbd 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml +++ b/VPet-Simulator.Windows/MainWindow.xaml @@ -7,7 +7,9 @@ - - + diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index 9b11295..beae9ed 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -28,6 +28,9 @@ namespace VPet_Simulator.Windows public readonly string ModPath = Environment.CurrentDirectory + @"\mod"; public readonly bool IsSteamUser; public Setting Set; + public List Pets = new List(); + public List CoreMODs = new List(); + public GameCore Core = new GameCore(); public MainWindow() { //判断是不是Steam用户,因为本软件会发布到Steam @@ -52,7 +55,7 @@ namespace VPet_Simulator.Windows Set = new Setting(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Setting.lps")); } else - Set = new Setting(); + Set = new Setting("Setting#VPET:|\n"); InitializeComponent(); @@ -64,15 +67,51 @@ namespace VPet_Simulator.Windows Close(); return; } - - var core = new GameCore(); - core.Setting = Set; - core.Controller = new MWController(this); - core.Graph = new GraphCore(); - core.Save = new Save(); - LoadGraph(core.Graph, modpath, ""); - DisplayGrid.Children.Add(new Main(core)); + Task.Run(GameLoad); } + public void GameLoad() + { + //加载所有MOD + List Path = new List(); + Path.AddRange(new DirectoryInfo(ModPath).EnumerateDirectories()); + if (IsSteamUser)//如果是steam用户,尝试加载workshop + { + Dispatcher.Invoke(new Action(() => LoadingText.Content = "尝试加载 Steam Workshop")); + int i = 1; + while (true) + { + var page = Steamworks.Ugc.Query.ItemsReadyToUse.GetPageAsync(i++).Result; + if (page.HasValue && page.Value.ResultCount != 0) + { + foreach (Steamworks.Ugc.Item entry in page.Value.Entries) + { + if (entry.Directory != null) + Path.Add(new DirectoryInfo(entry.Directory)); + } + } + else + { + break; + } + } + } + //加载mod + foreach (DirectoryInfo di in Path) + { + if (!File.Exists(di.FullName + @"\info.lps")) + continue; + Dispatcher.Invoke(new Action(() => LoadingText.Content = $"尝试加载 MOD数据: {di.Name}")); + CoreMODs.Add(new CoreMOD(di, this)); + } + Dispatcher.Invoke(new Action(() => LoadingText.Content = "尝试加载游戏内容")); + //加载游戏内容 + Core.Controller = new MWController(this); + Dispatcher.Invoke(new Action(() => Core.Graph = Pets[0].Graph)); + Core.Save = new Save(); + Dispatcher.Invoke(new Action(() => LoadingText.Visibility = Visibility.Collapsed)); + Dispatcher.Invoke(new Action(() => DisplayGrid.Child = new Main(Core))); + } + //public void DEBUGValue() //{ // Dispatcher.Invoke(() => @@ -83,51 +122,6 @@ namespace VPet_Simulator.Windows // Thread.Sleep(1000); // DEBUGValue(); //} - public static void LoadGraph(GraphCore graph, DirectoryInfo di, string path_name) - { - var list = di.EnumerateDirectories(); - if (list.Count() == 0) - { - if (File.Exists(di.FullName + @"\info.lps")) - {//如果自带描述信息,则手动加载 - } - else - {//自动加载 PNG ANMIN - path_name = path_name.Trim('_').ToLower(); - for (int i = 0; i < GraphTypeValue.Length; i++) - { - if (path_name.StartsWith(GraphTypeValue[i][0])) - { - if (path_name.Contains("happy")) - { - graph.AddGraph(new PNGAnimation(di.FullName, Save.ModeType.Happy, (GraphType)i, GraphTypeValue[i][1], GraphTypeValue[i][2]), (GraphType)i); - } - if (path_name.Contains("nomal")) - { - graph.AddGraph(new PNGAnimation(di.FullName, Save.ModeType.Nomal, (GraphType)i, GraphTypeValue[i][1], GraphTypeValue[i][2]), (GraphType)i); - } - if (path_name.Contains("poorcondition")) - { - graph.AddGraph(new PNGAnimation(di.FullName, Save.ModeType.PoorCondition, (GraphType)i, GraphTypeValue[i][1], GraphTypeValue[i][2]), (GraphType)i); - } - if (path_name.Contains("ill")) - { - graph.AddGraph(new PNGAnimation(di.FullName, Save.ModeType.Ill, (GraphType)i, GraphTypeValue[i][1], GraphTypeValue[i][2]), (GraphType)i); - } - return; - } - } -#if DEBUG - throw new Exception("未知的图像类型: " + path_name); -#endif - } - } - else - foreach (var p in list) - { - LoadGraph(graph, p, path_name + "_" + p.Name); - } - } } } diff --git a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj index d3c3b4e..ac09a6a 100644 --- a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj +++ b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj @@ -109,6 +109,9 @@ MSBuild:Compile Designer + + + winCharacterPanel.xaml @@ -127,7 +130,7 @@ App.xaml Code - + MainWindow.xaml Code