From 362546a81a8d63f0561d907ff28176a0b50d9362 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 14 Apr 2023 19:58:36 -0700 Subject: [PATCH] Added messages to lobby list when no lobbies found, or coopnet connection fails --- lang/English.ini | 3 ++- src/pc/djui/djui_panel_join_lobbies.c | 17 +++++++++++++++-- src/pc/network/coopnet/coopnet.c | 7 ++++--- src/pc/network/coopnet/coopnet.h | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lang/English.ini b/lang/English.ini index 96917c59..ebabbfc4 100644 --- a/lang/English.ini +++ b/lang/English.ini @@ -333,4 +333,5 @@ PRIVATE_LOBBIES = "PRIVATE LOBBIES" REFRESH = "Refresh" REFRESHING = "Refreshing..." ENTER_PASSWORD = "Enter the private lobby's password:" -SEARCH = "Search" \ No newline at end of file +SEARCH = "Search" +NONE_FOUND = "No lobbies were found." diff --git a/src/pc/djui/djui_panel_join_lobbies.c b/src/pc/djui/djui_panel_join_lobbies.c index e122df98..5ea54474 100644 --- a/src/pc/djui/djui_panel_join_lobbies.c +++ b/src/pc/djui/djui_panel_join_lobbies.c @@ -51,6 +51,13 @@ void djui_panel_join_query_finish(void) { if (!sRefreshButton) { return; } djui_text_set_text(sRefreshButton->text, DLANG(LOBBIES, REFRESH)); djui_base_set_enabled(&sRefreshButton->base, true); + + if (sLobbyLayout->base.child == NULL) { + struct DjuiText* text = djui_text_create(&sLobbyLayout->base, DLANG(LOBBIES, NONE_FOUND)); + djui_base_set_size_type(&text->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE); + djui_base_set_size(&text->base, 1, 1); + djui_text_set_alignment(text, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER); + } } void djui_panel_join_lobbies_on_destroy(UNUSED struct DjuiBase* caller) { @@ -71,7 +78,7 @@ void djui_panel_join_lobbies_create(struct DjuiBase* caller, const char* passwor if (sPassword) { free(sPassword); sPassword = NULL; } sPassword = strdup(password); bool private = (strlen(password) > 0); - ns_coopnet_query(djui_panel_join_query, djui_panel_join_query_finish, password); + bool querying = ns_coopnet_query(djui_panel_join_query, djui_panel_join_query_finish, password); struct DjuiBase* defaultBase = NULL; struct DjuiThreePanel* panel = djui_panel_menu_create(private ? DLANG(LOBBIES, PRIVATE_LOBBIES) : DLANG(LOBBIES, PUBLIC_LOBBIES)); @@ -92,6 +99,12 @@ void djui_panel_join_lobbies_create(struct DjuiBase* caller, const char* passwor } djui_paginated_calculate_height(paginated); #endif + if (!querying) { + struct DjuiText* text = djui_text_create(&sLobbyLayout->base, DLANG(NOTIF, COOPNET_CONNECTION_FAILED)); + djui_base_set_size_type(&text->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE); + djui_base_set_size(&text->base, 1, 1); + djui_text_set_alignment(text, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER); + } struct DjuiRect* rect2 = djui_rect_container_create(body, 64); { @@ -99,7 +112,7 @@ void djui_panel_join_lobbies_create(struct DjuiBase* caller, const char* passwor djui_base_set_size(&button1->base, 0.485f, 64); djui_base_set_alignment(&button1->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP); - sRefreshButton = djui_button_create(&rect2->base, DLANG(LOBBIES, REFRESHING), DJUI_BUTTON_STYLE_NORMAL, djui_panel_join_lobbies_refresh); + sRefreshButton = djui_button_create(&rect2->base, querying ? DLANG(LOBBIES, REFRESHING) : DLANG(LOBBIES, REFRESH), DJUI_BUTTON_STYLE_NORMAL, djui_panel_join_lobbies_refresh); djui_base_set_size(&sRefreshButton->base, 0.485f, 64); djui_base_set_alignment(&sRefreshButton->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP); djui_base_set_enabled(&sRefreshButton->base, false); diff --git a/src/pc/network/coopnet/coopnet.c b/src/pc/network/coopnet/coopnet.c index 75703176..9bdec2b7 100644 --- a/src/pc/network/coopnet/coopnet.c +++ b/src/pc/network/coopnet/coopnet.c @@ -20,11 +20,12 @@ static enum NetworkType sNetworkType; static CoopNetRc coopnet_initialize(void); -void ns_coopnet_query(QueryCallbackPtr callback, QueryFinishCallbackPtr finishCallback, const char* password) { +bool ns_coopnet_query(QueryCallbackPtr callback, QueryFinishCallbackPtr finishCallback, const char* password) { gCoopNetCallbacks.OnLobbyListGot = callback; gCoopNetCallbacks.OnLobbyListFinish = finishCallback; - if (coopnet_initialize() != COOPNET_OK) { return; } - coopnet_lobby_list_get(CN_GAME_STR, password); + if (coopnet_initialize() != COOPNET_OK) { return false; } + if (coopnet_lobby_list_get(CN_GAME_STR, password) != COOPNET_OK) { return false; } + return true; } static void coopnet_on_connected(uint64_t userId) { diff --git a/src/pc/network/coopnet/coopnet.h b/src/pc/network/coopnet/coopnet.h index 9ae9f935..a9667280 100644 --- a/src/pc/network/coopnet/coopnet.h +++ b/src/pc/network/coopnet/coopnet.h @@ -8,7 +8,7 @@ typedef void (*QueryFinishCallbackPtr)(void); extern struct NetworkSystem gNetworkSystemCoopNet; extern uint64_t gCoopNetDesiredLobby; -void ns_coopnet_query(QueryCallbackPtr callback, QueryFinishCallbackPtr finishCallback, const char* password); +bool ns_coopnet_query(QueryCallbackPtr callback, QueryFinishCallbackPtr finishCallback, const char* password); bool ns_coopnet_is_connected(void); void ns_coopnet_update(void);