2026-04-25 18:20:16 +07:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
|
|
|
|
namespace UI
|
|
|
|
|
{
|
|
|
|
|
public class LobbyController : MonoBehaviour
|
|
|
|
|
{
|
2026-04-26 05:02:49 +07:00
|
|
|
private VisualElement _joinView;
|
|
|
|
|
private VisualElement _createView;
|
2026-04-26 05:20:47 +07:00
|
|
|
|
|
|
|
|
private float _lastInteractionTime;
|
|
|
|
|
private bool _isCreateMode = false;
|
|
|
|
|
private const float AutoReturnDelay = 5f;
|
2026-04-25 18:20:16 +07:00
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
2026-04-26 05:02:49 +07:00
|
|
|
var root = GetComponent<UIDocument>().rootVisualElement;
|
|
|
|
|
|
|
|
|
|
_joinView = root.Q<VisualElement>("join-view");
|
|
|
|
|
_createView = root.Q<VisualElement>("create-view");
|
|
|
|
|
|
|
|
|
|
// Back button
|
|
|
|
|
root.Q<Button>("btn-back")?.RegisterCallback<ClickEvent>(evt => UIManager.Instance.GoBack());
|
|
|
|
|
root.Q<Button>("btn-settings")?.RegisterCallback<ClickEvent>(evt => UIManager.Instance.ToggleSettings());
|
|
|
|
|
|
|
|
|
|
// Create confirm -> Lounge
|
|
|
|
|
root.Q<Button>("btn-create-confirm")?.RegisterCallback<ClickEvent>(evt => UIManager.Instance.ShowScreen("Lounge"));
|
|
|
|
|
|
2026-04-26 05:20:47 +07:00
|
|
|
// 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
|
2026-04-26 05:02:49 +07:00
|
|
|
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;
|
|
|
|
|
});
|
2026-04-26 05:20:47 +07:00
|
|
|
|
|
|
|
|
ResetInteractionTimer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
if (_isCreateMode)
|
|
|
|
|
{
|
|
|
|
|
if (Time.time - _lastInteractionTime > AutoReturnDelay)
|
|
|
|
|
{
|
|
|
|
|
SetMode(false); // Auto return to Stage 1
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-25 18:20:16 +07:00
|
|
|
}
|
|
|
|
|
|
2026-04-26 05:02:49 +07:00
|
|
|
public void SetMode(bool isCreate)
|
2026-04-25 18:20:16 +07:00
|
|
|
{
|
2026-04-26 05:20:47 +07:00
|
|
|
_isCreateMode = isCreate;
|
2026-04-26 05:02:49 +07:00
|
|
|
if (_joinView == null) return;
|
2026-04-26 05:20:47 +07:00
|
|
|
|
2026-04-26 05:02:49 +07:00
|
|
|
_joinView.style.display = isCreate ? DisplayStyle.None : DisplayStyle.Flex;
|
|
|
|
|
_createView.style.display = isCreate ? DisplayStyle.Flex : DisplayStyle.None;
|
2026-04-26 05:20:47 +07:00
|
|
|
|
|
|
|
|
if (isCreate) ResetInteractionTimer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetInteractionTimer()
|
|
|
|
|
{
|
|
|
|
|
_lastInteractionTime = Time.time;
|
2026-04-25 18:20:16 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|