From 46dc67a7d8b653526af592fdaffc6884e560ed1c Mon Sep 17 00:00:00 2001 From: ZouJin Date: Sun, 26 May 2024 00:52:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E7=A8=8B=E8=A1=A8=E5=86=85=E6=A0=B8:?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=B7=A5=E4=BD=9C=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IMainWindow.cs | 7 +- VPet-Simulator.Windows.Interface/ISetting.cs | 4 + .../ScheduleItemBase.cs | 61 ----- .../ScheduleTask.cs | 241 ++++++++++++++++++ VPet-Simulator.Windows/MainWindow.cs | 5 + VPet-Simulator.Windows/MainWindow_Property.cs | 5 + .../WinDesign/winWorkMenu.xaml | 8 +- .../WinDesign/winWorkMenu.xaml.cs | 53 ++-- 8 files changed, 289 insertions(+), 95 deletions(-) delete mode 100644 VPet-Simulator.Windows.Interface/ScheduleItemBase.cs create mode 100644 VPet-Simulator.Windows.Interface/ScheduleTask.cs diff --git a/VPet-Simulator.Windows.Interface/IMainWindow.cs b/VPet-Simulator.Windows.Interface/IMainWindow.cs index f90756d..288e6bf 100644 --- a/VPet-Simulator.Windows.Interface/IMainWindow.cs +++ b/VPet-Simulator.Windows.Interface/IMainWindow.cs @@ -225,7 +225,12 @@ namespace VPet_Simulator.Windows.Interface /// /// 所有MOD文件位置 /// - public List MODPath { get; } + List MODPath { get; } + /// + /// 日程表 + /// + + ScheduleTask ScheduleTask { get; } } } diff --git a/VPet-Simulator.Windows.Interface/ISetting.cs b/VPet-Simulator.Windows.Interface/ISetting.cs index fc4b8a2..065d366 100644 --- a/VPet-Simulator.Windows.Interface/ISetting.cs +++ b/VPet-Simulator.Windows.Interface/ISetting.cs @@ -200,6 +200,10 @@ namespace VPet_Simulator.Windows.Interface /// 联机允许交互 /// bool MPNOTouch { get; set; } + /// + /// 桌宠皮肤(不一定是这个,如果找不到则为默认低0个) + /// + string PetGraph { get; } } } diff --git a/VPet-Simulator.Windows.Interface/ScheduleItemBase.cs b/VPet-Simulator.Windows.Interface/ScheduleItemBase.cs deleted file mode 100644 index 5674baf..0000000 --- a/VPet-Simulator.Windows.Interface/ScheduleItemBase.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Panuon.WPF; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Media; -using static VPet_Simulator.Core.GraphHelper; - -namespace VPet_Simulator.Windows.Interface; -/// -/// 日程表基础 -/// -public class ScheduleItemBase : NotifyPropertyChangedBase -{ - /// - /// 工作日程表 - /// - public class WorkScheduleItem - : ScheduleItemBase - { - public Work work { get; set; } - public WorkScheduleItem() - { - } - - public WorkScheduleItem(ImageSource image, - string workName, - int workTime) - { - Image = image; - WorkName = workName; - WorkTime = workTime; - } - - public ImageSource Image { get; set; } - - public string WorkName { get; set; } - - public int WorkTime { get; set; } - - public bool IsPreviousIsRest { get => _isPreviousIsRest; set => Set(ref _isPreviousIsRest, value); } - private bool _isPreviousIsRest; - } - - public class RestScheduleItem - : ScheduleItemBase - { - public RestScheduleItem() - { - } - - public RestScheduleItem(int restTime) - { - RestTime = restTime; - } - - public int RestTime { get => _restTime; set => Set(ref _restTime, value); } - private int _restTime; - } -} diff --git a/VPet-Simulator.Windows.Interface/ScheduleTask.cs b/VPet-Simulator.Windows.Interface/ScheduleTask.cs new file mode 100644 index 0000000..98e563a --- /dev/null +++ b/VPet-Simulator.Windows.Interface/ScheduleTask.cs @@ -0,0 +1,241 @@ +using LinePutScript; +using Panuon.WPF; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; +using System.Windows.Media; +using static VPet_Simulator.Core.GraphHelper; +using static VPet_Simulator.Core.GraphHelper.Work; + +namespace VPet_Simulator.Windows.Interface; + +/// +/// 日程表功能 +/// +public class ScheduleTask +{ + public ObservableCollection ScheduleItems { get; set; } = []; + private IMainWindow mw; + public int NowIndex { get; set; } = 0; + /// + /// 根据设置获取日程表 + /// + public ScheduleTask(IMainWindow imw) + { + this.mw = imw; + if (mw.GameSavesData.Data.ContainsLine("schedule")) + { + int i = 0; + var schedule = mw.GameSavesData.Data["schedule"]; + while (schedule.Contains(i.ToString())) + { + var sub = schedule[(gstr)i.ToString()].Split(','); + if (sub[0] == "rest") + { + ScheduleItems.Add(new RestScheduleItem(this, int.Parse(sub[1]))); + } + else + { + Work work = mw.Core.Graph.GraphConfig.Works.Find(w => w.Name == sub[0]); + if (work != null) + { + int dbl = int.Parse(sub[1]); + switch (work.Type) + { + case WorkType.Work: + ScheduleItems.Add(new WorkScheduleItem(this, work, dbl)); + break; + case WorkType.Study: + ScheduleItems.Add(new StudyScheduleItem(this, work, dbl)); + break; + case WorkType.Play: + ScheduleItems.Add(new PlayScheduleItem(this, work, dbl)); + break; + } + } + } + } + NowIndex = schedule[(gint)"now"]; + } + imw.Main.WorkTimer.E_FinishWork += WorkTimer_E_FinishWork; + RestTimer.Elapsed += RestTimer_Elapsed; + RestTimer.Start(); + } + public void Save() + { + mw.GameSavesData.Data["schedule"].Clear(); + mw.GameSavesData.Data["schedule"][(gint)"now"] = NowIndex; + for (int i = 0; i < ScheduleItems.Count; i++) + { + if (ScheduleItems[i] is RestScheduleItem rsi) + { + mw.GameSavesData.Data["schedule"][(gstr)i.ToString()] = $"rest,{rsi.RestTime}"; + } + else if (ScheduleItems[i] is WorkScheduleItem wsi) + { + mw.GameSavesData.Data["schedule"][(gstr)i.ToString()] = $"{wsi.Work.Name},{wsi.DBL}"; + } + } + } + + private void RestTimer_Elapsed(object sender, ElapsedEventArgs e) + { + if (RestTime-- < 0) + return; + if (RestTime == 0) + { + StartWork(); + } + else + { + RestTimer.Start(); + } + } + + public void StartWork() + { + RestTime = -100; + if (ScheduleItems.Count > 0) + { + if (NowIndex >= ScheduleItems.Count) + { + NowIndex = 0; + } + if (ScheduleItems[NowIndex] is WorkScheduleItem wsi) + { + mw.Main.StartWork(wsi.Work); + NowIndex++; + } + else if (ScheduleItems[NowIndex] is RestScheduleItem rsi) + { + NowIndex++; + RestTime = rsi.RestTime * 2; + RestTimer.Start(); + } + } + } + private int RestTime = 2; + private Timer RestTimer = new Timer() + { + Interval = 30000, + AutoReset = false + }; + + private void WorkTimer_E_FinishWork(Core.WorkTimer.FinishWorkInfo obj) => StartWork(); + + /// + /// 日程表日程 + /// + public class ScheduleItemBase : NotifyPropertyChangedBase + { + public ScheduleItemBase(ScheduleTask task) + { + Task = task; + } + public ScheduleTask Task; + /// + /// 休息时间 + /// + public virtual int RestTime { get; set; } = 0; + /// + /// 工作时间 + /// + public virtual int WorkTime { get; set; } = 0; + /// + /// 是否是当前正在进行的日程 + /// + public bool IsNow + { + get + { + if (Task.ScheduleItems.Count < Task.NowIndex) + { + return false; + } + return Task.ScheduleItems[Task.NowIndex] == this; + } + } + } + /// + /// 工作日程表日程 + /// + public class WorkScheduleItem + : ScheduleItemBase + { + /// + /// 翻倍倍率 + /// + public int DBL { get; set; } + /// + /// 当前绑定工作 + /// + public Work Work { get; set; } + public WorkScheduleItem(ScheduleTask task, Work work, int dbl) : base(task) + { + this.Work = work; + string source = task.mw.ImageSources.FindSource("work_" + task.mw.Set.PetGraph + "_" + work.Graph) ?? task.mw.ImageSources.FindSource("work_" + task.mw.Set.PetGraph + "_" + work.Name); + task.mw.Dispatcher.Invoke(() => + { + if (source == null) + { + //尝试显示默认图像 + Image = task.mw.ImageSources.FindImage("work_" + task.mw.Set.PetGraph + "_t_" + work.Type.ToString(), "work_" + work.Type.ToString()); + } + else + { + Image = ImageResources.NewSafeBitmapImage(source); + } + }); + } + + public ImageSource Image { get; set; } + + public string WorkName => Work.NameTrans; + + public override int WorkTime => Work.Time; + + public bool IsPreviousIsRest { get => _isPreviousIsRest; set => Set(ref _isPreviousIsRest, value); } + private bool _isPreviousIsRest; + } + /// + /// 学习日程表日程 + /// + public class StudyScheduleItem : WorkScheduleItem + { + public StudyScheduleItem(ScheduleTask task, Work work, int dbl) : base(task, work, dbl) + { + } + } + /// + /// 工作日程表日程 + /// + public class PlayScheduleItem : WorkScheduleItem + { + public PlayScheduleItem(ScheduleTask task, Work work, int dbl) : base(task, work, dbl) + { + } + public override int WorkTime => Work.Time / 2; + public override int RestTime => Work.Time / 2; + } + /// + /// 休息日程表日程 + /// + public class RestScheduleItem + : ScheduleItemBase + { + public RestScheduleItem(ScheduleTask task, int restTime) : base(task) + { + RestTime = restTime; + } + /// + /// 休息时间 + /// + public override int RestTime { get => _restTime; set => Set(ref _restTime, value); } + private int _restTime; + } +} + diff --git a/VPet-Simulator.Windows/MainWindow.cs b/VPet-Simulator.Windows/MainWindow.cs index 7d622ce..2de0664 100644 --- a/VPet-Simulator.Windows/MainWindow.cs +++ b/VPet-Simulator.Windows/MainWindow.cs @@ -220,6 +220,9 @@ namespace VPet_Simulator.Windows /// public void Save() { + //保存日程表 + ScheduleTask?.Save(); + //保存插件 foreach (MainPlugin mp in Plugins) mp.Save(); //游戏存档 @@ -1598,6 +1601,8 @@ namespace VPet_Simulator.Windows }; MusicTimer.Elapsed += MusicTimer_Elapsed; + //日程表加载 + ScheduleTask = new ScheduleTask(this); //await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "尝试加载游戏动画".Translate())); diff --git a/VPet-Simulator.Windows/MainWindow_Property.cs b/VPet-Simulator.Windows/MainWindow_Property.cs index 099fbf7..d662200 100644 --- a/VPet-Simulator.Windows/MainWindow_Property.cs +++ b/VPet-Simulator.Windows/MainWindow_Property.cs @@ -91,4 +91,9 @@ public partial class MainWindow /// 当前启用主题 /// public Theme Theme = null; + /// + /// 日程表 + /// + + public ScheduleTask ScheduleTask { get; set; } } diff --git a/VPet-Simulator.Windows/WinDesign/winWorkMenu.xaml b/VPet-Simulator.Windows/WinDesign/winWorkMenu.xaml index 71af354..94b6421 100644 --- a/VPet-Simulator.Windows/WinDesign/winWorkMenu.xaml +++ b/VPet-Simulator.Windows/WinDesign/winWorkMenu.xaml @@ -326,7 +326,7 @@ - +