feat: add hero stats panel

This commit is contained in:
k0t9i 2023-01-29 23:38:42 +04:00
parent f8b0b4b894
commit a8adf23959
5 changed files with 149 additions and 1 deletions

View File

@ -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();
}
}
}

View File

@ -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)

View File

@ -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">
<Window.Resources>
@ -18,6 +19,7 @@
<scm:SortDescription PropertyName="Distance" Direction="Ascending" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
<converters:PercentWidthConverter x:Key="PercentWidthConverter"/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
@ -28,7 +30,7 @@
<RowDefinition></RowDefinition>
<RowDefinition Height="240"></RowDefinition>
</Grid.RowDefinitions>
<ListBox Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ChatMessages, Mode=OneWay}">
<ListBox x:Name="listBox" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ChatMessages, Mode=OneWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Text, Mode=OneWay}" Foreground="{Binding Path=Color, Mode=OneWay}" />
@ -107,6 +109,84 @@
</TextBlock.Text>
</TextBlock>
</StackPanel>
<StackPanel x:Name="statsPanel">
<Grid Height="15" Margin="0 0 0 2">
<Image Stretch="Fill" Source="/Assets/icons/ps_cpbar_back.png"></Image>
<Image Stretch="Fill" Source="/Assets/icons/ps_cpbar.png" HorizontalAlignment="Left">
<Image.Width>
<MultiBinding Converter="{StaticResource PercentWidthConverter}">
<Binding Path="VitalStats.CpPercent"/>
<Binding Path="ActualWidth" ElementName="statsPanel"/>
</MultiBinding>
</Image.Width>
</Image>
<TextBlock Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}/{1}">
<Binding Path="VitalStats.Cp"/>
<Binding Path="VitalStats.MaxCp"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
<Grid Height="15" Margin="0 0 0 2">
<Image Stretch="Fill" Source="/Assets/icons/ps_hpbar_back.png"></Image>
<Image Stretch="Fill" Source="/Assets/icons/ps_hpbar.png" HorizontalAlignment="Left">
<Image.Width>
<MultiBinding Converter="{StaticResource PercentWidthConverter}">
<Binding Path="VitalStats.HpPercent"/>
<Binding Path="ActualWidth" ElementName="statsPanel"/>
</MultiBinding>
</Image.Width>
</Image>
<TextBlock Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}/{1}">
<Binding Path="VitalStats.Hp"/>
<Binding Path="VitalStats.MaxHp"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
<Grid Height="15" Margin="0 0 0 2">
<Image Stretch="Fill" Source="/Assets/icons/ps_mpbar_back.png"></Image>
<Image Stretch="Fill" Source="/Assets/icons/ps_mpbar.png" HorizontalAlignment="Left">
<Image.Width>
<MultiBinding Converter="{StaticResource PercentWidthConverter}">
<Binding Path="VitalStats.MpPercent"/>
<Binding Path="ActualWidth" ElementName="statsPanel"/>
</MultiBinding>
</Image.Width>
</Image>
<TextBlock Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}/{1}">
<Binding Path="VitalStats.Mp"/>
<Binding Path="VitalStats.MaxMp"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
<Grid Height="15">
<Grid.ColumnDefinitions></Grid.ColumnDefinitions>
<Image Stretch="Fill" Source="/Assets/icons/ps_expbar_back.png"></Image>
<Image Stretch="Fill" Source="/Assets/icons/ps_expbar.png" HorizontalAlignment="Left">
<Image.Width>
<MultiBinding Converter="{StaticResource PercentWidthConverter}">
<Binding Path="Experience.ExpPercent"/>
<Binding Path="ActualWidth" ElementName="statsPanel"/>
</MultiBinding>
</Image.Width>
</Image>
<TextBlock Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:F2}%">
<Binding Path="Experience.ExpPercent"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
</StackPanel>
<DockPanel>
<StackPanel DockPanel.Dock="Left" Margin="0 0 5 0">
<TextBlock Padding="0 0 0 3">Position:</TextBlock>

View File

@ -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)
{

View File

@ -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;