Update Correctly run UI

This commit is contained in:
2026-04-28 10:21:28 +07:00
parent 6d5a9a4e5b
commit ad03c1fefa
5 changed files with 31 additions and 36 deletions

View File

@@ -15,20 +15,25 @@ namespace Hallucinate.UI
root = uxmlRoot;
uiManager = manager;
// Default to hidden
// Đảm bảo ban đầu ẩn hết
Hide();
}
public virtual void Show()
{
if (root != null)
{
root.style.display = DisplayStyle.Flex;
root.style.opacity = 1;
}
}
public virtual void Hide()
{
if (root != null)
{
root.style.display = DisplayStyle.None;
}
}
public virtual async Task PlayTransitionIn()
@@ -36,8 +41,9 @@ namespace Hallucinate.UI
if (root == null) return;
Show();
// Fly-in from right using Custom tween for style.translate
// Reset vị trí mặc định để tránh lỗi trôi màn hình
root.style.translate = new StyleTranslate(new Translate(Length.Percent(100), 0));
await Tween.Custom(100f, 0f, duration: 0.5f, ease: Ease.OutBack,
onValueChange: val => root.style.translate = new StyleTranslate(new Translate(Length.Percent(val), 0)));
}
@@ -46,9 +52,9 @@ namespace Hallucinate.UI
{
if (root == null) return;
// Fly-out to left
await Tween.Custom(0f, -100f, duration: 0.5f, ease: Ease.InBack,
onValueChange: val => root.style.translate = new StyleTranslate(new Translate(Length.Percent(val), 0)));
Hide();
}
}

View File

@@ -78,8 +78,8 @@ namespace Hallucinate.UI
public override async Task PlayTransitionIn()
{
if (root != null) root.style.translate = new StyleTranslate(new Translate(0, 0));
Show();
// Đảm bảo chuột hệ thống luôn hiện
UnityEngine.Cursor.visible = true;
await Task.CompletedTask;
}

View File

@@ -36,6 +36,7 @@ namespace Hallucinate.UI
public override async Task PlayTransitionIn()
{
if (root != null) root.style.translate = new StyleTranslate(new Translate(0, 0));
Show();
_sidebar.style.translate = new StyleTranslate(new Translate(Length.Percent(-100), 0));
await Tween.Custom(-100f, 0f, duration: 0.4f, ease: Ease.OutQuad,

View File

@@ -30,14 +30,7 @@ namespace Hallucinate.UI
[SerializeField] private VisualTreeAsset settingsTemplate;
[SerializeField] private VisualTreeAsset hudTemplate;
[Header("Debug Settings")]
[SerializeField] private bool showDebugInfo = true;
private MainMenuController _mainMenuController;
private LobbyController _lobbyController;
private ProfileController _profileController;
private SettingsController _settingsController;
private HUDController _hudController;
private void Awake()
{
@@ -74,28 +67,25 @@ namespace Hallucinate.UI
_mainMenuController.SetGameIcon(gameIcon);
}
_lobbyController = RegisterController<LobbyController>(lobbyTemplate);
_profileController = RegisterController<ProfileController>(profileTemplate);
_settingsController = RegisterController<SettingsController>(settingsTemplate);
_hudController = RegisterController<HUDController>(hudTemplate);
RegisterController<LobbyController>(lobbyTemplate);
RegisterController<ProfileController>(profileTemplate);
RegisterController<SettingsController>(settingsTemplate);
RegisterController<HUDController>(hudTemplate);
// Start with Main Menu
// Khởi động màn hình đầu tiên
_ = Push<MainMenuController>();
}
private T RegisterController<T>(VisualTreeAsset template) where T : BaseUIController, new()
{
if (template == null)
{
Debug.LogWarning($"Template for {typeof(T).Name} is missing!");
return null;
}
if (template == null) return null;
var instance = template.Instantiate();
instance.style.flexGrow = 1;
instance.style.position = Position.Absolute;
instance.style.width = Length.Percent(100);
instance.style.height = Length.Percent(100);
instance.style.display = DisplayStyle.None; // Ẩn mặc định
_rootElement.Add(instance);
var controller = new T();
@@ -108,16 +98,15 @@ namespace Hallucinate.UI
private void Update()
{
_mainMenuController?.Update();
_hudController?.Update();
// Update các controller khác nếu cần
}
public async Task Push<T>() where T : BaseUIController
{
if (!_controllers.TryGetValue(typeof(T), out var newScreen))
{
Debug.LogError($"Controller of type {typeof(T)} not registered!");
return;
}
if (!_controllers.TryGetValue(typeof(T), out var newScreen)) return;
// Nếu màn hình mới chính là màn hình đang hiện, không làm gì cả
if (_history.Count > 0 && _history.Peek() == newScreen) return;
if (_history.Count > 0)
{
@@ -136,8 +125,11 @@ namespace Hallucinate.UI
var currentScreen = _history.Pop();
await currentScreen.PlayTransitionOut();
var previousScreen = _history.Peek();
await previousScreen.PlayTransitionIn();
if (_history.Count > 0)
{
var previousScreen = _history.Peek();
await previousScreen.PlayTransitionIn();
}
}
}
}