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