mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-13 21:15:12 -05:00
Only update vectors when options change
This commit is contained in:
parent
267c27036c
commit
b0cdfc1be1
@ -30,6 +30,10 @@ void DrawSong(ItemTrackerItem item);
|
||||
|
||||
OSContPad* buttonsPressed;
|
||||
|
||||
bool shouldUpdateVectors = true;
|
||||
|
||||
std::vector<ItemTrackerItem> mainWindowItems = {};
|
||||
|
||||
std::vector<ItemTrackerItem> inventoryItems = {
|
||||
ITEM_TRACKER_ITEM(ITEM_STICK, 0, DrawItem), ITEM_TRACKER_ITEM(ITEM_NUT, 0, DrawItem), ITEM_TRACKER_ITEM(ITEM_BOMB, 0, DrawItem),
|
||||
ITEM_TRACKER_ITEM(ITEM_BOW, 0, DrawItem), ITEM_TRACKER_ITEM(ITEM_ARROW_FIRE, 0, DrawItem), ITEM_TRACKER_ITEM(ITEM_DINS_FIRE, 0, DrawItem),
|
||||
@ -63,6 +67,8 @@ std::vector<ItemTrackerItem> dungeonRewardMedallions = {
|
||||
ITEM_TRACKER_ITEM(QUEST_MEDALLION_SPIRIT, 1 << 3, DrawQuest), ITEM_TRACKER_ITEM(QUEST_MEDALLION_SHADOW, 1 << 4, DrawQuest), ITEM_TRACKER_ITEM(QUEST_MEDALLION_LIGHT, 1 << 5, DrawQuest),
|
||||
};
|
||||
|
||||
std::vector<ItemTrackerItem> dungeonRewards = {};
|
||||
|
||||
std::vector<ItemTrackerItem> songItems = {
|
||||
ITEM_TRACKER_ITEM(QUEST_SONG_LULLABY, 0, DrawSong), ITEM_TRACKER_ITEM(QUEST_SONG_EPONA, 0, DrawSong), ITEM_TRACKER_ITEM(QUEST_SONG_SARIA, 0, DrawSong),
|
||||
ITEM_TRACKER_ITEM(QUEST_SONG_SUN, 0, DrawSong), ITEM_TRACKER_ITEM(QUEST_SONG_TIME, 0, DrawSong), ITEM_TRACKER_ITEM(QUEST_SONG_STORMS, 0, DrawSong),
|
||||
@ -102,6 +108,8 @@ std::map<uint16_t, std::string> itemTrackerDungeonShortNames = {
|
||||
{ SCENE_GERUDOWAY, "HIDE" },
|
||||
};
|
||||
|
||||
std::vector<ItemTrackerItem> dungeonItems = {};
|
||||
|
||||
std::unordered_map<uint32_t, ItemTrackerItem> actualItemTrackerItemMap = {
|
||||
{ ITEM_BOTTLE, ITEM_TRACKER_ITEM(ITEM_BOTTLE, 0, DrawItem) },
|
||||
{ ITEM_BIG_POE, ITEM_TRACKER_ITEM(ITEM_BIG_POE, 0, DrawItem) },
|
||||
@ -592,6 +600,7 @@ void LabeledComboBoxRightAligned(const char* label, const char* cvar, std::vecto
|
||||
if (ImGui::Selectable(options[i].c_str())) {
|
||||
CVar_SetS32(cvar, i);
|
||||
SohImGui::needs_save = true;
|
||||
shouldUpdateVectors = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -608,6 +617,7 @@ void PaddedEnhancementCheckbox(const char* text, const char* cvarName, s32 defau
|
||||
if (ImGui::Checkbox(text, &val)) {
|
||||
CVar_SetS32(cvarName, val);
|
||||
SohImGui::needs_save = true;
|
||||
shouldUpdateVectors = true;
|
||||
}
|
||||
if (padBottom) {
|
||||
ImGui::Dummy(ImVec2(0.0f, 0.0f));
|
||||
@ -615,28 +625,27 @@ void PaddedEnhancementCheckbox(const char* text, const char* cvarName, s32 defau
|
||||
}
|
||||
/* ****************************************************** */
|
||||
|
||||
void DrawItemTracker(bool& open) {
|
||||
if (!open) {
|
||||
CVar_SetS32("gItemTrackerEnabled", 0);
|
||||
void UpdateVectors() {
|
||||
if (!shouldUpdateVectors) {
|
||||
return;
|
||||
}
|
||||
int iconSize = CVar_GetS32("gItemTrackerIconSize", 36);
|
||||
int iconSpacing = CVar_GetS32("gItemTrackerIconSpacing", 12);
|
||||
int comboButton1Mask = buttonMap[CVar_GetS32("gItemTrackerComboButton1", 6)];
|
||||
int comboButton2Mask = buttonMap[CVar_GetS32("gItemTrackerComboButton2", 8)];
|
||||
bool comboButtonsHeld = buttonsPressed != nullptr && buttonsPressed[0].button & comboButton1Mask && buttonsPressed[0].button & comboButton2Mask;
|
||||
bool isPaused = CVar_GetS32("gItemTrackerShowOnlyPaused", 0) == 0 || gGlobalCtx != nullptr && gGlobalCtx->pauseCtx.state > 0;
|
||||
|
||||
if (isPaused && (CVar_GetS32("gItemTrackerDisplayType", 0) == 0 ? CVar_GetS32("gItemTrackerEnabled", 0) : comboButtonsHeld)) {
|
||||
if (
|
||||
(CVar_GetS32("gItemTrackerInventoryItemsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerEquipmentItemsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerMiscItemsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerDungeonRewardsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerSongsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerDungeonItemsDisplayType", 1) == 1)
|
||||
) {
|
||||
std::vector<ItemTrackerItem> mainWindowItems = {};
|
||||
SohImGui::console->SendInfoMessage("updateVectors");
|
||||
|
||||
dungeonRewards.clear();
|
||||
dungeonRewards.insert(dungeonRewards.end(), dungeonRewardStones.begin(), dungeonRewardStones.end());
|
||||
dungeonRewards.insert(dungeonRewards.end(), dungeonRewardMedallions.begin(), dungeonRewardMedallions.end());
|
||||
|
||||
dungeonItems.clear();
|
||||
if (CVar_GetS32("gItemTrackerDisplayDungeonItemsHorizontal", 1) && CVar_GetS32("gItemTrackerDungeonItemsDisplayType", 2) == 2) {
|
||||
dungeonItems = GetDungeonItemsVector(itemTrackerDungeons, 12);
|
||||
dungeonItems[23] = ITEM_TRACKER_ITEM(ITEM_KEY_SMALL, SCENE_GERUDOWAY, DrawDungeonItem);
|
||||
} else {
|
||||
dungeonItems = GetDungeonItemsVector(itemTrackerDungeons);
|
||||
dungeonItems[35] = ITEM_TRACKER_ITEM(ITEM_KEY_SMALL, SCENE_GERUDOWAY, DrawDungeonItem);
|
||||
}
|
||||
|
||||
mainWindowItems.clear();
|
||||
if (CVar_GetS32("gItemTrackerInventoryItemsDisplayType", 1) == 1) {
|
||||
mainWindowItems.insert(mainWindowItems.end(), inventoryItems.begin(), inventoryItems.end());
|
||||
}
|
||||
@ -663,11 +672,35 @@ void DrawItemTracker(bool& open) {
|
||||
mainWindowItems.insert(mainWindowItems.end(), songItems.begin(), songItems.end());
|
||||
}
|
||||
if (CVar_GetS32("gItemTrackerDungeonItemsDisplayType", 2) == 1) {
|
||||
std::vector<ItemTrackerItem> dungeonItemsTemp = GetDungeonItemsVector(itemTrackerDungeons);
|
||||
dungeonItemsTemp[35] = ITEM_TRACKER_ITEM(ITEM_KEY_SMALL, SCENE_GERUDOWAY, DrawDungeonItem);
|
||||
mainWindowItems.insert(mainWindowItems.end(), dungeonItemsTemp.begin(), dungeonItemsTemp.end());
|
||||
mainWindowItems.insert(mainWindowItems.end(), dungeonItems.begin(), dungeonItems.end());
|
||||
}
|
||||
|
||||
shouldUpdateVectors = false;
|
||||
}
|
||||
|
||||
void DrawItemTracker(bool& open) {
|
||||
UpdateVectors();
|
||||
if (!open) {
|
||||
CVar_SetS32("gItemTrackerEnabled", 0);
|
||||
return;
|
||||
}
|
||||
int iconSize = CVar_GetS32("gItemTrackerIconSize", 36);
|
||||
int iconSpacing = CVar_GetS32("gItemTrackerIconSpacing", 12);
|
||||
int comboButton1Mask = buttonMap[CVar_GetS32("gItemTrackerComboButton1", 6)];
|
||||
int comboButton2Mask = buttonMap[CVar_GetS32("gItemTrackerComboButton2", 8)];
|
||||
bool comboButtonsHeld = buttonsPressed != nullptr && buttonsPressed[0].button & comboButton1Mask && buttonsPressed[0].button & comboButton2Mask;
|
||||
bool isPaused = CVar_GetS32("gItemTrackerShowOnlyPaused", 0) == 0 || gGlobalCtx != nullptr && gGlobalCtx->pauseCtx.state > 0;
|
||||
|
||||
if (isPaused && (CVar_GetS32("gItemTrackerDisplayType", 0) == 0 ? CVar_GetS32("gItemTrackerEnabled", 0) : comboButtonsHeld)) {
|
||||
if (
|
||||
(CVar_GetS32("gItemTrackerInventoryItemsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerEquipmentItemsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerMiscItemsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerDungeonRewardsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerSongsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerDungeonItemsDisplayType", 1) == 1) ||
|
||||
(CVar_GetS32("gItemTrackerNotesDisplayType", 2) == 1)
|
||||
) {
|
||||
BeginFloatingWindows("Item Tracker##main window");
|
||||
DrawItemsInRows(mainWindowItems, 6);
|
||||
|
||||
@ -705,10 +738,7 @@ void DrawItemTracker(bool& open) {
|
||||
DrawItemsInRows(dungeonRewardStones);
|
||||
ImGui::EndGroup();
|
||||
} else {
|
||||
std::vector<ItemTrackerItem> dungeonRewardItems = {};
|
||||
dungeonRewardItems.insert(dungeonRewardItems.end(), dungeonRewardMedallions.begin(), dungeonRewardMedallions.end());
|
||||
dungeonRewardItems.insert(dungeonRewardItems.end(), dungeonRewardStones.begin(), dungeonRewardStones.end());
|
||||
DrawItemsInRows(dungeonRewardItems, 3);
|
||||
DrawItemsInRows(dungeonRewards, 3);
|
||||
}
|
||||
EndFloatingWindows();
|
||||
}
|
||||
@ -722,13 +752,9 @@ void DrawItemTracker(bool& open) {
|
||||
if (CVar_GetS32("gItemTrackerDungeonItemsDisplayType", 2) == 2) {
|
||||
BeginFloatingWindows("Dungeon Items Tracker");
|
||||
if (CVar_GetS32("gItemTrackerDisplayDungeonItemsHorizontal", 1)) {
|
||||
std::vector<ItemTrackerItem> dungeonItemsTemp = GetDungeonItemsVector(itemTrackerDungeons, 12);
|
||||
dungeonItemsTemp[23] = ITEM_TRACKER_ITEM(ITEM_KEY_SMALL, SCENE_GERUDOWAY, DrawDungeonItem);
|
||||
DrawItemsInRows(dungeonItemsTemp, 12);
|
||||
DrawItemsInRows(dungeonItems, 12);
|
||||
} else {
|
||||
std::vector<ItemTrackerItem> dungeonItemsTemp = GetDungeonItemsVector(itemTrackerDungeons);
|
||||
dungeonItemsTemp[35] = ITEM_TRACKER_ITEM(ITEM_KEY_SMALL, SCENE_GERUDOWAY, DrawDungeonItem);
|
||||
DrawItemsInRows(dungeonItemsTemp);
|
||||
DrawItemsInRows(dungeonItems);
|
||||
}
|
||||
EndFloatingWindows();
|
||||
}
|
||||
@ -748,7 +774,7 @@ void DrawItemTrackerOptions(bool& open) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(600,360), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(ImVec2(600,375), ImGuiCond_FirstUseEver);
|
||||
|
||||
if (!ImGui::Begin("Item Tracker Settings", &open, ImGuiWindowFlags_NoFocusOnAppearing)) {
|
||||
ImGui::End();
|
||||
@ -825,7 +851,7 @@ void DrawItemTrackerOptions(bool& open) {
|
||||
}
|
||||
|
||||
void InitItemTracker() {
|
||||
// TODO: We want to persist this open, but currently I'm not sure of a way to dependably wait till the textures are loaded before we draw the tracker
|
||||
// TODO: We want to persist this open, but currently the tracker is crashing if it's opened to quickly on launch
|
||||
SohImGui::AddWindow("Randomizer", "Item Tracker", DrawItemTracker);
|
||||
SohImGui::AddWindow("Randomizer", "Item Tracker Settings", DrawItemTrackerOptions);
|
||||
float trackerBgR = CVar_GetFloat("gItemTrackerBgColorR", 0);
|
||||
|
Loading…
Reference in New Issue
Block a user