Update
This commit is contained in:
76
Assets/Scripts/UI/PauseMenuController.cs
Normal file
76
Assets/Scripts/UI/PauseMenuController.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using UnityEngine.UIElements;
|
||||
using System.Threading.Tasks;
|
||||
using OnlyScove.Scripts;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Hallucinate.UI
|
||||
{
|
||||
public class PauseMenuController : BaseUIController
|
||||
{
|
||||
private Button _resumeBtn;
|
||||
private Button _quitBtn;
|
||||
|
||||
public override void Initialize(VisualElement uxmlRoot, UIManager manager)
|
||||
{
|
||||
base.Initialize(uxmlRoot, manager);
|
||||
|
||||
_resumeBtn = root.Q<Button>("ResumeBtn");
|
||||
_quitBtn = root.Q<Button>("QuitBtn");
|
||||
|
||||
if (_resumeBtn != null) _resumeBtn.clicked += OnResumeClicked;
|
||||
if (_quitBtn != null) _quitBtn.clicked += OnQuitClicked;
|
||||
|
||||
ApplyLocalization();
|
||||
if (LocalizationManager.Instance != null)
|
||||
LocalizationManager.Instance.OnLanguageChanged += ApplyLocalization;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (LocalizationManager.Instance != null)
|
||||
LocalizationManager.Instance.OnLanguageChanged -= ApplyLocalization;
|
||||
}
|
||||
|
||||
private void ApplyLocalization()
|
||||
{
|
||||
if (_resumeBtn != null) _resumeBtn.text = GetLoc("PAUSE_RESUME");
|
||||
if (_quitBtn != null) _quitBtn.text = GetLoc("PAUSE_QUIT");
|
||||
|
||||
var title = root.Q<Label>("PauseTitle");
|
||||
if (title != null) title.text = GetLoc("PAUSE_TITLE");
|
||||
}
|
||||
|
||||
private void OnResumeClicked()
|
||||
{
|
||||
uiManager.TogglePauseMenu();
|
||||
}
|
||||
|
||||
private void OnQuitClicked()
|
||||
{
|
||||
Debug.Log("[PauseMenu] Quit clicked - shutting down runner.");
|
||||
if (BasicSpawner.Instance != null && BasicSpawner.Instance.Runner != null)
|
||||
{
|
||||
BasicSpawner.Instance.Runner.Shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
uiManager.OnBackToMenu();
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task PlayTransitionIn()
|
||||
{
|
||||
Show();
|
||||
root.style.opacity = 0;
|
||||
PrimeTween.Tween.Custom(0f, 1f, duration: 0.2f, onValueChange: val => root.style.opacity = val);
|
||||
await Task.Delay(200);
|
||||
}
|
||||
|
||||
public override async Task PlayTransitionOut()
|
||||
{
|
||||
PrimeTween.Tween.Custom(1f, 0f, duration: 0.2f, onValueChange: val => root.style.opacity = val);
|
||||
await Task.Delay(200);
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user