From 6c1ed05bd7460c8c16a84a62dac95aad997e01f0 Mon Sep 17 00:00:00 2001 From: "Jonas Luz Jr." Date: Wed, 26 Nov 2025 07:21:44 -0300 Subject: [PATCH] Refactors UI interaction and state management Improves UI element handling by encapsulating UI logic. Enhances state management for session activity and input enablement through properties. Introduces event handlers for button clicks to decouple UI interactions. --- Assets/_Client/Scripts/UI/UIController.cs | 75 +++++++++++++++-------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/Assets/_Client/Scripts/UI/UIController.cs b/Assets/_Client/Scripts/UI/UIController.cs index bc787ab..ce39cca 100644 --- a/Assets/_Client/Scripts/UI/UIController.cs +++ b/Assets/_Client/Scripts/UI/UIController.cs @@ -12,36 +12,72 @@ namespace PPGIA.X540.Project3 private UIDocument _uiDocument; private VisualElement _root; - private readonly string[] _sessionButtonLabels = { - "Iniciar Sessão", - "Encerrar Sessão" + #region -- Fields & Properties ---------------------------------------- + // Buttons ------------------------------------------------------------ + private readonly string[] _sessionButtonLabels = { + "Iniciar Sessão", + "Encerrar Sessão" }; private Button _sessionButton; private Button _sendChatButton; + private int _currentSessionState = 0; + public bool SessionActive + { + get => _currentSessionState == 1; + set + { + _currentSessionState = value ? 1 : 0; + _sessionButton.text = _sessionButtonLabels[_currentSessionState]; + InputEnabled = value; + } + } + // Chat Fields -------------------------------------------------------- private TextField _chatInputField; - private TextField _chatOutputField; + public string ChatInput + { + get => _chatInputField.value; + set => _chatInputField.value = value; + } + private TextField _chatOutputField; public string ChatOutput { get => _chatOutputField.value; set => _chatOutputField.value = value; } - public bool SessionActive { - get => _currentSessionState == 1; + public bool InputEnabled + { + get + { + var value = _chatInputField.enabledSelf; + _sendChatButton.SetEnabled(value); + return value; + } set { - _currentSessionState = value ? 1 : 0; - UpdateStateForSession(); + _chatInputField.SetEnabled(value); + _sendChatButton.SetEnabled(value); } } - public Action OnSessionButtonClicked { get; set; } - public Action OnSendChatButtonClicked { get; set; } - public float Progress { get; set; } + // Progress Bar ------------------------------------------------------- + private ProgressBar _progressBar; + public float Progress + { + get => _progressBar.value; + set => _progressBar.value = value; + } + // Event Handlers ----------------------------------------------------- + public event Action OnSessionButtonClicked; + public event Action OnSendChatButtonClicked; + + #endregion ------------------------------------------------------------ + + #region -- MonoBehaviour Methods -------------------------------------- private void Awake() { _uiDocument = GetComponent(); @@ -51,12 +87,11 @@ namespace PPGIA.X540.Project3 _sendChatButton = _root.Q