mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 14:23:44 -07:00
Add presets sidebar, proof of concept row-based listing.
This commit is contained in:
parent
824c203b97
commit
e8d1d367ed
4 changed files with 226 additions and 14 deletions
|
@ -8,12 +8,29 @@
|
|||
#include "soh/SohGui/SohMenu.h"
|
||||
#include "soh/SohGui/SohGui.hpp"
|
||||
|
||||
std::string FormatLocations(std::vector<RandomizerCheck> locs) {
|
||||
std::string locString = "";
|
||||
for (auto loc : locs) {
|
||||
locString += std::to_string(loc) + ",";
|
||||
}
|
||||
return locString;
|
||||
namespace SohGui {
|
||||
extern std::shared_ptr<SohMenu> mSohMenu;
|
||||
}
|
||||
|
||||
void BlankButton() {
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, {0, 0, 0, 0});
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, {0, 0, 0, 0});
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, {0, 0, 0, 0});
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, {0, 0, 0, 0});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8.0f, 8.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 5.0f);
|
||||
}
|
||||
|
||||
void PresetCheckboxStyle(const ImVec4& color) {
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(color.x, color.y, color.z, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(color.x, color.y, color.z, 0.8f));
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(color.x, color.y, color.z, 0.6f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.0f, 0.0f, 0.0f, 0.3f));
|
||||
ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(1.0f, 1.0f, 1.0f, 0.7f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6.0f, 6.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 5.0f);
|
||||
}
|
||||
|
||||
void applyPreset(std::vector<PresetEntry> entries) {
|
||||
|
@ -80,3 +97,195 @@ void DrawPresetSelector(PresetType presetTypeId) {
|
|||
}
|
||||
UIWidgets::PopStyleButton();
|
||||
}
|
||||
|
||||
enum PresetSection {
|
||||
PRESET_SECTION_SETTINGS,
|
||||
PRESET_SECTION_ENHANCEMENTS,
|
||||
PRESET_SECTION_AUDIO,
|
||||
PRESET_SECTION_COSMETICS,
|
||||
PRESET_SECTION_RANDOMIZER,
|
||||
PRESET_SECTION_TRACKERS,
|
||||
};
|
||||
|
||||
struct PresetInfo {
|
||||
std::unordered_map<std::string, CVarVariant> settings;
|
||||
std::unordered_map<std::string, CVarVariant> enhancements;
|
||||
std::unordered_map<std::string, CVarVariant> audio;
|
||||
std::unordered_map<std::string, CVarVariant> cosmetics;
|
||||
std::unordered_map<std::string, CVarVariant> rando;
|
||||
std::unordered_map<std::string, CVarVariant> trackers;
|
||||
|
||||
bool applySettings = true, applyEnhancements = true, applyAudio = true, applyCosmetics = true, applyRando = true, applyTrackers = true;
|
||||
};
|
||||
|
||||
static std::unordered_map<std::string, PresetInfo> presets = {
|
||||
{ "Vanilla Plus", {
|
||||
{},
|
||||
{{"DpadEquips", 1}},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
}}
|
||||
};
|
||||
|
||||
void PresetsCustomWidget(WidgetInfo& info) {
|
||||
UIWidgets::PushStyleTabs(THEME_COLOR);
|
||||
ImGui::PushFont(OTRGlobals::Instance->fontMonoLargest);
|
||||
if (ImGui::BeginTable("PresetWidgetTable", 9)) {
|
||||
ImGui::TableSetupColumn("Name");
|
||||
ImGui::TableSetupColumn("Settings");
|
||||
ImGui::TableSetupColumn("Enhancements");
|
||||
ImGui::TableSetupColumn("Audio");
|
||||
ImGui::TableSetupColumn("Cosmetics");
|
||||
ImGui::TableSetupColumn("Randomizer");
|
||||
ImGui::TableSetupColumn("Trackers");
|
||||
ImGui::TableSetupColumn("Apply", ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize("Delete").x + ImGui::GetStyle().FramePadding.x * 2);
|
||||
ImGui::TableSetupColumn("Delete", ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize("Delete").x + ImGui::GetStyle().FramePadding.x * 2);
|
||||
BlankButton();
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button((ICON_FA_COG + std::string("##") + "headersettings").c_str());
|
||||
UIWidgets::Tooltip("Settings");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button((ICON_FA_PLUS_CIRCLE + std::string("##") + "headerenhancements").c_str());
|
||||
UIWidgets::Tooltip("Enhancements");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button((ICON_FA_MUSIC + std::string("##") + "headeraudio").c_str());
|
||||
UIWidgets::Tooltip("Audio");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button((ICON_FA_PAINT_BRUSH + std::string("##") + "headercosmetics").c_str());
|
||||
UIWidgets::Tooltip("Cosmetics");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button((ICON_FA_RANDOM + std::string("##") + "headerrando").c_str());
|
||||
UIWidgets::Tooltip("Randomizer");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button((ICON_FA_MAP + std::string("##") + "headertrackers").c_str());
|
||||
UIWidgets::Tooltip("Trackers");
|
||||
UIWidgets::PopStyleButton();
|
||||
|
||||
UIWidgets::CheckboxOptions checkboxOptions;
|
||||
checkboxOptions.DefaultValue(true).Padding({ 10.0f, 6.0f }).Color(THEME_COLOR);
|
||||
|
||||
for (auto [name, info] : presets) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(name.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
if (info.settings.empty()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f });
|
||||
BlankButton();
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "settings").c_str());
|
||||
ImGui::EndDisabled();
|
||||
UIWidgets::PopStyleButton();
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
else {
|
||||
UIWidgets::Checkbox(("##" + name + "settings").c_str(), &info.applySettings, UIWidgets::CheckboxOptions().DefaultValue(true));
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
if (info.enhancements.empty()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f });
|
||||
BlankButton();
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "enhancements").c_str());
|
||||
ImGui::EndDisabled();
|
||||
UIWidgets::PopStyleButton();
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
else {
|
||||
checkboxOptions.DefaultValue(info.applyEnhancements);
|
||||
ImGui::PushFont(OTRGlobals::Instance->fontMono);
|
||||
UIWidgets::Checkbox(("##" + name + "enhancements").c_str(), &info.applyEnhancements, checkboxOptions);
|
||||
ImGui::PopFont();
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
if (info.audio.empty()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f });
|
||||
BlankButton();
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "audio").c_str());
|
||||
ImGui::EndDisabled();
|
||||
UIWidgets::PopStyleButton();
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
else {
|
||||
UIWidgets::Checkbox(("##" + name + "audio").c_str(), &info.applyAudio, UIWidgets::CheckboxOptions().DefaultValue(true));
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
if (info.cosmetics.empty()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f });
|
||||
BlankButton();
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "cosmetics").c_str());
|
||||
ImGui::EndDisabled();
|
||||
UIWidgets::PopStyleButton();
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
else {
|
||||
UIWidgets::Checkbox(("##" + name + "cosmetics").c_str(), &info.applyCosmetics, UIWidgets::CheckboxOptions().DefaultValue(true));
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
if (info.rando.empty()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f });
|
||||
BlankButton();
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "rando").c_str());
|
||||
ImGui::EndDisabled();
|
||||
UIWidgets::PopStyleButton();
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
else {
|
||||
UIWidgets::Checkbox(("##" + name + "rando").c_str(), &info.applyRando, UIWidgets::CheckboxOptions().DefaultValue(true));
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
if (info.trackers.empty()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f });
|
||||
BlankButton();
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "trackers").c_str());
|
||||
ImGui::EndDisabled();
|
||||
UIWidgets::PopStyleButton();
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
else {
|
||||
UIWidgets::Checkbox(("##" + name + "trackers").c_str(), &info.applyTrackers, UIWidgets::CheckboxOptions().DefaultValue(true));
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
UIWidgets::PushStyleButton(THEME_COLOR);
|
||||
if (UIWidgets::Button(("Apply##" + name).c_str())) {
|
||||
|
||||
}
|
||||
UIWidgets::PopStyleButton();
|
||||
ImGui::TableNextColumn();
|
||||
UIWidgets::PushStyleButton(THEME_COLOR);
|
||||
if (UIWidgets::Button(("Delete##" + name).c_str())) {
|
||||
presets.erase(name);
|
||||
}
|
||||
UIWidgets::PopStyleButton();
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::PopFont();
|
||||
UIWidgets::PopStyleTabs();
|
||||
}
|
||||
|
||||
void RegisterPresetsWidgets() {
|
||||
SohGui::mSohMenu->AddSidebarEntry("Settings", "Presets", 1);
|
||||
WidgetPath path = { "Settings", "Presets", SECTION_COLUMN_1 };
|
||||
SohGui::mSohMenu->AddWidget(path, "PresetsWidget", WIDGET_CUSTOM)
|
||||
.CustomFunction(PresetsCustomWidget);
|
||||
}
|
||||
|
||||
//static RegisterMenuUpdateFunc updateFunc(UpdateResolutionVars, "Settings", "General");
|
||||
static RegisterMenuInitFunc initFunc(RegisterPresetsWidgets);
|
||||
|
|
|
@ -38,8 +38,6 @@ typedef struct PresetEntry {
|
|||
std::variant<int32_t, float, const char*, std::string> value;
|
||||
} PresetEntry;
|
||||
|
||||
std::string FormatLocations(std::vector<RandomizerCheck> locs);
|
||||
|
||||
void DrawPresetSelector(PresetType presetType);
|
||||
void clearCvars(std::vector<const char*> cvarsToClear);
|
||||
void applyPreset(std::vector<PresetEntry> entries);
|
||||
|
|
|
@ -204,19 +204,19 @@ bool WindowButton(const char* label, const char* cvarName, std::shared_ptr<Ship:
|
|||
return dirty;
|
||||
}
|
||||
|
||||
void PushStyleCheckbox(const ImVec4& color) {
|
||||
void PushStyleCheckbox(const ImVec4& color, ImVec2 padding) {
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(color.x, color.y, color.z, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(color.x, color.y, color.z, 0.8f));
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(color.x, color.y, color.z, 0.6f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.0f, 0.0f, 0.0f, 0.3f));
|
||||
ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(1.0f, 1.0f, 1.0f, 0.7f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 6.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, padding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 5.0f);
|
||||
}
|
||||
|
||||
void PushStyleCheckbox(Colors color) {
|
||||
PushStyleCheckbox(ColorValues.at(color));
|
||||
void PushStyleCheckbox(Colors color, ImVec2 padding) {
|
||||
PushStyleCheckbox(ColorValues.at(color), padding);
|
||||
}
|
||||
|
||||
void PopStyleCheckbox() {
|
||||
|
|
|
@ -194,6 +194,7 @@ struct CheckboxOptions : WidgetOptions {
|
|||
bool defaultValue = false; // Only applicable to CVarCheckbox
|
||||
ComponentAlignments alignment = ComponentAlignments::Left;
|
||||
LabelPositions labelPosition = LabelPositions::Near;
|
||||
ImVec2 padding = ImVec2(10.0f, 8.0f);
|
||||
Colors color = Colors::LightBlue;
|
||||
|
||||
CheckboxOptions& DefaultValue(bool defaultValue_) {
|
||||
|
@ -220,6 +221,10 @@ struct CheckboxOptions : WidgetOptions {
|
|||
WidgetOptions::disabledTooltip = disabledTooltip_;
|
||||
return *this;
|
||||
}
|
||||
CheckboxOptions& Padding(ImVec2 padding_) {
|
||||
padding = padding_;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct ComboboxOptions : WidgetOptions {
|
||||
|
@ -482,8 +487,8 @@ bool Button(const char* label, const ButtonOptions& options = {});
|
|||
bool WindowButton(const char* label, const char* cvarName, std::shared_ptr<Ship::GuiWindow> windowPtr,
|
||||
const WindowButtonOptions& options = {});
|
||||
|
||||
void PushStyleCheckbox(const ImVec4& color);
|
||||
void PushStyleCheckbox(Colors color = Colors::LightBlue);
|
||||
void PushStyleCheckbox(const ImVec4& color, ImVec2 padding = ImVec2(10.0f, 6.0f));
|
||||
void PushStyleCheckbox(Colors color = Colors::LightBlue, ImVec2 padding = ImVec2(10.0f, 6.0f));
|
||||
void PopStyleCheckbox();
|
||||
void RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash);
|
||||
bool Checkbox(const char* label, bool* v, const CheckboxOptions& options = {});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue