From a3283dcbf157818f2d8705aa04d5b09da9ed7a6f Mon Sep 17 00:00:00 2001 From: SnazzyPanda <35570455+SnazzyPanda@users.noreply.github.com> Date: Sat, 25 Nov 2023 20:56:07 -0600 Subject: [PATCH 1/9] Start working on confirm dialogue for delete --- Lamp/Control/lampControl.h | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Lamp/Control/lampControl.h b/Lamp/Control/lampControl.h index f5a7122..63d8a0b 100644 --- a/Lamp/Control/lampControl.h +++ b/Lamp/Control/lampControl.h @@ -349,6 +349,10 @@ namespace Lamp::Core{ ImGui::BeginDisabled((*it)->enabled); if (ImGui::Button(("Remove Mod##" + std::to_string(i)).c_str())) { + +ImGui::OpenPopup("Delete?"); + +/* int deleteResult = std::remove(absolute(path).c_str()); if(deleteResult != 0){ std::cout << "Error deleting file: " << absolute(path).c_str() << "\n Error msg: " << strerror(errno) << "\n"; @@ -357,10 +361,54 @@ namespace Lamp::Core{ std::cout << absolute(path).c_str() << std::endl; ModList.erase(it); Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); +*/ + + ImGui::EndDisabled(); // fixes a crash when deleting items (when at least 1 mod has been enabled) break; } +// Always center this window when appearing +ImVec2 center = ImGui::GetMainViewport()->GetCenter(); +ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); +if(ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ + ImGui::Text("Confirm deleting [mod name here]?"); + ImGui::Separator(); + + //static int unused_i = 0; + //ImGui::Combo("Combo", &unused_i, "Delete\0Delete harder\0"); + + //static bool dont_ask_me_next_time = false; + //ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + //ImGui::Checkbox("Don't ask me next time", &dont_ask_me_next_time); + //ImGui::PopStyleVar(); + + if (ImGui::Button("Delete", ImVec2(120, 0))) { + std::cout << "Would delete..."; + + + int deleteResult = std::remove(absolute(path).c_str()); + if(deleteResult != 0){ + std::cout << "Error deleting file: " << absolute(path).c_str() << "\n Error msg: " << strerror(errno) << "\n"; + } + + std::cout << absolute(path).c_str() << std::endl; + ModList.erase(it); + Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); + + ImGui::CloseCurrentPopup(); + } + ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); + if (ImGui::Button("Cancel", ImVec2(120, 0))) { + // Do nothing + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); +} + + + if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && (*it)->enabled) { ImGui::SetTooltip("Only disabled mods can be removed."); } From 0f89339808e3c7ec51471dd0793713b184341a91 Mon Sep 17 00:00:00 2001 From: SnazzyPanda <35570455+SnazzyPanda@users.noreply.github.com> Date: Thu, 30 Nov 2023 19:44:43 -0600 Subject: [PATCH 2/9] Got the delete confirmation dialogue mostly working There seems to be a crash when deleting the last mod in the list --- Lamp/Control/lampControl.h | 75 ++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/Lamp/Control/lampControl.h b/Lamp/Control/lampControl.h index 63d8a0b..deb7d0c 100644 --- a/Lamp/Control/lampControl.h +++ b/Lamp/Control/lampControl.h @@ -45,9 +45,11 @@ namespace Lamp::Core{ */ static lampString getFormattedTimeAndDate(); - lampHex Colour_SearchHighlight = ImVec4(0.3f, 0.f, 0.3f, 1); lampHex Colour_ButtonAlt = ImVec4(0.1f, 0.6f, 0.3f, 1); + + // an index outside of the loop/object recreation that we can reference for the delete modal (otherwise modal options display for every mod in the ModList) + int deletePos = -1; /** * @brief The `lampArchiveDisplayHelper` struct provides helper methods for displaying archives. */ @@ -174,7 +176,7 @@ namespace Lamp::Core{ if (ImGui::InputTextWithHint("##searcher","Type here to search your mods...", lampConfig::getInstance().searchBuffer, 250)) { lampConfig::getInstance().listHighlight = findClosestMatchPosition(); } - + ImGuiTableFlags mod_table_flags = 0; mod_table_flags |= ImGuiTableFlags_SizingStretchProp; mod_table_flags |= ImGuiTableFlags_Hideable; // allow hiding coumns via context menu @@ -349,8 +351,10 @@ namespace Lamp::Core{ ImGui::BeginDisabled((*it)->enabled); if (ImGui::Button(("Remove Mod##" + std::to_string(i)).c_str())) { + lampControl::getInstance().deletePos = i; + ImGui::OpenPopup("DELETE_MOD_MODAL"); + -ImGui::OpenPopup("Delete?"); /* int deleteResult = std::remove(absolute(path).c_str()); @@ -371,39 +375,54 @@ ImGui::OpenPopup("Delete?"); // Always center this window when appearing ImVec2 center = ImGui::GetMainViewport()->GetCenter(); ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); -if(ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ - ImGui::Text("Confirm deleting [mod name here]?"); - ImGui::Separator(); +if(ImGui::BeginPopupModal("DELETE_MOD_MODAL", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ + // prevent displaying buttons for each mod in the mod list, as this runs every iteration of for loop + if(lampControl::getInstance().deletePos == i){ + auto pendingDelete = ModList.begin() + lampControl::getInstance().deletePos; + std::filesystem::path tmppath = (*pendingDelete)->ArchivePath; + std::string delname = tmppath.filename().c_str(); - //static int unused_i = 0; - //ImGui::Combo("Combo", &unused_i, "Delete\0Delete harder\0"); + std::string promptMessage = "Confirm deleting "; + promptMessage.append(delname); + promptMessage.append("?"); + ImGui::Text(promptMessage.c_str()); + ImGui::Separator(); - //static bool dont_ask_me_next_time = false; - //ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - //ImGui::Checkbox("Don't ask me next time", &dont_ask_me_next_time); - //ImGui::PopStyleVar(); - if (ImGui::Button("Delete", ImVec2(120, 0))) { - std::cout << "Would delete..."; + //static int unused_i = 0; + //ImGui::Combo("Combo", &unused_i, "Delete\0Delete harder\0"); - int deleteResult = std::remove(absolute(path).c_str()); - if(deleteResult != 0){ - std::cout << "Error deleting file: " << absolute(path).c_str() << "\n Error msg: " << strerror(errno) << "\n"; - } + //static bool dont_ask_me_next_time = false; + //ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + //ImGui::Checkbox("Don't ask me next time", &dont_ask_me_next_time); + //ImGui::PopStyleVar(); - std::cout << absolute(path).c_str() << std::endl; - ModList.erase(it); - Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); + if (ImGui::Button("Delete", ImVec2(120, 0))) { + std::cout << "Would delete..."; - ImGui::CloseCurrentPopup(); - } - ImGui::SetItemDefaultFocus(); - ImGui::SameLine(); - if (ImGui::Button("Cancel", ImVec2(120, 0))) { - // Do nothing - ImGui::CloseCurrentPopup(); + + int deleteResult = std::remove(absolute(tmppath).c_str()); + if(deleteResult != 0){ + std::cout << "Error deleting file: " << absolute(tmppath).c_str() << "\n Error msg: " << strerror(errno) << "\n"; + } + + std::cout << absolute(tmppath).c_str() << std::endl; + ModList.erase(pendingDelete); + Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); + + lampControl::getInstance().deletePos = -1; + ImGui::CloseCurrentPopup(); + } + ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); + if (ImGui::Button("Cancel", ImVec2(120, 0))) { + // Do nothing + lampControl::getInstance().deletePos = -1; + ImGui::CloseCurrentPopup(); + } } + ImGui::EndPopup(); } From 9407e799086417e3dd154cffe672dec4aa8e4e13 Mon Sep 17 00:00:00 2001 From: SnazzyPanda <35570455+SnazzyPanda@users.noreply.github.com> Date: Thu, 30 Nov 2023 19:49:31 -0600 Subject: [PATCH 3/9] Possible fix for crash when deleting last mod --- Lamp/Control/lampControl.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lamp/Control/lampControl.h b/Lamp/Control/lampControl.h index deb7d0c..fccf824 100644 --- a/Lamp/Control/lampControl.h +++ b/Lamp/Control/lampControl.h @@ -413,6 +413,9 @@ if(ImGui::BeginPopupModal("DELETE_MOD_MODAL", NULL, ImGuiWindowFlags_AlwaysAutoR lampControl::getInstance().deletePos = -1; ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + ImGui::EndDisabled(); + break; } ImGui::SetItemDefaultFocus(); ImGui::SameLine(); From 8c287cde1614bded8878cdfdad1397a4ff85617b Mon Sep 17 00:00:00 2001 From: SnazzyPanda <35570455+SnazzyPanda@users.noreply.github.com> Date: Thu, 30 Nov 2023 19:54:44 -0600 Subject: [PATCH 4/9] Cleanup test/reference code and fix indentations --- Lamp/Control/lampControl.h | 135 +++++++++++++++---------------------- 1 file changed, 55 insertions(+), 80 deletions(-) diff --git a/Lamp/Control/lampControl.h b/Lamp/Control/lampControl.h index fccf824..821f188 100644 --- a/Lamp/Control/lampControl.h +++ b/Lamp/Control/lampControl.h @@ -348,97 +348,72 @@ namespace Lamp::Core{ } - ImGui::BeginDisabled((*it)->enabled); - - if (ImGui::Button(("Remove Mod##" + std::to_string(i)).c_str())) { - lampControl::getInstance().deletePos = i; - ImGui::OpenPopup("DELETE_MOD_MODAL"); + ImGui::BeginDisabled((*it)->enabled); + if (ImGui::Button(("Remove Mod##" + std::to_string(i)).c_str())) { + lampControl::getInstance().deletePos = i; + ImGui::OpenPopup("DELETE_MOD_MODAL"); + ImGui::EndDisabled(); // fixes a crash when deleting items (when at least 1 mod has been enabled) + break; + } -/* - int deleteResult = std::remove(absolute(path).c_str()); - if(deleteResult != 0){ - std::cout << "Error deleting file: " << absolute(path).c_str() << "\n Error msg: " << strerror(errno) << "\n"; - } + // Setup centering for the modal window + ImVec2 center = ImGui::GetMainViewport()->GetCenter(); + ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + + if(ImGui::BeginPopupModal("DELETE_MOD_MODAL", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ + // prevent displaying buttons for each mod in the mod list, as this runs every iteration of for loop + if(lampControl::getInstance().deletePos == i){ + auto pendingDelete = ModList.begin() + lampControl::getInstance().deletePos; + std::filesystem::path tmppath = (*pendingDelete)->ArchivePath; + std::string delname = tmppath.filename().c_str(); + + std::string promptMessage = "Confirm deleting "; + promptMessage.append(delname); + promptMessage.append("?"); + ImGui::Text(promptMessage.c_str()); + ImGui::Separator(); + + if (ImGui::Button("Delete", ImVec2(120, 0))) { + int deleteResult = std::remove(absolute(tmppath).c_str()); + if(deleteResult != 0){ + std::cout << "Error deleting file: " << absolute(tmppath).c_str() << "\n Error msg: " << strerror(errno) << "\n"; + } - std::cout << absolute(path).c_str() << std::endl; - ModList.erase(it); - Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); -*/ + std::cout << absolute(tmppath).c_str() << std::endl; + ModList.erase(pendingDelete); + Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); + lampControl::getInstance().deletePos = -1; + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + // re-end disabled. May be needed to avoid some crashes. + ImGui::EndDisabled(); - ImGui::EndDisabled(); // fixes a crash when deleting items (when at least 1 mod has been enabled) - break; + break; + } + ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); + if (ImGui::Button("Cancel", ImVec2(120, 0))) { + // Do nothing + lampControl::getInstance().deletePos = -1; + ImGui::CloseCurrentPopup(); + } } -// Always center this window when appearing -ImVec2 center = ImGui::GetMainViewport()->GetCenter(); -ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); -if(ImGui::BeginPopupModal("DELETE_MOD_MODAL", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ - // prevent displaying buttons for each mod in the mod list, as this runs every iteration of for loop - if(lampControl::getInstance().deletePos == i){ - auto pendingDelete = ModList.begin() + lampControl::getInstance().deletePos; - std::filesystem::path tmppath = (*pendingDelete)->ArchivePath; - std::string delname = tmppath.filename().c_str(); - - std::string promptMessage = "Confirm deleting "; - promptMessage.append(delname); - promptMessage.append("?"); - ImGui::Text(promptMessage.c_str()); - ImGui::Separator(); - - - - //static int unused_i = 0; - //ImGui::Combo("Combo", &unused_i, "Delete\0Delete harder\0"); - - //static bool dont_ask_me_next_time = false; - //ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - //ImGui::Checkbox("Don't ask me next time", &dont_ask_me_next_time); - //ImGui::PopStyleVar(); - - if (ImGui::Button("Delete", ImVec2(120, 0))) { - std::cout << "Would delete..."; - - - int deleteResult = std::remove(absolute(tmppath).c_str()); - if(deleteResult != 0){ - std::cout << "Error deleting file: " << absolute(tmppath).c_str() << "\n Error msg: " << strerror(errno) << "\n"; - } - - std::cout << absolute(tmppath).c_str() << std::endl; - ModList.erase(pendingDelete); - Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); - - lampControl::getInstance().deletePos = -1; - ImGui::CloseCurrentPopup(); - ImGui::EndPopup(); - ImGui::EndDisabled(); - break; - } - ImGui::SetItemDefaultFocus(); - ImGui::SameLine(); - if (ImGui::Button("Cancel", ImVec2(120, 0))) { - // Do nothing - lampControl::getInstance().deletePos = -1; - ImGui::CloseCurrentPopup(); - } - } - - ImGui::EndPopup(); -} + ImGui::EndPopup(); + } // end delete confirmation modal + if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && (*it)->enabled) { + ImGui::SetTooltip("Only disabled mods can be removed."); + } + if (ImGui::IsItemHovered(ImGuiHoveredFlags_None)) { + ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, lampControl::getInstance().Colour_SearchHighlight); + } - if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && (*it)->enabled) { - ImGui::SetTooltip("Only disabled mods can be removed."); - } - if (ImGui::IsItemHovered(ImGuiHoveredFlags_None)) { - ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, lampControl::getInstance().Colour_SearchHighlight); - } - - ImGui::EndDisabled(); + ImGui::EndDisabled(); for (auto ittt = ExtraOptions.begin(); ittt != ExtraOptions.end(); ++ittt) { From aef6b9c2020f89774d091cdec2385cc6ad564d7b Mon Sep 17 00:00:00 2001 From: SnazzyPanda <35570455+SnazzyPanda@users.noreply.github.com> Date: Thu, 30 Nov 2023 20:03:28 -0600 Subject: [PATCH 5/9] Fix wording on confirmation message and tweak the modal window --- Lamp/Control/lampControl.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lamp/Control/lampControl.h b/Lamp/Control/lampControl.h index 821f188..3e6b34a 100644 --- a/Lamp/Control/lampControl.h +++ b/Lamp/Control/lampControl.h @@ -352,7 +352,7 @@ namespace Lamp::Core{ if (ImGui::Button(("Remove Mod##" + std::to_string(i)).c_str())) { lampControl::getInstance().deletePos = i; - ImGui::OpenPopup("DELETE_MOD_MODAL"); + ImGui::OpenPopup("Confirm Deletion"); ImGui::EndDisabled(); // fixes a crash when deleting items (when at least 1 mod has been enabled) break; @@ -361,17 +361,17 @@ namespace Lamp::Core{ // Setup centering for the modal window ImVec2 center = ImGui::GetMainViewport()->GetCenter(); ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); - - if(ImGui::BeginPopupModal("DELETE_MOD_MODAL", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ + ImGui::SetNextWindowBgAlpha(0.9f); // This doesn't seem to mess anything up, but if it does search for new way to make modal bg more opaque. + if(ImGui::BeginPopupModal("Confirm Deletion", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ // prevent displaying buttons for each mod in the mod list, as this runs every iteration of for loop if(lampControl::getInstance().deletePos == i){ auto pendingDelete = ModList.begin() + lampControl::getInstance().deletePos; std::filesystem::path tmppath = (*pendingDelete)->ArchivePath; std::string delname = tmppath.filename().c_str(); - std::string promptMessage = "Confirm deleting "; + std::string promptMessage = "Are you sure you want to delete: "; promptMessage.append(delname); - promptMessage.append("?"); + promptMessage.append("?\n\nThis action cannot be undone."); ImGui::Text(promptMessage.c_str()); ImGui::Separator(); From f77419b65dc2a1cac62a4a9ecd8f48e61a32dbf5 Mon Sep 17 00:00:00 2001 From: SnazzyPanda <35570455+SnazzyPanda@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:10:52 -0600 Subject: [PATCH 6/9] Remove unnecessary variables --- Lamp/Control/lampControl.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Lamp/Control/lampControl.h b/Lamp/Control/lampControl.h index 3e6b34a..f765c4c 100644 --- a/Lamp/Control/lampControl.h +++ b/Lamp/Control/lampControl.h @@ -365,24 +365,20 @@ namespace Lamp::Core{ if(ImGui::BeginPopupModal("Confirm Deletion", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ // prevent displaying buttons for each mod in the mod list, as this runs every iteration of for loop if(lampControl::getInstance().deletePos == i){ - auto pendingDelete = ModList.begin() + lampControl::getInstance().deletePos; - std::filesystem::path tmppath = (*pendingDelete)->ArchivePath; - std::string delname = tmppath.filename().c_str(); - std::string promptMessage = "Are you sure you want to delete: "; - promptMessage.append(delname); + promptMessage.append(cutname); promptMessage.append("?\n\nThis action cannot be undone."); ImGui::Text(promptMessage.c_str()); ImGui::Separator(); if (ImGui::Button("Delete", ImVec2(120, 0))) { - int deleteResult = std::remove(absolute(tmppath).c_str()); + int deleteResult = std::remove(absolute(path).c_str()); if(deleteResult != 0){ - std::cout << "Error deleting file: " << absolute(tmppath).c_str() << "\n Error msg: " << strerror(errno) << "\n"; + std::cout << "Error deleting file: " << absolute(path).c_str() << "\n Error msg: " << strerror(errno) << "\n"; } - std::cout << absolute(tmppath).c_str() << std::endl; - ModList.erase(pendingDelete); + std::cout << absolute(path).c_str() << std::endl; + ModList.erase(it); Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); lampControl::getInstance().deletePos = -1; From 6b3c3a8440d957b4200e181104757faf6a8455d1 Mon Sep 17 00:00:00 2001 From: SnazzyPanda <35570455+SnazzyPanda@users.noreply.github.com> Date: Mon, 4 Dec 2023 16:41:58 -0600 Subject: [PATCH 7/9] Move prompt outside for loop This still does not fix the scroll jumping issue --- Lamp/Control/lampControl.h | 93 +++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/Lamp/Control/lampControl.h b/Lamp/Control/lampControl.h index f765c4c..6ff5440 100644 --- a/Lamp/Control/lampControl.h +++ b/Lamp/Control/lampControl.h @@ -358,48 +358,7 @@ namespace Lamp::Core{ break; } - // Setup centering for the modal window - ImVec2 center = ImGui::GetMainViewport()->GetCenter(); - ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); - ImGui::SetNextWindowBgAlpha(0.9f); // This doesn't seem to mess anything up, but if it does search for new way to make modal bg more opaque. - if(ImGui::BeginPopupModal("Confirm Deletion", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ - // prevent displaying buttons for each mod in the mod list, as this runs every iteration of for loop - if(lampControl::getInstance().deletePos == i){ - std::string promptMessage = "Are you sure you want to delete: "; - promptMessage.append(cutname); - promptMessage.append("?\n\nThis action cannot be undone."); - ImGui::Text(promptMessage.c_str()); - ImGui::Separator(); - - if (ImGui::Button("Delete", ImVec2(120, 0))) { - int deleteResult = std::remove(absolute(path).c_str()); - if(deleteResult != 0){ - std::cout << "Error deleting file: " << absolute(path).c_str() << "\n Error msg: " << strerror(errno) << "\n"; - } - - std::cout << absolute(path).c_str() << std::endl; - ModList.erase(it); - Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); - - lampControl::getInstance().deletePos = -1; - ImGui::CloseCurrentPopup(); - ImGui::EndPopup(); - // re-end disabled. May be needed to avoid some crashes. - ImGui::EndDisabled(); - break; - } - ImGui::SetItemDefaultFocus(); - ImGui::SameLine(); - if (ImGui::Button("Cancel", ImVec2(120, 0))) { - // Do nothing - lampControl::getInstance().deletePos = -1; - ImGui::CloseCurrentPopup(); - } - } - - ImGui::EndPopup(); - } // end delete confirmation modal if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && (*it)->enabled) { @@ -429,6 +388,58 @@ namespace Lamp::Core{ i++; } +// Setup centering for the modal window +ImVec2 center = ImGui::GetMainViewport()->GetCenter(); +ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); +ImGui::SetNextWindowBgAlpha(0.9f); // This doesn't seem to mess anything up, but if it does search for new way to make modal bg more opaque. +if(ImGui::BeginPopupModal("Confirm Deletion", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ + + + auto pendingDelete = ModList.begin() + lampControl::getInstance().deletePos; + + std::filesystem::path path((*pendingDelete)->ArchivePath); + std::string delname = path.filename().c_str(); + + // prevent displaying buttons for each mod in the mod list, as this runs every iteration of for loop + //if(lampControl::getInstance().deletePos == i){ + std::string promptMessage = "Are you sure you want to delete: "; + promptMessage.append(delname); + promptMessage.append("?\n\nThis action cannot be undone."); + ImGui::Text(promptMessage.c_str()); + ImGui::Separator(); + + if (ImGui::Button("Delete", ImVec2(120, 0))) { + int deleteResult = std::remove(absolute(path).c_str()); + if(deleteResult != 0){ + std::cout << "Error deleting file: " << absolute(path).c_str() << "\n Error msg: " << strerror(errno) << "\n"; + } + + std::cout << absolute(path).c_str() << std::endl; + ModList.erase(pendingDelete); + Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); + + lampControl::getInstance().deletePos = -1; + ImGui::CloseCurrentPopup(); + //ImGui::EndPopup(); + // re-end disabled. May be needed to avoid some crashes. + //ImGui::EndDisabled(); + + //break; + } + ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); + if (ImGui::Button("Cancel", ImVec2(120, 0))) { + // Do nothing + lampControl::getInstance().deletePos = -1; + ImGui::CloseCurrentPopup(); + } + //} + + ImGui::EndPopup(); +} // end delete confirmation modal + + + ImGui::EndTable(); } } From 290c6fb810bbb0d723f5d7221f66bb3c3a68cb70 Mon Sep 17 00:00:00 2001 From: SnazzyPanda <35570455+SnazzyPanda@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:25:19 -0600 Subject: [PATCH 8/9] Fix indentation --- Lamp/Control/lampControl.h | 81 +++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/Lamp/Control/lampControl.h b/Lamp/Control/lampControl.h index 6ff5440..52d1455 100644 --- a/Lamp/Control/lampControl.h +++ b/Lamp/Control/lampControl.h @@ -388,55 +388,46 @@ namespace Lamp::Core{ i++; } -// Setup centering for the modal window -ImVec2 center = ImGui::GetMainViewport()->GetCenter(); -ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); -ImGui::SetNextWindowBgAlpha(0.9f); // This doesn't seem to mess anything up, but if it does search for new way to make modal bg more opaque. -if(ImGui::BeginPopupModal("Confirm Deletion", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ - - - auto pendingDelete = ModList.begin() + lampControl::getInstance().deletePos; - - std::filesystem::path path((*pendingDelete)->ArchivePath); - std::string delname = path.filename().c_str(); - - // prevent displaying buttons for each mod in the mod list, as this runs every iteration of for loop - //if(lampControl::getInstance().deletePos == i){ - std::string promptMessage = "Are you sure you want to delete: "; - promptMessage.append(delname); - promptMessage.append("?\n\nThis action cannot be undone."); - ImGui::Text(promptMessage.c_str()); - ImGui::Separator(); - - if (ImGui::Button("Delete", ImVec2(120, 0))) { - int deleteResult = std::remove(absolute(path).c_str()); - if(deleteResult != 0){ - std::cout << "Error deleting file: " << absolute(path).c_str() << "\n Error msg: " << strerror(errno) << "\n"; - } + // Setup centering for the modal window + ImVec2 center = ImGui::GetMainViewport()->GetCenter(); + ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + ImGui::SetNextWindowBgAlpha(0.9f); // This doesn't seem to mess anything up, but if it does search for new way to make modal bg more opaque. + if(ImGui::BeginPopupModal("Confirm Deletion", NULL, ImGuiWindowFlags_AlwaysAutoResize)){ + auto pendingDelete = ModList.begin() + lampControl::getInstance().deletePos; + + std::filesystem::path path((*pendingDelete)->ArchivePath); + std::string delname = path.filename().c_str(); + + std::string promptMessage = "Are you sure you want to delete: "; + promptMessage.append(delname); + promptMessage.append("?\n\nThis action cannot be undone."); + ImGui::Text(promptMessage.c_str()); + ImGui::Separator(); + + if (ImGui::Button("Delete", ImVec2(120, 0))) { + int deleteResult = std::remove(absolute(path).c_str()); + if(deleteResult != 0){ + std::cout << "Error deleting file: " << absolute(path).c_str() << "\n Error msg: " << strerror(errno) << "\n"; + } - std::cout << absolute(path).c_str() << std::endl; - ModList.erase(pendingDelete); - Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); + std::cout << absolute(path).c_str() << std::endl; + ModList.erase(pendingDelete); + Core::FS::lampIO::saveModList(Lamp::Games::getInstance().currentGame->Ident().ShortHand, ModList,Games::getInstance().currentProfile); - lampControl::getInstance().deletePos = -1; - ImGui::CloseCurrentPopup(); - //ImGui::EndPopup(); - // re-end disabled. May be needed to avoid some crashes. - //ImGui::EndDisabled(); + lampControl::getInstance().deletePos = -1; + ImGui::CloseCurrentPopup(); + } + ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); - //break; - } - ImGui::SetItemDefaultFocus(); - ImGui::SameLine(); - if (ImGui::Button("Cancel", ImVec2(120, 0))) { - // Do nothing - lampControl::getInstance().deletePos = -1; - ImGui::CloseCurrentPopup(); - } - //} + if (ImGui::Button("Cancel", ImVec2(120, 0))) { + // Do nothing + lampControl::getInstance().deletePos = -1; + ImGui::CloseCurrentPopup(); + } - ImGui::EndPopup(); -} // end delete confirmation modal + ImGui::EndPopup(); + } // end delete confirmation modal From 0a95f3b4c1fe0d915fa1cc77467b675eabbd2b50 Mon Sep 17 00:00:00 2001 From: SnazzyPanda <35570455+SnazzyPanda@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:26:15 -0600 Subject: [PATCH 9/9] Right align the cancel button in the modal window --- Lamp/Control/lampControl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lamp/Control/lampControl.h b/Lamp/Control/lampControl.h index 52d1455..08048b9 100644 --- a/Lamp/Control/lampControl.h +++ b/Lamp/Control/lampControl.h @@ -419,7 +419,8 @@ namespace Lamp::Core{ } ImGui::SetItemDefaultFocus(); ImGui::SameLine(); - + // right-align the cancel button to help avoid potential misclicks on the delete button + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 120); if (ImGui::Button("Cancel", ImVec2(120, 0))) { // Do nothing lampControl::getInstance().deletePos = -1;