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

266 lines
8.9 KiB
C#
Raw Normal View History

2024-03-14 11:31:34 +00:00
using LinePutScript.Localization.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-03-11 07:22:23 +00:00
using System.Windows;
using System.Windows.Controls;
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-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-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-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-03-27 16:45:14 +00:00
switch (LsbCategory.SelectedIndex)
{
case 0:
detailTypes.ItemsSource = _workDetails;
btnStart.Content = "开始工作".Translate();
break;
case 1:
detailTypes.ItemsSource = _studyDetails;
btnStart.Content = "开始学习".Translate();
break;
case 2:
detailTypes.ItemsSource = _playDetails;
btnStart.Content = "开始玩耍".Translate();
break;
case 3:
detailTypes.ItemsSource = _starDetails;
btnStart.Content = "开始工作".Translate();
break;
2024-05-17 05:20:08 +00:00
case 4:
gdWork.Visibility = Visibility.Collapsed;
return;
2024-03-27 16:45:14 +00:00
}
2024-05-17 05:20:08 +00:00
gdWork.Visibility = Visibility.Visible;
2024-03-29 13:03:21 +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
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-03-11 07:22:23 +00:00
}