Update
This commit is contained in:
12
.idea/.idea.HALLUCINATE/.idea/workspace.xml
generated
12
.idea/.idea.HALLUCINATE/.idea/workspace.xml
generated
@@ -6,20 +6,10 @@
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="f9183c68-daf0-43b8-be4c-fad79983f91b" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/Editor/UIManagerEditor.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Editor/UIManagerEditor.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/Scove/UIScaleTest.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scove/UIScaleTest.unity" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/HUDController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/HUDController.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/LobbyController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/LobbyController.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/MainMenuController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/MainMenuController.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/ProfileController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/ProfileController.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/SettingsController.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/SettingsController.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/UI/UIManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/UI/UIManager.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/UI/Documents/Lobby.uxml" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/Documents/Lobby.uxml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/UI/Documents/MainGameHUD.uxml" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/Documents/MainGameHUD.uxml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/UI/Documents/MainMenu.uxml" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/Documents/MainMenu.uxml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/UI/Documents/Profile.uxml" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/Documents/Profile.uxml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/UI/Documents/Settings.uxml" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/Documents/Settings.uxml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/UI/MainPanelSettings.asset" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/MainPanelSettings.asset" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Assets/UI/Styles/Global.uss" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI/Styles/Global.uss" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@@ -152,7 +142,7 @@
|
||||
<workItem from="1776940053256" duration="13616000" />
|
||||
<workItem from="1777113431258" duration="10253000" />
|
||||
<workItem from="1777150520438" duration="58000" />
|
||||
<workItem from="1777150592854" duration="2288000" />
|
||||
<workItem from="1777150592854" duration="3918000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
|
||||
@@ -5,44 +5,36 @@ namespace UI
|
||||
{
|
||||
public class LobbyController : MonoBehaviour
|
||||
{
|
||||
private UIDocument _doc;
|
||||
private Button _btnLeave;
|
||||
private Button _btnStart;
|
||||
private ScrollView _playerList;
|
||||
private VisualElement _joinView;
|
||||
private VisualElement _createView;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_doc = GetComponent<UIDocument>();
|
||||
var root = _doc.rootVisualElement;
|
||||
var root = GetComponent<UIDocument>().rootVisualElement;
|
||||
|
||||
// BINDING: Tìm element theo tên (Name) đã đặt trong UXML
|
||||
_btnLeave = root.Q<Button>("btn-leave");
|
||||
_btnStart = root.Q<Button>("btn-start");
|
||||
_playerList = root.Q<ScrollView>("player-list");
|
||||
_joinView = root.Q<VisualElement>("join-view");
|
||||
_createView = root.Q<VisualElement>("create-view");
|
||||
|
||||
// ĐĂNG KÝ SỰ KIỆN:
|
||||
if (_btnLeave != null)
|
||||
_btnLeave.clicked += OnLeaveClicked;
|
||||
// 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"));
|
||||
|
||||
if (_btnStart != null)
|
||||
_btnStart.clicked += OnStartClicked;
|
||||
// Toggle password field in Create View
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
private void OnLeaveClicked()
|
||||
public void SetMode(bool isCreate)
|
||||
{
|
||||
UIManager.Instance.GoBack();
|
||||
}
|
||||
|
||||
private void OnStartClicked()
|
||||
{
|
||||
UIManager.Instance.ShowScreen("Lounge");
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Hủy đăng ký để tránh memory leak
|
||||
if (_btnLeave != null) _btnLeave.clicked -= OnLeaveClicked;
|
||||
if (_btnStart != null) _btnStart.clicked -= OnStartClicked;
|
||||
if (_joinView == null) return;
|
||||
_joinView.style.display = isCreate ? DisplayStyle.None : DisplayStyle.Flex;
|
||||
_createView.style.display = isCreate ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,9 @@ namespace UI
|
||||
private VisualElement _logoContainer;
|
||||
private VisualElement _logo;
|
||||
private VisualElement _ribbon;
|
||||
private VisualElement _logoPlaceholder;
|
||||
private bool _isActive = false;
|
||||
|
||||
[Header("Animation Settings")]
|
||||
public float pulseSpeed = 2f;
|
||||
public float pulseAmount = 0.1f;
|
||||
public float transitionDuration = 0.5f;
|
||||
|
||||
private void OnEnable()
|
||||
@@ -24,11 +22,11 @@ namespace UI
|
||||
_logoContainer = root.Q<VisualElement>("beat-logo-container");
|
||||
_logo = root.Q<VisualElement>("beat-logo");
|
||||
_ribbon = root.Q<VisualElement>("menu-ribbon");
|
||||
_logoPlaceholder = root.Q<VisualElement>("logo-placeholder");
|
||||
|
||||
// Register logo click
|
||||
_logoContainer.RegisterCallback<ClickEvent>(OnLogoClicked);
|
||||
|
||||
// Register button events
|
||||
// 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-settings")?.RegisterCallback<ClickEvent>(ev => UIManager.Instance.ToggleSettings());
|
||||
@@ -36,44 +34,37 @@ namespace UI
|
||||
root.Q<Button>("btn-exit")?.RegisterCallback<ClickEvent>(ev => Application.Quit());
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_isActive)
|
||||
{
|
||||
// Pulse Animation
|
||||
float scale = 1f + Mathf.Sin(Time.time * pulseSpeed) * pulseAmount;
|
||||
_logo.style.scale = new Scale(new Vector3(scale, scale, 1f));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLogoClicked(ClickEvent evt)
|
||||
{
|
||||
if (_isActive) return;
|
||||
StartCoroutine(TransitionToActive());
|
||||
if (!_isActive) {
|
||||
StartCoroutine(TransitionToActive());
|
||||
} else {
|
||||
UIManager.Instance.ShowScreen("Lobby");
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator TransitionToActive()
|
||||
{
|
||||
_isActive = true;
|
||||
|
||||
// 1. Shrink and move logo
|
||||
_logoContainer.style.transitionProperty = new List<StylePropertyName> { "scale", "translate" };
|
||||
_logoContainer.style.transitionDuration = new List<TimeValue> { new TimeValue(transitionDuration, TimeUnit.Second) };
|
||||
|
||||
_logoContainer.style.scale = new Scale(new Vector3(0.4f, 0.4f, 1f));
|
||||
// Translate is tricky in UI Toolkit relative to center, but we can use absolute positioning or a placeholder
|
||||
// For now, let's just fade in the ribbon and hide the central logo
|
||||
|
||||
yield return new WaitForSeconds(transitionDuration * 0.5f);
|
||||
|
||||
// 1. Show Ribbon (initially invisible)
|
||||
_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.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;
|
||||
_ribbon.style.opacity = 1;
|
||||
_logoContainer.style.display = DisplayStyle.None;
|
||||
|
||||
yield return new WaitForSeconds(transitionDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,113 +1,63 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using OnlyScove.Scripts;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class SettingsController : MonoBehaviour
|
||||
{
|
||||
private UIDocument _doc;
|
||||
private CameraController _cameraController;
|
||||
private VisualElement _contentGeneral;
|
||||
private VisualElement _contentGraphics;
|
||||
private VisualElement _contentAudio;
|
||||
private VisualElement _contentControls;
|
||||
|
||||
// Tabs Content
|
||||
private VisualElement _contentGeneral, _contentGraphics, _contentAudio;
|
||||
private Button _tabGeneral, _tabGraphics, _tabAudio, _tabControls;
|
||||
private Button _tabGeneral;
|
||||
private Button _tabGraphics;
|
||||
private Button _tabAudio;
|
||||
private Button _tabControls;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_doc = GetComponent<UIDocument>();
|
||||
_cameraController = Object.FindFirstObjectByType<CameraController>();
|
||||
var root = GetComponent<UIDocument>().rootVisualElement;
|
||||
|
||||
var root = _doc.rootVisualElement;
|
||||
|
||||
// Query Tabs
|
||||
// Tabs
|
||||
_tabGeneral = root.Q<Button>("tab-general");
|
||||
_tabGraphics = root.Q<Button>("tab-graphics");
|
||||
_tabAudio = root.Q<Button>("tab-audio");
|
||||
_tabControls = root.Q<Button>("tab-controls");
|
||||
|
||||
// Query Content
|
||||
// Content
|
||||
_contentGeneral = root.Q<VisualElement>("content-general");
|
||||
_contentGraphics = root.Q<VisualElement>("content-graphics");
|
||||
_contentAudio = root.Q<VisualElement>("content-audio");
|
||||
_contentControls = root.Q<VisualElement>("content-controls");
|
||||
|
||||
// Events
|
||||
_tabGeneral.clicked += () => SwitchTab(_contentGeneral, _tabGeneral);
|
||||
_tabGraphics.clicked += () => SwitchTab(_contentGraphics, _tabGraphics);
|
||||
_tabAudio.clicked += () => SwitchTab(_contentAudio, _tabAudio);
|
||||
// Register Tab Events
|
||||
_tabGeneral?.RegisterCallback<ClickEvent>(evt => SwitchTab(_contentGeneral, _tabGeneral));
|
||||
_tabGraphics?.RegisterCallback<ClickEvent>(evt => SwitchTab(_contentGraphics, _tabGraphics));
|
||||
_tabAudio?.RegisterCallback<ClickEvent>(evt => SwitchTab(_contentAudio, _tabAudio));
|
||||
_tabControls?.RegisterCallback<ClickEvent>(evt => SwitchTab(_contentControls, _tabControls));
|
||||
|
||||
root.Q<Button>("btn-close").clicked += () => UIManager.Instance.ToggleSettings();
|
||||
|
||||
// If we want a hard back button to MainMenu:
|
||||
// root.Q<Button>("btn-back").clicked += () => UIManager.Instance.GoBack();
|
||||
|
||||
// Camera Binding (FOV)
|
||||
var fovSlider = root.Q<Slider>("setting-fov");
|
||||
if (fovSlider != null)
|
||||
{
|
||||
fovSlider.RegisterValueChangedCallback(evt => {
|
||||
// Cần expose hoặc tạo hàm SetFOV trong CameraController
|
||||
Debug.Log($"Setting FOV to: {evt.newValue}");
|
||||
});
|
||||
}
|
||||
|
||||
// Language Binding
|
||||
var langDropdown = root.Q<DropdownField>("setting-language");
|
||||
if (langDropdown != null)
|
||||
{
|
||||
langDropdown.RegisterValueChangedCallback(evt => {
|
||||
string code = evt.newValue == "English" ? "en" : "vi";
|
||||
LocalizationManager.Instance.LoadLanguage(code);
|
||||
});
|
||||
}
|
||||
|
||||
// Lắng nghe sự kiện đổi ngôn ngữ để cập nhật Text
|
||||
if (LocalizationManager.Instance != null)
|
||||
{
|
||||
LocalizationManager.Instance.OnLanguageChanged += UpdateTexts;
|
||||
UpdateTexts();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[SettingsController] LocalizationManager Instance not found in scene!");
|
||||
}
|
||||
// Close
|
||||
root.Q<Button>("btn-close")?.RegisterCallback<ClickEvent>(evt => UIManager.Instance.ToggleSettings());
|
||||
}
|
||||
|
||||
private void SwitchTab(VisualElement targetContent, Button targetTab)
|
||||
{
|
||||
if (targetContent == null || targetTab == null) return;
|
||||
// Hide all
|
||||
_contentGeneral.style.display = DisplayStyle.None;
|
||||
if(_contentGraphics != null) _contentGraphics.style.display = DisplayStyle.None;
|
||||
if(_contentAudio != null) _contentAudio.style.display = DisplayStyle.None;
|
||||
if(_contentControls != null) _contentControls.style.display = DisplayStyle.None;
|
||||
|
||||
// Ẩn tất cả (Thêm null check)
|
||||
if (_contentGeneral != null) _contentGeneral.style.display = DisplayStyle.None;
|
||||
if (_contentGraphics != null) _contentGraphics.style.display = DisplayStyle.None;
|
||||
if (_contentAudio != null) _contentAudio.style.display = DisplayStyle.None;
|
||||
_tabGeneral.RemoveFromClassList("active-tab");
|
||||
_tabGraphics.RemoveFromClassList("active-tab");
|
||||
_tabAudio.RemoveFromClassList("active-tab");
|
||||
_tabControls.RemoveFromClassList("active-tab");
|
||||
|
||||
if (_tabGeneral != null) _tabGeneral.RemoveFromClassList("active-tab");
|
||||
if (_tabGraphics != null) _tabGraphics.RemoveFromClassList("active-tab");
|
||||
if (_tabAudio != null) _tabAudio.RemoveFromClassList("active-tab");
|
||||
|
||||
// Hiện cái được chọn
|
||||
// Show target
|
||||
targetContent.style.display = DisplayStyle.Flex;
|
||||
targetTab.AddToClassList("active-tab");
|
||||
}
|
||||
|
||||
private void UpdateTexts()
|
||||
{
|
||||
if (LocalizationManager.Instance == null) return;
|
||||
|
||||
var root = _doc.rootVisualElement;
|
||||
|
||||
// Dùng null-conditional operator (?.) để cực kỳ an toàn
|
||||
var titleLabel = root.Q<Label>("title");
|
||||
if (titleLabel != null) titleLabel.text = LocalizationManager.Instance.Get("settings_title");
|
||||
|
||||
if (_tabGeneral != null) _tabGeneral.text = LocalizationManager.Instance.Get("settings_general");
|
||||
if (_tabGraphics != null) _tabGraphics.text = LocalizationManager.Instance.Get("settings_graphics");
|
||||
if (_tabAudio != null) _tabAudio.text = LocalizationManager.Instance.Get("settings_audio");
|
||||
if (_tabControls != null) _tabControls.text = LocalizationManager.Instance.Get("settings_controls");
|
||||
|
||||
var btnBack = root.Q<Button>("btn-back");
|
||||
if (btnBack != null) btnBack.text = LocalizationManager.Instance.Get("settings_back");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,49 +16,142 @@ namespace UI
|
||||
public string screenName;
|
||||
public UIDocument document;
|
||||
public bool isOverlay;
|
||||
public Texture2D customCursor;
|
||||
public bool isActive; // For Editor and Initial state
|
||||
public bool isActive;
|
||||
}
|
||||
|
||||
public List<ScreenData> screens = new List<ScreenData>();
|
||||
|
||||
[Header("Settings")]
|
||||
public string initialScreen = "MainMenu";
|
||||
public float focusRadius = 300f;
|
||||
|
||||
[Header("Cursor Settings")]
|
||||
private VisualElement _customCursor;
|
||||
private List<VisualElement> _trailPool = new List<VisualElement>();
|
||||
private int _trailIndex = 0;
|
||||
public int trailCount = 15;
|
||||
public float focusRadius = 500f;
|
||||
|
||||
[Header("Editor Preview")]
|
||||
[Range(0f, 1f)]
|
||||
public float globalOpacity = 1f;
|
||||
|
||||
private Stack<string> _navigationStack = new Stack<string>();
|
||||
private string _currentScreenName;
|
||||
private VisualElement _lastHoveredElement;
|
||||
private bool _isSettingsOpen = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null) Instance = this;
|
||||
else { Destroy(gameObject); return; }
|
||||
|
||||
// Initialize all screens based on isActive or hidden
|
||||
foreach (var screen in screens)
|
||||
SetupCursor();
|
||||
foreach (var s in screens)
|
||||
{
|
||||
if (screen.document != null)
|
||||
{
|
||||
// Ensure the root has the screen-root class for transitions
|
||||
var root = screen.document.rootVisualElement;
|
||||
if (root != null)
|
||||
{
|
||||
root.AddToClassList("screen-root");
|
||||
root.style.display = DisplayStyle.None;
|
||||
}
|
||||
}
|
||||
if (s.document != null) s.document.rootVisualElement.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
ShowScreen(initialScreen);
|
||||
}
|
||||
|
||||
private void SetupCursor()
|
||||
{
|
||||
UIDocument doc = GetComponent<UIDocument>();
|
||||
if (doc == null && screens.Count > 0) doc = screens[0].document;
|
||||
if (doc == null) return;
|
||||
|
||||
var root = doc.rootVisualElement;
|
||||
|
||||
_customCursor = new VisualElement();
|
||||
_customCursor.style.width = 25;
|
||||
_customCursor.style.height = 25;
|
||||
_customCursor.style.backgroundColor = Color.white;
|
||||
_customCursor.style.borderTopLeftRadius = 13; _customCursor.style.borderTopRightRadius = 13;
|
||||
_customCursor.style.borderBottomLeftRadius = 13; _customCursor.style.borderBottomRightRadius = 13;
|
||||
_customCursor.style.position = Position.Absolute;
|
||||
_customCursor.pickingMode = PickingMode.Ignore;
|
||||
root.Add(_customCursor);
|
||||
|
||||
for (int i = 0; i < trailCount; i++)
|
||||
{
|
||||
var trail = new VisualElement();
|
||||
trail.style.width = 18; trail.style.height = 18;
|
||||
trail.style.backgroundColor = new Color(1, 1, 1, 0.4f);
|
||||
trail.style.borderTopLeftRadius = 9; trail.style.borderTopRightRadius = 9;
|
||||
trail.style.borderBottomLeftRadius = 9; trail.style.borderBottomRightRadius = 9;
|
||||
trail.style.position = Position.Absolute;
|
||||
trail.pickingMode = PickingMode.Ignore;
|
||||
root.Add(trail);
|
||||
_trailPool.Add(trail);
|
||||
}
|
||||
_customCursor.BringToFront();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
HandleGlobalInputs();
|
||||
HandleCursorlessFocus();
|
||||
Vector2 mousePos = Input.mousePosition;
|
||||
bool restrictY = (_currentScreenName == "MainMenu" && !_isSettingsOpen);
|
||||
float targetY = restrictY ? Screen.height / 2f : mousePos.y;
|
||||
Vector2 uiPos = new Vector2(mousePos.x, Screen.height - targetY);
|
||||
|
||||
if (_customCursor != null)
|
||||
{
|
||||
_customCursor.style.left = uiPos.x - 12.5f;
|
||||
_customCursor.style.top = uiPos.y - 12.5f;
|
||||
}
|
||||
|
||||
if (_trailPool.Count > 0)
|
||||
{
|
||||
var currentTrail = _trailPool[_trailIndex];
|
||||
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);
|
||||
_trailIndex = (_trailIndex + 1) % _trailPool.Count;
|
||||
}
|
||||
|
||||
HandleVirtualInput(uiPos);
|
||||
|
||||
if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.O))
|
||||
ToggleSettings();
|
||||
}
|
||||
|
||||
private void HandleVirtualInput(Vector2 uiPos)
|
||||
{
|
||||
UIDocument activeDoc = null;
|
||||
var settings = screens.Find(s => s.screenName == "Settings");
|
||||
if (_isSettingsOpen) activeDoc = settings.document;
|
||||
else activeDoc = screens.Find(s => s.screenName == _currentScreenName)?.document;
|
||||
|
||||
if (activeDoc == null) return;
|
||||
|
||||
VisualElement bestElement = null;
|
||||
float minDistance = float.MaxValue;
|
||||
|
||||
var interactables = activeDoc.rootVisualElement.Query<VisualElement>()
|
||||
.Where(e => e.focusable && e.pickingMode != PickingMode.Ignore).ToList();
|
||||
|
||||
foreach (var element in interactables)
|
||||
{
|
||||
Rect worldBounds = element.worldBound;
|
||||
float dist = Vector2.Distance(uiPos, worldBounds.center);
|
||||
if (dist < minDistance && dist < focusRadius) {
|
||||
minDistance = dist;
|
||||
bestElement = element;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestElement != _lastHoveredElement)
|
||||
{
|
||||
_lastHoveredElement?.RemoveFromClassList("hover");
|
||||
bestElement?.AddToClassList("hover");
|
||||
_lastHoveredElement = bestElement;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(0) && _lastHoveredElement != null)
|
||||
{
|
||||
using (var clickEvent = ClickEvent.GetPooled()) {
|
||||
clickEvent.target = _lastHoveredElement;
|
||||
_lastHoveredElement.SendEvent(clickEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Editor Support Methods ---
|
||||
@@ -87,132 +180,42 @@ namespace UI
|
||||
|
||||
// --- Runtime Logic ---
|
||||
|
||||
private void HandleGlobalInputs()
|
||||
{
|
||||
if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.O))
|
||||
{
|
||||
ToggleSettings();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
if (_navigationStack.Count > 1)
|
||||
{
|
||||
GoBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleCursorlessFocus()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_currentScreenName)) return;
|
||||
|
||||
var screen = screens.Find(s => s.screenName == _currentScreenName);
|
||||
if (screen == null || screen.document == null) return;
|
||||
|
||||
Vector2 mousePos = Input.mousePosition;
|
||||
Vector2 uiMousePos = new Vector2(mousePos.x, Screen.height - mousePos.y);
|
||||
|
||||
VisualElement bestElement = null;
|
||||
float minDistance = float.MaxValue;
|
||||
|
||||
var interactiveElements = screen.document.rootVisualElement.Query<VisualElement>()
|
||||
.Where(e => e.focusable && e.pickingMode == PickingMode.Position).ToList();
|
||||
|
||||
foreach (var element in interactiveElements)
|
||||
{
|
||||
Rect worldBounds = element.worldBound;
|
||||
Vector2 center = worldBounds.center;
|
||||
float dist = Vector2.Distance(uiMousePos, center);
|
||||
|
||||
if (dist < minDistance && dist < focusRadius)
|
||||
{
|
||||
minDistance = dist;
|
||||
bestElement = element;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestElement != _lastHoveredElement)
|
||||
{
|
||||
_lastHoveredElement?.RemoveFromClassList("hover");
|
||||
bestElement?.AddToClassList("hover");
|
||||
_lastHoveredElement = bestElement;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(0) && _lastHoveredElement != null)
|
||||
{
|
||||
using (var clickEvent = ClickEvent.GetPooled())
|
||||
{
|
||||
clickEvent.target = _lastHoveredElement;
|
||||
_lastHoveredElement.SendEvent(clickEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowScreen(string name)
|
||||
{
|
||||
var nextData = screens.Find(s => s.screenName == name);
|
||||
if (nextData == null) return;
|
||||
var screen = screens.Find(s => s.screenName == name);
|
||||
if (screen == null) return;
|
||||
|
||||
// Hide all first for a clean state at runtime
|
||||
foreach (var s in screens)
|
||||
if (!screen.isOverlay)
|
||||
{
|
||||
if (s.document != null) s.document.rootVisualElement.style.display = DisplayStyle.None;
|
||||
s.isActive = false;
|
||||
foreach(var s in screens) if(!s.isOverlay) s.document.rootVisualElement.style.display = DisplayStyle.None;
|
||||
_navigationStack.Push(name);
|
||||
_currentScreenName = name;
|
||||
}
|
||||
|
||||
_navigationStack.Push(name);
|
||||
_currentScreenName = name;
|
||||
nextData.isActive = true;
|
||||
|
||||
nextData.document.rootVisualElement.style.display = DisplayStyle.Flex;
|
||||
nextData.document.rootVisualElement.style.opacity = globalOpacity;
|
||||
ApplyCursorSettings(nextData);
|
||||
screen.document.rootVisualElement.style.display = DisplayStyle.Flex;
|
||||
screen.isActive = true;
|
||||
UnityEngine.Cursor.visible = false;
|
||||
}
|
||||
|
||||
public void GoBack()
|
||||
{
|
||||
if (_navigationStack.Count <= 1) return;
|
||||
|
||||
string current = _navigationStack.Pop();
|
||||
var currentData = screens.Find(s => s.screenName == current);
|
||||
if (currentData != null) currentData.document.rootVisualElement.style.display = DisplayStyle.None;
|
||||
|
||||
_currentScreenName = _navigationStack.Peek();
|
||||
var prevData = screens.Find(s => s.screenName == _currentScreenName);
|
||||
if (prevData != null)
|
||||
{
|
||||
prevData.document.rootVisualElement.style.display = DisplayStyle.Flex;
|
||||
ApplyCursorSettings(prevData);
|
||||
}
|
||||
var prev = screens.Find(s => s.screenName == _currentScreenName);
|
||||
if (prev != null) prev.document.rootVisualElement.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
|
||||
public void ToggleSettings()
|
||||
{
|
||||
var settings = screens.Find(s => s.screenName == "Settings");
|
||||
if (settings == null) return;
|
||||
|
||||
bool isShowing = settings.document.rootVisualElement.style.display == DisplayStyle.Flex;
|
||||
settings.document.rootVisualElement.style.display = isShowing ? DisplayStyle.None : DisplayStyle.Flex;
|
||||
|
||||
if (!isShowing)
|
||||
{
|
||||
settings.document.sortingOrder = 999;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyCursorSettings(ScreenData data)
|
||||
{
|
||||
if (data.screenName == "HUD")
|
||||
{
|
||||
UnityEngine.Cursor.visible = false;
|
||||
UnityEngine.Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Cursor.visible = false;
|
||||
UnityEngine.Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
_isSettingsOpen = settings.document.rootVisualElement.style.display == DisplayStyle.None;
|
||||
settings.document.rootVisualElement.style.display = _isSettingsOpen ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
settings.isActive = _isSettingsOpen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,9 +110,15 @@
|
||||
/* Cursorless Focus System */
|
||||
.slanted-button.hover {
|
||||
background-color: var(--primary-hover);
|
||||
scale: 1.1;
|
||||
scale: 1.15;
|
||||
rotate: -2deg;
|
||||
border-width: 2px;
|
||||
border-color: white;
|
||||
transition-duration: 0.15s;
|
||||
}
|
||||
|
||||
.slanted-button.hover .slanted-button-inner {
|
||||
color: #FFD700; /* Golden text on hover */
|
||||
}
|
||||
|
||||
/* HUD Components */
|
||||
|
||||
Reference in New Issue
Block a user