This commit is contained in:
2026-04-29 01:04:28 +07:00
parent 29888fadfa
commit 21c999a904
32 changed files with 1423 additions and 894 deletions

View File

@@ -16,7 +16,7 @@ namespace Hallucinate.UI
private float _lastInteractionTime;
private const float IDLE_TIMEOUT = 5.0f;
private bool _isFirstLoad = true; // Biến cờ để nhận biết lần đầu vào game
private bool _isFirstLoad = true;
private Tween _pulseTween;
private Tween _rotationTween;
@@ -38,13 +38,12 @@ namespace Hallucinate.UI
_logo.RegisterCallback<ClickEvent>(OnLogoClicked);
// Bind Buttons
var settingsBtn = root.Q<Button>("SettingsBtn");
if (settingsBtn != null) settingsBtn.clicked += () => uiManager.ToggleSettings();
root.Q<Button>("JoinBtn").clicked += () => uiManager.Push<LobbyController>();
root.Q<Button>("CreateBtn").clicked += () => uiManager.Push<LobbyController>();
root.Q<Button>("ProfileBtn").clicked += () => uiManager.Push<ProfileController>();
root.Q<Button>("JoinBtn").clicked += async () => await uiManager.Push<LobbyController>();
root.Q<Button>("CreateBtn").clicked += async () => await uiManager.Push<LobbyController>();
root.Q<Button>("ProfileBtn").clicked += async () => await uiManager.Push<ProfileController>();
root.Q<Button>("ExitBtn").clicked += () => Application.Quit();
ResetLogoPosition();
@@ -86,8 +85,10 @@ namespace Hallucinate.UI
if (_currentIcon == null) return;
if (_rotationTween.isAlive) _rotationTween.Stop();
_rotationTween = Tween.Custom(0f, 360f, duration: 4f, cycles: -1, ease: Ease.Linear,
onValueChange: val => _logo.style.rotate = new StyleRotate(new Rotate(Angle.Degrees(val))));
_rotationTween = Tween.Custom(0f, 360f, duration: 4f,
onValueChange: val => _logo.style.rotate = new StyleRotate(new Rotate(Angle.Degrees(val))),
cycles: -1,
ease: Ease.Linear);
}
public override async Task PlayTransitionIn()
@@ -102,20 +103,11 @@ namespace Hallucinate.UI
_ribbon.style.opacity = 0;
}
// Khởi động lại rotation nếu có icon
StartRotation();
await base.PlayTransitionIn();
// Nếu không phải lần đầu load (tức là quay lại bằng nút Back), tự động bung Ribbon
if (!_isFirstLoad)
{
TransitionToRibbon();
}
else
{
_isFirstLoad = false; // Đã xong lần đầu, các lần sau sẽ tự động bung
}
if (!_isFirstLoad) TransitionToRibbon();
else _isFirstLoad = false;
}
public override async Task PlayTransitionOut()
@@ -124,11 +116,11 @@ namespace Hallucinate.UI
await base.PlayTransitionOut();
}
private void OnLogoClicked(ClickEvent evt)
private async void OnLogoClicked(ClickEvent evt)
{
_lastInteractionTime = Time.time;
if (_currentState == MenuState.Idle) TransitionToRibbon();
else _ = uiManager.Push<LobbyController>();
else await uiManager.Push<LobbyController>();
}
private void TransitionToRibbon()
@@ -149,17 +141,25 @@ namespace Hallucinate.UI
Rect targetBounds = _logoSpace.worldBound;
if (targetBounds.width <= 0) return;
Tween.Custom(_logo.resolvedStyle.left, targetBounds.x, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.left = val);
// Center logo in LogoSpace (within the centered Ribbon)
float targetX = targetBounds.x + (targetBounds.width / 2f) - 50f;
float targetY = targetBounds.y + (targetBounds.height / 2f) - 50f;
Tween.Custom(_logo.resolvedStyle.left, targetX, duration: 0.5f,
onValueChange: val => _logo.style.left = val,
ease: Ease.OutQuad);
Tween.Custom(_logo.resolvedStyle.top, targetBounds.y - 35, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.top = val);
Tween.Custom(_logo.resolvedStyle.top, targetY, duration: 0.5f,
onValueChange: val => _logo.style.top = val,
ease: Ease.OutQuad);
Tween.Custom(_logo.resolvedStyle.width, 120f, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.width = val);
Tween.Custom(_logo.resolvedStyle.width, 100f, duration: 0.5f,
onValueChange: val => _logo.style.width = val,
ease: Ease.OutQuad);
Tween.Custom(_logo.resolvedStyle.height, 120f, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.height = val);
Tween.Custom(_logo.resolvedStyle.height, 100f, duration: 0.5f,
onValueChange: val => _logo.style.height = val,
ease: Ease.OutQuad);
_lastInteractionTime = Time.time;
}
@@ -172,14 +172,10 @@ namespace Hallucinate.UI
float targetX = (Screen.width / 2f) - 100;
float targetY = (Screen.height / 2f) - 100;
Tween.Custom(_logo.resolvedStyle.left, targetX, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.left = val);
Tween.Custom(_logo.resolvedStyle.top, targetY, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.top = val);
Tween.Custom(_logo.resolvedStyle.width, 200f, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.width = val);
Tween.Custom(_logo.resolvedStyle.height, 200f, duration: 0.5f, ease: Ease.OutQuad,
onValueChange: val => _logo.style.height = val);
Tween.Custom(_logo.resolvedStyle.left, targetX, duration: 0.5f, onValueChange: val => _logo.style.left = val, ease: Ease.OutQuad);
Tween.Custom(_logo.resolvedStyle.top, targetY, duration: 0.5f, onValueChange: val => _logo.style.top = val, ease: Ease.OutQuad);
Tween.Custom(_logo.resolvedStyle.width, 200f, duration: 0.5f, onValueChange: val => _logo.style.width = val, ease: Ease.OutQuad);
Tween.Custom(_logo.resolvedStyle.height, 200f, duration: 0.5f, onValueChange: val => _logo.style.height = val, ease: Ease.OutQuad);
Tween.Custom(1f, 0f, duration: 0.5f, onValueChange: val => _ribbon.style.opacity = val)
.OnComplete(() => _ribbon.style.display = DisplayStyle.None);
@@ -200,7 +196,12 @@ namespace Hallucinate.UI
private void StartPulse()
{
_pulseTween = Tween.Scale(_logo.transform, Vector3.one * 1.1f, duration: 0.8f, cycles: -1, cycleMode: CycleMode.Yoyo, ease: Ease.InOutSine);
if (_pulseTween.isAlive) _pulseTween.Stop();
_pulseTween = Tween.Custom(Vector3.one, Vector3.one * 1.1f, duration: 0.8f,
onValueChange: val => _logo.style.scale = new StyleScale(new Scale(val)),
cycles: -1,
cycleMode: CycleMode.Yoyo,
ease: Ease.InOutSine);
}
}
}