Struct instead of ImVec + basic comportment for all case

This commit is contained in:
PurpleHato 2022-09-03 01:30:47 +02:00
parent 2ead2557f0
commit f69d9697e9

View File

@ -233,77 +233,102 @@ typedef enum {
ITEM_TRACKER_NUMBER_AMMO, ITEM_TRACKER_NUMBER_AMMO,
} ItemTrackerNumberOption; } ItemTrackerNumberOption;
struct ItemTrackerNumbers {
int currentCapacity;
int maxCapacity;
int currentAmmo;
};
bool IsValidSaveFile() { bool IsValidSaveFile() {
bool validSave = gSaveContext.fileNum >= 0 && gSaveContext.fileNum <= 2; bool validSave = gSaveContext.fileNum >= 0 && gSaveContext.fileNum <= 2;
return validSave; return validSave;
} }
ImVec2 GetItemCurrentAndMax(ItemTrackerItem item) { ItemTrackerNumbers GetItemCurrentAndMax(ItemTrackerItem item) {
ImVec2 result = { 0, 0 }; ItemTrackerNumbers result;
result.currentCapacity = 0;
result.maxCapacity = 0;
result.currentAmmo = 0;
switch (item.id) { switch (item.id) {
case ITEM_STICK: case ITEM_STICK:
result.x = CUR_CAPACITY(UPG_STICKS); result.currentCapacity = CUR_CAPACITY(UPG_STICKS);
result.y = 30; result.maxCapacity = 30;
result.currentAmmo = AMMO(ITEM_STICK);
break; break;
case ITEM_NUT: case ITEM_NUT:
result.x = CUR_CAPACITY(UPG_NUTS); result.currentCapacity = CUR_CAPACITY(UPG_NUTS);
result.y = 40; result.maxCapacity = 40;
result.currentAmmo = AMMO(ITEM_NUT);
break; break;
case ITEM_BOMB: case ITEM_BOMB:
result.x = CUR_CAPACITY(UPG_BOMB_BAG); result.currentCapacity = CUR_CAPACITY(UPG_BOMB_BAG);
result.y = 40; result.maxCapacity = 40;
result.currentAmmo = AMMO(ITEM_BOMB);
break; break;
case ITEM_BOW: case ITEM_BOW:
result.x = CUR_CAPACITY(UPG_QUIVER); result.currentCapacity = CUR_CAPACITY(UPG_QUIVER);
result.y = 50; result.maxCapacity = 50;
result.currentAmmo = AMMO(ITEM_BOW);
break; break;
case ITEM_SLINGSHOT: case ITEM_SLINGSHOT:
result.x = CUR_CAPACITY(UPG_BULLET_BAG); result.currentCapacity = CUR_CAPACITY(UPG_BULLET_BAG);
result.y = 50; result.maxCapacity = 50;
result.currentAmmo = AMMO(ITEM_SLINGSHOT);
break; break;
case ITEM_WALLET_ADULT: case ITEM_WALLET_ADULT:
result.currentCapacity = CUR_CAPACITY(UPG_WALLET);
result.maxCapacity = 200;
result.currentAmmo = gSaveContext.rupees;
break;
case ITEM_WALLET_GIANT: case ITEM_WALLET_GIANT:
result.x = CUR_CAPACITY(UPG_WALLET); result.currentCapacity = CUR_CAPACITY(UPG_WALLET);
result.y = 500; result.maxCapacity = 500;
result.currentAmmo = gSaveContext.rupees;
break;
case ITEM_BOMBCHU:
result.currentCapacity = 50;
result.maxCapacity = 50;
result.currentAmmo = AMMO(ITEM_BOMBCHU);
break; break;
case ITEM_BEAN: case ITEM_BEAN:
result.x = AMMO(ITEM_BEAN); result.currentCapacity = 10;
result.y = 10; result.maxCapacity = 10;
result.currentAmmo = AMMO(ITEM_BEAN);
break; break;
case QUEST_SKULL_TOKEN: case QUEST_SKULL_TOKEN:
result.x = gSaveContext.inventory.gsTokens; result.maxCapacity = 100;
result.y = 100; result.currentAmmo = gSaveContext.inventory.gsTokens;
break; break;
case ITEM_KEY_SMALL: case ITEM_KEY_SMALL:
result.x = gSaveContext.inventory.dungeonKeys[item.data]; result.currentCapacity = gSaveContext.inventory.dungeonKeys[item.data];
switch (item.data) { switch (item.data) {
case SCENE_BMORI1: case SCENE_BMORI1:
result.y = 5; result.maxCapacity = 5;
break; break;
case SCENE_HIDAN: case SCENE_HIDAN:
result.y = 8; result.maxCapacity = 8;
break; break;
case SCENE_MIZUSIN: case SCENE_MIZUSIN:
result.y = 6; result.maxCapacity = 6;
break; break;
case SCENE_JYASINZOU: case SCENE_JYASINZOU:
result.y = 5; result.maxCapacity = 5;
break; break;
case SCENE_HAKADAN: case SCENE_HAKADAN:
result.y = 5; result.maxCapacity = 5;
break; break;
case SCENE_HAKADANCH: case SCENE_HAKADANCH:
result.y = 3; result.maxCapacity = 3;
break; break;
case SCENE_GANONTIKA: case SCENE_GANONTIKA:
result.y = 2; result.maxCapacity = 2;
break; break;
case SCENE_MEN: case SCENE_MEN:
result.y = 9; result.maxCapacity = 9;
break; break;
case SCENE_GERUDOWAY: case SCENE_GERUDOWAY:
result.y = 4; result.maxCapacity = 4;
break; break;
} }
break; break;
@ -314,7 +339,7 @@ ImVec2 GetItemCurrentAndMax(ItemTrackerItem item) {
void DrawItemCount(ItemTrackerItem item) { void DrawItemCount(ItemTrackerItem item) {
int iconSize = CVar_GetS32("gItemTrackerIconSize", 36); int iconSize = CVar_GetS32("gItemTrackerIconSize", 36);
ImVec2 currentAndMax = GetItemCurrentAndMax(item); ItemTrackerNumbers currentAndMax = GetItemCurrentAndMax(item);
ImVec2 p = ImGui::GetCursorScreenPos(); ImVec2 p = ImGui::GetCursorScreenPos();
if (!IsValidSaveFile()) { if (!IsValidSaveFile()) {
@ -323,33 +348,62 @@ void DrawItemCount(ItemTrackerItem item) {
return; return;
} }
if (currentAndMax.x > 0) { if (currentAndMax.currentCapacity > 0) {
if (currentAndMax.x >= currentAndMax.y) { if (currentAndMax.currentCapacity >= currentAndMax.maxCapacity) {
std::string currentString = std::to_string((int)currentAndMax.x); std::string currentString = std::to_string((int)currentAndMax.currentCapacity);
float x = CVar_GetS32("gItemTrackerCurrentOnLeft", 0) ? p.x : p.x + (iconSize / 2) - (ImGui::CalcTextSize(currentString.c_str()).x / 2); float x = CVar_GetS32("gItemTrackerCurrentOnLeft", 0) ? p.x : p.x + (iconSize / 2) - (ImGui::CalcTextSize(currentString.c_str()).x / 2);
ImGui::SetCursorScreenPos(ImVec2(x, p.y - 14)); ImGui::SetCursorScreenPos(ImVec2(x, p.y - 14));
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255)); ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255));
ImGui::Text("%d", (int)currentAndMax.x); ImGui::Text("%d", (int)currentAndMax.currentCapacity);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} else { } else {
if (CVar_GetS32("gItemTrackerCapacityTrack", 0) == ITEM_TRACKER_NUMBER_CAPACITY) { switch (CVar_GetS32("gItemTrackerCapacityTrack", 0)) {
std::string currentAndMaxString = std::to_string((int)currentAndMax.x) + "/" + std::to_string((int)currentAndMax.y); case ITEM_TRACKER_NUMBER_NONE:
break;
case ITEM_TRACKER_NUMBER_CURRENT_CAPACITY_ONLY:
{
std::string currentString = std::to_string((int)currentAndMax.currentCapacity);
float x = CVar_GetS32("gItemTrackerCurrentOnLeft", 0) ? p.x : p.x + (iconSize / 2) - (ImGui::CalcTextSize(currentString.c_str()).x / 2);
ImGui::SetCursorScreenPos(ImVec2(p.x + (iconSize / 2) - (ImGui::CalcTextSize(currentAndMaxString.c_str()).x / 2), p.y - 14)); ImGui::SetCursorScreenPos(ImVec2(x, p.y - 14));
ImGui::Text("%d/", (int)currentAndMax.x); ImGui::Text("%d", (int)currentAndMax.currentCapacity);
ImGui::SameLine(0, 0.0f); }
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255)); break;
ImGui::Text("%d", (int)currentAndMax.y); case ITEM_TRACKER_NUMBER_CURRENT_AMMO_ONLY:
ImGui::PopStyleColor(); {
} else if (CVar_GetS32("gItemTrackerCapacityTrack", 0) == ITEM_TRACKER_NUMBER_NONE) { std::string currentString = std::to_string((int)currentAndMax.currentAmmo);
return; float x = CVar_GetS32("gItemTrackerCurrentOnLeft", 0) ? p.x : p.x + (iconSize / 2) - (ImGui::CalcTextSize(currentString.c_str()).x / 2);
} else {
std::string currentString = std::to_string((int)currentAndMax.x); ImGui::SetCursorScreenPos(ImVec2(x, p.y - 14));
float x = CVar_GetS32("gItemTrackerCurrentOnLeft", 0) ? p.x : p.x + (iconSize / 2) - (ImGui::CalcTextSize(currentString.c_str()).x / 2); ImGui::Text("%d", (int)currentAndMax.currentAmmo);
}
break;
case ITEM_TRACKER_NUMBER_CAPACITY:
{
std::string currentAndMaxString = std::to_string((int)currentAndMax.currentCapacity) + "/" + std::to_string((int)currentAndMax.maxCapacity);
ImGui::SetCursorScreenPos(ImVec2(p.x + (iconSize / 2) - (ImGui::CalcTextSize(currentAndMaxString.c_str()).x / 2), p.y - 14));
ImGui::Text("%d/", (int)currentAndMax.currentCapacity);
ImGui::SameLine(0, 0.0f);
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255));
ImGui::Text("%d", (int)currentAndMax.maxCapacity);
ImGui::PopStyleColor();
}
break;
case ITEM_TRACKER_NUMBER_AMMO:
{
std::string currentAndMaxString = std::to_string((int)currentAndMax.currentAmmo) + "/" + std::to_string((int)currentAndMax.maxCapacity);
ImGui::SetCursorScreenPos(ImVec2(p.x + (iconSize / 2) - (ImGui::CalcTextSize(currentAndMaxString.c_str()).x / 2), p.y - 14));
ImGui::Text("%d/", (int)currentAndMax.currentAmmo);
ImGui::SameLine(0, 0.0f);
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255));
ImGui::Text("%d", (int)currentAndMax.maxCapacity);
ImGui::PopStyleColor();
}
break;
ImGui::SetCursorScreenPos(ImVec2(x, p.y - 14));
ImGui::Text("%d", (int)currentAndMax.x);
} }
} }
} }