Complete tracker window restoration on preset application.

This commit is contained in:
Malkierian 2025-04-30 18:43:04 -07:00
commit 520874bfef
4 changed files with 56 additions and 25 deletions

View file

@ -198,12 +198,6 @@ void SavePreset(std::string& presetName) {
file.close();
}
std::vector<std::string> blocks = {
CVAR_PREFIX_SETTING, CVAR_PREFIX_WINDOW, CVAR_PREFIX_ENHANCEMENT, CVAR_PREFIX_RANDOMIZER_ENHANCEMENT,
CVAR_PREFIX_AUDIO, CVAR_PREFIX_COSMETIC, CVAR_PREFIX_RANDOMIZER_SETTING, CVAR_PREFIX_TRACKER,
CVAR_PREFIX_CHEAT
};
static std::string newPresetName;
static bool saveSection[PRESET_SECTION_MAX];
@ -354,16 +348,20 @@ void PresetsCustomWidget(WidgetInfo& info) {
UIWidgets::PushStyleButton(THEME_COLOR);
if (UIWidgets::Button(("Apply##" + name).c_str(), UIWidgets::ButtonOptions().Padding({ 6.0f, 6.0f }))) {
for (int i = PRESET_SECTION_SETTINGS; i < PRESET_SECTION_MAX; i++) {
if (info.apply[i]) {
if (info.presetValues["blocks"].contains(blockInfo[i].names[1])) {
if (info.apply[i] && info.presetValues["blocks"].contains(blockInfo[i].names[1])) {
if (i == PRESET_SECTION_TRACKERS) {
ItemTracker_LoadFromPreset(
info.presetValues["blocks"][blockInfo[i].names[1]]["windows"]);
ItemTracker_LoadFromPreset(info.presetValues["blocks"][blockInfo[i].names[1]]["windows"]);
if (info.presetValues["blocks"][blockInfo[i].names[1]]["windows"].contains(
"Check Tracker")) {
CheckTracker::CheckTracker_LoadFromPreset(
info.presetValues["blocks"][blockInfo[i].names[1]]["windows"]["Entrance Tracker"]);
EntranceTracker_LoadFromPreset(
info.presetValues["blocks"][blockInfo[i].names[1]]["windows"]["Check Tracker"]);
}
if (info.presetValues["blocks"][blockInfo[i].names[1]]["windows"].contains(
"Entrance Tracker")) {
EntranceTracker_LoadFromPreset(
info.presetValues["blocks"][blockInfo[i].names[1]]["windows"]["Entrance Tracker"]);
}
}
auto section = info.presetValues["blocks"][blockInfo[i].names[1]];
for (auto& item : section.items()) {
if (section[item.key()].is_null()) {
@ -376,7 +374,6 @@ void PresetsCustomWidget(WidgetInfo& info) {
}
}
}
}
for (auto& section : info.presetValues["blocks"]) {}
}
UIWidgets::PopStyleButton();

View file

@ -39,6 +39,10 @@ static s16 lastEntranceIndex = -1;
static s16 currentGrottoId = -1;
static s16 lastSceneOrEntranceDetected = -1;
static bool presetLoaded = false;
static ImVec2 presetPos;
static ImVec2 presetSize;
static std::string spoilerEntranceGroupNames[] = {
"Spawns/Warp Songs/Owls",
"Kokiri Forest",
@ -446,6 +450,9 @@ const EntranceData* GetEntranceData(s16 index) {
}
void EntranceTracker_LoadFromPreset(nlohmann::json info) {
presetLoaded = true;
presetPos = { info["pos"]["x"], info["pos"]["y"] };
presetSize = { info["size"]["width"], info["size"]["height"] };
}
// Used for verifying the names on both sides of entrance pairs match. Keeping for ease of use for further name changes
@ -760,7 +767,13 @@ void EntranceTrackerWindow::Draw() {
}
void EntranceTrackerWindow::DrawElement() {
if (presetLoaded) {
ImGui::SetNextWindowSize(presetSize);
ImGui::SetNextWindowPos(presetPos);
presetLoaded = false;
} else {
ImGui::SetNextWindowSize(ImVec2(600, 375), ImGuiCond_FirstUseEver);
}
if (!ImGui::Begin("Entrance Tracker", &mIsVisible, ImGuiWindowFlags_NoFocusOnAppearing)) {
ImGui::End();

View file

@ -375,6 +375,10 @@ uint32_t notesIdleFrames = 0;
bool notesNeedSave = false;
const uint32_t notesMaxIdleFrames = 40; // two seconds of game time, since OnGameFrameUpdate is used to tick
static bool presetLoaded = false;
static std::unordered_map<std::string, ImVec2> presetPos;
static std::unordered_map<std::string, ImVec2> presetSize;
void ItemTrackerOnFrame() {
if (notesNeedSave && notesIdleFrames <= notesMaxIdleFrames) {
notesIdleFrames++;
@ -399,6 +403,13 @@ bool HasEquipment(ItemTrackerItem item) {
}
void ItemTracker_LoadFromPreset(nlohmann::json trackerInfo) {
presetLoaded = true;
for (auto window : itemTrackerWindowIDs) {
if (trackerInfo.contains(window)) {
presetPos[window] = { trackerInfo[window]["pos"]["x"], trackerInfo[window]["pos"]["y"] };
presetSize[window] = { trackerInfo[window]["size"]["width"], trackerInfo[window]["size"]["height"] };
}
}
}
ItemTrackerNumbers GetItemCurrentAndMax(ItemTrackerItem item) {
@ -1174,6 +1185,12 @@ void BeginFloatingWindows(std::string UniqueName, ImGuiWindowFlags flags = 0) {
ImGui::PushStyleColor(ImGuiCol_WindowBg, color);
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 4.0f);
if (presetLoaded && presetPos.contains(UniqueName)) {
ImGui::SetNextWindowSize(presetSize[UniqueName]);
ImGui::SetNextWindowPos(presetPos[UniqueName]);
presetSize.erase(UniqueName);
presetPos.erase(UniqueName);
}
ImGui::Begin(UniqueName.c_str(), nullptr, windowFlags);
}
void EndFloatingWindows() {
@ -1530,7 +1547,7 @@ void ItemTrackerWindow::DrawElement() {
SECTION_DISPLAY_EXTENDED_MAIN_WINDOW) ||
(CVarGetInteger(CVAR_TRACKER_ITEM("DisplayType.Notes"), SECTION_DISPLAY_HIDDEN) ==
SECTION_DISPLAY_MAIN_WINDOW)) {
BeginFloatingWindows("Item Tracker##main window");
BeginFloatingWindows("Item Tracker");
DrawItemsInRows(mainWindowItems, 6);
if (CVarGetInteger(CVAR_TRACKER_ITEM("DisplayType.Notes"), SECTION_DISPLAY_HIDDEN) ==
@ -1660,6 +1677,10 @@ void ItemTrackerWindow::DrawElement() {
EndFloatingWindows();
}
}
if (presetLoaded) {
shouldUpdateVectors = true;
presetLoaded = false;
}
}
static std::unordered_map<int32_t, const char*> itemTrackerCapacityTrackOptions = {

View file

@ -25,7 +25,7 @@ bool HasEquipment(ItemTrackerItem);
#define ITEM_TRACKER_ITEM_CUSTOM(id, name, nameFaded, data, drawFunc) \
{ id, #name, #nameFaded "_Faded", data, drawFunc }
static std::vector<const char*> itemTrackerWindowIDs = { "Item Tracker##main window",
static std::vector<const char*> itemTrackerWindowIDs = { "Item Tracker",
"Inventory Items Tracker",
"Equipment Items Tracker",
"Misc Items Tracker",