Rando: Keyring tristate (#3960)

* Initial implementation

* Fix build

* Update UIWidgets.cpp

* Update option.cpp

* Update settings.cpp

* Update settings.cpp

* Apply Pepper0ni's patch

Co-Authored-By: Pepper0ni <93387759+Pepper0ni@users.noreply.github.com>

* Update option_descriptions.cpp

---------

Co-authored-by: Pepper0ni <93387759+Pepper0ni@users.noreply.github.com>
This commit is contained in:
Pepe20129
2024-07-17 05:25:06 +02:00
committed by GitHub
parent 2ff795e227
commit 8eb6304999
7 changed files with 141 additions and 45 deletions
+52 -3
View File
@@ -127,7 +127,7 @@ namespace UIWidgets {
draw_list->PathStroke(col, 0, thickness);
}
bool CustomCheckbox(const char* label, bool* v, bool disabled, CheckboxGraphics disabledGraphic) {
bool CustomCheckbox(const char* label, bool* v, bool disabled, CheckboxGraphics disabledGraphic, bool renderCrossWhenOff) {
ImGuiWindow* window = ImGui::GetCurrentWindow();
if (window->SkipItems) {
return false;
@@ -168,9 +168,9 @@ namespace UIWidgets {
} else if ((!disabled && *v) || (disabled && disabledGraphic == CheckboxGraphics::Checkmark)) {
const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f));
ImGui::RenderCheckMark(window->DrawList, check_bb.Min + ImVec2(pad, pad), check_col, square_sz - pad * 2.0f);
} else if (disabled && disabledGraphic == CheckboxGraphics::Cross) {
} else if ((!disabled && !*v && renderCrossWhenOff) || (disabled && disabledGraphic == CheckboxGraphics::Cross)) {
const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f));
RenderCross(window->DrawList, check_bb.Min + ImVec2(pad, pad), cross_col, square_sz - pad * 2.0f);
RenderCross(window->DrawList, check_bb.Min + ImVec2(pad, pad), disabled ? cross_col : check_col, square_sz - pad * 2.0f);
}
ImVec2 label_pos = ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y);
@@ -185,6 +185,36 @@ namespace UIWidgets {
return pressed;
}
bool CustomCheckboxTristate(const char* label, int* v, bool disabled, CheckboxGraphics disabledGraphic) {
bool ret;
if (*v == 0) {
bool b = false;
ret = CustomCheckbox(label, &b, disabled, disabledGraphic, true);
if (ret) {
*v = 1;
}
} else if (*v == 1) {
ImGui::PushItemFlag(ImGuiItemFlags_MixedValue, true);
bool b = true;
ret = CustomCheckbox(label, &b, disabled, disabledGraphic, true);
if (ret) {
*v = 2;
}
ImGui::PopItemFlag();
} else if (*v == 2) {
bool b = true;
ret = CustomCheckbox(label, &b, disabled, disabledGraphic, true);
if (ret) {
*v = 0;
}
} else {
SPDLOG_INFO("Invalid CheckBoxTristate value: {}", *v);
*v = 0;
return false;
}
return ret;
}
void ReEnableComponent(const char* disabledTooltipText) {
// End of disable region of previous component
ImGui::PopStyleVar(1);
@@ -218,6 +248,25 @@ namespace UIWidgets {
return changed;
}
bool EnhancementCheckboxTristate(const char* text, const char* cvarName, bool disabled, const char* disabledTooltipText, CheckboxGraphics disabledGraphic, bool defaultValue) {
bool changed = false;
if (disabled) {
DisableComponent(ImGui::GetStyle().Alpha * 0.5f);
}
int val = CVarGetInteger(cvarName, defaultValue);
if (CustomCheckboxTristate(text, &val, disabled, disabledGraphic)) {
CVarSetInteger(cvarName, val);
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
changed = true;
}
if (disabled) {
ReEnableComponent(disabledTooltipText);
}
return changed;
}
bool PaddedEnhancementCheckbox(const char* text, const char* cvarName, bool padTop, bool padBottom, bool disabled, const char* disabledTooltipText, CheckboxGraphics disabledGraphic, bool defaultValue) {
ImGui::BeginGroup();
if (padTop) Spacer(0);