mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-04-28 13:17:58 +03:00
Remove MenuOptionIndex Middleman and fix rando presets (#5185)
* Remove CVar Middleman and fix rando presets * Throwing in a couple of typo corrections
This commit is contained in:
parent
2564721b2c
commit
45b8f228d9
8 changed files with 13 additions and 77 deletions
|
@ -75,9 +75,6 @@ void DrawPresetSelector(PresetType presetTypeId) {
|
|||
}
|
||||
CVarSetInteger(presetTypeCvar.c_str(), selectedPresetId);
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||
if (presetTypeId == PRESET_TYPE_RANDOMIZER){
|
||||
Rando::Settings::GetInstance()->ReloadOptions();
|
||||
}
|
||||
}
|
||||
UIWidgets::PopStyleButton();
|
||||
}
|
||||
|
|
|
@ -62,8 +62,8 @@ const std::string& Option::GetDescription() const {
|
|||
return description;
|
||||
}
|
||||
|
||||
uint8_t Option::GetMenuOptionIndex() const {
|
||||
return menuSelection;
|
||||
uint8_t Option::GetOptionIndex() const {
|
||||
return CVarGetInteger(cvarName.c_str(), defaultOption);
|
||||
}
|
||||
|
||||
const std::string& Option::GetOptionText(size_t index) const {
|
||||
|
@ -74,18 +74,6 @@ const std::string& Option::GetCVarName() const {
|
|||
return cvarName;
|
||||
}
|
||||
|
||||
void Option::SaveCVar() const {
|
||||
if (!cvarName.empty()) {
|
||||
CVarSetInteger(cvarName.c_str(), GetMenuOptionIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void Option::SetFromCVar() {
|
||||
if (!cvarName.empty()) {
|
||||
SetMenuIndex(CVarGetInteger(cvarName.c_str(), defaultOption));
|
||||
}
|
||||
}
|
||||
|
||||
void Option::SetDelayedOption() {
|
||||
delayedSelection = contextSelection;
|
||||
}
|
||||
|
@ -94,13 +82,6 @@ void Option::RestoreDelayedOption() {
|
|||
contextSelection = delayedSelection;
|
||||
}
|
||||
|
||||
void Option::SetMenuIndex(size_t idx) {
|
||||
menuSelection = idx;
|
||||
if (menuSelection > options.size() - 1) {
|
||||
menuSelection = options.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Option::SetContextIndex(size_t idx) {
|
||||
// TODO: Set to Context's OptionValue array.
|
||||
contextSelection = idx;
|
||||
|
@ -122,8 +103,8 @@ bool Option::IsHidden() const {
|
|||
}
|
||||
|
||||
void Option::ChangeOptions(std::vector<std::string> opts) {
|
||||
if (menuSelection >= opts.size()) {
|
||||
menuSelection = opts.size() - 1;
|
||||
if (GetOptionIndex() >= opts.size()) {
|
||||
CVarSetInteger(cvarName.c_str(), opts.size() - 1);
|
||||
}
|
||||
options = std::move(opts);
|
||||
}
|
||||
|
@ -202,10 +183,9 @@ Option::Option(size_t key_, std::string name_, std::vector<std::string> options_
|
|||
: key(key_), name(std::move(name_)), options(std::move(options_)), category(category_),
|
||||
cvarName(std::move(cvarName_)), description(std::move(description_)), widgetType(widgetType_),
|
||||
defaultOption(defaultOption_), defaultHidden(defaultHidden_), imFlags(imFlags_) {
|
||||
menuSelection = contextSelection = defaultOption;
|
||||
contextSelection = defaultOption;
|
||||
hidden = defaultHidden;
|
||||
PopulateTextToNum();
|
||||
SetFromCVar();
|
||||
}
|
||||
|
||||
bool Option::RenderCheckbox() {
|
||||
|
@ -245,10 +225,9 @@ bool Option::RenderCombobox() {
|
|||
|
||||
bool Option::RenderSlider() {
|
||||
bool changed = false;
|
||||
int val = GetMenuOptionIndex();
|
||||
int val = CVarGetInteger(cvarName.c_str(), defaultOption);
|
||||
if (val > options.size() - 1) {
|
||||
val = options.size() - 1;
|
||||
CVarSetInteger(cvarName.c_str(), val);
|
||||
changed = true;
|
||||
}
|
||||
UIWidgets::IntSliderOptions widgetOptions = UIWidgets::IntSliderOptions().Color(THEME_COLOR).Min(0).Max(options.size() - 1).Tooltip(description.c_str()).Format(options[val].c_str()).DefaultValue(defaultOption);
|
||||
|
@ -266,7 +245,6 @@ bool Option::RenderSlider() {
|
|||
}
|
||||
if (changed) {
|
||||
CVarSetInteger(cvarName.c_str(), val);
|
||||
SetFromCVar();
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||
}
|
||||
return changed;
|
||||
|
|
|
@ -225,19 +225,7 @@ class Option {
|
|||
*
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t GetMenuOptionIndex() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the CVar corresponding to the property `cvarName` equal to the value
|
||||
* of the property `selectedValue`.
|
||||
*/
|
||||
void SaveCVar() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the value of property `selectedValue` equal to the CVar corresponding
|
||||
* to the property `cvarName`.
|
||||
*/
|
||||
void SetFromCVar();
|
||||
uint8_t GetOptionIndex() const;
|
||||
|
||||
/**
|
||||
* @brief Set the delayedOption to the currently selected index so it can be restored later.
|
||||
|
@ -249,13 +237,6 @@ class Option {
|
|||
*/
|
||||
void RestoreDelayedOption();
|
||||
|
||||
/**
|
||||
* @brief Set the menu index for this Option. Also calls `SetVariable()`.
|
||||
*
|
||||
* @param idx the index to set as the selected index.
|
||||
*/
|
||||
void SetMenuIndex(size_t idx);
|
||||
|
||||
/**
|
||||
* @brief Set the rando context index for this Option. Also calls `SetVariable()`.
|
||||
*
|
||||
|
@ -344,7 +325,6 @@ protected:
|
|||
void PopulateTextToNum();
|
||||
std::string name;
|
||||
std::vector<std::string> options;
|
||||
uint8_t menuSelection = 0;
|
||||
uint8_t contextSelection = 0;
|
||||
uint8_t delayedSelection = 0;
|
||||
bool hidden = false;
|
||||
|
|
|
@ -1871,7 +1871,6 @@ void GenerateRandomizerImgui(std::string seed = "") {
|
|||
CVarSave();
|
||||
auto ctx = Rando::Context::GetInstance();
|
||||
//RANDOTODO proper UI for selecting if a spoiler loaded should be used for settings
|
||||
Rando::Settings::GetInstance()->SetAllFromCVar();
|
||||
Rando::Settings::GetInstance()->SetAllToContext();
|
||||
|
||||
// todo: this efficently when we build out cvar array support
|
||||
|
@ -1972,6 +1971,7 @@ void RandomizerSettingsWindow::DrawElement() {
|
|||
}
|
||||
CVarSetInteger(presetTypeCvar.c_str(), randomizerPresetSelected);
|
||||
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
|
||||
mSettings->UpdateOptionProperties();
|
||||
}
|
||||
|
||||
UIWidgets::Spacer(0);
|
||||
|
|
|
@ -1147,12 +1147,6 @@ const OptionGroup& Settings::GetOptionGroup(const RandomizerSettingGroupKey key)
|
|||
return mOptionGroups[key];
|
||||
}
|
||||
|
||||
void Settings::SetAllFromCVar() {
|
||||
for (auto& option : mOptions) {
|
||||
option.SetFromCVar();
|
||||
}
|
||||
}
|
||||
|
||||
void Settings::UpdateOptionProperties() {
|
||||
// Default to hiding bridge opts and the extra sliders.
|
||||
mOptions[RSK_RAINBOW_BRIDGE].AddFlag(IMFLAG_SEPARATOR_BOTTOM);
|
||||
|
@ -2222,11 +2216,6 @@ void Settings::ParseJson(nlohmann::json spoilerFileJson) {
|
|||
}
|
||||
}
|
||||
|
||||
void Settings::ReloadOptions() {
|
||||
for (int i = 0; i < RSK_MAX; i++) {
|
||||
mOptions[i].SetFromCVar();
|
||||
}
|
||||
}
|
||||
void Settings::AssignContext(std::shared_ptr<Context> ctx) {
|
||||
mContext = ctx;
|
||||
}
|
||||
|
@ -2237,13 +2226,13 @@ void Settings::ClearContext() {
|
|||
|
||||
void Settings::SetAllToContext() {
|
||||
for (int i = 0; i < RSK_MAX; i++) {
|
||||
mContext->GetOption(static_cast<RandomizerSettingKey>(i)).Set(mOptions[i].GetMenuOptionIndex());
|
||||
mContext->GetOption(static_cast<RandomizerSettingKey>(i)).Set(mOptions[i].GetOptionIndex());
|
||||
}
|
||||
for (int i = 0; i < RT_MAX; i++) {
|
||||
mContext->GetTrickOption(static_cast<RandomizerTrick>(i)).Set(mTrickOptions[i].GetMenuOptionIndex());
|
||||
mContext->GetTrickOption(static_cast<RandomizerTrick>(i)).Set(mTrickOptions[i].GetOptionIndex());
|
||||
}
|
||||
for (int i = 0; i < RC_MAX; i++) {
|
||||
mContext->GetItemLocation(i)->SetExcludedOption(StaticData::GetLocation(static_cast<RandomizerCheck>(i))->GetExcludedOption()->GetMenuOptionIndex());
|
||||
mContext->GetItemLocation(i)->SetExcludedOption(StaticData::GetLocation(static_cast<RandomizerCheck>(i))->GetExcludedOption()->GetOptionIndex());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,12 +88,6 @@ class Settings {
|
|||
*/
|
||||
const OptionGroup& GetOptionGroup(RandomizerSettingGroupKey key);
|
||||
|
||||
/**
|
||||
* @brief sets the `selectedOption` of all Options to the value of the CVar
|
||||
* corresponding to their `cvarName`s.
|
||||
*/
|
||||
void SetAllFromCVar();
|
||||
|
||||
/**
|
||||
* @brief Updates various properties of options based on the value of other options.
|
||||
* Used to update visibility, whether or not interaction is disabled, and what the
|
||||
|
@ -113,7 +107,6 @@ class Settings {
|
|||
*/
|
||||
void ParseJson(nlohmann::json spoilerFileJson);
|
||||
std::map<RandomizerArea, std::vector<RandomizerTrick>> mTricksByArea = {};
|
||||
void ReloadOptions();
|
||||
|
||||
/**
|
||||
* @brief Assigns a Rando::Context instance to this settings instance
|
||||
|
|
|
@ -2514,7 +2514,6 @@ void SoH_ProcessDroppedFiles(std::string filePath) {
|
|||
}
|
||||
|
||||
Rando::Settings::GetInstance()->UpdateOptionProperties();
|
||||
Rando::Settings::GetInstance()->SetAllFromCVar();
|
||||
|
||||
auto gui = Ship::Context::GetInstance()->GetWindow()->GetGui();
|
||||
gui->GetGuiWindow("Console")->Hide();
|
||||
|
|
|
@ -904,7 +904,7 @@ void SohMenu::AddMenuEnhancements() {
|
|||
.Options(CheckboxOptions().Tooltip(
|
||||
"Removes the Dungeon Entrance icon on the top-left corner of the screen when no dungeon is present on the "
|
||||
"current map."));
|
||||
AddWidget(path, "Fix Two-Handled Idle Animations", WIDGET_CVAR_CHECKBOX)
|
||||
AddWidget(path, "Fix Two-Handed Idle Animations", WIDGET_CVAR_CHECKBOX)
|
||||
.CVar(CVAR_ENHANCEMENT("TwoHandedIdle"))
|
||||
.Options(CheckboxOptions().Tooltip(
|
||||
"Re-Enables the two-handed idle animation, a seemingly finished animation that was disabled on accident "
|
||||
|
@ -975,7 +975,7 @@ void SohMenu::AddMenuEnhancements() {
|
|||
.Options(CheckboxOptions().Tooltip(
|
||||
"Restore pre-release behavior where defeating a Gold Skulltula will play a cutscene showing it die."));
|
||||
AddWidget(path, "Pulsate Boss Icon", WIDGET_CVAR_CHECKBOX)
|
||||
.CVar(CVAR_ENHANCEMENT("Pulsate Boss Icon"))
|
||||
.CVar(CVAR_ENHANCEMENT("PulsateBossIcon"))
|
||||
.Options(CheckboxOptions().Tooltip(
|
||||
"Restores an unfinished feature to pulsate the boss room icon when you are in the boss room."));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue