/
Landilf
/
2413_Ryumin_CourseWork
Обзор
Документация
Войти
/
Landilf
/
2413_Ryumin_CourseWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
CourseWork/GUI/Views/VictoryView.axaml.cs
136 строк
5 KB
Landilf
add project
27 янв 2026, 13:57
27 янв 2026, 13:57
753b3e7
Код
Авторство
О чём код?
using Avalonia; using Avalonia.Controls; using Avalonia.Media; using GUI.ViewModels; using System.Globalization; using GameCore.Resources; using GameCore; namespace GUI.Views; public partial class VictoryView : UserControl { /// <summary> /// Конструктор. /// </summary> public VictoryView() { InitializeComponent(); } /// <summary> /// Обработчик смены DataContext. /// </summary> /// <param name="parEventArgs">Аргументы события.</param> protected override void OnDataContextChanged(EventArgs parEventArgs) { base.OnDataContextChanged(parEventArgs); if (DataContext is VictoryViewModel vm) { vm.PropertyChanged += (s, e) => InvalidateVisual(); } } /// <summary> /// Отрисовывает экран победы. /// </summary> /// <param name="parContext">Контекст рисования.</param> public override void Render(DrawingContext parContext) { base.Render(parContext); if (DataContext is not VictoryViewModel vm) { return; } parContext.DrawRectangle(new SolidColorBrush(Color.Parse(GameConfig.COLOR_MAP_EMPTY)), null, Bounds); double centerX = Bounds.Width / 2; var brush = new SolidColorBrush(Color.Parse("#D93025")); // Подготовка текстов для расчета высоты var title = CreateText(Strings.VictoryTitle, 40, FontWeight.Bold, brush); var timeText = CreateText(string.Format(Strings.VictoryTime, vm.GameTimeStr), 24, FontWeight.Normal, brush); var prompt = CreateText(vm.TopScoreMessage, 20, FontWeight.Normal, brush); var enterHint = CreateText(Strings.PromptEnterName, 14, FontWeight.Normal, brush); var escapeHint = CreateText(Strings.PromptEscapeEdit, 14, FontWeight.Normal, brush); // Расчет общей высоты контента double totalHeight = title.Height + 30 + timeText.Height + 30 + prompt.Height + 40 + 50; if (vm.IsInTop) { totalHeight += 70 + enterHint.Height + escapeHint.Height + 5; // Высота поля ввода + отступ + подсказки } double currentY = (Bounds.Height - totalHeight) / 2; // 1. Заголовок parContext.DrawText(title, new Point(centerX - title.Width / 2, currentY)); currentY += title.Height + 30; // 2. Статистика parContext.DrawText(timeText, new Point(centerX - timeText.Width / 2, currentY)); currentY += timeText.Height + 30; // 3. Сообщение о рекорде parContext.DrawText(prompt, new Point(centerX - prompt.Width / 2, currentY)); currentY += prompt.Height + 20; // 4. Поле ввода и подсказки (только если в топе) if (vm.IsInTop) { var inputRect = new Rect(centerX - 150, currentY, 300, 50); var inputBg = vm.IsTypingName ? Color.Parse("#F4CCCC") : Color.Parse("#EAD1DC"); var inputBorder = vm.IsTypingName ? Color.Parse("#D93025") : Color.Parse("#EA9999"); parContext.DrawRectangle(new SolidColorBrush(inputBg), new Pen(new SolidColorBrush(inputBorder), vm.IsTypingName ? 3 : 1), inputRect); string displayText = vm.Username + (vm.IsTypingName ? "_" : ""); var nameText = CreateText(displayText, 20, FontWeight.Bold, brush); parContext.DrawText(nameText, new Point(centerX - nameText.Width / 2, inputRect.Y + (inputRect.Height - nameText.Height) / 2)); parContext.DrawText(enterHint, new Point(centerX - enterHint.Width / 2, inputRect.Y + 50 + 5)); parContext.DrawText(escapeHint, new Point(centerX - escapeHint.Width / 2, inputRect.Y + 50 + 5 + enterHint.Height + 5)); currentY += 50 + 5 + enterHint.Height + 5 + escapeHint.Height + 40; } else { currentY += 20; } // 5. Кнопки double startX = centerX - (vm.MenuItems.Count * 240 / 2.0); for (int i = 0; i < vm.MenuItems.Count; i++) { var item = vm.MenuItems[i]; bool isSelected = i == vm.SelectedIndex && !vm.IsTypingName; var btnRect = new Rect(startX + i * 240, currentY, 220, 50); if (isSelected) { parContext.DrawRectangle(new SolidColorBrush(Color.Parse("#F4CCCC")), new Pen(new SolidColorBrush(Color.Parse("#EA9999")), 2), btnRect); } else if (!vm.IsTypingName) { parContext.DrawRectangle(null, new Pen(new SolidColorBrush(Color.Parse("#EA9999")), 1), btnRect); } var btnBrush = (vm.IsTypingName) ? new SolidColorBrush(Color.Parse("#A0D93025")) : brush; var btnText = CreateText(item.Title, 20, isSelected ? FontWeight.Bold : FontWeight.Normal, btnBrush); parContext.DrawText(btnText, new Point(btnRect.X + (btnRect.Width - btnText.Width) / 2, btnRect.Y + (btnRect.Height - btnText.Height) / 2)); } } private FormattedText CreateText(string parText, double parSize, FontWeight parWeight, IBrush parBrush) { return new FormattedText(parText ?? "", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial", FontStyle.Normal, parWeight), parSize, parBrush); } }