From a8adf23959f3b195a2b2691f179f1ad599674ac9 Mon Sep 17 00:00:00 2001 From: k0t9i Date: Sun, 29 Jan 2023 23:38:42 +0400 Subject: [PATCH] feat: add hero stats panel --- .../Converters/PercentWidthConverter.cs | 26 ++++++ .../ViewModels/HeroSummaryInfoViewModel.cs | 13 +++ Client/Application/Views/MainWindow.xaml | 82 ++++++++++++++++++- Client/Domain/ValueObjects/ExperienceInfo.cs | 7 ++ Client/Domain/ValueObjects/VitalStats.cs | 22 +++++ 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 Client/Application/Converters/PercentWidthConverter.cs diff --git a/Client/Application/Converters/PercentWidthConverter.cs b/Client/Application/Converters/PercentWidthConverter.cs new file mode 100644 index 0000000..a291255 --- /dev/null +++ b/Client/Application/Converters/PercentWidthConverter.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Client.Application.Converters +{ + public class PercentWidthConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (!(values[0] is double)) + { + return 0.0; + } + return ((double)values[0] / 100 * (Double)values[1]); + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Client/Application/ViewModels/HeroSummaryInfoViewModel.cs b/Client/Application/ViewModels/HeroSummaryInfoViewModel.cs index 9628a13..b26c57f 100644 --- a/Client/Application/ViewModels/HeroSummaryInfoViewModel.cs +++ b/Client/Application/ViewModels/HeroSummaryInfoViewModel.cs @@ -48,6 +48,13 @@ namespace Client.Application.ViewModels return hero.ExperienceInfo; } } + public VitalStats VitalStats + { + get + { + return hero.VitalStats; + } + } public HeroSummaryInfoViewModel(Hero hero) { this.hero = hero; @@ -56,6 +63,12 @@ namespace Client.Application.ViewModels hero.Phenotype.PropertyChanged += Phenotype_PropertyChanged; hero.ExperienceInfo.PropertyChanged += ExperienceInfo_PropertyChanged; hero.Transform.Position.PropertyChanged += Position_PropertyChanged; + hero.VitalStats.PropertyChanged += VitalStats_PropertyChanged; + } + + private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + OnPropertyChanged("VitalStats"); } private void Position_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) diff --git a/Client/Application/Views/MainWindow.xaml b/Client/Application/Views/MainWindow.xaml index e7573ff..80e94ba 100644 --- a/Client/Application/Views/MainWindow.xaml +++ b/Client/Application/Views/MainWindow.xaml @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Client" xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" + xmlns:converters="clr-namespace:Client.Application.Converters" mc:Ignorable="d" Title="MainWindow" Height="600" Width="1024"> @@ -18,6 +19,7 @@ + @@ -28,7 +30,7 @@ - + @@ -107,6 +109,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Position: diff --git a/Client/Domain/ValueObjects/ExperienceInfo.cs b/Client/Domain/ValueObjects/ExperienceInfo.cs index 11b88f1..23b0f87 100644 --- a/Client/Domain/ValueObjects/ExperienceInfo.cs +++ b/Client/Domain/ValueObjects/ExperienceInfo.cs @@ -13,6 +13,13 @@ namespace Client.Domain.ValueObjects public uint Exp { get => exp; set { if (value != exp) { exp = value; OnPropertyChanged("Exp"); } } } public uint Sp { get => sp; set { if (value != sp) { sp = value; OnPropertyChanged("Sp"); } } } public ulong ExpToLevel { get => expToLevel; set { if (value != expToLevel) { expToLevel = value; OnPropertyChanged("ExpToLevel"); } } } + public double ExpPercent + { + get + { + return ExpToLevel != 0 ? Exp / (double) ExpToLevel * 100 : 0; + } + } public ExperienceInfo(uint level, uint exp, uint sp) { diff --git a/Client/Domain/ValueObjects/VitalStats.cs b/Client/Domain/ValueObjects/VitalStats.cs index 5ae82d5..70381d3 100644 --- a/Client/Domain/ValueObjects/VitalStats.cs +++ b/Client/Domain/ValueObjects/VitalStats.cs @@ -18,6 +18,28 @@ namespace Client.Domain.ValueObjects public uint Cp { get => cp; set { if (value != cp) { cp = value; OnPropertyChanged("Cp"); } } } public uint MaxCp { get => maxCp; set { if (value != maxCp) { maxCp = value; OnPropertyChanged("MaxCp"); } } } + public double HpPercent + { + get + { + return maxHp != 0 ? hp / (double)maxHp * 100 : 0; + } + } + public double MpPercent + { + get + { + return maxMp != 0 ? mp / (double)maxMp * 100 : 0; + } + } + public double CpPercent + { + get + { + return maxCp != 0 ? cp / (double)maxCp * 100 : 0; + } + } + public VitalStats(uint hp, uint maxHp, uint mp, uint maxMp, uint cp, uint maxCp) { this.hp = hp;