统计面板支持跟随数据实时更新

This commit is contained in:
ZouJin 2023-10-31 14:02:38 +08:00
parent 5622ef495c
commit b11c5b736f
2 changed files with 41 additions and 3 deletions

View File

@ -6,7 +6,8 @@
xmlns:local="clr-namespace:VPet_Simulator.Windows"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Title="{ll:Str 面板}" Width="500" Height="500"
Style="{DynamicResource BaseWindowXStyle}" WindowStartupLocation="CenterScreen" mc:Ignorable="d">
Style="{DynamicResource BaseWindowXStyle}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"
Closed="WindowX_Closed">
<Window.Resources>
<Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Center" />

View File

@ -3,6 +3,7 @@ using Panuon.WPF.UI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
@ -27,11 +28,25 @@ namespace VPet_Simulator.Windows
StatList.Add(new StatInfo(v.Key, v.Value.GetDouble()));
}
DataGridStatic.ItemsSource = StatList;
mw.GameSavesData.Statistics.StatisticChanged += Statistics_StatisticChanged;
}
private void Statistics_StatisticChanged(Interface.Statistics sender, string name, LinePutScript.SetObject value)
{
var v = StatList.FirstOrDefault(x => x.StatId == name);
if (v != null)
{
v.StatCount = value.GetDouble();
}
else
{
StatList.Add(new StatInfo(name, value.GetDouble()));
}
}
private ObservableCollection<StatInfo> StatList { get; set; } = new();
private class StatInfo
private class StatInfo : INotifyPropertyChanged
{
public StatInfo(string statId, double statCount)
{
@ -61,10 +76,27 @@ namespace VPet_Simulator.Windows
/// </summary>
public string StatName { get; set; }
private double _statCount;
/// <summary>
/// 统计内容
/// </summary>
public double StatCount { get; set; }
public double StatCount
{
get { return _statCount; }
set
{
if (_statCount != value)
{
_statCount = value;
OnPropertyChanged(nameof(StatCount));
}
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
private void PgbExperience_GeneratingPercentText(
@ -167,5 +199,10 @@ namespace VPet_Simulator.Windows
);
}
}
private void WindowX_Closed(object sender, EventArgs e)
{
mw.GameSavesData.Statistics.StatisticChanged -= Statistics_StatisticChanged;
}
}
}