mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 22:33:43 -07:00
Apply CVarClear()
calls in CVar-prefixed widget functions.
This commit is contained in:
parent
8ac717525d
commit
26437223c3
3 changed files with 61 additions and 16 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 1d7c3386928fdb919a99e62c2f44ea4942d153e1
|
Subproject commit 35c3a7e80721e5f5a5260753c14499dc943dd3d8
|
|
@ -378,7 +378,11 @@ bool CVarCheckbox(const char* label, const char* cvarName, const CheckboxOptions
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
bool value = (bool)CVarGetInteger(cvarName, options.defaultValue);
|
bool value = (bool)CVarGetInteger(cvarName, options.defaultValue);
|
||||||
if (Checkbox(label, &value, options)) {
|
if (Checkbox(label, &value, options)) {
|
||||||
|
if (value == options.defaultValue) {
|
||||||
|
CVarClear(cvarName);
|
||||||
|
} else {
|
||||||
CVarSetInteger(cvarName, value);
|
CVarSetInteger(cvarName, value);
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ShipInit::Init(cvarName);
|
ShipInit::Init(cvarName);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -609,7 +613,11 @@ bool CVarSliderInt(const char* label, const char* cvarName, const IntSliderOptio
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
int32_t value = CVarGetInteger(cvarName, options.defaultValue);
|
int32_t value = CVarGetInteger(cvarName, options.defaultValue);
|
||||||
if (SliderInt(label, &value, options)) {
|
if (SliderInt(label, &value, options)) {
|
||||||
|
if (value == options.defaultValue) {
|
||||||
|
CVarClear(cvarName);
|
||||||
|
} else {
|
||||||
CVarSetInteger(cvarName, value);
|
CVarSetInteger(cvarName, value);
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ShipInit::Init(cvarName);
|
ShipInit::Init(cvarName);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -740,7 +748,11 @@ bool CVarSliderFloat(const char* label, const char* cvarName, const FloatSliderO
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
float value = CVarGetFloat(cvarName, options.defaultValue);
|
float value = CVarGetFloat(cvarName, options.defaultValue);
|
||||||
if (SliderFloat(label, &value, options)) {
|
if (SliderFloat(label, &value, options)) {
|
||||||
|
if (value == options.defaultValue) {
|
||||||
|
CVarClear(cvarName);
|
||||||
|
} else {
|
||||||
CVarSetFloat(cvarName, value);
|
CVarSetFloat(cvarName, value);
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ShipInit::Init(cvarName);
|
ShipInit::Init(cvarName);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -814,7 +826,11 @@ bool CVarInputString(const char* label, const char* cvarName, const InputOptions
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
std::string value = CVarGetString(cvarName, options.defaultValue.c_str());
|
std::string value = CVarGetString(cvarName, options.defaultValue.c_str());
|
||||||
if (InputString(label, &value, options)) {
|
if (InputString(label, &value, options)) {
|
||||||
|
if (value == options.defaultValue) {
|
||||||
|
CVarClear(cvarName);
|
||||||
|
} else {
|
||||||
CVarSetString(cvarName, value.c_str());
|
CVarSetString(cvarName, value.c_str());
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ShipInit::Init(cvarName);
|
ShipInit::Init(cvarName);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -866,7 +882,11 @@ bool CVarInputInt(const char* label, const char* cvarName, const InputOptions& o
|
||||||
int32_t defaultValue = std::stoi(options.defaultValue);
|
int32_t defaultValue = std::stoi(options.defaultValue);
|
||||||
int32_t value = CVarGetInteger(cvarName, defaultValue);
|
int32_t value = CVarGetInteger(cvarName, defaultValue);
|
||||||
if (InputInt(label, &value, options)) {
|
if (InputInt(label, &value, options)) {
|
||||||
|
if (value == defaultValue) {
|
||||||
|
CVarClear(cvarName);
|
||||||
|
} else {
|
||||||
CVarSetInteger(cvarName, value);
|
CVarSetInteger(cvarName, value);
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ShipInit::Init(cvarName);
|
ShipInit::Init(cvarName);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -952,11 +972,15 @@ bool CVarColorPicker(const char* label, const char* cvarName, Color_RGBA8 defaul
|
||||||
UIWidgets::CheckboxOptions({ { .tooltip = "Prevents this color from being changed" } }).Color(themeColor));
|
UIWidgets::CheckboxOptions({ { .tooltip = "Prevents this color from being changed" } }).Color(themeColor));
|
||||||
}
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
if (color.r == defaultColor.r && color.g == defaultColor.g && color.b == defaultColor.b && color.a == defaultColor.a) {
|
||||||
|
CVarClear(valueCVar.c_str());
|
||||||
|
} else {
|
||||||
color.r = (uint8_t)(colorVec.x * 255.0f);
|
color.r = (uint8_t)(colorVec.x * 255.0f);
|
||||||
color.g = (uint8_t)(colorVec.y * 255.0f);
|
color.g = (uint8_t)(colorVec.y * 255.0f);
|
||||||
color.b = (uint8_t)(colorVec.z * 255.0f);
|
color.b = (uint8_t)(colorVec.z * 255.0f);
|
||||||
color.a = (uint8_t)(colorVec.w * 255.0f);
|
color.a = (uint8_t)(colorVec.w * 255.0f);
|
||||||
CVarSetColor(valueCVar.c_str(), color);
|
CVarSetColor(valueCVar.c_str(), color);
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ShipInit::Init(valueCVar.c_str());
|
ShipInit::Init(valueCVar.c_str());
|
||||||
changed = true;
|
changed = true;
|
||||||
|
@ -1028,10 +1052,14 @@ bool CVarRadioButton(const char* text, const char* cvarName, int32_t id, const R
|
||||||
std::string make_invisible = "##" + std::string(text) + std::string(cvarName);
|
std::string make_invisible = "##" + std::string(text) + std::string(cvarName);
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
int val = CVarGetInteger(cvarName, 0);
|
int val = CVarGetInteger(cvarName, options.defaultIndex);
|
||||||
PushStyleCheckbox(options.color);
|
PushStyleCheckbox(options.color);
|
||||||
if (ImGui::RadioButton(make_invisible.c_str(), id == val)) {
|
if (ImGui::RadioButton(make_invisible.c_str(), id == val)) {
|
||||||
|
if (id == options.defaultIndex) {
|
||||||
|
CVarClear(cvarName);
|
||||||
|
} else {
|
||||||
CVarSetInteger(cvarName, id);
|
CVarSetInteger(cvarName, id);
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,6 +399,7 @@ struct FloatSliderOptions : WidgetOptions {
|
||||||
|
|
||||||
struct RadioButtonsOptions : WidgetOptions {
|
struct RadioButtonsOptions : WidgetOptions {
|
||||||
std::unordered_map<int32_t, const char*> buttonMap;
|
std::unordered_map<int32_t, const char*> buttonMap;
|
||||||
|
int32_t defaultIndex = 0;
|
||||||
Colors color = Colors::LightBlue;
|
Colors color = Colors::LightBlue;
|
||||||
|
|
||||||
RadioButtonsOptions& ButtonMap(std::unordered_map<int32_t, const char*> buttonMap_) {
|
RadioButtonsOptions& ButtonMap(std::unordered_map<int32_t, const char*> buttonMap_) {
|
||||||
|
@ -413,6 +414,10 @@ struct RadioButtonsOptions : WidgetOptions {
|
||||||
color = color_;
|
color = color_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
RadioButtonsOptions& DefaultIndex(float defaultIndex_) {
|
||||||
|
defaultIndex = defaultIndex_;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InputOptions : WidgetOptions {
|
struct InputOptions : WidgetOptions {
|
||||||
|
@ -875,7 +880,11 @@ bool CVarCombobox(const char* label, const char* cvarName, const std::unordered_
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
|
int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
|
||||||
if (Combobox<T>(label, &value, comboMap, options)) {
|
if (Combobox<T>(label, &value, comboMap, options)) {
|
||||||
|
if (value == options.defaultIndex) {
|
||||||
|
CVarClear(cvarName);
|
||||||
|
} else {
|
||||||
CVarSetInteger(cvarName, value);
|
CVarSetInteger(cvarName, value);
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ShipInit::Init(cvarName);
|
ShipInit::Init(cvarName);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -889,7 +898,11 @@ bool CVarCombobox(const char* label, const char* cvarName, const std::vector<con
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
|
int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
|
||||||
if (Combobox<T>(label, &value, comboVector, options)) {
|
if (Combobox<T>(label, &value, comboVector, options)) {
|
||||||
|
if (value == options.defaultIndex) {
|
||||||
|
CVarClear(cvarName);
|
||||||
|
} else {
|
||||||
CVarSetInteger(cvarName, value);
|
CVarSetInteger(cvarName, value);
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ShipInit::Init(cvarName);
|
ShipInit::Init(cvarName);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -903,7 +916,11 @@ bool CVarCombobox(const char* label, const char* cvarName, const char* (&comboAr
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
|
int32_t value = CVarGetInteger(cvarName, options.defaultIndex);
|
||||||
if (Combobox<T>(label, &value, comboArray, options)) {
|
if (Combobox<T>(label, &value, comboArray, options)) {
|
||||||
|
if (value == options.defaultIndex) {
|
||||||
|
CVarClear(cvarName);
|
||||||
|
} else {
|
||||||
CVarSetInteger(cvarName, value);
|
CVarSetInteger(cvarName, value);
|
||||||
|
}
|
||||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||||
ShipInit::Init(cvarName);
|
ShipInit::Init(cvarName);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue