mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-19 13:00:11 -07:00
[Tweak] Move Personal Notes to Save File (#3909)
* Moves personal notes to the save file under a new itemTracker save section. * Update soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp --------- Co-authored-by: Archez <Archez@users.noreply.github.com>
This commit is contained in:
parent
cf6101f4da
commit
30a063b75d
1 changed files with 27 additions and 15 deletions
|
@ -30,6 +30,8 @@ void DrawBottle(ItemTrackerItem item);
|
||||||
void DrawQuest(ItemTrackerItem item);
|
void DrawQuest(ItemTrackerItem item);
|
||||||
void DrawSong(ItemTrackerItem item);
|
void DrawSong(ItemTrackerItem item);
|
||||||
|
|
||||||
|
int itemTrackerSectionId;
|
||||||
|
|
||||||
bool shouldUpdateVectors = true;
|
bool shouldUpdateVectors = true;
|
||||||
|
|
||||||
std::vector<ItemTrackerItem> mainWindowItems = {};
|
std::vector<ItemTrackerItem> mainWindowItems = {};
|
||||||
|
@ -282,11 +284,6 @@ void ItemTrackerOnFrame() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveNotes(uint32_t fileNum) {
|
|
||||||
CVarSetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), std::string(std::begin(itemTrackerNotes), std::end(itemTrackerNotes)).c_str());
|
|
||||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsValidSaveFile() {
|
bool IsValidSaveFile() {
|
||||||
bool validSave = gSaveContext.fileNum >= 0 && gSaveContext.fileNum <= 2;
|
bool validSave = gSaveContext.fileNum >= 0 && gSaveContext.fileNum <= 2;
|
||||||
return validSave;
|
return validSave;
|
||||||
|
@ -734,7 +731,7 @@ void DrawNotes(bool resizeable = false) {
|
||||||
}
|
}
|
||||||
if ((ImGui::IsItemDeactivatedAfterEdit() || (notesNeedSave && notesIdleFrames > notesMaxIdleFrames)) && IsValidSaveFile()) {
|
if ((ImGui::IsItemDeactivatedAfterEdit() || (notesNeedSave && notesIdleFrames > notesMaxIdleFrames)) && IsValidSaveFile()) {
|
||||||
notesNeedSave = false;
|
notesNeedSave = false;
|
||||||
SaveNotes(gSaveContext.fileNum);
|
SaveManager::Instance->SaveSection(gSaveContext.fileNum, itemTrackerSectionId, true);
|
||||||
}
|
}
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
}
|
}
|
||||||
|
@ -959,6 +956,26 @@ void UpdateVectors() {
|
||||||
shouldUpdateVectors = false;
|
shouldUpdateVectors = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemTrackerInitFile(bool isDebug) {
|
||||||
|
itemTrackerNotes.clear();
|
||||||
|
itemTrackerNotes.push_back(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemTrackerSaveFile(SaveContext* saveContext, int sectionID, bool fullSave) {
|
||||||
|
SaveManager::Instance->SaveData("personalNotes", std::string(std::begin(itemTrackerNotes), std::end(itemTrackerNotes)).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemTrackerLoadFile() {
|
||||||
|
std::string initialTrackerNotes = "";
|
||||||
|
SaveManager::Instance->LoadData("personalNotes", initialTrackerNotes);
|
||||||
|
itemTrackerNotes.resize(initialTrackerNotes.length() + 1);
|
||||||
|
if (initialTrackerNotes != "") {
|
||||||
|
SohUtils::CopyStringToCharArray(itemTrackerNotes.Data, initialTrackerNotes.c_str(), itemTrackerNotes.size());
|
||||||
|
} else {
|
||||||
|
itemTrackerNotes.push_back(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ItemTrackerWindow::DrawElement() {
|
void ItemTrackerWindow::DrawElement() {
|
||||||
UpdateVectors();
|
UpdateVectors();
|
||||||
|
|
||||||
|
@ -1223,14 +1240,9 @@ void ItemTrackerWindow::InitElement() {
|
||||||
itemTrackerNotes.push_back(0);
|
itemTrackerNotes.push_back(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnLoadFile>([](uint32_t fileNum) {
|
SaveManager::Instance->AddInitFunction(ItemTrackerInitFile);
|
||||||
const char* initialTrackerNotes = CVarGetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), "");
|
itemTrackerSectionId = SaveManager::Instance->AddSaveFunction("itemTrackerData", 1, ItemTrackerSaveFile, true, -1);
|
||||||
itemTrackerNotes.resize(strlen(initialTrackerNotes) + 1);
|
SaveManager::Instance->AddLoadFunction("itemTrackerData", 1, ItemTrackerLoadFile);
|
||||||
strcpy(itemTrackerNotes.Data, initialTrackerNotes);
|
|
||||||
});
|
|
||||||
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnDeleteFile>([](uint32_t fileNum) {
|
|
||||||
CVarSetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), "");
|
|
||||||
LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
|
||||||
});
|
|
||||||
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>(ItemTrackerOnFrame);
|
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>(ItemTrackerOnFrame);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue