/
romashov.z
/
PPAGame
Обзор
Документация
Войти
/
romashov.z
/
PPAGame
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
gameUI-clean
PPAGameUI/Converters/HealthToColorConverter.cs
61 строка
3 KB
Artemiy Ivanov
PPAGame + PPAGameUI Avalonia UI
02 июн 2026, 13:42
02 июн 2026, 13:42
c122c02
Код
Авторство
О чём код?
using Avalonia.Data.Converters; using Avalonia.Media; using System; using System.Globalization; namespace PPAGameUI.Converters; public class HealthToColorConverter : IValueConverter { public static readonly HealthToColorConverter Instance = new(); public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is double ratio) { if (ratio > 0.6) return new SolidColorBrush(Color.Parse("#4CAF50")); if (ratio > 0.3) return new SolidColorBrush(Color.Parse("#FF9800")); return new SolidColorBrush(Color.Parse("#F44336")); } return new SolidColorBrush(Colors.Gray); } public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } public class AliveToOpacityConverter : IValueConverter { public static readonly AliveToOpacityConverter Instance = new(); public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value is bool alive && alive ? 1.0 : 0.35; public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } // Цвет строки лога по первому символу (эмодзи-префиксу) public class LogEntryColorConverter : IValueConverter { public static readonly LogEntryColorConverter Instance = new(); public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is string text) { if (text.StartsWith("⚔️")) return "#F38BA8"; // атака — красный if (text.StartsWith("🏹")) return "#FAB387"; // лучник — оранжевый if (text.StartsWith("💀")) return "#585B70"; // смерть — серый if (text.StartsWith("💚")) return "#A6E3A1"; // лечение — зелёный if (text.StartsWith("🔮")) return "#CBA6F7"; // маг — фиолетовый if (text.StartsWith("🗡️")) return "#F9E2AF"; // оруженосец — жёлтый if (text.StartsWith("===")) return "#CDD6F4"; // заголовок хода — белый if (text.StartsWith("🏆") || text.StartsWith("🤝")) return "#A6E3A1"; } return "#6C7086"; } public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); }