From b1bb8fe8c022684e86a853ee90b0faf496845341 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:54:55 -0400 Subject: [PATCH 1/3] Fix SDL issue (#1870) (#1871) (cherry picked from commit cc7f831ec1d94c717fc088263865b4cff3050e19) Co-authored-by: David Chavez --- soh/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/soh/CMakeLists.txt b/soh/CMakeLists.txt index 490e554a5..5b8498b6b 100644 --- a/soh/CMakeLists.txt +++ b/soh/CMakeLists.txt @@ -1699,7 +1699,7 @@ find_package(SDL2) set(SDL2-INCLUDE ${SDL2_INCLUDE_DIRS}) if (CMAKE_SYSTEM_NAME STREQUAL "Windows") - find_package(SDL2-net) + find_package(SDL2_net) set(SDL2-NET-INCLUDE ${SDL_NET_INCLUDE_DIRS}) endif() @@ -1972,7 +1972,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows") "glu32;" "SDL2::SDL2;" "SDL2::SDL2main;" - "SDL2::SDL2_net;" + "SDL2_net::SDL2_net-static;" "glfw;" "winmm;" "imm32;" From 6c30d7a435fabe05c98bf612f6cb2d3da2d87d17 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 31 Oct 2022 22:23:41 +0100 Subject: [PATCH 2/3] Fix Piece of Heart sound (#1862) (#1876) --- soh/src/overlays/actors/ovl_player_actor/z_player.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index dabafa2c9..25f6cf8ca 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -12564,12 +12564,12 @@ s32 func_8084DFF4(GlobalContext* globalCtx, Player* this) { Audio_PlaySoundGeneral(NA_SE_SY_GET_BOXITEM, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } else { if ((giEntry.itemId == ITEM_HEART_CONTAINER) || - ((giEntry.itemId == ITEM_HEART_PIECE) && + ((giEntry.itemId == ITEM_HEART_PIECE_2) && ((gSaveContext.inventory.questItems & 0xF0000000) == 0x40000000))) { temp1 = NA_BGM_HEART_GET | 0x900; } else { temp1 = temp2 = - (giEntry.itemId == ITEM_HEART_PIECE) ? NA_BGM_SMALL_ITEM_GET : NA_BGM_ITEM_GET | 0x900; + (giEntry.itemId == ITEM_HEART_PIECE_2) ? NA_BGM_SMALL_ITEM_GET : NA_BGM_ITEM_GET | 0x900; } Audio_PlayFanfare(temp1); } From 2f96e2813565e238d54cfda04833ebe4090babfb Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Tue, 1 Nov 2022 22:58:09 -0400 Subject: [PATCH 3/3] fix: show/hide cursors properly (#1829) --- libultraship/libultraship/ImGuiImpl.cpp | 35 +++++++------------ libultraship/libultraship/ImGuiImpl.h | 2 +- .../libultraship/Lib/Fast3D/gfx_dxgi.cpp | 23 ++++++++---- .../libultraship/Lib/Fast3D/gfx_sdl2.cpp | 10 ++++-- .../Lib/Fast3D/gfx_window_manager_api.h | 2 +- libultraship/libultraship/Window.cpp | 20 +++++------ libultraship/libultraship/Window.h | 2 +- 7 files changed, 47 insertions(+), 47 deletions(-) diff --git a/libultraship/libultraship/ImGuiImpl.cpp b/libultraship/libultraship/ImGuiImpl.cpp index d26d0243c..98678cab1 100644 --- a/libultraship/libultraship/ImGuiImpl.cpp +++ b/libultraship/libultraship/ImGuiImpl.cpp @@ -401,8 +401,11 @@ namespace SohImGui { #endif Ship::RegisterHook([] { - if (Window::GetInstance()->IsFullscreen()) - ShowCursor(CVar_GetS32("gOpenMenuBar", 0), Dialogues::dLoadSettings); + bool menuBarOpen = CVar_GetS32("gOpenMenuBar", 0); + Window::GetInstance()->SetMenuBar(menuBarOpen); + if (Window::GetInstance()->IsFullscreen()) { + SetCursorVisibility(menuBarOpen); + } LoadTexture("Game_Icon", "assets/ship_of_harkinian/icons/gSohIcon.png"); LoadTexture("A-Btn", "assets/ship_of_harkinian/buttons/ABtn.png"); @@ -482,11 +485,13 @@ namespace SohImGui { if (ImGui::IsKeyPressed(TOGGLE_BTN) || (ImGui::IsKeyPressed(TOGGLE_PAD_BTN) && CVar_GetS32("gControlNav", 0))) { - bool menu_bar = CVar_GetS32("gOpenMenuBar", 0); - CVar_SetS32("gOpenMenuBar", !menu_bar); + bool menu_bar = !CVar_GetS32("gOpenMenuBar", 0); + CVar_SetS32("gOpenMenuBar", menu_bar); needs_save = true; Window::GetInstance()->SetMenuBar(menu_bar); - ShowCursor(menu_bar, Dialogues::dMenubar); + if (Window::GetInstance()->IsFullscreen()) { + SetCursorVisibility(menu_bar); + } Window::GetInstance()->GetControlDeck()->SaveControllerSettings(); if (CVar_GetS32("gControlNav", 0) && CVar_GetS32("gOpenMenuBar", 0)) { io->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; @@ -918,24 +923,8 @@ namespace SohImGui { DefaultAssets[name] = asset; } - void ShowCursor(bool hide, Dialogues d) { - if (d == Dialogues::dLoadSettings) { - Window::GetInstance()->ShowCursor(hide); - return; - } - - if (d == Dialogues::dConsole && CVar_GetS32("gOpenMenuBar", 0)) { - return; - } - if (!Window::GetInstance()->IsFullscreen()) { - oldCursorState = false; - return; - } - - if (oldCursorState != hide) { - oldCursorState = hide; - Window::GetInstance()->ShowCursor(hide); - } + void SetCursorVisibility(bool visible) { + Window::GetInstance()->SetCursorVisibility(visible); } void BeginGroupPanel(const char* name, const ImVec2& size) { diff --git a/libultraship/libultraship/ImGuiImpl.h b/libultraship/libultraship/ImGuiImpl.h index 3de813f76..9c1cd550c 100644 --- a/libultraship/libultraship/ImGuiImpl.h +++ b/libultraship/libultraship/ImGuiImpl.h @@ -110,7 +110,7 @@ namespace SohImGui { ImTextureID GetTextureByName(const std::string& name); void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint = ImVec4(1, 1, 1, 1)); - void ShowCursor(bool hide, Dialogues w); + void SetCursorVisibility(bool visible); void BeginGroupPanel(const char* name, const ImVec2 & size = ImVec2(0.0f, 0.0f)); void EndGroupPanel(float minHeight = 0.0f); } diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp index b0ea8a601..cf2a4d24b 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp @@ -352,12 +352,21 @@ static void gfx_dxgi_set_fullscreen_changed_callback(void (*on_fullscreen_change dxgi.on_fullscreen_changed = on_fullscreen_changed; } -static void gfx_dxgi_show_cursor(bool hide) { - /** - * @bug When menubar is open in windowed mode and you toggle fullscreen - * ShowCursor no longer responds. Debugging shows the bool to be correct. - **/ - ShowCursor(hide); +static void gfx_dxgi_set_cursor_visibility(bool visible) { + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showcursor + // https://devblogs.microsoft.com/oldnewthing/20091217-00/?p=15643 + // ShowCursor uses a counter, not a boolean value, and increments or decrements that value when called + // This means we need to keep calling it until we get the value we want + int cursorVisibilityCounter; + if (visible) { + do { + cursorVisibilityCounter = ShowCursor(true); + } while (cursorVisibilityCounter < 0); + } else { + do { + cursorVisibilityCounter = ShowCursor(false); + } while (cursorVisibilityCounter >= 0); + } } static void gfx_dxgi_set_fullscreen(bool enable) { @@ -730,7 +739,7 @@ extern "C" struct GfxWindowManagerAPI gfx_dxgi_api = { gfx_dxgi_set_keyboard_callbacks, gfx_dxgi_set_fullscreen_changed_callback, gfx_dxgi_set_fullscreen, - gfx_dxgi_show_cursor, + gfx_dxgi_set_cursor_visibility, gfx_dxgi_main_loop, gfx_dxgi_get_dimensions, gfx_dxgi_handle_events, diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp index 9de508a3f..ca3105abb 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp @@ -219,8 +219,12 @@ static void gfx_sdl_set_fullscreen(bool enable) { set_fullscreen(enable, true); } -static void gfx_sdl_show_cursor(bool hide) { - SDL_ShowCursor(hide); +static void gfx_sdl_set_cursor_visibility(bool visible) { + if (visible) { + SDL_ShowCursor(SDL_ENABLE); + } else { + SDL_ShowCursor(SDL_DISABLE); + } } static void gfx_sdl_set_keyboard_callbacks(bool (*on_key_down)(int scancode), bool (*on_key_up)(int scancode), void (*on_all_keys_up)(void)) { @@ -394,7 +398,7 @@ struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_set_keyboard_callbacks, gfx_sdl_set_fullscreen_changed_callback, gfx_sdl_set_fullscreen, - gfx_sdl_show_cursor, + gfx_sdl_set_cursor_visibility, gfx_sdl_main_loop, gfx_sdl_get_dimensions, gfx_sdl_handle_events, diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_window_manager_api.h b/libultraship/libultraship/Lib/Fast3D/gfx_window_manager_api.h index 99344940e..8e9e52dd3 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_window_manager_api.h +++ b/libultraship/libultraship/Lib/Fast3D/gfx_window_manager_api.h @@ -9,7 +9,7 @@ struct GfxWindowManagerAPI { void (*set_keyboard_callbacks)(bool (*on_key_down)(int scancode), bool (*on_key_up)(int scancode), void (*on_all_keys_up)(void)); void (*set_fullscreen_changed_callback)(void (*on_fullscreen_changed)(bool is_now_fullscreen)); void (*set_fullscreen)(bool enable); - void (*show_cursor)(bool hide); + void (*set_cursor_visibility)(bool visible); void (*main_loop)(void (*run_one_game_iter)(void)); void (*get_dimensions)(uint32_t *width, uint32_t *height); void (*handle_events)(void); diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index 821f9d87f..1cb865f5c 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -261,7 +261,7 @@ namespace Ship { if (GetConfig()->isNewInstance) { GetConfig()->setInt("Window.Width", 640); GetConfig()->setInt("Window.Height", 480); - GetConfig()->setBool("Window.Options", false); + GetConfig()->setString("Window.GfxBackend", ""); GetConfig()->setString("Window.AudioBackend", ""); @@ -296,8 +296,6 @@ namespace Ship { dwHeight = GetConfig()->getInt("Window.Height", 480); } - dwMenubar = GetConfig()->getBool("Window.Options", false); - gfxBackend = GetConfig()->getString("Window.GfxBackend"); InitializeWindowManager(); @@ -363,13 +361,8 @@ namespace Ship { WmApi->set_fullscreen(bIsFullscreen); } - void Window::ShowCursor(bool hide) { - if (!this->bIsFullscreen || this->dwMenubar) { - WmApi->show_cursor(true); - } - else { - WmApi->show_cursor(hide); - } + void Window::SetCursorVisibility(bool visible) { + WmApi->set_cursor_visibility(visible); } void Window::MainLoop(void (*MainFunction)(void)) { @@ -425,7 +418,12 @@ namespace Ship { Window::GetInstance()->bIsFullscreen = bIsFullscreen; pConf->setBool("Window.Fullscreen.Enabled", bIsFullscreen); - Window::GetInstance()->ShowCursor(!bIsFullscreen); + if (bIsFullscreen) { + bool menuBarOpen = Window::GetInstance()->GetMenuBar(); + Window::GetInstance()->SetCursorVisibility(menuBarOpen); + } else if (!bIsFullscreen) { + Window::GetInstance()->SetCursorVisibility(true); + } } uint32_t Window::GetCurrentWidth() { diff --git a/libultraship/libultraship/Window.h b/libultraship/libultraship/Window.h index c989aa394..edf95eed6 100644 --- a/libultraship/libultraship/Window.h +++ b/libultraship/libultraship/Window.h @@ -35,7 +35,7 @@ namespace Ship { uint16_t GetPixelDepth(float x, float y); void ToggleFullscreen(); void SetFullscreen(bool bIsFullscreen); - void ShowCursor(bool hide); + void SetCursorVisibility(bool visible); uint32_t GetCurrentWidth(); uint32_t GetCurrentHeight(); bool IsFullscreen();