Danro-Jump/Assets/Scripts/Runtime/UI/Gameplay/ContinueGameOverlayWindow.cs
Danil Iarosh 839a68aef1 Improve VFX, UI overlays, session statistics, COM reliability, audio mixer, and expand architecture guides
Подробный список изменений:
- Перенесены эффекты частиц из C#-кода в готовые префабы-ассеты (Vfx Prefabs) в папке Assets/Resources/Vfx/ с автоматической генерацией материалов в Editor.
- Исправлены ошибки duration на играющих системах частиц и розовые текстуры в GameVfxService.cs.
- Исправлена навигация и фокус кнопок на оверлеях ContinueGameOverlay и PrizeResultOverlay с автоматическим подсвечиванием кнопок лимонно-зеленым цветом при фокусе и проигрыванием звука.
- Добавлена проверка настроек в GameplayHudController.cs для скрытия ContinueGameOverlay, если продолжение игры отключено.
- Расширен сбор статистики: создана структура GameplaySessionRecord, добавлена история до 50 раундов в PrizeSessionStateService и JsonPrizeSessionStateRepository, выведен расчет средних показателей и список 5 последних раундов в сервисной статистике.
- Повышена надежность COM-транспорта: добавлен sleep (80мс) в Dispose для graceful shutdown потоков, реализован цикл переподключения до 10 попыток при обрыве связи.
- Интегрированы настройки громкости с микшером: изменен шаг изменения громкости на 5% (0.05) для удобства, добавлен статус-чек и логи в ApplyServiceVolumes, расширены юнит-тесты на GetFloat параметры.
- Созданы новые архитектурные гайды по аппаратному COM-транспорту и призовой экономике автомата в папке GUIDES/architecture/.
- Оптимизирован и обновлен RAG-индекс проекта.
2026-07-03 15:04:08 +03:00

183 lines
5.6 KiB
C#

using System;
using UnityEngine;
using UnityEngine.UIElements;
using DanroJump.Audio;
namespace DanroJump.UI.Gameplay
{
/// <summary>
/// Полноэкранное предложение продолжить забег за баланс.
/// </summary>
public sealed class ContinueGameOverlayWindow : IDisposable
{
private const float OpenInputGuardSeconds = 0.45f;
private readonly VisualElement root;
private readonly Label titleLabel;
private readonly Label detailsLabel;
private readonly Button continueButton;
private readonly Button menuButton;
private readonly IGameAudioService audioService;
private float inputEnabledAtTime = float.NegativeInfinity;
public ContinueGameOverlayWindow(VisualElement root, IGameAudioService audioService = null)
{
this.root = root;
this.audioService = audioService;
titleLabel = root?.Q<Label>("ContinueGameTitle");
detailsLabel = root?.Q<Label>("ContinueGameDetails");
continueButton = root?.Q<Button>("ContinueGameButton");
menuButton = root?.Q<Button>("ContinueMenuButton");
if (continueButton != null)
{
continueButton.clicked += HandleContinueClicked;
continueButton.RegisterCallback<FocusInEvent>(HandleButtonFocusIn);
continueButton.RegisterCallback<FocusOutEvent>(HandleButtonFocusOut);
}
if (menuButton != null)
{
menuButton.clicked += HandleMenuClicked;
menuButton.RegisterCallback<FocusInEvent>(HandleButtonFocusIn);
menuButton.RegisterCallback<FocusOutEvent>(HandleButtonFocusOut);
}
}
public event Action ContinueRequested;
public event Action MenuRequested;
public bool IsOpen { get; private set; }
public void SetOffer(int cost, int lives)
{
SetLabel(titleLabel, "Продолжить игру?");
SetLabel(detailsLabel, $"Стоимость: {Math.Max(0, cost)}. Дополнительные жизни: {Math.Max(1, lives)}.");
if (continueButton != null)
{
continueButton.SetEnabled(true);
}
}
public void SetUnavailable()
{
SetLabel(titleLabel, "Игра окончена");
SetLabel(detailsLabel, "Недостаточно баланса или функция отключена в сервисных настройках.");
if (continueButton != null)
{
continueButton.SetEnabled(false);
}
}
public void Open()
{
if (root == null)
{
return;
}
root.style.display = DisplayStyle.Flex;
root.SetEnabled(true);
IsOpen = true;
inputEnabledAtTime = Time.unscaledTime + OpenInputGuardSeconds;
FocusDefaultButton();
}
private void FocusDefaultButton()
{
if (continueButton != null && continueButton.enabledSelf)
{
continueButton.Focus();
}
else if (menuButton != null)
{
menuButton.Focus();
}
}
public void Close()
{
if (root == null)
{
return;
}
root.style.display = DisplayStyle.None;
root.SetEnabled(false);
IsOpen = false;
}
public void Dispose()
{
if (continueButton != null)
{
continueButton.clicked -= HandleContinueClicked;
continueButton.UnregisterCallback<FocusInEvent>(HandleButtonFocusIn);
continueButton.UnregisterCallback<FocusOutEvent>(HandleButtonFocusOut);
}
if (menuButton != null)
{
menuButton.clicked -= HandleMenuClicked;
menuButton.UnregisterCallback<FocusInEvent>(HandleButtonFocusIn);
menuButton.UnregisterCallback<FocusOutEvent>(HandleButtonFocusOut);
}
}
private static readonly Color FocusedButtonTint = new Color32(0xCE, 0xFF, 0x1A, 0xFF);
private static readonly Color NormalButtonTint = Color.white;
private void HandleButtonFocusIn(FocusInEvent evt)
{
if (evt.currentTarget is Button button)
{
audioService?.Play(GameAudioEvent.UiNavigate);
button.style.unityBackgroundImageTintColor = new StyleColor(FocusedButtonTint);
}
}
private void HandleButtonFocusOut(FocusOutEvent evt)
{
if (evt.currentTarget is Button button)
{
button.style.unityBackgroundImageTintColor = new StyleColor(NormalButtonTint);
}
}
private static void SetLabel(Label label, string value)
{
if (label != null)
{
label.text = value;
}
}
private void HandleContinueClicked()
{
if (IsInputGuardActive())
{
return;
}
ContinueRequested?.Invoke();
}
private void HandleMenuClicked()
{
if (IsInputGuardActive())
{
return;
}
MenuRequested?.Invoke();
}
private bool IsInputGuardActive()
{
return Time.unscaledTime < inputEnabledAtTime;
}
}
}