refactor(IPL's): fix crashes and general improvements (#2304)

This commit is contained in:
YimMenuTheBest 2023-10-23 15:33:01 -06:00 committed by GitHub
parent da028f03b3
commit 0de9182735
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 118 additions and 37 deletions

File diff suppressed because one or more lines are too long

View File

@ -93,52 +93,72 @@ namespace big
ImGui::SeparatorText("GUI_TAB_IPL"_T.data()); ImGui::SeparatorText("GUI_TAB_IPL"_T.data());
if (ImGui::BeginCombo("IPL_LOCATION"_T.data(), ipls[g.self.ipls.select].friendly_name)) static int current_select = -1;
static int last_select = current_select;
ImGui::SetNextItemWidth(400);
if (ImGui::BeginCombo("##Ipllocation", ipls[current_select].friendly_name))
{ {
for (int i = 0; i < IM_ARRAYSIZE(ipls); i++) for (int i = 0; i < IM_ARRAYSIZE(ipls); i++)
{ {
if (ImGui::Selectable(ipls[i].friendly_name, i == g.self.ipls.select)) bool is_selected = (i == current_select);
g.self.ipls.select = i; if (ImGui::Selectable(ipls[i].friendly_name, is_selected))
{
if (i == g.self.ipls.select) current_select = i;
}
if (is_selected)
{
ImGui::SetItemDefaultFocus(); ImGui::SetItemDefaultFocus();
} }
}
ImGui::EndCombo(); ImGui::EndCombo();
} }
ImGui::SameLine();
const auto& selected_ipl = ipls[g.self.ipls.select]; components::button("LOAD_IPL"_T, []
if (components::button("LOAD_IPL"_T))
{ {
//unload all previous ipls // If we've changed selections, first unload previously loaded IPL, then load previously deleted IPLs
for (auto& ipl : ipls) if (current_select != last_select)
for (auto& ipl_name : ipl.ipl_names)
{ {
if (STREAMING::IS_IPL_ACTIVE(ipl_name)) // Unload previously loaded IPL of the last selection
for (auto& ipl_name_unload : ipls[last_select].ipl_names)
{ {
LOG(INFO) << "unloading existing ipl " << ipl_name; if (STREAMING::IS_IPL_ACTIVE(ipl_name_unload))
STREAMING::REMOVE_IPL(ipl_name); {
STREAMING::REMOVE_IPL(ipl_name_unload);
} }
} }
//load the new ipl // Load previously deleted IPLs of the last selection
for (auto& ipl_name : selected_ipl.ipl_names) for (auto& ipl_name_load : ipls[last_select].ipl_names_remove)
{
STREAMING::REQUEST_IPL(ipl_name_load);
}
// Load new IPLs of the current selection
for (auto& ipl_name : ipls[current_select].ipl_names)
{
STREAMING::REQUEST_IPL(ipl_name); STREAMING::REQUEST_IPL(ipl_name);
} }
ImGui::SameLine(); // Remove old IPLs of the current selection to avoid conflicts
for (auto& ipl_name_remove : ipls[current_select].ipl_names_remove_when_load)
if (components::button("TP_TO_IPL"_T))
{ {
teleport::to_coords(selected_ipl.location); STREAMING::REMOVE_IPL(ipl_name_remove);
} }
last_select = current_select;
}
});
ImGui::SameLine();
components::button("TP_TO_IPL"_T, []
{
teleport::to_coords(ipls[current_select].location);
});
ImGui::Spacing(); ImGui::Spacing();
components::small_text("IPL_INFOS"_T); components::small_text("IPL_INFOS"_T);
ImGui::Text(std::vformat("IPL_CNT"_T, std::make_format_args(selected_ipl.ipl_names.size())).data()); ImGui::Text(std::vformat("IPL_CNT"_T, std::make_format_args(ipls[current_select].ipl_names.size())).data());
ImGui::Text(std::vformat("IPL_POSITION"_T, ImGui::Text(std::vformat("IPL_POSITION"_T, std::make_format_args(ipls[current_select].location.x, ipls[current_select].location.y, ipls[current_select].location.z)).data());
std::make_format_args(selected_ipl.location.x, selected_ipl.location.y, selected_ipl.location.z))
.data());
} }
} }