支持开机启动

This commit is contained in:
ZouJin 2023-02-17 16:33:46 +11:00
parent 2edc1df1db
commit 35acb61760
9 changed files with 105 additions and 19 deletions

View File

@ -59,7 +59,7 @@ namespace VPet_Simulator.Core
{ {
Task.Run(() => Task.Run(() =>
{ {
Thread.Sleep(timeleft * 100); Thread.Sleep(timeleft * 50);
if (m.DisplayType == GraphCore.GraphType.Default || m.DisplayType.ToString().Contains("Say")) if (m.DisplayType == GraphCore.GraphType.Default || m.DisplayType.ToString().Contains("Say"))
m.Display(GraphCore.GraphType.Say_C_End, m.DisplayNomal); m.Display(GraphCore.GraphType.Say_C_End, m.DisplayNomal);
}); });
@ -77,9 +77,9 @@ namespace VPet_Simulator.Core
} }
} }
public Timer EndTimer = new Timer() { Interval = 100 }; public Timer EndTimer = new Timer() { Interval = 200 };
public Timer ShowTimer = new Timer() { Interval = 40 }; public Timer ShowTimer = new Timer() { Interval = 40 };
public Timer CloseTimer = new Timer() { Interval = 10 }; public Timer CloseTimer = new Timer() { Interval = 20 };
int timeleft; int timeleft;
/// <summary> /// <summary>
/// 显示消息 /// 显示消息

View File

