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());
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++)
{
if (ImGui::Selectable(ipls[i].friendly_name, i == g.self.ipls.select))
g.self.ipls.select = i;
if (i == g.self.ipls.select)
bool is_selected = (i == current_select);
if (ImGui::Selectable(ipls[i].friendly_name, is_selected))
{
current_select = i;
}
if (is_selected)
{
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
}
const auto& selected_ipl = ipls[g.self.ipls.select];
if (components::button("LOAD_IPL"_T))
ImGui::SameLine();
components::button("LOAD_IPL"_T, []
{
//unload all previous ipls
for (auto& ipl : ipls)
for (auto& ipl_name : ipl.ipl_names)
// If we've changed selections, first unload previously loaded IPL, then load previously deleted IPLs
if (current_select != last_select)
{
// Unload previously loaded IPL of the last selection
for (auto& ipl_name_unload : ipls[last_select].ipl_names)
{
if (STREAMING::IS_IPL_ACTIVE(ipl_name))
if (STREAMING::IS_IPL_ACTIVE(ipl_name_unload))
{
LOG(INFO) << "unloading existing ipl " << ipl_name;
STREAMING::REMOVE_IPL(ipl_name);
STREAMING::REMOVE_IPL(ipl_name_unload);
}
}
//load the new ipl
for (auto& ipl_name : selected_ipl.ipl_names)
STREAMING::REQUEST_IPL(ipl_name);
}
// Load previously deleted IPLs of the last selection
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);
}
// Remove old IPLs of the current selection to avoid conflicts
for (auto& ipl_name_remove : ipls[current_select].ipl_names_remove_when_load)
{
STREAMING::REMOVE_IPL(ipl_name_remove);
}
last_select = current_select;
}
});
ImGui::SameLine();
if (components::button("TP_TO_IPL"_T))
components::button("TP_TO_IPL"_T, []
{
teleport::to_coords(selected_ipl.location);
}
teleport::to_coords(ipls[current_select].location);
});
ImGui::Spacing();
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_POSITION"_T,
std::make_format_args(selected_ipl.location.x, selected_ipl.location.y, selected_ipl.location.z))
.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, std::make_format_args(ipls[current_select].location.x, ipls[current_select].location.y, ipls[current_select].location.z)).data());
}
}