重构Main加载

This commit is contained in:
ZouJin 2024-03-19 17:20:07 +08:00
parent eac5a74371
commit 56502ca22c
4 changed files with 449 additions and 416 deletions

View File

@ -10,7 +10,7 @@
<MediaElement x:Name="VoicePlayer" LoadedBehavior="Manual" UnloadedBehavior="Stop" x:FieldModifier="public" /> <MediaElement x:Name="VoicePlayer" LoadedBehavior="Manual" UnloadedBehavior="Stop" x:FieldModifier="public" />
<Grid x:Name="UIGrid_Back" x:FieldModifier="public" VerticalAlignment="Top" Width="500" /> <Grid x:Name="UIGrid_Back" x:FieldModifier="public" VerticalAlignment="Top" Width="500" />
<Border x:Name="PetGrid" Height="500" VerticalAlignment="Top" Width="500" x:FieldModifier="public"/> <Border x:Name="PetGrid" Height="500" VerticalAlignment="Top" Width="500" x:FieldModifier="public"/>
<Border x:Name="PetGrid2" Height="500" VerticalAlignment="Top" Width="500" x:FieldModifier="public"/> <Border x:Name="PetGrid2" Height="500" VerticalAlignment="Top" Width="500" x:FieldModifier="public" Visibility="Collapsed"/>
<Grid x:Name="UIGrid" x:FieldModifier="public" VerticalAlignment="Top" Width="500" /> <Grid x:Name="UIGrid" x:FieldModifier="public" VerticalAlignment="Top" Width="500" />
<Label x:Name="LabelDisplay" HorizontalAlignment="Center" VerticalAlignment="Center" Content="内容显示如下" <Label x:Name="LabelDisplay" HorizontalAlignment="Center" VerticalAlignment="Center" Content="内容显示如下"
FontSize="30" Background="{DynamicResource DARKPrimaryTransA}" FontSize="30" Background="{DynamicResource DARKPrimaryTransA}"

View File

