Fixes crash during randomization of individual sound effects. (#2203)

* Fixes randomization of individual sound effects.

* Re-adds the mistakenly removed const specifier.

* Implements new randomization syntax that actually fixes the crash.

* Increases default width of sfx editor menu.

The default width was cutting off a lot of the text in the dropdowns due to the added Randomize button.
This commit is contained in:
Christopher Leggett 2022-12-19 05:12:36 -05:00 committed by GitHub
parent 4999df5395
commit 56ac27b8f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -297,19 +297,17 @@ void Draw_SfxTab(const std::string& tabId, const std::map<u16, std::tuple<std::s
ImGui::SameLine(); ImGui::SameLine();
ImGui::PushItemWidth(-FLT_MIN); ImGui::PushItemWidth(-FLT_MIN);
if (ImGui::Button(randomizeButton.c_str())) { if (ImGui::Button(randomizeButton.c_str())) {
bool valid = false; while (true) {
uint32_t value; auto it = map.begin();
while (!valid) { std::advance(it, rand() % map.size());
value = Random(2, map.size()); const auto& [value, seqData] = *it;
if (map.contains(value)) { const auto& [name, sfxKey, seqType] = seqData;
auto [name, sfxKey, seqType] = map.at(value);
if (seqType & type) { if (seqType & type) {
valid = true;
}
}
}
CVar_SetS32(cvarKey.c_str(), value); CVar_SetS32(cvarKey.c_str(), value);
SohImGui::RequestCvarSaveOnNextTick(); SohImGui::RequestCvarSaveOnNextTick();
break;
}
}
} }
} }
ImGui::EndTable(); ImGui::EndTable();
@ -355,7 +353,7 @@ void DrawSfxEditor(bool& open) {
CVar_SetS32("gSfxEditor", 0); CVar_SetS32("gSfxEditor", 0);
return; return;
} }
ImGui::SetNextWindowSize(ImVec2(465, 630), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(900, 630), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("SFX Editor", &open)) { if (!ImGui::Begin("SFX Editor", &open)) {
ImGui::End(); ImGui::End();
return; return;