mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 16:44:48 -07:00
card menu improvement, change controller support (bug #3)
This commit is contained in:
parent
4f9252c65c
commit
231887367c
25 changed files with 305 additions and 205 deletions
|
|
@ -17,91 +17,68 @@
|
|||
#include "tab_game.h"
|
||||
|
||||
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, QGraphicsItem *parent)
|
||||
: AbstractCardItem(_name, _owner, parent), id(_cardid), attacking(false), facedown(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
||||
: AbstractCardItem(_name, _owner, parent), zone(0), id(_cardid), attacking(false), facedown(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
||||
{
|
||||
owner->addCard(this);
|
||||
|
||||
if (owner->getLocal()) {
|
||||
aTap = new QAction(this);
|
||||
aTap->setData(0);
|
||||
connect(aTap, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
|
||||
aUntap = new QAction(this);
|
||||
aUntap->setData(1);
|
||||
connect(aUntap, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
|
||||
aDoesntUntap = new QAction(this);
|
||||
aDoesntUntap->setData(2);
|
||||
connect(aDoesntUntap, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
|
||||
aAttach = new QAction(this);
|
||||
connect(aAttach, SIGNAL(triggered()), owner, SLOT(actAttach()));
|
||||
aUnattach = new QAction(this);
|
||||
connect(aUnattach, SIGNAL(triggered()), owner, SLOT(actUnattach()));
|
||||
aSetPT = new QAction(this);
|
||||
connect(aSetPT, SIGNAL(triggered()), owner, SLOT(actSetPT()));
|
||||
aSetAnnotation = new QAction(this);
|
||||
connect(aSetAnnotation, SIGNAL(triggered()), owner, SLOT(actSetAnnotation()));
|
||||
aFlip = new QAction(this);
|
||||
aFlip->setData(3);
|
||||
connect(aFlip, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
|
||||
aClone = new QAction(this);
|
||||
aClone->setData(4);
|
||||
connect(aClone, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
|
||||
aMoveToTopLibrary = new QAction(this);
|
||||
aMoveToTopLibrary->setData(5);
|
||||
aMoveToBottomLibrary = new QAction(this);
|
||||
aMoveToBottomLibrary->setData(6);
|
||||
aMoveToGraveyard = new QAction(this);
|
||||
aMoveToGraveyard->setData(7);
|
||||
aMoveToExile = new QAction(this);
|
||||
aMoveToExile->setData(8);
|
||||
connect(aMoveToTopLibrary, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
|
||||
connect(aMoveToBottomLibrary, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
|
||||
connect(aMoveToGraveyard, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
|
||||
connect(aMoveToExile, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
|
||||
aTap = new QAction(this);
|
||||
aTap->setData(0);
|
||||
connect(aTap, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||
aUntap = new QAction(this);
|
||||
aUntap->setData(1);
|
||||
connect(aUntap, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||
aDoesntUntap = new QAction(this);
|
||||
aDoesntUntap->setData(2);
|
||||
connect(aDoesntUntap, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||
aAttach = new QAction(this);
|
||||
connect(aAttach, SIGNAL(triggered()), this, SLOT(actAttach()));
|
||||
aUnattach = new QAction(this);
|
||||
connect(aUnattach, SIGNAL(triggered()), this, SLOT(actUnattach()));
|
||||
aSetPT = new QAction(this);
|
||||
connect(aSetPT, SIGNAL(triggered()), this, SLOT(actSetPT()));
|
||||
aSetAnnotation = new QAction(this);
|
||||
connect(aSetAnnotation, SIGNAL(triggered()), this, SLOT(actSetAnnotation()));
|
||||
aFlip = new QAction(this);
|
||||
aFlip->setData(3);
|
||||
connect(aFlip, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||
aClone = new QAction(this);
|
||||
aClone->setData(4);
|
||||
connect(aClone, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||
aMoveToTopLibrary = new QAction(this);
|
||||
aMoveToTopLibrary->setData(5);
|
||||
aMoveToBottomLibrary = new QAction(this);
|
||||
aMoveToBottomLibrary->setData(6);
|
||||
aMoveToGraveyard = new QAction(this);
|
||||
aMoveToGraveyard->setData(7);
|
||||
aMoveToExile = new QAction(this);
|
||||
aMoveToExile->setData(8);
|
||||
connect(aMoveToTopLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||
connect(aMoveToBottomLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||
connect(aMoveToGraveyard, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||
connect(aMoveToExile, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
|
||||
|
||||
aPlay = new QAction(this);
|
||||
connect(aPlay, SIGNAL(triggered()), this, SLOT(actPlay()));
|
||||
|
||||
cardMenu = new QMenu;
|
||||
cardMenu->addAction(aTap);
|
||||
cardMenu->addAction(aUntap);
|
||||
cardMenu->addAction(aDoesntUntap);
|
||||
cardMenu->addAction(aFlip);
|
||||
cardMenu->addSeparator();
|
||||
cardMenu->addAction(aAttach);
|
||||
cardMenu->addAction(aUnattach);
|
||||
cardMenu->addSeparator();
|
||||
cardMenu->addAction(aSetPT);
|
||||
cardMenu->addAction(aSetAnnotation);
|
||||
cardMenu->addSeparator();
|
||||
cardMenu->addAction(aClone);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
QAction *tempAddCounter = new QAction(this);
|
||||
tempAddCounter->setData(9 + i * 1000);
|
||||
QAction *tempRemoveCounter = new QAction(this);
|
||||
tempRemoveCounter->setData(10 + i * 1000);
|
||||
QAction *tempSetCounter = new QAction(this);
|
||||
tempSetCounter->setData(11 + i * 1000);
|
||||
aAddCounter.append(tempAddCounter);
|
||||
aRemoveCounter.append(tempRemoveCounter);
|
||||
aSetCounter.append(tempSetCounter);
|
||||
connect(tempAddCounter, SIGNAL(triggered()), owner, SLOT(actCardCounterTrigger()));
|
||||
connect(tempRemoveCounter, SIGNAL(triggered()), owner, SLOT(actCardCounterTrigger()));
|
||||
connect(tempSetCounter, SIGNAL(triggered()), owner, SLOT(actCardCounterTrigger()));
|
||||
|
||||
cardMenu->addSeparator();
|
||||
cardMenu->addAction(tempAddCounter);
|
||||
cardMenu->addAction(tempRemoveCounter);
|
||||
cardMenu->addAction(tempSetCounter);
|
||||
}
|
||||
cardMenu->addSeparator();
|
||||
|
||||
moveMenu = cardMenu->addMenu(QString());
|
||||
moveMenu->addAction(aMoveToTopLibrary);
|
||||
moveMenu->addAction(aMoveToBottomLibrary);
|
||||
moveMenu->addAction(aMoveToGraveyard);
|
||||
moveMenu->addAction(aMoveToExile);
|
||||
|
||||
|
||||
retranslateUi();
|
||||
} else
|
||||
cardMenu = 0;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
QAction *tempAddCounter = new QAction(this);
|
||||
tempAddCounter->setData(9 + i * 1000);
|
||||
QAction *tempRemoveCounter = new QAction(this);
|
||||
tempRemoveCounter->setData(10 + i * 1000);
|
||||
QAction *tempSetCounter = new QAction(this);
|
||||
tempSetCounter->setData(11 + i * 1000);
|
||||
aAddCounter.append(tempAddCounter);
|
||||
aRemoveCounter.append(tempRemoveCounter);
|
||||
aSetCounter.append(tempSetCounter);
|
||||
connect(tempAddCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
|
||||
connect(tempRemoveCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
|
||||
connect(tempSetCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
|
||||
}
|
||||
cardMenu = new QMenu;
|
||||
moveMenu = new QMenu;
|
||||
|
||||
retranslateUi();
|
||||
updateCardMenu();
|
||||
}
|
||||
|
||||
CardItem::~CardItem()
|
||||
|
|
@ -110,6 +87,8 @@ CardItem::~CardItem()
|
|||
|
||||
delete cardMenu;
|
||||
cardMenu = 0;
|
||||
delete moveMenu;
|
||||
moveMenu = 0;
|
||||
|
||||
deleteDragItem();
|
||||
}
|
||||
|
|
@ -139,37 +118,85 @@ void CardItem::deleteLater()
|
|||
AbstractCardItem::deleteLater();
|
||||
}
|
||||
|
||||
void CardItem::setZone(CardZone *_zone)
|
||||
{
|
||||
zone = _zone;
|
||||
updateCardMenu();
|
||||
}
|
||||
|
||||
void CardItem::updateCardMenu()
|
||||
{
|
||||
cardMenu->clear();
|
||||
|
||||
if (owner->getLocal()) {
|
||||
if (zone) {
|
||||
if (zone->getName() == "table") {
|
||||
cardMenu->addAction(aTap);
|
||||
cardMenu->addAction(aUntap);
|
||||
cardMenu->addAction(aDoesntUntap);
|
||||
cardMenu->addAction(aFlip);
|
||||
cardMenu->addSeparator();
|
||||
cardMenu->addAction(aAttach);
|
||||
if (attachedTo)
|
||||
cardMenu->addAction(aUnattach);
|
||||
cardMenu->addSeparator();
|
||||
cardMenu->addAction(aSetPT);
|
||||
cardMenu->addAction(aSetAnnotation);
|
||||
cardMenu->addSeparator();
|
||||
cardMenu->addAction(aClone);
|
||||
|
||||
for (int i = 0; i < aAddCounter.size(); ++i) {
|
||||
cardMenu->addSeparator();
|
||||
cardMenu->addAction(aAddCounter[i]);
|
||||
cardMenu->addAction(aRemoveCounter[i]);
|
||||
cardMenu->addAction(aSetCounter[i]);
|
||||
}
|
||||
cardMenu->addSeparator();
|
||||
} else {
|
||||
cardMenu->addAction(aPlay);
|
||||
}
|
||||
}
|
||||
|
||||
moveMenu->clear();
|
||||
moveMenu->addAction(aMoveToTopLibrary);
|
||||
moveMenu->addAction(aMoveToBottomLibrary);
|
||||
moveMenu->addAction(aMoveToGraveyard);
|
||||
moveMenu->addAction(aMoveToExile);
|
||||
cardMenu->addMenu(moveMenu);
|
||||
}
|
||||
}
|
||||
|
||||
void CardItem::retranslateUi()
|
||||
{
|
||||
if (owner->getLocal()) {
|
||||
aTap->setText(tr("&Tap"));
|
||||
aUntap->setText(tr("&Untap"));
|
||||
aDoesntUntap->setText(tr("Toggle &normal untapping"));
|
||||
aFlip->setText(tr("&Flip"));
|
||||
aClone->setText(tr("&Clone"));
|
||||
aAttach->setText(tr("&Attach to card..."));
|
||||
aAttach->setShortcut(tr("Ctrl+A"));
|
||||
aUnattach->setText(tr("Unattac&h"));
|
||||
aSetPT->setText(tr("Set &P/T..."));
|
||||
aSetAnnotation->setText(tr("&Set annotation..."));
|
||||
QStringList counterColors;
|
||||
counterColors.append(tr("red"));
|
||||
counterColors.append(tr("yellow"));
|
||||
counterColors.append(tr("green"));
|
||||
for (int i = 0; i < aAddCounter.size(); ++i)
|
||||
aAddCounter[i]->setText(tr("&Add counter (%1)").arg(counterColors[i]));
|
||||
for (int i = 0; i < aRemoveCounter.size(); ++i)
|
||||
aRemoveCounter[i]->setText(tr("&Remove counter (%1)").arg(counterColors[i]));
|
||||
for (int i = 0; i < aSetCounter.size(); ++i)
|
||||
aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(counterColors[i]));
|
||||
aMoveToTopLibrary->setText(tr("&top of library"));
|
||||
aMoveToBottomLibrary->setText(tr("&bottom of library"));
|
||||
aMoveToGraveyard->setText(tr("&graveyard"));
|
||||
aMoveToGraveyard->setShortcut(tr("Ctrl+Del"));
|
||||
aMoveToExile->setText(tr("&exile"));
|
||||
|
||||
moveMenu->setTitle(tr("&Move to"));
|
||||
}
|
||||
aPlay->setText(tr("&Play"));
|
||||
|
||||
aTap->setText(tr("&Tap"));
|
||||
aUntap->setText(tr("&Untap"));
|
||||
aDoesntUntap->setText(tr("Toggle &normal untapping"));
|
||||
aFlip->setText(tr("&Flip"));
|
||||
aClone->setText(tr("&Clone"));
|
||||
aAttach->setText(tr("&Attach to card..."));
|
||||
aAttach->setShortcut(tr("Ctrl+A"));
|
||||
aUnattach->setText(tr("Unattac&h"));
|
||||
aSetPT->setText(tr("Set &P/T..."));
|
||||
aSetAnnotation->setText(tr("&Set annotation..."));
|
||||
QStringList counterColors;
|
||||
counterColors.append(tr("red"));
|
||||
counterColors.append(tr("yellow"));
|
||||
counterColors.append(tr("green"));
|
||||
for (int i = 0; i < aAddCounter.size(); ++i)
|
||||
aAddCounter[i]->setText(tr("&Add counter (%1)").arg(counterColors[i]));
|
||||
for (int i = 0; i < aRemoveCounter.size(); ++i)
|
||||
aRemoveCounter[i]->setText(tr("&Remove counter (%1)").arg(counterColors[i]));
|
||||
for (int i = 0; i < aSetCounter.size(); ++i)
|
||||
aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(counterColors[i]));
|
||||
aMoveToTopLibrary->setText(tr("&top of library"));
|
||||
aMoveToBottomLibrary->setText(tr("&bottom of library"));
|
||||
aMoveToGraveyard->setText(tr("&graveyard"));
|
||||
aMoveToGraveyard->setShortcut(tr("Ctrl+Del"));
|
||||
aMoveToExile->setText(tr("&exile"));
|
||||
|
||||
moveMenu->setTitle(tr("&Move to"));
|
||||
}
|
||||
|
||||
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
|
|
@ -263,6 +290,8 @@ void CardItem::setAttachedTo(CardItem *_attachedTo)
|
|||
|
||||
if (zone)
|
||||
zone->reorganizeCards();
|
||||
|
||||
updateCardMenu();
|
||||
}
|
||||
|
||||
void CardItem::resetState()
|
||||
|
|
@ -376,7 +405,7 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
||||
void CardItem::playCard(QGraphicsSceneMouseEvent *event)
|
||||
void CardItem::playCard(bool faceDown)
|
||||
{
|
||||
// Do nothing if the card belongs to another player
|
||||
if (!owner->getLocal())
|
||||
|
|
@ -385,22 +414,19 @@ void CardItem::playCard(QGraphicsSceneMouseEvent *event)
|
|||
TableZone *tz = qobject_cast<TableZone *>(zone);
|
||||
if (tz)
|
||||
tz->toggleTapped();
|
||||
else {
|
||||
bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
||||
bool tapped = info->getCipt();
|
||||
|
||||
zone->getPlayer()->playCard(this, faceDown, tapped);
|
||||
}
|
||||
else
|
||||
zone->getPlayer()->playCard(this, faceDown, info->getCipt());
|
||||
}
|
||||
|
||||
void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::RightButton) {
|
||||
if (cardMenu)
|
||||
cardMenu->exec(event->screenPos());
|
||||
if (!cardMenu->isEmpty())
|
||||
cardMenu->exec(event->screenPos());
|
||||
} else if ((event->button() == Qt::LeftButton) && !settingsCache->getDoubleClickToPlay()) {
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
playCard(event);
|
||||
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
|
||||
}
|
||||
|
||||
AbstractCardItem::mouseReleaseEvent(event);
|
||||
|
|
@ -409,7 +435,7 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (settingsCache->getDoubleClickToPlay())
|
||||
playCard(event);
|
||||
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
|
||||
event->accept();
|
||||
}
|
||||
|
||||
|
|
@ -423,3 +449,38 @@ QVariant CardItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
|||
}
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void CardItem::cardMenuAction()
|
||||
{
|
||||
owner->cardMenuAction(static_cast<QAction *>(sender()));
|
||||
}
|
||||
|
||||
void CardItem::actAttach()
|
||||
{
|
||||
owner->actAttach(static_cast<QAction *>(sender()));
|
||||
}
|
||||
|
||||
void CardItem::actUnattach()
|
||||
{
|
||||
owner->actUnattach(static_cast<QAction *>(sender()));
|
||||
}
|
||||
|
||||
void CardItem::actSetPT()
|
||||
{
|
||||
owner->actSetPT(static_cast<QAction *>(sender()));
|
||||
}
|
||||
|
||||
void CardItem::actSetAnnotation()
|
||||
{
|
||||
owner->actSetAnnotation(static_cast<QAction *>(sender()));
|
||||
}
|
||||
|
||||
void CardItem::actCardCounterTrigger()
|
||||
{
|
||||
owner->actCardCounterTrigger(static_cast<QAction *>(sender()));
|
||||
}
|
||||
|
||||
void CardItem::actPlay()
|
||||
{
|
||||
playCard(false);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue