Persist item tracker notes

This commit is contained in:
Garrett Cox 2022-09-03 09:15:05 -05:00
parent adcb29fc86
commit ed8966054c
3 changed files with 13 additions and 1 deletions

View File

@ -31,4 +31,5 @@ namespace Ship {
DEFINE_HOOK(LoadTexture, void(const char* path, uint8_t** texture)); DEFINE_HOOK(LoadTexture, void(const char* path, uint8_t** texture));
DEFINE_HOOK(GfxInit, void()); DEFINE_HOOK(GfxInit, void());
DEFINE_HOOK(ExitGame, void()); DEFINE_HOOK(ExitGame, void());
DEFINE_HOOK(LoadFile, void(uint32_t fileNum));
} }

View File

@ -485,6 +485,8 @@ void DrawSong(ItemTrackerItem item) {
SetLastItemHoverText(SohUtils::GetQuestItemName(item.id)); SetLastItemHoverText(SohUtils::GetQuestItemName(item.id));
} }
static ImVector<char> itemTrackerNotes;
void DrawNotes(bool resizeable = false) { void DrawNotes(bool resizeable = false) {
ImGui::BeginGroup(); ImGui::BeginGroup();
int iconSize = CVar_GetS32("gItemTrackerIconSize", 36); int iconSize = CVar_GetS32("gItemTrackerIconSize", 36);
@ -510,12 +512,15 @@ void DrawNotes(bool resizeable = false) {
(void*)itemTrackerNotes); (void*)itemTrackerNotes);
} }
}; };
static ImVector<char> itemTrackerNotes;
if (itemTrackerNotes.empty()) { if (itemTrackerNotes.empty()) {
itemTrackerNotes.push_back(0); itemTrackerNotes.push_back(0);
} }
ImVec2 size = resizeable ? ImVec2(-FLT_MIN, ImGui::GetContentRegionAvail().y) : ImVec2(((iconSize + iconSpacing) * 6) - 8, 200); ImVec2 size = resizeable ? ImVec2(-FLT_MIN, ImGui::GetContentRegionAvail().y) : ImVec2(((iconSize + iconSpacing) * 6) - 8, 200);
ItemTrackerNotes::TrackerNotesInputTextMultiline("##ItemTrackerNotes", &itemTrackerNotes, size, ImGuiInputTextFlags_AllowTabInput); 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(); ImGui::EndGroup();
} }
@ -925,4 +930,8 @@ void InitItemTracker() {
Ship::RegisterHook<Ship::ControllerRead>([](OSContPad* cont_pad) { Ship::RegisterHook<Ship::ControllerRead>([](OSContPad* cont_pad) {
buttonsPressed = cont_pad; buttonsPressed = cont_pad;
}); });
Ship::RegisterHook<Ship::LoadFile>([](uint32_t fileNum) {
const char* initialTrackerNotes = CVar_GetString(("gItemTrackerNotes" + std::to_string(gSaveContext.fileNum)).c_str(), "");
strcpy(itemTrackerNotes.Data, initialTrackerNotes);
});
} }

View File

@ -5,6 +5,7 @@
#include "functions.h" #include "functions.h"
#include "macros.h" #include "macros.h"
#include "Cvar.h" #include "Cvar.h"
#include "Hooks.h"
#define NOGDI // avoid various windows defines that conflict with things in z64.h #define NOGDI // avoid various windows defines that conflict with things in z64.h
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
@ -1570,6 +1571,7 @@ extern "C" void Save_SaveGlobal(void) {
extern "C" void Save_LoadFile(void) { extern "C" void Save_LoadFile(void) {
SaveManager::Instance->LoadFile(gSaveContext.fileNum); SaveManager::Instance->LoadFile(gSaveContext.fileNum);
Ship::ExecuteHooks<Ship::LoadFile>(gSaveContext.fileNum);
} }
extern "C" void Save_AddLoadFunction(char* name, int version, SaveManager::LoadFunc func) { extern "C" void Save_AddLoadFunction(char* name, int version, SaveManager::LoadFunc func) {