Merge pull request #1396 from garrettjoecox/item-tracker-notes

Persist item tracker notes
This commit is contained in:
briaguya 2022-09-03 18:40:32 -04:00 committed by GitHub
commit e55ec29d66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -31,4 +31,6 @@ 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));
DEFINE_HOOK(DeleteFile, void(uint32_t fileNum));
}

View File

@ -484,6 +484,8 @@ void DrawSong(ItemTrackerItem item) {
UIWidgets::SetLastItemHoverText(SohUtils::GetQuestItemName(item.id));
}
static ImVector<char> itemTrackerNotes;
void DrawNotes(bool resizeable = false) {
ImGui::BeginGroup();
int iconSize = CVar_GetS32("gItemTrackerIconSize", 36);
@ -509,12 +511,15 @@ void DrawNotes(bool resizeable = false) {
(void*)itemTrackerNotes);
}
};
static ImVector<char> 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::RequestCvarSaveOnNextTick();
}
ImGui::EndGroup();
}
@ -924,4 +929,12 @@ void InitItemTracker() {
Ship::RegisterHook<Ship::ControllerRead>([](OSContPad* cont_pad) {
buttonsPressed = cont_pad;
});
Ship::RegisterHook<Ship::LoadFile>([](uint32_t fileNum) {
const char* initialTrackerNotes = CVar_GetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), "");
strcpy(itemTrackerNotes.Data, initialTrackerNotes);
});
Ship::RegisterHook<Ship::DeleteFile>([](uint32_t fileNum) {
CVar_SetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), "");
SohImGui::RequestCvarSaveOnNextTick();
});
}

View File

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