diff options
| author | Archez <Archez@users.noreply.github.com> | 2024-11-13 20:13:54 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-13 20:13:54 -0500 |
| commit | 6d76ce9f5e60b2e90ceba4b52693214db67e7917 (patch) | |
| tree | d733cd1256ba34a7640fd2199f167c499cb57739 | |
| parent | e0ed28543bde8fa7aa113729dbbfeaac8da7a733 (diff) | |
Fix crashing with modern menu and UIWidgets with no tooltips (#851)
* Fix crashing with modern menu and UIWidgets when null is passed for tooltips
* move to shiputils
| -rw-r--r-- | mm/2s2h/BenGui/Menu.cpp | 3 | ||||
| -rw-r--r-- | mm/2s2h/BenGui/SearchableMenuItems.h | 4 | ||||
| -rw-r--r-- | mm/2s2h/BenGui/UIWidgets.cpp | 17 | ||||
| -rw-r--r-- | mm/2s2h/BenGui/UIWidgets.hpp | 33 | ||||
| -rw-r--r-- | mm/2s2h/DeveloperTools/SaveEditor.cpp | 4 | ||||
| -rw-r--r-- | mm/2s2h/ShipUtils.cpp | 4 | ||||
| -rw-r--r-- | mm/2s2h/ShipUtils.h | 1 |
7 files changed, 39 insertions, 27 deletions
diff --git a/mm/2s2h/BenGui/Menu.cpp b/mm/2s2h/BenGui/Menu.cpp index 554038b64..ca8f04925 100644 --- a/mm/2s2h/BenGui/Menu.cpp +++ b/mm/2s2h/BenGui/Menu.cpp @@ -400,7 +400,8 @@ void BenMenu::DrawElement() { info.isHidden) { continue; } - std::string widgetStr = std::string(info.widgetName) + std::string(info.widgetTooltip); + std::string widgetStr = std::string(info.widgetName) + + std::string(info.widgetTooltip != NULL ? info.widgetTooltip : ""); std::transform(menuSearchText.begin(), menuSearchText.end(), menuSearchText.begin(), ::tolower); std::transform(widgetStr.begin(), widgetStr.end(), widgetStr.begin(), ::tolower); widgetStr.erase(std::remove(widgetStr.begin(), widgetStr.end(), ' '), widgetStr.end()); diff --git a/mm/2s2h/BenGui/SearchableMenuItems.h b/mm/2s2h/BenGui/SearchableMenuItems.h index c03a93faa..a8e22f27d 100644 --- a/mm/2s2h/BenGui/SearchableMenuItems.h +++ b/mm/2s2h/BenGui/SearchableMenuItems.h @@ -1947,7 +1947,9 @@ void SearchMenuGetItem(widgetInfo& widget) { info.widgetType == WIDGET_SEPARATOR_TEXT || info.isHidden) { continue; } - std::string widgetStr = std::string(info.widgetName) + std::string(info.widgetTooltip); + std::string widgetStr = + std::string(info.widgetName) + + std::string(info.widgetTooltip != NULL ? info.widgetTooltip : ""); std::transform(menuSearchText.begin(), menuSearchText.end(), menuSearchText.begin(), ::tolower); menuSearchText.erase(std::remove(menuSearchText.begin(), menuSearchText.end(), ' '), diff --git a/mm/2s2h/BenGui/UIWidgets.cpp b/mm/2s2h/BenGui/UIWidgets.cpp index 632aac6b0..03063aa14 100644 --- a/mm/2s2h/BenGui/UIWidgets.cpp +++ b/mm/2s2h/BenGui/UIWidgets.cpp @@ -6,6 +6,7 @@ #include <string> #include <unordered_map> #include <libultraship/libultra/types.h> +#include "2s2h/ShipUtils.h" namespace UIWidgets { // Automatically adds newlines to break up text longer than a specified number of characters @@ -113,9 +114,9 @@ bool Button(const char* label, const ButtonOptions& options) { PopStyleButton(); ImGui::EndDisabled(); if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && - strcmp(options.disabledTooltip, "") != 0) { + !Ship_IsCStringEmpty(options.disabledTooltip)) { ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); - } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.tooltip, "") != 0) { + } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); } return dirty; @@ -260,9 +261,9 @@ bool Checkbox(const char* _label, bool* value, const CheckboxOptions& options) { PopStyleCheckbox(); ImGui::EndDisabled(); if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && - strcmp(options.disabledTooltip, "") != 0) { + !Ship_IsCStringEmpty(options.disabledTooltip)) { ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); - } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.tooltip, "") != 0) { + } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); } return pressed; @@ -369,9 +370,9 @@ bool SliderInt(const char* label, int32_t* value, int32_t min, int32_t max, cons ImGui::EndDisabled(); ImGui::EndGroup(); if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && - strcmp(options.disabledTooltip, "") != 0) { + !Ship_IsCStringEmpty(options.disabledTooltip)) { ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); - } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.tooltip, "") != 0) { + } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); } ImGui::PopID(); @@ -485,9 +486,9 @@ bool SliderFloat(const char* label, float* value, float min, float max, const Fl ImGui::EndDisabled(); ImGui::EndGroup(); if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && - strcmp(options.disabledTooltip, "") != 0) { + !Ship_IsCStringEmpty(options.disabledTooltip)) { ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); - } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.tooltip, "") != 0) { + } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); } ImGui::PopID(); diff --git a/mm/2s2h/BenGui/UIWidgets.hpp b/mm/2s2h/BenGui/UIWidgets.hpp index 90357360d..875bbecef 100644 --- a/mm/2s2h/BenGui/UIWidgets.hpp +++ b/mm/2s2h/BenGui/UIWidgets.hpp @@ -9,6 +9,7 @@ #include <imgui.h> #include <libultraship/libultraship.h> #include <unordered_map> +#include "2s2h/ShipUtils.h" namespace UIWidgets { @@ -129,7 +130,7 @@ namespace UIWidgets { PushStyleCombobox(options.color); if (options.alignment == ComponentAlignment::Left) { if (options.labelPosition == LabelPosition::Above) { - ImGui::Text(label); + ImGui::Text("%s", label); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } else if (options.labelPosition == LabelPosition::Near) { ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2); @@ -140,7 +141,7 @@ namespace UIWidgets { if (options.labelPosition == LabelPosition::Above) { ImGui::NewLine(); ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x); - ImGui::Text(label); + ImGui::Text("%s", label); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } else if (options.labelPosition == LabelPosition::Near) { ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2); @@ -167,23 +168,23 @@ namespace UIWidgets { if (options.alignment == ComponentAlignment::Left) { if (options.labelPosition == LabelPosition::Near) { ImGui::SameLine(); - ImGui::Text(label); + ImGui::Text("%s", label); } else if (options.labelPosition == LabelPosition::Far) { ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x); - ImGui::Text(label); + ImGui::Text("%s", label); } } else if (options.alignment == ComponentAlignment::Right) { if (options.labelPosition == LabelPosition::Near || options.labelPosition == LabelPosition::Far) { ImGui::SameLine(startX); - ImGui::Text(label); + ImGui::Text("%s", label); } } PopStyleCombobox(); ImGui::EndDisabled(); ImGui::EndGroup(); - if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.disabledTooltip, "") != 0) { + if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.disabledTooltip)) { ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); - } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.tooltip, "") != 0) { + } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); } ImGui::PopID(); @@ -256,9 +257,9 @@ namespace UIWidgets { PopStyleCombobox(); ImGui::EndDisabled(); ImGui::EndGroup(); - if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.disabledTooltip, "") != 0) { + if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.disabledTooltip)) { ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); - } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.tooltip, "") != 0) { + } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); } ImGui::PopID(); @@ -281,7 +282,7 @@ namespace UIWidgets { PushStyleCombobox(options.color); if (options.alignment == ComponentAlignment::Left) { if (options.labelPosition == LabelPosition::Above) { - ImGui::Text(label); + ImGui::Text("%s", label); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } else if (options.labelPosition == LabelPosition::Near) { ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x - ImGui::GetStyle().ItemSpacing.x * 2); @@ -292,7 +293,7 @@ namespace UIWidgets { if (options.labelPosition == LabelPosition::Above) { ImGui::NewLine(); ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x); - ImGui::Text(label); + ImGui::Text("%s", label); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); } else if (options.labelPosition == LabelPosition::Near) { ImGui::SameLine(ImGui::CalcTextSize(label).x + ImGui::GetStyle().ItemSpacing.x * 2); @@ -320,23 +321,23 @@ namespace UIWidgets { if (options.alignment == ComponentAlignment::Left) { if (options.labelPosition == LabelPosition::Near) { ImGui::SameLine(); - ImGui::Text(label); + ImGui::Text("%s", label); } else if (options.labelPosition == LabelPosition::Far) { ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(label).x); - ImGui::Text(label); + ImGui::Text("%s", label); } } else if (options.alignment == ComponentAlignment::Right) { if (options.labelPosition == LabelPosition::Near || options.labelPosition == LabelPosition::Far) { ImGui::SameLine(startX); - ImGui::Text(label); + ImGui::Text("%s", label); } } PopStyleCombobox(); ImGui::EndDisabled(); ImGui::EndGroup(); - if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.disabledTooltip, "") != 0) { + if (options.disabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.disabledTooltip)) { ImGui::SetTooltip("%s", WrappedText(options.disabledTooltip).c_str()); - } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(options.tooltip, "") != 0) { + } else if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !Ship_IsCStringEmpty(options.tooltip)) { ImGui::SetTooltip("%s", WrappedText(options.tooltip).c_str()); } ImGui::PopID(); diff --git a/mm/2s2h/DeveloperTools/SaveEditor.cpp b/mm/2s2h/DeveloperTools/SaveEditor.cpp index 40e0a0062..acd9aa9a7 100644 --- a/mm/2s2h/DeveloperTools/SaveEditor.cpp +++ b/mm/2s2h/DeveloperTools/SaveEditor.cpp @@ -559,13 +559,15 @@ void DrawGeneralTab() { if (ImGui::SliderInt("##setBank", &bankedRupees, 0, 5000, "Banked Rupees: %d")) { HS_SET_BANK_RUPEES(bankedRupees); } - UIWidgets::Tooltip("To recieve the rewards, set the bank to 199, 999, or 4,999 then deposit a single rupee"); + UIWidgets::Tooltip("To receive the rewards, set the bank to 199, 999, or 4,999 then deposit a single rupee"); UIWidgets::PopStyleSlider(); DrawTempleClears(); UIWidgets::Checkbox("Has Tatl", (bool*)&gSaveContext.save.hasTatl, { .color = UIWidgets::Colors::Gray }); UIWidgets::Checkbox("Is Owl Save", (bool*)&gSaveContext.save.isOwlSave, { .color = UIWidgets::Colors::Gray }); + UIWidgets::Checkbox("Finished Intro Sequence", (bool*)&gSaveContext.save.isFirstCycle, + { .color = UIWidgets::Colors::Gray }); ImGui::EndGroup(); ImGui::PopItemWidth(); diff --git a/mm/2s2h/ShipUtils.cpp b/mm/2s2h/ShipUtils.cpp index 2b4c26ce9..c657d5ec1 100644 --- a/mm/2s2h/ShipUtils.cpp +++ b/mm/2s2h/ShipUtils.cpp @@ -12,6 +12,10 @@ extern TexturePtr gQuestIcons[14]; extern TexturePtr gBombersNotebookPhotos[24]; } +extern "C" bool Ship_IsCStringEmpty(const char* str) { + return str == NULL || str[0] == '\0'; +} + // Build vertex coordinates for a quad command // In order of top left, top right, bottom left, then bottom right // Supports flipping the texture horizontally diff --git a/mm/2s2h/ShipUtils.h b/mm/2s2h/ShipUtils.h index 8afcb5117..6b3f5d729 100644 --- a/mm/2s2h/ShipUtils.h +++ b/mm/2s2h/ShipUtils.h @@ -11,6 +11,7 @@ void LoadGuiTextures(); extern "C" { #endif +bool Ship_IsCStringEmpty(const char* str); void Ship_CreateQuadVertexGroup(Vtx* vtxList, s32 xStart, s32 yStart, s32 width, s32 height, u8 flippedH); f32 Ship_GetCharFontWidthNES(u8 character); TexturePtr Ship_GetCharFontTextureNES(u8 character); |
