From 22426a8127e71f3eb2729c66c9f642944bc44b01 Mon Sep 17 00:00:00 2001 From: David Racine Date: Thu, 20 Aug 2026 13:56:41 -0400 Subject: [PATCH] Resolve the Fast3dGui cast once per scope instead of per call (#7095) Reaching the Fast3d GUI is spelled out in full at every call site: std::dynamic_pointer_cast( Ship::Context::GetRawInstance()->GetWindow()->GetGui())->GetTextureByName(name) Each one locks the Context weak_ptr, copies a shared_ptr for the window and one for the GUI, then runs a dynamic_cast, only to drop all three again. InputViewer::DrawElement does that 43 times per frame, and the item tracker and save editor repeat it once per icon drawn. Binding it to a local once per scope leaves the behaviour identical and reads better. The local goes in the innermost block that covers the call sites, so it stays behind the guards that were already there: DrawElement still resolves nothing when the input viewer is off. RenderButton keeps its inline casts. Its two call sites are in exclusive branches, so a local would add a cast on the path that takes neither. --- .../Enhancements/TimeDisplay/TimeDisplay.cpp | 26 ++-- soh/soh/Enhancements/controls/InputViewer.cpp | 144 ++++++------------ .../Enhancements/debugger/debugSaveEditor.cpp | 122 ++++++--------- .../Enhancements/randomizer/Plandomizer.cpp | 77 ++++------ .../randomizer/randomizer_item_tracker.cpp | 31 ++-- .../Enhancements/timesplits/TimeSplits.cpp | 50 +++--- soh/soh/OTRGlobals.cpp | 31 ++-- soh/soh/SohGui/ImGuiUtils.cpp | 52 +++---- 8 files changed, 193 insertions(+), 340 deletions(-) diff --git a/soh/soh/Enhancements/TimeDisplay/TimeDisplay.cpp b/soh/soh/Enhancements/TimeDisplay/TimeDisplay.cpp index 34e84b4f5a..288b07abe0 100644 --- a/soh/soh/Enhancements/TimeDisplay/TimeDisplay.cpp +++ b/soh/soh/Enhancements/TimeDisplay/TimeDisplay.cpp @@ -204,6 +204,8 @@ void TimeDisplayWindow::Draw() { ImGui::TableNextColumn(); if (timeDisplayTime != "-:--") { + auto gui = + std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); char* textToDecode = new char[timeDisplayTime.size() + 1]; textToDecode = std::strcpy(textToDecode, timeDisplayTime.c_str()); size_t textLength = timeDisplayTime.length(); @@ -217,15 +219,11 @@ void TimeDisplayWindow::Draw() { } if (textToDecode[i] == '.') { ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (8.0f * fontScale)); - ImGui::Image(std::dynamic_pointer_cast( - Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(digitList[textureIndex].first), + ImGui::Image(gui->GetTextureByName(digitList[textureIndex].first), ImVec2(8.0f * fontScale, 8.0f * fontScale), ImVec2(0, 0.5f), ImVec2(1, 1), textColor, ImVec4(0, 0, 0, 0)); } else { - ImGui::Image(std::dynamic_pointer_cast( - Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(digitList[textureIndex].first), + ImGui::Image(gui->GetTextureByName(digitList[textureIndex].first), ImVec2(8.0f * fontScale, 16.0f * fontScale), ImVec2(0, 0), ImVec2(1, 1), textColor, ImVec4(0, 0, 0, 0)); } @@ -263,18 +261,14 @@ static void TimeDisplayInitTimers() { } void TimeDisplayWindow::InitElement() { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("GAMEPLAY_TIMER", gClockIconTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("DAY_TIME_TIMER", gSunIconTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("NIGHT_TIME_TIMER", gMoonIconTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("NAVI_TIMER", gNaviIconTex, "", ImVec4(1, 1, 1, 1)); + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); + gui->LoadGuiTexture("GAMEPLAY_TIMER", gClockIconTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("DAY_TIME_TIMER", gSunIconTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("NIGHT_TIME_TIMER", gMoonIconTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("NAVI_TIMER", gNaviIconTex, "", ImVec4(1, 1, 1, 1)); for (auto& load : digitList) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(load.first.c_str(), load.second, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture(load.first.c_str(), load.second, "", ImVec4(1, 1, 1, 1)); } TimeDisplayInitSettings(); diff --git a/soh/soh/Enhancements/controls/InputViewer.cpp b/soh/soh/Enhancements/controls/InputViewer.cpp index de34e55a16..161610e93c 100644 --- a/soh/soh/Enhancements/controls/InputViewer.cpp +++ b/soh/soh/Enhancements/controls/InputViewer.cpp @@ -73,82 +73,46 @@ void InputViewer::Draw() { void InputViewer::DrawElement() { if (CVarGetInteger(CVAR_WINDOW("InputViewer"), 0)) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); static bool sButtonTexturesLoaded = false; if (!sButtonTexturesLoaded) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Input-Viewer-Background", "textures/buttons/InputViewerBackground.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("A-Btn", "textures/buttons/ABtn.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("B-Btn", "textures/buttons/BBtn.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("L-Btn", "textures/buttons/LBtn.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("R-Btn", "textures/buttons/RBtn.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Z-Btn", "textures/buttons/ZBtn.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Start-Btn", "textures/buttons/StartBtn.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("C-Left", "textures/buttons/CLeft.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("C-Right", "textures/buttons/CRight.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("C-Up", "textures/buttons/CUp.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("C-Down", "textures/buttons/CDown.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Analog-Stick", "textures/buttons/AnalogStick.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Dpad-Left", "textures/buttons/DPadLeft.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Dpad-Right", "textures/buttons/DPadRight.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Dpad-Up", "textures/buttons/DPadUp.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Dpad-Down", "textures/buttons/DPadDown.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Modifier-1", "textures/buttons/Mod1.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Modifier-2", "textures/buttons/Mod2.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Right-Stick", "textures/buttons/RightStick.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("A-Btn Outline", "textures/buttons/ABtnOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("B-Btn Outline", "textures/buttons/BBtnOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("L-Btn Outline", "textures/buttons/LBtnOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("R-Btn Outline", "textures/buttons/RBtnOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Z-Btn Outline", "textures/buttons/ZBtnOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Start-Btn Outline", "textures/buttons/StartBtnOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("C-Left Outline", "textures/buttons/CLeftOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("C-Right Outline", "textures/buttons/CRightOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("C-Up Outline", "textures/buttons/CUpOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("C-Down Outline", "textures/buttons/CDownOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Analog-Stick Outline", "textures/buttons/AnalogStickOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Dpad-Left Outline", "textures/buttons/DPadLeftOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Dpad-Right Outline", "textures/buttons/DPadRightOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Dpad-Up Outline", "textures/buttons/DPadUpOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Dpad-Down Outline", "textures/buttons/DPadDownOutline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Modifier-1 Outline", "textures/buttons/Mod1Outline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Modifier-2 Outline", "textures/buttons/Mod2Outline.png"); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadTextureFromRawImage("Right-Stick Outline", "textures/buttons/RightStickOutline.png"); + gui->LoadTextureFromRawImage("Input-Viewer-Background", "textures/buttons/InputViewerBackground.png"); + gui->LoadTextureFromRawImage("A-Btn", "textures/buttons/ABtn.png"); + gui->LoadTextureFromRawImage("B-Btn", "textures/buttons/BBtn.png"); + gui->LoadTextureFromRawImage("L-Btn", "textures/buttons/LBtn.png"); + gui->LoadTextureFromRawImage("R-Btn", "textures/buttons/RBtn.png"); + gui->LoadTextureFromRawImage("Z-Btn", "textures/buttons/ZBtn.png"); + gui->LoadTextureFromRawImage("Start-Btn", "textures/buttons/StartBtn.png"); + gui->LoadTextureFromRawImage("C-Left", "textures/buttons/CLeft.png"); + gui->LoadTextureFromRawImage("C-Right", "textures/buttons/CRight.png"); + gui->LoadTextureFromRawImage("C-Up", "textures/buttons/CUp.png"); + gui->LoadTextureFromRawImage("C-Down", "textures/buttons/CDown.png"); + gui->LoadTextureFromRawImage("Analog-Stick", "textures/buttons/AnalogStick.png"); + gui->LoadTextureFromRawImage("Dpad-Left", "textures/buttons/DPadLeft.png"); + gui->LoadTextureFromRawImage("Dpad-Right", "textures/buttons/DPadRight.png"); + gui->LoadTextureFromRawImage("Dpad-Up", "textures/buttons/DPadUp.png"); + gui->LoadTextureFromRawImage("Dpad-Down", "textures/buttons/DPadDown.png"); + gui->LoadTextureFromRawImage("Modifier-1", "textures/buttons/Mod1.png"); + gui->LoadTextureFromRawImage("Modifier-2", "textures/buttons/Mod2.png"); + gui->LoadTextureFromRawImage("Right-Stick", "textures/buttons/RightStick.png"); + gui->LoadTextureFromRawImage("A-Btn Outline", "textures/buttons/ABtnOutline.png"); + gui->LoadTextureFromRawImage("B-Btn Outline", "textures/buttons/BBtnOutline.png"); + gui->LoadTextureFromRawImage("L-Btn Outline", "textures/buttons/LBtnOutline.png"); + gui->LoadTextureFromRawImage("R-Btn Outline", "textures/buttons/RBtnOutline.png"); + gui->LoadTextureFromRawImage("Z-Btn Outline", "textures/buttons/ZBtnOutline.png"); + gui->LoadTextureFromRawImage("Start-Btn Outline", "textures/buttons/StartBtnOutline.png"); + gui->LoadTextureFromRawImage("C-Left Outline", "textures/buttons/CLeftOutline.png"); + gui->LoadTextureFromRawImage("C-Right Outline", "textures/buttons/CRightOutline.png"); + gui->LoadTextureFromRawImage("C-Up Outline", "textures/buttons/CUpOutline.png"); + gui->LoadTextureFromRawImage("C-Down Outline", "textures/buttons/CDownOutline.png"); + gui->LoadTextureFromRawImage("Analog-Stick Outline", "textures/buttons/AnalogStickOutline.png"); + gui->LoadTextureFromRawImage("Dpad-Left Outline", "textures/buttons/DPadLeftOutline.png"); + gui->LoadTextureFromRawImage("Dpad-Right Outline", "textures/buttons/DPadRightOutline.png"); + gui->LoadTextureFromRawImage("Dpad-Up Outline", "textures/buttons/DPadUpOutline.png"); + gui->LoadTextureFromRawImage("Dpad-Down Outline", "textures/buttons/DPadDownOutline.png"); + gui->LoadTextureFromRawImage("Modifier-1 Outline", "textures/buttons/Mod1Outline.png"); + gui->LoadTextureFromRawImage("Modifier-2 Outline", "textures/buttons/Mod2Outline.png"); + gui->LoadTextureFromRawImage("Right-Stick Outline", "textures/buttons/RightStickOutline.png"); sButtonTexturesLoaded = true; } @@ -165,9 +129,7 @@ void InputViewer::DrawElement() { CVarGetInteger(CVAR_INPUT_VIEWER("ButtonOutlineMode"), BUTTON_OUTLINE_NOT_PRESSED); const bool useGlobalOutlineMode = CVarGetInteger(CVAR_INPUT_VIEWER("UseGlobalButtonOutlineMode"), 1); - ImVec2 bgSize = - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureSize("Input-Viewer-Background"); + ImVec2 bgSize = gui->GetTextureSize("Input-Viewer-Background"); ImVec2 scaledBGSize = ImVec2(bgSize.x * scale, bgSize.y * scale); ImGui::SetNextWindowSize( @@ -203,10 +165,8 @@ void InputViewer::DrawElement() { if (CVarGetInteger(CVAR_INPUT_VIEWER("ShowBackground"), 1)) { ImGui::SetNextItemAllowOverlap(); // Background - ImGui::Image( - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("Input-Viewer-Background"), - scaledBGSize, ImVec2(0, 0), ImVec2(1.0f, 1.0f)); + ImGui::Image(gui->GetTextureByName("Input-Viewer-Background"), scaledBGSize, ImVec2(0, 0), + ImVec2(1.0f, 1.0f)); } // A/B @@ -355,10 +315,8 @@ void InputViewer::DrawElement() { (analogOutlineMode == STICK_MODE_HIDDEN_IN_DEADZONE && !analogStickIsInDeadzone)) { ImGui::SetNextItemAllowOverlap(); ImGui::SetCursorPos(aPos); - ImGui::Image( - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("Analog-Stick Outline"), - scaledBGSize, ImVec2(0, 0), ImVec2(1.0f, 1.0f)); + ImGui::Image(gui->GetTextureByName("Analog-Stick Outline"), scaledBGSize, ImVec2(0, 0), + ImVec2(1.0f, 1.0f)); } const int analogStickMode = CVarGetInteger(CVAR_INPUT_VIEWER("AnalogStick.VisibilityMode"), STICK_MODE_ALWAYS_SHOWN); @@ -368,10 +326,7 @@ void InputViewer::DrawElement() { ImGui::SetCursorPos( ImVec2(aPos.x + maxStickDistance * ((float)(pads[0].stick_x) / MAX_AXIS_RANGE) * scale, aPos.y - maxStickDistance * ((float)(pads[0].stick_y) / MAX_AXIS_RANGE) * scale)); - ImGui::Image( - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("Analog-Stick"), - scaledBGSize, ImVec2(0, 0), ImVec2(1.0f, 1.0f)); + ImGui::Image(gui->GetTextureByName("Analog-Stick"), scaledBGSize, ImVec2(0, 0), ImVec2(1.0f, 1.0f)); } // Right Stick @@ -382,10 +337,8 @@ void InputViewer::DrawElement() { (rightOutlineMode == STICK_MODE_HIDDEN_IN_DEADZONE && !rightStickIsInDeadzone)) { ImGui::SetNextItemAllowOverlap(); ImGui::SetCursorPos(aPos); - ImGui::Image( - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("Right-Stick Outline"), - scaledBGSize, ImVec2(0, 0), ImVec2(1.0f, 1.0f)); + ImGui::Image(gui->GetTextureByName("Right-Stick Outline"), scaledBGSize, ImVec2(0, 0), + ImVec2(1.0f, 1.0f)); } const int rightStickMode = CVarGetInteger(CVAR_INPUT_VIEWER("RightStick.VisibilityMode"), STICK_MODE_ALWAYS_HIDDEN); @@ -395,10 +348,7 @@ void InputViewer::DrawElement() { ImGui::SetCursorPos( ImVec2(aPos.x + maxRightStickDistance * ((float)(pads[0].right_stick_x) / MAX_AXIS_RANGE) * scale, aPos.y - maxRightStickDistance * ((float)(pads[0].right_stick_y) / MAX_AXIS_RANGE) * scale)); - ImGui::Image( - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("Right-Stick"), - scaledBGSize, ImVec2(0, 0), ImVec2(1.0f, 1.0f)); + ImGui::Image(gui->GetTextureByName("Right-Stick"), scaledBGSize, ImVec2(0, 0), ImVec2(1.0f, 1.0f)); } // Analog stick angle text diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp index 4930c01814..c44ad0cb41 100644 --- a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp @@ -175,6 +175,7 @@ static bool DungeonHasBossKey(int32_t dungeonIndex) { // restrictToValid: pointer to shared restrict flag (nullptr = use internal static) static void DrawButtonItemSelector(const char* label, int buttonIndex, UIWidgets::Colors color, bool isBButton = false, const bool* restrictToValidPtr = nullptr) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); // Use provided restrictToValid or default to true (restricted mode) bool useRestriction = restrictToValidPtr ? *restrictToValidPtr : true; uint8_t* buttonItem = &gSaveContext.equips.buttonItems[buttonIndex]; @@ -219,22 +220,16 @@ static void DrawButtonItemSelector(const char* label, int buttonIndex, UIWidgets if (item == ITEM_ROCS_FEATHER) { std::string rocId = std::string("RG_ROCS_FEATHER_btn_") + label; - if (ImGui::ImageButton( - rocId.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("RG_ROCS_FEATHER"), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1))) { + if (ImGui::ImageButton(rocId.c_str(), gui->GetTextureByName("RG_ROCS_FEATHER"), ImVec2(IMAGE_SIZE, IMAGE_SIZE), + ImVec2(0, 0), ImVec2(1, 1))) { ImGui::OpenPopup(label); } } else if (const auto mappedItem = itemMapping.find(item); item != ITEM_NONE && mappedItem != itemMapping.end()) { const ItemMapEntry& slotEntry = mappedItem->second; // Use label-based ID to avoid conflicts when same item is on multiple buttons std::string itemId = std::string("item_btn_") + label + "_" + slotEntry.name; - if (ImGui::ImageButton( - itemId.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(slotEntry.name), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1))) { + if (ImGui::ImageButton(itemId.c_str(), gui->GetTextureByName(slotEntry.name), ImVec2(IMAGE_SIZE, IMAGE_SIZE), + ImVec2(0, 0), ImVec2(1, 1))) { ImGui::OpenPopup(label); } } else { @@ -300,11 +295,8 @@ static void DrawButtonItemSelector(const char* label, int buttonIndex, UIWidgets const ItemMapEntry& slotEntry = possibleItems[pickerIndex]; PushStyleButton(Colors::DarkGray); std::string pickerItemId = std::string("item_picker_") + label + "_" + slotEntry.name; - auto ret = ImGui::ImageButton( - pickerItemId.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(slotEntry.name), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); + auto ret = ImGui::ImageButton(pickerItemId.c_str(), gui->GetTextureByName(slotEntry.name), + ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); PopStyleButton(); if (ret) { *buttonItem = slotEntry.id; @@ -361,11 +353,8 @@ static void DrawButtonItemSelector(const char* label, int buttonIndex, UIWidgets ImGui::SameLine(); PushStyleButton(Colors::DarkGray); std::string rocPickerId = std::string("RG_ROCS_FEATHER_picker_") + label; - auto retRoc = ImGui::ImageButton( - rocPickerId.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("RG_ROCS_FEATHER"), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); + auto retRoc = ImGui::ImageButton(rocPickerId.c_str(), gui->GetTextureByName("RG_ROCS_FEATHER"), + ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); PopStyleButton(); if (retRoc) { *buttonItem = ITEM_ROCS_FEATHER; @@ -955,10 +944,9 @@ void DrawGeneralTab() { } void DrawBGSItemFlag(uint8_t itemID) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); const ItemMapEntry& slotEntry = itemMapping[itemID]; - ImGui::Image(std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(slotEntry.name), - ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1)); + ImGui::Image(gui->GetTextureByName(slotEntry.name), ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1)); } // Re-sync any C/D-pad button that mirrors an edited inventory slot (buttonItems[i] == items[cButtonSlots[i-1]]), @@ -975,6 +963,7 @@ static void SyncButtonItemsForSlot(uint8_t slot) { } void DrawInventoryTab() { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 3.0f); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8.0f, 8.0f)); ImGui::BeginChild("inventoryTab", ImVec2(0, 0), true); @@ -1060,19 +1049,13 @@ void DrawInventoryTab() { PushStyleButton(Colors::DarkGray); bool wasClicked = false; if (item == ITEM_ROCS_FEATHER) { - wasClicked = ImGui::ImageButton( - "RG_ROCS_FEATHER", - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("RG_ROCS_FEATHER"), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); + wasClicked = ImGui::ImageButton("RG_ROCS_FEATHER", gui->GetTextureByName("RG_ROCS_FEATHER"), + ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); } else if (const auto mappedItem = itemMapping.find(item); item != ITEM_NONE && mappedItem != itemMapping.end()) { const ItemMapEntry& slotEntry = mappedItem->second; - wasClicked = ImGui::ImageButton( - slotEntry.name.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(slotEntry.name), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); + wasClicked = ImGui::ImageButton(slotEntry.name.c_str(), gui->GetTextureByName(slotEntry.name), + ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); } else { wasClicked = ImGui::Button("##itemNone", ImVec2(IMAGE_SIZE, IMAGE_SIZE) + ImGui::GetStyle().FramePadding * 2); @@ -1169,10 +1152,7 @@ void DrawInventoryTab() { } const ItemMapEntry& slotEntry = possibleItems[pickerIndex]; PushStyleButton(Colors::DarkGray); - auto ret = ImGui::ImageButton(slotEntry.name.c_str(), - std::dynamic_pointer_cast( - Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(slotEntry.name), + auto ret = ImGui::ImageButton(slotEntry.name.c_str(), gui->GetTextureByName(slotEntry.name), ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); PopStyleButton(); if (ret) { @@ -1189,10 +1169,7 @@ void DrawInventoryTab() { if (addRocsFeather) { ImGui::SameLine(); PushStyleButton(Colors::DarkGray); - auto retRoc = ImGui::ImageButton("RG_ROCS_FEATHER_PICKER", - std::dynamic_pointer_cast( - Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("RG_ROCS_FEATHER"), + auto retRoc = ImGui::ImageButton("RG_ROCS_FEATHER_PICKER", gui->GetTextureByName("RG_ROCS_FEATHER"), ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); PopStyleButton(); if (retRoc) { @@ -1896,6 +1873,7 @@ void DrawUpgrade(const std::string& categoryName, int32_t categoryId, const std: // Draws a combo that lets you choose and upgrade value from a popup grid of icons void DrawUpgradeIcon(const std::string& categoryName, int32_t categoryId, const std::vector& items) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); static const char* upgradePopupPicker = "upgradePopupPicker"; ImGui::PushID(categoryName.c_str()); @@ -1904,11 +1882,9 @@ void DrawUpgradeIcon(const std::string& categoryName, int32_t categoryId, const auto value = (size_t)CUR_UPG_VALUE(categoryId); uint8_t item = value < items.size() ? items[value] : (uint8_t)ITEM_NONE; const ItemMapEntry& slotEntry = itemMapping[item]; - if (ImGui::ImageButton( - slotEntry.name.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(item != ITEM_NONE ? slotEntry.name : itemMapping[items[1]].nameFaded), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1))) { + if (ImGui::ImageButton(slotEntry.name.c_str(), + gui->GetTextureByName(item != ITEM_NONE ? slotEntry.name : itemMapping[items[1]].nameFaded), + ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1))) { ImGui::OpenPopup(upgradePopupPicker); } PopStyleButton(); @@ -1930,11 +1906,8 @@ void DrawUpgradeIcon(const std::string& categoryName, int32_t categoryId, const Tooltip("None"); } else { const ItemMapEntry& slotEntry = itemMapping[items[pickerIndex]]; - auto ret = ImGui::ImageButton( - slotEntry.name.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(slotEntry.name), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); + auto ret = ImGui::ImageButton(slotEntry.name.c_str(), gui->GetTextureByName(slotEntry.name), + ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); if (ret) { Inventory_ChangeUpgrade(categoryId, static_cast(pickerIndex)); ImGui::CloseCurrentPopup(); @@ -1949,6 +1922,7 @@ void DrawUpgradeIcon(const std::string& categoryName, int32_t categoryId, const } void DrawEquipmentTab() { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 3.0f); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8.0f, 8.0f)); ImGui::BeginChild("equipmentTab", ImVec2(0, 0), true); @@ -2005,11 +1979,9 @@ void DrawEquipmentTab() { } PushStyleButton(Colors::DarkGray); - auto ret = ImGui::ImageButton( - entry.name.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasEquip ? entry.name : entry.nameFaded), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); + auto ret = + ImGui::ImageButton(entry.name.c_str(), gui->GetTextureByName(hasEquip ? entry.name : entry.nameFaded), + ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); if (ret) { if (hasEquip) { gSaveContext.inventory.equipment &= ~bitMask; @@ -2256,15 +2228,14 @@ void DrawEquipmentTab() { // Draws a toggleable icon for a quest item that is faded when disabled void DrawQuestItemButton(uint32_t item) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); const QuestMapEntry& entry = questMapping[item]; uint32_t bitMask = 1 << entry.id; bool hasQuestItem = (bitMask & gSaveContext.inventory.questItems) != 0; PushStyleButton(Colors::DarkGray); - auto ret = ImGui::ImageButton( - entry.name.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasQuestItem ? entry.name : entry.nameFaded), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); + auto ret = + ImGui::ImageButton(entry.name.c_str(), gui->GetTextureByName(hasQuestItem ? entry.name : entry.nameFaded), + ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); if (ret) { if (hasQuestItem) { gSaveContext.inventory.questItems &= ~bitMask; @@ -2278,15 +2249,13 @@ void DrawQuestItemButton(uint32_t item) { // Draws a toggleable icon for a dungeon item that is faded when disabled void DrawDungeonItemButton(uint32_t item, uint32_t scene) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); const ItemMapEntry& entry = itemMapping[item]; uint32_t bitMask = 1 << (entry.id - ITEM_KEY_BOSS); // Bitset starts at ITEM_KEY_BOSS == 0. the rest are sequential bool hasItem = (bitMask & gSaveContext.inventory.dungeonItems[scene]) != 0; PushStyleButton(Colors::DarkGray); - auto ret = ImGui::ImageButton( - entry.name.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasItem ? entry.name : entry.nameFaded), - ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1)); + auto ret = ImGui::ImageButton(entry.name.c_str(), gui->GetTextureByName(hasItem ? entry.name : entry.nameFaded), + ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1)); if (ret) { if (hasItem) { gSaveContext.inventory.dungeonItems[scene] &= ~bitMask; @@ -2299,6 +2268,7 @@ void DrawDungeonItemButton(uint32_t item, uint32_t scene) { } void DrawQuestStatusTab() { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 3.0f); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8.0f, 8.0f)); ImGui::BeginChild("questStatusTab", ImVec2(0, 0), true); @@ -2347,11 +2317,9 @@ void DrawQuestStatusTab() { uint32_t bitMask = 1 << entry.id; bool hasQuestItem = (bitMask & gSaveContext.inventory.questItems) != 0; PushStyleButton(Colors::DarkGray); - auto ret = ImGui::ImageButton( - entry.name.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasQuestItem ? entry.name : entry.nameFaded), - ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); + auto ret = + ImGui::ImageButton(entry.name.c_str(), gui->GetTextureByName(hasQuestItem ? entry.name : entry.nameFaded), + ImVec2(IMAGE_SIZE, IMAGE_SIZE), ImVec2(0, 0), ImVec2(1, 1)); if (ret) { if (hasQuestItem) { gSaveContext.inventory.questItems &= ~bitMask; @@ -2450,6 +2418,8 @@ void DrawDungeonItemsTab() { // Small keys - clickable button with popup (only for dungeons that have keys) if (GetMaxKeysForDungeon(dungeonIndex) > 0) { + auto gui = + std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); // Save cursor position before small key button to restore for boss key alignment ImVec2 smallKeyCursor = ImGui::GetCursorScreenPos(); @@ -2461,12 +2431,10 @@ void DrawDungeonItemsTab() { bool showNormal = (keyCount != 255); // Show count label for any value except 255 (-1) bool showCount = (keyCount != 255); - if (ImGui::ImageButton( - itemMapping[ITEM_KEY_SMALL].name.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(showNormal ? itemMapping[ITEM_KEY_SMALL].name - : itemMapping[ITEM_KEY_SMALL].nameFaded), - ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1))) { + if (ImGui::ImageButton(itemMapping[ITEM_KEY_SMALL].name.c_str(), + gui->GetTextureByName(showNormal ? itemMapping[ITEM_KEY_SMALL].name + : itemMapping[ITEM_KEY_SMALL].nameFaded), + ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1))) { ImGui::OpenPopup(keyPopupId.c_str()); } PopStyleButton(); diff --git a/soh/soh/Enhancements/randomizer/Plandomizer.cpp b/soh/soh/Enhancements/randomizer/Plandomizer.cpp index da32f3602d..75b7b134bc 100644 --- a/soh/soh/Enhancements/randomizer/Plandomizer.cpp +++ b/soh/soh/Enhancements/randomizer/Plandomizer.cpp @@ -309,9 +309,9 @@ ImVec4 plandomizerGetItemColor(Rando::Item randoItem) { return itemColor; } if (randoItem.GetItemType() == ITEMTYPE_SONG) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); uint32_t questID = Rando::Logic::RandoGetToQuestItem[randoItem.GetRandomizerGet()]; - textureID = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(songMapping.at((QuestItem)questID).name); + textureID = gui->GetTextureByName(songMapping.at((QuestItem)questID).name); itemColor = songMapping.at((QuestItem)questID).color; imageSize = ImVec2(24.0f, 32.0f); imagePadding = 6.0f; @@ -375,6 +375,7 @@ void PlandomizerPopulateSeedList() { } void PlandomizerItemImageCorrection(Rando::Item randoItem) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); textureID = 0; imageSize = ImVec2(32.0f, 32.0f); imagePadding = 2.0f; @@ -384,21 +385,17 @@ void PlandomizerItemImageCorrection(Rando::Item randoItem) { itemColor = plandomizerGetItemColor(randoItem); if (randoItem.GetItemType() == ITEMTYPE_SMALLKEY || randoItem.GetItemType() == ITEMTYPE_FORTRESS_SMALLKEY) { - textureID = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("ITEM_KEY_SMALL"); + textureID = gui->GetTextureByName("ITEM_KEY_SMALL"); return; } if (randoItem.GetItemType() == ITEMTYPE_BOSSKEY) { - textureID = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("ITEM_KEY_BOSS"); + textureID = gui->GetTextureByName("ITEM_KEY_BOSS"); return; } for (auto& map : itemImageMap) { if (map.first == randoItem.GetRandomizerGet()) { - textureID = - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(map.second.c_str()); + textureID = gui->GetTextureByName(map.second.c_str()); if (map.second.find("ITEM_ARROWS") != std::string::npos) { textureUV0 = ImVec2(0, 1); textureUV1 = ImVec2(1, 0); @@ -412,19 +409,16 @@ void PlandomizerItemImageCorrection(Rando::Item randoItem) { } if (randoItem.GetRandomizerGet() >= RG_GOHMA_SOUL && randoItem.GetRandomizerGet() <= RG_GANON_SOUL) { - textureID = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("BOSS_SOUL"); + textureID = gui->GetTextureByName("BOSS_SOUL"); } if (randoItem.GetRandomizerGet() >= RG_OCARINA_A_BUTTON && randoItem.GetRandomizerGet() <= RG_OCARINA_C_RIGHT_BUTTON) { - textureID = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("ITEM_OCARINA_TIME"); + textureID = gui->GetTextureByName("ITEM_OCARINA_TIME"); } if (textureID == 0) { - textureID = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(itemMapping[randoItem.GetGIEntry()->itemId].name); + textureID = gui->GetTextureByName(itemMapping[randoItem.GetGIEntry()->itemId].name); } } @@ -974,6 +968,8 @@ void PlandomizerDrawOptions() { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetContentRegionAvail().x * 0.5f) - (34.0f * 5.0f)); if (spoilerLogData.size() > 0) { if (ImGui::BeginTable("HashIcons", 5)) { + auto gui = + std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); for (int i = 0; i < 5; i++) { ImGui::TableSetupColumn("Icon", ImGuiTableColumnFlags_WidthFixed, 34.0f); } @@ -983,14 +979,9 @@ void PlandomizerDrawOptions() { PlandoPushImageButtonStyle(); for (auto& hash : plandoHash) { ImGui::PushID(index); - textureID = std::dynamic_pointer_cast( - Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(gSeedTextures[hash].tex); + textureID = gui->GetTextureByName(gSeedTextures[hash].tex); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 2.0f)); - auto upRet = ImGui::ImageButton("HASH_ARROW_UP", - std::dynamic_pointer_cast( - Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("HASH_ARROW_UP"), + auto upRet = ImGui::ImageButton("HASH_ARROW_UP", gui->GetTextureByName("HASH_ARROW_UP"), ImVec2(35.0f, 18.0f), ImVec2(1, 1), ImVec2(0, 0), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)); ImGui::PopStyleVar(); @@ -1003,10 +994,7 @@ void PlandomizerDrawOptions() { } ImGui::Image(textureID, ImVec2(35.0f, 35.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 2.0f)); - auto downRet = ImGui::ImageButton("HASH_ARROW_DWN", - std::dynamic_pointer_cast( - Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("HASH_ARROW_DWN"), + auto downRet = ImGui::ImageButton("HASH_ARROW_DWN", gui->GetTextureByName("HASH_ARROW_DWN"), ImVec2(35.0f, 18.0f), ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1)); ImGui::PopStyleVar(); @@ -1186,28 +1174,17 @@ void PlandomizerWindow::DrawElement() { } void PlandomizerWindow::InitElement() { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("ITEM_RUPEE_GRAYSCALE", gRupeeCounterIconTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("ITEM_HEART_GRAYSCALE", gHeartFullTex, "", ImVec4(0.87f, 0.10f, 0.10f, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("ITEM_SEEDS", gItemIconDekuSeedsTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("ITEM_ARROWS_SMALL", gDropArrows1Tex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("ITEM_ARROWS_MEDIUM", gDropArrows2Tex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("ITEM_ARROWS_LARGE", gDropArrows3Tex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("ITEM_ICE_TRAP", gMagicArrowEquipEffectTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("HASH_ARROW_UP", gEmptyCDownArrowTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("HASH_ARROW_DWN", gEmptyCDownArrowTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("BOSS_SOUL", gBossSoulTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("TRIFORCE_PIECE", gTriforcePieceTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("TRIFORCE", gTriforcePieceTex, "", ImVec4(1, 1, 1, 1)); + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); + gui->LoadGuiTexture("ITEM_RUPEE_GRAYSCALE", gRupeeCounterIconTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("ITEM_HEART_GRAYSCALE", gHeartFullTex, "", ImVec4(0.87f, 0.10f, 0.10f, 1)); + gui->LoadGuiTexture("ITEM_SEEDS", gItemIconDekuSeedsTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("ITEM_ARROWS_SMALL", gDropArrows1Tex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("ITEM_ARROWS_MEDIUM", gDropArrows2Tex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("ITEM_ARROWS_LARGE", gDropArrows3Tex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("ITEM_ICE_TRAP", gMagicArrowEquipEffectTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("HASH_ARROW_UP", gEmptyCDownArrowTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("HASH_ARROW_DWN", gEmptyCDownArrowTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("BOSS_SOUL", gBossSoulTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("TRIFORCE_PIECE", gTriforcePieceTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("TRIFORCE", gTriforcePieceTex, "", ImVec4(1, 1, 1, 1)); } diff --git a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp index 5829a62ac2..02d8e2e31b 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp @@ -843,27 +843,25 @@ void DrawItemCount(ItemTrackerItem item, bool hideMax) { } void DrawEquip(ItemTrackerItem item) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); assert(item.kind == ITEM_KIND_ITEM); bool hasEquip = HasEquipment(item) && IsValidSaveFile(); bool giantsKnife = item.id == ITEM_SWORD_BGS && hasEquip && !gSaveContext.bgsFlag; std::string iconName = giantsKnife ? "ITEM_SWORD_KNIFE" : hasEquip ? item.iconName : item.fadedIconName; float iconSize = static_cast(CVarGetInteger(CVAR_TRACKER_ITEM("IconSize"), 36)); - ImGui::Image(std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(iconName), - ImVec2(iconSize, iconSize), ImVec2(0.0f, 0.0f), ImVec2(1, 1)); + ImGui::Image(gui->GetTextureByName(iconName), ImVec2(iconSize, iconSize), ImVec2(0.0f, 0.0f), ImVec2(1, 1)); Tooltip(giantsKnife ? "Giant's Knife" : SohUtils::GetItemName(item.id).c_str()); } void DrawQuest(ItemTrackerItem item) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); assert(item.kind == ITEM_KIND_QUEST); bool hasQuestItem = HasQuestItem(item); float iconSize = static_cast(CVarGetInteger(CVAR_TRACKER_ITEM("IconSize"), 36)); ImGui::BeginGroup(); - ImGui::ImageWithBg( - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasQuestItem && IsValidSaveFile() ? item.iconName : item.fadedIconName), - ImVec2(iconSize, iconSize), ImVec2(0, 0), ImVec2(1, 1)); + ImGui::ImageWithBg(gui->GetTextureByName(hasQuestItem && IsValidSaveFile() ? item.iconName : item.fadedIconName), + ImVec2(iconSize, iconSize), ImVec2(0, 0), ImVec2(1, 1)); if (item.id == QUEST_SKULL_TOKEN) { DrawItemCount(item, false); @@ -887,6 +885,7 @@ bool HasBossSoul(RandomizerInf bossSoul) { } void DrawItem(ItemTrackerItem item) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); uint32_t actualItemId = GameInteractor::IsSaveLoaded() && item.kind == ITEM_KIND_ITEM ? INV_CONTENT(item.id) : (uint8_t)ITEM_NONE; float iconSize = static_cast(CVarGetInteger(CVAR_TRACKER_ITEM("IconSize"), 36)); @@ -1204,8 +1203,7 @@ void DrawItem(ItemTrackerItem item) { ImGui::BeginGroup(); - ImGui::Image(std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasItem && IsValidSaveFile() ? item.iconName : item.fadedIconName), + ImGui::Image(gui->GetTextureByName(hasItem && IsValidSaveFile() ? item.iconName : item.fadedIconName), ImVec2(iconSize, iconSize), ImVec2(0, 0), ImVec2(1, 1)); DrawItemCount(item, hideMax); @@ -1224,6 +1222,7 @@ void DrawItem(ItemTrackerItem item) { } void DrawBottle(ItemTrackerItem item) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); assert(item.kind == ITEM_KIND_ITEM); uint32_t actualItemId = GameInteractor::IsSaveLoaded() ? (gSaveContext.inventory.items[SLOT(item.id) + item.data]) : false; @@ -1236,14 +1235,14 @@ void DrawBottle(ItemTrackerItem item) { } float iconSize = static_cast(CVarGetInteger(CVAR_TRACKER_ITEM("IconSize"), 36)); - ImGui::Image(std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasItem && IsValidSaveFile() ? item.iconName : item.fadedIconName), + ImGui::Image(gui->GetTextureByName(hasItem && IsValidSaveFile() ? item.iconName : item.fadedIconName), ImVec2(iconSize, iconSize), ImVec2(0, 0), ImVec2(1, 1)); Tooltip(SohUtils::GetItemName(item.id).c_str()); }; void DrawDungeonItem(ItemTrackerItem item) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); assert(item.kind == ITEM_KIND_ITEM); uint32_t itemId = item.id; ImU32 dungeonColor = IM_COL_WHITE; @@ -1253,12 +1252,10 @@ void DrawDungeonItem(ItemTrackerItem item) { bool hasSmallKey = GameInteractor::IsSaveLoaded() ? ((gSaveContext.inventory.dungeonKeys[item.data]) >= 0) : false; ImGui::BeginGroup(); if (itemId == ITEM_KEY_SMALL) { - ImGui::Image(std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasSmallKey && IsValidSaveFile() ? item.iconName : item.fadedIconName), + ImGui::Image(gui->GetTextureByName(hasSmallKey && IsValidSaveFile() ? item.iconName : item.fadedIconName), ImVec2(iconSize, iconSize), ImVec2(0, 0), ImVec2(1, 1)); } else { - ImGui::Image(std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasItem && IsValidSaveFile() ? item.iconName : item.fadedIconName), + ImGui::Image(gui->GetTextureByName(hasItem && IsValidSaveFile() ? item.iconName : item.fadedIconName), ImVec2(iconSize, iconSize), ImVec2(0, 0), ImVec2(1, 1)); } @@ -1299,13 +1296,13 @@ void DrawDungeonItem(ItemTrackerItem item) { } void DrawSong(ItemTrackerItem item) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); assert(item.kind == ITEM_KIND_QUEST); float iconSize = static_cast(CVarGetInteger(CVAR_TRACKER_ITEM("IconSize"), 36)); ImVec2 p = ImGui::GetCursorScreenPos(); bool hasSong = HasSong(item); ImGui::SetCursorScreenPos(ImVec2(p.x + 6, p.y)); - ImGui::Image(std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(hasSong && IsValidSaveFile() ? item.iconName : item.fadedIconName), + ImGui::Image(gui->GetTextureByName(hasSong && IsValidSaveFile() ? item.iconName : item.fadedIconName), ImVec2(iconSize / 1.5f, iconSize), ImVec2(0, 0), ImVec2(1, 1)); Tooltip(SohUtils::GetQuestItemName(item.id).c_str()); } diff --git a/soh/soh/Enhancements/timesplits/TimeSplits.cpp b/soh/soh/Enhancements/timesplits/TimeSplits.cpp index 57939d3741..689033ec03 100644 --- a/soh/soh/Enhancements/timesplits/TimeSplits.cpp +++ b/soh/soh/Enhancements/timesplits/TimeSplits.cpp @@ -431,16 +431,14 @@ void TimeSplitsFileManagement(uint32_t action, const char* listEntry, std::vecto void TimeSplitsPopUpContext() { if ((popupID != -1) && ImGui::BeginPopup("TimeSplitsPopUp")) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); if (popupID == ITEM_SKULL_TOKEN) { ImGui::BeginTable("Token Table", 2); ImGui::TableNextColumn(); SplitsPushImageButtonStyle(); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 2.0f)); - ImGui::ImageButton( - "QUEST_SKULL_TOKEN", - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName("QUEST_SKULL_TOKEN"), - ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0)); + ImGui::ImageButton("QUEST_SKULL_TOKEN", gui->GetTextureByName("QUEST_SKULL_TOKEN"), ImVec2(32.0f, 32.0f), + ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0)); ImGui::PopStyleVar(); ImGui::TableNextColumn(); SplitsPopImageButtonStyle(); @@ -490,11 +488,9 @@ void TimeSplitsPopUpContext() { ImGui::BeginGroup(); ImGui::PushID(popupObject.splitID); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 2.0f)); - auto ret = ImGui::ImageButton( - popupObject.splitImage.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(popupObject.splitImage), - ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0), popupObject.splitTint); + auto ret = ImGui::ImageButton(popupObject.splitImage.c_str(), + gui->GetTextureByName(popupObject.splitImage), ImVec2(32.0f, 32.0f), + ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0), popupObject.splitTint); ImGui::PopStyleVar(); if (ret) { splitList.push_back(popupObject); @@ -646,6 +642,7 @@ void TimeSplitsDrawSplitsList() { ImGui::BeginChild("SplitTable", ImVec2(0.0f, ImGui::GetWindowHeight() - 128.0f)); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(4, 0)); if (ImGui::BeginTable("Splits", 5, ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable)) { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); ImGui::TableSetupColumn("Item Image", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoHeaderLabel, 34.0f); ImGui::TableSetupColumn("Item Name"); @@ -665,11 +662,8 @@ void TimeSplitsDrawSplitsList() { } TimeSplitsGetImageSize(split.splitID); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(imagePadding, imagePadding)); - auto ret = ImGui::ImageButton( - split.splitImage.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(split.splitImage), - imageSize, ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0), split.splitTint); + auto ret = ImGui::ImageButton(split.splitImage.c_str(), gui->GetTextureByName(split.splitImage), imageSize, + ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0), split.splitTint); ImGui::PopStyleVar(); if (ret) { TimeSplitsSkipSplit(dragIndex); @@ -745,16 +739,15 @@ void TimeSplitsDrawItemList(uint32_t type) { for (auto& split : splitObjectList) { if (split.splitType == type) { + auto gui = + std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); ImGui::TableNextColumn(); ImGui::PushID(split.splitID); TimeSplitsGetImageSize(split.splitID); SplitsPushImageButtonStyle(); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(imagePadding, imagePadding)); - auto ret = ImGui::ImageButton( - split.splitImage.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(split.splitImage), - imageSize, ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0), split.splitTint); + auto ret = ImGui::ImageButton(split.splitImage.c_str(), gui->GetTextureByName(split.splitImage), imageSize, + ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0), split.splitTint); ImGui::PopStyleVar(); if (ret) { if (popupList.contains(split.splitID) && (split.splitType < SPLIT_TYPE_BOSS)) { @@ -883,6 +876,8 @@ void TimeSplitsDrawManageList() { ImGui::TableNextColumn(); ImGui::BeginTabBar("List Preview"); if (ImGui::BeginTabItem("Preview")) { + auto gui = + std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); ImGui::BeginChild("PreviewChild"); for (auto& data : splitList) { float availableWidth = ImGui::GetContentRegionAvail().x; @@ -894,11 +889,9 @@ void TimeSplitsDrawManageList() { } TimeSplitsGetImageSize(data.splitID); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(imagePadding, imagePadding)); - auto ret = ImGui::ImageButton( - data.splitImage.c_str(), - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetTextureByName(data.splitImage), - imageSize, ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0), data.splitTint); + auto ret = + ImGui::ImageButton(data.splitImage.c_str(), gui->GetTextureByName(data.splitImage), imageSize, + ImVec2(0, 0), ImVec2(1, 1), ImVec4(0, 0, 0, 0), data.splitTint); ImGui::PopStyleVar(); if (ret) { removeIndex = index; @@ -980,12 +973,11 @@ void TimeSplitWindow::DrawElement() { } void TimeSplitWindow::InitElement() { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); TimeSplitsUpdateWindowSize(); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("SPECIAL_TRIFORCE_PIECE_WHITE", gWTriforcePieceTex, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("SPECIAL_SPLIT_ENTRANCE", gSplitEntranceTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("SPECIAL_TRIFORCE_PIECE_WHITE", gWTriforcePieceTex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture("SPECIAL_SPLIT_ENTRANCE", gSplitEntranceTex, "", ImVec4(1, 1, 1, 1)); Color_RGBA8 defaultColour = { 0, 0, 0, 255 }; windowColor = VecFromRGBA8(CVarGetColor(CVAR_ENHANCEMENT("TimeSplits.WindowColor.Value"), defaultColour)); diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 1bf777a52d..6b09fe87ab 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1692,6 +1692,7 @@ extern "C" uint64_t GetUnixTimestamp() { } extern "C" void Graph_StartFrame() { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); #ifndef __WIIU__ using Ship::KbScancode; int32_t dwScancode = OTRGlobals::Instance->context->GetWindow()->GetLastScancode(); @@ -1699,9 +1700,8 @@ extern "C" void Graph_StartFrame() { switch (dwScancode) { case KbScancode::LUS_KB_F1: { - std::shared_ptr modal = static_pointer_cast( - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetGuiWindow("Modal Window")); + std::shared_ptr modal = + static_pointer_cast(gui->GetGuiWindow("Modal Window")); if (modal->IsPopupOpen("Menu Moved")) { modal->DismissPopup(); } else { @@ -1714,9 +1714,7 @@ extern "C" void Graph_StartFrame() { } case KbScancode::LUS_KB_F5: { if (CVarGetInteger(CVAR_CHEAT("SaveStatesEnabled"), 0) == 0) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetGameOverlay() - ->TextDrawNotification(6.0f, true, "Save states not enabled. Check Cheats Menu."); + gui->GetGameOverlay()->TextDrawNotification(6.0f, true, "Save states not enabled. Check Cheats Menu."); return; } const unsigned int slot = OTRGlobals::Instance->gSaveStateMgr->GetCurrentSlot(); @@ -1736,9 +1734,7 @@ extern "C" void Graph_StartFrame() { } case KbScancode::LUS_KB_F6: { if (CVarGetInteger(CVAR_CHEAT("SaveStatesEnabled"), 0) == 0) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetGameOverlay() - ->TextDrawNotification(6.0f, true, "Save states not enabled. Check Cheats Menu."); + gui->GetGameOverlay()->TextDrawNotification(6.0f, true, "Save states not enabled. Check Cheats Menu."); return; } unsigned int slot = OTRGlobals::Instance->gSaveStateMgr->GetCurrentSlot(); @@ -1752,9 +1748,7 @@ extern "C" void Graph_StartFrame() { } case KbScancode::LUS_KB_F7: { if (CVarGetInteger(CVAR_CHEAT("SaveStatesEnabled"), 0) == 0) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetGameOverlay() - ->TextDrawNotification(6.0f, true, "Save states not enabled. Check Cheats Menu."); + gui->GetGameOverlay()->TextDrawNotification(6.0f, true, "Save states not enabled. Check Cheats Menu."); return; } const unsigned int slot = OTRGlobals::Instance->gSaveStateMgr->GetCurrentSlot(); @@ -2201,9 +2195,9 @@ extern "C" void OTRControllerCallback(uint8_t rumble) { static std::shared_ptr controllerConfigWindow = nullptr; if (controllerConfigWindow == nullptr) { - controllerConfigWindow = std::dynamic_pointer_cast( - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetGuiWindow("Controller Configuration")); + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); + controllerConfigWindow = + std::dynamic_pointer_cast(gui->GetGuiWindow("Controller Configuration")); } else if (controllerConfigWindow->TestingRumble()) { return; } @@ -2485,6 +2479,7 @@ bool SoH_HandleConfigDrop(char* filePath) { return false; } try { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); std::ifstream configStream(filePath); if (!configStream) { return false; @@ -2522,17 +2517,13 @@ bool SoH_HandleConfigDrop(char* filePath) { } } - auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); gui->GetGuiWindow("Console")->Hide(); gui->GetGuiWindow("Actor Viewer")->Hide(); gui->GetGuiWindow("Collision Viewer")->Hide(); gui->GetGuiWindow("Save Editor")->Hide(); gui->GetGuiWindow("Display List Viewer")->Hide(); gui->GetGuiWindow("Stats")->Hide(); - std::dynamic_pointer_cast( - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->GetGuiWindow("Console")) - ->ClearBindings(); + std::dynamic_pointer_cast(gui->GetGuiWindow("Console"))->ClearBindings(); Rando::Settings::GetInstance()->UpdateAllOptions(); SohGui::MarkRandomizerMenusDirty(); diff --git a/soh/soh/SohGui/ImGuiUtils.cpp b/soh/soh/SohGui/ImGuiUtils.cpp index 4be40a681a..5452e3d290 100644 --- a/soh/soh/SohGui/ImGuiUtils.cpp +++ b/soh/soh/SohGui/ImGuiUtils.cpp @@ -221,72 +221,56 @@ const char* GetTextureForItemId(uint32_t itemId) { } void RegisterImGuiItemIcons() { + auto gui = std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()); for (const auto& entry : itemMapping) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", ImVec4(1, 1, 1, 0.3f)); + gui->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", ImVec4(1, 1, 1, 0.3f)); } for (const auto& entry : gregMapping) { ImVec4 gregGreen = ImVec4(42.0f / 255.0f, 169.0f / 255.0f, 40.0f / 255.0f, 1.0f); ImVec4 gregFadedGreen = gregGreen; gregFadedGreen.w = 0.3f; - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", gregGreen); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", gregFadedGreen); + gui->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", gregGreen); + gui->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", gregFadedGreen); } for (const auto& entry : customItemsMapping) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", ImVec4(1, 1, 1, 0.3f)); + gui->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", ImVec4(1, 1, 1, 0.3f)); } for (const auto& entry : jabbernutMapping) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", ImVec4(1, 1, 1, 0.3f)); + gui->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", ImVec4(1, 1, 1, 0.3f)); } ImVec4 silver = ImVec4(0.7f, 0.7f, 0.7f, 1.0f); ImVec4 silverFaded = silver; silverFaded.w = 0.3f; - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("ITEM_RUPEE_SILVER", gRupeeCounterIconTex, "", silver); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture("ITEM_RUPEE_SILVER_Faded", gRupeeCounterIconTex, "", silverFaded); + gui->LoadGuiTexture("ITEM_RUPEE_SILVER", gRupeeCounterIconTex, "", silver); + gui->LoadGuiTexture("ITEM_RUPEE_SILVER_Faded", gRupeeCounterIconTex, "", silverFaded); for (const auto& entry : questMapping) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", ImVec4(1, 1, 1, 1)); - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", ImVec4(1, 1, 1, 0.3f)); + gui->LoadGuiTexture(entry.second.name, entry.second.texturePath, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture(entry.second.nameFaded, entry.second.texturePath, "", ImVec4(1, 1, 1, 0.3f)); } for (const auto& [quest, entry] : songMapping) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.name, gSongNoteTex, "", entry.color); + gui->LoadGuiTexture(entry.name, gSongNoteTex, "", entry.color); ImVec4 fadedCol = entry.color; fadedCol.w = 0.3f; - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.nameFaded, gSongNoteTex, "", fadedCol); + gui->LoadGuiTexture(entry.nameFaded, gSongNoteTex, "", fadedCol); } for (const auto& entry : vanillaSongMapping) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.name, gSongNoteTex, "", entry.color); + gui->LoadGuiTexture(entry.name, gSongNoteTex, "", entry.color); ImVec4 fadedCol = entry.color; fadedCol.w = 0.3f; - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.nameFaded, gSongNoteTex, "", fadedCol); + gui->LoadGuiTexture(entry.nameFaded, gSongNoteTex, "", fadedCol); } for (const auto& entry : gSeedTextures) { - std::dynamic_pointer_cast(Ship::Context::GetRawInstance()->GetWindow()->GetGui()) - ->LoadGuiTexture(entry.tex, entry.tex, "", ImVec4(1, 1, 1, 1)); + gui->LoadGuiTexture(entry.tex, entry.tex, "", ImVec4(1, 1, 1, 1)); } } \ No newline at end of file