@ -52,11 +52,11 @@ namespace VPet_Simulator.Core
public bool IsWorking { get; private set; } = false; public bool IsWorking { get; private set; } = false;
public SoundPlayer soundPlayer = new SoundPlayer(); public SoundPlayer soundPlayer = new SoundPlayer();
public bool windowMediaPlayerAvailable = true; public bool windowMediaPlayerAvailable = true;
public Main(GameCore core, bool loadtouchevent = true, IGraph startUPGraph = null)
public void Load_0_BaseConsole()
{
Dispatcher.Invoke(() =>
{ {
//Console.WriteLine(DateTime.Now.ToString("T:fff"));
InitializeComponent();
Core = core;
WorkTimer = new WorkTimer(this); WorkTimer = new WorkTimer(this);
WorkTimer.Visibility = Visibility.Collapsed; WorkTimer.Visibility = Visibility.Collapsed;
UIGrid.Children.Add(WorkTimer); UIGrid.Children.Add(WorkTimer);
@ -66,29 +66,17 @@ namespace VPet_Simulator.Core
MsgBar = new MessageBar(this); MsgBar = new MessageBar(this);
MsgBar.Visibility = Visibility.Collapsed; MsgBar.Visibility = Visibility.Collapsed;
UIGrid.Children.Add(MsgBar.This); UIGrid.Children.Add(MsgBar.This);
labeldisplaytimer.Elapsed += Labledisplaytimer_Elapsed; });
DisplayNomal = DisplayDefault;
if (loadtouchevent)
{
LoadTouchEvent();
} }
if (!core.Controller.EnableFunction) public void Load_3_BindingTimer()
Core.Save.Mode = NoFunctionMOD;
IGraph ig = startUPGraph ?? Core.Graph.FindGraph(Core.Graph.FindName(GraphType.StartUP), AnimatType.Single, core.Save.Mode);
ig ??= Core.Graph.FindGraph(Core.Graph.FindName(GraphType.Default), AnimatType.Single, core.Save.Mode);
//var ig2 = Core.Graph.FindGraph(GraphType.Default, core.GameSave.Mode);
PetGrid2.Visibility = Visibility.Collapsed;
Task.Run(() =>
{ {
EventTimer.Elapsed += (s, e) => EventTimer_Elapsed(); EventTimer.Elapsed += (s, e) => EventTimer_Elapsed();
MoveTimer.Elapsed += MoveTimer_Elapsed; MoveTimer.Elapsed += MoveTimer_Elapsed;
SmartMoveTimer.Elapsed += SmartMoveTimer_Elapsed; SmartMoveTimer.Elapsed += SmartMoveTimer_Elapsed;
//while (!ig.IsReady) }
//{ public async Task Load_2_WaitGraph()
// Thread.Sleep(100); {
//}//新功能:等待所有图像加载完成再跑 //新功能:等待所有图像加载完成再跑
foreach (var igs in Core.Graph.GraphsList.Values) foreach (var igs in Core.Graph.GraphsList.Values)
{ {
foreach (var ig2 in igs.Values) foreach (var ig2 in igs.Values)
@ -97,12 +85,18 @@ namespace VPet_Simulator.Core
{ {
while (!ig3.IsReady) while (!ig3.IsReady)
{ {
Thread.Sleep(100); await Task.Delay(100);
} }
} }
} }
} }
}
public void Load_4_Start(IGraph startUPGraph = null)
{
IGraph ig = startUPGraph ?? Core.Graph.FindGraph(Core.Graph.FindName(GraphType.StartUP), AnimatType.Single, Core.Save.Mode);
ig ??= Core.Graph.FindGraph(Core.Graph.FindName(GraphType.Default), AnimatType.Single, Core.Save.Mode);
Task.Run(() =>
{
ig.Run(PetGrid, () => ig.Run(PetGrid, () =>
{ {
IsWorking = true; IsWorking = true;
@ -116,6 +110,33 @@ namespace VPet_Simulator.Core
}); });
} }
public void Load_24_WaitAndStart()
{
Load_2_WaitGraph().Wait();
Load_4_Start();
}
public Main(GameCore core)
{
InitializeComponent();
Core = core;
labeldisplaytimer.Elapsed += Labledisplaytimer_Elapsed;
DisplayNomal = DisplayDefault;
if (!core.Controller.EnableFunction)
Core.Save.Mode = NoFunctionMOD;
}
public void LoadALL()
{
Load_0_BaseConsole();
Load_2_TouchEvent();
Load_2_WaitGraph().Wait();
Load_3_BindingTimer();
Load_4_Start();
}
private void Labledisplaytimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void Labledisplaytimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
if (--labeldisplaycount <= 0) if (--labeldisplaycount <= 0)
@ -140,7 +161,7 @@ namespace VPet_Simulator.Core
/// <summary> /// <summary>
/// 自动加载触摸事件 /// 自动加载触摸事件
/// </summary> /// </summary>
public void LoadTouchEvent() public void Load_2_TouchEvent()
{ {
Core.TouchEvent.Add(new TouchArea(Core.Graph.GraphConfig.TouchHeadLocate, Core.Graph.GraphConfig.TouchHeadSize, () => { DisplayTouchHead(); return true; })); Core.TouchEvent.Add(new TouchArea(Core.Graph.GraphConfig.TouchHeadLocate, Core.Graph.GraphConfig.TouchHeadSize, () => { DisplayTouchHead(); return true; }));
Core.TouchEvent.Add(new TouchArea(Core.Graph.GraphConfig.TouchBodyLocate, Core.Graph.GraphConfig.TouchBodySize, () => { DisplayTouchBody(); return true; })); Core.TouchEvent.Add(new TouchArea(Core.Graph.GraphConfig.TouchBodyLocate, Core.Graph.GraphConfig.TouchBodySize, () => { DisplayTouchBody(); return true; }));

View File

@ -1537,7 +1537,7 @@ namespace VPet_Simulator.Windows
await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "尝试加载游戏动画".Translate())); //await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "尝试加载游戏动画".Translate()));
await Dispatcher.InvokeAsync(new Action(() => await Dispatcher.InvokeAsync(new Action(() =>
{ {
LoadingText.Content = "尝试加载动画和生成缓存\n该步骤可能会耗时比较长\n请耐心等待".Translate(); LoadingText.Content = "尝试加载动画和生成缓存\n该步骤可能会耗时比较长\n请耐心等待".Translate();
@ -1552,8 +1552,11 @@ namespace VPet_Simulator.Windows
else else
#endif #endif
Main = new Main(Core); Main = new Main(Core);
}));
Main.LoadALL();
Main.NoFunctionMOD = Set.CalFunState; Main.NoFunctionMOD = Set.CalFunState;
await Dispatcher.InvokeAsync(() =>
{
//清空资源 //清空资源
Main.Resources = Application.Current.Resources; Main.Resources = Application.Current.Resources;
Main.MsgBar.This.Resources = Application.Current.Resources; Main.MsgBar.This.Resources = Application.Current.Resources;
@ -1969,7 +1972,8 @@ namespace VPet_Simulator.Windows
else if (Set.IsMSGMOD(cm.Name)) else if (Set.IsMSGMOD(cm.Name))
MessageBoxX.Show("由于 {0} 包含代码插件\n虚拟桌宠模拟器已自动停止加载该插件\n请手动前往设置允许启用该mod 代码插件".Translate(cm.Name), "{0} 未加载代码插件".Translate(cm.Name)); MessageBoxX.Show("由于 {0} 包含代码插件\n虚拟桌宠模拟器已自动停止加载该插件\n请手动前往设置允许启用该mod 代码插件".Translate(cm.Name), "{0} 未加载代码插件".Translate(cm.Name));
})); });
////游戏提示 ////游戏提示
//if (Set["SingleTips"][(gint)"open"] == 0 && Set.StartUPBoot == true && Set.StartUPBootSteam == true) //if (Set["SingleTips"][(gint)"open"] == 0 && Set.StartUPBoot == true && Set.StartUPBootSteam == true)

View File

@ -205,6 +205,15 @@ public partial class MPFriends : WindowX
Core.Graph = petloader.Graph(mw.Set.Resolution); Core.Graph = petloader.Graph(mw.Set.Resolution);
Main = new Main(Core); Main = new Main(Core);
Main.MsgBar = new MessageBar(Main);
Main.MsgBar.Visibility = Visibility.Collapsed;
Main.UIGrid.Children.Add(Main.MsgBar.This);
Main.ToolBar = new Core.ToolBar(Main);
Main.ToolBar.Visibility = Visibility.Collapsed;
Main.UIGrid.Children.Add(Main.ToolBar);
Main.Load_2_TouchEvent();
Task.Run(Main.Load_24_WaitAndStart);
Main.EventTimer.AutoReset = false; Main.EventTimer.AutoReset = false;
Main.EventTimer.Enabled = false; Main.EventTimer.Enabled = false;
@ -212,7 +221,6 @@ public partial class MPFriends : WindowX
Main.Resources = Application.Current.Resources; Main.Resources = Application.Current.Resources;
Main.MsgBar.This.Resources = Application.Current.Resources; Main.MsgBar.This.Resources = Application.Current.Resources;
Main.ToolBar.Resources = Application.Current.Resources; Main.ToolBar.Resources = Application.Current.Resources;
Main.ToolBar.LoadClean();
HideForDesign.Children.Remove(MPTalkBox); HideForDesign.Children.Remove(MPTalkBox);
Main.ToolBar.MainGrid.Children.Add(MPTalkBox); Main.ToolBar.MainGrid.Children.Add(MPTalkBox);