From 4767cb96d2461299729b2d46cb81e781ba7fdaf5 Mon Sep 17 00:00:00 2001 From: ZouJin Date: Mon, 19 Aug 2024 23:23:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E5=B7=A5=E4=BD=9C=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20#417?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet-Simulator.Core/Display/MainLogic.cs | 23 +++++++- VPet-Simulator.Core/Display/ToolBar.xaml.cs | 2 +- VPet-Simulator.Core/Display/WorkTimer.xaml.cs | 54 ++++++++++++++----- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/VPet-Simulator.Core/Display/MainLogic.cs b/VPet-Simulator.Core/Display/MainLogic.cs index 22746d0..ed7348c 100644 --- a/VPet-Simulator.Core/Display/MainLogic.cs +++ b/VPet-Simulator.Core/Display/MainLogic.cs @@ -9,6 +9,7 @@ using System.Windows; using System.Windows.Controls; using static VPet_Simulator.Core.GraphHelper; using static VPet_Simulator.Core.GraphInfo; +using static VPet_Simulator.Core.WorkTimer; namespace VPet_Simulator.Core { @@ -346,7 +347,7 @@ namespace VPet_Simulator.Core //看情况播放停止工作动画 if (Core.Save.Mode == IGameSave.ModeType.Ill && State == WorkingState.Work) { - Dispatcher.Invoke(() => WorkTimer.Stop()); + Dispatcher.Invoke(() => WorkTimer.Stop(reason: FinishWorkInfo.StopReason.StateFail)); } } public void PlaySwitchAnimat(IGameSave.ModeType before, IGameSave.ModeType after) @@ -569,7 +570,7 @@ namespace VPet_Simulator.Core if (!Core.Controller.EnableFunction || Core.Save.Mode != IGameSave.ModeType.Ill) if (!Core.Controller.EnableFunction || Core.Save.Level >= work.LevelLimit) if (State == Main.WorkingState.Work && NowWork.Name == work.Name) - WorkTimer.Stop(); + WorkTimer.Stop(reason: FinishWorkInfo.StopReason.MenualStop); else { if (WorkCheck != null && !WorkCheck.Invoke(work)) @@ -585,5 +586,23 @@ namespace VPet_Simulator.Core work.NameTrans), LocalizeCore.Translate("{0}取消", work.NameTrans)); return false; } + /// + /// 任务开始时调用该参数 + /// + public event Action Event_WorkStart; + /// + /// 任务完成时调用该参数 (重定向至WorkTimer.E_FinishWork) + /// + public event Action Event_WorkEnd + { + add + { + WorkTimer.E_FinishWork += value; + } + remove + { + WorkTimer.E_FinishWork -= value; + } + } } } diff --git a/VPet-Simulator.Core/Display/ToolBar.xaml.cs b/VPet-Simulator.Core/Display/ToolBar.xaml.cs index 40b96e0..e06f397 100644 --- a/VPet-Simulator.Core/Display/ToolBar.xaml.cs +++ b/VPet-Simulator.Core/Display/ToolBar.xaml.cs @@ -428,7 +428,7 @@ namespace VPet_Simulator.Core m.DisplaySleep(true); else { - m.WorkTimer.Stop(() => m.DisplaySleep(true)); + m.WorkTimer.Stop(() => m.DisplaySleep(true), WorkTimer.FinishWorkInfo.StopReason.MenualStop); } } } diff --git a/VPet-Simulator.Core/Display/WorkTimer.xaml.cs b/VPet-Simulator.Core/Display/WorkTimer.xaml.cs index 6261d03..ad0ae67 100644 --- a/VPet-Simulator.Core/Display/WorkTimer.xaml.cs +++ b/VPet-Simulator.Core/Display/WorkTimer.xaml.cs @@ -1,9 +1,11 @@ using LinePutScript.Localization.WPF; using System; +using System.Drawing; using System.Windows; using System.Windows.Controls; using static VPet_Simulator.Core.GraphHelper; using static VPet_Simulator.Core.GraphInfo; +using static VPet_Simulator.Core.WorkTimer.FinishWorkInfo; namespace VPet_Simulator.Core { @@ -37,10 +39,6 @@ namespace VPet_Simulator.Core /// public DateTime StartTime; /// - /// 任务完成时调用该参数 - /// - public event Action E_FinishWork; - /// /// 完成工作信息 /// public struct FinishWorkInfo @@ -58,26 +56,54 @@ namespace VPet_Simulator.Core /// public double spendtime; /// + /// 停止工作的原因 + /// + public enum StopReason + { + /// + /// 时间结束完成 + /// + TimeFinish, + /// + /// 玩家手动停止 + /// + MenualStop, + /// + /// 因为状态等停止 + /// + StateFail, + /// + /// 其他原因 + /// + Other, + } + /// + /// 停止原因 + /// + public StopReason Reason; + /// /// 完成工作信息 /// /// 当前工作 /// 当前盈利(自动计算附加) - public FinishWorkInfo(Work work, double count) + public FinishWorkInfo(Work work, double count, StopReason reason) { this.work = work; this.count = count * (1 + work.FinishBonus); this.spendtime = work.Time; + this.Reason = reason; } /// /// 完成工作信息 /// /// 当前工作 /// 当前盈利(自动计算附加) - public FinishWorkInfo(Work work, double count, DateTime starttime) + public FinishWorkInfo(Work work, double count, DateTime starttime, StopReason reason) { this.work = work; this.count = count * (1 + work.FinishBonus); this.spendtime = DateTime.Now.Subtract(starttime).TotalMinutes; + this.Reason = reason; } } /// @@ -95,18 +121,18 @@ namespace VPet_Simulator.Core //ts = TimeSpan.FromMinutes(MaxTime); //tleft = TimeSpan.Zero; //PBLeft.Value = MaxTime; - FinishWorkInfo fwi = new FinishWorkInfo(m.NowWork, GetCount); + FinishWorkInfo fwi = new FinishWorkInfo(m.NowWork, GetCount, FinishWorkInfo.StopReason.TimeFinish); if (m.NowWork.Type == Work.WorkType.Work) { m.Core.Save.Money += GetCount * m.NowWork.FinishBonus; Stop(() => m.SayRnd(LocalizeCore.Translate("{2}完成啦, 累计赚了 {0:f2} 金钱\n共计花费了{1}分钟", fwi.count, - fwi.spendtime, fwi.work.NameTrans), true)); + fwi.spendtime, fwi.work.NameTrans), true), StopReason.TimeFinish); } else { m.Core.Save.Exp += GetCount * m.NowWork.FinishBonus; Stop(() => m.SayRnd(LocalizeCore.Translate("{2}完成啦, 累计获得 {0:f2} 经验\n共计花费了{1}分钟", fwi.count, - fwi.spendtime, fwi.work.NameTrans), true)); + fwi.spendtime, fwi.work.NameTrans), true), StopReason.TimeFinish); } return; } @@ -209,11 +235,11 @@ namespace VPet_Simulator.Core /// 停止工作 /// /// - public void Stop(Action @then = null) + public void Stop(Action @then = null, StopReason reason = StopReason.MenualStop) { if (m.State == Main.WorkingState.Work && m.NowWork != null) { - FinishWorkInfo fwi = new FinishWorkInfo(m.NowWork, GetCount, StartTime); + FinishWorkInfo fwi = new FinishWorkInfo(m.NowWork, GetCount, StartTime, reason); E_FinishWork?.Invoke(fwi); } Visibility = Visibility.Collapsed; @@ -222,7 +248,11 @@ namespace VPet_Simulator.Core } private void btnStop_Click(object sender, RoutedEventArgs e) { - Stop(); + Stop(reason: StopReason.MenualStop); } + /// + /// 任务完成时调用该参数 + /// + public event Action E_FinishWork; } }