From ed8966054c07ba5a9becfa14e67894fb715e7d7e Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Sat, 3 Sep 2022 09:15:05 -0500 Subject: [PATCH] Persist item tracker notes --- libultraship/libultraship/Hooks.h | 1 + .../randomizer/randomizer_item_tracker.cpp | 11 ++++++++++- soh/soh/SaveManager.cpp | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libultraship/libultraship/Hooks.h b/libultraship/libultraship/Hooks.h index 5f29a831c..f9cd8b4ba 100644 --- a/libultraship/libultraship/Hooks.h +++ b/libultraship/libultraship/Hooks.h @@ -31,4 +31,5 @@ namespace Ship { DEFINE_HOOK(LoadTexture, void(const char* path, uint8_t** texture)); DEFINE_HOOK(GfxInit, void()); DEFINE_HOOK(ExitGame, void()); + DEFINE_HOOK(LoadFile, void(uint32_t fileNum)); } diff --git a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp index 8cede9a66..f39e1d944 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp @@ -485,6 +485,8 @@ void DrawSong(ItemTrackerItem item) { SetLastItemHoverText(SohUtils::GetQuestItemName(item.id)); } +static ImVector itemTrackerNotes; + void DrawNotes(bool resizeable = false) { ImGui::BeginGroup(); int iconSize = CVar_GetS32("gItemTrackerIconSize", 36); @@ -510,12 +512,15 @@ void DrawNotes(bool resizeable = false) { (void*)itemTrackerNotes); } }; - static ImVector itemTrackerNotes; if (itemTrackerNotes.empty()) { itemTrackerNotes.push_back(0); } ImVec2 size = resizeable ? ImVec2(-FLT_MIN, ImGui::GetContentRegionAvail().y) : ImVec2(((iconSize + iconSpacing) * 6) - 8, 200); ItemTrackerNotes::TrackerNotesInputTextMultiline("##ItemTrackerNotes", &itemTrackerNotes, size, ImGuiInputTextFlags_AllowTabInput); + if (ImGui::IsItemDeactivatedAfterEdit() && IsValidSaveFile()) { + CVar_SetString(("gItemTrackerNotes" + std::to_string(gSaveContext.fileNum)).c_str(), std::string(std::begin(itemTrackerNotes), std::end(itemTrackerNotes)).c_str()); + SohImGui::needs_save = true; + } ImGui::EndGroup(); } @@ -925,4 +930,8 @@ void InitItemTracker() { Ship::RegisterHook([](OSContPad* cont_pad) { buttonsPressed = cont_pad; }); + Ship::RegisterHook([](uint32_t fileNum) { + const char* initialTrackerNotes = CVar_GetString(("gItemTrackerNotes" + std::to_string(gSaveContext.fileNum)).c_str(), ""); + strcpy(itemTrackerNotes.Data, initialTrackerNotes); + }); } diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index 8d8e7cd77..7050813b6 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -5,6 +5,7 @@ #include "functions.h" #include "macros.h" #include "Cvar.h" +#include "Hooks.h" #define NOGDI // avoid various windows defines that conflict with things in z64.h #include "spdlog/spdlog.h" @@ -1570,6 +1571,7 @@ extern "C" void Save_SaveGlobal(void) { extern "C" void Save_LoadFile(void) { SaveManager::Instance->LoadFile(gSaveContext.fileNum); + Ship::ExecuteHooks(gSaveContext.fileNum); } extern "C" void Save_AddLoadFunction(char* name, int version, SaveManager::LoadFunc func) {