feat: cleanup in summary info

This commit is contained in:
k0t9i
2023-01-31 01:12:02 +04:00
parent 89cec4f40f
commit ea6778a3bd
4 changed files with 104 additions and 69 deletions

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace Client.Application.Converters
{
public class NullToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? Visibility.Hidden : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -11,34 +11,31 @@ namespace Client.Application.ViewModels
{ {
public class HeroSummaryInfoViewModel : NotifyPropertyChanged public class HeroSummaryInfoViewModel : NotifyPropertyChanged
{ {
public string Fullname public bool IsVisible {
get
{
return true;
}
}
public FullName Fullname
{ {
get get
{ {
return hero.FullName.Nickname; return hero.FullName;
} }
} }
public string Race public Phenotype Phenotype
{ {
get get
{ {
//todo race string return hero.Phenotype;
return hero.Phenotype.Race.ToString();
} }
} }
public string Class public Transform Transform
{ {
get get
{ {
//todo class string return hero.Transform;
return hero.Phenotype.Class.ToString();
}
}
public Vector3 Position
{
get
{
return hero.Transform.Position;
} }
} }
public ExperienceInfo Experience public ExperienceInfo Experience
@@ -55,6 +52,20 @@ namespace Client.Application.ViewModels
return hero.VitalStats; return hero.VitalStats;
} }
} }
public InventoryInfo InventoryInfo
{
get
{
return hero.InventoryInfo;
}
}
public ulong Money
{
get
{
return 0;
}
}
public HeroSummaryInfoViewModel(Hero hero) public HeroSummaryInfoViewModel(Hero hero)
{ {
this.hero = hero; this.hero = hero;
@@ -62,8 +73,14 @@ namespace Client.Application.ViewModels
hero.FullName.PropertyChanged += FullName_PropertyChanged; hero.FullName.PropertyChanged += FullName_PropertyChanged;
hero.Phenotype.PropertyChanged += Phenotype_PropertyChanged; hero.Phenotype.PropertyChanged += Phenotype_PropertyChanged;
hero.ExperienceInfo.PropertyChanged += ExperienceInfo_PropertyChanged; hero.ExperienceInfo.PropertyChanged += ExperienceInfo_PropertyChanged;
hero.Transform.Position.PropertyChanged += Position_PropertyChanged; hero.Transform.PropertyChanged += Transform_PropertyChanged;
hero.VitalStats.PropertyChanged += VitalStats_PropertyChanged; hero.VitalStats.PropertyChanged += VitalStats_PropertyChanged;
hero.InventoryInfo.PropertyChanged += InventoryInfo_PropertyChanged;
}
private void InventoryInfo_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
OnPropertyChanged("InventoryInfo");
} }
private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
@@ -71,38 +88,25 @@ namespace Client.Application.ViewModels
OnPropertyChanged("VitalStats"); OnPropertyChanged("VitalStats");
} }
private void Position_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) private void Transform_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
OnPropertyChanged("Position"); OnPropertyChanged("Transform");
} }
private void Phenotype_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) private void Phenotype_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
if (e.PropertyName == "Class") OnPropertyChanged("Phenotype");
{
OnPropertyChanged("Class");
}
if (e.PropertyName == "Race")
{
OnPropertyChanged("Race");
}
} }
private void ExperienceInfo_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) private void ExperienceInfo_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Exp" || e.PropertyName == "ExpToLevel" || e.PropertyName == "ExpToPrevLevel" || e.PropertyName == "Level")
{ {
OnPropertyChanged("Experience"); OnPropertyChanged("Experience");
} }
}
private void FullName_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) private void FullName_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Nickname")
{ {
OnPropertyChanged("Fullname"); OnPropertyChanged("Fullname");
} }
}
private readonly Hero hero; private readonly Hero hero;
} }

View File