@ -9,8 +9,17 @@ using System.Windows;
namespace VPet_Simulator.Core namespace VPet_Simulator.Core
{ {
/// <summary>
/// 图像显示核心
/// </summary>
public class GraphCore public class GraphCore
{ {
public GraphCore()
{
if (!Directory.Exists(CachePath))
Directory.CreateDirectory(CachePath);
}
public static string CachePath = AppDomain.CurrentDomain.BaseDirectory + @"\cache"; public static string CachePath = AppDomain.CurrentDomain.BaseDirectory + @"\cache";
/// <summary> /// <summary>
/// 动画类型 /// 动画类型

View File

@ -1,4 +1,5 @@
<UserControl x:Class="VPet_Simulator.Core.PNGAnimation" <pu:ContentControlX x:Class="VPet_Simulator.Core.PNGAnimation"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@ -8,4 +9,4 @@
d:DesignHeight="500" d:DesignWidth="500"> d:DesignHeight="500" d:DesignWidth="500">
<Grid x:Name="MainGrid"> <Grid x:Name="MainGrid">
</Grid> </Grid>
</UserControl> </pu:ContentControlX>

View File

@ -18,13 +18,14 @@ using System.Threading;
using System.Drawing; using System.Drawing;
using LinePutScript; using LinePutScript;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TreeView; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TreeView;
using Panuon.WPF.UI;
namespace VPet_Simulator.Core namespace VPet_Simulator.Core
{ {
/// <summary> /// <summary>
/// PNGAnimation.xaml 的交互逻辑 /// PNGAnimation.xaml 的交互逻辑
/// </summary> /// </summary>
public partial class PNGAnimation : UserControl, IGraph public partial class PNGAnimation : ContentControlX, IGraph
{ {
/// <summary> /// <summary>
/// 所有动画帧 /// 所有动画帧

View File

@ -248,8 +248,24 @@ namespace VPet_Simulator.Windows
/// </summary> /// </summary>
public int SmartMoveInterval public int SmartMoveInterval
{ {
get => this["gameconfig"].GetInt("smartmoveinterval", 20*60); get => this["gameconfig"].GetInt("smartmoveinterval", 20 * 60);
set => this["gameconfig"].SetInt("smartmoveinterval", value); set => this["gameconfig"].SetInt("smartmoveinterval", value);
} }
/// <summary>
/// 开机启动
/// </summary>
public bool StartUPBoot
{
get => this["gameconfig"].GetBool("startboot");
set => this["gameconfig"].SetBool("startboot", value);
}
/// <summary>
/// 开机启动 Steam
/// </summary>
public bool StartUPBootSteam
{
get => !this["gameconfig"].GetBool("startbootsteam");
set => this["gameconfig"].SetBool("startbootsteam", !value);
}
} }
} }

View File

@ -73,10 +73,6 @@ namespace VPet_Simulator.Windows
else else
Set = new Setting("Setting#VPET:|\n"); Set = new Setting("Setting#VPET:|\n");
if (!Directory.Exists(GraphCore.CachePath))
{
Directory.CreateDirectory(GraphCore.CachePath);
}
//this.Width = 400 * ZoomSlider.Value; //this.Width = 400 * ZoomSlider.Value;
//this.Height = 450 * ZoomSlider.Value; //this.Height = 450 * ZoomSlider.Value;
@ -160,7 +156,9 @@ namespace VPet_Simulator.Windows
Dispatcher.Invoke(new Action(() => Dispatcher.Invoke(new Action(() =>
{ {
LoadingText.Content = "尝试加载动画和生成缓存";
Core.Graph = Pets[0].Graph(); Core.Graph = Pets[0].Graph();
LoadingText.Content = "正在加载游戏";
winSetting = new winGameSetting(this); winSetting = new winGameSetting(this);
Main = new Main(Core) { }; Main = new Main(Core) { };
Main.DefaultClickAction = () => Main.DefaultClickAction = () =>
@ -173,7 +171,7 @@ namespace VPet_Simulator.Windows
}; };
DisplayGrid.Child = Main; DisplayGrid.Child = Main;
Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "退出桌宠", () => { Close(); }); Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "退出桌宠", () => { Close(); });
Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "管理控制台", () => { new winConsole(this).Show(); }); Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "开发控制台", () => { new winConsole(this).Show(); });
Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "反馈中心", () => { new winReport(this).Show(); }); Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "反馈中心", () => { new winReport(this).Show(); });
Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "设置面板", () => Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "设置面板", () =>
{ {
@ -211,7 +209,7 @@ namespace VPet_Simulator.Windows
notifyIcon.Visible = true; notifyIcon.Visible = true;
if (Set["SingleTips"].GetBool("helloworld")) if (!Set["SingleTips"].GetBool("helloworld"))
{ {
Set["SingleTips"].SetBool("helloworld", true); Set["SingleTips"].SetBool("helloworld", true);
notifyIcon.ShowBalloonTip(10, "你好 " + (IsSteamUser ? Steamworks.SteamClient.Name : Environment.UserName), notifyIcon.ShowBalloonTip(10, "你好 " + (IsSteamUser ? Steamworks.SteamClient.Name : Environment.UserName),
@ -222,11 +220,11 @@ namespace VPet_Simulator.Windows
Main.Say("欢迎使用虚拟桌宠模拟器\n这是个早期的测试版,若有bug请多多包涵\n欢迎在菜单栏-管理-反馈中提交bug或建议"); Main.Say("欢迎使用虚拟桌宠模拟器\n这是个早期的测试版,若有bug请多多包涵\n欢迎在菜单栏-管理-反馈中提交bug或建议");
}); });
} }
else if (Set["SingleTips"].GetDateTime("update") <= new DateTime(2023, 2, 13)) else if (Set["SingleTips"].GetDateTime("update") <= new DateTime(2023, 2, 17))
{ {
Set["SingleTips"].SetDateTime("update", DateTime.Now); Set["SingleTips"].SetDateTime("update", DateTime.Now);
notifyIcon.ShowBalloonTip(10, "更新通知 02/13", notifyIcon.ShowBalloonTip(10, "更新通知 02/17",
"现在使用缓存机制,不仅占用小,而且再也不会有那种闪闪的问题了!", ToolTipIcon.Info); "现在使用缓存机制,不仅占用小,而且再也不会有那种闪闪的问题了!\n现已支持开机启动功能,前往设置设置开机启动", ToolTipIcon.Info);
} }
})); }));
} }

View File

