Update
This commit is contained in:
@@ -7,6 +7,10 @@ namespace UI
|
||||
{
|
||||
private VisualElement _joinView;
|
||||
private VisualElement _createView;
|
||||
|
||||
private float _lastInteractionTime;
|
||||
private bool _isCreateMode = false;
|
||||
private const float AutoReturnDelay = 5f;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
@@ -22,19 +26,50 @@ namespace UI
|
||||
// Create confirm -> Lounge
|
||||
root.Q<Button>("btn-create-confirm")?.RegisterCallback<ClickEvent>(evt => UIManager.Instance.ShowScreen("Lounge"));
|
||||
|
||||
// Toggle password field in Create View
|
||||
// Register Interaction Resetters
|
||||
var textFields = root.Query<TextField>().ToList();
|
||||
foreach (var field in textFields)
|
||||
field.RegisterValueChangedCallback(evt => ResetInteractionTimer());
|
||||
|
||||
var toggles = root.Query<Toggle>().ToList();
|
||||
foreach (var t in toggles)
|
||||
t.RegisterValueChangedCallback(evt => ResetInteractionTimer());
|
||||
|
||||
// Password Toggle Logic
|
||||
var passToggle = root.Q<Toggle>("toggle-password");
|
||||
var passField = root.Q<TextField>("field-password");
|
||||
passToggle?.RegisterValueChangedCallback(evt => {
|
||||
if(passField != null) passField.style.display = evt.newValue ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
});
|
||||
|
||||
ResetInteractionTimer();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isCreateMode)
|
||||
{
|
||||
if (Time.time - _lastInteractionTime > AutoReturnDelay)
|
||||
{
|
||||
SetMode(false); // Auto return to Stage 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMode(bool isCreate)
|
||||
{
|
||||
_isCreateMode = isCreate;
|
||||
if (_joinView == null) return;
|
||||
|
||||
_joinView.style.display = isCreate ? DisplayStyle.None : DisplayStyle.Flex;
|
||||
_createView.style.display = isCreate ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
|
||||
if (isCreate) ResetInteractionTimer();
|
||||
}
|
||||
|
||||
private void ResetInteractionTimer()
|
||||
{
|
||||
_lastInteractionTime = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ namespace UI
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
if (transform.parent == null)
|
||||
DontDestroyOnLoad(gameObject);
|
||||
LoadLanguage(_currentLanguage);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -13,7 +13,13 @@ namespace UI
|
||||
private VisualElement _logoPlaceholder;
|
||||
private bool _isActive = false;
|
||||
|
||||
[Header("Animation Settings")]
|
||||
public float transitionDuration = 0.5f;
|
||||
public float idleTimeout = 5f;
|
||||
public float pulseSpeed = 2f;
|
||||
public float pulseAmount = 0.05f;
|
||||
|
||||
private float _lastInteractionTime;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
@@ -26,45 +32,105 @@ namespace UI
|
||||
|
||||
_logoContainer.RegisterCallback<ClickEvent>(OnLogoClicked);
|
||||
|
||||
// Register interactions to reset idle timer
|
||||
root.RegisterCallback<MouseMoveEvent>(evt => ResetIdleTimer());
|
||||
var buttons = root.Query<Button>().ToList();
|
||||
foreach (var btn in buttons)
|
||||
{
|
||||
btn.RegisterCallback<ClickEvent>(evt => ResetIdleTimer());
|
||||
}
|
||||
|
||||
// Routing
|
||||
root.Q<Button>("btn-create")?.RegisterCallback<ClickEvent>(ev => UIManager.Instance.ShowScreen("Lobby"));
|
||||
root.Q<Button>("btn-join")?.RegisterCallback<ClickEvent>(ev => UIManager.Instance.ShowScreen("Lobby"));
|
||||
root.Q<Button>("btn-create")?.RegisterCallback<ClickEvent>(ev => NavigateToLobby(true));
|
||||
root.Q<Button>("btn-join")?.RegisterCallback<ClickEvent>(ev => NavigateToLobby(false));
|
||||
root.Q<Button>("btn-settings")?.RegisterCallback<ClickEvent>(ev => UIManager.Instance.ToggleSettings());
|
||||
root.Q<Button>("btn-profile")?.RegisterCallback<ClickEvent>(ev => UIManager.Instance.ShowScreen("Profile"));
|
||||
root.Q<Button>("btn-exit")?.RegisterCallback<ClickEvent>(ev => Application.Quit());
|
||||
|
||||
ResetToIdleState();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// 1. Logic Pulsing (Luôn chạy)
|
||||
float baseScale = _isActive ? 0.38f : 1.0f;
|
||||
float pulse = Mathf.Sin(Time.time * pulseSpeed) * pulseAmount;
|
||||
_logo.style.scale = new Scale(new Vector3(baseScale + pulse, baseScale + pulse, 1f));
|
||||
|
||||
// 2. Logic Idle Timeout
|
||||
if (_isActive)
|
||||
{
|
||||
if (Time.time - _lastInteractionTime > idleTimeout)
|
||||
{
|
||||
StartCoroutine(TransitionToIdle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void NavigateToLobby(bool isCreate)
|
||||
{
|
||||
var lobby = Object.FindFirstObjectByType<LobbyController>();
|
||||
lobby?.SetMode(isCreate);
|
||||
UIManager.Instance.ShowScreen("Lobby");
|
||||
}
|
||||
|
||||
private void OnLogoClicked(ClickEvent evt)
|
||||
{
|
||||
ResetIdleTimer();
|
||||
if (!_isActive) {
|
||||
// Chỉ chuyển từ Idle sang Active
|
||||
StartCoroutine(TransitionToActive());
|
||||
} else {
|
||||
UIManager.Instance.ShowScreen("Lobby");
|
||||
// Khi đã trong dải Ribbon, nhấn để vào Create Room
|
||||
NavigateToLobby(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetIdleTimer()
|
||||
{
|
||||
_lastInteractionTime = Time.time;
|
||||
}
|
||||
|
||||
private void ResetToIdleState()
|
||||
{
|
||||
_isActive = false;
|
||||
_ribbon.style.display = DisplayStyle.None;
|
||||
_logoContainer.style.translate = new Translate(0, 0);
|
||||
_logoContainer.pickingMode = PickingMode.Position;
|
||||
}
|
||||
|
||||
private IEnumerator TransitionToActive()
|
||||
{
|
||||
_isActive = true;
|
||||
|
||||
// 1. Show Ribbon (initially invisible)
|
||||
ResetIdleTimer();
|
||||
|
||||
_ribbon.style.display = DisplayStyle.Flex;
|
||||
_ribbon.style.opacity = 0;
|
||||
|
||||
// 2. Animate Logo to Ribbon
|
||||
_logoContainer.style.transitionProperty = new List<StylePropertyName> { "scale", "translate", "opacity" };
|
||||
_logoContainer.style.transitionProperty = new List<StylePropertyName> { "translate", "opacity" };
|
||||
_logoContainer.style.transitionDuration = new List<TimeValue> { new TimeValue(transitionDuration, TimeUnit.Second) };
|
||||
|
||||
yield return null; // Wait for layout update
|
||||
|
||||
// Tính toán khoảng cách di chuyển (Nếu cần thiết, ở đây dùng scale đơn giản)
|
||||
_logoContainer.style.scale = new Scale(new Vector3(0.4f, 0.4f, 1f));
|
||||
|
||||
_ribbon.style.transitionProperty = new List<StylePropertyName> { "opacity" };
|
||||
_ribbon.style.transitionDuration = new List<TimeValue> { new TimeValue(transitionDuration, TimeUnit.Second) };
|
||||
|
||||
yield return null;
|
||||
|
||||
// Di chuyển logo sang vị trí thứ 2 (-20%)
|
||||
_logoContainer.style.translate = new Translate(Length.Percent(-20f), 0);
|
||||
_ribbon.style.opacity = 1;
|
||||
|
||||
yield return new WaitForSeconds(transitionDuration);
|
||||
}
|
||||
|
||||
private IEnumerator TransitionToIdle()
|
||||
{
|
||||
_isActive = false;
|
||||
|
||||
_logoContainer.style.translate = new Translate(0, 0);
|
||||
_ribbon.style.opacity = 0;
|
||||
|
||||
yield return new WaitForSeconds(transitionDuration);
|
||||
_ribbon.style.display = DisplayStyle.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,13 +86,20 @@ namespace UI
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Calculate Virtual Mouse Position
|
||||
Vector2 mousePos = Input.mousePosition;
|
||||
bool restrictY = (_currentScreenName == "MainMenu" && !_isSettingsOpen);
|
||||
bool isMainMenu = (_currentScreenName == "MainMenu");
|
||||
bool restrictY = (isMainMenu && !_isSettingsOpen);
|
||||
float targetY = restrictY ? Screen.height / 2f : mousePos.y;
|
||||
Vector2 uiPos = new Vector2(mousePos.x, Screen.height - targetY);
|
||||
|
||||
// Visibility Logic for Cursor & Trail
|
||||
bool showCursor = !isMainMenu || _isSettingsOpen;
|
||||
DisplayStyle cursorDisplay = showCursor ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
|
||||
if (_customCursor != null)
|
||||
{
|
||||
_customCursor.style.display = cursorDisplay;
|
||||
_customCursor.style.left = uiPos.x - 12.5f;
|
||||
_customCursor.style.top = uiPos.y - 12.5f;
|
||||
}
|
||||
@@ -103,10 +110,17 @@ namespace UI
|
||||
currentTrail.style.left = uiPos.x - 9;
|
||||
currentTrail.style.top = uiPos.y - 9;
|
||||
currentTrail.style.opacity = 0.5f;
|
||||
foreach(var t in _trailPool) t.style.opacity = Mathf.Max(0, t.style.opacity.value - Time.deltaTime * 4f);
|
||||
|
||||
foreach(var t in _trailPool)
|
||||
{
|
||||
t.style.display = cursorDisplay;
|
||||
t.style.opacity = Mathf.Max(0, t.style.opacity.value - Time.deltaTime * 4f);
|
||||
}
|
||||
|
||||
_trailIndex = (_trailIndex + 1) % _trailPool.Count;
|
||||
}
|
||||
|
||||
// Handle Focus & Clicks using virtual coordinates
|
||||
HandleVirtualInput(uiPos);
|
||||
|
||||
if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.O))
|
||||
|
||||
Reference in New Issue
Block a user