Return key name instead of unknown

This commit is contained in:
Grinch_ 2022-05-17 16:51:59 +06:00
parent 52dad9acd8
commit d73836ce81
6 changed files with 20 additions and 26 deletions

View File

@ -619,9 +619,9 @@
"MoveWhenFiring": "Move when firing", "MoveWhenFiring": "Move when firing",
"RapidFire": "Rapid fire", "RapidFire": "Rapid fire",
"SelectGang": "Select gang", "SelectGang": "Select gang",
"Weapon1": "Weap 1", "Weapon1": "Weapon 1",
"Weapon2": "Weap 2", "Weapon2": "Weapon 2",
"Weapon3": "Weap 3", "Weapon3": "Weapon 3",
"WeaponTweaksText": "Weapon tweaks apply globally\nto every ped weapon type" "WeaponTweaksText": "Weapon tweaks apply globally\nto every ped weapon type"
}, },
"Window": { "Window": {

View File

@ -56,11 +56,12 @@ public:
return defaultValue; return defaultValue;
} }
#ifdef _GTA_ // Return keyname if no default value is provided
// Wanted to do this in the macro TEXT/ TEXT_S if (defaultValue == "")
// But VS Code complains about it so.. {
defaultValue += "##" + key; defaultValue = "#" + key;
#endif }
std::string rtn = m_pJson->GetValueStr(key, defaultValue); std::string rtn = m_pJson->GetValueStr(key, defaultValue);
if (rtn == defaultValue) if (rtn == defaultValue)

View File

@ -76,8 +76,8 @@
#include "fontmgr.h" #include "fontmgr.h"
#include "locale.h" #include "locale.h"
#define TEXT(x) Locale::GetText(x, "Unknown").c_str() #define TEXT(x) Locale::GetText(x).c_str()
#define TEXT_S(x) Locale::GetText(x,"Unknown") #define TEXT_S(x) Locale::GetText(x)
using namespace plugin; using namespace plugin;

View File

@ -99,7 +99,7 @@ bool Ui::RoundedImageButton(ImTextureID user_texture_id, ImVec2& size, const cha
return ImGui::IsItemClicked(0); return ImGui::IsItemClicked(0);
} }
bool Ui::ListBox(const char* label, std::vector<std::string>& all_items, int& selected) bool Ui::ListBox(const char* label, const std::vector<std::string>& all_items, int& selected)
{ {
bool rtn = false; bool rtn = false;
if (ImGui::BeginCombo(label, all_items[selected].c_str())) if (ImGui::BeginCombo(label, all_items[selected].c_str()))
@ -120,7 +120,7 @@ bool Ui::ListBox(const char* label, std::vector<std::string>& all_items, int& se
return rtn; return rtn;
} }
bool Ui::ListBoxStr(const char* label, std::vector<std::string>& all_items, std::string& selected) bool Ui::ListBoxStr(const char* label, const std::vector<std::string>& all_items, std::string& selected)
{ {
bool rtn = false; bool rtn = false;
if (ImGui::BeginCombo(label, selected.c_str())) if (ImGui::BeginCombo(label, selected.c_str()))
@ -139,7 +139,7 @@ bool Ui::ListBoxStr(const char* label, std::vector<std::string>& all_items, std:
return rtn; return rtn;
} }
bool Ui::ListBoxCustomNames(const char* label, std::vector<std::string>& 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; bool rtn = false;
std::string display_selected = (selected == "All") ? selected : customNames[std::stoi(selected)]; std::string display_selected = (selected == "All") ? selected : customNames[std::stoi(selected)];
@ -558,7 +558,7 @@ void Ui::DrawImages(ResourceStore &store, std::function<void(std::string&)> onLe
ImGui::PushItemWidth((ImGui::GetWindowContentRegionWidth() - style.ItemSpacing.x)/2); ImGui::PushItemWidth((ImGui::GetWindowContentRegionWidth() - style.ItemSpacing.x)/2);
if (customNames) if (customNames)
{ {
ListBoxCustomNames("##Categories", store.m_Categories, store.m_Selected, customNames, length); ListBoxCustomNames("##Categories", store.m_Selected, customNames, length);
} }
else else
{ {

View File

@ -75,9 +75,9 @@ public:
static ImVec2 GetSize(short count = 1, bool spacing = true); static ImVec2 GetSize(short count = 1, bool spacing = true);
static bool ListBox(const char* label, std::vector<std::string>& all_items, int& selected); static bool ListBox(const char* label, const std::vector<std::string>& all_items, int& selected);
static bool ListBoxStr(const char* label, std::vector<std::string>& all_items, std::string& selected); static bool ListBoxStr(const char* label, const std::vector<std::string>& all_items, std::string& selected);
static bool ListBoxCustomNames(const char* label, std::vector<std::string>& all_items, std::string& selected, const char* custom_names[] = nullptr, size_t length = 0); 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<NamedMemory>& named_mem); static void RadioButtonAddress(const char* label, std::vector<NamedMemory>& named_mem);
static void RadioButtonAddressEx(const char* label, int addr, std::vector<NamedValue>& named_val); static void RadioButtonAddressEx(const char* label, int addr, std::vector<NamedValue>& named_val);

View File

@ -367,15 +367,8 @@ void Weapon::ShowPage()
{ {
ImGui::Spacing(); ImGui::Spacing();
Ui::ListBox(TEXT("Weapon.SelectGang"), m_GangList, m_nSelectedGang); Ui::ListBox(TEXT("Weapon.SelectGang"), m_GangList, m_nSelectedGang);
std::vector<std::string> vec = {TEXT("Weapon.Weapon1"), TEXT("Weapon.Weapon2"), TEXT("Weapon.Weapon3")};
ImGui::Columns(3, 0, false); Ui::ListBox(TEXT("Ped.SelectWeapon"), vec, m_nSelectedWeapon);
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);
ImGui::Spacing(); ImGui::Spacing();
ImGui::Text(TEXT("Weapon.CurrentWeapon"), ImGui::Text(TEXT("Weapon.CurrentWeapon"),
m_WeaponData.m_pJson->m_Data[std::to_string(m_nGangWeaponList[m_nSelectedGang][m_nSelectedWeapon])].get< m_WeaponData.m_pJson->m_Data[std::to_string(m_nGangWeaponList[m_nSelectedGang][m_nSelectedWeapon])].get<