VPet/VPet-Simulator.Windows/WinDesign/winWorkMenu.xaml.cs

518 lines
17 KiB
C#
Raw Normal View History

2024-03-14 11:31:34 +00:00
using LinePutScript.Localization.WPF;
2024-05-17 18:07:56 +00:00
using Panuon.WPF;
2024-03-27 16:45:14 +00:00
using Panuon.WPF.UI;
2024-03-14 11:31:34 +00:00
using System;
2024-03-11 07:22:23 +00:00
using System.Collections.Generic;
2024-03-27 18:36:56 +00:00
using System.Collections.ObjectModel;
2024-05-17 18:07:56 +00:00
using System.Linq;
2024-03-11 07:22:23 +00:00
using System.Windows;
using System.Windows.Controls;
2024-05-17 18:07:56 +00:00
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Windows.Media.Imaging;
2024-03-27 16:45:14 +00:00
using System.Windows.Threading;
2024-03-14 11:31:34 +00:00
using VPet_Simulator.Windows.Interface;
2024-03-12 16:38:23 +00:00
using static VPet_Simulator.Core.GraphHelper;
2024-03-11 07:22:23 +00:00
namespace VPet_Simulator.Windows;
/// <summary>
/// winWorkMenu.xaml 的交互逻辑
/// </summary>
2024-03-27 16:45:14 +00:00
public partial class winWorkMenu : WindowX
2024-03-11 07:22:23 +00:00
{
2024-03-12 16:38:23 +00:00
MainWindow mw;
List<Work> ws;
List<Work> ss;
List<Work> ps;
2024-03-27 16:45:14 +00:00
2024-03-27 18:36:56 +00:00
private readonly ObservableCollection<string> _workDetails = new ObservableCollection<string>();
private readonly ObservableCollection<string> _studyDetails = new ObservableCollection<string>();
private readonly ObservableCollection<string> _playDetails = new ObservableCollection<string>();
private readonly ObservableCollection<string> _starDetails = new ObservableCollection<string>();
2024-05-17 18:07:56 +00:00
private readonly ObservableCollection<ScheduleItemBase> _schedules = new ObservableCollection<ScheduleItemBase>();
2024-03-27 16:45:14 +00:00
public void ShowImageDefault(Work.WorkType type)
{
Dispatcher.BeginInvoke(() =>
{
WorkViewImage.Source = mw.ImageSources.FindImage("work_" + mw.Set.PetGraph + "_t_" + type.ToString(), "work_" + type.ToString());
}, DispatcherPriority.Loaded);
2024-05-17 18:07:56 +00:00
_schedules.CollectionChanged += Schedules_CollectionChanged;
icSchedule.ItemsSource = _schedules;
2024-03-27 16:45:14 +00:00
}
2024-03-14 11:31:34 +00:00
public winWorkMenu(MainWindow mw, Work.WorkType type)
2024-03-11 07:22:23 +00:00
{
InitializeComponent();
2024-03-12 16:38:23 +00:00
this.mw = mw;
mw.Main.WorkList(out ws, out ss, out ps);
2024-03-14 11:31:34 +00:00
if (ws.Count == 0)
2024-03-27 16:45:14 +00:00
LsbCategory.Items.Remove(LsbiWork);
2024-03-14 11:31:34 +00:00
else
foreach (var v in ws)
{
2024-03-27 16:45:14 +00:00
_workDetails.Add(v.NameTrans);
2024-03-14 11:31:34 +00:00
}
if (ss.Count == 0)
2024-03-27 16:45:14 +00:00
LsbCategory.Items.Remove(LsbiStudy);
2024-03-14 11:31:34 +00:00
else
foreach (var v in ss)
{
2024-03-27 16:45:14 +00:00
_studyDetails.Add(v.NameTrans);
2024-03-14 11:31:34 +00:00
}
if (ps.Count == 0)
2024-03-27 16:45:14 +00:00
LsbCategory.Items.Remove(LsbiPlay);
2024-03-14 11:31:34 +00:00
else
foreach (var v in ps)
{
2024-03-27 16:45:14 +00:00
_playDetails.Add(v.NameTrans);
2024-03-14 11:31:34 +00:00
}
2024-03-26 13:10:09 +00:00
foreach (var v in mw.WorkStar())
{
2024-03-27 16:45:14 +00:00
_starDetails.Add(v.NameTrans);
2024-03-26 13:10:09 +00:00
}
2024-03-27 16:45:14 +00:00
LsbCategory.SelectedIndex = (int)type;
2024-03-15 05:18:05 +00:00
ShowImageDefault(type);
2024-03-27 18:36:56 +00:00
AllowChange = true;
2024-05-17 18:07:56 +00:00
_schedules.Add(new WorkScheduleItem(
mw.ImageSources.FindImage("work_" + mw.Set.PetGraph + "_t_" + type.ToString(), "work_" + type.ToString()),
"学习",
60
));
_schedules.Add(new RestScheduleItem(10));
_schedules.Add(new WorkScheduleItem(
mw.ImageSources.FindImage("work_" + mw.Set.PetGraph + "_t_" + type.ToString(), "work_" + type.ToString()),
"学习",
70
));
2024-05-18 18:51:38 +00:00
ComboBoxHelper.SetWatermark(detailTypes, "---" + "请选择".Translate() + "---");
ComboBoxHelper.SetWatermark(combTaskType, "---" + "请选择".Translate() + "套餐".Translate() + "---");
2024-03-14 11:31:34 +00:00
}
2024-03-26 13:10:09 +00:00
public bool IsWorkStar(Work work) => mw.Set["work_star"].GetBool(work.Name);
public void SetWorkStar(Work work, bool setvalue) => mw.Set["work_star"].SetBool(work.Name, setvalue);
2024-03-14 11:31:34 +00:00
private bool AllowChange = false;
Work nowwork;
2024-03-15 05:18:05 +00:00
Work nowworkdisplay;
2024-03-14 11:31:34 +00:00
public void ShowWork()
{
AllowChange = false;
btnStart.IsEnabled = true;
//判断倍率
if (nowwork.LevelLimit > mw.GameSavesData.GameSave.Level)
{
wDouble.IsEnabled = false;
wDouble.Value = 1;
}
else
{
int max = Math.Min(4000, mw.GameSavesData.GameSave.Level) / (nowwork.LevelLimit + 10);
2024-03-14 11:31:34 +00:00
if (max <= 1)
{
wDouble.IsEnabled = false;
wDouble.Value = 1;
}
else
{
wDouble.IsEnabled = true;
wDouble.Maximum = max;
2024-03-26 13:10:09 +00:00
wDouble.Value = mw.Set["workmenu"].GetInt("double_" + nowwork.Name, 1);
2024-03-14 11:31:34 +00:00
}
}
if (wDouble.Value == 1)
ShowWork(nowwork);
else
ShowWork(nowwork.Double((int)wDouble.Value));
AllowChange = true;
}
public void ShowWork(Work work)
{
2024-04-04 16:54:34 +00:00
if (!mw.Set["gameconfig"].GetBool("noAutoCal") && work.IsOverLoad())
{
work.FixOverLoad();
}
2024-03-15 05:18:05 +00:00
nowworkdisplay = work;
2024-03-27 18:36:56 +00:00
2024-03-14 11:31:34 +00:00
//显示图像
2024-03-21 15:40:37 +00:00
string source = mw.ImageSources.FindSource("work_" + mw.Set.PetGraph + "_" + work.Graph) ?? mw.ImageSources.FindSource("work_" + mw.Set.PetGraph + "_" + work.Name);
2024-03-14 11:31:34 +00:00
if (source == null)
2024-03-12 16:38:23 +00:00
{
2024-03-14 11:31:34 +00:00
//尝试显示默认图像
2024-03-15 05:18:05 +00:00
ShowImageDefault(work.Type);
2024-03-12 16:38:23 +00:00
}
2024-03-14 11:31:34 +00:00
else
2024-03-12 16:38:23 +00:00
{
2024-03-14 11:31:34 +00:00
WorkViewImage.Source = Interface.ImageResources.NewSafeBitmapImage(source);
2024-03-12 16:38:23 +00:00
}
2024-03-14 11:31:34 +00:00
if (work.Type == Work.WorkType.Work)
2024-03-27 18:36:56 +00:00
tbGain.Text = "金钱".Translate();
2024-03-14 11:31:34 +00:00
else
2024-03-27 18:36:56 +00:00
tbGain.Text = "经验".Translate();
2024-03-28 10:19:25 +00:00
tbSpeed.Text = work.Get().ToString("f2");
tbFood.Text = work.StrengthFood.ToString("f2");
tbDrink.Text = work.StrengthDrink.ToString("f2");
tbSpirit.Text = work.Feeling.ToString("f2");
2024-03-27 16:45:14 +00:00
tbLvLimit.Text = work.LevelLimit.ToString("f0");
2024-03-14 11:31:34 +00:00
if (work.Time > 100)
2024-03-27 16:45:14 +00:00
tbTime.Text = (work.Time / 60).ToString("f2") + 'h';
2024-03-14 11:31:34 +00:00
else
2024-03-27 16:45:14 +00:00
tbTime.Text = work.Time.ToString() + 'm';
tbBonus.Text = 'x' + (1 + work.FinishBonus).ToString("f2");
tbRatio.Text = 'x' + wDouble.Value.ToString("f0");
2024-03-26 13:10:09 +00:00
tbtn_star.IsChecked = IsWorkStar(work);
2024-03-14 11:31:34 +00:00
}
2024-03-27 16:45:14 +00:00
private void LsbCategory_SelectionChanged(object sender, SelectionChangedEventArgs e)
2024-03-14 11:31:34 +00:00
{
2024-03-27 16:45:14 +00:00
Dispatcher.BeginInvoke(() =>
2024-03-14 11:31:34 +00:00
{
2024-03-27 16:45:14 +00:00
var lastIndex = detailTypes.SelectedIndex;
2024-05-17 05:20:08 +00:00
if (LsbCategory.SelectedIndex < 3)
2024-03-27 18:36:56 +00:00
ShowImageDefault((Work.WorkType)LsbCategory.SelectedIndex);
2024-05-17 18:07:56 +00:00
gdWork.Visibility = Visibility.Visible;
gdSchedule.Visibility = Visibility.Collapsed;
2024-03-27 16:45:14 +00:00
switch (LsbCategory.SelectedIndex)
{
case 0:
detailTypes.ItemsSource = _workDetails;
btnStart.Content = "开始工作".Translate();
2024-05-18 18:51:38 +00:00
ComboBoxHelper.SetWatermark(detailTypes, "---" + "请选择".Translate() + "工作".Translate() + "---");
2024-03-27 16:45:14 +00:00
break;
case 1:
detailTypes.ItemsSource = _studyDetails;
btnStart.Content = "开始学习".Translate();
2024-05-18 18:51:38 +00:00
ComboBoxHelper.SetWatermark(detailTypes, "---" + "请选择".Translate() + "学习".Translate() + "---");
2024-03-27 16:45:14 +00:00
break;
case 2:
detailTypes.ItemsSource = _playDetails;
btnStart.Content = "开始玩耍".Translate();
2024-05-18 18:51:38 +00:00
ComboBoxHelper.SetWatermark(detailTypes, "---" + "请选择".Translate() + "玩耍".Translate() + "---");
2024-03-27 16:45:14 +00:00
break;
case 3:
detailTypes.ItemsSource = _starDetails;
btnStart.Content = "开始工作".Translate();
2024-05-18 18:51:38 +00:00
ComboBoxHelper.SetWatermark(detailTypes, "---" + "请选择".Translate() + "---");
2024-03-27 16:45:14 +00:00
break;
2024-05-17 05:20:08 +00:00
case 4:
gdWork.Visibility = Visibility.Collapsed;
2024-05-17 18:07:56 +00:00
gdSchedule.Visibility = Visibility.Visible;
2024-05-17 05:20:08 +00:00
return;
2024-03-27 16:45:14 +00:00
}
2024-05-18 18:51:38 +00:00
//detailTypes.IsDropDownOpen = true;
2024-03-27 18:36:56 +00:00
detailTypes_SelectionChanged(null, null);
}, DispatcherPriority.Loaded);
2024-03-14 11:31:34 +00:00
}
2024-03-12 16:38:23 +00:00
2024-03-14 11:31:34 +00:00
private void wDouble_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!AllowChange) return;
2024-03-26 11:27:37 +00:00
mw.Set["workmenu"].SetInt("double_" + nowwork.Name, (int)wDouble.Value);
2024-03-14 11:31:34 +00:00
ShowWork(nowwork.Double((int)wDouble.Value));
}
2024-03-27 16:45:14 +00:00
private void detailTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
2024-03-14 11:31:34 +00:00
{
2024-03-27 16:45:14 +00:00
Dispatcher.BeginInvoke(() =>
{
if (detailTypes.SelectedIndex < 0)
{
tbGain.Text = "??";
tbSpeed.Text = "??";
tbFood.Text = "??";
tbDrink.Text = "??";
tbSpirit.Text = "??";
tbLvLimit.Text = "??";
tbTime.Text = "??";
tbBonus.Text = "??";
tbRatio.Text = "??";
return;
}
switch (LsbCategory.SelectedIndex)
{
case 0:
nowwork = (ws[detailTypes.SelectedIndex]);
break;
case 1:
nowwork = (ss[detailTypes.SelectedIndex]);
break;
case 2:
nowwork = (ps[detailTypes.SelectedIndex]);
break;
case 3:
if (!AllowChange) return;
var works = mw.WorkStar();
if (works.Count <= detailTypes.SelectedIndex) return;
nowwork = (works[detailTypes.SelectedIndex]);
break;
2024-05-17 05:20:08 +00:00
case 4:
return;
2024-03-27 16:45:14 +00:00
}
ShowWork();
2024-03-27 18:36:56 +00:00
}, DispatcherPriority.Loaded);
2024-03-14 11:31:34 +00:00
}
private void Window_Closed(object sender, EventArgs e)
{
mw.winWorkMenu = null;
2024-03-11 07:22:23 +00:00
}
2024-03-15 05:18:05 +00:00
2024-05-17 18:07:56 +00:00
private void Schedules_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
CalculateSceduleTime();
}
2024-03-15 05:18:05 +00:00
private void btnStart_Click(object sender, RoutedEventArgs e)
{
if (nowworkdisplay != null)
2024-03-16 14:39:25 +00:00
{
2024-03-18 14:26:50 +00:00
if (mw.Main.StartWork(nowworkdisplay))
Close();
2024-03-16 14:39:25 +00:00
}
2024-03-15 05:18:05 +00:00
}
2024-03-26 11:27:37 +00:00
2024-03-26 13:10:09 +00:00
private void tbtn_star_Click(object sender, RoutedEventArgs e)
{
2024-03-27 18:36:56 +00:00
if (nowwork == null)
return;
2024-03-26 13:10:09 +00:00
SetWorkStar(nowwork, tbtn_star.IsChecked == true);
AllowChange = false;
2024-03-27 16:45:14 +00:00
_starDetails.Clear();
2024-03-26 14:54:32 +00:00
mw.WorkStarMenu.Items.Clear();
2024-03-26 13:10:09 +00:00
//更新星标
foreach (var v in mw.WorkStar())
{
2024-03-27 16:45:14 +00:00
_starDetails.Add(v.NameTrans);
2024-03-27 18:36:56 +00:00
var mi = new MenuItem()
2024-03-26 13:10:09 +00:00
{
2024-03-27 18:36:56 +00:00
Header = v.NameTrans
2024-03-26 13:10:09 +00:00
};
2024-03-27 18:36:56 +00:00
mi.Click += (s, e) => mw.Main.ToolBar.StartWork(v.Double(mw.Set["workmenu"].GetInt("double_" + v.Name, 1)));
2024-03-26 13:10:09 +00:00
mw.WorkStarMenu.Items.Add(mi);
}
2024-03-27 18:36:56 +00:00
if (detailTypes.ItemsSource == _starDetails)
2024-03-27 16:45:14 +00:00
{
2024-03-27 18:36:56 +00:00
detailTypes_SelectionChanged(null, null);
2024-03-27 16:45:14 +00:00
}
2024-03-26 13:10:09 +00:00
AllowChange = true;
2024-03-26 11:27:37 +00:00
}
2024-05-17 18:07:56 +00:00
private void btnStartSchedule_Click(object sender, RoutedEventArgs e)
{
}
private void NumberInput_ValueChanged(object sender, SelectedValueChangedRoutedEventArgs<double?> e)
{
CalculateSceduleTime();
}
private void CalculateSceduleTime()
{
int workTime = 0;
int restTime = 0;
for (int i = 0; i < _schedules.Count; i++)
{
var item = _schedules[i];
var lastItem = i == 0 ? null : _schedules[i - 1];
if (item is WorkScheduleItem workItem)
{
workItem.IsPreviousIsRest = lastItem is RestScheduleItem;
workTime += workItem.WorkTime;
}
else if (item is RestScheduleItem restItem)
{
restTime += restItem.RestTime;
}
}
rpgbSchedule.Maximum = workTime + restTime;
rpgbSchedule.Value = workTime;
runScheduleWork.Text = workTime.ToString();
runScheduleRest.Text = restTime.ToString();
}
private void tbtn_Agency_CheckChanged(object sender, RoutedEventArgs e)
{
if (imgAgency == null)
{
return;
}
if (sender == tbtnAgencyJob)
{
imgAgency.Source = new BitmapImage(new Uri($"pack://application:,,,/Res/img/r_agency_job.png"));
tbtnAgencyTraning.IsChecked = false;
}
else if (sender == tbtnAgencyTraning)
{
imgAgency.Source = new BitmapImage(new Uri($"pack://application:,,,/Res/img/r_agency_training.png"));
tbtnAgencyJob.IsChecked = false;
}
}
private void tbtnAgency_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
var toggleButton = sender as ToggleButton;
if (toggleButton.IsChecked == true)
{
e.Handled = true;
}
}
private void btnSignAgency_Click(object sender, RoutedEventArgs e)
{
}
private void btn_addRest_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var scheduleItem = button.DataContext as ScheduleItemBase;
if (scheduleItem == null)
{
2024-05-18 18:51:38 +00:00
if (_schedules.LastOrDefault() is RestScheduleItem lastRest)
2024-05-17 18:07:56 +00:00
{
lastRest.RestTime += 30;
}
else
{
_schedules.Add(new RestScheduleItem(30));
}
}
else
{
var index = _schedules.IndexOf(scheduleItem);
_schedules.Insert(index, new RestScheduleItem(30));
}
}
private void btn_removeSchedule_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var scheduleItem = button.DataContext as ScheduleItemBase;
var index = _schedules.IndexOf(scheduleItem);
var previousItem = index == 0 ? null : _schedules[index - 1];
var nextItem = index == _schedules.Count - 1 ? null : _schedules[index + 1];
if (previousItem is RestScheduleItem previousRest
&& nextItem is RestScheduleItem nextRest)
{
previousRest.RestTime += nextRest.RestTime;
_schedules.Remove(nextRest);
}
_schedules.Remove(scheduleItem);
}
private void btn_scheduleUp_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var scheduleItem = button.DataContext as ScheduleItemBase;
var index = _schedules.IndexOf(scheduleItem);
2024-05-18 18:51:38 +00:00
if (index == 0)
2024-05-17 18:07:56 +00:00
{
return;
}
var previousItem = index == 0 ? null : _schedules[index - 1];
var nextItem = index == _schedules.Count - 1 ? null : _schedules[index + 1];
if (previousItem is RestScheduleItem previousRest
&& nextItem is RestScheduleItem nextRest)
{
previousRest.RestTime += nextRest.RestTime;
_schedules.Remove(nextRest);
}
_schedules.Remove(scheduleItem);
_schedules.Insert(Math.Max(index - 1, 0), scheduleItem);
}
private void btn_scheduleDown_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var scheduleItem = button.DataContext as ScheduleItemBase;
var index = _schedules.IndexOf(scheduleItem);
if (index == _schedules.Count - 1)
{
return;
}
var previousItem = index == 0 ? null : _schedules[index - 1];
var nextItem = index == _schedules.Count - 1 ? null : _schedules[index + 1];
if (previousItem is RestScheduleItem previousRest
&& nextItem is RestScheduleItem nextRest)
{
previousRest.RestTime += nextRest.RestTime;
_schedules.Remove(nextRest);
}
_schedules.Remove(scheduleItem);
_schedules.Insert(Math.Min(index + 1, _schedules.Count), scheduleItem);
}
2024-03-11 07:22:23 +00:00
}
2024-05-17 18:07:56 +00:00
public abstract class ScheduleItemBase
: NotifyPropertyChangedBase
{
}
public class WorkScheduleItem
: ScheduleItemBase
{
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;
}
internal class ScheduleItemTemplateSelector
: DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
var element = container as FrameworkElement;
2024-05-18 18:51:38 +00:00
if (item is WorkScheduleItem workItem)
2024-05-17 18:07:56 +00:00
{
return element.FindResource("WorkScheduleTemplate") as DataTemplate;
}
2024-05-18 18:51:38 +00:00
else if (item is RestScheduleItem restItem)
2024-05-17 18:07:56 +00:00
{
return element.FindResource("RestScheduleTemplate") as DataTemplate;
}
throw new NotImplementedException();
}
}