Shipwright/soh/soh/Enhancements/presets.cpp
briaguya 2308ab8823
build soh with LUS 1.0.0 (#2881)
* Bump LUS

* Ship -> LUS namespace change

* z_scene_otr Ship -> LUS namespace

* Starting to get SoH to build with LUS imgui changes.

* start stuff

* gamecontroleditor build issues resolved maybe

* cosmetics editor and what not

* console

* actor viewer

* more stuff

* more stuff

* on to errors that make sense

* putting this down for a bit

* no idea what these errors mean now

* some kind of progress maybe

* latest lus main

* more

* back to linker errors and being lost

* Fixes command function signature.

* More fixes

* Even more fixes

* Bump LUS

* More Fixes.

* Fixes even more errors.

* lus bump

* input editor as var

* audio editor working

* it builds with this

* bump lus

* it opens

* bump lus to latest main again

* make sure to do all the command registering in debugconsole

* lus and what not

* switch type stuff plz

* undo

* do the thing that fixes the thing

* fix mac?

* correctly show/hide menubar on boot

* bump lus

* input blocking updates

* bump lus

* Bump LUS

* Press F1 to open enhancement menus moved to SoH

* lus and rendering backend stuff

* audio backend and lus

* Bump LUS

* Fixes WindowBackend dropdown

* Bump LUS

* misc -> utils and moves binarytools to utils.

* Window refactor

* bump lus

* make it work

* Fixes for moved files again

* Bump LUS

* Mercury -> Config

* Bump LUS

* Reacts to removed LUS hooks and bump LUS

* Remove Hook: GfxInit

* Removes debug audio_setgamevolume to 1

* use non-crashing branch of lus

* fix: make audio init work without hooks

* game icon stuff

* multifix bmp

* use input viewer class branch for now

* just "Ship" it's cleaner

* Bump LUS

* Removed ExitGame hook.

* Bump LUS

* Hook system removed from LUS.

* More LUS updates

* Changes to make window position saving.

* Bump LUS

* Bump LUS (for real)

* LUS resources now return a specialized pointer.

* Bump LUS

* Fixes issue in SetPathways::GetPointerSize

* Bump LUS to 1.0.0

* builds but crashes

* fix crash

* better macro names in debug console

* remove commeted out line

* remove redundant check tracker settings window logic

* remove commented out line

* move the *

* remove extra seqplayers enum def

* this sneaky little guy was hiding behind a wii u ifdef

* remove extra check tracker header

---------

Co-authored-by: Kenix <kenixwhisperwind@gmail.com>
Co-authored-by: briaguya <briaguya@alice>
2023-06-03 15:27:45 -04:00

66 lines
2.4 KiB
C++

#include "presets.h"
#include <variant>
#include <string>
#include <cstdint>
#include <libultraship/bridge.h>
#include "soh/UIWidgets.hpp"
#include <libultraship/libultraship.h>
void clearCvars(std::vector<const char*> cvarsToClear) {
for(const char* cvar : cvarsToClear) {
CVarClear(cvar);
}
}
void applyPreset(std::vector<PresetEntry> entries) {
for(auto& [cvar, type, value] : entries) {
switch (type) {
case PRESET_ENTRY_TYPE_S32:
CVarSetInteger(cvar, std::get<int32_t>(value));
break;
case PRESET_ENTRY_TYPE_FLOAT:
CVarSetFloat(cvar, std::get<float>(value));
break;
case PRESET_ENTRY_TYPE_STRING:
CVarSetString(cvar, std::get<const char*>(value));
break;
}
}
}
void DrawPresetSelector(PresetType presetTypeId) {
const std::string presetTypeCvar = "gPreset" + std::to_string(presetTypeId);
const PresetTypeDefinition presetTypeDef = presetTypes.at(presetTypeId);
const uint16_t selectedPresetId = CVarGetInteger(presetTypeCvar.c_str(), 0);
const PresetDefinition selectedPresetDef = presetTypeDef.presets.at(selectedPresetId);
std::string comboboxTooltip = "";
for ( auto iter = presetTypeDef.presets.begin(); iter != presetTypeDef.presets.end(); ++iter ) {
if (iter->first != 0) comboboxTooltip += "\n\n";
comboboxTooltip += std::string(iter->second.label) + " - " + std::string(iter->second.description);
}
UIWidgets::PaddedText("Presets", false, true);
if (ImGui::BeginCombo("##PresetsComboBox", selectedPresetDef.label)) {
for ( auto iter = presetTypeDef.presets.begin(); iter != presetTypeDef.presets.end(); ++iter ) {
if (ImGui::Selectable(iter->second.label, iter->first == selectedPresetId)) {
CVarSetInteger(presetTypeCvar.c_str(), iter->first);
}
}
ImGui::EndCombo();
}
UIWidgets::Tooltip(comboboxTooltip.c_str());
UIWidgets::Spacer(0);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6.0f, 4.0f));
if (ImGui::Button(("Apply Preset##" + presetTypeCvar).c_str())) {
clearCvars(presetTypeDef.cvarsToClear);
if (selectedPresetId != 0) {
applyPreset(selectedPresetDef.entries);
}
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
}
ImGui::PopStyleVar(1);
}