From bc6def77a4f799a4ecdd15da5ef91da57a640b76 Mon Sep 17 00:00:00 2001 From: Baoulettes Date: Thu, 19 May 2022 19:48:49 +0200 Subject: [PATCH 1/7] ComboBox Simplification --- libultraship/libultraship/SohImGuiImpl.cpp | 41 +++++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index d17d6ccee..207adf86d 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -390,6 +390,32 @@ namespace SohImGui { } } + void EnhancementCombobox(const char* cvarname, const char* ComboArray[], s16 FirstTimeValue = -1){ + //The -1 do not force the make to add a default value + if (FirstTimeValue < 0){ + //If there is no default value it will pass this condition + FirstTimeValue = 0; + } + //And now we set the default value to the CVar fallback + //This way we ensure to show the number we want the user to see the first time + s16 selected=CVar_GetS32(cvarname, FirstTimeValue); + //Now we set the fetched value to the drop box. + //This way if a player set something else than the default it will show their selection. + s16 DefaultValue=selected; + if (ImGui::BeginCombo("##cvarname", ComboArray[DefaultValue])) { + s16 ComboxSize = sizeof(&ComboArray) / sizeof(ComboArray[0]); + //Seem like it does not count entry 0 so it end up doing 0, 1, 2 and count 2 not 3 + for (uint8_t i = 0; i <= ComboxSize+1; i++) { + if (ImGui::Selectable(ComboArray[i], i==selected)) { + CVar_SetS32(cvarname, i); + selected=i; + needs_save = true; + } + } + ImGui::EndCombo(); + } + } + void EnhancementRadioButton(std::string text, std::string cvarName, int id) { /*Usage : EnhancementRadioButton("My Visible Name","gMyCVarName", MyID); @@ -634,20 +660,9 @@ namespace SohImGui { EXPERIMENTAL(); ImGui::Text("Texture Filter (Needs reload)"); + EnhancementCombobox("gTextureFilter", filters); GfxRenderingAPI* gapi = gfx_get_current_rendering_api(); - if (ImGui::BeginCombo("##filters", filters[gapi->get_texture_filter()])) { - for (int fId = 0; fId <= FilteringMode::NONE; fId++) { - if (ImGui::Selectable(filters[fId], fId == gapi->get_texture_filter())) { - INFO("New Filter: %s", filters[fId]); - gapi->set_texture_filter((FilteringMode)fId); - - CVar_SetS32("gTextureFilter", (int)fId); - needs_save = true; - } - - } - ImGui::EndCombo(); - } + gapi->set_texture_filter((FilteringMode)CVar_GetS32("gTextureFilter", 0)); overlay->DrawSettings(); ImGui::EndMenu(); } From d36b641bfbe5be5158ff09f27bd7971ac1bcb21d Mon Sep 17 00:00:00 2001 From: Baoulettes Date: Thu, 19 May 2022 19:52:30 +0200 Subject: [PATCH 2/7] few things in comment needed fix --- libultraship/libultraship/SohImGuiImpl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 207adf86d..3c92043fa 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -391,9 +391,9 @@ namespace SohImGui { } void EnhancementCombobox(const char* cvarname, const char* ComboArray[], s16 FirstTimeValue = -1){ - //The -1 do not force the make to add a default value + //The -1 do not force the maker to add a default first value if (FirstTimeValue < 0){ - //If there is no default value it will pass this condition + //If there is no default value it will pass this condition and so to prevent crash we set 0 FirstTimeValue = 0; } //And now we set the default value to the CVar fallback From 6229233b5f08b5ecac654be0212cc2c0d5e7a283 Mon Sep 17 00:00:00 2001 From: Baoulettes Date: Thu, 19 May 2022 20:00:36 +0200 Subject: [PATCH 3/7] sizeof fix --- libultraship/libultraship/SohImGuiImpl.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 3c92043fa..86e486066 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -390,7 +390,7 @@ namespace SohImGui { } } - void EnhancementCombobox(const char* cvarname, const char* ComboArray[], s16 FirstTimeValue = -1){ + void EnhancementCombobox(const char* name, const char* ComboArray[], s16 FirstTimeValue = -1){ //The -1 do not force the maker to add a default first value if (FirstTimeValue < 0){ //If there is no default value it will pass this condition and so to prevent crash we set 0 @@ -398,16 +398,17 @@ namespace SohImGui { } //And now we set the default value to the CVar fallback //This way we ensure to show the number we want the user to see the first time - s16 selected=CVar_GetS32(cvarname, FirstTimeValue); + s16 selected=CVar_GetS32(name, FirstTimeValue); //Now we set the fetched value to the drop box. //This way if a player set something else than the default it will show their selection. s16 DefaultValue=selected; - if (ImGui::BeginCombo("##cvarname", ComboArray[DefaultValue])) { - s16 ComboxSize = sizeof(&ComboArray) / sizeof(ComboArray[0]); + if (ImGui::BeginCombo("##name", ComboArray[DefaultValue])) { + //char *[] got two extra : '\123' (begin) '\n' (last) + s16 ComboxSize = sizeof(&ComboArray)-2; //Seem like it does not count entry 0 so it end up doing 0, 1, 2 and count 2 not 3 - for (uint8_t i = 0; i <= ComboxSize+1; i++) { + for (uint8_t i = 0; i <= ComboxSize; i++) { if (ImGui::Selectable(ComboArray[i], i==selected)) { - CVar_SetS32(cvarname, i); + CVar_SetS32(name, i); selected=i; needs_save = true; } From bb44350a8f9524f064fbd0fbf9e9fecf73ee36b4 Mon Sep 17 00:00:00 2001 From: Baoulettes Date: Fri, 20 May 2022 02:42:53 +0200 Subject: [PATCH 4/7] Remove comment and stuff useless --- libultraship/libultraship/SohImGuiImpl.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 86e486066..1986cc889 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -391,26 +391,20 @@ namespace SohImGui { } void EnhancementCombobox(const char* name, const char* ComboArray[], s16 FirstTimeValue = -1){ - //The -1 do not force the maker to add a default first value if (FirstTimeValue < 0){ - //If there is no default value it will pass this condition and so to prevent crash we set 0 FirstTimeValue = 0; } - //And now we set the default value to the CVar fallback - //This way we ensure to show the number we want the user to see the first time s16 selected=CVar_GetS32(name, FirstTimeValue); - //Now we set the fetched value to the drop box. - //This way if a player set something else than the default it will show their selection. s16 DefaultValue=selected; if (ImGui::BeginCombo("##name", ComboArray[DefaultValue])) { - //char *[] got two extra : '\123' (begin) '\n' (last) - s16 ComboxSize = sizeof(&ComboArray)-2; - //Seem like it does not count entry 0 so it end up doing 0, 1, 2 and count 2 not 3 + s16 ComboxSize = sizeof(&ComboArray); for (uint8_t i = 0; i <= ComboxSize; i++) { - if (ImGui::Selectable(ComboArray[i], i==selected)) { + if (strlen(ComboArray[i]) > 1) { + if (ImGui::Selectable(ComboArray[i], i==selected)) { CVar_SetS32(name, i); selected=i; needs_save = true; + } } } ImGui::EndCombo(); From 49e15d342d2cd4f6ba89fff79feff51c21839107 Mon Sep 17 00:00:00 2001 From: Baoulettes Date: Fri, 20 May 2022 02:44:37 +0200 Subject: [PATCH 5/7] Add definition --- libultraship/libultraship/SohImGuiImpl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libultraship/libultraship/SohImGuiImpl.h b/libultraship/libultraship/SohImGuiImpl.h index dd0ec9fd3..665897e82 100644 --- a/libultraship/libultraship/SohImGuiImpl.h +++ b/libultraship/libultraship/SohImGuiImpl.h @@ -68,6 +68,7 @@ namespace SohImGui { void EnhancementCheckbox(std::string text, std::string cvarName); void EnhancementSliderInt(std::string text, std::string id, std::string cvarName, int min, int max, std::string format); void EnhancementSliderFloat(std::string text, std::string id, std::string cvarName, float min, float max, std::string format, float defaultValue); + void EnhancementCombobox(const char* name, const char* ComboArray[], s16 FirstTimeValue = -1); void DrawMainMenuAndCalculateGameSize(void); From c0cd3b54006f63cab7600a6db7779b8958b7064a Mon Sep 17 00:00:00 2001 From: Baoulettes Date: Fri, 20 May 2022 15:07:15 +0200 Subject: [PATCH 6/7] Changing int type --- libultraship/libultraship/SohImGuiImpl.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 1986cc889..de3617334 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -390,14 +390,14 @@ namespace SohImGui { } } - void EnhancementCombobox(const char* name, const char* ComboArray[], s16 FirstTimeValue = -1){ - if (FirstTimeValue < 0){ + void EnhancementCombobox(const char* name, const char* ComboArray[], uint8_t FirstTimeValue = 0){ + if (FirstTimeValue <= 0){ FirstTimeValue = 0; } - s16 selected=CVar_GetS32(name, FirstTimeValue); - s16 DefaultValue=selected; + uint8_t selected=CVar_GetS32(name, FirstTimeValue); + uint8_t DefaultValue=selected; if (ImGui::BeginCombo("##name", ComboArray[DefaultValue])) { - s16 ComboxSize = sizeof(&ComboArray); + uint8_t ComboxSize = sizeof(&ComboArray); for (uint8_t i = 0; i <= ComboxSize; i++) { if (strlen(ComboArray[i]) > 1) { if (ImGui::Selectable(ComboArray[i], i==selected)) { From 2115111ea8b71d36b3df3e1b95092f83bf05eb4e Mon Sep 17 00:00:00 2001 From: Baoulettes Date: Fri, 20 May 2022 15:08:03 +0200 Subject: [PATCH 7/7] fix int type, removing default value, should build --- libultraship/libultraship/SohImGuiImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship/libultraship/SohImGuiImpl.h b/libultraship/libultraship/SohImGuiImpl.h index 665897e82..c2f4649df 100644 --- a/libultraship/libultraship/SohImGuiImpl.h +++ b/libultraship/libultraship/SohImGuiImpl.h @@ -68,7 +68,7 @@ namespace SohImGui { void EnhancementCheckbox(std::string text, std::string cvarName); void EnhancementSliderInt(std::string text, std::string id, std::string cvarName, int min, int max, std::string format); void EnhancementSliderFloat(std::string text, std::string id, std::string cvarName, float min, float max, std::string format, float defaultValue); - void EnhancementCombobox(const char* name, const char* ComboArray[], s16 FirstTimeValue = -1); + void EnhancementCombobox(const char* name, const char* ComboArray[], uint8_t FirstTimeValue); void DrawMainMenuAndCalculateGameSize(void);