支持主题和字体修改

This commit is contained in:
ZouJin 2024-02-28 22:02:28 +08:00
parent 813fd373fe
commit 85d22dbb96
18 changed files with 304 additions and 47 deletions

View File

@ -7,6 +7,18 @@ namespace VPet_Simulator.Core
{
public static partial class Function
{
/// <summary>
/// HEX值转颜色
/// </summary>
/// <param name="HEX">HEX值</param>
/// <returns>颜色</returns>
public static Color HEXToColor(string HEX) => (Color)ColorConverter.ConvertFromString(HEX);
/// <summary>
/// 颜色转HEX值
/// </summary>
/// <param name="color">颜色</param>
/// <returns>HEX值</returns>
public static string ColorToHEX(Color color) => "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
public static Random Rnd = new Random();
/// <summary>
/// 获取资源笔刷
@ -15,7 +27,7 @@ namespace VPet_Simulator.Core
/// <returns></returns>
public static Brush ResourcesBrush(BrushType name)
{
return (Brush)Application.Current.Resources.MergedDictionaries[0].MergedDictionaries[0][name.ToString()];
return (Brush)Application.Current.Resources[name.ToString()];
}
public enum BrushType
{

View File

@ -37,6 +37,7 @@ namespace VPet_Simulator.Windows.Interface
autobuy = this["gameconfig"].GetBool("autobuy");
autogift = this["gameconfig"].GetBool("autogift");
}
//public override string ToString()
//{//留作备份,未来版本删了
// this["statistics"] = new Line("statistics", "", "", Statistics_OLD.ToSubs().ToArray());

View File

@ -0,0 +1,54 @@
using LinePutScript;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace VPet_Simulator.Windows.Interface
{
/// <summary>
/// 游戏主题
/// </summary>
public class Theme
{
public string Name;
public string xName;
public string Image;
public ImageResources Images;
public LpsDocument ThemeColor;
public Theme(LpsDocument lps)
{
xName = lps.First().Name;
Name = lps.First().Info;
Image = lps.First().Find("image").info;
lps.RemoveAt(0);
ThemeColor = lps;
Images = new ImageResources();
}
}
/// <summary>
/// 字体
/// </summary>
public class IFont
{
public string Name;
public string Path;
public IFont(FileInfo path)
{
Name = path.Name.Substring(0, path.Name.Length - path.Extension.Length);
Path = path.Directory.FullName + @"\#" + Name;
}
public FontFamily Font
{
get
{//file:///D:\Documents\Visual Studio 2022\Projects\VPet\VPet-Simulator.Windows\Res\#凤凰点阵体 12px
return new FontFamily(@"file:///" + Path);
}
}
}
}

View File

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<configuration>
<appSettings>
<add key="SendKeys" value="SendInput"/>
</appSettings>

View File

@ -1,31 +1,23 @@
<Application
x:Class="VPet_Simulator.Windows.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VPet_Simulator.Windows"
xmlns:pu="https://opensource.panuon.com/wpf-ui"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/VPet-Simulator.Windows.Interface;component/ResourceStyle.xaml" />
<Application x:Class="VPet_Simulator.Windows.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:VPet_Simulator.Windows"
xmlns:pu="https://opensource.panuon.com/wpf-ui" StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<FontFamily x:Key="MainFont">
/VPet-Simulator.Windows;component/Res/Font/#OPPOSans R
</FontFamily>
<FontFamily x:Key="RemixIcon">
/VPet-Simulator.Windows;component/Res/#remixicon
</FontFamily>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<FontFamily x:Key="MainFont">
/VPet-Simulator.Windows;component/Res/Font/#OPPOSans R
</FontFamily>
<FontFamily x:Key="RemixIcon">
/VPet-Simulator.Windows;component/Res/#remixicon
</FontFamily>
</ResourceDictionary>
<ResourceDictionary>
<pu:GlobalSettings x:Key="globalSettings" FontFamily="{StaticResource MainFont}" FontSize="14"
IconFontFamily="/VPet-Simulator.Windows;component/Res/#remixicon" IconFontSize="16" />
</ResourceDictionary>
<ResourceDictionary Source="/VPet-Simulator.Windows.Interface;component/ResourceStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<ResourceDictionary>
<pu:GlobalSettings
x:Key="globalSettings"
FontFamily="{StaticResource MainFont}"
FontSize="14"
IconFontFamily="/VPet-Simulator.Windows;component/Res/#remixicon"
IconFontSize="16" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application.Resources>
</Application>

View File

@ -9,7 +9,9 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Windows;
using System.Windows.Media;
using System.Xml.Linq;
using VPet_Simulator.Core;
using VPet_Simulator.Windows.Interface;
@ -125,6 +127,39 @@ namespace VPet_Simulator.Windows
{
switch (di.Name.ToLower())
{
case "theme":
Tag.Add("theme");
if (Directory.Exists(di.FullName + @"\fonts"))
foreach (var str in Directory.EnumerateFiles(di.FullName + @"\fonts", "*.ttf"))
{
mw.Fonts.Add(new IFont(new FileInfo(str)));
}
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
{
var tmp = new Theme(new LpsDocument(File.ReadAllText(fi.FullName)));
var oldtheme = mw.Themes.Find(x => x.xName == tmp.xName);
if (oldtheme != null)
mw.Themes.Remove(oldtheme);
mw.Themes.Add(tmp);
//加载图片包
DirectoryInfo tmpdi = new DirectoryInfo(di.FullName + '\\' + tmp.Image);
if (tmpdi.Exists)
{
foreach (FileInfo tmpfi in tmpdi.EnumerateFiles("*.png"))
{
tmp.Images.AddSource(tmpfi.Name.ToLower().Substring(0, tmpfi.Name.Length - 4), tmpfi.FullName);
}
foreach (DirectoryInfo fordi in tmpdi.EnumerateDirectories())
{
foreach (FileInfo tmpfi in fordi.EnumerateFiles("*.png"))
{
tmp.Images.AddSource(fordi.Name + '_' + tmpfi.Name.ToLower().Substring(0, tmpfi.Name.Length - 4), tmpfi.FullName);
}
}
}
}
break;
case "pet":
//宠物模型
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))

View File

@ -35,6 +35,7 @@ using Line = LinePutScript.Line;
using static VPet_Simulator.Windows.Interface.ExtensionFunction;
using Image = System.Windows.Controls.Image;
using System.Data;
using System.Windows.Media;
#if SteamOutput
using VPet.Solution;
#endif
@ -76,6 +77,84 @@ namespace VPet_Simulator.Windows
/// 所有三方插件
/// </summary>
public List<MainPlugin> Plugins { get; } = new List<MainPlugin>();
/// <summary>
/// 所有字体(位置)
/// </summary>
public List<IFont> Fonts { get; } = new List<IFont>();
/// <summary>
/// 所有主题
/// </summary>
public List<Theme> Themes = new List<Theme>();
/// <summary>
/// 当前启用主题
/// </summary>
public Theme Theme = null;
/// <summary>
/// 加载主题
/// </summary>
/// <param name="themename">主题名称</param>
public void LoadTheme(string themename)
{
Theme ctheme = Themes.Find(x => x.Name == themename || x.xName == themename);
if (ctheme == null)
{
return;
}
Theme = ctheme;
//加载图片包
ImageSources.AddSources(ctheme.Images);
//阴影颜色
Application.Current.Resources["ShadowColor"] = Function.HEXToColor('#' + ctheme.ThemeColor[(gstr)"ShadowColor"]);
foreach (ILine lin in ctheme.ThemeColor.Assemblage.FindAll(x => !x.Name.Contains("Color")))
Application.Current.Resources[lin.Name] = new SolidColorBrush(Function.HEXToColor('#' + lin.info));
//系统生成部分颜色
Color c = Function.HEXToColor('#' + ctheme.ThemeColor["Primary"].info);
c.A = 204;
Application.Current.Resources["PrimaryTrans"] = new SolidColorBrush(c);
c.A = 44;
Application.Current.Resources["PrimaryTrans4"] = new SolidColorBrush(c);
c.A = 170;
Application.Current.Resources["PrimaryTransA"] = new SolidColorBrush(c);
c.A = 238;
Application.Current.Resources["PrimaryTransE"] = new SolidColorBrush(c);
c = Function.HEXToColor('#' + ctheme.ThemeColor["Secondary"].info);
c.A = 204;
Application.Current.Resources["SecondaryTrans"] = new SolidColorBrush(c);
c.A = 44;
Application.Current.Resources["SecondaryTrans4"] = new SolidColorBrush(c);
c.A = 170;
Application.Current.Resources["SecondaryTransA"] = new SolidColorBrush(c);
c.A = 238;
Application.Current.Resources["SecondaryTransE"] = new SolidColorBrush(c);
c = Function.HEXToColor('#' + ctheme.ThemeColor["DARKPrimary"].info);
c.A = 204;
Application.Current.Resources["DARKPrimaryTrans"] = new SolidColorBrush(c);
c.A = 44;
Application.Current.Resources["DARKPrimaryTrans4"] = new SolidColorBrush(c);
c.A = 170;
Application.Current.Resources["DARKPrimaryTransA"] = new SolidColorBrush(c);
c.A = 238;
Application.Current.Resources["DARKPrimaryTransE"] = new SolidColorBrush(c);
}
public void LoadFont(string fontname)
{
IFont cfont = Fonts.Find(x => x.Name == fontname);
if (cfont == null)
{
return;
}
Application.Current.Resources["MainFont"] = cfont.Font;
Panuon.WPF.UI.GlobalSettings.Setting.FontFamily = cfont.Font;
}
public List<Food> Foods { get; } = new List<Food>();
/// <summary>
/// 版本号
@ -1427,6 +1506,10 @@ namespace VPet_Simulator.Windows
Main = new Main(Core);
Main.NoFunctionMOD = Set.CalFunState;
//加载主题:
LoadTheme(Set.Theme);
//加载字体
LoadFont(Set.Font);
LoadingText.Content = "正在加载游戏\n该步骤可能会耗时比较长\n请耐心等待".Translate();

View File

@ -7,7 +7,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" d:DesignHeight="1000"
xmlns:system="clr-namespace:System;assembly=mscorlib" Width="{ll:Dbe SettingWidth, DefValue=650}" Height="550"
Closing="WindowX_Closing" FontSize="16" Style="{DynamicResource BaseWindowXStyle}" Topmost="True"
Closing="WindowX_Closing" FontSize="16" Style="{DynamicResource BaseWindowXStyle}" Topmost="True"
WindowStartupLocation="CenterScreen" mc:Ignorable="d">
<!--<pu:WindowX.Resources>
<DataTemplate x:Key="DIYDataTemplate">
@ -20,11 +20,12 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBox x:Name="tb_seach_menu" FontSize="16" pu:TextBoxHelper.Watermark="{ll:Str 搜索设置}"
Style="{DynamicResource StandardTextBoxStyle}" VerticalAlignment="Top" Margin="3,6,6,0" TextChanged="tb_seach_menu_textchange" />
Style="{DynamicResource StandardTextBoxStyle}" VerticalAlignment="Top" Margin="3,6,6,0"
TextChanged="tb_seach_menu_textchange" />
<ListBox x:Name="ListMenu" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="3,40,6,3"
BorderBrush="{DynamicResource Primary}"
pu:ListBoxHelper.CornerRadius="5" BorderThickness="2" Background="{DynamicResource SecondaryLighter}"
BorderBrush="{DynamicResource Primary}" pu:ListBoxHelper.CornerRadius="5" BorderThickness="2"
Background="{DynamicResource SecondaryLighter}"
pu:ListBoxHelper.ItemsHoverBackground="{DynamicResource Primary}"
pu:ListBoxHelper.ItemsSelectedBackground="{DynamicResource SecondaryLight}" />
<GridSplitter Width="3" Background="{DynamicResource PrimaryDarker}" />
@ -149,12 +150,12 @@
<TextBlock Grid.Row="5" Grid.ColumnSpan="2" VerticalAlignment="Center" Text="{ll:Str 渲染分辨率}" />
<TextBlock Grid.Row="6" VerticalAlignment="Center" Text="{ll:Str 主题}" />
<ComboBox x:Name="ThemeBox" Grid.Row="6" Grid.Column="2" Margin="0,3,0,2" FontSize="16"
IsEnabled="False" SelectionChanged="ThemeBox_SelectionChanged"
SelectionChanged="ThemeBox_SelectionChanged"
Style="{DynamicResource StandardComboBoxStyle}" />
<TextBlock Grid.Row="7" VerticalAlignment="Center" Text="{ll:Str 字体}" />
<ComboBox x:Name="FontBox" Grid.Row="7" Grid.Column="2" Margin="0,2,0,3" FontSize="16"
IsEnabled="False" SelectionChanged="FontBox_SelectionChanged"
SelectionChanged="FontBox_SelectionChanged"
Style="{DynamicResource StandardComboBoxStyle}" />
<TextBlock Grid.Row="8" VerticalAlignment="Center" Text="{ll:Str 启动位置}" />
<Grid Grid.Row="8" Grid.Column="2">
@ -396,9 +397,9 @@
<Button x:Name="btn_cleancache" Grid.Row="1" Grid.Column="2" Margin="4" Padding="1"
pu:ButtonHelper.CornerRadius="4" Background="{DynamicResource SecondaryLight}"
Click="cleancache_click" Content="{ll:Str 清理缓存}" ToolTip="{ll:Str '清理缓存的动画,声音文件'}" />
<Button Grid.Row="1" Grid.Column="2" Margin="4" Padding="1"
pu:ButtonHelper.CornerRadius="4" Background="{DynamicResource SecondaryLight}"
Click="cleancache_click" Content="{ll:Str 清理缓存}" ToolTip="{ll:Str '清理缓存的动画,声音文件'}" />
<Button Grid.Row="1" Grid.Column="2" Margin="4" Padding="1" pu:ButtonHelper.CornerRadius="4"
Background="{DynamicResource SecondaryLight}" Click="cleancache_click"
Content="{ll:Str 清理缓存}" ToolTip="{ll:Str '清理缓存的动画,声音文件'}" />
<TextBlock Margin="0,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"
Background="{x:Null}" TextWrapping="Wrap">
<Run FontSize="18" FontWeight="Bold" Text="{ll:Str 桌宠多开}" /> <LineBreak />
@ -429,9 +430,10 @@
Background="{DynamicResource SecondaryLight}" Content="{ll:Str 打开}"
ToolTip="{ll:Str 打开当前选择的多开存档}" VerticalAlignment="Top" Height="25"
Click="btn_muti_open_click" />
<Button x:Name="btn_mutidel" Grid.Row="1" Grid.Column="3" Margin="5" Padding="1" pu:ButtonHelper.CornerRadius="4"
Background="{DynamicResource SecondaryLight}" Content="{ll:Str 删除}"
ToolTip="{ll:Str 删除当前选择的多开存档}" VerticalAlignment="Bottom" Height="25" Click="btn_mutidel_Click" />
<Button x:Name="btn_mutidel" Grid.Row="1" Grid.Column="3" Margin="5" Padding="1"
pu:ButtonHelper.CornerRadius="4" Background="{DynamicResource SecondaryLight}"
Content="{ll:Str 删除}" ToolTip="{ll:Str 删除当前选择的多开存档}" VerticalAlignment="Bottom"
Height="25" Click="btn_mutidel_Click" />
<ListBox x:Name="LBHave" Grid.Row="1" Grid.Column="2" Margin="1,2,1,2"
pu:ListBoxHelper.CornerRadius="4" BorderBrush="{DynamicResource DARKPrimary}"
BorderThickness="2" MinHeight="66"

View File

@ -147,6 +147,19 @@ namespace VPet_Simulator.Windows
}
}
foreach (var v in mw.Fonts)
{
FontBox.Items.Add(v.Name);
}
FontBox.SelectedItem = mw.Set.Font;
foreach (var v in mw.Themes)
{
ThemeBox.Items.Add(v.Name);
}
if (mw.Theme != null)
ThemeBox.SelectedItem = mw.Theme.Name;
VoiceCatchSilder.Value = mw.Set.MusicCatch;
VoiceMaxSilder.Value = mw.Set.MusicMax;
@ -476,12 +489,20 @@ namespace VPet_Simulator.Windows
private void ThemeBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!AllowChange)
return;
string str = (string)(ThemeBox.SelectedItem);
mw.LoadTheme(str);
mw.Set.Theme = mw.Theme.xName;
}
private void FontBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!AllowChange)
return;
string str = (string)(FontBox.SelectedItem);
mw.LoadFont(str);
mw.Set.Font = str;
}
private void CBAutoSave_SelectionChanged(object sender, SelectionChangedEventArgs e)

