diff --git a/.idea/.idea.HALLUCINATE/.idea/workspace.xml b/.idea/.idea.HALLUCINATE/.idea/workspace.xml
index ab4766c0..cbb4222c 100644
--- a/.idea/.idea.HALLUCINATE/.idea/workspace.xml
+++ b/.idea/.idea.HALLUCINATE/.idea/workspace.xml
@@ -5,14 +5,10 @@
-
-
+
+
-
-
-
-
@@ -149,7 +145,7 @@
-
+
diff --git a/Assets/Scripts/UI/BaseUIController.cs b/Assets/Scripts/UI/BaseUIController.cs
index ad14c5f4..e375fa01 100644
--- a/Assets/Scripts/UI/BaseUIController.cs
+++ b/Assets/Scripts/UI/BaseUIController.cs
@@ -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();
}
}
diff --git a/Assets/Scripts/UI/MainMenuController.cs b/Assets/Scripts/UI/MainMenuController.cs
index 064300a5..16129d53 100644
--- a/Assets/Scripts/UI/MainMenuController.cs
+++ b/Assets/Scripts/UI/MainMenuController.cs
@@ -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;
}
diff --git a/Assets/Scripts/UI/SettingsController.cs b/Assets/Scripts/UI/SettingsController.cs
index 410f999b..d5491838 100644
--- a/Assets/Scripts/UI/SettingsController.cs
+++ b/Assets/Scripts/UI/SettingsController.cs
@@ -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,
diff --git a/Assets/Scripts/UI/UIManager.cs b/Assets/Scripts/UI/UIManager.cs
index 55446341..8c218fae 100644
--- a/Assets/Scripts/UI/UIManager.cs
+++ b/Assets/Scripts/UI/UIManager.cs
@@ -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(lobbyTemplate);
- _profileController = RegisterController(profileTemplate);
- _settingsController = RegisterController(settingsTemplate);
- _hudController = RegisterController(hudTemplate);
+ RegisterController(lobbyTemplate);
+ RegisterController(profileTemplate);
+ RegisterController(settingsTemplate);
+ RegisterController(hudTemplate);
- // Start with Main Menu
+ // Khởi động màn hình đầu tiên
_ = Push();
}
private T RegisterController(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() 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();
+ }
}
}
}