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

187 lines
5.6 KiB
C#
Raw Normal View History

2024-03-14 11:31:34 +00:00
using LinePutScript.Localization.WPF;
using System;
2024-03-11 07:22:23 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
2024-03-14 11:31:34 +00:00
using VPet_Simulator.Core;
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>
public partial class winWorkMenu : Window
{
2024-03-12 16:38:23 +00:00
MainWindow mw;
List<Work> ws;
List<Work> ss;
List<Work> ps;
2024-03-21 15:40:37 +00:00
public void ShowImageDefault(Work.WorkType type) => WorkViewImage.Source = mw.ImageSources.FindImage("work_" + mw.Set.PetGraph + "_t_" + type.ToString(), "work_" + type.ToString());
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)
tbc.Items.Remove(tiw);
else
foreach (var v in ws)
{
lbWork.Items.Add(v.NameTrans);
}
if (ss.Count == 0)
tbc.Items.Remove(tis);
else
foreach (var v in ss)
{
lbStudy.Items.Add(v.NameTrans);
}
if (ps.Count == 0)
tbc.Items.Remove(tip);
else
foreach (var v in ps)
{
lbPlay.Items.Add(v.NameTrans);
}
2024-03-12 16:38:23 +00:00
2024-03-14 11:31:34 +00:00
tbc.SelectedIndex = (int)type;
2024-03-15 05:18:05 +00:00
ShowImageDefault(type);
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;
wDouble.Value = mw.Set.GameData.GetInt("workmenu_" + 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-03-15 05:18:05 +00:00
nowworkdisplay = work;
2024-03-14 11:31:34 +00:00
lName.Content = work.NameTrans;
//显示图像
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
StringBuilder sb = new StringBuilder();
if (work.Type == Work.WorkType.Work)
sb.AppendLine("金钱".Translate());
else
sb.AppendLine("经验".Translate());
sb.AppendLine(work.Get().ToString("f2"));
sb.AppendLine(work.StrengthFood.ToString("f2"));
sb.AppendLine(work.StrengthDrink.ToString("f2"));
sb.AppendLine(work.Feeling.ToString("f2"));
sb.AppendLine(work.LevelLimit.ToString("f0"));
if (work.Time > 100)
sb.AppendLine((work.Time / 60).ToString("f2") + 'h');
else
sb.AppendLine(work.Time.ToString() + 'm');
sb.AppendLine('x' + (1 + work.FinishBonus).ToString("f2"));
sb.AppendLine('x' + wDouble.Value.ToString("f0"));
tbDisplay.Text = sb.ToString();
}
private void tbc_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
2024-03-15 05:18:05 +00:00
ShowImageDefault((Work.WorkType)tbc.SelectedIndex);
2024-03-14 11:31:34 +00:00
switch (tbc.SelectedIndex)
{
case 0:
btnStart.Content = "开始工作".Translate();
break;
case 1:
btnStart.Content = "开始学习".Translate();
break;
case 2:
btnStart.Content = "开始玩耍".Translate();
break;
}
}
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;
mw.Set.GameData.SetInt("workmenu_" + nowwork.Name, (int)wDouble.Value);
2024-03-14 11:31:34 +00:00
ShowWork(nowwork.Double((int)wDouble.Value));
}
private void lbWork_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
nowwork = (ws[lbWork.SelectedIndex]);
ShowWork();
2024-03-21 08:44:07 +00:00
e.Handled = true;
2024-03-14 11:31:34 +00:00
}
private void lbStudy_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
nowwork = (ss[lbStudy.SelectedIndex]);
ShowWork();
2024-03-21 08:44:07 +00:00
e.Handled = true;
2024-03-14 11:31:34 +00:00
}
private void lbPlay_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
nowwork = (ps[lbPlay.SelectedIndex]);
ShowWork();
2024-03-21 08:44:07 +00:00
e.Handled = true;
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-11 07:22:23 +00:00
}