@@ -8,18 +8,19 @@
xmlns:converters="clr-namespace:Client.Application.Converters" xmlns:converters="clr-namespace:Client.Application.Converters"
xmlns:components="clr-namespace:Client.Application.Components" xmlns:components="clr-namespace:Client.Application.Components"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="600" Width="1024"> Title="L2Bot 2.0 Client" Height="600" Width="1024">
<Window.Resources> <Window.Resources>
<CollectionViewSource x:Key="SortedCreatures" Source="{Binding Creatures}" IsLiveSortingRequested="True"> <CollectionViewSource x:Key="SortedCreatures" Source="{Binding Creatures, Mode=OneWay}" IsLiveSortingRequested="True">
<CollectionViewSource.SortDescriptions> <CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Distance" Direction="Ascending" /> <scm:SortDescription PropertyName="Distance" Direction="Ascending" />
</CollectionViewSource.SortDescriptions> </CollectionViewSource.SortDescriptions>
</CollectionViewSource> </CollectionViewSource>
<CollectionViewSource x:Key="SortedDrops" Source="{Binding Drops}" IsLiveSortingRequested="True"> <CollectionViewSource x:Key="SortedDrops" Source="{Binding Drops, Mode=OneWay}" IsLiveSortingRequested="True">
<CollectionViewSource.SortDescriptions> <CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Distance" Direction="Ascending" /> <scm:SortDescription PropertyName="Distance" Direction="Ascending" />
</CollectionViewSource.SortDescriptions> </CollectionViewSource.SortDescriptions>
</CollectionViewSource> </CollectionViewSource>
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
</Window.Resources> </Window.Resources>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@@ -46,17 +47,17 @@
<RowDefinition Height="2*"></RowDefinition> <RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition> <RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<ListBox ItemsSource="{Binding Source={StaticResource SortedCreatures}}" Grid.Row="0"> <ListBox ItemsSource="{Binding Source={StaticResource SortedCreatures}, Mode=OneWay}" Grid.Row="0">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Margin="5"> <StackPanel Margin="5">
<TextBlock FontSize="16" Text="{Binding Path=Title}" /> <TextBlock FontSize="16" Text="{Binding Path=Title,Mode=OneWay}" />
<TextBlock FontSize="11"> <TextBlock FontSize="11">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding StringFormat="{}{0}; distance: {1:F2}m; delta z: {2:F2}m"> <MultiBinding StringFormat="{}{0}; distance: {1:F2}m; delta z: {2:F2}m">
<Binding Path="Info"/> <Binding Path="Info" Mode="OneWay"/>
<Binding Path="Distance"/> <Binding Path="Distance" Mode="OneWay"/>
<Binding Path="DeltaZ"/> <Binding Path="DeltaZ" Mode="OneWay"/>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>
@@ -64,26 +65,26 @@
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
<ListBox ItemsSource="{Binding Source={StaticResource SortedDrops}}" Grid.Row="1"> <ListBox ItemsSource="{Binding Source={StaticResource SortedDrops}, Mode=OneWay}" Grid.Row="1">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<DockPanel> <DockPanel>
<Image DockPanel.Dock="Left" Source="{Binding Path=IconName, FallbackValue=./Assets/icons/_fallback.png}" Height="32" Width="32" /> <Image DockPanel.Dock="Left" Source="{Binding Path=IconName, FallbackValue=./Assets/icons/_fallback.png, Mode=OneWay}" Height="32" Width="32" />
<StackPanel Margin="5"> <StackPanel Margin="5">
<TextBlock FontSize="16"> <TextBlock FontSize="16">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding StringFormat="{}{0}[{1}]"> <MultiBinding StringFormat="{}{0}[{1}]">
<Binding Path="Name"/> <Binding Path="Name" Mode="OneWay"/>
<Binding Path="ItemId"/> <Binding Path="ItemId" Mode="OneWay"/>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>
<TextBlock FontSize="11"> <TextBlock FontSize="11">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding StringFormat="{}Count {0}; distance: {1:F2}m; delta z: {2:F2}m"> <MultiBinding StringFormat="{}Count {0}; distance: {1:F2}m; delta z: {2:F2}m">
<Binding Path="Amount"/> <Binding Path="Amount" Mode="OneWay"/>
<Binding Path="Distance"/> <Binding Path="Distance" Mode="OneWay"/>
<Binding Path="DeltaZ"/> <Binding Path="DeltaZ" Mode="OneWay"/>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>
@@ -96,20 +97,20 @@
</TabItem.Content> </TabItem.Content>
</TabItem> </TabItem>
</TabControl> </TabControl>
<StackPanel Grid.Row="1" Grid.Column="1" DataContext="{Binding Hero, Mode=OneWay}" Margin="4"> <StackPanel Grid.Row="1" Grid.Column="1" DataContext="{Binding Hero, Mode=OneWay}" Margin="4" Visibility="{Binding Path=.,Converter={StaticResource NullToVisibilityConverter}}">
<TextBlock FontSize="16" Text="{Binding Path=Fullname, Mode=OneWay}"></TextBlock> <TextBlock FontSize="16" Text="{Binding Path=Fullname.Nickname, Mode=OneWay}"></TextBlock>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock> <TextBlock>
<TextBlock.Text> <TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1} {2}lvl"> <MultiBinding StringFormat="{}{0}, {1} {2}lvl">
<Binding Path="Race"/> <Binding Path="Phenotype.Race" Mode="OneWay"/>
<Binding Path="Class"/> <Binding Path="Phenotype.Class" Mode="OneWay"/>
<Binding Path="Experience.Level"/> <Binding Path="Experience.Level" Mode="OneWay"/>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
<components:StatsPanel DataContext="{Binding .}" /> <components:StatsPanel DataContext="{Binding ., Mode=OneWay}" Margin="0 5 0 5" />
<DockPanel> <DockPanel>
<StackPanel DockPanel.Dock="Left" Margin="0 0 5 0"> <StackPanel DockPanel.Dock="Left" Margin="0 0 5 0">
<TextBlock Padding="0 0 0 3">Position:</TextBlock> <TextBlock Padding="0 0 0 3">Position:</TextBlock>
@@ -122,34 +123,34 @@
<TextBlock Padding="0 0 0 3"> <TextBlock Padding="0 0 0 3">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding StringFormat="{}{0:F0}, {1:F0}, {2:F0}"> <MultiBinding StringFormat="{}{0:F0}, {1:F0}, {2:F0}">
<Binding Path="Position.X"/> <Binding Path="Transform.Position.X" Mode="OneWay"/>
<Binding Path="Position.Y"/> <Binding Path="Transform.Position.Y" Mode="OneWay"/>
<Binding Path="Position.Z"/> <Binding Path="Transform.Position.Z" Mode="OneWay"/>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>
<TextBlock Padding="0 0 0 3"> <TextBlock Padding="0 0 0 3">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding StringFormat="{}{0}/{1}"> <MultiBinding StringFormat="{}{0}/{1}">
<Binding Path="Experience.Exp"/> <Binding Path="Experience.Exp" Mode="OneWay"/>
<Binding Path="Experience.ExpToLevel"/> <Binding Path="Experience.ExpToLevel" Mode="OneWay"/>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>
<TextBlock Padding="0 0 0 3"> <TextBlock Padding="0 0 0 3">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding StringFormat="{}{0}/{1}"> <MultiBinding StringFormat="{}{0}/{1}">
<Binding Path="Weight.Current"/> <Binding Path="InventoryInfo.Weight" Mode="OneWay"/>
<Binding Path="Weight.Max"/> <Binding Path="InventoryInfo.MaxWeight" Mode="OneWay"/>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>
<TextBlock Text="{Binding Path=Money}" Padding="0 0 0 3"></TextBlock> <TextBlock Text="{Binding Path=Money, Mode=OneWay}" Padding="0 0 0 3"></TextBlock>
<TextBlock Padding="0 0 0 3"> <TextBlock Padding="0 0 0 3">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding StringFormat="{}{0}/{1}"> <MultiBinding StringFormat="{}{0}/{1}">
<Binding Path="Slots.Current"/> <Binding Path="InventoryInfo.Slots" Mode="OneWay"/>
<Binding Path="Slots.Max"/> <Binding Path="InventoryInfo.Slots" Mode="OneWay"/>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>

View File

@@ -1,16 +1,22 @@
namespace Client.Domain.ValueObjects using Client.Domain.Common;
namespace Client.Domain.ValueObjects
{ {
public class InventoryInfo public class InventoryInfo : NotifyPropertyChanged
{ {
public uint MaxWeight { get; set; } private uint maxWeight;
public uint Weight { get; set; } private uint weight;
public uint Slots { get; set; } private uint slots;
public uint MaxWeight { get => maxWeight; set { if (value != maxWeight) { maxWeight = value; OnPropertyChanged("MaxWeight"); } } }
public uint Weight { get => weight; set { if (value != weight) { weight = value; OnPropertyChanged("Weight"); } } }
public uint Slots { get => slots; set { if (value != slots) { slots = value; OnPropertyChanged("Slots"); } } }
public InventoryInfo(uint maxWeight, uint weight, uint slots) public InventoryInfo(uint maxWeight, uint weight, uint slots)
{ {
MaxWeight = maxWeight; this.maxWeight = maxWeight;
Weight = weight; this.weight = weight;
Slots = slots; this.slots = slots;
} }
} }
} }