feat: fix inventory occupied slots

This commit is contained in:
Иванов Иван
2024-08-24 12:35:56 +02:00
parent f50e218013
commit fa078bcead
3 changed files with 27 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ using Client.Domain.Entities;
using Client.Domain.ValueObjects; using Client.Domain.ValueObjects;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -89,10 +90,19 @@ namespace Client.Application.ViewModels
return ai.IsEnabled ? ai.CurrentState.ToString() : "Disabled"; return ai.IsEnabled ? ai.CurrentState.ToString() : "Disabled";
} }
} }
public HeroSummaryInfoViewModel(Hero hero, AIInterface ai) public int InventoryOccupiedSlots
{
get
{
return items.Count + questItems.Count;
}
}
public HeroSummaryInfoViewModel(Hero hero, AIInterface ai, ObservableCollection<ItemListViewModel> items, ObservableCollection<ItemListViewModel> questItems)
{ {
this.hero = hero; this.hero = hero;
this.ai = ai; this.ai = ai;
this.items = items;
this.questItems = questItems;
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;
@@ -101,6 +111,18 @@ namespace Client.Application.ViewModels
hero.InventoryInfo.PropertyChanged += InventoryInfo_PropertyChanged; hero.InventoryInfo.PropertyChanged += InventoryInfo_PropertyChanged;
hero.PropertyChanged += Hero_PropertyChanged; hero.PropertyChanged += Hero_PropertyChanged;
ai.PropertyChanged += Ai_PropertyChanged; ai.PropertyChanged += Ai_PropertyChanged;
items.CollectionChanged += Items_CollectionChanged;
questItems.CollectionChanged += QuestItems_CollectionChanged;
}
private void QuestItems_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged("InventoryOccupiedSlots");
}
private void Items_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged("InventoryOccupiedSlots");
} }
private void Ai_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) private void Ai_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
@@ -169,6 +191,8 @@ namespace Client.Application.ViewModels
private readonly Hero hero; private readonly Hero hero;
private readonly AIInterface ai; private readonly AIInterface ai;
private readonly ObservableCollection<ItemListViewModel> items;
private readonly ObservableCollection<ItemListViewModel> questItems;
private TargetSummaryInfoViewModel? target; private TargetSummaryInfoViewModel? target;
} }
} }

View File

@@ -39,7 +39,7 @@ namespace Client.Application.ViewModels
public void Handle(HeroCreatedEvent @event) public void Handle(HeroCreatedEvent @event)
{ {
Hero = new HeroSummaryInfoViewModel(@event.Hero, ai); Hero = new HeroSummaryInfoViewModel(@event.Hero, ai, Items, QuestItems);
hero = @event.Hero; hero = @event.Hero;
Map.Hero = hero; Map.Hero = hero;
Map.CombatZone = new AICombatZoneMapViewModel(aiConfig.Combat.Zone, hero); Map.CombatZone = new AICombatZoneMapViewModel(aiConfig.Combat.Zone, hero);

View File

@@ -257,7 +257,7 @@
<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="InventoryInfo.Slots" Mode="OneWay"/> <Binding Path="InventoryOccupiedSlots" Mode="OneWay"/>
<Binding Path="InventoryInfo.Slots" Mode="OneWay"/> <Binding Path="InventoryInfo.Slots" Mode="OneWay"/>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>