feat: add skills

This commit is contained in:
k0t9i
2023-02-01 00:30:20 +04:00
parent 823241ef32
commit 32fdef9b1c
13 changed files with 310 additions and 14 deletions

View File

@@ -24,7 +24,9 @@ namespace Client.Application.ViewModels
EventHandlerInterface<CreatureDeletedEvent>,
EventHandlerInterface<DropCreatedEvent>,
EventHandlerInterface<DropDeletedEvent>,
EventHandlerInterface<ChatMessageCreatedEvent>
EventHandlerInterface<ChatMessageCreatedEvent>,
EventHandlerInterface<SkillCreatedEvent>,
EventHandlerInterface<SkillDeletedEvent>
{
public void Handle(HeroCreatedEvent @event)
{
@@ -71,9 +73,32 @@ namespace Client.Application.ViewModels
ChatMessages.Add(new ChatMessageViewModel(@event.Message));
}
public void Handle(SkillCreatedEvent @event)
{
if (hero != null)
{
if (@event.Skill.IsActive)
{
ActiveSkills.Add(new SkillListViewModel(@event.Skill));
}
else
{
PassiveSkills.Add(new SkillListViewModel(@event.Skill));
}
}
}
public void Handle(SkillDeletedEvent @event)
{
ActiveSkills.RemoveAll(x => x.Id == @event.Id);
PassiveSkills.RemoveAll(x => x.Id == @event.Id);
}
public ObservableCollection<ChatMessageViewModel> ChatMessages { get; } = new ObservableCollection<ChatMessageViewModel>();
public ObservableCollection<CreatureListViewModel> Creatures { get; } = new ObservableCollection<CreatureListViewModel>();
public ObservableCollection<DropListViewModel> Drops { get; } = new ObservableCollection<DropListViewModel>();
public ObservableCollection<SkillListViewModel> ActiveSkills { get; } = new ObservableCollection<SkillListViewModel>();
public ObservableCollection<SkillListViewModel> PassiveSkills { get; } = new ObservableCollection<SkillListViewModel>();
public HeroSummaryInfoViewModel? Hero { get; private set; }
public Hero? hero;
}

View File

@@ -0,0 +1,66 @@
using Client.Domain.Common;
using Client.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Application.ViewModels
{
public class SkillListViewModel : ObservableObject
{
public uint Id => skill.Id;
public string Name => skill.Name;
public uint Level => skill.Level;
public string Description=> skill.Description;
public string IconName => "/Assets/icons/" + skill.IconName + ".png";
public bool IsActive => skill.IsActive;
public bool IsReadyToUse => skill.IsReadyToUse;
public bool IsBusy => !skill.IsReadyToUse;
public uint Cost => skill.Cost;
public int Range => skill.Range;
public SkillListViewModel(Skill skill)
{
this.skill = skill;
skill.PropertyChanged += Skill_PropertyChanged;
}
private void Skill_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Description")
{
OnPropertyChanged("Description");
}
if (e.PropertyName == "IsReadyToUse")
{
OnPropertyChanged("IsBusy");
OnPropertyChanged("IsReadyToUse");
}
if (e.PropertyName == "Level")
{
OnPropertyChanged("Level");
}
if (e.PropertyName == "Cost")
{
OnPropertyChanged("Cost");
}
if (e.PropertyName == "Range")
{
OnPropertyChanged("Range");
}
if (e.PropertyName == "Name")
{
OnPropertyChanged("Name");
}
if (e.PropertyName == "IconName")
{
OnPropertyChanged("IconName");
}
}
private readonly Skill skill;
}
}

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:ctrls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
xmlns:converters="clr-namespace:Client.Application.Converters"
xmlns:components="clr-namespace:Client.Application.Components"
mc:Ignorable="d"
@@ -21,11 +22,12 @@
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
<ctrls:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="454"></ColumnDefinition>
<ColumnDefinition Width="444"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
@@ -96,6 +98,86 @@
</Grid>
</TabItem.Content>
</TabItem>
<TabItem>
<TabItem.Header>Skills</TabItem.Header>
<TabItem.Content>
<TabControl>
<TabItem>
<TabItem.Header>Active</TabItem.Header>
<TabItem.Content>
<ItemsControl ItemsSource="{Binding ActiveSkills,Mode=OneWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button IsEnabled="{Binding Path=IsReadyToUse,Mode=OneWay}">
<Button.Content>
<Grid>
<Image Source="{Binding Path=IconName}" Height="32" Width="32" />
<Rectangle Fill="Black" Opacity=".5" Visibility="{Binding Path=IsBusy,Converter={StaticResource BooleanToVisibilityConverter},Mode=OneWay}"/>
</Grid>
</Button.Content>
<Button.ToolTip>
<StackPanel MaxWidth="300">
<TextBlock TextWrapping="Wrap" FontWeight="Bold" FontSize="14" Margin="0,0,0,5">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} Lv {1}">
<Binding Path="Name" Mode="OneWay"/>
<Binding Path="Level" Mode="OneWay"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Cost,Mode=OneWay,StringFormat='MP Cost {0}'}" />
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Range,Mode=OneWay,StringFormat='Range {0}'}" />
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Description,Mode=OneWay}" />
</StackPanel>
</Button.ToolTip>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</TabItem.Content>
</TabItem>
<TabItem>
<TabItem.Header>Passive</TabItem.Header>
<TabItem.Content>
<ItemsControl ItemsSource="{Binding PassiveSkills,Mode=OneWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button IsEnabled="False" ToolTipService.ShowOnDisabled="True">
<Button.Content>
<Image Source="{Binding Path=IconName}" Height="32" Width="32" />
</Button.Content>
<Button.ToolTip>
<StackPanel MaxWidth="300">
<TextBlock TextWrapping="Wrap" FontWeight="Bold" FontSize="14" Margin="0,0,0,5">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} Lv {1}">
<Binding Path="Name" Mode="OneWay"/>
<Binding Path="Level" Mode="OneWay"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Description,Mode=OneWay}" />
</StackPanel>
</Button.ToolTip>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</TabItem.Content>
</TabItem>
</TabControl>
</TabItem.Content>
</TabItem>
</TabControl>
<Grid Grid.Row="1" Grid.Column="1" DataContext="{Binding Hero, Mode=OneWay}" Margin="4" Visibility="{Binding Path=.,Converter={StaticResource NullToVisibilityConverter}}">
<Grid.ColumnDefinitions>
@@ -107,7 +189,7 @@
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel>
<StackPanel Margin="4">
<TextBlock FontSize="16" Text="{Binding Path=Fullname.Nickname, Mode=OneWay}"></TextBlock>
<TextBlock>
<TextBlock.Text>