From 6ef8537d5d12d81072136adae6dfb92bb3e1e936 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Fri, 4 Apr 2025 22:31:27 -0700 Subject: [PATCH] implement filter logic --- cockatrice/src/game/zones/view_zone.cpp | 17 ++++++++++++++++- cockatrice/src/game/zones/view_zone.h | 3 +++ cockatrice/src/game/zones/view_zone_widget.cpp | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/game/zones/view_zone.cpp b/cockatrice/src/game/zones/view_zone.cpp index 9e9ba6e81..793f90918 100644 --- a/cockatrice/src/game/zones/view_zone.cpp +++ b/cockatrice/src/game/zones/view_zone.cpp @@ -148,7 +148,16 @@ void ZoneViewZone::updateCardIds(CardAction action) // Because of boundingRect(), this function must not be called before the zone was added to a scene. void ZoneViewZone::reorganizeCards() { - CardList cardsToDisplay(cards); + // filter cards + CardList cardsToDisplay = CardList(cards.getContentsKnown()); + for (auto card : cards) { + if (filterString.check(card->getInfo())) { + card->show(); + cardsToDisplay.append(card); + } else { + card->hide(); + } + } // sort cards QList sortOptions; @@ -263,6 +272,12 @@ ZoneViewZone::GridSize ZoneViewZone::positionCardsForDisplay(CardList &cards, Ca } } +void ZoneViewZone::setFilterString(const QString &_filterString) +{ + filterString = FilterString(_filterString); + reorganizeCards(); +} + void ZoneViewZone::setGroupBy(CardList::SortOption _groupBy) { groupBy = _groupBy; diff --git a/cockatrice/src/game/zones/view_zone.h b/cockatrice/src/game/zones/view_zone.h index 3c69317aa..84fbe5ce6 100644 --- a/cockatrice/src/game/zones/view_zone.h +++ b/cockatrice/src/game/zones/view_zone.h @@ -1,6 +1,7 @@ #ifndef ZONEVIEWERZONE_H #define ZONEVIEWERZONE_H +#include "../filters/filter_string.h" #include "select_zone.h" #include @@ -35,6 +36,7 @@ private: int minRows, numberCards; CardZone *origZone; bool revealZone, writeableRevealZone; + FilterString filterString = FilterString(""); CardList::SortOption groupBy, sortBy; bool pileView; bool isReversed; @@ -96,6 +98,7 @@ public: } public slots: void close(); + void setFilterString(const QString &_filterString); void setGroupBy(CardList::SortOption _groupBy); void setSortBy(CardList::SortOption _sortBy); void setPileView(int _pileView); diff --git a/cockatrice/src/game/zones/view_zone_widget.cpp b/cockatrice/src/game/zones/view_zone_widget.cpp index cf5838484..85a91afdf 100644 --- a/cockatrice/src/game/zones/view_zone_widget.cpp +++ b/cockatrice/src/game/zones/view_zone_widget.cpp @@ -145,6 +145,8 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, if (CardList::NoSort == static_cast(groupBySelector.currentData().toInt())) { pileViewCheckBox.setEnabled(false); } + + connect(&searchEdit, &QLineEdit::textChanged, zone, &ZoneViewZone::setFilterString); } setLayout(vbox);