From 4fb951c0bfffab1c1910245beeb1505a451077ab Mon Sep 17 00:00:00 2001 From: MysterD Date: Sun, 11 Jul 2021 01:48:37 -0700 Subject: [PATCH] Fix commandline params for client/server --- src/pc/djui/djui.c | 18 ++++++++++++++---- src/pc/djui/djui.h | 2 ++ src/pc/djui/djui_cursor.c | 2 ++ src/pc/djui/djui_panel.c | 9 +++++++++ src/pc/djui/djui_panel.h | 1 + src/pc/network/discord/activity.c | 1 + src/pc/network/network.c | 5 ----- src/pc/network/network.h | 1 - .../packets/packet_level_respawn_info.c | 2 +- src/pc/network/packets/packet_object.c | 2 +- src/pc/network/socket/socket.c | 1 + src/pc/pc_main.c | 3 +++ 12 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/pc/djui/djui.c b/src/pc/djui/djui.c index d751345a..f861a327 100644 --- a/src/pc/djui/djui.c +++ b/src/pc/djui/djui.c @@ -1,19 +1,30 @@ #include "djui.h" #include "../debuglog.h" +#include "pc/cliopts.h" static Gfx* sSavedDisplayListHead = NULL; struct DjuiRoot* gDjuiRoot = NULL; struct DjuiFlowLayout* buttonContainer; -static void djui_init(void) { +void djui_init(void) { gDjuiRoot = djui_root_create(); - djui_panel_main_create(NULL); - //djui_panel_debug_create(); + if (gCLIOpts.Network != NT_SERVER) { + djui_panel_main_create(NULL); + //djui_panel_debug_create(); + } + djui_cursor_create(); } +void djui_connect_menu_open(void) { + djui_panel_shutdown(); + djui_panel_main_create(NULL); + djui_panel_join_create(NULL); + djui_panel_join_message_create(NULL); +} + void djui_render_patch(void) { // reset the head and re-render DJUI if (sSavedDisplayListHead == NULL) { return; } @@ -24,7 +35,6 @@ void djui_render_patch(void) { } void djui_render(void) { - if (gDjuiRoot == NULL) { djui_init(); } sSavedDisplayListHead = gDisplayListHead; create_dl_ortho_matrix(); diff --git a/src/pc/djui/djui.h b/src/pc/djui/djui.h index 4e0736d8..1bf0a7b7 100644 --- a/src/pc/djui/djui.h +++ b/src/pc/djui/djui.h @@ -45,5 +45,7 @@ extern struct DjuiRoot* gDjuiRoot; +void djui_init(void); +void djui_connect_menu_open(void); void djui_render_patch(void); void djui_render(void); diff --git a/src/pc/djui/djui_cursor.c b/src/pc/djui/djui_cursor.c index 6acf0704..acf3c21b 100644 --- a/src/pc/djui/djui_cursor.c +++ b/src/pc/djui/djui_cursor.c @@ -99,6 +99,8 @@ void djui_cursor_move(s8 xDir, s8 yDir) { void djui_cursor_update(void) { #if defined(CAPI_SDL2) || defined(CAPI_SDL1) if (djui_interactable_is_binding()) { return; } + if (sMouseCursor == NULL) { return; } + if (!djui_panel_is_active()) { return; } controller_sdl_read_mouse_window(); diff --git a/src/pc/djui/djui_panel.c b/src/pc/djui/djui_panel.c index 962c7d7b..02182f64 100644 --- a/src/pc/djui/djui_panel.c +++ b/src/pc/djui/djui_panel.c @@ -13,6 +13,10 @@ static struct DjuiPanel* sPanelList = NULL; static struct DjuiPanel* sPanelRemoving = NULL; static f32 sMoveAmount = 0; +bool djui_panel_is_active(void) { + return (sPanelList != NULL); +} + void djui_panel_add(struct DjuiBase* caller, struct DjuiBase* panelBase, struct DjuiBase* defaultElementBase) { bool firstPanel = (sPanelList == NULL); gDjuiPanelJoinMessageVisible = false; @@ -22,6 +26,11 @@ void djui_panel_add(struct DjuiBase* caller, struct DjuiBase* panelBase, struct sPanelList->defaultElementBase = caller; } + // hide second from the top immediately + if (sPanelList != NULL && sPanelList->parent != NULL) { + djui_base_set_visible(sPanelList->parent->base, false); + } + // allocate panel struct DjuiPanel* panel = malloc(sizeof(struct DjuiPanel)); panel->parent = sPanelList; diff --git a/src/pc/djui/djui_panel.h b/src/pc/djui/djui_panel.h index e802312c..2b077c5f 100644 --- a/src/pc/djui/djui_panel.h +++ b/src/pc/djui/djui_panel.h @@ -4,6 +4,7 @@ #define DJUI_DEFAULT_PANEL_WIDTH (400.0f + (16 * 2.0f)) #define DJUI_PANEL_HEADER_OFFSET (-8) +bool djui_panel_is_active(void); void djui_panel_add(struct DjuiBase* caller, struct DjuiBase* panelBase, struct DjuiBase* defaultElementBase); void djui_panel_back(void); void djui_panel_update(void); diff --git a/src/pc/network/discord/activity.c b/src/pc/network/discord/activity.c index e4aa213c..ba6ea9e6 100644 --- a/src/pc/network/discord/activity.c +++ b/src/pc/network/discord/activity.c @@ -3,6 +3,7 @@ #include "discord_network.h" #include "pc/debuglog.h" #include "pc/network/version.h" +#include "pc/djui/djui.h" #define HASH_LENGTH 8 struct DiscordActivity gCurActivity = { 0 }; diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 79594db3..a516b955 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -283,8 +283,3 @@ void chat_add_message(char* message) { void djui_show_popup(char* message) { LOG_INFO("popup: %s", message); } - -// TODO: replace -void djui_connect_menu_open(void) { - LOG_INFO("djui: connecting"); -} diff --git a/src/pc/network/network.h b/src/pc/network/network.h index 99e114ee..df372d50 100644 --- a/src/pc/network/network.h +++ b/src/pc/network/network.h @@ -104,5 +104,4 @@ void network_shutdown(bool sendLeaving); // TODO: replace void chat_add_message(char* message); void djui_show_popup(char* message); -void djui_connect_menu_open(void); #endif diff --git a/src/pc/network/packets/packet_level_respawn_info.c b/src/pc/network/packets/packet_level_respawn_info.c index 2506c676..3e63da61 100644 --- a/src/pc/network/packets/packet_level_respawn_info.c +++ b/src/pc/network/packets/packet_level_respawn_info.c @@ -93,7 +93,7 @@ static u16 get_spawn_info_index_of_object(struct Object* o) { //// void network_send_level_respawn_info(struct Object* o, u8 respawnInfoBits) { - if (gNetworkType == NT_NONE) { return; } + if (gNetworkType == NT_NONE || gNetworkPlayerLocal == NULL) { return; } // make sure our area is valid if (!gNetworkPlayerLocal->currAreaSyncValid) { diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c index 93aa55cf..b1d206c4 100644 --- a/src/pc/network/packets/packet_object.c +++ b/src/pc/network/packets/packet_object.c @@ -383,7 +383,7 @@ static void packet_read_object_only_death(struct Packet* p, struct Object* o) { // ----- main send/receive ----- // void network_send_object(struct Object* o) { - if (gNetworkType == NT_NONE) { return; } + if (gNetworkType == NT_NONE || gNetworkPlayerLocal == NULL) { return; } // sanity check SyncObject if (!network_sync_object_initialized(o)) { return; } diff --git a/src/pc/network/socket/socket.c b/src/pc/network/socket/socket.c index f3dce82f..19d25f4e 100644 --- a/src/pc/network/socket/socket.c +++ b/src/pc/network/socket/socket.c @@ -2,6 +2,7 @@ #include "socket.h" #include "pc/configfile.h" #include "pc/debuglog.h" +#include "pc/djui/djui.h" static SOCKET curSocket = INVALID_SOCKET; static struct sockaddr_in addr[MAX_PLAYERS] = { 0 }; diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 67ea5245..7325ceff 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -42,6 +42,7 @@ #include "pc/discord/discordrpc.h" #endif #include "pc/network/version.h" +#include "pc/djui/djui.h" OSMesg D_80339BEC; OSMesgQueue gSIEventMesgQueue; @@ -266,6 +267,8 @@ void main_func(void) { audio_api = &audio_null; } + djui_init(); + if (gCLIOpts.Network == NT_CLIENT) { network_set_system(NS_SOCKET); strncpy(configJoinIp, gCLIOpts.JoinIp, IP_MAX_LEN);