Update Setting
This commit is contained in:
@@ -109,11 +109,16 @@ namespace Hallucinate.UI
|
||||
_chatInput.RegisterCallback<KeyDownEvent>(OnChatKeyDown, TrickleDown.TrickleDown);
|
||||
}
|
||||
|
||||
if (LocalizationManager.Instance != null)
|
||||
{
|
||||
LocalizationManager.Instance.OnLanguageChanged += ApplyLocalization;
|
||||
ApplyLocalization();
|
||||
}
|
||||
|
||||
// Đăng ký sự kiện từ Spawner
|
||||
if (BasicSpawner.Instance != null)
|
||||
{
|
||||
RegisterSpawnerEvents();
|
||||
_ = BasicSpawner.Instance.StartLobby();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -127,7 +132,6 @@ namespace Hallucinate.UI
|
||||
BasicSpawner.Instance.OnSessionListUpdatedEvent += UpdateRoomList;
|
||||
BasicSpawner.Instance.OnJoinFailedEvent += () => { if(_joinPassError != null) _joinPassError.style.display = DisplayStyle.Flex; };
|
||||
BasicSpawner.Instance.OnJoinStartedEvent += () => { };
|
||||
_ = BasicSpawner.Instance.StartLobby();
|
||||
}
|
||||
|
||||
private void OnChatKeyDown(KeyDownEvent evt)
|
||||
@@ -180,6 +184,96 @@ namespace Hallucinate.UI
|
||||
box.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (LocalizationManager.Instance != null)
|
||||
{
|
||||
LocalizationManager.Instance.OnLanguageChanged -= ApplyLocalization;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyLocalization()
|
||||
{
|
||||
if (LocalizationManager.Instance == null) return;
|
||||
|
||||
// JOIN VIEW
|
||||
var joinHeading = root.Q<Label>(null, "text-heading"); // Header in JoinContainer
|
||||
if (joinHeading != null && _joinContainer.Contains(joinHeading)) joinHeading.text = GetT("LOBBY_FIND_SESSIONS");
|
||||
|
||||
var searchInput = root.Q<TextField>("SearchInput");
|
||||
if (searchInput != null) searchInput.textEdition.placeholder = GetT("LOBBY_SEARCH_PLACEHOLDER");
|
||||
|
||||
var backBtn = root.Q<Button>("BackToMenuBtn");
|
||||
if (backBtn != null) backBtn.text = GetT("LOBBY_BACK");
|
||||
|
||||
var goToCreateBtn = root.Q<Button>("GoToCreateBtn");
|
||||
if (goToCreateBtn != null) goToCreateBtn.text = GetT("LOBBY_CREATE_NEW");
|
||||
|
||||
// CREATE VIEW
|
||||
var createHeading = root.Q<Label>(null, "text-heading"); // Header in CreateContainer
|
||||
// Note: Querying by class might be ambiguous if multiple exist, better to find within container
|
||||
var createHeader = _createContainer?.Q<Label>(null, "text-heading");
|
||||
if (createHeader != null) createHeader.text = GetT("LOBBY_CREATE_HEADER");
|
||||
|
||||
var roomIdLabel = _createContainer?.Q<Label>(null, "text-label"); // First label is usually ID
|
||||
// Since they don't have unique names, we'll try to find them by order or text match
|
||||
_createContainer?.Query<Label>().ForEach(l => {
|
||||
if (l.text.Contains("ROOM ID")) l.text = GetT("LOBBY_ROOM_ID_LABEL");
|
||||
if (l.text.Contains("ROOM NAME")) l.text = GetT("LOBBY_ROOM_NAME_LABEL");
|
||||
});
|
||||
|
||||
if (_roomIDInput != null) _roomIDInput.textEdition.placeholder = GetT("LOBBY_ROOM_ID_PLACEHOLDER");
|
||||
if (_roomNameInput != null) _roomNameInput.textEdition.placeholder = GetT("LOBBY_ROOM_NAME_PLACEHOLDER");
|
||||
if (_passToggle != null) _passToggle.label = GetT("LOBBY_REQUIRE_PASS");
|
||||
if (_roomPassInput != null) _roomPassInput.textEdition.placeholder = GetT("LOBBY_PASS_PLACEHOLDER");
|
||||
|
||||
var cancelCreateBtn = root.Q<Button>("CancelCreateBtn");
|
||||
if (cancelCreateBtn != null) cancelCreateBtn.text = GetT("LOBBY_CANCEL");
|
||||
|
||||
var confirmCreateBtn = root.Q<Button>("ConfirmCreateBtn");
|
||||
if (confirmCreateBtn != null) confirmCreateBtn.text = GetT("LOBBY_CREATE_BTN");
|
||||
|
||||
// LOUNGE VIEW
|
||||
if (_loungeRoomName != null && _loungeRoomName.text == "SESSION NAME")
|
||||
_loungeRoomName.text = GetT("LOBBY_SESSION_NAME_DEFAULT");
|
||||
|
||||
var loungeIdLabel = root.Q<Label>("LoungeID");
|
||||
if (loungeIdLabel != null)
|
||||
{
|
||||
string currentId = loungeIdLabel.text.Replace("ID: ", "");
|
||||
loungeIdLabel.text = GetT("LOBBY_ID_PREFIX") + currentId;
|
||||
}
|
||||
|
||||
var vsLabel = _loungeContainer?.Q<Label>(null); // VS label doesn't have name
|
||||
_loungeContainer?.Query<Label>().ForEach(l => {
|
||||
if (l.text == "VS") l.text = GetT("LOBBY_VS");
|
||||
});
|
||||
|
||||
if (_chatInput != null) _chatInput.textEdition.placeholder = GetT("LOBBY_CHAT_PLACEHOLDER");
|
||||
|
||||
var leaveLoungeBtn = root.Q<Button>("LeaveLoungeBtn");
|
||||
if (leaveLoungeBtn != null) leaveLoungeBtn.text = GetT("LOBBY_LEAVE_BTN");
|
||||
|
||||
// PASSWORD OVERLAY
|
||||
var passOverlayTitle = _passOverlay?.Q<Label>(null, "text-subheading");
|
||||
if (passOverlayTitle != null) passOverlayTitle.text = GetT("LOBBY_PROTECTED_TITLE");
|
||||
|
||||
var passOverlayDesc = _passOverlay?.Q<Label>(null, "text-label");
|
||||
if (passOverlayDesc != null && passOverlayDesc.text.Contains("requires a password"))
|
||||
passOverlayDesc.text = GetT("LOBBY_PROTECTED_DESC");
|
||||
|
||||
if (_joinPassInput != null) _joinPassInput.textEdition.placeholder = GetT("LOBBY_JOIN_PASS_PLACEHOLDER");
|
||||
if (_joinPassError != null) _joinPassError.text = GetT("LOBBY_JOIN_PASS_ERROR");
|
||||
|
||||
var closePassBtn = root.Q<Button>("ClosePassBtn");
|
||||
if (closePassBtn != null) closePassBtn.text = GetT("LOBBY_CANCEL");
|
||||
|
||||
var confirmJoinBtn = root.Q<Button>("ConfirmJoinBtn");
|
||||
if (confirmJoinBtn != null) confirmJoinBtn.text = GetT("LOBBY_JOIN_BTN");
|
||||
}
|
||||
|
||||
private string GetT(string key) => LocalizationManager.Instance != null ? LocalizationManager.Instance.GetLocalizedString(key) : key;
|
||||
|
||||
public void SetRoomTemplate(VisualTreeAsset template) => _roomItemTemplate = template;
|
||||
|
||||
public override async Task PlayTransitionIn()
|
||||
@@ -218,8 +312,13 @@ namespace Hallucinate.UI
|
||||
|
||||
private async void OnCreateRoomClicked()
|
||||
{
|
||||
Debug.Log("[LobbyController] Create Room Clicked");
|
||||
var spawner = BasicSpawner.Instance;
|
||||
if (spawner == null) return;
|
||||
if (spawner == null)
|
||||
{
|
||||
Debug.LogError("[LobbyController] Spawner Instance is NULL!");
|
||||
return;
|
||||
}
|
||||
|
||||
string id = _roomIDInput != null && !string.IsNullOrEmpty(_roomIDInput.value)
|
||||
? _roomIDInput.value.Trim()
|
||||
@@ -264,12 +363,19 @@ namespace Hallucinate.UI
|
||||
item.Q<Label>("RoomName").text = displayName;
|
||||
item.Q<Label>("PlayerCount").text = $"{session.PlayerCount}/{session.MaxPlayers}";
|
||||
|
||||
var statusBadge = item.Q<Label>("StatusBadge");
|
||||
if (statusBadge != null) statusBadge.text = GetT("ROOM_STATUS_WAITING");
|
||||
|
||||
bool needsPass = session.Properties.ContainsKey("pw");
|
||||
var lockIcon = item.Q<Label>("LockIcon");
|
||||
if (lockIcon != null) lockIcon.style.display = needsPass ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
|
||||
var joinBtn = item.Q<Button>("JoinBtn");
|
||||
if (joinBtn != null) joinBtn.clicked += () => OnRoomItemClicked(session);
|
||||
if (joinBtn != null)
|
||||
{
|
||||
joinBtn.text = GetT("ROOM_JOIN_BTN");
|
||||
joinBtn.clicked += () => OnRoomItemClicked(session);
|
||||
}
|
||||
|
||||
_roomList.Add(item);
|
||||
}
|
||||
@@ -381,12 +487,12 @@ namespace Hallucinate.UI
|
||||
if (hostRef != PlayerRef.None && _playerDataManager.TryGetPlayerMetaData(hostRef, out var hostData))
|
||||
{
|
||||
_hostNameLabel.text = hostData.Name.ToString().ToUpper();
|
||||
_hostStatusLabel.text = hostData.IsReady ? "READY" : "NOT READY";
|
||||
_hostStatusLabel.text = hostData.IsReady ? GetT("LOBBY_READY") : GetT("LOBBY_NOT_READY");
|
||||
_hostStatusLabel.style.color = hostData.IsReady ? Color.green : Color.red;
|
||||
}
|
||||
else if (hostRef != PlayerRef.None)
|
||||
{
|
||||
_hostNameLabel.text = "SYNCING...";
|
||||
_hostNameLabel.text = GetT("LOBBY_SYNCING");
|
||||
_hostStatusLabel.text = "-";
|
||||
}
|
||||
|
||||
@@ -394,17 +500,17 @@ namespace Hallucinate.UI
|
||||
if (guestRef != PlayerRef.None && _playerDataManager.TryGetPlayerMetaData(guestRef, out var guestData))
|
||||
{
|
||||
_guestNameLabel.text = guestData.Name.ToString().ToUpper();
|
||||
_guestStatusLabel.text = guestData.IsReady ? "READY" : "NOT READY";
|
||||
_guestStatusLabel.text = guestData.IsReady ? GetT("LOBBY_READY") : GetT("LOBBY_NOT_READY");
|
||||
_guestStatusLabel.style.color = guestData.IsReady ? Color.green : Color.red;
|
||||
}
|
||||
else if (runner.ActivePlayers.Count() >= 2)
|
||||
{
|
||||
_guestNameLabel.text = "SYNCING...";
|
||||
_guestNameLabel.text = GetT("LOBBY_SYNCING");
|
||||
_guestStatusLabel.text = "-";
|
||||
}
|
||||
else
|
||||
{
|
||||
_guestNameLabel.text = "WAITING...";
|
||||
_guestNameLabel.text = GetT("LOBBY_WAITING_LABEL");
|
||||
_guestStatusLabel.text = "-";
|
||||
_guestStatusLabel.style.color = Color.gray;
|
||||
}
|
||||
@@ -429,6 +535,7 @@ namespace Hallucinate.UI
|
||||
|
||||
if (_startBtn != null)
|
||||
{
|
||||
_startBtn.text = GetT("LOBBY_START_BTN");
|
||||
_startBtn.style.display = isHost ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
_startBtn.SetEnabled(allReady && playerCount >= 2);
|
||||
}
|
||||
@@ -440,13 +547,13 @@ namespace Hallucinate.UI
|
||||
// Style for Ready Button
|
||||
if (myData.IsReady)
|
||||
{
|
||||
_readyBtn.text = "UNREADY";
|
||||
_readyBtn.text = GetT("LOBBY_UNREADY_BTN");
|
||||
_readyBtn.style.backgroundColor = new StyleColor(Color.green);
|
||||
_readyBtn.style.color = new StyleColor(Color.black);
|
||||
}
|
||||
else
|
||||
{
|
||||
_readyBtn.text = "READY UP";
|
||||
_readyBtn.text = GetT("LOBBY_READY_BTN");
|
||||
_readyBtn.style.backgroundColor = new StyleColor(new Color(0.2f, 0.2f, 0.2f, 0.8f));
|
||||
_readyBtn.style.color = new StyleColor(Color.white);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user