/
puma
/
ppa
Обзор
Документация
Войти
/
puma
/
ppa
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
EtoUI/UnitCardFactory.cs
106 строк
3 KB
Margarita
Добавить EtoUI: GUI на Eto.Forms с полем боя, светлой темой и картинками юнитов
11 май 2026, 22:02
11 май 2026, 22:02
c948d85
Код
Авторство
О чём код?
using System; using Eto.Forms; using Eto.Drawing; public static class UnitCardFactory { public static Eto.Forms.Control CreateUnitCard( IUnit unit, bool isSelected = false) { if (unit == null) throw new ArgumentNullException(nameof(unit)); Eto.Drawing.Image image; string imagePath = UnitImageProvider.GetImagePath(unit); try { if (!System.IO.File.Exists(imagePath)) { imagePath = UnitImageProvider.GetDefaultImagePath(); } image = new Eto.Drawing.Bitmap(imagePath); } catch { image = new Eto.Drawing.Bitmap(64, 64, Eto.Drawing.PixelFormat.Format32bppRgba); } var imageView = new Eto.Forms.ImageView { Image = image, Size = new Eto.Drawing.Size(64, 64) }; var descriptionLabel = new Eto.Forms.Label { Text = BuildUnitDescription(unit), Wrap = Eto.Forms.WrapMode.Word, TextAlignment = Eto.Forms.TextAlignment.Center }; var cardLayout = new Eto.Forms.StackLayout { Spacing = 4, HorizontalContentAlignment = Eto.Forms.HorizontalAlignment.Center, Items = { imageView, descriptionLabel } }; var cardPanel = new Eto.Forms.Panel { Padding = new Eto.Drawing.Padding(6), Size = new Eto.Drawing.Size(150, 250), Content = cardLayout, BackgroundColor = isSelected ? Eto.Drawing.Color.FromArgb(173, 216, 230) : Eto.Drawing.Color.FromArgb(235, 235, 235) }; return cardPanel; } public static string BuildUnitDescription(IUnit unit) { if (unit == null) throw new ArgumentNullException(nameof(unit)); var lines = new System.Collections.Generic.List<string> { unit.Name, $"HP: {unit.MaxHealth}", $"ATK: {unit.Attack}", $"DEF: {unit.Defense}", $"COST: {unit.Cost}" }; if (unit.SpecialAbility is ArrowAbility arrowAbility) { lines.Add("Skill: Arrow"); lines.Add($"Range: {arrowAbility.Range}"); lines.Add($"Power: {arrowAbility.Power}"); } else if (unit.SpecialAbility is HealAbility healAbility) { lines.Add("Skill: Heal"); lines.Add($"Range: {healAbility.Range}"); lines.Add($"Heal: {healAbility.HealPower}"); } else if (unit.SpecialAbility is CloneAbility cloneAbility) { lines.Add("Skill: Clone"); lines.Add($"Range: {cloneAbility.Range}"); lines.Add($"Chance: {cloneAbility.CloneProbability}%"); } else { lines.Add("Skill: None"); } return string.Join(Environment.NewLine, lines); } }