From 279aa8c836ebea5ef7d1908639b61eb56b83072f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Wed, 27 Nov 2024 23:52:35 +0100 Subject: [PATCH] Don't hide PrintingSelector button widgets if the deck contains a card from the set. --- .../all_zones_card_amount_widget.cpp | 10 ++++++++ .../all_zones_card_amount_widget.h | 2 ++ .../printing_selector_card_overlay_widget.cpp | 25 +++++++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.cpp b/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.cpp index 23ececb67..a61845823 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.cpp +++ b/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.cpp @@ -48,6 +48,16 @@ AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent, setMouseTracking(true); } +int AllZonesCardAmountWidget::getMainboardAmount() +{ + return buttonBoxMainboard->countCardsInZone(DECK_ZONE_MAIN); +} + +int AllZonesCardAmountWidget::getSideboardAmount() +{ + return buttonBoxSideboard->countCardsInZone(DECK_ZONE_SIDE); +} + #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) void AllZonesCardAmountWidget::enterEvent(QEnterEvent *event) #else diff --git a/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.h b/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.h index 3730a5502..d1c6dcbdd 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.h +++ b/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.h @@ -18,6 +18,8 @@ public: QTreeView *deckView, CardInfoPtr rootCard, CardInfoPerSet setInfoForCard); + int getMainboardAmount(); + int getSideboardAmount(); #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) void enterEvent(QEnterEvent *event) override; #else diff --git a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_card_overlay_widget.cpp b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_card_overlay_widget.cpp index a7a977536..b540a557c 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_card_overlay_widget.cpp +++ b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector_card_overlay_widget.cpp @@ -37,7 +37,12 @@ PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *pa new AllZonesCardAmountWidget(this, deckEditor, deckModel, deckView, setCard, setInfoForCard); allZonesCardAmountWidget->raise(); // Ensure it's on top of the picture - allZonesCardAmountWidget->setVisible(false); + // Set initial visibility based on amounts + if (allZonesCardAmountWidget->getMainboardAmount() > 0 || allZonesCardAmountWidget->getSideboardAmount() > 0) { + allZonesCardAmountWidget->setVisible(true); + } else { + allZonesCardAmountWidget->setVisible(false); + } // Attempt to cast the parent to PrintingSelectorCardDisplayWidget if (const auto *parentWidget = qobject_cast(parent)) { @@ -74,13 +79,29 @@ void PrintingSelectorCardOverlayWidget::enterEvent(QEvent *event) #endif { QWidget::enterEvent(event); - allZonesCardAmountWidget->setVisible(true); deckEditor->updateCardInfo(setCard); + + // Check if either mainboard or sideboard amount is greater than 0 + if (allZonesCardAmountWidget->getMainboardAmount() > 0 || allZonesCardAmountWidget->getSideboardAmount() > 0) { + // Don't change visibility if amounts are greater than 0 + return; + } + + // Show the widget if amounts are 0 + allZonesCardAmountWidget->setVisible(true); } void PrintingSelectorCardOverlayWidget::leaveEvent(QEvent *event) { QWidget::leaveEvent(event); + + // Check if either mainboard or sideboard amount is greater than 0 + if (allZonesCardAmountWidget->getMainboardAmount() > 0 || allZonesCardAmountWidget->getSideboardAmount() > 0) { + // Don't hide the widget if amounts are greater than 0 + return; + } + + // Hide the widget if amounts are 0 allZonesCardAmountWidget->setVisible(false); }