Updates GUI for new working flow.

This commit is contained in:
Jonas Luz Jr. 2025-11-26 13:24:33 -03:00
parent 6c1ed05bd7
commit ea4535ebb6
4 changed files with 67 additions and 69 deletions

View File

@ -2,6 +2,5 @@
}
.expandable {
flex-grow: 1;
white-space: normal;
}

View File

@ -1,11 +1,10 @@
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Style src="project://database/Assets/_Client/GUI/Main.uss?fileID=7433441132597879392&amp;guid=fe550b4c3daa62b448a38ddf615910a6&amp;type=3#Main" />
<ui:VisualElement name="VE_Panel" style="flex-grow: 1;">
<ui:Button text="Iniciar sessão" name="B_Session" />
<ui:Label text="Chat:" />
<ui:TextField placeholder-text="Digite sua mensagem" name="TF_ChatInput" class="expandable" />
<ui:Button text="Enviar mensagem" name="B_SendChat" />
<ui:Button text="Falar..." name="B_Talk" />
<ui:ProgressBar value="0" title="Processando... Por favor, espere..." name="PB_Progress" enabled="true" />
<ui:TextField placeholder-text="response" multiline="true" readonly="true" name="TF_ChatOutput" class="expandable" />
<ui:ScrollView>
<ui:TextField placeholder-text="response" multiline="true" readonly="true" name="TF_Dialogue" class="expandable" />
</ui:ScrollView>
</ui:VisualElement>
</ui:UXML>

View File

@ -6,40 +6,28 @@ using UnityEngine.UIElements;
namespace PPGIA.X540.Project3
{
[RequireComponent(typeof(UIController))]
[RequireComponent(typeof(UIDocument))]
public class UIController : MonoBehaviour
{
public enum UIState
{
Idle = 0,
Recording = 1,
Processing = 2
}
private UIDocument _uiDocument;
private VisualElement _root;
#region -- Fields & Properties ----------------------------------------
// Buttons ------------------------------------------------------------
private readonly string[] _sessionButtonLabels = {
"Iniciar Sessão",
"Encerrar Sessão"
private readonly string[] _sendChatButtonLabels = {
"Falar...",
"Enviar...",
"Processando... Aguarde..."
};
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;
public string ChatInput
{
get => _chatInputField.value;
set => _chatInputField.value = value;
}
// UI controls --------------------------------------------------------
private Button _talkButton;
private TextField _chatOutputField;
public string ChatOutput
@ -48,22 +36,6 @@ namespace PPGIA.X540.Project3
set => _chatOutputField.value = value;
}
public bool InputEnabled
{
get
{
var value = _chatInputField.enabledSelf;
_sendChatButton.SetEnabled(value);
return value;
}
set
{
_chatInputField.SetEnabled(value);
_sendChatButton.SetEnabled(value);
}
}
// Progress Bar -------------------------------------------------------
private ProgressBar _progressBar;
public float Progress
{
@ -71,9 +43,30 @@ namespace PPGIA.X540.Project3
set => _progressBar.value = value;
}
// State management ---------------------------------------------------
private UIState _currentState = UIState.Idle;
public UIState CurrentState
{
get => _currentState;
set
{
_currentState = value;
_talkButton.text = _sendChatButtonLabels[(int)value];
if (value == UIState.Processing)
{
_talkButton.SetEnabled(false);
_progressBar.value = 0.5f;
}
else
{
_talkButton.SetEnabled(true);
_progressBar.value = 0f;
}
}
}
// Event Handlers -----------------------------------------------------
public event Action OnSessionButtonClicked;
public event Action<string> OnSendChatButtonClicked;
public event Action OnTalkButtonClicked;
#endregion ------------------------------------------------------------
@ -83,36 +76,43 @@ namespace PPGIA.X540.Project3
_uiDocument = GetComponent<UIDocument>();
_root = _uiDocument.rootVisualElement;
_sessionButton = _root.Q<Button>("B_Session");
_sendChatButton = _root.Q<Button>("B_SendChat");
_chatInputField = _root.Q<TextField>("TF_ChatInput");
_chatOutputField = _root.Q<TextField>("TF_ChatOutput");
_talkButton = _root.Q<Button>("B_Talk");
if (_talkButton == null)
{
Debug.LogError("Talk Button not found in UI.");
}
_progressBar = _root.Q<ProgressBar>("PB_Progress");
if (_progressBar == null)
{
Debug.LogError("Progress Bar not found in UI.");
}
void OnEnable()
_chatOutputField = _root.Q<TextField>("TF_Dialogue");
if (_chatOutputField == null)
{
_sessionButton.clicked += OnSessionButtonClickedInternal;
_sendChatButton.clicked += OnSendChatButtonClickedInternal;
Debug.LogError("Chat Output Field not found in UI.");
}
void OnDisable()
CurrentState = UIState.Idle;
}
private void OnEnable()
{
_sessionButton.clicked -= OnSessionButtonClickedInternal;
_sendChatButton.clicked -= OnSendChatButtonClickedInternal;
_talkButton.clicked += OnTalkButtonClickedInternal;
}
private void OnDisable()
{
_talkButton.clicked -= OnTalkButtonClickedInternal;
}
#endregion ------------------------------------------------------------
private void OnSessionButtonClickedInternal()
{
OnSessionButtonClicked?.Invoke();
// SessionActive state should be updated externally, no logic here.
}
private void OnTalkButtonClickedInternal() => OnTalkButtonClicked?.Invoke();
private void OnSendChatButtonClickedInternal()
public void AppendChatOutput(string newText)
{
OnSendChatButtonClicked?.Invoke(_chatInputField.value);
_chatInputField.value = string.Empty;
ChatOutput += newText;
}
}
}

View File

@ -29,7 +29,7 @@ MonoBehaviour:
m_Match: 0
m_SortingOrder: 0
m_TargetDisplay: 0
m_BindingLogLevel: 0
m_BindingLogLevel: 2
m_ClearDepthStencil: 1
m_ClearColor: 0
m_ColorClearValue: {r: 0, g: 0, b: 0, a: 0}