View File

@ -0,0 +1,20 @@
default#原版默认:|image#default:|
Primary#FF81d4fa:|
PrimaryLight#FFA3E2FF:|
PrimaryLighter#FFC1EBFF:|
PrimaryDark#FF5CBEEA:|
PrimaryDarker#FF3CA9DB:|
PrimaryText#FF000000:|
Secondary#FF90caf9:|
SecondaryLight#FFADD7F9:|
SecondaryLighter#FFCBE4F9:|
SecondaryDark#FF6BB1E9:|
SecondaryDarker#FF4999DA:|
SecondaryText#FF000000:|
DARKPrimary#FF039be5:|
DARKPrimaryLight#FF1FA9EC:|
DARKPrimaryLighter#FF3DB8F4:|
DARKPrimaryDark#FF0290D5:|
DARKPrimaryDarker#FF0286C6:|
DARKPrimaryText#FFffffff:|
ShadowColor#90CAF9:|

View File

@ -0,0 +1,20 @@
prupe#混色紫:|image#default:|
Primary#FF64b5f6:|
PrimaryLight#FF90caf9:|
PrimaryLighter#FFbbdefb:|
PrimaryDark#FF7e57c2:|
PrimaryDarker#FF7b1fa2:|
PrimaryText#FF000000:|
Secondary#FF7986cb:|
SecondaryLight#FF9fa8da:|
SecondaryLighter#FFc5cae9:|
SecondaryDark#FF512da8:|
SecondaryDarker#FF4527a0:|
SecondaryText#FF000000:|
DARKPrimary#FF4a148c:|
DARKPrimaryLight#FF6a1b9a:|
DARKPrimaryLighter#FF9c4dcc:|
DARKPrimaryDark#FF3a106c:|
DARKPrimaryDarker#FF12005e:|
DARKPrimaryText#FFffffff:|
ShadowColor#FF7986cb:|

View File

@ -0,0 +1,20 @@
vup#默认虚拟主播风格:|image#vup:|
Primary#FF81d4fa:|
PrimaryLight#FFA3E2FF:|
PrimaryLighter#FFC1EBFF:|
PrimaryDark#FF5CBEEA:|
PrimaryDarker#FF3CA9DB:|
PrimaryText#FF000000:|
Secondary#FF90caf9:|
SecondaryLight#FFADD7F9:|
SecondaryLighter#FFCBE4F9:|
SecondaryDark#FF6BB1E9:|
SecondaryDarker#FF4999DA:|
SecondaryText#FF000000:|
DARKPrimary#FF039be5:|
DARKPrimaryLight#FF1FA9EC:|
DARKPrimaryLighter#FF3DB8F4:|
DARKPrimaryDark#FF0290D5:|
DARKPrimaryDarker#FF0286C6:|
DARKPrimaryText#FFffffff:|
ShadowColor#90CAF9:|