mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 01:23:24 -08:00
[Refactor] Move card selection actions to GameScene and p/t parsing to CardState (#7426)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
c9853734ad
commit
4879ddbd0f
10 changed files with 121 additions and 116 deletions
|
|
@ -40,6 +40,7 @@
|
|||
#include <QSharedPointer>
|
||||
#include <QtMath>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <libcockatrice/settings/interface_settings.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
#include <numeric>
|
||||
|
|
@ -124,6 +125,56 @@ QList<CardItem *> GameScene::selectedCards() const
|
|||
return selectedCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects every card of @p zone for which @p filter holds.
|
||||
* @param filter A predicate to filter which cards are selected.
|
||||
*/
|
||||
static void selectCardsInZone(
|
||||
const CardZoneLogic *zone,
|
||||
std::function<bool(const CardItem *)> filter = [](const CardItem *) { return true; })
|
||||
{
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &cardItem : zone->getCards()) {
|
||||
if (cardItem && filter(cardItem)) {
|
||||
cardItem->setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::selectAllInZone(const CardItem *card)
|
||||
{
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectCardsInZone(card->getZone());
|
||||
}
|
||||
|
||||
void GameScene::selectSameRow(const CardItem *card)
|
||||
{
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto isSameRow = [card](const CardItem *cardItem) {
|
||||
return qAbs(card->scenePos().y() - cardItem->scenePos().y()) < 50;
|
||||
};
|
||||
selectCardsInZone(card->getZone(), isSameRow);
|
||||
}
|
||||
|
||||
void GameScene::selectSameColumn(const CardItem *card)
|
||||
{
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto isSameColumn = [card](const CardItem *cardItem) { return cardItem->x() == card->x(); };
|
||||
selectCardsInZone(card->getZone(), isSameColumn);
|
||||
}
|
||||
|
||||
CardItem *GameScene::getActiveCard() const
|
||||
{
|
||||
return activeCard;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue