From d73836ce8111f42918549168bc937386baa60a2a Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Tue, 17 May 2022 16:51:59 +0600 Subject: [PATCH] Return key name instead of unknown --- resource/common/locale/English.json | 6 +++--- src/locale.h | 11 ++++++----- src/pch.h | 4 ++-- src/ui.cpp | 8 ++++---- src/ui.h | 6 +++--- src/weapon.cpp | 11 ++--------- 6 files changed, 20 insertions(+), 26 deletions(-) diff --git a/resource/common/locale/English.json b/resource/common/locale/English.json index 2e4757b..cc09c73 100644 --- a/resource/common/locale/English.json +++ b/resource/common/locale/English.json @@ -619,9 +619,9 @@ "MoveWhenFiring": "Move when firing", "RapidFire": "Rapid fire", "SelectGang": "Select gang", - "Weapon1": "Weap 1", - "Weapon2": "Weap 2", - "Weapon3": "Weap 3", + "Weapon1": "Weapon 1", + "Weapon2": "Weapon 2", + "Weapon3": "Weapon 3", "WeaponTweaksText": "Weapon tweaks apply globally\nto every ped weapon type" }, "Window": { diff --git a/src/locale.h b/src/locale.h index c3c7a4a..f9833bf 100644 --- a/src/locale.h +++ b/src/locale.h @@ -56,11 +56,12 @@ public: return defaultValue; } -#ifdef _GTA_ - // Wanted to do this in the macro TEXT/ TEXT_S - // But VS Code complains about it so.. - defaultValue += "##" + key; -#endif + // Return keyname if no default value is provided + if (defaultValue == "") + { + defaultValue = "#" + key; + } + std::string rtn = m_pJson->GetValueStr(key, defaultValue); if (rtn == defaultValue) diff --git a/src/pch.h b/src/pch.h index 4310265..7334505 100644 --- a/src/pch.h +++ b/src/pch.h @@ -76,8 +76,8 @@ #include "fontmgr.h" #include "locale.h" -#define TEXT(x) Locale::GetText(x, "Unknown").c_str() -#define TEXT_S(x) Locale::GetText(x,"Unknown") +#define TEXT(x) Locale::GetText(x).c_str() +#define TEXT_S(x) Locale::GetText(x) using namespace plugin; diff --git a/src/ui.cpp b/src/ui.cpp index bba557e..12079f0 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -99,7 +99,7 @@ bool Ui::RoundedImageButton(ImTextureID user_texture_id, ImVec2& size, const cha return ImGui::IsItemClicked(0); } -bool Ui::ListBox(const char* label, std::vector& all_items, int& selected) +bool Ui::ListBox(const char* label, const std::vector& all_items, int& selected) { bool rtn = false; if (ImGui::BeginCombo(label, all_items[selected].c_str())) @@ -120,7 +120,7 @@ bool Ui::ListBox(const char* label, std::vector& all_items, int& se return rtn; } -bool Ui::ListBoxStr(const char* label, std::vector& all_items, std::string& selected) +bool Ui::ListBoxStr(const char* label, const std::vector& all_items, std::string& selected) { bool rtn = false; if (ImGui::BeginCombo(label, selected.c_str())) @@ -139,7 +139,7 @@ bool Ui::ListBoxStr(const char* label, std::vector& all_items, std: return rtn; } -bool Ui::ListBoxCustomNames(const char* label, std::vector& all_items, std::string& selected, const char* customNames[], size_t length) +bool Ui::ListBoxCustomNames(const char* label, std::string& selected, const char* customNames[], size_t length) { bool rtn = false; std::string display_selected = (selected == "All") ? selected : customNames[std::stoi(selected)]; @@ -558,7 +558,7 @@ void Ui::DrawImages(ResourceStore &store, std::function onLe ImGui::PushItemWidth((ImGui::GetWindowContentRegionWidth() - style.ItemSpacing.x)/2); if (customNames) { - ListBoxCustomNames("##Categories", store.m_Categories, store.m_Selected, customNames, length); + ListBoxCustomNames("##Categories", store.m_Selected, customNames, length); } else { diff --git a/src/ui.h b/src/ui.h index c06fc18..9e56445 100644 --- a/src/ui.h +++ b/src/ui.h @@ -75,9 +75,9 @@ public: static ImVec2 GetSize(short count = 1, bool spacing = true); - static bool ListBox(const char* label, std::vector& all_items, int& selected); - static bool ListBoxStr(const char* label, std::vector& all_items, std::string& selected); - static bool ListBoxCustomNames(const char* label, std::vector& all_items, std::string& selected, const char* custom_names[] = nullptr, size_t length = 0); + static bool ListBox(const char* label, const std::vector& all_items, int& selected); + static bool ListBoxStr(const char* label, const std::vector& all_items, std::string& selected); + static bool ListBoxCustomNames(const char* label, std::string& selected, const char* custom_names[] = nullptr, size_t length = 0); static void RadioButtonAddress(const char* label, std::vector& named_mem); static void RadioButtonAddressEx(const char* label, int addr, std::vector& named_val); diff --git a/src/weapon.cpp b/src/weapon.cpp index 372c358..1d0f4ad 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -367,15 +367,8 @@ void Weapon::ShowPage() { ImGui::Spacing(); Ui::ListBox(TEXT("Weapon.SelectGang"), m_GangList, m_nSelectedGang); - - ImGui::Columns(3, 0, false); - ImGui::RadioButton(TEXT("Weapon.Weapon1"), &m_nSelectedWeapon, 0); - ImGui::NextColumn(); - ImGui::RadioButton(TEXT("Weapon.Weapon2"), &m_nSelectedWeapon, 1); - ImGui::NextColumn(); - ImGui::RadioButton(TEXT("Weapon.Weapon3"), &m_nSelectedWeapon, 2); - ImGui::Columns(1); - + std::vector vec = {TEXT("Weapon.Weapon1"), TEXT("Weapon.Weapon2"), TEXT("Weapon.Weapon3")}; + Ui::ListBox(TEXT("Ped.SelectWeapon"), vec, m_nSelectedWeapon); ImGui::Spacing(); ImGui::Text(TEXT("Weapon.CurrentWeapon"), m_WeaponData.m_pJson->m_Data[std::to_string(m_nGangWeaponList[m_nSelectedGang][m_nSelectedWeapon])].get<