feat: add view models for all entities
This commit is contained in:
55
Client/Application/ViewModels/ChatMessageViewModel.cs
Normal file
55
Client/Application/ViewModels/ChatMessageViewModel.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
public class ChatMessageViewModel
|
||||
{
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return message.Name + ": " + message.Text;
|
||||
}
|
||||
}
|
||||
|
||||
public SolidColorBrush Color
|
||||
{
|
||||
get
|
||||
{
|
||||
SolidColorBrush? color;
|
||||
if (!colors.TryGetValue(message.Channel, out color))
|
||||
{
|
||||
color = defaultColor;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public ChatMessageViewModel(ChatMessage message)
|
||||
{
|
||||
this.message = message;
|
||||
|
||||
colors = new Dictionary<ChatChannelEnum, SolidColorBrush>
|
||||
{
|
||||
{ ChatChannelEnum.Shout, Brushes.OrangeRed },
|
||||
{ ChatChannelEnum.Tell, Brushes.Magenta },
|
||||
{ ChatChannelEnum.Party, Brushes.LimeGreen },
|
||||
{ ChatChannelEnum.Clan, Brushes.Violet },
|
||||
{ ChatChannelEnum.Gm, Brushes.Red },
|
||||
{ ChatChannelEnum.Trade, Brushes.HotPink }
|
||||
};
|
||||
}
|
||||
|
||||
private readonly ChatMessage message;
|
||||
private readonly Dictionary<ChatChannelEnum, SolidColorBrush> colors;
|
||||
private readonly SolidColorBrush defaultColor = Brushes.Black;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
public interface CreatureListViewModelInterface
|
||||
{
|
||||
uint Id { get; }
|
||||
string Title { get; }
|
||||
string Info { get; }
|
||||
float Distance { get; }
|
||||
float DeltaZ { get; }
|
||||
}
|
||||
}
|
113
Client/Application/ViewModels/DropListViewModel.cs
Normal file
113
Client/Application/ViewModels/DropListViewModel.cs
Normal file
@ -0,0 +1,113 @@
|
||||
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 DropListViewModel : NotifyPropertyChanged
|
||||
{
|
||||
public uint Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return drop.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return drop.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public uint Amount
|
||||
{
|
||||
get
|
||||
{
|
||||
return drop.Amount;
|
||||
}
|
||||
}
|
||||
|
||||
public uint ItemId
|
||||
{
|
||||
get
|
||||
{
|
||||
return drop.ItemId;
|
||||
}
|
||||
}
|
||||
|
||||
public float Distance
|
||||
{
|
||||
get
|
||||
{
|
||||
return drop.Transform.Position.HorizontalDistance(hero.Transform.Position) / 100;
|
||||
}
|
||||
}
|
||||
public float DeltaZ
|
||||
{
|
||||
get
|
||||
{
|
||||
return (drop.Transform.Position.Z - hero.Transform.Position.Z) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
public string IconName
|
||||
{
|
||||
get
|
||||
{
|
||||
return "/Assets/icons/" + drop.IconName + ".png";
|
||||
}
|
||||
}
|
||||
|
||||
public DropListViewModel(Drop drop, Hero hero)
|
||||
{
|
||||
this.drop = drop;
|
||||
this.hero = hero;
|
||||
|
||||
drop.PropertyChanged += Drop_PropertyChanged;
|
||||
drop.Transform.Position.PropertyChanged += DropPosition_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
|
||||
}
|
||||
|
||||
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void DropPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void Drop_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Name")
|
||||
{
|
||||
OnPropertyChanged("Name");
|
||||
}
|
||||
if (e.PropertyName == "Amount")
|
||||
{
|
||||
OnPropertyChanged("Amount");
|
||||
}
|
||||
if (e.PropertyName == "ItemId")
|
||||
{
|
||||
OnPropertyChanged("ItemId");
|
||||
}
|
||||
if (e.PropertyName == "IconName")
|
||||
{
|
||||
OnPropertyChanged("IconName");
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Drop drop;
|
||||
private readonly Hero hero;
|
||||
}
|
||||
}
|
124
Client/Application/ViewModels/HeroSummaryInfoViewModel.cs
Normal file
124
Client/Application/ViewModels/HeroSummaryInfoViewModel.cs
Normal file
@ -0,0 +1,124 @@
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
public class HeroSummaryInfoViewModel : NotifyPropertyChanged
|
||||
{
|
||||
public string Fullname
|
||||
{
|
||||
get
|
||||
{
|
||||
return hero.FullName.Nickname;
|
||||
}
|
||||
}
|
||||
public string Race
|
||||
{
|
||||
get
|
||||
{
|
||||
//toto race string
|
||||
return hero.Phenotype.Race.ToString();
|
||||
}
|
||||
}
|
||||
public string Class
|
||||
{
|
||||
get
|
||||
{
|
||||
//todo class string
|
||||
return hero.Phenotype.Class.ToString();
|
||||
}
|
||||
}
|
||||
public string Level
|
||||
{
|
||||
get
|
||||
{
|
||||
return hero.ExperienceInfo.Level.ToString();
|
||||
}
|
||||
}
|
||||
public Vector3 Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return hero.Transform.Position;
|
||||
}
|
||||
}
|
||||
public ExperienceInfo Experience
|
||||
{
|
||||
get
|
||||
{
|
||||
return hero.ExperienceInfo;
|
||||
}
|
||||
}
|
||||
public HeroSummaryInfoViewModel(Hero hero)
|
||||
{
|
||||
this.hero = hero;
|
||||
|
||||
hero.FullName.PropertyChanged += FullName_PropertyChanged;
|
||||
hero.Phenotype.PropertyChanged += Phenotype_PropertyChanged;
|
||||
hero.ExperienceInfo.PropertyChanged += ExperienceInfo_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += Position_PropertyChanged;
|
||||
}
|
||||
|
||||
private void Position_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Position");
|
||||
}
|
||||
|
||||
private void Phenotype_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Class")
|
||||
{
|
||||
OnPropertyChanged("Class");
|
||||
}
|
||||
if (e.PropertyName == "Race")
|
||||
{
|
||||
OnPropertyChanged("Race");
|
||||
}
|
||||
}
|
||||
|
||||
private void ExperienceInfo_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Level")
|
||||
{
|
||||
OnPropertyChanged("Level");
|
||||
}
|
||||
if (e.PropertyName == "Exp" || e.PropertyName == "ExpToLevel")
|
||||
{
|
||||
OnPropertyChanged("Experience");
|
||||
}
|
||||
}
|
||||
|
||||
private void FullName_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Nickname")
|
||||
{
|
||||
OnPropertyChanged("Fullname");
|
||||
}
|
||||
}
|
||||
|
||||
private void Hero_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Fullname")
|
||||
{
|
||||
OnPropertyChanged("Fullname");
|
||||
}
|
||||
if (e.PropertyName == "Phenotype")
|
||||
{
|
||||
OnPropertyChanged("Class");
|
||||
OnPropertyChanged("Race");
|
||||
}
|
||||
if (e.PropertyName == "ExperienceInfo")
|
||||
{
|
||||
OnPropertyChanged("Level");
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Hero hero;
|
||||
}
|
||||
}
|
101
Client/Application/ViewModels/MainViewModel.cs
Normal file
101
Client/Application/ViewModels/MainViewModel.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using Client.Domain.Common;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.ValueObjects;
|
||||
using Client.Domain.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Application.ViewModels
|
||||
{
|
||||
public class MainViewModel : NotifyPropertyChanged, MainViewModelInterface
|
||||
{
|
||||
|
||||
public void AddChatMessage(ChatMessage chatMessage)
|
||||
{
|
||||
ChatMessages.Add(new ChatMessageViewModel(chatMessage));
|
||||
}
|
||||
|
||||
public void CreateHero(Hero hero)
|
||||
{
|
||||
Hero = new HeroSummaryInfoViewModel(hero);
|
||||
this.hero = hero;
|
||||
OnPropertyChanged("Hero");
|
||||
}
|
||||
public void DeleteHero()
|
||||
{
|
||||
Hero = null;
|
||||
hero = null;
|
||||
OnPropertyChanged("Hero");
|
||||
}
|
||||
|
||||
public void AddNpc(NPC npc)
|
||||
{
|
||||
if (hero != null)
|
||||
{
|
||||
Creatures.Add(new NpcListViewModel(npc, hero));
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveNpc(NPC npc)
|
||||
{
|
||||
foreach (var item in Creatures)
|
||||
{
|
||||
if (item.Id == npc.Id)
|
||||
{
|
||||
Creatures.Remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPlayer(Player player)
|
||||
{
|
||||
if (hero != null)
|
||||
{
|
||||
Creatures.Add(new PlayerListViewModel(player, hero));
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovePlayer(Player player)
|
||||
{
|
||||
foreach (var item in Creatures)
|
||||
{
|
||||
if (item.Id == player.Id)
|
||||
{
|
||||
Creatures.Remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddDrop(Drop drop)
|
||||
{
|
||||
if (hero != null)
|
||||
{
|
||||
Drops.Add(new DropListViewModel(drop, hero));
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveDrop(Drop drop)
|
||||
{
|
||||
foreach (var item in Drops)
|
||||
{
|
||||
if (item.Id == drop.Id)
|
||||
{
|
||||
Drops.Remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<ChatMessageViewModel> ChatMessages { get; } = new ObservableCollection<ChatMessageViewModel>();
|
||||
public ObservableCollection<CreatureListViewModelInterface> Creatures { get; } = new ObservableCollection<CreatureListViewModelInterface>();
|
||||
public ObservableCollection<DropListViewModel> Drops { get; } = new ObservableCollection<DropListViewModel>();
|
||||
public HeroSummaryInfoViewModel? Hero { get; private set; }
|
||||
public Hero? hero;
|
||||
}
|
||||
}
|
107
Client/Application/ViewModels/NpcListViewModel.cs
Normal file
107
Client/Application/ViewModels/NpcListViewModel.cs
Normal file
@ -0,0 +1,107 @@
|
||||
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 NpcListViewModel : NotifyPropertyChanged, CreatureListViewModelInterface
|
||||
{
|
||||
public uint Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return npc.Id;
|
||||
}
|
||||
}
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
string result = "";
|
||||
|
||||
if (npc.IsDead())
|
||||
{
|
||||
result += "Dead ";
|
||||
}
|
||||
result += npc.FullName.Nickname + "[" + npc.NpcId + "]";
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public string Info
|
||||
{
|
||||
get
|
||||
{
|
||||
string result = "Npc";
|
||||
|
||||
if (npc.IsHostile)
|
||||
{
|
||||
result = "Monster";
|
||||
//todo aggr
|
||||
}
|
||||
//todo level
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public float Distance
|
||||
{
|
||||
get
|
||||
{
|
||||
return npc.Transform.Position.HorizontalDistance(hero.Transform.Position) / 100;
|
||||
}
|
||||
}
|
||||
public float DeltaZ
|
||||
{
|
||||
get
|
||||
{
|
||||
return (npc.Transform.Position.Z - hero.Transform.Position.Z) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
public NpcListViewModel(NPC npc, Hero hero)
|
||||
{
|
||||
this.npc = npc;
|
||||
this.hero = hero;
|
||||
|
||||
npc.VitalStats.PropertyChanged += VitalStats_PropertyChanged;
|
||||
npc.FullName.PropertyChanged += FullName_PropertyChanged;
|
||||
npc.Transform.Position.PropertyChanged += NpcPosition_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
|
||||
}
|
||||
|
||||
private void NpcPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void FullName_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Nickname")
|
||||
{
|
||||
OnPropertyChanged("Title");
|
||||
}
|
||||
}
|
||||
|
||||
private void VitalStats_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Hp" || e.PropertyName == "MaxHp")
|
||||
{
|
||||
OnPropertyChanged("Title");
|
||||
}
|
||||
}
|
||||
|
||||
private readonly NPC npc;
|
||||
private readonly Hero hero;
|
||||
}
|
||||
}
|
92
Client/Application/ViewModels/PlayerListViewModel.cs
Normal file
92
Client/Application/ViewModels/PlayerListViewModel.cs
Normal file
@ -0,0 +1,92 @@
|
||||
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 PlayerListViewModel : NotifyPropertyChanged, CreatureListViewModelInterface
|
||||
{
|
||||
public uint Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return player.Id;
|
||||
}
|
||||
}
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return player.FullName.Nickname;
|
||||
}
|
||||
}
|
||||
public string Info
|
||||
{
|
||||
get
|
||||
{
|
||||
//todo race and class strings
|
||||
return player.Phenotype.Race.ToString() + ", " + player.Phenotype.Class.ToString();
|
||||
}
|
||||
}
|
||||
public float Distance
|
||||
{
|
||||
get
|
||||
{
|
||||
return player.Transform.Position.HorizontalDistance(hero.Transform.Position) / 100;
|
||||
}
|
||||
}
|
||||
public float DeltaZ
|
||||
{
|
||||
get
|
||||
{
|
||||
return (player.Transform.Position.Z - hero.Transform.Position.Z) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerListViewModel(Player player, Hero hero)
|
||||
{
|
||||
this.player = player;
|
||||
this.hero = hero;
|
||||
|
||||
player.Phenotype.PropertyChanged += Phenotype_PropertyChanged;
|
||||
player.FullName.PropertyChanged += FullName_PropertyChanged;
|
||||
player.Transform.Position.PropertyChanged += PlayerPosition_PropertyChanged;
|
||||
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
|
||||
}
|
||||
|
||||
private void Phenotype_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Race" || e.PropertyName == "Class")
|
||||
{
|
||||
OnPropertyChanged("Info");
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayerPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void HeroPosition_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged("Distance");
|
||||
OnPropertyChanged("DeltaZ");
|
||||
}
|
||||
|
||||
private void FullName_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Nickname")
|
||||
{
|
||||
OnPropertyChanged("Title");
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Player player;
|
||||
private readonly Hero hero;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user