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

172 lines
5.1 KiB
C#
Raw Normal View History

2023-10-25 15:57:18 +00:00
using LinePutScript.Localization.WPF;
using Panuon.WPF.UI;
2023-10-26 14:31:58 +00:00
using System;
2023-10-25 15:57:18 +00:00
using System.Collections.Generic;
2023-10-26 14:31:58 +00:00
using System.Collections.ObjectModel;
using System.Linq;
2023-01-08 02:59:54 +00:00
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
2023-01-10 10:43:32 +00:00
namespace VPet_Simulator.Windows
2023-01-08 02:59:54 +00:00
{
/// <summary>
/// winCharacterPanel.xaml 的交互逻辑
/// </summary>
public partial class winCharacterPanel : WindowX
{
2023-10-25 15:57:18 +00:00
MainWindow mw;
2023-10-26 14:31:58 +00:00
2023-10-25 15:57:18 +00:00
public winCharacterPanel(MainWindow mw)
2023-01-08 02:59:54 +00:00
{
2023-10-25 15:57:18 +00:00
this.mw = mw;
2023-01-08 02:59:54 +00:00
InitializeComponent();
2023-10-25 15:57:18 +00:00
foreach (var v in mw.GameSavesData.Statistics.Data)
{
2023-10-27 08:43:20 +00:00
StatList.Add(new StatInfo(v.Key, v.Value.GetDouble()));
2023-10-25 15:57:18 +00:00
}
2023-10-26 14:31:58 +00:00
DataGridStatic.ItemsSource = StatList;
2023-10-25 15:57:18 +00:00
}
2023-10-26 14:31:58 +00:00
private ObservableCollection<StatInfo> StatList { get; set; } = new();
private class StatInfo
2023-10-25 15:57:18 +00:00
{
2023-10-27 08:43:20 +00:00
public StatInfo(string statId, double statCount)
2023-10-25 15:57:18 +00:00
{
2023-10-26 14:31:58 +00:00
StatId = statId;
StatCount = statCount;
if (statId.StartsWith("buy_"))
2023-10-25 15:57:18 +00:00
{
2023-10-27 08:43:20 +00:00
StatName = "购买次数".Translate() + '_' + statId.Substring(4).Translate();
}
else if (statId.StartsWith("stat_"))
{
StatName = "统计".Translate() + '_' + statId.Substring(5).Translate();
2023-10-25 15:57:18 +00:00
}
else
{
2023-10-26 14:31:58 +00:00
StatName = statId.Translate();
2023-10-25 15:57:18 +00:00
}
}
/// <summary>
/// 统计ID
/// </summary>
2023-10-26 14:31:58 +00:00
public string StatId { get; set; }
2023-10-25 15:57:18 +00:00
/// <summary>
/// 统计显示名称
/// </summary>
2023-10-26 14:31:58 +00:00
public string StatName { get; set; }
2023-10-25 15:57:18 +00:00
/// <summary>
/// 统计内容
/// </summary>
2023-10-27 08:43:20 +00:00
public double StatCount { get; set; }
2023-01-08 02:59:54 +00:00
}
2023-10-26 14:31:58 +00:00
private void PgbExperience_GeneratingPercentText(
object sender,
GeneratingPercentTextRoutedEventArgs e
)
2023-01-08 02:59:54 +00:00
{
e.Text = $"{e.Value * 10} / {100 * 10}";
}
2023-10-26 14:31:58 +00:00
private void PgbStrength_GeneratingPercentText(
object sender,
GeneratingPercentTextRoutedEventArgs e
)
2023-01-08 02:59:54 +00:00
{
e.Text = $"{e.Value} / 100";
}
2023-10-26 14:31:58 +00:00
private void PgbSpirit_GeneratingPercentText(
object sender,
GeneratingPercentTextRoutedEventArgs e
)
2023-01-08 02:59:54 +00:00
{
var progressBar = (ProgressBar)sender;
progressBar.Foreground = GetForeground(e.Value);
progressBar.BorderBrush = GetForeground(e.Value);
e.Text = $"{e.Value} / 100";
}
2023-10-26 14:31:58 +00:00
private void PgbHunger_GeneratingPercentText(
object sender,
GeneratingPercentTextRoutedEventArgs e
)
2023-01-08 02:59:54 +00:00
{
var progressBar = (ProgressBar)sender;
progressBar.Foreground = GetForeground(e.Value);
progressBar.BorderBrush = GetForeground(e.Value);
e.Text = $"{e.Value} / 100";
}
2023-10-26 14:31:58 +00:00
private void PgbThirsty_GeneratingPercentText(
object sender,
GeneratingPercentTextRoutedEventArgs e
)
2023-01-08 02:59:54 +00:00
{
var progressBar = (ProgressBar)sender;
progressBar.Foreground = GetForeground(e.Value);
progressBar.BorderBrush = GetForeground(e.Value);
e.Text = $"{e.Value} / 100";
2023-10-25 15:57:18 +00:00
if (e.Value <= 20)
2023-01-08 02:59:54 +00:00
{
txtHearth.Visibility = Visibility.Visible;
stkHearth.Visibility = Visibility.Visible;
}
}
2023-10-26 14:31:58 +00:00
private void PgbHearth_GeneratingPercentText(
object sender,
GeneratingPercentTextRoutedEventArgs e
)
2023-01-08 02:59:54 +00:00
{
e.Text = $"{e.Value} / 100";
}
private Brush GetForeground(double value)
{
2023-10-25 15:57:18 +00:00
if (value >= 80)
2023-01-08 02:59:54 +00:00
{
return FindResource("SuccessProgressBarForeground") as Brush;
}
2023-10-25 15:57:18 +00:00
else if (value >= 50)
2023-01-08 02:59:54 +00:00
{
return FindResource("WarningProgressBarForeground") as Brush;
}
else
{
return FindResource("DangerProgressBarForeground") as Brush;
}
}
2023-10-26 14:31:58 +00:00
private void TextBox_Search_TextChanged(object sender, TextChangedEventArgs e)
{
if (sender is not TextBox textBox)
return;
if (string.IsNullOrWhiteSpace(textBox.Text))
{
DataGridStatic.ItemsSource = StatList;
}
else
{
DataGridStatic.ItemsSource = StatList.Where(
i =>
i.StatName.IndexOf(
textBox.Text,
StringComparison.InvariantCultureIgnoreCase
2023-10-27 08:43:20 +00:00
) >= 0 || i.StatId.IndexOf(
textBox.Text,
StringComparison.InvariantCultureIgnoreCase
2023-10-26 14:31:58 +00:00
) >= 0
);
}
}
2023-01-08 02:59:54 +00:00
}
}