/
romashov.z
/
PPAGame
Обзор
Документация
Войти
/
romashov.z
/
PPAGame
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
gameUI-clean
PPAGameUI/ViewModels/UnitViewModel.cs
63 строки
2 KB
Artemiy Ivanov
fix: панель с армией
02 июн 2026, 14:14
02 июн 2026, 14:14
d2ad2a0
Код
Авторство
О чём код?
using System.ComponentModel; using System.Runtime.CompilerServices; using ArmyBattleGame; namespace PPAGameUI.ViewModels; public class UnitViewModel : INotifyPropertyChanged { private readonly IUnit _unit; public bool IsFrontRow { get; } public UnitViewModel(IUnit unit, bool isFrontRow = false) { _unit = unit; IsFrontRow = isFrontRow; } public string Name => _unit.DisplayName; public double Health => _unit.Health; public double MaxHealth => _unit.MaxHealth; public bool IsAlive => _unit.IsAlive; public int Shield => _unit.Shield; public double Damage => _unit.Damage; public double HealthRatio => MaxHealth > 0 ? Health / MaxHealth : 0; public string HpText => $"{Health:F0}/{MaxHealth:F0}"; public string Tooltip => $"{Name}\n" + $"HP: {Health:F0}/{MaxHealth:F0}\n" + $"Урон: {Damage:F0}\n" + $"Щит: {Shield}" + (IsFrontRow ? "\n⚔️ На передовой" : ""); public string Icon => GetIcon(_unit); internal static string GetIcon(IUnit unit) => unit switch { ArcherUnit => "🏹", HealerUnit => "💚", WizardUnit => "🔮", GulyayGorodAdapter => "🏰", BuffedHeavyUnit => "⚔️★", HeavyUnit => "⚔️", LiteUnit => "🗡️", _ => "❓" }; public void Refresh() { OnPropertyChanged(nameof(Health)); OnPropertyChanged(nameof(HealthRatio)); OnPropertyChanged(nameof(HpText)); OnPropertyChanged(nameof(IsAlive)); OnPropertyChanged(nameof(Name)); OnPropertyChanged(nameof(Tooltip)); } public event PropertyChangedEventHandler? PropertyChanged; private void OnPropertyChanged([CallerMemberName] string? name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); }