Skip to content

Commit

Permalink
Merge pull request #42 from garrettjoecox/split_v2
Browse files Browse the repository at this point in the history
Working popup
  • Loading branch information
Caladius authored Oct 18, 2024
2 parents 330ebd5 + 1564540 commit 48c8bef
Showing 1 changed file with 38 additions and 49 deletions.
87 changes: 38 additions & 49 deletions soh/soh/Enhancements/timesplits/TimeSplits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,52 +340,33 @@ void TimeSplitsFileManagement(uint32_t action, const char* listEntry, std::vecto
}
}

void TimeSplitsPopUpContext(uint32_t itemClicked) {
uint32_t rowIndex = 0;
ImGui::OpenPopup(std::to_string(itemClicked).c_str());
auto it = popupList.find(itemClicked);
if (it != popupList.end()) {
if (ImGui::BeginPopup(std::to_string(itemClicked).c_str())) {
for (auto& popupID : it->second) {
auto findID = std::find_if(splitObjectList.begin(), splitObjectList.end(),
[popupID](const SplitObject& obj) {
return obj.splitID == popupID;
});

if (findID != splitObjectList.end()) {
SplitObject& popupObject = *findID;
if (ImGui::ImageButton(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(popupObject.splitImage),
ImVec2(26.0f, 26.0f), ImVec2(0, 0), ImVec2(1, 1), 2.0f, ImVec4(0, 0, 0, 0), popupObject.splitTint)) {
splitList.push_back(popupObject);
if (splitList.size() == 1) {
splitList[0].splitTimeStatus = SPLIT_ACTIVE;
} else {
splitList[splitList.size() - 1].splitTimeStatus = SPLIT_INACTIVE;
}
ImGui::CloseCurrentPopup();
displayPopup = false;
}
if (rowIndex != 5) {
ImGui::SameLine();
}
rowIndex++;
void TimeSplitsPopUpContext() {
int rowIndex = 0;
if (ImGui::BeginPopup("TimeSplitsPopUp") && popupID) {
for (auto item : popupList[popupID]) {
auto findID = std::find_if(splitObjectList.begin(), splitObjectList.end(), [&](const SplitObject& obj) { return obj.splitID == item; });
if (findID == splitObjectList.end()) {
continue;
}

SplitObject& popupObject = *findID;
if (ImGui::ImageButton(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(popupObject.splitImage),
ImVec2(26.0f, 26.0f), ImVec2(0, 0), ImVec2(1, 1), 2.0f, ImVec4(0, 0, 0, 0), popupObject.splitTint)) {
splitList.push_back(popupObject);
if (splitList.size() == 1) {
splitList[0].splitTimeStatus = SPLIT_ACTIVE;
} else {
splitList[splitList.size() - 1].splitTimeStatus = SPLIT_INACTIVE;
}
ImGui::CloseCurrentPopup();
displayPopup = false;
}
ImGui::EndPopup();
}
} else {
auto findID = std::find_if(splitObjectList.begin(), splitObjectList.end(),
[itemClicked](const SplitObject& obj) {
return obj.splitID == popupID;
});
SplitObject& popupObject = *findID;
splitList.push_back(popupObject);
if (splitList.size() == 1) {
splitList[0].splitTimeStatus = SPLIT_ACTIVE;
} else {
splitList[splitList.size() - 1].splitTimeStatus = SPLIT_INACTIVE;
if (rowIndex != 5) {
ImGui::SameLine();
}
rowIndex++;
}
displayPopup = false;
ImGui::EndPopup();
}
}

Expand Down Expand Up @@ -577,9 +558,21 @@ void TimeSplitsDrawItemList(uint32_t type) {
ImGui::PushID(split.splitID);
if (ImGui::ImageButton(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(split.splitImage),
ImVec2(26.0f, 26.0f), ImVec2(0, 0), ImVec2(1, 1), 2.0f, ImVec4(0, 0, 0, 0), split.splitTint)) {
popupID = split.splitID;
displayPopup = true;

if (popupList.contains(split.splitID)) {
popupID = split.splitID;
ImGui::OpenPopup("TimeSplitsPopUp");
} else {
splitList.push_back(split);
if (splitList.size() == 1) {
splitList[0].splitTimeStatus = SPLIT_ACTIVE;
} else {
splitList[splitList.size() - 1].splitTimeStatus = SPLIT_INACTIVE;
}
}
}

TimeSplitsPopUpContext();
ImGui::PopID();
ImGui::TableNextColumn();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 7.0f));
Expand Down Expand Up @@ -693,10 +686,6 @@ void TimeSplitWindow::DrawElement() {
initialized = true;
}

if (displayPopup) {
TimeSplitsPopUpContext(popupID);
}

ImGui::PushStyleColor(ImGuiCol_WindowBg, windowColor);
if (!ImGui::Begin("Time Splitter Window", &mIsVisible, ImGuiWindowFlags_NoFocusOnAppearing)) {
ImGui::End();
Expand Down

0 comments on commit 48c8bef

Please sign in to comment.