From 0d60649715a6c42ff9ca12b54a60ccadb5e32a5b Mon Sep 17 00:00:00 2001 From: bicarus <202771338+bicarus-dev@users.noreply.github.com> Date: Tue, 31 Mar 2026 00:07:34 -0700 Subject: [PATCH] overlay: small tweaks to cards tab (#602) ## Link to GitHub Issue or related Pull Request, if one exists #593 ## Description of change * Display a confirmation dialog when clicking on `Generate` for the first time (to prevent accidental loss of card number) * If `cardN.txt` contents are read back successfully, show card number in green to indicate success, and red in case of failure. --- src/spice2x/overlay/windows/config.cpp | 87 ++++++++++++++++++++++---- src/spice2x/overlay/windows/config.h | 3 +- 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/spice2x/overlay/windows/config.cpp b/src/spice2x/overlay/windows/config.cpp index dca7571..023828c 100644 --- a/src/spice2x/overlay/windows/config.cpp +++ b/src/spice2x/overlay/windows/config.cpp @@ -58,6 +58,7 @@ namespace overlay::windows { const auto PROJECT_URL = "https://spice2x.github.io"; constexpr ImVec4 TEXT_COLOR_GREEN(0.f, 1.f, 0.f, 1.f); + constexpr ImVec4 TEXT_COLOR_RED(1.f, 0.f, 0.f, 1.f); constexpr uint32_t OPTION_INPUT_TEXT_WIDTH = 512; std::unique_ptr asio_driver_list; @@ -3831,16 +3832,24 @@ namespace overlay::windows { // generate button ImGui::SameLine(); if (ImGui::Button("Generate")) { - generate_ea_card(buffer); - card_changed = true; + if (!this->keypads_card_overwrite_confirmed[player] && buffer_len > 0) { + ImGui::OpenPopup("Card Generator##GenerateCardConfirm"); + } else { + generate_ea_card(buffer); + card_changed = true; + } } // clear button if (option.is_active()) { ImGui::SameLine(); if (ImGui::Button("Clear")) { - buffer[0] = '\0'; - card_changed = true; + if (!this->keypads_card_overwrite_confirmed[player] && buffer_len > 0) { + ImGui::OpenPopup("Clear Card##ClearCardConfirm"); + } else { + buffer[0] = '\0'; + card_changed = true; + } } } } else { @@ -3857,6 +3866,61 @@ namespace overlay::windows { ImGui::TextColored(ImVec4(1.f, 0.f, 0.f, 1.f), "Invalid card number"); } + if (ImGui::BeginPopupModal( + "Card Generator##GenerateCardConfirm", + nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + + ImGui::TextUnformatted( + "What do you want to do?"); + ImGui::Spacing(); + ImGui::Separator(); + ImGui::Spacing(); + ImGui::AlignTextToFramePadding(); + ImGui::Bullet(); + ImGui::SameLine(); + if (ImGui::Button("Discard current card and generate new one")) { + this->keypads_card_overwrite_confirmed[player] = true; + generate_ea_card(buffer); + card_changed = true; + ImGui::CloseCurrentPopup(); + } + ImGui::AlignTextToFramePadding(); + ImGui::Bullet(); + ImGui::SameLine(); + if (ImGui::Button("Keep current card and cancel")) { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + if (ImGui::BeginPopupModal( + "Clear Card##ClearCardConfirm", + nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + + ImGui::TextUnformatted( + "This cannot be undone. Are you sure?"); + ImGui::Spacing(); + ImGui::Separator(); + ImGui::Spacing(); + ImGui::AlignTextToFramePadding(); + ImGui::Bullet(); + ImGui::SameLine(); + if (ImGui::Button("Yes, delete card number")) { + this->keypads_card_overwrite_confirmed[player] = true; + buffer[0] = '\0'; + card_changed = true; + ImGui::CloseCurrentPopup(); + } + ImGui::AlignTextToFramePadding(); + ImGui::Bullet(); + ImGui::SameLine(); + if (ImGui::Button("No, keep my card number")) { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + ImGui::TreePop(); } @@ -3995,7 +4059,7 @@ namespace overlay::windows { } ImGui::SameLine(); - if (ImGui::Button("Edit")) { + if (ImGui::Button("Edit in Notepad")) { std::filesystem::path path; if (!bindings.card_paths[player].empty()) { path = bindings.card_paths[player]; @@ -4023,19 +4087,20 @@ namespace overlay::windows { } // card number box - ImGui::PushStyleColor( - ImGuiCol_Text, - this->keypads_card_file_contents_valid[player] ? ImVec4(1.f, 1.f, 1.f, 1.f) : - ImVec4(1.f, 0.f, 0.f, 1.f)); + ImGui::SetNextItemWidth(TEXT_INPUT_WIDTH); ImGui::BeginDisabled(); if (this->keypads_card_number[player][0] != 0) { + ImGui::PushStyleColor( + ImGuiCol_Text, + this->keypads_card_file_contents_valid[player] ? + TEXT_COLOR_GREEN : TEXT_COLOR_RED); ImGui::Text("Card from file: %s", this->keypads_card_number[player]); + ImGui::PopStyleColor(); } else { - ImGui::TextUnformatted("Failed to read file."); + ImGui::TextColored(TEXT_COLOR_RED, "Failed to read file."); } ImGui::EndDisabled(); - ImGui::PopStyleColor(); } ImGui::TreePop(); diff --git a/src/spice2x/overlay/windows/config.h b/src/spice2x/overlay/windows/config.h index d29dc46..524ea6a 100644 --- a/src/spice2x/overlay/windows/config.h +++ b/src/spice2x/overlay/windows/config.h @@ -87,7 +87,7 @@ namespace overlay::windows { bool auto_match_soft_enabled = true; bool auto_match_p2 = false; - // keypads tab + // cards tab int keypads_selected[2] {}; char keypads_card_path[2][1024] {}; std::thread *keypads_card_select = nullptr; @@ -96,6 +96,7 @@ namespace overlay::windows { char keypads_card_number[2][18] {}; bool keypads_card_override_valid[2] = { false, false }; bool keypads_card_file_contents_valid[2] = { false, false }; + bool keypads_card_overwrite_confirmed[2]; // presets tab std::vector templates_cache;