@ -216,5 +216,16 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -90,11 +90,12 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<pu:Switch x:Name="StartUpBox" BorderBrush="{DynamicResource PrimaryDark}" <pu:Switch x:Name="StartUpBox" BorderBrush="{DynamicResource PrimaryDark}"
CheckedBackground="{DynamicResource Primary}" IsEnabled="False" CheckedBackground="{DynamicResource Primary}"
CheckedBorderBrush="{DynamicResource Primary}" Background="Transparent" CheckedBorderBrush="{DynamicResource Primary}" Background="Transparent"
BoxWidth="35" BoxHeight="18" ToggleSize="14" ToggleShadowColor="{x:Null}" BoxWidth="35" BoxHeight="18" ToggleSize="14" ToggleShadowColor="{x:Null}"
ToggleBrush="{DynamicResource PrimaryDark}" Content="开机启动" ToggleBrush="{DynamicResource PrimaryDark}" Content="开机启动"
CheckedToggleBrush="{DynamicResource DARKPrimaryText}" ToolTip="该游戏随着开机启动该程序" /> CheckedToggleBrush="{DynamicResource DARKPrimaryText}" ToolTip="该游戏随着开机启动该程序"
Checked="StartUpBox_Checked" Unchecked="StartUpBox_Checked" />
<pu:Switch x:Name="StartUpSteamBox" BorderBrush="{DynamicResource PrimaryDark}" <pu:Switch x:Name="StartUpSteamBox" BorderBrush="{DynamicResource PrimaryDark}"
CheckedBackground="{DynamicResource Primary}" CheckedBackground="{DynamicResource Primary}"
IsEnabled="{Binding ElementName=StartUpBox,Path=IsChecked}" IsEnabled="{Binding ElementName=StartUpBox,Path=IsChecked}"
@ -102,7 +103,8 @@
BoxWidth="35" BoxHeight="18" ToggleSize="14" ToggleShadowColor="{x:Null}" BoxWidth="35" BoxHeight="18" ToggleSize="14" ToggleShadowColor="{x:Null}"
ToggleBrush="{DynamicResource PrimaryDark}" Content="从Steam启动" ToggleBrush="{DynamicResource PrimaryDark}" Content="从Steam启动"
CheckedToggleBrush="{DynamicResource DARKPrimaryText}" CheckedToggleBrush="{DynamicResource DARKPrimaryText}"
ToolTip="从Steam启动该游戏, 统计时长不能停" Grid.Column="1" /> ToolTip="从Steam启动该游戏, 统计时长不能停" Grid.Column="1" Checked="StartUpSteamBox_Checked"
Unchecked="StartUpSteamBox_Checked" />
</Grid> </Grid>
<TextBlock Grid.Row="6" Text="宠物动画" VerticalAlignment="Center" FontSize="14" /> <TextBlock Grid.Row="6" Text="宠物动画" VerticalAlignment="Center" FontSize="14" />
<ComboBox x:Name="PetBox" Grid.Row="6" Grid.Column="2" ToolTip="加载的宠物动画,重启后生效" <ComboBox x:Name="PetBox" Grid.Row="6" Grid.Column="2" ToolTip="加载的宠物动画,重启后生效"

View File

@ -3,6 +3,7 @@ using Steamworks.Ugc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -52,6 +53,9 @@ namespace VPet_Simulator.Windows
SmartMoveEventBox.IsChecked = mw.Set.SmartMove; SmartMoveEventBox.IsChecked = mw.Set.SmartMove;
PressLengthSlider.Value = mw.Set.PressLength / 1000.0; PressLengthSlider.Value = mw.Set.PressLength / 1000.0;
StartUpBox.IsChecked = mw.Set.StartUPBoot;
StartUpSteamBox.IsChecked = mw.Set.StartUPBootSteam;
foreach (PetLoader pl in mw.Pets) foreach (PetLoader pl in mw.Pets)
{ {
PetBox.Items.Add(pl.Name); PetBox.Items.Add(pl.Name);
@ -534,7 +538,51 @@ namespace VPet_Simulator.Windows
{ {
mw.Main.SetMoveMode(mw.Set.AllowMove, mw.Set.SmartMove, mw.Set.SmartMoveInterval * 1000); mw.Main.SetMoveMode(mw.Set.AllowMove, mw.Set.SmartMove, mw.Set.SmartMoveInterval * 1000);
} }
private void GenStartUP()
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\VPET_Simulator.lnk";
if (mw.Set.StartUPBoot)
{
if (File.Exists(path))
{
return;
}
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
string shortcutAddress;
if (mw.Set.StartUPBootSteam)
#if DEMO
shortcutAddress = "steam://rungameid/2293870";
#else
shortcutAddress = "steam://rungameid/1920960";
#endif
else
shortcutAddress = System.Reflection.Assembly.GetExecutingAssembly().Location;
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(path);
shortcut.Description = "VPet Simulator";
shortcut.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
shortcut.TargetPath = shortcutAddress;
shortcut.IconLocation = AppDomain.CurrentDomain.BaseDirectory + @"vpeticon.ico";
shortcut.Save();
}
else
{
if (File.Exists(path))
{
File.Delete(path);
}
}
}
private void StartUpBox_Checked(object sender, RoutedEventArgs e)
{
mw.Set.StartUPBoot = StartUpBox.IsChecked == true;
GenStartUP();
}
private void StartUpSteamBox_Checked(object sender, RoutedEventArgs e)
{
mw.Set.StartUPBootSteam = StartUpSteamBox.IsChecked == true;
GenStartUP();
}
} }
} }