mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 14:23:44 -07:00
Complete tracker window restoration on preset application.
This commit is contained in:
parent
8dba1bcdd9
commit
520874bfef
4 changed files with 56 additions and 25 deletions
|
@ -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,25 +348,28 @@ 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 (i == PRESET_SECTION_TRACKERS) {
|
||||
ItemTracker_LoadFromPreset(
|
||||
info.presetValues["blocks"][blockInfo[i].names[1]]["windows"]);
|
||||
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"]);
|
||||
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"]);
|
||||
}
|
||||
auto section = info.presetValues["blocks"][blockInfo[i].names[1]];
|
||||
for (auto& item : section.items()) {
|
||||
if (section[item.key()].is_null()) {
|
||||
CVarClearBlock(item.key().c_str());
|
||||
} else {
|
||||
Ship::Context::GetInstance()->GetConfig()->SetBlock(
|
||||
fmt::format("{}.{}", "CVars", item.key()), item.value());
|
||||
Ship::Context::GetInstance()->GetConsoleVariables()->Load();
|
||||
}
|
||||
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()) {
|
||||
CVarClearBlock(item.key().c_str());
|
||||
} else {
|
||||
Ship::Context::GetInstance()->GetConfig()->SetBlock(
|
||||
fmt::format("{}.{}", "CVars", item.key()), item.value());
|
||||
Ship::Context::GetInstance()->GetConsoleVariables()->Load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
ImGui::SetNextWindowSize(ImVec2(600, 375), ImGuiCond_FirstUseEver);
|
||||
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();
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue