diff --git a/VPet-Simulator.Core/Handle/Function.cs b/VPet-Simulator.Core/Handle/Function.cs index 2faf131..affa849 100644 --- a/VPet-Simulator.Core/Handle/Function.cs +++ b/VPet-Simulator.Core/Handle/Function.cs @@ -14,7 +14,7 @@ namespace VPet_Simulator.Core /// public static Brush ResourcesBrush(BrushType name) { - return (Brush)Application.Current.Resources.MergedDictionaries[0][name.ToString()]; + return (Brush)Application.Current.Resources.MergedDictionaries[0].MergedDictionaries[0][name.ToString()]; } public enum BrushType { diff --git a/VPet-Simulator.Core/Handle/GameSave.cs b/VPet-Simulator.Core/Handle/GameSave.cs index 182e496..ffbc174 100644 --- a/VPet-Simulator.Core/Handle/GameSave.cs +++ b/VPet-Simulator.Core/Handle/GameSave.cs @@ -174,7 +174,10 @@ namespace VPet_Simulator.Core else StrengthChange(StoreStrengthFood); } - + /// + /// 吃食物 + /// + /// 食物类 public void EatFood(IFood food) { Exp += food.Exp; diff --git a/VPet-Simulator.Core/VPet-Simulator.Core.csproj b/VPet-Simulator.Core/VPet-Simulator.Core.csproj index b63860f..9e4c973 100644 --- a/VPet-Simulator.Core/VPet-Simulator.Core.csproj +++ b/VPet-Simulator.Core/VPet-Simulator.Core.csproj @@ -71,7 +71,7 @@ - ..\packages\LinePutScript.1.8.1\lib\net462\LinePutScript.dll + ..\packages\LinePutScript.1.8.2\lib\net462\LinePutScript.dll ..\packages\Panuon.WPF.1.0.1\lib\net462\Panuon.WPF.dll diff --git a/VPet-Simulator.Core/packages.config b/VPet-Simulator.Core/packages.config index 01cdc92..ea43eed 100644 --- a/VPet-Simulator.Core/packages.config +++ b/VPet-Simulator.Core/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/VPet-Simulator.Windows.Interface/Food.cs b/VPet-Simulator.Windows.Interface/Food.cs index 55a658b..a1e3eb5 100644 --- a/VPet-Simulator.Windows.Interface/Food.cs +++ b/VPet-Simulator.Windows.Interface/Food.cs @@ -1,33 +1,118 @@ using LinePutScript.Converter; +using Panuon.WPF; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Media; using VPet_Simulator.Core; +using static LinePutScript.Converter.LPSConvert; namespace VPet_Simulator.Windows.Interface { - public class Food : IFood + public class Food : NotifyPropertyChangedBase, IFood { - [Line] + + /// + /// 食物类型 + /// + public enum FoodType + { + /// + /// 食物 (默认) + /// + Food, + /// + /// 收藏 (自定义) + /// + Star, + /// + /// 正餐 + /// + Meal, + /// + /// 零食 + /// + Snack, + /// + /// 饮料 + /// + Drink, + /// + /// 功能性 + /// + Functional, + /// + /// 药品 + /// + Drug, + } + /// + /// 食物类型 + /// + [Line(type: ConvertType.ToEnum, ignoreCase: true)] + public FoodType Type { get; set; } = FoodType.Food; + /// + /// 食物名字 + /// + [Line(name: "name")] + public string Name { get; set; } + [Line(ignoreCase: true)] public int Exp { get; set; } - [Line] + [Line(ignoreCase: true)] public double Strength { get; set; } - [Line] + [Line(ignoreCase: true)] public double StrengthFood { get; set; } - [Line] + [Line(ignoreCase: true)] public double StrengthDrink { get; set; } - [Line] + [Line(ignoreCase: true)] public double Feeling { get; set; } - [Line] + [Line(ignoreCase: true)] public double Health { get; set; } - [Line] + [Line(ignoreCase: true)] public double Likability { get; set; } /// /// 食物价格 /// - [Line] + [Line(ignoreCase: true)] public double Price { get; set; } + /// + /// 描述 + /// + [Line(ignoreCase: true)] + public string Desc { get; set; } + /// + /// 描述(ToBetterBuy) + /// + public string Description + { + get + { + StringBuilder sb = new StringBuilder(Desc); + return sb.ToString(); + } + } + /// + /// 显示的图片 + /// + public ImageSource ImageSource { get; set; } + /// + /// 是否已收藏 + /// + public bool Star { get; set; } + /// + /// 物品图片 + /// + [Line(ignoreCase: true)] + public string Image; + /// + /// 加载物品图片 + /// + public void LoadImageSource(IMainWindow imw) + { + ImageSource = imw.ImageSources.FindImage(Image ?? Name, "food"); + Star = imw.Set["betterbuy"]["star"].GetInfos().Contains(Name); + } } } diff --git a/VPet-Simulator.Windows.Interface/IMainWindow.cs b/VPet-Simulator.Windows.Interface/IMainWindow.cs index be0c9b0..3e60d15 100644 --- a/VPet-Simulator.Windows.Interface/IMainWindow.cs +++ b/VPet-Simulator.Windows.Interface/IMainWindow.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Windows.Media; using VPet_Simulator.Core; namespace VPet_Simulator.Windows.Interface @@ -47,7 +48,11 @@ namespace VPet_Simulator.Windows.Interface /// /// 所有食物 /// - List Items { get; } + List Foods { get; } + /// + /// 图片资源 + /// + ImageResources ImageSources { get; } /// /// 设置游戏缩放倍率 /// diff --git a/VPet-Simulator.Windows.Interface/Source.cs b/VPet-Simulator.Windows.Interface/Source.cs new file mode 100644 index 0000000..9560a1a --- /dev/null +++ b/VPet-Simulator.Windows.Interface/Source.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; +using LinePutScript; +using LinePutScript.Dictionary; + +namespace VPet_Simulator.Windows.Interface +{ + /// + /// 资源集 + /// + public class Resources : LPS_D + { + public Resources() { } + /// + /// 添加资源,后来覆盖之前 + /// + /// 资源行 + /// 功能位置 + public void AddSource(ILine line, string modpath) + { + ISub source = line.Find("source"); + if (source == null) + return; + //else if (!source.Info.Contains(":\\")) + source.Info = modpath + '\\' + source.Info; + line.Name = line.Name.ToLower(); + AddorReplaceLine(line); + } + /// + /// 添加资源,后来覆盖之前 + /// + /// 资源行 + public void AddSource(ILine line) + { + ISub source = line.Find("source"); + if (source == null) + return; + //else if (!source.Info.Contains(":\\")) + line.Name = line.Name.ToLower(); + AddorReplaceLine(line); + } + /// + /// 添加多个资源,后来覆盖之前 + /// + /// 资源表 + public void AddSources(ILPS lps) + { + foreach (ILine line in lps) + { + line.Name = line.Name.ToLower(); + AddSource(line); + } + } + /// + /// 添加多个资源,后来覆盖之前 + /// + /// 资源表 + /// 功能位置 + public void AddSources(ILPS lps, string modpath = "") + { + foreach (ILine line in lps) + { + AddSource(line, modpath); + } + } + /// + /// 添加资源,后来覆盖之前的 + /// + /// 资源名字 + /// 资源位置 + public void AddSource(string name, string path) + { + AddorReplaceLine(new Line(name.ToLower(), "", "", new Sub("source", path))); + } + /// + /// 查找资源 + /// + /// 资源名称 + /// 如果未找到,退回这个值 + /// 返回资源位置,如果未找到,则退回nofind + public string FindSource(string name, string nofind = null) + { + ILine line = FindLine(name.ToLower()); + if (line == null) + return nofind; + return line.Find("source").Info; + } + /// + /// 查找资源 + /// + /// 资源名称 + /// 如果未找到,退回这个值 + /// 返回资源位置,如果未找到,则退回nofind + public Uri FindSourceUri(string name, string nofind = null) + { + ILine line = FindLine(name.ToLower()); + if (line == null) + if (nofind != null) + return new Uri(nofind); + else + return null; + return new Uri(line.Find("source").Info); + } + } + + /// + /// 图片资源集合 + /// + public class ImageResources : Resources + { + public ImageResources() + { + + } + /// + /// 添加图片集,后来覆盖之前 + /// + /// 图片集 + /// 文件夹位置 + public void AddImages(LpsDocument lps, string modpath = "") => AddSources(lps, modpath); + /// + /// 添加单个图片,后来覆盖之前 + /// + /// 图片行 + /// 文件夹位置 + public void AddImage(ILine line, string modpath = "") => AddSource(line, modpath); + /// + /// 查找图片资源 + /// + /// 图片名称 + /// 图片资源,如果未找到则退回错误提示图片 + public BitmapImage FindImage(string imagename) => new BitmapImage(FindImageUri(imagename)); + + public Uri FindImageUri(string imagename) + { +#if DEBUGs + var v = FindSourceUri(imagename, "pack://application:,,,/Res/Image/system/error.png"); + if (v.AbsoluteUri == "pack://application:,,,/Res/Image/system/error.png") + throw new Exception($"image nofound {imagename}"); + return v; +#else + return FindSourceUri(imagename, "pack://application:,,,/Res/Image/system/error.png"); +#endif + } + + /// + /// 查找图片资源 如果找不到则使用上级 + /// + /// 图片名称 + /// 图片资源,如果未找到则退回错误提示图片 + /// 上级图片 如果没有专属的图片,则提供上级的图片 + public BitmapImage FindImage(string imagename, string superior) + { + string source = FindSource(imagename); + if (source == null) + { + return new BitmapImage(FindImageUri(superior)); + } + return new BitmapImage(new Uri(source)); + } + /// + /// 图片设置 (eg:定位锚点等) + /// + public LpsDocument ImageSetting = new LpsDocument(); + } +} diff --git a/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj b/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj index c3d6769..69b35d7 100644 --- a/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj +++ b/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj @@ -89,7 +89,7 @@ - ..\packages\LinePutScript.1.8.1\lib\net462\LinePutScript.dll + ..\packages\LinePutScript.1.8.2\lib\net462\LinePutScript.dll ..\packages\Panuon.WPF.1.0.1\lib\net462\Panuon.WPF.dll @@ -116,6 +116,7 @@ + diff --git a/VPet-Simulator.Windows.Interface/packages.config b/VPet-Simulator.Windows.Interface/packages.config index 01cdc92..ea43eed 100644 --- a/VPet-Simulator.Windows.Interface/packages.config +++ b/VPet-Simulator.Windows.Interface/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/VPet-Simulator.Windows/App.xaml b/VPet-Simulator.Windows/App.xaml index e902a27..9d1b4f7 100644 --- a/VPet-Simulator.Windows/App.xaml +++ b/VPet-Simulator.Windows/App.xaml @@ -7,6 +7,7 @@ + /VPet-Simulator.Windows;component/Res/Font/#OPPOSans R @@ -22,7 +23,6 @@ IconFontFamily="/VPet-Simulator.Windows;component/Res/#remixicon" IconFontSize="16" /> - diff --git a/VPet-Simulator.Windows/Function/CoreMOD.cs b/VPet-Simulator.Windows/Function/CoreMOD.cs index aed9c4e..b6412fe 100644 --- a/VPet-Simulator.Windows/Function/CoreMOD.cs +++ b/VPet-Simulator.Windows/Function/CoreMOD.cs @@ -1,4 +1,5 @@ using LinePutScript; +using LinePutScript.Converter; using System; using System.Collections.Generic; using System.IO; @@ -35,6 +36,29 @@ namespace VPet_Simulator.Windows public string Content = ""; public bool SuccessLoad = true; public static string INTtoVER(int ver) => $"{ver / 100}.{ver % 100:00}"; + public static void LoadImage(MainWindow mw, DirectoryInfo di) + { + //加载其他放在文件夹的图片 + foreach (FileInfo fi in di.EnumerateFiles("*.png")) + { + mw.ImageSources.AddSource(fi.Name.ToLower().Substring(0, fi.Name.Length - 4), fi.FullName); + } + //加载其他放在文件夹中文件夹的图片 + foreach (DirectoryInfo fordi in di.EnumerateDirectories()) + { + LoadImage(mw, fordi); + } + //加载标志好的图片和图片设置 + foreach (FileInfo fi in di.EnumerateFiles("*.lps")) + { + var tmp = new LpsDocument(File.ReadAllText(fi.FullName)); + if (fi.Name.ToLower().StartsWith("set_")) + foreach (var line in tmp) + mw.ImageSources.ImageSetting.AddorReplaceLine(line); + else + mw.ImageSources.AddImages(tmp, di.FullName); + } + } public CoreMOD(DirectoryInfo directory, MainWindow mw) { Path = directory; @@ -83,6 +107,23 @@ namespace VPet_Simulator.Windows } } break; + case "food": + Content += "食物\n"; + foreach (FileInfo fi in di.EnumerateFiles("*.lps")) + { + var tmp = new LpsDocument(File.ReadAllText(fi.FullName)); + foreach (ILine li in tmp) + { + string tmps = li.Find("name").info; + mw.Foods.RemoveAll(x => x.Name == tmps); + mw.Foods.Add(LPSConvert.DeserializeObject(li)); + } + } + break; + case "image": + Content += "图片包\n"; + LoadImage(mw, di); + break; case "plugin": Content += "代码插件\n"; SuccessLoad = false; @@ -133,7 +174,7 @@ namespace VPet_Simulator.Windows modlps.FindorAddLine("authorid").InfoToInt64 = AuthorID; modlps.FindorAddLine("itemid").info = ItemID.ToString(); File.WriteAllText(Path.FullName + @"\info.lps", modlps.ToString()); - } + } } public static class ExtensionSetting { diff --git a/VPet-Simulator.Windows/MainWindow.cs b/VPet-Simulator.Windows/MainWindow.cs index 5456bf8..2376865 100644 --- a/VPet-Simulator.Windows/MainWindow.cs +++ b/VPet-Simulator.Windows/MainWindow.cs @@ -22,12 +22,14 @@ namespace VPet_Simulator.Windows public Main Main { get; set; } public UIElement TalkBox; public winGameSetting winSetting { get; set; } + public winBetterBuy winBetterBuy { get; set; } public ChatGPTClient CGPTClient; + public ImageResources ImageSources { get; set; } = new ImageResources(); /// /// 所有三方插件 /// public List Plugins { get; } = new List(); - public List Items { get; } = new List(); + public List Foods { get; } = new List(); /// /// 版本号 /// diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index 8495fe1..dcb153a 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -218,6 +218,7 @@ namespace VPet_Simulator.Windows LoadingText.Content = "正在加载CGPT"; winSetting = new winGameSetting(this); + winBetterBuy = new winBetterBuy(this); Main = new Main(Core) { }; if (!Set["CGPT"][(gbol)"enable"] && IsSteamUser) { @@ -240,6 +241,8 @@ namespace VPet_Simulator.Windows { new winReport(this, "由于插件引起的游戏启动错误\n" + e.ToString()).Show(); } + Foods.ForEach(item => item.LoadImageSource(this)); + Main.DefaultClickAction = () => { if (new TimeSpan(DateTime.Now.Ticks - lastclicktime).TotalSeconds > 20) @@ -277,15 +280,24 @@ namespace VPet_Simulator.Windows Main.ToolBar.Visibility = Visibility.Collapsed; IRunImage eat = (IRunImage)Core.Graph.FindGraph(GraphType.Eat, GameSave.ModeType.Nomal); var b = Main.FindDisplayBorder(eat); - eat.Run(b, new BitmapImage(new Uri("pack://application:,,,/Res/tony.bmp")), Main.DisplayToNomal); + eat.Run(b, new BitmapImage(new Uri("pack://application:,,,/Res/汉堡.png")), Main.DisplayToNomal); } ); - Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Feed, "给不二一测试用的窗口", () => + Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Feed, "吃饭", () => + { + winBetterBuy.Show(Food.FoodType.Meal); + } + ); + Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Feed, "喝水", () => { - new winBetterBuy(this).Show(); + winBetterBuy.Show(Food.FoodType.Drink); } - ); - + ); + Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Feed, "药品", () => + { + winBetterBuy.Show(Food.FoodType.Drug); + } + ); Main.SetMoveMode(Set.AllowMove, Set.SmartMove, Set.SmartMoveInterval * 1000); Main.SetLogicInterval((int)(Set.LogicInterval * 1000)); if (Set.MessageBarOutside) diff --git a/VPet-Simulator.Windows/Res/汉堡.png b/VPet-Simulator.Windows/Res/汉堡.png new file mode 100644 index 0000000..933e32d Binary files /dev/null and b/VPet-Simulator.Windows/Res/汉堡.png differ diff --git a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj index fbf51f9..7a5fbd7 100644 --- a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj +++ b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj @@ -76,10 +76,10 @@ - ..\packages\ChatGPT.API.Framework.1.0.2\lib\net462\ChatGPT.API.Framework.dll + ..\packages\ChatGPT.API.Framework.1.0.4\lib\net462\ChatGPT.API.Framework.dll - ..\packages\LinePutScript.1.8.1\lib\net48\LinePutScript.dll + ..\packages\LinePutScript.1.8.2\lib\net48\LinePutScript.dll ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll @@ -252,6 +252,7 @@ + PreserveNewest diff --git a/VPet-Simulator.Windows/WinDesign/winBetterBuy.xaml b/VPet-Simulator.Windows/WinDesign/winBetterBuy.xaml index ad5d976..aabb94d 100644 --- a/VPet-Simulator.Windows/WinDesign/winBetterBuy.xaml +++ b/VPet-Simulator.Windows/WinDesign/winBetterBuy.xaml @@ -1,89 +1,46 @@  + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:pu="https://opensource.panuon.com/wpf-ui" xmlns:local="clr-namespace:VPet_Simulator.Windows" + mc:Ignorable="d" Title="更好买" Height="450" Width="800" FontSize="14" WindowStartupLocation="CenterScreen" + Background="#E0F6FF" pu:WindowXCaption.Height="45" pu:WindowXCaption.Background="{DynamicResource DARKPrimary}" + pu:WindowXCaption.Foreground="#FFFFFF" pu:WindowXCaption.Buttons="Close" Topmost="True" + pu:WindowXCaption.ShadowColor="{DynamicResource ShadowColor}" Closing="WindowX_Closing"> - -