mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-25 16:13:54 -07:00
[Game] Move graphics out of game and into game_graphics (#6928)
* [Game][Player] Pull out graphics_items out of player_logic Took 25 seconds Took 9 minutes * [Game] Move graphics files into game_graphics Took 1 minute Took 2 minutes Took 23 seconds Took 1 minute Took 2 seconds * Include. Took 4 minutes Took 3 minutes Took 4 minutes Took 1 minute Took 3 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
571da4f1c6
commit
3441be422e
116 changed files with 208 additions and 192 deletions
|
|
@ -1,28 +0,0 @@
|
|||
/**
|
||||
* @file card_menu_action_type.h
|
||||
* @ingroup GameMenusPlayers
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_CARD_MENU_ACTION_TYPE_H
|
||||
#define COCKATRICE_CARD_MENU_ACTION_TYPE_H
|
||||
|
||||
enum CardMenuActionType
|
||||
{
|
||||
// Per-card attribute actions (must be <= cmClone for cardMenuAction() dispatch)
|
||||
cmTap,
|
||||
cmUntap,
|
||||
cmDoesntUntap,
|
||||
cmFlip,
|
||||
cmPeek,
|
||||
cmClone,
|
||||
// Move actions (must be > cmClone for cardMenuAction() dispatch)
|
||||
cmMoveToTopLibrary,
|
||||
cmMoveToBottomLibrary,
|
||||
cmMoveToHand,
|
||||
cmMoveToGraveyard,
|
||||
cmMoveToExile,
|
||||
cmMoveToTable
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_CARD_MENU_ACTION_TYPE_H
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* @file abstract_player_component.h
|
||||
* @ingroup GameMenusPlayers
|
||||
* @brief Polymorphic interface for player-bound UI components managed by PlayerMenu.
|
||||
*/
|
||||
|
||||
#ifndef COCKATRICE_ABSTRACT_PLAYER_COMPONENT_H
|
||||
#define COCKATRICE_ABSTRACT_PLAYER_COMPONENT_H
|
||||
|
||||
/**
|
||||
* @brief Interface for player-bound UI components that need shortcut and translation lifecycle management.
|
||||
*
|
||||
* Not a QObject — avoids diamond inheritance with Qt's MOC. Each concrete component
|
||||
* inherits QObject through its Qt base class (QMenu, TearOffMenu, QGraphicsItem, etc.)
|
||||
* and this interface through regular multiple inheritance.
|
||||
*/
|
||||
class AbstractPlayerComponent
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractPlayerComponent() = default;
|
||||
|
||||
/** @brief Bind keyboard shortcuts. Called when this player gains focus. */
|
||||
virtual void setShortcutsActive() = 0;
|
||||
|
||||
/** @brief Unbind keyboard shortcuts. Called when this player loses focus. */
|
||||
virtual void setShortcutsInactive() = 0;
|
||||
|
||||
/** @brief Retranslate all user-visible strings. Called on language change. */
|
||||
virtual void retranslateUi() = 0;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_ABSTRACT_PLAYER_COMPONENT_H
|
||||
|
|
@ -1,551 +0,0 @@
|
|||
#include "card_menu.h"
|
||||
|
||||
#include "../../../client/settings/card_counter_settings.h"
|
||||
#include "../../../interface/widgets/tabs/tab_game.h"
|
||||
#include "../../board/card_item.h"
|
||||
#include "../../zones/view_zone_logic.h"
|
||||
#include "../card_menu_action_type.h"
|
||||
#include "../player_actions.h"
|
||||
#include "../player_graphics_item.h"
|
||||
#include "../player_logic.h"
|
||||
#include "move_menu.h"
|
||||
#include "pt_menu.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
#include <libcockatrice/card/relation/card_relation.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
/**
|
||||
* @brief Creates a circular icon filled with the specified color.
|
||||
*/
|
||||
static QIcon createCircleIcon(const QColor &color)
|
||||
{
|
||||
QPixmap pixmap(32, 32);
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(color);
|
||||
painter.drawEllipse(pixmap.rect());
|
||||
|
||||
return QIcon(pixmap);
|
||||
}
|
||||
|
||||
template <typename Slot>
|
||||
static QAction *makeAction(QObject *parent, Slot &&slot, bool checkable = false, bool checked = false)
|
||||
{
|
||||
auto *a = new QAction(parent);
|
||||
a->setCheckable(checkable);
|
||||
if (checkable) {
|
||||
a->setChecked(checked);
|
||||
}
|
||||
QObject::connect(a, &QAction::triggered, parent, std::forward<Slot>(slot));
|
||||
return a;
|
||||
}
|
||||
|
||||
CardMenu::CardMenu(PlayerGraphicsItem *_player, const CardItem *_card, bool _shortcutsActive)
|
||||
: player(_player), card(_card), shortcutsActive(_shortcutsActive)
|
||||
{
|
||||
const QList<PlayerLogic *> &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values();
|
||||
|
||||
for (auto playerToAdd : players) {
|
||||
if (playerToAdd == player->getLogic()) {
|
||||
continue;
|
||||
}
|
||||
playersInfo.append(qMakePair(playerToAdd->getPlayerInfo()->getName(), playerToAdd->getPlayerInfo()->getId()));
|
||||
}
|
||||
|
||||
connect(player->getLogic()->getGame()->getPlayerManager(), &PlayerManager::playerRemoved, this,
|
||||
&CardMenu::removePlayer);
|
||||
|
||||
auto *actions = player->getLogic()->getPlayerActions();
|
||||
auto *gameScene = player->getGameScene();
|
||||
|
||||
// Single selection resolver used by all lambdas — called at trigger time
|
||||
auto sel = [gameScene]() { return gameScene->selectedCards(); };
|
||||
|
||||
// Unified dispatcher for card menu actions
|
||||
auto invoke = [actions, sel](CardMenuActionType type) {
|
||||
return [actions, sel, type]() { actions->cardMenuAction(sel(), type); };
|
||||
};
|
||||
|
||||
// Actions using invoke (type dispatch, need selection)
|
||||
aTap = makeAction(this, invoke(cmTap));
|
||||
aDoesntUntap = makeAction(this, invoke(cmDoesntUntap), /*checkable=*/true, card && card->getDoesntUntap());
|
||||
aFlip = makeAction(this, invoke(cmFlip));
|
||||
aPeek = makeAction(this, invoke(cmPeek));
|
||||
aClone = makeAction(this, invoke(cmClone));
|
||||
|
||||
// Actions using selection directly
|
||||
aUnattach = makeAction(this, [actions, sel]() { actions->actUnattach(sel()); });
|
||||
aSetAnnotation = makeAction(this, [actions, sel]() { actions->actRequestSetAnnotationDialog(sel()); });
|
||||
aPlay = makeAction(this, [actions, sel]() { actions->actPlay(sel()); });
|
||||
aPlayFacedown = makeAction(this, [actions, sel]() { actions->actPlayFacedown(sel()); });
|
||||
aHide = makeAction(this, [actions, sel]() { actions->actHide(sel()); });
|
||||
aReduceLifeByPower = makeAction(this, [actions, sel]() { actions->actReduceLifeByPower(sel()); });
|
||||
|
||||
// Actions that use activeCard, not selection — direct connection
|
||||
aAttach = new QAction(this);
|
||||
aDrawArrow = new QAction(this);
|
||||
aSelectAll = new QAction(this);
|
||||
aSelectRow = new QAction(this);
|
||||
aSelectColumn = new QAction(this);
|
||||
|
||||
connect(aAttach, &QAction::triggered, actions, &PlayerActions::actAttach);
|
||||
connect(aDrawArrow, &QAction::triggered, actions, &PlayerActions::actDrawArrow);
|
||||
connect(aSelectAll, &QAction::triggered, actions, &PlayerActions::actSelectAll);
|
||||
connect(aSelectRow, &QAction::triggered, actions, &PlayerActions::actSelectRow);
|
||||
connect(aSelectColumn, &QAction::triggered, actions, &PlayerActions::actSelectColumn);
|
||||
|
||||
aRevealToAll = new QAction(this);
|
||||
|
||||
mCardCounters = new QMenu;
|
||||
|
||||
// Card counters
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
QColor color = SettingsCache::instance().cardCounters().color(i);
|
||||
QIcon circleIcon = createCircleIcon(color);
|
||||
|
||||
auto *addAction = makeAction(this, [actions, sel, i]() { actions->actAddCardCounter(sel(), i); });
|
||||
addAction->setIcon(circleIcon);
|
||||
aAddCounter.append(addAction);
|
||||
|
||||
auto *removeAction = makeAction(this, [actions, sel, i]() { actions->actRemoveCardCounter(sel(), i); });
|
||||
removeAction->setIcon(circleIcon);
|
||||
aRemoveCounter.append(removeAction);
|
||||
|
||||
auto *setAction = makeAction(this, [actions, sel, i]() { actions->actRequestSetCardCounterDialog(sel(), i); });
|
||||
setAction->setIcon(circleIcon);
|
||||
aSetCounter.append(setAction);
|
||||
}
|
||||
|
||||
setShortcutsActive();
|
||||
|
||||
retranslateUi();
|
||||
|
||||
if (card == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool revealedCard = false;
|
||||
bool writeableCard = player->getLogic()->getPlayerInfo()->getLocalOrJudge();
|
||||
if (auto *view = qobject_cast<ZoneViewZoneLogic *>(card->getZone())) {
|
||||
if (view->getRevealZone()) {
|
||||
if (view->getWriteableRevealZone()) {
|
||||
writeableCard = true;
|
||||
} else {
|
||||
revealedCard = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (revealedCard) {
|
||||
addAction(aHide);
|
||||
addSeparator();
|
||||
addAction(aClone);
|
||||
addSeparator();
|
||||
addAction(aSelectAll);
|
||||
addAction(aSelectColumn);
|
||||
addRelatedCardView();
|
||||
} else {
|
||||
if (card->getZone()) {
|
||||
if (card->getZone()->getName() == ZoneNames::TABLE) {
|
||||
createTableMenu(writeableCard);
|
||||
} else if (card->getZone()->getName() == ZoneNames::STACK) {
|
||||
createStackMenu(writeableCard);
|
||||
} else if (card->getZone()->getName() == ZoneNames::EXILE ||
|
||||
card->getZone()->getName() == ZoneNames::GRAVE) {
|
||||
createGraveyardOrExileMenu(writeableCard);
|
||||
} else {
|
||||
createHandOrCustomZoneMenu(writeableCard);
|
||||
}
|
||||
} else {
|
||||
createZonelessMenu(writeableCard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CardMenu::removePlayer(PlayerLogic *playerToRemove)
|
||||
{
|
||||
for (auto it = playersInfo.begin(); it != playersInfo.end();) {
|
||||
if (it->second == playerToRemove->getPlayerInfo()->getId()) {
|
||||
it = playersInfo.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CardMenu::createTableMenu(bool canModifyCard)
|
||||
{
|
||||
// Card is on the battlefield
|
||||
if (!canModifyCard) {
|
||||
addAction(aDrawArrow);
|
||||
addSeparator();
|
||||
addAction(aClone);
|
||||
addSeparator();
|
||||
addAction(aReduceLifeByPower);
|
||||
addSeparator();
|
||||
addAction(aSelectAll);
|
||||
addAction(aSelectRow);
|
||||
addRelatedCardView();
|
||||
addRelatedCardActions();
|
||||
return;
|
||||
}
|
||||
|
||||
addAction(aTap);
|
||||
addAction(aDoesntUntap);
|
||||
addAction(aFlip);
|
||||
if (card->getFaceDown()) {
|
||||
addAction(aPeek);
|
||||
}
|
||||
addSeparator();
|
||||
addAction(aClone);
|
||||
addMenu(new MoveMenu(player));
|
||||
addSeparator();
|
||||
addAction(aAttach);
|
||||
if (card->getAttachedTo()) {
|
||||
addAction(aUnattach);
|
||||
}
|
||||
addAction(aDrawArrow);
|
||||
addSeparator();
|
||||
addMenu(new PtMenu(player));
|
||||
addAction(aSetAnnotation);
|
||||
addSeparator();
|
||||
addAction(aReduceLifeByPower);
|
||||
addSeparator();
|
||||
addAction(aSelectAll);
|
||||
addAction(aSelectRow);
|
||||
|
||||
addSeparator();
|
||||
mCardCounters->clear();
|
||||
for (int i = 0; i < aAddCounter.size(); ++i) {
|
||||
mCardCounters->addSeparator();
|
||||
mCardCounters->addAction(aAddCounter[i]);
|
||||
if (card->getCounters().contains(i)) {
|
||||
mCardCounters->addAction(aRemoveCounter[i]);
|
||||
}
|
||||
mCardCounters->addAction(aSetCounter[i]);
|
||||
}
|
||||
addSeparator();
|
||||
addMenu(mCardCounters);
|
||||
addRelatedCardView();
|
||||
addRelatedCardActions();
|
||||
}
|
||||
|
||||
void CardMenu::createStackMenu(bool canModifyCard)
|
||||
{
|
||||
// Card is on the stack
|
||||
if (!canModifyCard) {
|
||||
addAction(aDrawArrow);
|
||||
addSeparator();
|
||||
addAction(aClone);
|
||||
addSeparator();
|
||||
addAction(aSelectAll);
|
||||
addRelatedCardView();
|
||||
addRelatedCardActions();
|
||||
return;
|
||||
}
|
||||
|
||||
addAction(aPlay);
|
||||
addAction(aPlayFacedown);
|
||||
addSeparator();
|
||||
addAction(aClone);
|
||||
addMenu(new MoveMenu(player));
|
||||
addSeparator();
|
||||
addAction(aAttach);
|
||||
addAction(aDrawArrow);
|
||||
addSeparator();
|
||||
addAction(aSelectAll);
|
||||
addRelatedCardView();
|
||||
addRelatedCardActions();
|
||||
}
|
||||
|
||||
void CardMenu::createGraveyardOrExileMenu(bool canModifyCard)
|
||||
{
|
||||
// Card is in the graveyard or exile
|
||||
if (!canModifyCard) {
|
||||
addAction(aDrawArrow);
|
||||
addSeparator();
|
||||
addAction(aClone);
|
||||
addSeparator();
|
||||
addAction(aSelectAll);
|
||||
addAction(aSelectColumn);
|
||||
addRelatedCardView();
|
||||
addRelatedCardActions();
|
||||
return;
|
||||
}
|
||||
|
||||
addAction(aPlay);
|
||||
addAction(aPlayFacedown);
|
||||
addSeparator();
|
||||
addAction(aClone);
|
||||
addMenu(new MoveMenu(player));
|
||||
addSeparator();
|
||||
addAction(aAttach);
|
||||
addAction(aDrawArrow);
|
||||
addSeparator();
|
||||
addAction(aSelectAll);
|
||||
addAction(aSelectColumn);
|
||||
addRelatedCardView();
|
||||
addRelatedCardActions();
|
||||
}
|
||||
|
||||
void CardMenu::createHandOrCustomZoneMenu(bool canModifyCard)
|
||||
{
|
||||
if (!canModifyCard) {
|
||||
addAction(aDrawArrow);
|
||||
addSeparator();
|
||||
addAction(aClone);
|
||||
addSeparator();
|
||||
addAction(aSelectAll);
|
||||
addRelatedCardView();
|
||||
addRelatedCardActions();
|
||||
return;
|
||||
}
|
||||
|
||||
// Card is in hand or a custom zone specified by server
|
||||
addAction(aPlay);
|
||||
addAction(aPlayFacedown);
|
||||
|
||||
QMenu *revealMenu = addMenu(tr("Re&veal to..."));
|
||||
|
||||
initContextualPlayersMenu(revealMenu, aRevealToAll);
|
||||
|
||||
connect(revealMenu, &QMenu::triggered, this, [this](QAction *action) {
|
||||
player->getLogic()->getPlayerActions()->actReveal(player->getGameScene()->selectedCards(), action);
|
||||
});
|
||||
|
||||
addSeparator();
|
||||
addAction(aClone);
|
||||
addMenu(new MoveMenu(player));
|
||||
|
||||
// actions that are really wonky when done from deck or sideboard
|
||||
if (card->getZone()->getName() == ZoneNames::HAND) {
|
||||
addSeparator();
|
||||
addAction(aAttach);
|
||||
addAction(aDrawArrow);
|
||||
}
|
||||
|
||||
addSeparator();
|
||||
addAction(aSelectAll);
|
||||
if (qobject_cast<ZoneViewZoneLogic *>(card->getZone())) {
|
||||
addAction(aSelectColumn);
|
||||
}
|
||||
|
||||
addRelatedCardView();
|
||||
if (card->getZone()->getName() == ZoneNames::HAND) {
|
||||
addRelatedCardActions();
|
||||
}
|
||||
}
|
||||
|
||||
void CardMenu::createZonelessMenu(bool canModifyCard)
|
||||
{
|
||||
if (canModifyCard) {
|
||||
addMenu(new MoveMenu(player));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Populates the menu with an action for each active player.
|
||||
*
|
||||
* The "all players" action is created separately, so it has to be passed into this function.
|
||||
* It will be put at the top of the menu.
|
||||
*
|
||||
* @param menu The menu to add the player actions to.
|
||||
* @param allPlayersAction The action for "all players".
|
||||
*/
|
||||
void CardMenu::initContextualPlayersMenu(QMenu *menu, QAction *allPlayersAction)
|
||||
{
|
||||
allPlayersAction->setData(-1);
|
||||
menu->addAction(allPlayersAction);
|
||||
menu->addSeparator();
|
||||
|
||||
for (const auto &playerInfo : playersInfo) {
|
||||
menu->addAction(playerInfo.first)->setData(playerInfo.second);
|
||||
}
|
||||
}
|
||||
|
||||
void CardMenu::addRelatedCardView()
|
||||
{
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
auto exactCard = card->getCard();
|
||||
if (!exactCard) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool atLeastOneGoodRelationFound = false;
|
||||
QList<CardRelation *> relatedCards = exactCard.getInfo().getAllRelatedCards();
|
||||
for (const CardRelation *cardRelation : relatedCards) {
|
||||
CardInfoPtr relatedCard = CardDatabaseManager::query()->getCardInfo(cardRelation->getName());
|
||||
if (relatedCard != nullptr) {
|
||||
atLeastOneGoodRelationFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!atLeastOneGoodRelationFound) {
|
||||
return;
|
||||
}
|
||||
|
||||
addSeparator();
|
||||
auto viewRelatedCards = new QMenu(tr("View related cards"));
|
||||
addMenu(viewRelatedCards);
|
||||
for (const CardRelation *relatedCard : relatedCards) {
|
||||
QString relatedCardName = relatedCard->getName();
|
||||
CardRef cardRef = {relatedCardName, exactCard.getPrinting().getUuid()};
|
||||
QAction *viewCard = viewRelatedCards->addAction(relatedCardName);
|
||||
Q_UNUSED(viewCard);
|
||||
|
||||
connect(viewCard, &QAction::triggered, this, [this, cardRef] { emit cardInfoRequested(cardRef); });
|
||||
}
|
||||
}
|
||||
|
||||
void CardMenu::addRelatedCardActions()
|
||||
{
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
auto exactCard = card->getCard();
|
||||
if (!exactCard) {
|
||||
return;
|
||||
}
|
||||
|
||||
QList<CardRelation *> relatedCards = exactCard.getInfo().getAllRelatedCards();
|
||||
if (relatedCards.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
addSeparator();
|
||||
int index = 0;
|
||||
QAction *createRelatedCards = nullptr;
|
||||
for (const CardRelation *cardRelation : relatedCards) {
|
||||
ExactCard relatedCard =
|
||||
CardDatabaseManager::query()->getCardFromSameSet(cardRelation->getName(), card->getCard().getPrinting());
|
||||
if (!relatedCard) {
|
||||
relatedCard = CardDatabaseManager::query()->getCard({cardRelation->getName()});
|
||||
}
|
||||
if (!relatedCard) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString relatedCardName;
|
||||
if (relatedCard.getInfo().getPowTough().size() > 0) {
|
||||
relatedCardName = relatedCard.getInfo().getPowTough() + " " + relatedCard.getName(); // "n/n name"
|
||||
} else {
|
||||
relatedCardName = relatedCard.getName(); // "name"
|
||||
}
|
||||
|
||||
QString text = tr("Token: ");
|
||||
if (cardRelation->getDoesAttach()) {
|
||||
text +=
|
||||
tr(cardRelation->getDoesTransform() ? "Transform into " : "Attach to ") + "\"" + relatedCardName + "\"";
|
||||
} else if (cardRelation->getIsVariable()) {
|
||||
text += "X " + relatedCardName;
|
||||
} else if (cardRelation->getDefaultCount() != 1) {
|
||||
text += QString::number(cardRelation->getDefaultCount()) + "x " + relatedCardName;
|
||||
} else {
|
||||
text += relatedCardName;
|
||||
}
|
||||
|
||||
if (createRelatedCards == nullptr) {
|
||||
if (relatedCards.length() == 1) {
|
||||
createRelatedCards = new QAction(text, this); // set actCreateAllRelatedCards with this text
|
||||
break; // do not set an individual entry as there is only one entry
|
||||
} else {
|
||||
createRelatedCards = new QAction(tr("All tokens"), this);
|
||||
}
|
||||
}
|
||||
|
||||
auto *createRelated = new QAction(text, this);
|
||||
createRelated->setData(QVariant(index++));
|
||||
connect(createRelated, &QAction::triggered, player->getLogic()->getPlayerActions(),
|
||||
&PlayerActions::actCreateRelatedCard);
|
||||
addAction(createRelated);
|
||||
}
|
||||
|
||||
if (createRelatedCards) {
|
||||
if (shortcutsActive) {
|
||||
createRelatedCards->setShortcuts(
|
||||
SettingsCache::instance().shortcuts().getShortcut("Player/aCreateRelatedTokens"));
|
||||
}
|
||||
connect(createRelatedCards, &QAction::triggered, player->getLogic()->getPlayerActions(),
|
||||
&PlayerActions::actCreateAllRelatedCards);
|
||||
addAction(createRelatedCards);
|
||||
}
|
||||
}
|
||||
|
||||
void CardMenu::retranslateUi()
|
||||
{
|
||||
aSelectAll->setText(tr("&Select All"));
|
||||
aSelectRow->setText(tr("S&elect Row"));
|
||||
aSelectColumn->setText(tr("S&elect Column"));
|
||||
|
||||
aPlay->setText(tr("&Play"));
|
||||
aHide->setText(tr("&Hide"));
|
||||
aPlayFacedown->setText(tr("Play &Face Down"));
|
||||
aRevealToAll->setText(tr("&All players"));
|
||||
//: Turn sideways or back again
|
||||
aTap->setText(tr("&Tap / Untap"));
|
||||
aDoesntUntap->setText(tr("Skip &untapping"));
|
||||
//: Turn face up/face down
|
||||
aFlip->setText(tr("T&urn Over")); // Only the user facing names in client got renamed to "turn over"
|
||||
// All code and proto bits are still unchanged (flip) for compatibility reasons
|
||||
// A protocol rewrite with v3 could incorporate that, see #3100
|
||||
aPeek->setText(tr("&Peek at card face"));
|
||||
aClone->setText(tr("&Clone"));
|
||||
aAttach->setText(tr("Attac&h to card..."));
|
||||
aUnattach->setText(tr("Unattac&h"));
|
||||
aDrawArrow->setText(tr("&Draw arrow..."));
|
||||
aSetAnnotation->setText(tr("&Set annotation..."));
|
||||
aReduceLifeByPower->setText(tr("Reduce life by power"));
|
||||
|
||||
mCardCounters->setTitle(tr("Ca&rd counters"));
|
||||
|
||||
auto &cardCounterSettings = SettingsCache::instance().cardCounters();
|
||||
|
||||
for (int i = 0; i < aAddCounter.size(); ++i) {
|
||||
aAddCounter[i]->setText(tr("&Add counter (%1)").arg(cardCounterSettings.displayName(i)));
|
||||
}
|
||||
for (int i = 0; i < aRemoveCounter.size(); ++i) {
|
||||
aRemoveCounter[i]->setText(tr("&Remove counter (%1)").arg(cardCounterSettings.displayName(i)));
|
||||
}
|
||||
for (int i = 0; i < aSetCounter.size(); ++i) {
|
||||
aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(cardCounterSettings.displayName(i)));
|
||||
}
|
||||
}
|
||||
|
||||
void CardMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
||||
aHide->setShortcuts(shortcuts.getShortcut("Player/aHide"));
|
||||
aPlay->setShortcuts(shortcuts.getShortcut("Player/aPlay"));
|
||||
aPlayFacedown->setShortcuts(shortcuts.getShortcut("Player/aPlayFacedown"));
|
||||
aRevealToAll->setShortcuts(shortcuts.getShortcut("Player/aRevealToAll"));
|
||||
|
||||
aTap->setShortcuts(shortcuts.getShortcut("Player/aTap"));
|
||||
aDoesntUntap->setShortcuts(shortcuts.getShortcut("Player/aDoesntUntap"));
|
||||
aFlip->setShortcuts(shortcuts.getShortcut("Player/aFlip"));
|
||||
aPeek->setShortcuts(shortcuts.getShortcut("Player/aPeek"));
|
||||
aClone->setShortcuts(shortcuts.getShortcut("Player/aClone"));
|
||||
aAttach->setShortcuts(shortcuts.getShortcut("Player/aAttach"));
|
||||
aUnattach->setShortcuts(shortcuts.getShortcut("Player/aUnattach"));
|
||||
aDrawArrow->setShortcuts(shortcuts.getShortcut("Player/aDrawArrow"));
|
||||
aSetAnnotation->setShortcuts(shortcuts.getShortcut("Player/aSetAnnotation"));
|
||||
aReduceLifeByPower->setShortcuts(shortcuts.getShortcut("Player/aReduceLifeByPower"));
|
||||
|
||||
aSelectAll->setShortcuts(shortcuts.getShortcut("Player/aSelectAll"));
|
||||
aSelectRow->setShortcuts(shortcuts.getShortcut("Player/aSelectRow"));
|
||||
aSelectColumn->setShortcuts(shortcuts.getShortcut("Player/aSelectColumn"));
|
||||
|
||||
static const QStringList colorWords = {"Red", "Yellow", "Green", "Cyan", "Purple", "Magenta"};
|
||||
for (int i = 0; i < aAddCounter.size(); i++) {
|
||||
aAddCounter[i]->setShortcuts(shortcuts.getShortcut("Player/aCC" + colorWords[i]));
|
||||
aRemoveCounter[i]->setShortcuts(shortcuts.getShortcut("Player/aRC" + colorWords[i]));
|
||||
aSetCounter[i]->setShortcuts(shortcuts.getShortcut("Player/aSC" + colorWords[i]));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* @file card_menu.h
|
||||
* @ingroup GameMenusCards
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_CARD_MENU_H
|
||||
#define COCKATRICE_CARD_MENU_H
|
||||
|
||||
#include <QMenu>
|
||||
#include <libcockatrice/utility/card_ref.h>
|
||||
|
||||
class CardItem;
|
||||
class PlayerGraphicsItem;
|
||||
class PlayerLogic;
|
||||
class CardMenu : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void cardInfoRequested(const CardRef &cardRef);
|
||||
|
||||
public:
|
||||
explicit CardMenu(PlayerGraphicsItem *player, const CardItem *card, bool shortcutsActive);
|
||||
void removePlayer(PlayerLogic *playerToRemove);
|
||||
void createTableMenu(bool canModifyCard);
|
||||
void createStackMenu(bool canModifyCard);
|
||||
void createGraveyardOrExileMenu(bool canModifyCard);
|
||||
void createHandOrCustomZoneMenu(bool canModifyCard);
|
||||
void createZonelessMenu(bool canModifyCard);
|
||||
|
||||
QMenu *mCardCounters;
|
||||
|
||||
QAction *aPlay, *aPlayFacedown;
|
||||
QAction *aRevealToAll;
|
||||
QAction *aHide;
|
||||
QAction *aClone;
|
||||
QAction *aSelectAll, *aSelectRow, *aSelectColumn;
|
||||
QAction *aDrawArrow;
|
||||
QAction *aTap, *aDoesntUntap;
|
||||
QAction *aFlip, *aPeek;
|
||||
QAction *aAttach, *aUnattach;
|
||||
QAction *aSetAnnotation;
|
||||
QAction *aReduceLifeByPower;
|
||||
|
||||
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
const CardItem *card;
|
||||
QList<QPair<QString, int>> playersInfo;
|
||||
bool shortcutsActive;
|
||||
|
||||
void addRelatedCardActions();
|
||||
void retranslateUi();
|
||||
void initContextualPlayersMenu(QMenu *menu, QAction *allPlayersAction);
|
||||
void setShortcutsActive();
|
||||
void addRelatedCardView();
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_CARD_MENU_H
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
#include "custom_zone_menu.h"
|
||||
|
||||
#include "../player_logic.h"
|
||||
|
||||
CustomZoneMenu::CustomZoneMenu(PlayerGraphicsItem *_player) : player(_player)
|
||||
{
|
||||
menuAction()->setVisible(false);
|
||||
|
||||
connect(player->getLogic(), &PlayerLogic::clearCustomZonesMenu, this, &CustomZoneMenu::clearCustomZonesMenu);
|
||||
connect(player->getLogic(), &PlayerLogic::addViewCustomZoneActionToCustomZoneMenu, this,
|
||||
&CustomZoneMenu::addViewCustomZoneActionToCustomZoneMenu);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void CustomZoneMenu::retranslateUi()
|
||||
{
|
||||
setTitle(tr("C&ustom Zones"));
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
|
||||
for (auto aViewZone : actions()) {
|
||||
aViewZone->setText(tr("View custom zone '%1'").arg(aViewZone->data().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CustomZoneMenu::clearCustomZonesMenu()
|
||||
{
|
||||
clear();
|
||||
menuAction()->setVisible(false);
|
||||
}
|
||||
|
||||
void CustomZoneMenu::addViewCustomZoneActionToCustomZoneMenu(QString zoneName)
|
||||
{
|
||||
menuAction()->setVisible(true);
|
||||
QAction *aViewZone = addAction(tr("View custom zone '%1'").arg(zoneName));
|
||||
aViewZone->setData(zoneName);
|
||||
connect(aViewZone, &QAction::triggered, this,
|
||||
[zoneName, this]() { player->getGameScene()->toggleZoneView(player->getLogic(), zoneName, -1); });
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/**
|
||||
* @file custom_zone_menu.h
|
||||
* @ingroup GameMenusZones
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_CUSTOM_ZONE_MENU_H
|
||||
#define COCKATRICE_CUSTOM_ZONE_MENU_H
|
||||
|
||||
#include "abstract_player_component.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class CustomZoneMenu : public QMenu, public AbstractPlayerComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CustomZoneMenu(PlayerGraphicsItem *player);
|
||||
void retranslateUi() override;
|
||||
void setShortcutsActive() override
|
||||
{
|
||||
}
|
||||
void setShortcutsInactive() override
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
private slots:
|
||||
void clearCustomZonesMenu();
|
||||
void addViewCustomZoneActionToCustomZoneMenu(QString zoneName);
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_CUSTOM_ZONE_MENU_H
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
#include "grave_menu.h"
|
||||
|
||||
#include "../../abstract_game.h"
|
||||
#include "../player_actions.h"
|
||||
#include "../player_logic.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
GraveyardMenu::GraveyardMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
|
||||
{
|
||||
createMoveActions();
|
||||
createViewActions();
|
||||
|
||||
addAction(aViewGraveyard);
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) {
|
||||
mRevealRandomGraveyardCard = addMenu(QString());
|
||||
connect(mRevealRandomGraveyardCard, &QMenu::aboutToShow, this,
|
||||
&GraveyardMenu::populateRevealRandomMenuWithActivePlayers);
|
||||
|
||||
addSeparator();
|
||||
|
||||
moveGraveMenu = addTearOffMenu(QString());
|
||||
moveGraveMenu->addAction(aMoveGraveToTopLibrary);
|
||||
moveGraveMenu->addAction(aMoveGraveToBottomLibrary);
|
||||
moveGraveMenu->addSeparator();
|
||||
moveGraveMenu->addAction(aMoveGraveToHand);
|
||||
moveGraveMenu->addSeparator();
|
||||
moveGraveMenu->addAction(aMoveGraveToRfg);
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void GraveyardMenu::createMoveActions()
|
||||
{
|
||||
auto grave = player->getLogic()->getGraveZone();
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) {
|
||||
aMoveGraveToTopLibrary = new QAction(this);
|
||||
aMoveGraveToTopLibrary->setData(QList<QVariant>() << ZoneNames::DECK << 0);
|
||||
|
||||
aMoveGraveToBottomLibrary = new QAction(this);
|
||||
aMoveGraveToBottomLibrary->setData(QList<QVariant>() << ZoneNames::DECK << -1);
|
||||
|
||||
aMoveGraveToHand = new QAction(this);
|
||||
aMoveGraveToHand->setData(QList<QVariant>() << ZoneNames::HAND << 0);
|
||||
|
||||
aMoveGraveToRfg = new QAction(this);
|
||||
aMoveGraveToRfg->setData(QList<QVariant>() << ZoneNames::EXILE << 0);
|
||||
|
||||
connect(aMoveGraveToTopLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone);
|
||||
connect(aMoveGraveToBottomLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone);
|
||||
connect(aMoveGraveToHand, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone);
|
||||
connect(aMoveGraveToRfg, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone);
|
||||
}
|
||||
}
|
||||
|
||||
void GraveyardMenu::createViewActions()
|
||||
{
|
||||
PlayerActions *playerActions = player->getLogic()->getPlayerActions();
|
||||
|
||||
aViewGraveyard = new QAction(this);
|
||||
connect(aViewGraveyard, &QAction::triggered, playerActions, &PlayerActions::actViewGraveyard);
|
||||
}
|
||||
|
||||
void GraveyardMenu::populateRevealRandomMenuWithActivePlayers()
|
||||
{
|
||||
mRevealRandomGraveyardCard->clear();
|
||||
|
||||
QAction *allPlayers = mRevealRandomGraveyardCard->addAction(tr("&All players"));
|
||||
allPlayers->setData(-1);
|
||||
connect(allPlayers, &QAction::triggered, this, &GraveyardMenu::onRevealRandomTriggered);
|
||||
|
||||
mRevealRandomGraveyardCard->addSeparator();
|
||||
|
||||
const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player->getLogic()) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealRandomGraveyardCard->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &GraveyardMenu::onRevealRandomTriggered);
|
||||
}
|
||||
}
|
||||
|
||||
void GraveyardMenu::onRevealRandomTriggered()
|
||||
{
|
||||
if (auto *a = qobject_cast<QAction *>(sender())) {
|
||||
player->getLogic()->getPlayerActions()->actRevealRandomGraveyardCard(a->data().toInt());
|
||||
}
|
||||
}
|
||||
|
||||
void GraveyardMenu::retranslateUi()
|
||||
{
|
||||
setTitle(tr("&Graveyard"));
|
||||
|
||||
aViewGraveyard->setText(tr("&View graveyard"));
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
moveGraveMenu->setTitle(tr("&Move graveyard to..."));
|
||||
aMoveGraveToTopLibrary->setText(tr("&Top of library"));
|
||||
aMoveGraveToBottomLibrary->setText(tr("&Bottom of library"));
|
||||
aMoveGraveToHand->setText(tr("&Hand"));
|
||||
aMoveGraveToRfg->setText(tr("&Exile"));
|
||||
|
||||
mRevealRandomGraveyardCard->setTitle(tr("Reveal random card to..."));
|
||||
}
|
||||
}
|
||||
|
||||
void GraveyardMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
aViewGraveyard->setShortcuts(shortcuts.getShortcut("Player/aViewGraveyard"));
|
||||
}
|
||||
|
||||
void GraveyardMenu::setShortcutsInactive()
|
||||
{
|
||||
aViewGraveyard->setShortcut(QKeySequence());
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* @file grave_menu.h
|
||||
* @ingroup GameMenusZones
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_GRAVE_MENU_H
|
||||
#define COCKATRICE_GRAVE_MENU_H
|
||||
|
||||
#include "../../../interface/widgets/menus/tearoff_menu.h"
|
||||
#include "abstract_player_component.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class GraveyardMenu : public TearOffMenu, public AbstractPlayerComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void newPlayerActionCreated(QAction *action);
|
||||
|
||||
public:
|
||||
explicit GraveyardMenu(PlayerGraphicsItem *player, QWidget *parent = nullptr);
|
||||
void createMoveActions();
|
||||
void createViewActions();
|
||||
void populateRevealRandomMenuWithActivePlayers();
|
||||
void onRevealRandomTriggered();
|
||||
void retranslateUi() override;
|
||||
void setShortcutsActive() override;
|
||||
void setShortcutsInactive() override;
|
||||
|
||||
QMenu *mRevealRandomGraveyardCard = nullptr;
|
||||
QMenu *moveGraveMenu = nullptr;
|
||||
|
||||
QAction *aViewGraveyard = nullptr;
|
||||
QAction *aMoveGraveToTopLibrary = nullptr;
|
||||
QAction *aMoveGraveToBottomLibrary = nullptr;
|
||||
QAction *aMoveGraveToHand = nullptr;
|
||||
QAction *aMoveGraveToRfg = nullptr;
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_GRAVE_MENU_H
|
||||
|
|
@ -1,223 +0,0 @@
|
|||
#include "hand_menu.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
#include "../../../client/settings/shortcuts_settings.h"
|
||||
#include "../../../game_graphics/zones/hand_zone.h"
|
||||
#include "../../abstract_game.h"
|
||||
#include "../player_actions.h"
|
||||
#include "../player_graphics_item.h"
|
||||
#include "../player_logic.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
HandMenu::HandMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
|
||||
{
|
||||
auto *actions = player->getLogic()->getPlayerActions();
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) {
|
||||
aViewHand = new QAction(this);
|
||||
|
||||
connect(aViewHand, &QAction::triggered, actions, &PlayerActions::actViewHand);
|
||||
addAction(aViewHand);
|
||||
|
||||
mSortHand = addMenu(QString());
|
||||
|
||||
aSortHandByName = new QAction(this);
|
||||
aSortHandByName->setData(CardList::SortByName);
|
||||
aSortHandByType = new QAction(this);
|
||||
aSortHandByType->setData(CardList::SortByMainType);
|
||||
aSortHandByManaValue = new QAction(this);
|
||||
aSortHandByManaValue->setData(CardList::SortByManaValue);
|
||||
|
||||
connect(aSortHandByType, &QAction::triggered, actions, &PlayerActions::actSortHand);
|
||||
connect(aSortHandByName, &QAction::triggered, actions, &PlayerActions::actSortHand);
|
||||
connect(aSortHandByManaValue, &QAction::triggered, actions, &PlayerActions::actSortHand);
|
||||
|
||||
mSortHand->addAction(aSortHandByName);
|
||||
mSortHand->addAction(aSortHandByType);
|
||||
mSortHand->addAction(aSortHandByManaValue);
|
||||
}
|
||||
|
||||
mRevealHand = addMenu(QString());
|
||||
connect(mRevealHand, &QMenu::aboutToShow, this, &HandMenu::populateRevealHandMenuWithActivePlayers);
|
||||
|
||||
aRevealHandToAll = new QAction(this);
|
||||
aRevealHandToAll->setData(-1);
|
||||
connect(aRevealHandToAll, &QAction::triggered, this, &HandMenu::onRevealHandTriggered);
|
||||
|
||||
mRevealRandomHandCard = addMenu(QString());
|
||||
connect(mRevealRandomHandCard, &QMenu::aboutToShow, this,
|
||||
&HandMenu::populateRevealRandomHandCardMenuWithActivePlayers);
|
||||
|
||||
aRevealRandomHandCardToAll = new QAction(this);
|
||||
aRevealRandomHandCardToAll->setData(-1);
|
||||
connect(aRevealRandomHandCardToAll, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardTriggered);
|
||||
|
||||
// We still need to add these actions to menu here so that the shortcuts are active right away
|
||||
mRevealHand->addAction(aRevealHandToAll);
|
||||
mRevealRandomHandCard->addAction(aRevealRandomHandCardToAll);
|
||||
|
||||
addSeparator();
|
||||
|
||||
aMulligan = new QAction(this);
|
||||
connect(aMulligan, &QAction::triggered, actions, &PlayerActions::actRequestMulliganDialog);
|
||||
addAction(aMulligan);
|
||||
|
||||
// Mulligan same size
|
||||
aMulliganSame = new QAction(this);
|
||||
connect(aMulliganSame, &QAction::triggered, actions, &PlayerActions::actMulliganSameSize);
|
||||
addAction(aMulliganSame);
|
||||
|
||||
// Mulligan -1
|
||||
aMulliganMinusOne = new QAction(this);
|
||||
connect(aMulliganMinusOne, &QAction::triggered, actions, &PlayerActions::actMulliganMinusOne);
|
||||
addAction(aMulliganMinusOne);
|
||||
|
||||
addSeparator();
|
||||
|
||||
mMoveHandMenu = addTearOffMenu(QString());
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) {
|
||||
aMoveHandToTopLibrary = new QAction(this);
|
||||
aMoveHandToTopLibrary->setData(QList<QVariant>() << ZoneNames::DECK << 0);
|
||||
aMoveHandToBottomLibrary = new QAction(this);
|
||||
aMoveHandToBottomLibrary->setData(QList<QVariant>() << ZoneNames::DECK << -1);
|
||||
aMoveHandToGrave = new QAction(this);
|
||||
aMoveHandToGrave->setData(QList<QVariant>() << ZoneNames::GRAVE << 0);
|
||||
aMoveHandToRfg = new QAction(this);
|
||||
aMoveHandToRfg->setData(QList<QVariant>() << ZoneNames::EXILE << 0);
|
||||
|
||||
auto hand = player->getLogic()->getHandZone();
|
||||
|
||||
connect(aMoveHandToTopLibrary, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone);
|
||||
connect(aMoveHandToBottomLibrary, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone);
|
||||
connect(aMoveHandToGrave, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone);
|
||||
connect(aMoveHandToRfg, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone);
|
||||
|
||||
mMoveHandMenu->addAction(aMoveHandToTopLibrary);
|
||||
mMoveHandMenu->addAction(aMoveHandToBottomLibrary);
|
||||
mMoveHandMenu->addSeparator();
|
||||
mMoveHandMenu->addAction(aMoveHandToGrave);
|
||||
mMoveHandMenu->addSeparator();
|
||||
mMoveHandMenu->addAction(aMoveHandToRfg);
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void HandMenu::retranslateUi()
|
||||
{
|
||||
setTitle(tr("&Hand"));
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aViewHand->setText(tr("&View hand"));
|
||||
|
||||
mSortHand->setTitle(tr("Sort hand by..."));
|
||||
aSortHandByName->setText(tr("Name"));
|
||||
aSortHandByType->setText(tr("Type"));
|
||||
aSortHandByManaValue->setText(tr("Mana Value"));
|
||||
|
||||
aMulligan->setText(tr("Take &mulligan (Choose hand size)"));
|
||||
aMulliganSame->setText(tr("Take mulligan (Same hand size)"));
|
||||
aMulliganMinusOne->setText(tr("Take mulligan (Hand size - 1)"));
|
||||
|
||||
mMoveHandMenu->setTitle(tr("&Move hand to..."));
|
||||
aMoveHandToTopLibrary->setText(tr("&Top of library"));
|
||||
aMoveHandToBottomLibrary->setText(tr("&Bottom of library"));
|
||||
aMoveHandToGrave->setText(tr("&Graveyard"));
|
||||
aMoveHandToRfg->setText(tr("&Exile"));
|
||||
|
||||
mRevealHand->setTitle(tr("&Reveal hand to..."));
|
||||
aRevealHandToAll->setText(tr("All players"));
|
||||
|
||||
mRevealRandomHandCard->setTitle(tr("Reveal r&andom card to..."));
|
||||
aRevealRandomHandCardToAll->setText(tr("All players"));
|
||||
}
|
||||
}
|
||||
|
||||
void HandMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
aViewHand->setShortcuts(shortcuts.getShortcut("Player/aViewHand"));
|
||||
aSortHandByName->setShortcuts(shortcuts.getShortcut("Player/aSortHandByName"));
|
||||
aSortHandByType->setShortcuts(shortcuts.getShortcut("Player/aSortHandByType"));
|
||||
aSortHandByManaValue->setShortcuts(shortcuts.getShortcut("Player/aSortHandByManaValue"));
|
||||
aMulligan->setShortcuts(shortcuts.getShortcut("Player/aMulligan"));
|
||||
aMulliganSame->setShortcuts(shortcuts.getShortcut("Player/aMulliganSame"));
|
||||
aMulliganMinusOne->setShortcuts(shortcuts.getShortcut("Player/aMulliganMinusOne"));
|
||||
aRevealHandToAll->setShortcuts(shortcuts.getShortcut("Player/aRevealHandToAll"));
|
||||
aRevealRandomHandCardToAll->setShortcuts(shortcuts.getShortcut("Player/aRevealRandomHandCardToAll"));
|
||||
}
|
||||
|
||||
void HandMenu::setShortcutsInactive()
|
||||
{
|
||||
aViewHand->setShortcut(QKeySequence());
|
||||
aSortHandByName->setShortcut(QKeySequence());
|
||||
aSortHandByType->setShortcut(QKeySequence());
|
||||
aSortHandByManaValue->setShortcut(QKeySequence());
|
||||
aMulligan->setShortcut(QKeySequence());
|
||||
aRevealHandToAll->setShortcut(QKeySequence());
|
||||
aRevealRandomHandCardToAll->setShortcut(QKeySequence());
|
||||
}
|
||||
|
||||
void HandMenu::populateRevealHandMenuWithActivePlayers()
|
||||
{
|
||||
mRevealHand->clear();
|
||||
|
||||
mRevealHand->addAction(aRevealHandToAll);
|
||||
|
||||
mRevealHand->addSeparator();
|
||||
|
||||
const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player->getLogic()) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealHand->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &HandMenu::onRevealHandTriggered);
|
||||
}
|
||||
}
|
||||
|
||||
void HandMenu::populateRevealRandomHandCardMenuWithActivePlayers()
|
||||
{
|
||||
mRevealRandomHandCard->clear();
|
||||
|
||||
mRevealRandomHandCard->addAction(aRevealRandomHandCardToAll);
|
||||
|
||||
mRevealRandomHandCard->addSeparator();
|
||||
|
||||
const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player->getLogic()) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealRandomHandCard->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardTriggered);
|
||||
}
|
||||
}
|
||||
|
||||
void HandMenu::onRevealHandTriggered()
|
||||
{
|
||||
auto *action = qobject_cast<QAction *>(sender());
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int targetId = action->data().toInt();
|
||||
player->getLogic()->getPlayerActions()->actRevealHand(targetId);
|
||||
}
|
||||
|
||||
void HandMenu::onRevealRandomHandCardTriggered()
|
||||
{
|
||||
auto *action = qobject_cast<QAction *>(sender());
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int targetId = action->data().toInt();
|
||||
player->getLogic()->getPlayerActions()->actRevealRandomHandCard(targetId);
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/**
|
||||
* @file hand_menu.h
|
||||
* @ingroup GameMenusZones
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_HAND_MENU_H
|
||||
#define COCKATRICE_HAND_MENU_H
|
||||
|
||||
#include "../../../interface/widgets/menus/tearoff_menu.h"
|
||||
#include "abstract_player_component.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class PlayerActions;
|
||||
|
||||
class HandMenu : public TearOffMenu, public AbstractPlayerComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HandMenu(PlayerGraphicsItem *player, QWidget *parent = nullptr);
|
||||
|
||||
QMenu *revealHandMenu() const
|
||||
{
|
||||
return mRevealHand;
|
||||
}
|
||||
QMenu *revealRandomHandCardMenu() const
|
||||
{
|
||||
return mRevealRandomHandCard;
|
||||
}
|
||||
|
||||
void retranslateUi() override;
|
||||
void setShortcutsActive() override;
|
||||
void setShortcutsInactive() override;
|
||||
|
||||
private slots:
|
||||
void populateRevealHandMenuWithActivePlayers();
|
||||
void populateRevealRandomHandCardMenuWithActivePlayers();
|
||||
void onRevealHandTriggered();
|
||||
void onRevealRandomHandCardTriggered();
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
|
||||
QAction *aViewHand = nullptr;
|
||||
QAction *aMulligan = nullptr;
|
||||
QAction *aMulliganSame = nullptr;
|
||||
QAction *aMulliganMinusOne = nullptr;
|
||||
|
||||
QMenu *mSortHand = nullptr;
|
||||
QAction *aSortHandByName = nullptr;
|
||||
QAction *aSortHandByType = nullptr;
|
||||
QAction *aSortHandByManaValue = nullptr;
|
||||
|
||||
QMenu *mRevealHand = nullptr;
|
||||
QAction *aRevealHandToAll = nullptr;
|
||||
|
||||
QMenu *mRevealRandomHandCard = nullptr;
|
||||
QAction *aRevealRandomHandCardToAll = nullptr;
|
||||
|
||||
QMenu *mMoveHandMenu = nullptr;
|
||||
QAction *aMoveHandToTopLibrary = nullptr;
|
||||
QAction *aMoveHandToBottomLibrary = nullptr;
|
||||
QAction *aMoveHandToGrave = nullptr;
|
||||
QAction *aMoveHandToRfg = nullptr;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_HAND_MENU_H
|
||||
|
|
@ -1,420 +0,0 @@
|
|||
#include "library_menu.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
#include "../../../client/settings/shortcuts_settings.h"
|
||||
#include "../../../interface/widgets/tabs/tab_game.h"
|
||||
#include "../../abstract_game.h"
|
||||
#include "../player_actions.h"
|
||||
#include "../player_logic.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QGraphicsView>
|
||||
#include <QMenu>
|
||||
|
||||
LibraryMenu::LibraryMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
|
||||
{
|
||||
createDrawActions();
|
||||
createShuffleActions();
|
||||
createMoveActions();
|
||||
createViewActions();
|
||||
|
||||
addAction(aDrawCard);
|
||||
addAction(aDrawCards);
|
||||
addAction(aUndoDraw);
|
||||
addSeparator();
|
||||
addAction(aShuffle);
|
||||
addSeparator();
|
||||
addAction(aViewLibrary);
|
||||
addAction(aViewTopCards);
|
||||
addAction(aViewBottomCards);
|
||||
addSeparator();
|
||||
|
||||
mRevealLibrary = addMenu(QString());
|
||||
connect(mRevealLibrary, &QMenu::aboutToShow, this, &LibraryMenu::populateRevealLibraryMenuWithActivePlayers);
|
||||
|
||||
mLendLibrary = addMenu(QString());
|
||||
connect(mLendLibrary, &QMenu::aboutToShow, this, &LibraryMenu::populateLendLibraryMenuWithActivePlayers);
|
||||
|
||||
mRevealTopCard = addMenu(QString());
|
||||
connect(mRevealTopCard, &QMenu::aboutToShow, this, &LibraryMenu::populateRevealTopCardMenuWithActivePlayers);
|
||||
|
||||
addAction(aAlwaysRevealTopCard);
|
||||
addAction(aAlwaysLookAtTopCard);
|
||||
addSeparator();
|
||||
topLibraryMenu = addTearOffMenu(QString());
|
||||
bottomLibraryMenu = addTearOffMenu(QString());
|
||||
addSeparator();
|
||||
addAction(aOpenDeckInDeckEditor);
|
||||
|
||||
topLibraryMenu->addAction(aMoveTopToPlay);
|
||||
topLibraryMenu->addAction(aMoveTopToPlayFaceDown);
|
||||
topLibraryMenu->addAction(aMoveTopCardToBottom);
|
||||
topLibraryMenu->addSeparator();
|
||||
topLibraryMenu->addAction(aMoveTopCardToGraveyard);
|
||||
topLibraryMenu->addAction(aMoveTopCardsToGraveyard);
|
||||
topLibraryMenu->addAction(aMoveTopCardsToGraveyardFaceDown);
|
||||
topLibraryMenu->addAction(aMoveTopCardToExile);
|
||||
topLibraryMenu->addAction(aMoveTopCardsToExile);
|
||||
topLibraryMenu->addAction(aMoveTopCardsToExileFaceDown);
|
||||
topLibraryMenu->addAction(aMoveTopCardsUntil);
|
||||
topLibraryMenu->addSeparator();
|
||||
topLibraryMenu->addAction(aShuffleTopCards);
|
||||
|
||||
bottomLibraryMenu->addAction(aDrawBottomCard);
|
||||
bottomLibraryMenu->addAction(aDrawBottomCards);
|
||||
bottomLibraryMenu->addSeparator();
|
||||
bottomLibraryMenu->addAction(aMoveBottomToPlay);
|
||||
bottomLibraryMenu->addAction(aMoveBottomToPlayFaceDown);
|
||||
bottomLibraryMenu->addAction(aMoveBottomCardToTop);
|
||||
bottomLibraryMenu->addSeparator();
|
||||
bottomLibraryMenu->addAction(aMoveBottomCardToGraveyard);
|
||||
bottomLibraryMenu->addAction(aMoveBottomCardsToGraveyard);
|
||||
bottomLibraryMenu->addAction(aMoveBottomCardsToGraveyardFaceDown);
|
||||
bottomLibraryMenu->addAction(aMoveBottomCardToExile);
|
||||
bottomLibraryMenu->addAction(aMoveBottomCardsToExile);
|
||||
bottomLibraryMenu->addAction(aMoveBottomCardsToExileFaceDown);
|
||||
bottomLibraryMenu->addSeparator();
|
||||
bottomLibraryMenu->addAction(aShuffleBottomCards);
|
||||
|
||||
connect(player->getLogic(), &PlayerLogic::resetTopCardMenuActions, this, &LibraryMenu::resetTopCardMenuActions);
|
||||
connect(player->getLogic(), &PlayerLogic::deckChanged, this, &LibraryMenu::enableOpenInDeckEditorAction);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void LibraryMenu::enableOpenInDeckEditorAction() const
|
||||
{
|
||||
aOpenDeckInDeckEditor->setEnabled(true);
|
||||
}
|
||||
|
||||
void LibraryMenu::resetTopCardMenuActions()
|
||||
{
|
||||
aAlwaysRevealTopCard->setChecked(false);
|
||||
aAlwaysLookAtTopCard->setChecked(false);
|
||||
}
|
||||
|
||||
void LibraryMenu::createDrawActions()
|
||||
{
|
||||
PlayerActions *playerActions = player->getLogic()->getPlayerActions();
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) {
|
||||
aDrawCard = new QAction(this);
|
||||
connect(aDrawCard, &QAction::triggered, playerActions, &PlayerActions::actDrawCard);
|
||||
aDrawCards = new QAction(this);
|
||||
connect(aDrawCards, &QAction::triggered, playerActions, &PlayerActions::actRequestDrawCardsDialog);
|
||||
aUndoDraw = new QAction(this);
|
||||
connect(aUndoDraw, &QAction::triggered, playerActions, &PlayerActions::actUndoDraw);
|
||||
aDrawBottomCard = new QAction(this);
|
||||
connect(aDrawBottomCard, &QAction::triggered, playerActions, &PlayerActions::actDrawBottomCard);
|
||||
aDrawBottomCards = new QAction(this);
|
||||
connect(aDrawBottomCards, &QAction::triggered, playerActions, &PlayerActions::actRequestDrawBottomCardsDialog);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::createShuffleActions()
|
||||
{
|
||||
PlayerActions *playerActions = player->getLogic()->getPlayerActions();
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) {
|
||||
aShuffle = new QAction(this);
|
||||
connect(aShuffle, &QAction::triggered, playerActions, &PlayerActions::actShuffle);
|
||||
aShuffleTopCards = new QAction(this);
|
||||
connect(aShuffleTopCards, &QAction::triggered, playerActions, &PlayerActions::actRequestShuffleTopDialog);
|
||||
aShuffleBottomCards = new QAction(this);
|
||||
connect(aShuffleBottomCards, &QAction::triggered, playerActions, &PlayerActions::actRequestShuffleBottomDialog);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::createMoveActions()
|
||||
{
|
||||
PlayerActions *playerActions = player->getLogic()->getPlayerActions();
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) {
|
||||
aMoveTopToPlay = new QAction(this);
|
||||
connect(aMoveTopToPlay, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToPlay);
|
||||
aMoveTopToPlayFaceDown = new QAction(this);
|
||||
connect(aMoveTopToPlayFaceDown, &QAction::triggered, playerActions,
|
||||
&PlayerActions::actMoveTopCardToPlayFaceDown);
|
||||
aMoveTopCardToGraveyard = new QAction(this);
|
||||
connect(aMoveTopCardToGraveyard, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToGrave);
|
||||
aMoveTopCardToExile = new QAction(this);
|
||||
connect(aMoveTopCardToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToExile);
|
||||
aMoveTopCardsToGraveyard = new QAction(this);
|
||||
connect(aMoveTopCardsToGraveyard, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsToGrave);
|
||||
aMoveTopCardsToGraveyardFaceDown = new QAction(this);
|
||||
connect(aMoveTopCardsToGraveyardFaceDown, &QAction::triggered, playerActions,
|
||||
&PlayerActions::actMoveTopCardsToGraveFaceDown);
|
||||
aMoveTopCardsToExile = new QAction(this);
|
||||
connect(aMoveTopCardsToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsToExile);
|
||||
aMoveTopCardsToExileFaceDown = new QAction(this);
|
||||
connect(aMoveTopCardsToExileFaceDown, &QAction::triggered, playerActions,
|
||||
&PlayerActions::actMoveTopCardsToExileFaceDown);
|
||||
aMoveTopCardsUntil = new QAction(this);
|
||||
connect(aMoveTopCardsUntil, &QAction::triggered, playerActions,
|
||||
&PlayerActions::actRequestMoveTopCardsUntilDialog);
|
||||
aMoveTopCardToBottom = new QAction(this);
|
||||
connect(aMoveTopCardToBottom, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToBottom);
|
||||
|
||||
aMoveBottomToPlay = new QAction(this);
|
||||
connect(aMoveBottomToPlay, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardToPlay);
|
||||
aMoveBottomToPlayFaceDown = new QAction(this);
|
||||
connect(aMoveBottomToPlayFaceDown, &QAction::triggered, playerActions,
|
||||
&PlayerActions::actMoveBottomCardToPlayFaceDown);
|
||||
aMoveBottomCardToGraveyard = new QAction(this);
|
||||
connect(aMoveBottomCardToGraveyard, &QAction::triggered, playerActions,
|
||||
&PlayerActions::actMoveBottomCardToGrave);
|
||||
aMoveBottomCardToExile = new QAction(this);
|
||||
connect(aMoveBottomCardToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardToExile);
|
||||
aMoveBottomCardsToGraveyard = new QAction(this);
|
||||
connect(aMoveBottomCardsToGraveyard, &QAction::triggered, playerActions,
|
||||
&PlayerActions::actMoveBottomCardsToGrave);
|
||||
aMoveBottomCardsToGraveyardFaceDown = new QAction(this);
|
||||
connect(aMoveBottomCardsToGraveyardFaceDown, &QAction::triggered, playerActions,
|
||||
&PlayerActions::actMoveBottomCardsToGraveFaceDown);
|
||||
aMoveBottomCardsToExile = new QAction(this);
|
||||
connect(aMoveBottomCardsToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardsToExile);
|
||||
aMoveBottomCardsToExileFaceDown = new QAction(this);
|
||||
connect(aMoveBottomCardsToExileFaceDown, &QAction::triggered, playerActions,
|
||||
&PlayerActions::actMoveBottomCardsToExileFaceDown);
|
||||
aMoveBottomCardToTop = new QAction(this);
|
||||
connect(aMoveBottomCardToTop, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardToTop);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::createViewActions()
|
||||
{
|
||||
PlayerActions *playerActions = player->getLogic()->getPlayerActions();
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) {
|
||||
aViewLibrary = new QAction(this);
|
||||
connect(aViewLibrary, &QAction::triggered, playerActions, &PlayerActions::actViewLibrary);
|
||||
|
||||
aViewTopCards = new QAction(this);
|
||||
connect(aViewTopCards, &QAction::triggered, playerActions, &PlayerActions::actRequestViewTopCardsDialog);
|
||||
aViewBottomCards = new QAction(this);
|
||||
connect(aViewBottomCards, &QAction::triggered, playerActions, &PlayerActions::actRequestViewBottomCardsDialog);
|
||||
aAlwaysRevealTopCard = new QAction(this);
|
||||
aAlwaysRevealTopCard->setCheckable(true);
|
||||
connect(aAlwaysRevealTopCard, &QAction::triggered, playerActions, &PlayerActions::actAlwaysRevealTopCard);
|
||||
aAlwaysLookAtTopCard = new QAction(this);
|
||||
aAlwaysLookAtTopCard->setCheckable(true);
|
||||
connect(aAlwaysLookAtTopCard, &QAction::triggered, playerActions, &PlayerActions::actAlwaysLookAtTopCard);
|
||||
aOpenDeckInDeckEditor = new QAction(this);
|
||||
aOpenDeckInDeckEditor->setEnabled(false);
|
||||
connect(aOpenDeckInDeckEditor, &QAction::triggered, playerActions, &PlayerActions::actOpenDeckInDeckEditor);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::retranslateUi()
|
||||
{
|
||||
setTitle(tr("&Library"));
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aViewLibrary->setText(tr("&View library"));
|
||||
aViewTopCards->setText(tr("View &top cards of library..."));
|
||||
aViewBottomCards->setText(tr("View bottom cards of library..."));
|
||||
mRevealLibrary->setTitle(tr("Reveal &library to..."));
|
||||
mLendLibrary->setTitle(tr("Lend library to..."));
|
||||
mRevealTopCard->setTitle(tr("Reveal &top cards to..."));
|
||||
topLibraryMenu->setTitle(tr("&Top of library..."));
|
||||
bottomLibraryMenu->setTitle(tr("&Bottom of library..."));
|
||||
aAlwaysRevealTopCard->setText(tr("&Always reveal top card"));
|
||||
aAlwaysLookAtTopCard->setText(tr("&Always look at top card"));
|
||||
aOpenDeckInDeckEditor->setText(tr("&Open deck in deck editor"));
|
||||
|
||||
aDrawCard->setText(tr("&Draw card"));
|
||||
aDrawCards->setText(tr("D&raw cards..."));
|
||||
aUndoDraw->setText(tr("&Undo last draw"));
|
||||
|
||||
aShuffle->setText(tr("Shuffle"));
|
||||
|
||||
aMoveTopToPlay->setText(tr("&Play top card"));
|
||||
aMoveTopToPlayFaceDown->setText(tr("Play top card &face down"));
|
||||
aMoveTopCardToBottom->setText(tr("Put top card on &bottom"));
|
||||
aMoveTopCardToGraveyard->setText(tr("Move top card to grave&yard"));
|
||||
aMoveTopCardToExile->setText(tr("Move top card to e&xile"));
|
||||
aMoveTopCardsToGraveyard->setText(tr("Move top cards to &graveyard..."));
|
||||
aMoveTopCardsToGraveyardFaceDown->setText(tr("Move top cards to graveyard face down..."));
|
||||
aMoveTopCardsToExile->setText(tr("Move top cards to &exile..."));
|
||||
aMoveTopCardsToExileFaceDown->setText(tr("Move top cards to exile face down..."));
|
||||
aMoveTopCardsUntil->setText(tr("Put top cards on stack &until..."));
|
||||
aShuffleTopCards->setText(tr("Shuffle top cards..."));
|
||||
|
||||
aDrawBottomCard->setText(tr("&Draw bottom card"));
|
||||
aDrawBottomCards->setText(tr("D&raw bottom cards..."));
|
||||
aMoveBottomToPlay->setText(tr("&Play bottom card"));
|
||||
aMoveBottomToPlayFaceDown->setText(tr("Play bottom card &face down"));
|
||||
aMoveBottomCardToGraveyard->setText(tr("Move bottom card to grave&yard"));
|
||||
aMoveBottomCardToExile->setText(tr("Move bottom card to e&xile"));
|
||||
aMoveBottomCardsToGraveyard->setText(tr("Move bottom cards to &graveyard..."));
|
||||
aMoveBottomCardsToGraveyardFaceDown->setText(tr("Move bottom cards to graveyard face down..."));
|
||||
aMoveBottomCardsToExile->setText(tr("Move bottom cards to &exile..."));
|
||||
aMoveBottomCardsToExileFaceDown->setText(tr("Move bottom cards to exile face down..."));
|
||||
aMoveBottomCardToTop->setText(tr("Put bottom card on &top"));
|
||||
aShuffleBottomCards->setText(tr("Shuffle bottom cards..."));
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::populateRevealLibraryMenuWithActivePlayers()
|
||||
{
|
||||
mRevealLibrary->clear();
|
||||
|
||||
QAction *allPlayers = mRevealLibrary->addAction(tr("&All players"));
|
||||
allPlayers->setData(-1);
|
||||
connect(allPlayers, &QAction::triggered, this, &LibraryMenu::onRevealLibraryTriggered);
|
||||
|
||||
mRevealLibrary->addSeparator();
|
||||
|
||||
const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player->getLogic()) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealLibrary->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &LibraryMenu::onRevealLibraryTriggered);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::populateLendLibraryMenuWithActivePlayers()
|
||||
{
|
||||
mLendLibrary->clear();
|
||||
|
||||
const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player->getLogic()) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mLendLibrary->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &LibraryMenu::onLendLibraryTriggered);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::populateRevealTopCardMenuWithActivePlayers()
|
||||
{
|
||||
mRevealTopCard->clear();
|
||||
|
||||
QAction *allPlayers = mRevealTopCard->addAction(tr("&All players"));
|
||||
allPlayers->setData(-1);
|
||||
connect(allPlayers, &QAction::triggered, this, &LibraryMenu::onRevealTopCardTriggered);
|
||||
|
||||
mRevealTopCard->addSeparator();
|
||||
|
||||
const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player->getLogic()) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealTopCard->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &LibraryMenu::onRevealTopCardTriggered);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::onRevealLibraryTriggered()
|
||||
{
|
||||
if (auto *a = qobject_cast<QAction *>(sender())) {
|
||||
player->getLogic()->getPlayerActions()->actRevealLibrary(a->data().toInt());
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::onLendLibraryTriggered()
|
||||
{
|
||||
if (auto *a = qobject_cast<QAction *>(sender())) {
|
||||
player->getLogic()->getPlayerActions()->actLendLibrary(a->data().toInt());
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::onRevealTopCardTriggered()
|
||||
{
|
||||
QWidget *parent = nullptr;
|
||||
if (auto *view = player->scene() ? player->scene()->views().value(0) : nullptr) {
|
||||
parent = view->window();
|
||||
}
|
||||
if (auto *a = qobject_cast<QAction *>(sender())) {
|
||||
|
||||
int deckSize = player->getLogic()->getDeckZone()->getCards().size();
|
||||
bool ok = true;
|
||||
int number = QInputDialog::getInt(parent, tr("Reveal top cards of library"),
|
||||
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1,
|
||||
deckSize, 1, &ok);
|
||||
|
||||
if (ok) {
|
||||
player->getLogic()->getPlayerActions()->actRevealTopCards(a->data().toInt(), number);
|
||||
defaultNumberTopCards = number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
||||
aViewLibrary->setShortcuts(shortcuts.getShortcut("Player/aViewLibrary"));
|
||||
aViewTopCards->setShortcuts(shortcuts.getShortcut("Player/aViewTopCards"));
|
||||
aViewBottomCards->setShortcuts(shortcuts.getShortcut("Player/aViewBottomCards"));
|
||||
aDrawCard->setShortcuts(shortcuts.getShortcut("Player/aDrawCard"));
|
||||
aDrawCards->setShortcuts(shortcuts.getShortcut("Player/aDrawCards"));
|
||||
aUndoDraw->setShortcuts(shortcuts.getShortcut("Player/aUndoDraw"));
|
||||
aShuffle->setShortcuts(shortcuts.getShortcut("Player/aShuffle"));
|
||||
aShuffleTopCards->setShortcuts(shortcuts.getShortcut("Player/aShuffleTopCards"));
|
||||
aShuffleBottomCards->setShortcuts(shortcuts.getShortcut("Player/aShuffleBottomCards"));
|
||||
aAlwaysRevealTopCard->setShortcuts(shortcuts.getShortcut("Player/aAlwaysRevealTopCard"));
|
||||
aAlwaysLookAtTopCard->setShortcuts(shortcuts.getShortcut("Player/aAlwaysLookAtTopCard"));
|
||||
aMoveTopToPlay->setShortcuts(shortcuts.getShortcut("Player/aMoveTopToPlay"));
|
||||
aMoveTopToPlayFaceDown->setShortcuts(shortcuts.getShortcut("Player/aMoveTopToPlayFaceDown"));
|
||||
aMoveTopCardToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardToGraveyard"));
|
||||
aMoveTopCardsToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardsToGraveyard"));
|
||||
aMoveTopCardsToGraveyardFaceDown->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardsToGraveyardFaceDown"));
|
||||
aMoveTopCardToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardToExile"));
|
||||
aMoveTopCardsToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardsToExile"));
|
||||
aMoveTopCardsToExileFaceDown->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardsToExileFaceDown"));
|
||||
aMoveTopCardsUntil->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardsUntil"));
|
||||
aMoveTopCardToBottom->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardToBottom"));
|
||||
aDrawBottomCard->setShortcuts(shortcuts.getShortcut("Player/aDrawBottomCard"));
|
||||
aDrawBottomCards->setShortcuts(shortcuts.getShortcut("Player/aDrawBottomCards"));
|
||||
aMoveBottomToPlay->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomToPlay"));
|
||||
aMoveBottomToPlayFaceDown->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomToPlayFaceDown"));
|
||||
aMoveBottomCardToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardToGrave"));
|
||||
aMoveBottomCardsToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardsToGrave"));
|
||||
aMoveBottomCardsToGraveyardFaceDown->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardsToGraveFaceDown"));
|
||||
aMoveBottomCardToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardToExile"));
|
||||
aMoveBottomCardsToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardsToExile"));
|
||||
aMoveBottomCardsToExileFaceDown->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardsToExileFaceDown"));
|
||||
aMoveBottomCardToTop->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardToTop"));
|
||||
}
|
||||
|
||||
void LibraryMenu::setShortcutsInactive()
|
||||
{
|
||||
aViewLibrary->setShortcut(QKeySequence());
|
||||
aViewTopCards->setShortcut(QKeySequence());
|
||||
aViewBottomCards->setShortcut(QKeySequence());
|
||||
aDrawCard->setShortcut(QKeySequence());
|
||||
aDrawCards->setShortcut(QKeySequence());
|
||||
aUndoDraw->setShortcut(QKeySequence());
|
||||
aShuffle->setShortcut(QKeySequence());
|
||||
aShuffleTopCards->setShortcut(QKeySequence());
|
||||
aShuffleBottomCards->setShortcut(QKeySequence());
|
||||
aAlwaysRevealTopCard->setShortcut(QKeySequence());
|
||||
aAlwaysLookAtTopCard->setShortcut(QKeySequence());
|
||||
aMoveTopToPlay->setShortcut(QKeySequence());
|
||||
aMoveTopToPlayFaceDown->setShortcut(QKeySequence());
|
||||
aMoveTopCardToGraveyard->setShortcut(QKeySequence());
|
||||
aMoveTopCardsToGraveyard->setShortcut(QKeySequence());
|
||||
aMoveTopCardsToGraveyardFaceDown->setShortcut(QKeySequence());
|
||||
aMoveTopCardToExile->setShortcut(QKeySequence());
|
||||
aMoveTopCardsToExile->setShortcut(QKeySequence());
|
||||
aMoveTopCardsToExileFaceDown->setShortcut(QKeySequence());
|
||||
aMoveTopCardsUntil->setShortcut(QKeySequence());
|
||||
aDrawBottomCard->setShortcut(QKeySequence());
|
||||
aDrawBottomCards->setShortcut(QKeySequence());
|
||||
aMoveBottomToPlay->setShortcut(QKeySequence());
|
||||
aMoveBottomToPlayFaceDown->setShortcut(QKeySequence());
|
||||
aMoveBottomCardToGraveyard->setShortcut(QKeySequence());
|
||||
aMoveBottomCardsToGraveyard->setShortcut(QKeySequence());
|
||||
aMoveBottomCardsToGraveyardFaceDown->setShortcut(QKeySequence());
|
||||
aMoveBottomCardToExile->setShortcut(QKeySequence());
|
||||
aMoveBottomCardsToExile->setShortcut(QKeySequence());
|
||||
aMoveBottomCardsToExileFaceDown->setShortcut(QKeySequence());
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/**
|
||||
* @file library_menu.h
|
||||
* @ingroup GameMenusZones
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_LIBRARY_MENU_H
|
||||
#define COCKATRICE_LIBRARY_MENU_H
|
||||
|
||||
#include "../../../interface/widgets/menus/tearoff_menu.h"
|
||||
#include "abstract_player_component.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class PlayerLogic;
|
||||
class PlayerActions;
|
||||
|
||||
class LibraryMenu : public TearOffMenu, public AbstractPlayerComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
void enableOpenInDeckEditorAction() const;
|
||||
void resetTopCardMenuActions();
|
||||
|
||||
public:
|
||||
LibraryMenu(PlayerGraphicsItem *player, QWidget *parent = nullptr);
|
||||
void createDrawActions();
|
||||
void createShuffleActions();
|
||||
void createMoveActions();
|
||||
void createViewActions();
|
||||
void retranslateUi() override;
|
||||
void populateRevealLibraryMenuWithActivePlayers();
|
||||
void populateLendLibraryMenuWithActivePlayers();
|
||||
void populateRevealTopCardMenuWithActivePlayers();
|
||||
void onRevealLibraryTriggered();
|
||||
void onLendLibraryTriggered();
|
||||
void onRevealTopCardTriggered();
|
||||
void setShortcutsActive() override;
|
||||
void setShortcutsInactive() override;
|
||||
|
||||
[[nodiscard]] bool isAlwaysRevealTopCardChecked() const
|
||||
{
|
||||
return aAlwaysRevealTopCard->isChecked();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isAlwaysLookAtTopCardChecked() const
|
||||
{
|
||||
return aAlwaysLookAtTopCard->isChecked();
|
||||
}
|
||||
|
||||
// expose useful actions/menus if PlayerMenu needs them
|
||||
[[nodiscard]] QMenu *revealLibrary() const
|
||||
{
|
||||
return mRevealLibrary;
|
||||
}
|
||||
[[nodiscard]] QMenu *lendLibraryMenu() const
|
||||
{
|
||||
return mLendLibrary;
|
||||
}
|
||||
[[nodiscard]] QMenu *revealTopCardMenu() const
|
||||
{
|
||||
return mRevealTopCard;
|
||||
}
|
||||
|
||||
QMenu *topLibraryMenu = nullptr;
|
||||
QMenu *bottomLibraryMenu = nullptr;
|
||||
|
||||
// Expose submenus that PlayerMenu tracks in its lists
|
||||
QMenu *mRevealLibrary = nullptr;
|
||||
QMenu *mLendLibrary = nullptr;
|
||||
QMenu *mRevealTopCard = nullptr;
|
||||
|
||||
QAction *aDrawCard = nullptr;
|
||||
QAction *aDrawCards = nullptr;
|
||||
QAction *aUndoDraw = nullptr;
|
||||
|
||||
QAction *aShuffle = nullptr;
|
||||
QAction *aViewLibrary = nullptr;
|
||||
QAction *aViewTopCards = nullptr;
|
||||
QAction *aViewBottomCards = nullptr;
|
||||
QAction *aAlwaysRevealTopCard = nullptr;
|
||||
QAction *aAlwaysLookAtTopCard = nullptr;
|
||||
QAction *aOpenDeckInDeckEditor = nullptr;
|
||||
|
||||
QAction *aMoveTopToPlay = nullptr;
|
||||
QAction *aMoveTopToPlayFaceDown = nullptr;
|
||||
QAction *aMoveTopCardToBottom = nullptr;
|
||||
QAction *aMoveTopCardToGraveyard = nullptr;
|
||||
QAction *aMoveTopCardToExile = nullptr;
|
||||
QAction *aMoveTopCardsToGraveyard = nullptr;
|
||||
QAction *aMoveTopCardsToGraveyardFaceDown = nullptr;
|
||||
QAction *aMoveTopCardsToExile = nullptr;
|
||||
QAction *aMoveTopCardsToExileFaceDown = nullptr;
|
||||
QAction *aMoveTopCardsUntil = nullptr;
|
||||
QAction *aShuffleTopCards = nullptr;
|
||||
|
||||
QAction *aDrawBottomCard = nullptr;
|
||||
QAction *aDrawBottomCards = nullptr;
|
||||
QAction *aMoveBottomToPlay = nullptr;
|
||||
QAction *aMoveBottomToPlayFaceDown = nullptr;
|
||||
QAction *aMoveBottomCardToTop = nullptr;
|
||||
QAction *aMoveBottomCardToGraveyard = nullptr;
|
||||
QAction *aMoveBottomCardToExile = nullptr;
|
||||
QAction *aMoveBottomCardsToGraveyard = nullptr;
|
||||
QAction *aMoveBottomCardsToGraveyardFaceDown = nullptr;
|
||||
QAction *aMoveBottomCardsToExile = nullptr;
|
||||
QAction *aMoveBottomCardsToExileFaceDown = nullptr;
|
||||
QAction *aShuffleBottomCards = nullptr;
|
||||
|
||||
int defaultNumberTopCards = 1;
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_LIBRARY_MENU_H
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
#include "move_menu.h"
|
||||
|
||||
#include "../card_menu_action_type.h"
|
||||
#include "../player_actions.h"
|
||||
#include "../player_logic.h"
|
||||
|
||||
MoveMenu::MoveMenu(PlayerGraphicsItem *player) : QMenu(tr("Move to"))
|
||||
{
|
||||
aMoveToTopLibrary = new QAction(this);
|
||||
aMoveToTopLibrary->setData(cmMoveToTopLibrary);
|
||||
aMoveToBottomLibrary = new QAction(this);
|
||||
aMoveToBottomLibrary->setData(cmMoveToBottomLibrary);
|
||||
aMoveToXfromTopOfLibrary = new QAction(this);
|
||||
aMoveToTable = new QAction(this);
|
||||
aMoveToTable->setData(cmMoveToTable);
|
||||
aMoveToGraveyard = new QAction(this);
|
||||
aMoveToHand = new QAction(this);
|
||||
aMoveToHand->setData(cmMoveToHand);
|
||||
aMoveToGraveyard->setData(cmMoveToGraveyard);
|
||||
aMoveToExile = new QAction(this);
|
||||
aMoveToExile->setData(cmMoveToExile);
|
||||
|
||||
auto *actions = player->getLogic()->getPlayerActions();
|
||||
|
||||
auto invoke = [player](CardMenuActionType type) {
|
||||
return [type, player]() {
|
||||
player->getLogic()->getPlayerActions()->cardMenuAction(player->getGameScene()->selectedCards(), type);
|
||||
};
|
||||
};
|
||||
|
||||
connect(aMoveToTopLibrary, &QAction::triggered, actions, invoke(cmMoveToTopLibrary));
|
||||
connect(aMoveToBottomLibrary, &QAction::triggered, actions, invoke(cmMoveToBottomLibrary));
|
||||
connect(aMoveToXfromTopOfLibrary, &QAction::triggered, actions,
|
||||
&PlayerActions::actRequestMoveCardXCardsFromTopDialog);
|
||||
connect(aMoveToTable, &QAction::triggered, actions, invoke(cmMoveToTable));
|
||||
connect(aMoveToHand, &QAction::triggered, actions, invoke(cmMoveToHand));
|
||||
connect(aMoveToGraveyard, &QAction::triggered, actions, invoke(cmMoveToGraveyard));
|
||||
connect(aMoveToExile, &QAction::triggered, actions, invoke(cmMoveToExile));
|
||||
|
||||
addAction(aMoveToTopLibrary);
|
||||
addAction(aMoveToXfromTopOfLibrary);
|
||||
addAction(aMoveToBottomLibrary);
|
||||
addSeparator();
|
||||
addAction(aMoveToTable);
|
||||
addSeparator();
|
||||
addAction(aMoveToHand);
|
||||
addSeparator();
|
||||
addAction(aMoveToGraveyard);
|
||||
addSeparator();
|
||||
addAction(aMoveToExile);
|
||||
|
||||
setShortcutsActive();
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void MoveMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
||||
aMoveToTopLibrary->setShortcuts(shortcuts.getShortcut("Player/aMoveToTopLibrary"));
|
||||
aMoveToBottomLibrary->setShortcuts(shortcuts.getShortcut("Player/aMoveToBottomLibrary"));
|
||||
aMoveToTable->setShortcuts(shortcuts.getShortcut("Player/aMoveToTable"));
|
||||
aMoveToHand->setShortcuts(shortcuts.getShortcut("Player/aMoveToHand"));
|
||||
aMoveToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveToGraveyard"));
|
||||
aMoveToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveToExile"));
|
||||
}
|
||||
|
||||
void MoveMenu::retranslateUi()
|
||||
{
|
||||
aMoveToTopLibrary->setText(tr("&Top of library in random order"));
|
||||
aMoveToXfromTopOfLibrary->setText(tr("X cards from the top of library..."));
|
||||
aMoveToBottomLibrary->setText(tr("&Bottom of library in random order"));
|
||||
aMoveToTable->setText(tr("T&able"));
|
||||
aMoveToHand->setText(tr("&Hand"));
|
||||
aMoveToGraveyard->setText(tr("&Graveyard"));
|
||||
aMoveToExile->setText(tr("&Exile"));
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
* @file move_menu.h
|
||||
* @ingroup GameMenusZones
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_MOVE_MENU_H
|
||||
#define COCKATRICE_MOVE_MENU_H
|
||||
#include <QMenu>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class MoveMenu : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MoveMenu(PlayerGraphicsItem *player);
|
||||
void setShortcutsActive();
|
||||
void retranslateUi();
|
||||
|
||||
QAction *aMoveToTopLibrary = nullptr;
|
||||
QAction *aMoveToXfromTopOfLibrary = nullptr;
|
||||
QAction *aMoveToBottomLibrary = nullptr;
|
||||
|
||||
QAction *aMoveToHand = nullptr;
|
||||
QAction *aMoveToTable = nullptr;
|
||||
QAction *aMoveToGraveyard = nullptr;
|
||||
QAction *aMoveToExile = nullptr;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_MOVE_MENU_H
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
#include "player_menu.h"
|
||||
|
||||
#include "../../../game_graphics/zones/hand_zone.h"
|
||||
#include "../../../game_graphics/zones/pile_zone.h"
|
||||
#include "../../../game_graphics/zones/table_zone.h"
|
||||
#include "../../../interface/widgets/tabs/tab_game.h"
|
||||
#include "../../board/card_item.h"
|
||||
#include "card_menu.h"
|
||||
#include "hand_menu.h"
|
||||
|
||||
#include <libcockatrice/protocol/pb/command_reveal_cards.pb.h>
|
||||
|
||||
PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_player)
|
||||
{
|
||||
connect(player->getLogic(), &PlayerLogic::requestCardMenuUpdate, this, &PlayerMenu::updateCardMenu);
|
||||
connect(this, &PlayerMenu::cardInfoRequested, player, &PlayerGraphicsItem::cardInfoRequested);
|
||||
|
||||
playerMenu = new TearOffMenu();
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
handMenu = addManagedMenu<HandMenu>(player, playerMenu);
|
||||
libraryMenu = addManagedMenu<LibraryMenu>(player, playerMenu);
|
||||
} else {
|
||||
handMenu = nullptr;
|
||||
libraryMenu = nullptr;
|
||||
}
|
||||
|
||||
graveMenu = addManagedMenu<GraveyardMenu>(player, playerMenu);
|
||||
rfgMenu = addManagedMenu<RfgMenu>(player, playerMenu);
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
sideboardMenu = addManagedMenu<SideboardMenu>(player, playerMenu);
|
||||
customZonesMenu = addManagedMenu<CustomZoneMenu>(player);
|
||||
playerMenu->addSeparator();
|
||||
|
||||
countersMenu = playerMenu->addMenu(QString());
|
||||
|
||||
utilityMenu = createManagedComponent<UtilityMenu>(player, playerMenu);
|
||||
} else {
|
||||
sideboardMenu = nullptr;
|
||||
customZonesMenu = nullptr;
|
||||
countersMenu = nullptr;
|
||||
utilityMenu = nullptr;
|
||||
}
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocal()) {
|
||||
sayMenu = addManagedMenu<SayMenu>(player);
|
||||
} else {
|
||||
sayMenu = nullptr;
|
||||
}
|
||||
|
||||
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
||||
&PlayerMenu::refreshShortcuts);
|
||||
refreshShortcuts();
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void PlayerMenu::setMenusForGraphicItems()
|
||||
{
|
||||
player->getTableZoneGraphicsItem()->setMenu(playerMenu);
|
||||
player->getGraveyardZoneGraphicsItem()->setMenu(graveMenu, graveMenu->aViewGraveyard);
|
||||
player->getRfgZoneGraphicsItem()->setMenu(rfgMenu, rfgMenu->aViewRfg);
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
player->getHandZoneGraphicsItem()->setMenu(handMenu);
|
||||
player->getDeckZoneGraphicsItem()->setMenu(libraryMenu, libraryMenu->aDrawCard);
|
||||
player->getSideboardZoneGraphicsItem()->setMenu(sideboardMenu);
|
||||
}
|
||||
}
|
||||
|
||||
QMenu *PlayerMenu::updateCardMenu(const CardItem *card)
|
||||
{
|
||||
if (!card) {
|
||||
emit cardMenuUpdated(nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// If is spectator (as spectators don't need card menus), return
|
||||
// only update the menu if the card is actually selected
|
||||
if ((player->getLogic()->getGame()->getPlayerManager()->isSpectator() &&
|
||||
!player->getLogic()->getGame()->getPlayerManager()->isJudge()) ||
|
||||
player->getLogic()->getGame()->getActiveCard() != card) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CardMenu *menu = new CardMenu(player, card, shortcutsActive);
|
||||
connect(menu, &CardMenu::cardInfoRequested, this, &PlayerMenu::cardInfoRequested);
|
||||
emit cardMenuUpdated(menu);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
void PlayerMenu::retranslateUi()
|
||||
{
|
||||
playerMenu->setTitle(tr("Player \"%1\"").arg(player->getLogic()->getPlayerInfo()->getName()));
|
||||
|
||||
for (auto *component : managedComponents) {
|
||||
component->retranslateUi();
|
||||
}
|
||||
|
||||
if (countersMenu) {
|
||||
countersMenu->setTitle(tr("&Counters"));
|
||||
}
|
||||
|
||||
emit retranslateRequested();
|
||||
}
|
||||
|
||||
void PlayerMenu::refreshShortcuts()
|
||||
{
|
||||
if (shortcutsActive) {
|
||||
// Judges get access to every player's menus but only want shortcuts to be set for their own.
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge() &&
|
||||
!player->getLogic()->getPlayerInfo()->getLocal()) {
|
||||
setShortcutsInactive();
|
||||
} else {
|
||||
setShortcutsActive();
|
||||
}
|
||||
} else {
|
||||
setShortcutsInactive();
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMenu::setShortcutsActive()
|
||||
{
|
||||
shortcutsActive = true;
|
||||
for (auto *c : managedComponents) {
|
||||
c->setShortcutsActive();
|
||||
}
|
||||
emit shortcutsActivated();
|
||||
}
|
||||
|
||||
void PlayerMenu::setShortcutsInactive()
|
||||
{
|
||||
shortcutsActive = false;
|
||||
for (auto *c : managedComponents) {
|
||||
c->setShortcutsInactive();
|
||||
}
|
||||
emit shortcutsDeactivated();
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
/**
|
||||
* @file player_menu.h
|
||||
* @ingroup GameMenusPlayers
|
||||
* @brief Orchestrates lifecycle management for all player-bound UI components.
|
||||
*/
|
||||
|
||||
#ifndef COCKATRICE_PLAYER_MENU_H
|
||||
#define COCKATRICE_PLAYER_MENU_H
|
||||
|
||||
#include "../../../interface/widgets/menus/tearoff_menu.h"
|
||||
#include "custom_zone_menu.h"
|
||||
#include "grave_menu.h"
|
||||
#include "hand_menu.h"
|
||||
#include "library_menu.h"
|
||||
#include "rfg_menu.h"
|
||||
#include "say_menu.h"
|
||||
#include "sideboard_menu.h"
|
||||
#include "utility_menu.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QMenu>
|
||||
#include <QObject>
|
||||
|
||||
class CardItem;
|
||||
class CardMenu;
|
||||
class PlayerGraphicsItem;
|
||||
class PlayerMenu : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void cardMenuUpdated(CardMenu *cardMenu);
|
||||
void cardInfoRequested(const CardRef &cardRef);
|
||||
void shortcutsActivated();
|
||||
void shortcutsDeactivated();
|
||||
void retranslateRequested();
|
||||
|
||||
public slots:
|
||||
void setMenusForGraphicItems();
|
||||
QMenu *updateCardMenu(const CardItem *card);
|
||||
|
||||
private slots:
|
||||
void refreshShortcuts();
|
||||
|
||||
public:
|
||||
explicit PlayerMenu(PlayerGraphicsItem *player);
|
||||
/** @brief Retranslate all user-visible strings. Called on language change. */
|
||||
void retranslateUi();
|
||||
|
||||
[[nodiscard]] QMenu *getPlayerMenu() const
|
||||
{
|
||||
return playerMenu;
|
||||
}
|
||||
|
||||
[[nodiscard]] QMenu *getCountersMenu()
|
||||
{
|
||||
return countersMenu;
|
||||
}
|
||||
|
||||
[[nodiscard]] LibraryMenu *getLibraryMenu() const
|
||||
{
|
||||
return libraryMenu;
|
||||
}
|
||||
|
||||
[[nodiscard]] UtilityMenu *getUtilityMenu() const
|
||||
{
|
||||
return utilityMenu;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool getShortcutsActive() const
|
||||
{
|
||||
return shortcutsActive;
|
||||
}
|
||||
|
||||
/** @brief Bind keyboard shortcuts. Called when this player gains focus. */
|
||||
void setShortcutsActive();
|
||||
/** @brief Unbind keyboard shortcuts. Called when this player loses focus. */
|
||||
void setShortcutsInactive();
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
TearOffMenu *playerMenu;
|
||||
QMenu *countersMenu;
|
||||
HandMenu *handMenu;
|
||||
LibraryMenu *libraryMenu;
|
||||
SideboardMenu *sideboardMenu;
|
||||
GraveyardMenu *graveMenu;
|
||||
RfgMenu *rfgMenu;
|
||||
UtilityMenu *utilityMenu;
|
||||
SayMenu *sayMenu;
|
||||
CustomZoneMenu *customZonesMenu;
|
||||
|
||||
/** @brief Drives AbstractPlayerComponent lifecycle delegation. Counters are iterated separately via
|
||||
* player->getCounters().
|
||||
*/
|
||||
QList<AbstractPlayerComponent *> managedComponents;
|
||||
bool shortcutsActive = false;
|
||||
|
||||
/** @brief Creates component, adds it as a submenu of playerMenu, and registers in managedComponents. */
|
||||
template <typename MenuT, typename... Args> MenuT *addManagedMenu(Args &&...args)
|
||||
{
|
||||
auto *menu = new MenuT(std::forward<Args>(args)...);
|
||||
playerMenu->addMenu(menu);
|
||||
managedComponents.append(menu);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/** @brief Creates component and registers in managedComponents, but does NOT add it as a submenu. */
|
||||
template <typename ComponentT, typename... Args> ComponentT *createManagedComponent(Args &&...args)
|
||||
{
|
||||
auto *component = new ComponentT(std::forward<Args>(args)...);
|
||||
managedComponents.append(component);
|
||||
return component;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_MENU_H
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
#include "pt_menu.h"
|
||||
|
||||
#include "../player_actions.h"
|
||||
#include "../player_logic.h"
|
||||
|
||||
PtMenu::PtMenu(PlayerGraphicsItem *player) : QMenu(tr("Power / toughness"))
|
||||
{
|
||||
PlayerActions *playerActions = player->getLogic()->getPlayerActions();
|
||||
|
||||
aIncP = new QAction(this);
|
||||
connect(aIncP, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actIncP(player->getGameScene()->selectedCards()); });
|
||||
aDecP = new QAction(this);
|
||||
connect(aDecP, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actDecP(player->getGameScene()->selectedCards()); });
|
||||
aIncT = new QAction(this);
|
||||
connect(aIncT, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actIncT(player->getGameScene()->selectedCards()); });
|
||||
aDecT = new QAction(this);
|
||||
connect(aDecT, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actDecT(player->getGameScene()->selectedCards()); });
|
||||
aIncPT = new QAction(this);
|
||||
connect(aIncPT, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actIncPT(player->getGameScene()->selectedCards()); });
|
||||
aDecPT = new QAction(this);
|
||||
connect(aDecPT, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actDecPT(player->getGameScene()->selectedCards()); });
|
||||
aFlowP = new QAction(this);
|
||||
connect(aFlowP, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actFlowP(player->getGameScene()->selectedCards()); });
|
||||
aFlowT = new QAction(this);
|
||||
connect(aFlowT, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actFlowT(player->getGameScene()->selectedCards()); });
|
||||
aSetPT = new QAction(this);
|
||||
connect(aSetPT, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actRequestSetPTDialog(player->getGameScene()->selectedCards()); });
|
||||
aResetPT = new QAction(this);
|
||||
connect(aResetPT, &QAction::triggered, playerActions,
|
||||
[player, playerActions] { playerActions->actResetPT(player->getGameScene()->selectedCards()); });
|
||||
|
||||
addAction(aIncP);
|
||||
addAction(aDecP);
|
||||
addAction(aFlowP);
|
||||
addSeparator();
|
||||
addAction(aIncT);
|
||||
addAction(aDecT);
|
||||
addAction(aFlowT);
|
||||
addSeparator();
|
||||
addAction(aIncPT);
|
||||
addAction(aDecPT);
|
||||
addSeparator();
|
||||
addAction(aSetPT);
|
||||
addAction(aResetPT);
|
||||
|
||||
setShortcutsActive();
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void PtMenu::retranslateUi()
|
||||
{
|
||||
aIncP->setText(tr("&Increase power"));
|
||||
aDecP->setText(tr("&Decrease power"));
|
||||
aIncT->setText(tr("I&ncrease toughness"));
|
||||
aDecT->setText(tr("D&ecrease toughness"));
|
||||
aIncPT->setText(tr("In&crease power and toughness"));
|
||||
aDecPT->setText(tr("Dec&rease power and toughness"));
|
||||
aFlowP->setText(tr("Increase power and decrease toughness"));
|
||||
aFlowT->setText(tr("Decrease power and increase toughness"));
|
||||
aSetPT->setText(tr("Set &power and toughness..."));
|
||||
aResetPT->setText(tr("Reset p&ower and toughness"));
|
||||
}
|
||||
|
||||
void PtMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
||||
aIncP->setShortcuts(shortcuts.getShortcut("Player/aIncP"));
|
||||
aDecP->setShortcuts(shortcuts.getShortcut("Player/aDecP"));
|
||||
aIncT->setShortcuts(shortcuts.getShortcut("Player/aIncT"));
|
||||
aDecT->setShortcuts(shortcuts.getShortcut("Player/aDecT"));
|
||||
aIncPT->setShortcuts(shortcuts.getShortcut("Player/aIncPT"));
|
||||
aDecPT->setShortcuts(shortcuts.getShortcut("Player/aDecPT"));
|
||||
aFlowP->setShortcuts(shortcuts.getShortcut("Player/aFlowP"));
|
||||
aFlowT->setShortcuts(shortcuts.getShortcut("Player/aFlowT"));
|
||||
aSetPT->setShortcuts(shortcuts.getShortcut("Player/aSetPT"));
|
||||
aResetPT->setShortcuts(shortcuts.getShortcut("Player/aResetPT"));
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/**
|
||||
* @file pt_menu.h
|
||||
* @ingroup GameMenusCards
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_PT_MENU_H
|
||||
#define COCKATRICE_PT_MENU_H
|
||||
#include <QMenu>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class PtMenu : public QMenu
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PtMenu(PlayerGraphicsItem *player);
|
||||
void retranslateUi();
|
||||
void setShortcutsActive();
|
||||
|
||||
QAction *aIncP = nullptr;
|
||||
QAction *aDecP = nullptr;
|
||||
QAction *aFlowP = nullptr;
|
||||
QAction *aIncT = nullptr;
|
||||
QAction *aDecT = nullptr;
|
||||
QAction *aFlowT = nullptr;
|
||||
|
||||
QAction *aIncPT = nullptr;
|
||||
QAction *aDecPT = nullptr;
|
||||
QAction *aSetPT = nullptr;
|
||||
QAction *aResetPT = nullptr;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PT_MENU_H
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
#include "rfg_menu.h"
|
||||
|
||||
#include "../player_actions.h"
|
||||
#include "../player_logic.h"
|
||||
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
RfgMenu::RfgMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
|
||||
{
|
||||
createMoveActions();
|
||||
createViewActions();
|
||||
|
||||
addAction(aViewRfg);
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
addSeparator();
|
||||
moveRfgMenu = addTearOffMenu(QString());
|
||||
moveRfgMenu->addAction(aMoveRfgToTopLibrary);
|
||||
moveRfgMenu->addAction(aMoveRfgToBottomLibrary);
|
||||
moveRfgMenu->addSeparator();
|
||||
moveRfgMenu->addAction(aMoveRfgToHand);
|
||||
moveRfgMenu->addSeparator();
|
||||
moveRfgMenu->addAction(aMoveRfgToGrave);
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void RfgMenu::createMoveActions()
|
||||
{
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
auto rfg = player->getLogic()->getRfgZone();
|
||||
|
||||
aMoveRfgToTopLibrary = new QAction(this);
|
||||
aMoveRfgToTopLibrary->setData(QList<QVariant>() << ZoneNames::DECK << 0);
|
||||
aMoveRfgToBottomLibrary = new QAction(this);
|
||||
aMoveRfgToBottomLibrary->setData(QList<QVariant>() << ZoneNames::DECK << -1);
|
||||
aMoveRfgToHand = new QAction(this);
|
||||
aMoveRfgToHand->setData(QList<QVariant>() << ZoneNames::HAND << 0);
|
||||
aMoveRfgToGrave = new QAction(this);
|
||||
aMoveRfgToGrave->setData(QList<QVariant>() << ZoneNames::GRAVE << 0);
|
||||
|
||||
connect(aMoveRfgToTopLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone);
|
||||
connect(aMoveRfgToBottomLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone);
|
||||
connect(aMoveRfgToHand, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone);
|
||||
connect(aMoveRfgToGrave, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone);
|
||||
}
|
||||
}
|
||||
|
||||
void RfgMenu::createViewActions()
|
||||
{
|
||||
PlayerActions *playerActions = player->getLogic()->getPlayerActions();
|
||||
|
||||
aViewRfg = new QAction(this);
|
||||
connect(aViewRfg, &QAction::triggered, playerActions, &PlayerActions::actViewRfg);
|
||||
}
|
||||
|
||||
void RfgMenu::retranslateUi()
|
||||
{
|
||||
setTitle(tr("&Exile"));
|
||||
|
||||
aViewRfg->setText(tr("&View exile"));
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
moveRfgMenu->setTitle(tr("&Move exile to..."));
|
||||
aMoveRfgToTopLibrary->setText(tr("&Top of library"));
|
||||
aMoveRfgToBottomLibrary->setText(tr("&Bottom of library"));
|
||||
aMoveRfgToHand->setText(tr("&Hand"));
|
||||
aMoveRfgToGrave->setText(tr("&Graveyard"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* @file rfg_menu.h
|
||||
* @ingroup GameMenusZones
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_RFG_MENU_H
|
||||
#define COCKATRICE_RFG_MENU_H
|
||||
|
||||
#include "../../../interface/widgets/menus/tearoff_menu.h"
|
||||
#include "abstract_player_component.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class RfgMenu : public TearOffMenu, public AbstractPlayerComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RfgMenu(PlayerGraphicsItem *player, QWidget *parent = nullptr);
|
||||
void createMoveActions();
|
||||
void createViewActions();
|
||||
void retranslateUi() override;
|
||||
void setShortcutsActive() override
|
||||
{
|
||||
}
|
||||
void setShortcutsInactive() override
|
||||
{
|
||||
}
|
||||
|
||||
QMenu *moveRfgMenu = nullptr;
|
||||
|
||||
QAction *aViewRfg = nullptr;
|
||||
QAction *aMoveRfgToTopLibrary = nullptr;
|
||||
QAction *aMoveRfgToBottomLibrary = nullptr;
|
||||
QAction *aMoveRfgToHand = nullptr;
|
||||
QAction *aMoveRfgToGrave = nullptr;
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_RFG_MENU_H
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
#include "say_menu.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
#include "../player_actions.h"
|
||||
#include "../player_logic.h"
|
||||
|
||||
SayMenu::SayMenu(PlayerGraphicsItem *_player) : player(_player)
|
||||
{
|
||||
connect(&SettingsCache::instance().messages(), &MessageSettings::messageMacrosChanged, this, &SayMenu::initSayMenu);
|
||||
initSayMenu();
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void SayMenu::retranslateUi()
|
||||
{
|
||||
setTitle(tr("S&ay"));
|
||||
}
|
||||
|
||||
void SayMenu::setShortcutsActive()
|
||||
{
|
||||
shortcutsActive = true;
|
||||
|
||||
const auto menuActions = actions();
|
||||
for (int i = 0; i < menuActions.size() && i < 10; ++i) {
|
||||
menuActions[i]->setShortcut(QKeySequence("Ctrl+" + QString::number((i + 1) % 10)));
|
||||
}
|
||||
}
|
||||
|
||||
void SayMenu::setShortcutsInactive()
|
||||
{
|
||||
shortcutsActive = false;
|
||||
|
||||
for (auto *action : actions()) {
|
||||
action->setShortcut(QKeySequence());
|
||||
}
|
||||
}
|
||||
|
||||
void SayMenu::initSayMenu()
|
||||
{
|
||||
clear();
|
||||
|
||||
int count = SettingsCache::instance().messages().getCount();
|
||||
setEnabled(count > 0);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
auto *newAction = new QAction(SettingsCache::instance().messages().getMessageAt(i), this);
|
||||
connect(newAction, &QAction::triggered, player->getLogic()->getPlayerActions(), &PlayerActions::actSayMessage);
|
||||
addAction(newAction);
|
||||
}
|
||||
|
||||
if (shortcutsActive) {
|
||||
setShortcutsActive();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* @file say_menu.h
|
||||
* @ingroup GameMenusPlayers
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_SAY_MENU_H
|
||||
#define COCKATRICE_SAY_MENU_H
|
||||
|
||||
#include "abstract_player_component.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class SayMenu : public QMenu, public AbstractPlayerComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SayMenu(PlayerGraphicsItem *player);
|
||||
|
||||
void retranslateUi() override;
|
||||
void setShortcutsActive() override;
|
||||
void setShortcutsInactive() override;
|
||||
|
||||
private slots:
|
||||
void initSayMenu();
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
bool shortcutsActive = false;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_SAY_MENU_H
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
#include "sideboard_menu.h"
|
||||
|
||||
#include "../player_actions.h"
|
||||
#include "../player_logic.h"
|
||||
|
||||
SideboardMenu::SideboardMenu(PlayerGraphicsItem *player, QMenu *playerMenu) : QMenu(playerMenu)
|
||||
{
|
||||
aViewSideboard = new QAction(this);
|
||||
connect(aViewSideboard, &QAction::triggered, player->getLogic()->getPlayerActions(),
|
||||
&PlayerActions::actViewSideboard);
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
addAction(aViewSideboard);
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void SideboardMenu::retranslateUi()
|
||||
{
|
||||
setTitle(tr("&Sideboard"));
|
||||
aViewSideboard->setText(tr("&View sideboard"));
|
||||
}
|
||||
|
||||
void SideboardMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
||||
aViewSideboard->setShortcuts(shortcuts.getShortcut("Player/aViewSideboard"));
|
||||
}
|
||||
|
||||
void SideboardMenu::setShortcutsInactive()
|
||||
{
|
||||
aViewSideboard->setShortcut(QKeySequence());
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
* @file sideboard_menu.h
|
||||
* @ingroup GameMenusZones
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_SIDEBOARD_MENU_H
|
||||
#define COCKATRICE_SIDEBOARD_MENU_H
|
||||
|
||||
#include "abstract_player_component.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class SideboardMenu : public QMenu, public AbstractPlayerComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SideboardMenu(PlayerGraphicsItem *player, QMenu *playerMenu);
|
||||
void retranslateUi() override;
|
||||
void setShortcutsActive() override;
|
||||
void setShortcutsInactive() override;
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
|
||||
QAction *aViewSideboard;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_SIDEBOARD_MENU_H
|
||||
|
|
@ -1,146 +0,0 @@
|
|||
#include "utility_menu.h"
|
||||
|
||||
#include "../../../interface/deck_loader/deck_loader.h"
|
||||
#include "../player_actions.h"
|
||||
#include "../player_logic.h"
|
||||
#include "player_menu.h"
|
||||
|
||||
#include <libcockatrice/deck_list/tree/deck_list_card_node.h>
|
||||
#include <libcockatrice/deck_list/tree/inner_deck_list_node.h>
|
||||
|
||||
UtilityMenu::UtilityMenu(PlayerGraphicsItem *_player, QMenu *playerMenu) : QMenu(playerMenu), player(_player)
|
||||
{
|
||||
PlayerActions *playerActions = player->getLogic()->getPlayerActions();
|
||||
connect(playerActions, &PlayerActions::requestEnableAndSetCreateAnotherTokenAction, this,
|
||||
&UtilityMenu::setAndEnableCreateAnotherTokenAction);
|
||||
connect(playerActions, &PlayerActions::requestSetLastToken, this, &UtilityMenu::setLastToken);
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aUntapAll = new QAction(this);
|
||||
connect(aUntapAll, &QAction::triggered, playerActions, &PlayerActions::actUntapAll);
|
||||
|
||||
aRollDie = new QAction(this);
|
||||
connect(aRollDie, &QAction::triggered, playerActions, &PlayerActions::actRequestRollDieDialog);
|
||||
|
||||
aFlipCoin = new QAction(this);
|
||||
connect(aFlipCoin, &QAction::triggered, playerActions, &PlayerActions::actFlipCoin);
|
||||
|
||||
aCreateToken = new QAction(this);
|
||||
connect(aCreateToken, &QAction::triggered, playerActions, [this]() {
|
||||
player->getLogic()->getPlayerActions()->actRequestCreateTokenDialog(getPredefinedTokens());
|
||||
});
|
||||
|
||||
aCreateAnotherToken = new QAction(this);
|
||||
connect(aCreateAnotherToken, &QAction::triggered, playerActions, &PlayerActions::actCreateAnotherToken);
|
||||
aCreateAnotherToken->setEnabled(false);
|
||||
|
||||
aIncrementAllCardCounters = new QAction(this);
|
||||
connect(aIncrementAllCardCounters, &QAction::triggered, playerActions, [this]() {
|
||||
player->getLogic()->getPlayerActions()->actIncrementAllCardCounters(
|
||||
player->getGameScene()->selectedCards());
|
||||
});
|
||||
|
||||
createPredefinedTokenMenu = new QMenu(QString());
|
||||
createPredefinedTokenMenu->setEnabled(false);
|
||||
connect(player->getLogic(), &PlayerLogic::deckChanged, this, &UtilityMenu::populatePredefinedTokensMenu);
|
||||
|
||||
playerMenu->addAction(aIncrementAllCardCounters);
|
||||
playerMenu->addSeparator();
|
||||
playerMenu->addAction(aUntapAll);
|
||||
playerMenu->addSeparator();
|
||||
playerMenu->addAction(aRollDie);
|
||||
playerMenu->addAction(aFlipCoin);
|
||||
playerMenu->addSeparator();
|
||||
playerMenu->addAction(aCreateToken);
|
||||
playerMenu->addAction(aCreateAnotherToken);
|
||||
playerMenu->addMenu(createPredefinedTokenMenu);
|
||||
playerMenu->addSeparator();
|
||||
} else {
|
||||
aCreateToken = nullptr;
|
||||
aCreateAnotherToken = nullptr;
|
||||
createPredefinedTokenMenu = nullptr;
|
||||
aIncrementAllCardCounters = nullptr;
|
||||
aUntapAll = nullptr;
|
||||
aRollDie = nullptr;
|
||||
aFlipCoin = nullptr;
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void UtilityMenu::populatePredefinedTokensMenu()
|
||||
{
|
||||
clear();
|
||||
setEnabled(false);
|
||||
predefinedTokens.clear();
|
||||
const DeckList &deckList = player->getLogic()->getDeck();
|
||||
|
||||
if (deckList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto tokenCardNodes = deckList.getCardNodes({DECK_ZONE_TOKENS});
|
||||
|
||||
if (!tokenCardNodes.isEmpty()) {
|
||||
setEnabled(true);
|
||||
|
||||
for (int i = 0; i < tokenCardNodes.size(); ++i) {
|
||||
const QString tokenName = tokenCardNodes[i]->getName();
|
||||
predefinedTokens.append(tokenName);
|
||||
QAction *a = addAction(tokenName);
|
||||
if (i < 10) {
|
||||
a->setShortcut(QKeySequence("Alt+" + QString::number((i + 1) % 10)));
|
||||
}
|
||||
connect(a, &QAction::triggered, player->getLogic()->getPlayerActions(),
|
||||
&PlayerActions::actCreatePredefinedToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityMenu::setLastToken(CardInfoPtr lastToken)
|
||||
{
|
||||
if (!createAnotherTokenActionExists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
player->getLogic()->getPlayerActions()->setLastTokenInfo(lastToken);
|
||||
}
|
||||
|
||||
void UtilityMenu::retranslateUi()
|
||||
{
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aIncrementAllCardCounters->setText(tr("Increment all card counters"));
|
||||
aUntapAll->setText(tr("&Untap all permanents"));
|
||||
aRollDie->setText(tr("R&oll die..."));
|
||||
aFlipCoin->setText(tr("Flip coin"));
|
||||
aCreateToken->setText(tr("&Create token..."));
|
||||
aCreateAnotherToken->setText(tr("C&reate another token"));
|
||||
createPredefinedTokenMenu->setTitle(tr("Cr&eate predefined token"));
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aIncrementAllCardCounters->setShortcuts(shortcuts.getShortcut("Player/aIncrementAllCardCounters"));
|
||||
aUntapAll->setShortcuts(shortcuts.getShortcut("Player/aUntapAll"));
|
||||
aRollDie->setShortcuts(shortcuts.getShortcut("Player/aRollDie"));
|
||||
aFlipCoin->setShortcuts(shortcuts.getShortcut("Player/aFlipCoin"));
|
||||
aCreateToken->setShortcuts(shortcuts.getShortcut("Player/aCreateToken"));
|
||||
aCreateAnotherToken->setShortcuts(shortcuts.getShortcut("Player/aCreateAnotherToken"));
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityMenu::setShortcutsInactive()
|
||||
{
|
||||
if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aUntapAll->setShortcut(QKeySequence());
|
||||
aRollDie->setShortcut(QKeySequence());
|
||||
aFlipCoin->setShortcut(QKeySequence());
|
||||
aCreateToken->setShortcut(QKeySequence());
|
||||
aCreateAnotherToken->setShortcut(QKeySequence());
|
||||
aIncrementAllCardCounters->setShortcut(QKeySequence());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/**
|
||||
* @file utility_menu.h
|
||||
* @ingroup GameMenusPlayers
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_UTILITY_MENU_H
|
||||
#define COCKATRICE_UTILITY_MENU_H
|
||||
|
||||
#include "abstract_player_component.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <libcockatrice/card/card_info.h>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class UtilityMenu : public QMenu, public AbstractPlayerComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
void populatePredefinedTokensMenu();
|
||||
void setLastToken(CardInfoPtr lastToken);
|
||||
void retranslateUi() override;
|
||||
void setShortcutsActive() override;
|
||||
void setShortcutsInactive() override;
|
||||
|
||||
public:
|
||||
explicit UtilityMenu(PlayerGraphicsItem *player, QMenu *playerMenu);
|
||||
|
||||
[[nodiscard]] bool createAnotherTokenActionExists() const
|
||||
{
|
||||
return aCreateAnotherToken != nullptr;
|
||||
}
|
||||
|
||||
void setAndEnableCreateAnotherTokenAction(QString text)
|
||||
{
|
||||
aCreateAnotherToken->setText(tr("C&reate another %1 token").arg(text));
|
||||
aCreateAnotherToken->setEnabled(true);
|
||||
}
|
||||
|
||||
QStringList getPredefinedTokens() const
|
||||
{
|
||||
return predefinedTokens;
|
||||
}
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
QStringList predefinedTokens;
|
||||
|
||||
QMenu *createPredefinedTokenMenu;
|
||||
|
||||
QAction *aIncrementAllCardCounters;
|
||||
QAction *aUntapAll, *aRollDie, *aFlipCoin;
|
||||
QAction *aCreateToken, *aCreateAnotherToken;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_UTILITY_MENU_H
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
#include "player_actions.h"
|
||||
|
||||
#include "../../game_graphics/dialogs/dlg_move_top_cards_until.h"
|
||||
#include "../../game_graphics/dialogs/dlg_roll_dice.h"
|
||||
#include "../../game_graphics/player/card_menu_action_type.h"
|
||||
#include "../../game_graphics/zones/hand_zone.h"
|
||||
#include "../../game_graphics/zones/table_zone.h"
|
||||
#include "../../interface/widgets/tabs/tab_game.h"
|
||||
#include "../../interface/widgets/utility/get_text_with_max.h"
|
||||
#include "../board/card_item.h"
|
||||
#include "../dialogs/dlg_move_top_cards_until.h"
|
||||
#include "../dialogs/dlg_roll_dice.h"
|
||||
#include "../zones/view_zone_logic.h"
|
||||
#include "card_menu_action_type.h"
|
||||
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
#include <libcockatrice/card/relation/card_relation.h>
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
#ifndef COCKATRICE_PLAYER_ACTIONS_H
|
||||
#define COCKATRICE_PLAYER_ACTIONS_H
|
||||
#include "../dialogs/dlg_create_token.h"
|
||||
#include "../dialogs/dlg_move_top_cards_until.h"
|
||||
#include "card_menu_action_type.h"
|
||||
|
||||
#include "../../game_graphics/board/card_item.h"
|
||||
#include "../../game_graphics/dialogs/dlg_create_token.h"
|
||||
#include "../../game_graphics/dialogs/dlg_move_top_cards_until.h"
|
||||
#include "../../game_graphics/player/card_menu_action_type.h"
|
||||
#include "event_processing_options.h"
|
||||
#include "player_logic.h"
|
||||
|
||||
|
|
@ -26,7 +28,6 @@ class Message;
|
|||
}
|
||||
} // namespace google
|
||||
|
||||
class CardItem;
|
||||
class Command_MoveCard;
|
||||
class GameEventContext;
|
||||
class PendingCommand;
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
#include "player_area.h"
|
||||
|
||||
#include "../../interface/theme_manager.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
PlayerArea::PlayerArea(QGraphicsItem *parentItem) : QObject(), QGraphicsItem(parentItem)
|
||||
{
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
connect(themeManager, &ThemeManager::themeChanged, this, &PlayerArea::updateBg);
|
||||
updateBg();
|
||||
}
|
||||
|
||||
void PlayerArea::updateBg()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
QBrush brush = themeManager->getExtraBgBrush(ThemeManager::Player, playerZoneId);
|
||||
painter->fillRect(boundingRect(), brush);
|
||||
}
|
||||
|
||||
void PlayerArea::setSize(qreal width, qreal height)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
bRect = QRectF(0, 0, width, height);
|
||||
}
|
||||
|
||||
void PlayerArea::setPlayerZoneId(int _playerZoneId)
|
||||
{
|
||||
playerZoneId = _playerZoneId;
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* @file player_area.h
|
||||
* @ingroup GameGraphicsPlayers
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_PLAYER_AREA_H
|
||||
#define COCKATRICE_PLAYER_AREA_H
|
||||
|
||||
#include "../../game_graphics/board/graphics_item_type.h"
|
||||
#include "QGraphicsItem"
|
||||
|
||||
/**
|
||||
* The entire graphical area belonging to a single player.
|
||||
*/
|
||||
class PlayerArea : public QObject, public QGraphicsItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QGraphicsItem)
|
||||
private:
|
||||
QRectF bRect;
|
||||
int playerZoneId;
|
||||
private slots:
|
||||
void updateBg();
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
Type = typeOther
|
||||
};
|
||||
[[nodiscard]] int type() const override
|
||||
{
|
||||
return Type;
|
||||
}
|
||||
|
||||
explicit PlayerArea(QGraphicsItem *parent = nullptr);
|
||||
[[nodiscard]] QRectF boundingRect() const override
|
||||
{
|
||||
return bRect;
|
||||
}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
void setSize(qreal width, qreal height);
|
||||
|
||||
void setPlayerZoneId(int _playerZoneId);
|
||||
[[nodiscard]] int getPlayerZoneId() const
|
||||
{
|
||||
return playerZoneId;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_AREA_H
|
||||
|
|
@ -1,298 +0,0 @@
|
|||
#include "player_dialogs.h"
|
||||
|
||||
#include "../../client/settings/card_counter_settings.h"
|
||||
#include "../../interface/widgets/utility/get_text_with_max.h"
|
||||
#include "../board/card_item.h"
|
||||
#include "../dialogs/dlg_roll_dice.h"
|
||||
#include "../player/player_graphics_item.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <libcockatrice/card/relation/card_relation.h>
|
||||
|
||||
PlayerDialogs::PlayerDialogs(PlayerGraphicsItem *_player, PlayerActions *_playerActions)
|
||||
: QObject(_player), player(_player), playerActions(_playerActions)
|
||||
{
|
||||
connect(playerActions, &PlayerActions::requestViewTopCardsDialog, this,
|
||||
&PlayerDialogs::onViewTopCardsDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestViewBottomCardsDialog, this,
|
||||
&PlayerDialogs::onViewBottomCardsDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestShuffleTopDialog, this, &PlayerDialogs::onShuffleTopDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestShuffleBottomDialog, this,
|
||||
&PlayerDialogs::onShuffleBottomDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestMulliganDialog, this, &PlayerDialogs::onMulliganDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestDrawCardsDialog, this, &PlayerDialogs::onDrawCardsDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestMoveTopCardsToDialog, this,
|
||||
&PlayerDialogs::onMoveTopCardsToDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestMoveTopCardsUntilDialog, this,
|
||||
&PlayerDialogs::onMoveTopCardsUntilDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestMoveBottomCardsToDialog, this,
|
||||
&PlayerDialogs::onMoveBottomCardsToDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestDrawBottomCardsDialog, this,
|
||||
&PlayerDialogs::onDrawBottomCardsDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestRollDieDialog, this, &PlayerDialogs::onRollDieDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestCreateTokenDialog, this,
|
||||
&PlayerDialogs::onCreateTokenDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestCreateRelatedFromRelationDialog, this,
|
||||
&PlayerDialogs::onCreateRelatedFromRelationDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestMoveCardXCardsFromTopDialog, this,
|
||||
&PlayerDialogs::onMoveCardXCardsFromTopDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestSetPTDialog, this, &PlayerDialogs::onSetPTDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestSetAnnotationDialog, this,
|
||||
&PlayerDialogs::onSetAnnotationDialogRequested);
|
||||
|
||||
connect(playerActions, &PlayerActions::requestSetCardCounterDialog, this,
|
||||
&PlayerDialogs::onSetCardCounterDialogRequested);
|
||||
}
|
||||
|
||||
void PlayerDialogs::onViewTopCardsDialogRequested(int defaultNumberTopCards, int deckSize)
|
||||
{
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(dialogParent(), tr("View top cards of library"),
|
||||
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1,
|
||||
deckSize, 1, &ok);
|
||||
if (ok) {
|
||||
playerActions->actViewTopCards(number);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onViewBottomCardsDialogRequested(int defaultNumberBottomCards, int deckSize)
|
||||
{
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(dialogParent(), tr("View bottom cards of library"),
|
||||
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberBottomCards, 1,
|
||||
deckSize, 1, &ok);
|
||||
if (ok) {
|
||||
playerActions->actViewBottomCards(number);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onShuffleTopDialogRequested(int defaultNumberTopCards, int maxCards)
|
||||
{
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(dialogParent(), tr("Shuffle top cards of library"),
|
||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
||||
maxCards, 1, &ok);
|
||||
if (ok) {
|
||||
playerActions->actShuffleTop(number);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onShuffleBottomDialogRequested(int defaultNumberBottomCards, int maxCards)
|
||||
{
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(dialogParent(), tr("Shuffle bottom cards of library"),
|
||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
||||
maxCards, 1, &ok);
|
||||
if (ok) {
|
||||
playerActions->actShuffleBottom(number);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onMulliganDialogRequested(int startSize, int handSize, int deckSize)
|
||||
{
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(dialogParent(), tr("Draw hand"),
|
||||
tr("Number of cards: (max. %1)").arg(deckSize) + '\n' +
|
||||
tr("0 and lower are in comparison to current hand size"),
|
||||
startSize, -handSize, deckSize, 1, &ok);
|
||||
|
||||
if (ok) {
|
||||
playerActions->actMulligan(number);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onDrawCardsDialogRequested(int defaultNumberTopCards, int deckSize)
|
||||
{
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(dialogParent(), tr("Draw cards"), tr("Number of cards: (max. %1)").arg(deckSize),
|
||||
defaultNumberTopCards, 1, deckSize, 1, &ok);
|
||||
|
||||
if (ok) {
|
||||
playerActions->actDrawCards(number);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onMoveTopCardsToDialogRequested(int defaultNumberTopCards,
|
||||
int maxCards,
|
||||
const QString &targetZone,
|
||||
const QString &zoneDisplayName,
|
||||
bool faceDown)
|
||||
{
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(dialogParent(), tr("Move top cards to %1").arg(zoneDisplayName),
|
||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
||||
maxCards, 1, &ok);
|
||||
if (ok) {
|
||||
playerActions->moveTopCardsTo(number, targetZone, faceDown);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onMoveTopCardsUntilDialogRequested(MoveTopCardsUntilOptions options)
|
||||
{
|
||||
DlgMoveTopCardsUntil dlg(dialogParent(), options);
|
||||
if (!dlg.exec()) {
|
||||
return;
|
||||
}
|
||||
playerActions->moveTopCardsUntil(dlg.getExpr(), dlg.getOptions());
|
||||
}
|
||||
|
||||
void PlayerDialogs::onMoveBottomCardsToDialogRequested(int defaultNumberBottomCards,
|
||||
int maxCards,
|
||||
const QString &targetZone,
|
||||
const QString &zoneDisplayName,
|
||||
bool faceDown)
|
||||
{
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(dialogParent(), tr("Move bottom cards to %1").arg(zoneDisplayName),
|
||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
||||
maxCards, 1, &ok);
|
||||
if (ok) {
|
||||
playerActions->moveBottomCardsTo(number, targetZone, faceDown);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onDrawBottomCardsDialogRequested(int defaultNumberBottomCards, int maxCards)
|
||||
{
|
||||
bool ok;
|
||||
int number =
|
||||
QInputDialog::getInt(dialogParent(), tr("Draw bottom cards"), tr("Number of cards: (max. %1)").arg(maxCards),
|
||||
defaultNumberBottomCards, 1, maxCards, 1, &ok);
|
||||
if (ok) {
|
||||
playerActions->actDrawBottomCards(number);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onRollDieDialogRequested()
|
||||
{
|
||||
DlgRollDice dlg(dialogParent());
|
||||
if (!dlg.exec()) {
|
||||
return;
|
||||
}
|
||||
playerActions->actRollDie(dlg.getDieSideCount(), dlg.getDiceToRollCount());
|
||||
}
|
||||
|
||||
void PlayerDialogs::onCreateRelatedFromRelationDialogRequested(const CardItem *sourceCard,
|
||||
const CardRelation *cardRelation)
|
||||
{
|
||||
if (sourceCard == nullptr || cardRelation == nullptr) {
|
||||
playerActions->setLastRelatedCreationSucceeded(false);
|
||||
return;
|
||||
}
|
||||
|
||||
int variableCount = cardRelation->getDefaultCount();
|
||||
|
||||
if (cardRelation->getIsVariable()) {
|
||||
bool ok;
|
||||
|
||||
emit requestDialogSemaphore(true);
|
||||
|
||||
variableCount = QInputDialog::getInt(dialogParent(), tr("Create tokens"), tr("Number:"),
|
||||
cardRelation->getDefaultCount(), 1, MAX_TOKENS_PER_DIALOG, 1, &ok);
|
||||
|
||||
emit requestDialogSemaphore(false);
|
||||
|
||||
if (!ok) {
|
||||
playerActions->setLastRelatedCreationSucceeded(false); // cancelled
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const bool succeeded = playerActions->createRelatedFromRelation(sourceCard, cardRelation, variableCount);
|
||||
|
||||
playerActions->setLastRelatedCreationSucceeded(succeeded);
|
||||
|
||||
if (succeeded) {
|
||||
playerActions->onRelatedCardCreated(sourceCard, cardRelation); // only on confirmed success
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onCreateTokenDialogRequested(const QStringList &predefinedTokens)
|
||||
{
|
||||
DlgCreateToken dlg(predefinedTokens, dialogParent());
|
||||
if (!dlg.exec()) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerActions->actCreateToken(dlg.getTokenInfo());
|
||||
}
|
||||
|
||||
void PlayerDialogs::onMoveCardXCardsFromTopDialogRequested(int defaultNumberTopCardsToPlaceBelow, int deckSize)
|
||||
{
|
||||
bool ok;
|
||||
int number =
|
||||
QInputDialog::getInt(dialogParent(), tr("Place card X cards from top of library"),
|
||||
tr("Which position should this card be placed:") + "\n" + tr("(max. %1)").arg(deckSize),
|
||||
defaultNumberTopCardsToPlaceBelow, 1, deckSize, 1, &ok);
|
||||
number -= 1; // indexes start at 0
|
||||
|
||||
if (ok) {
|
||||
playerActions->actMoveCardXCardsFromTop(player->getGameScene()->selectedCards(), number);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDialogs::onSetPTDialogRequested(const QString &oldPT)
|
||||
{
|
||||
bool ok;
|
||||
auto cards = player->getGameScene()->selectedCards();
|
||||
emit requestDialogSemaphore(true);
|
||||
QString pt = getTextWithMax(dialogParent(), tr("Change power/toughness"), tr("Change stats to:"), QLineEdit::Normal,
|
||||
oldPT, &ok);
|
||||
emit requestDialogSemaphore(false);
|
||||
|
||||
if (!ok || player->getLogic()->clearCardsToDelete()) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerActions->actSetPT(cards, pt);
|
||||
}
|
||||
|
||||
void PlayerDialogs::onSetAnnotationDialogRequested(const QString &oldAnnotation)
|
||||
{
|
||||
auto cards = player->getGameScene()->selectedCards();
|
||||
emit requestDialogSemaphore(true);
|
||||
AnnotationDialog *dialog = new AnnotationDialog(dialogParent());
|
||||
dialog->setOptions(QInputDialog::UsePlainTextEditForTextInput);
|
||||
dialog->setWindowTitle(tr("Set annotation"));
|
||||
dialog->setLabelText(tr("Please enter the new annotation:"));
|
||||
dialog->setTextValue(oldAnnotation);
|
||||
bool ok = dialog->exec();
|
||||
emit requestDialogSemaphore(false);
|
||||
if (!ok || player->getLogic()->clearCardsToDelete()) {
|
||||
return;
|
||||
}
|
||||
QString annotation = dialog->textValue().left(MAX_NAME_LENGTH);
|
||||
playerActions->actSetAnnotation(cards, annotation);
|
||||
}
|
||||
|
||||
void PlayerDialogs::onSetCardCounterDialogRequested(int counterId, const QString &oldValueForDlg)
|
||||
{
|
||||
auto cards = player->getGameScene()->selectedCards();
|
||||
emit requestDialogSemaphore(true);
|
||||
|
||||
auto &cardCounterSettings = SettingsCache::instance().cardCounters();
|
||||
QString counterName = cardCounterSettings.displayName(counterId);
|
||||
|
||||
AbstractCounterDialog dialog(counterName, oldValueForDlg, dialogParent());
|
||||
int ok = dialog.exec();
|
||||
|
||||
emit requestDialogSemaphore(false);
|
||||
if (!ok || player->getLogic()->clearCardsToDelete()) {
|
||||
return;
|
||||
}
|
||||
playerActions->actSetCardCounter(cards, counterId, dialog.textValue());
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
#ifndef COCKATRICE_PLAYER_DIALOGS_H
|
||||
#define COCKATRICE_PLAYER_DIALOGS_H
|
||||
#include "player_actions.h"
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QObject>
|
||||
|
||||
class PlayerGraphicsItem;
|
||||
class PlayerDialogs : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PlayerDialogs(PlayerGraphicsItem *player, PlayerActions *playerActions);
|
||||
|
||||
signals:
|
||||
void requestDialogSemaphore(bool active);
|
||||
|
||||
public slots:
|
||||
void onViewTopCardsDialogRequested(int defaultNumberTopCards, int deckSize);
|
||||
void onViewBottomCardsDialogRequested(int defaultNumberBottomCards, int deckSize);
|
||||
void onShuffleTopDialogRequested(int defaultNumberTopCards, int maxCards);
|
||||
void onShuffleBottomDialogRequested(int defaultNumberBottomCards, int maxCards);
|
||||
void onMulliganDialogRequested(int startSize, int handSize, int deckSize);
|
||||
void onDrawCardsDialogRequested(int defaultNumberTopCards, int deckSize);
|
||||
void onMoveTopCardsToDialogRequested(int defaultNumberTopCards,
|
||||
int maxCards,
|
||||
const QString &targetZone,
|
||||
const QString &zoneDisplayName,
|
||||
bool faceDown);
|
||||
void onMoveTopCardsUntilDialogRequested(MoveTopCardsUntilOptions options);
|
||||
void onMoveBottomCardsToDialogRequested(int defaultNumberBottomCards,
|
||||
int maxCards,
|
||||
const QString &targetZone,
|
||||
const QString &zoneDisplayName,
|
||||
bool faceDown);
|
||||
void onDrawBottomCardsDialogRequested(int defaultNumberBottomCards, int maxCards);
|
||||
void onRollDieDialogRequested();
|
||||
void onCreateRelatedFromRelationDialogRequested(const CardItem *sourceCard, const CardRelation *cardRelation);
|
||||
void onCreateTokenDialogRequested(const QStringList &predefinedTokens);
|
||||
void onMoveCardXCardsFromTopDialogRequested(int defaultNumberTopCardsToPlaceBelow, int deckSize);
|
||||
void onSetPTDialogRequested(const QString &oldPT);
|
||||
void onSetAnnotationDialogRequested(const QString &oldAnnotation);
|
||||
void onSetCardCounterDialogRequested(int counterId, const QString &oldValueForDlg);
|
||||
|
||||
private:
|
||||
PlayerGraphicsItem *player;
|
||||
PlayerActions *playerActions;
|
||||
|
||||
QWidget *dialogParent() const
|
||||
{
|
||||
if (auto *s = player->scene()) {
|
||||
if (auto *v = s->views().value(0)) {
|
||||
return v->window();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_DIALOGS_H
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
#include "player_event_handler.h"
|
||||
|
||||
#include "../../game_graphics/board/arrow_item.h"
|
||||
#include "../../game_graphics/board/card_item.h"
|
||||
#include "../../game_graphics/zones/view_zone.h"
|
||||
#include "../../interface/widgets/tabs/tab_game.h"
|
||||
#include "../board/arrow_data.h"
|
||||
#include "../board/arrow_item.h"
|
||||
#include "../board/card_item.h"
|
||||
#include "../board/card_list.h"
|
||||
#include "player_actions.h"
|
||||
#include "player_logic.h"
|
||||
|
|
|
|||
|
|
@ -1,282 +0,0 @@
|
|||
#include "player_graphics_item.h"
|
||||
|
||||
#include "../../game_graphics/zones/hand_zone.h"
|
||||
#include "../../game_graphics/zones/pile_zone.h"
|
||||
#include "../../game_graphics/zones/stack_zone.h"
|
||||
#include "../../game_graphics/zones/table_zone.h"
|
||||
#include "../../interface/widgets/tabs/tab_game.h"
|
||||
#include "../board/abstract_card_item.h"
|
||||
#include "../board/counter_general.h"
|
||||
#include "../hand_counter.h"
|
||||
#include "player_actions.h"
|
||||
#include "player_dialogs.h"
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player)
|
||||
{
|
||||
connect(&SettingsCache::instance(), &SettingsCache::horizontalHandChanged, this,
|
||||
&PlayerGraphicsItem::rearrangeZones);
|
||||
connect(&SettingsCache::instance(), &SettingsCache::handJustificationChanged, this,
|
||||
&PlayerGraphicsItem::rearrangeZones);
|
||||
connect(player, &PlayerLogic::rearrangeCounters, this, &PlayerGraphicsItem::rearrangeCounters);
|
||||
connect(player, &PlayerLogic::activeChanged, this, &PlayerGraphicsItem::onPlayerActiveChanged);
|
||||
connect(player, &PlayerLogic::concededChanged, this, [this](int, bool c) { setVisible(!c); });
|
||||
connect(player, &PlayerLogic::zoneIdChanged, this, [this](int id) { playerArea->setPlayerZoneId(id); });
|
||||
|
||||
connect(player, &PlayerLogic::counterAdded, this, &PlayerGraphicsItem::onCounterAdded);
|
||||
connect(player, &PlayerLogic::counterRemoved, this, &PlayerGraphicsItem::onCounterRemoved);
|
||||
|
||||
playerMenu = new PlayerMenu(this);
|
||||
|
||||
connect(playerMenu, &PlayerMenu::shortcutsActivated, this, [this]() {
|
||||
for (auto *ctr : counterWidgets) {
|
||||
ctr->setShortcutsActive();
|
||||
}
|
||||
});
|
||||
connect(playerMenu, &PlayerMenu::shortcutsDeactivated, this, [this]() {
|
||||
for (auto *ctr : counterWidgets) {
|
||||
ctr->setShortcutsInactive();
|
||||
}
|
||||
});
|
||||
connect(playerMenu, &PlayerMenu::retranslateRequested, this, [this]() {
|
||||
for (auto *ctr : counterWidgets) {
|
||||
ctr->retranslateUi();
|
||||
}
|
||||
});
|
||||
|
||||
playerDialogs = new PlayerDialogs(this, player->getPlayerActions());
|
||||
|
||||
connect(playerDialogs, &PlayerDialogs::requestDialogSemaphore, player, &PlayerLogic::setDialogSemaphore);
|
||||
|
||||
playerArea = new PlayerArea(this);
|
||||
|
||||
playerTarget = new PlayerTarget(player, playerArea);
|
||||
qreal avatarMargin =
|
||||
(counterAreaWidth + CardDimensions::HEIGHT_F + 15 - playerTarget->boundingRect().width()) / 2.0;
|
||||
playerTarget->setPos(QPointF(avatarMargin, avatarMargin));
|
||||
|
||||
initializeZones();
|
||||
|
||||
playerMenu->setMenusForGraphicItems();
|
||||
|
||||
connect(tableZoneGraphicsItem, &TableZone::sizeChanged, this, &PlayerGraphicsItem::updateBoundingRect);
|
||||
|
||||
updateBoundingRect();
|
||||
|
||||
rearrangeZones();
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::retranslateUi()
|
||||
{
|
||||
playerMenu->retranslateUi();
|
||||
|
||||
QMapIterator<QString, CardZoneLogic *> zoneIterator(player->getZones());
|
||||
while (zoneIterator.hasNext()) {
|
||||
emit zoneIterator.next().value()->retranslateUi();
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::onPlayerActiveChanged(bool _active)
|
||||
{
|
||||
tableZoneGraphicsItem->setActive(_active);
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::initializeZones()
|
||||
{
|
||||
deckZoneGraphicsItem = new PileZone(player->getDeckZone(), this);
|
||||
auto base = QPointF(counterAreaWidth + (CardDimensions::HEIGHT_F - CardDimensions::WIDTH_F + 15) / 2.0,
|
||||
10 + playerTarget->boundingRect().height() + 5 -
|
||||
(CardDimensions::HEIGHT_F - CardDimensions::WIDTH_F) / 2.0);
|
||||
deckZoneGraphicsItem->setPos(base);
|
||||
|
||||
qreal h = deckZoneGraphicsItem->boundingRect().width() + 5;
|
||||
|
||||
sideboardGraphicsItem = new PileZone(player->getSideboardZone(), this);
|
||||
player->getSideboardZone()->setGraphicsVisibility(false);
|
||||
|
||||
auto *handCounter = new HandCounter(playerArea);
|
||||
handCounter->setPos(base + QPointF(0, h + 10));
|
||||
qreal h2 = handCounter->boundingRect().height();
|
||||
|
||||
graveyardZoneGraphicsItem = new PileZone(player->getGraveZone(), this);
|
||||
graveyardZoneGraphicsItem->setPos(base + QPointF(0, h + h2 + 10));
|
||||
|
||||
rfgZoneGraphicsItem = new PileZone(player->getRfgZone(), this);
|
||||
rfgZoneGraphicsItem->setPos(base + QPointF(0, 2 * h + h2 + 10));
|
||||
|
||||
tableZoneGraphicsItem = new TableZone(player->getTableZone(), mirrored, this);
|
||||
connect(tableZoneGraphicsItem, &TableZone::sizeChanged, this, &PlayerGraphicsItem::updateBoundingRect);
|
||||
connect(this, &PlayerGraphicsItem::mirroredChanged, tableZoneGraphicsItem, &TableZone::setMirrored);
|
||||
|
||||
stackZoneGraphicsItem =
|
||||
new StackZone(player->getStackZone(), static_cast<int>(tableZoneGraphicsItem->boundingRect().height()), this);
|
||||
|
||||
handZoneGraphicsItem =
|
||||
new HandZone(player->getHandZone(), static_cast<int>(tableZoneGraphicsItem->boundingRect().height()), this);
|
||||
connect(player->getPlayerActions(), &PlayerActions::requestSortHand, handZoneGraphicsItem, &HandZone::sortHand);
|
||||
|
||||
connect(handZoneGraphicsItem->getLogic(), &HandZoneLogic::cardCountChanged, handCounter,
|
||||
&HandCounter::updateNumber);
|
||||
connect(handCounter, &HandCounter::showContextMenu, handZoneGraphicsItem, &HandZone::showContextMenu);
|
||||
}
|
||||
|
||||
QRectF PlayerGraphicsItem::boundingRect() const
|
||||
{
|
||||
return bRect;
|
||||
}
|
||||
|
||||
qreal PlayerGraphicsItem::getMinimumWidth() const
|
||||
{
|
||||
qreal result = tableZoneGraphicsItem->getMinimumWidth() + CardDimensions::HEIGHT_F + 15 + counterAreaWidth +
|
||||
stackZoneGraphicsItem->boundingRect().width();
|
||||
if (!SettingsCache::instance().getHorizontalHand()) {
|
||||
result += handZoneGraphicsItem->boundingRect().width();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::paint(QPainter * /*painter*/,
|
||||
const QStyleOptionGraphicsItem * /*option*/,
|
||||
QWidget * /*widget*/)
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::processSceneSizeChange(int newPlayerWidth)
|
||||
{
|
||||
// Extend table (and hand, if horizontal) to accommodate the new player width.
|
||||
qreal tableWidth = newPlayerWidth - CardDimensions::HEIGHT_F - 15 - counterAreaWidth -
|
||||
stackZoneGraphicsItem->boundingRect().width();
|
||||
if (!SettingsCache::instance().getHorizontalHand()) {
|
||||
tableWidth -= handZoneGraphicsItem->boundingRect().width();
|
||||
}
|
||||
|
||||
tableZoneGraphicsItem->setWidth(tableWidth);
|
||||
handZoneGraphicsItem->setWidth(tableWidth + stackZoneGraphicsItem->boundingRect().width());
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::setMirrored(bool _mirrored)
|
||||
{
|
||||
if (mirrored != _mirrored) {
|
||||
mirrored = _mirrored;
|
||||
emit mirroredChanged(mirrored);
|
||||
rearrangeZones();
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::onCounterAdded(CounterState *state)
|
||||
{
|
||||
AbstractCounter *widget;
|
||||
if (state->getName() == "life") {
|
||||
widget = playerTarget->addCounter(state);
|
||||
} else {
|
||||
widget = new GeneralCounter(state, player, true, this);
|
||||
}
|
||||
counterWidgets.insert(state->getId(), widget);
|
||||
|
||||
if (playerMenu->getCountersMenu() && widget->getMenu()) {
|
||||
playerMenu->getCountersMenu()->addMenu(widget->getMenu());
|
||||
}
|
||||
|
||||
if (playerMenu->getShortcutsActive()) {
|
||||
widget->setShortcutsActive();
|
||||
}
|
||||
|
||||
rearrangeCounters();
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::onCounterRemoved(int counterId)
|
||||
{
|
||||
auto *widget = counterWidgets.take(counterId);
|
||||
if (!widget) {
|
||||
return;
|
||||
}
|
||||
if (playerMenu->getCountersMenu() && widget->getMenu()) {
|
||||
playerMenu->getCountersMenu()->removeAction(widget->getMenu()->menuAction());
|
||||
}
|
||||
widget->delCounter();
|
||||
rearrangeCounters();
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::rearrangeCounters()
|
||||
{
|
||||
qreal ySize = boundingRect().y() + 80;
|
||||
constexpr qreal padding = 5;
|
||||
for (auto *ctr : counterWidgets.values()) {
|
||||
if (!ctr->getShownInCounterArea()) {
|
||||
continue;
|
||||
}
|
||||
QRectF br = ctr->boundingRect();
|
||||
ctr->setPos((counterAreaWidth - br.width()) / 2, ySize);
|
||||
ySize += br.height() + padding;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::rearrangeZones()
|
||||
{
|
||||
auto base = QPointF(CardDimensions::HEIGHT_F + counterAreaWidth + 15, 0);
|
||||
if (SettingsCache::instance().getHorizontalHand()) {
|
||||
if (mirrored) {
|
||||
if (player->getHandZone()->contentsKnown()) {
|
||||
handVisible = true;
|
||||
handZoneGraphicsItem->setPos(base);
|
||||
base += QPointF(0, handZoneGraphicsItem->boundingRect().height());
|
||||
} else {
|
||||
handVisible = false;
|
||||
}
|
||||
|
||||
stackZoneGraphicsItem->setPos(base);
|
||||
base += QPointF(stackZoneGraphicsItem->boundingRect().width(), 0);
|
||||
|
||||
tableZoneGraphicsItem->setPos(base);
|
||||
} else {
|
||||
stackZoneGraphicsItem->setPos(base);
|
||||
|
||||
tableZoneGraphicsItem->setPos(base.x() + stackZoneGraphicsItem->boundingRect().width(), 0);
|
||||
base += QPointF(0, tableZoneGraphicsItem->boundingRect().height());
|
||||
|
||||
if (player->getHandZone()->contentsKnown()) {
|
||||
handVisible = true;
|
||||
handZoneGraphicsItem->setPos(base);
|
||||
} else {
|
||||
handVisible = false;
|
||||
}
|
||||
}
|
||||
handZoneGraphicsItem->setWidth(tableZoneGraphicsItem->getWidth() +
|
||||
stackZoneGraphicsItem->boundingRect().width());
|
||||
} else {
|
||||
handVisible = true;
|
||||
|
||||
handZoneGraphicsItem->setPos(base);
|
||||
base += QPointF(handZoneGraphicsItem->boundingRect().width(), 0);
|
||||
|
||||
stackZoneGraphicsItem->setPos(base);
|
||||
base += QPointF(stackZoneGraphicsItem->boundingRect().width(), 0);
|
||||
|
||||
tableZoneGraphicsItem->setPos(base);
|
||||
}
|
||||
handZoneGraphicsItem->setVisible(handVisible);
|
||||
handZoneGraphicsItem->updateOrientation();
|
||||
tableZoneGraphicsItem->reorganizeCards();
|
||||
updateBoundingRect();
|
||||
rearrangeCounters();
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::updateBoundingRect()
|
||||
{
|
||||
prepareGeometryChange();
|
||||
qreal width = CardDimensions::HEIGHT_F + 15 + counterAreaWidth + stackZoneGraphicsItem->boundingRect().width();
|
||||
if (SettingsCache::instance().getHorizontalHand()) {
|
||||
qreal handHeight = handVisible ? handZoneGraphicsItem->boundingRect().height() : 0;
|
||||
bRect = QRectF(0, 0, width + tableZoneGraphicsItem->boundingRect().width(),
|
||||
tableZoneGraphicsItem->boundingRect().height() + handHeight);
|
||||
} else {
|
||||
bRect = QRectF(
|
||||
0, 0, width + handZoneGraphicsItem->boundingRect().width() + tableZoneGraphicsItem->boundingRect().width(),
|
||||
tableZoneGraphicsItem->boundingRect().height());
|
||||
}
|
||||
playerArea->setSize(CardDimensions::HEIGHT_F + counterAreaWidth + 15, bRect.height());
|
||||
|
||||
emit sizeChanged();
|
||||
}
|
||||
|
|
@ -1,146 +0,0 @@
|
|||
/**
|
||||
* @file player_graphics_item.h
|
||||
* @ingroup GameGraphicsPlayers
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_PLAYER_GRAPHICS_ITEM_H
|
||||
#define COCKATRICE_PLAYER_GRAPHICS_ITEM_H
|
||||
#include "../board/abstract_counter.h"
|
||||
#include "../game_scene.h"
|
||||
#include "player_logic.h"
|
||||
|
||||
#include <QGraphicsObject>
|
||||
|
||||
class HandZone;
|
||||
class PileZone;
|
||||
class PlayerDialogs;
|
||||
class PlayerTarget;
|
||||
class StackZone;
|
||||
class TableZone;
|
||||
class ZoneViewZone;
|
||||
|
||||
class PlayerGraphicsItem : public QGraphicsObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
Type = typeOther
|
||||
};
|
||||
int type() const override
|
||||
{
|
||||
return Type;
|
||||
}
|
||||
|
||||
static constexpr int counterAreaWidth = 55;
|
||||
|
||||
explicit PlayerGraphicsItem(PlayerLogic *player);
|
||||
void initializeZones();
|
||||
|
||||
[[nodiscard]] QRectF boundingRect() const override;
|
||||
qreal getMinimumWidth() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
void processSceneSizeChange(int newPlayerWidth);
|
||||
|
||||
void setMirrored(bool _mirrored);
|
||||
|
||||
bool getMirrored() const
|
||||
{
|
||||
return mirrored;
|
||||
}
|
||||
|
||||
GameScene *getGameScene() const
|
||||
{
|
||||
return static_cast<GameScene *>(scene());
|
||||
}
|
||||
|
||||
PlayerLogic *getLogic() const
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
[[nodiscard]] PlayerMenu *getPlayerMenu() const
|
||||
{
|
||||
return playerMenu;
|
||||
}
|
||||
|
||||
PlayerArea *getPlayerArea() const
|
||||
{
|
||||
return playerArea;
|
||||
}
|
||||
|
||||
PlayerTarget *getPlayerTarget() const
|
||||
{
|
||||
return playerTarget;
|
||||
}
|
||||
|
||||
[[nodiscard]] PileZone *getDeckZoneGraphicsItem() const
|
||||
{
|
||||
return deckZoneGraphicsItem;
|
||||
}
|
||||
|
||||
[[nodiscard]] PileZone *getSideboardZoneGraphicsItem() const
|
||||
{
|
||||
return sideboardGraphicsItem;
|
||||
}
|
||||
|
||||
[[nodiscard]] PileZone *getGraveyardZoneGraphicsItem() const
|
||||
{
|
||||
return graveyardZoneGraphicsItem;
|
||||
}
|
||||
[[nodiscard]] PileZone *getRfgZoneGraphicsItem() const
|
||||
{
|
||||
return rfgZoneGraphicsItem;
|
||||
}
|
||||
[[nodiscard]] TableZone *getTableZoneGraphicsItem() const
|
||||
{
|
||||
return tableZoneGraphicsItem;
|
||||
}
|
||||
[[nodiscard]] StackZone *getStackZoneGraphicsItem() const
|
||||
{
|
||||
return stackZoneGraphicsItem;
|
||||
}
|
||||
[[nodiscard]] HandZone *getHandZoneGraphicsItem() const
|
||||
{
|
||||
return handZoneGraphicsItem;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void onPlayerActiveChanged(bool _active);
|
||||
void onCounterAdded(CounterState *state);
|
||||
void onCounterRemoved(int counterId);
|
||||
void rearrangeCounters();
|
||||
void retranslateUi();
|
||||
|
||||
signals:
|
||||
void sizeChanged();
|
||||
void playerCountChanged();
|
||||
void mirroredChanged(bool isMirrored);
|
||||
void cardInfoRequested(const CardRef &cardRef);
|
||||
|
||||
private:
|
||||
PlayerLogic *player;
|
||||
PlayerMenu *playerMenu;
|
||||
PlayerDialogs *playerDialogs;
|
||||
PlayerArea *playerArea;
|
||||
PlayerTarget *playerTarget;
|
||||
QMap<int, AbstractCounter *> counterWidgets;
|
||||
PileZone *deckZoneGraphicsItem;
|
||||
PileZone *sideboardGraphicsItem;
|
||||
PileZone *graveyardZoneGraphicsItem;
|
||||
PileZone *rfgZoneGraphicsItem;
|
||||
TableZone *tableZoneGraphicsItem;
|
||||
StackZone *stackZoneGraphicsItem;
|
||||
HandZone *handZoneGraphicsItem;
|
||||
QRectF bRect;
|
||||
bool mirrored;
|
||||
bool handVisible = false;
|
||||
|
||||
private slots:
|
||||
void updateBoundingRect();
|
||||
void rearrangeZones();
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_GRAPHICS_ITEM_H
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
#ifndef COCKATRICE_PLAYER_INFO_H
|
||||
#define COCKATRICE_PLAYER_INFO_H
|
||||
|
||||
#include "player_target.h"
|
||||
#include "../../game_graphics/player/player_target.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
|
|
|
|||
|
|
@ -1,236 +0,0 @@
|
|||
#include "player_list_widget.h"
|
||||
|
||||
#include "../../interface/pixel_map_generator.h"
|
||||
#include "../../interface/widgets/server/user/user_context_menu.h"
|
||||
#include "../../interface/widgets/server/user/user_list_manager.h"
|
||||
#include "../../interface/widgets/server/user/user_list_widget.h"
|
||||
#include "../../interface/widgets/tabs/tab_game.h"
|
||||
#include "../../interface/widgets/tabs/tab_supervisor.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QMouseEvent>
|
||||
#include <libcockatrice/protocol/pb/command_kick_from_game.pb.h>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_playerproperties.pb.h>
|
||||
#include <libcockatrice/protocol/pb/session_commands.pb.h>
|
||||
|
||||
PlayerListItemDelegate::PlayerListItemDelegate(QObject *const parent) : QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool PlayerListItemDelegate::editorEvent(QEvent *event,
|
||||
QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index)
|
||||
{
|
||||
if ((event->type() == QEvent::MouseButtonPress) && index.isValid()) {
|
||||
auto *const mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent->button() == Qt::RightButton) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
static_cast<PlayerListWidget *>(parent())->showContextMenu(mouseEvent->globalPosition().toPoint(), index);
|
||||
#else
|
||||
static_cast<PlayerListWidget *>(parent())->showContextMenu(mouseEvent->globalPos(), index);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
PlayerListTWI::PlayerListTWI() : QTreeWidgetItem(Type)
|
||||
{
|
||||
}
|
||||
|
||||
bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const
|
||||
{
|
||||
// Sort by spectator/player
|
||||
if (data(1, Qt::UserRole) != other.data(1, Qt::UserRole)) {
|
||||
return data(1, Qt::UserRole).toBool();
|
||||
}
|
||||
|
||||
// Sort by player ID
|
||||
return data(4, Qt::UserRole + 1).toInt() < other.data(4, Qt::UserRole + 1).toInt();
|
||||
}
|
||||
|
||||
PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor,
|
||||
AbstractClient *_client,
|
||||
AbstractGame *_game,
|
||||
QWidget *parent)
|
||||
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false)
|
||||
{
|
||||
readyIcon = QPixmap("theme:icons/ready_start");
|
||||
notReadyIcon = QPixmap("theme:icons/not_ready_start");
|
||||
concededIcon = QPixmap("theme:icons/conceded");
|
||||
playerIcon = loadColorAdjustedPixmap("theme:icons/player");
|
||||
judgeIcon = loadColorAdjustedPixmap("theme:icons/scales");
|
||||
spectatorIcon = loadColorAdjustedPixmap("theme:icons/spectator");
|
||||
lockIcon = QPixmap("theme:icons/lock");
|
||||
|
||||
if (tabSupervisor) {
|
||||
itemDelegate = new PlayerListItemDelegate(this);
|
||||
setItemDelegate(itemDelegate);
|
||||
|
||||
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
|
||||
connect(userContextMenu, &UserContextMenu::openMessageDialog, this, &PlayerListWidget::openMessageDialog);
|
||||
} else {
|
||||
userContextMenu = nullptr;
|
||||
}
|
||||
|
||||
setMinimumHeight(40);
|
||||
setIconSize(QSize(20, 15));
|
||||
setColumnCount(6);
|
||||
setColumnWidth(0, 20);
|
||||
setColumnWidth(1, 20);
|
||||
setColumnWidth(2, 20);
|
||||
setColumnWidth(3, 20);
|
||||
setColumnWidth(5, 20);
|
||||
setHeaderHidden(true);
|
||||
setRootIsDecorated(false);
|
||||
setUniformRowHeights(true);
|
||||
setItemsExpandable(false);
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void PlayerListWidget::retranslateUi()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerListWidget::addPlayer(const ServerInfo_PlayerProperties &player)
|
||||
{
|
||||
QTreeWidgetItem *newPlayer = new PlayerListTWI;
|
||||
players.insert(player.player_id(), newPlayer);
|
||||
updatePlayerProperties(player);
|
||||
addTopLevelItem(newPlayer);
|
||||
sortItems(1, Qt::AscendingOrder);
|
||||
resizeColumnToContents(4);
|
||||
resizeColumnToContents(5);
|
||||
}
|
||||
|
||||
void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId)
|
||||
{
|
||||
if (playerId == -1) {
|
||||
playerId = prop.player_id();
|
||||
}
|
||||
|
||||
QTreeWidgetItem *player = players.value(playerId, 0);
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool isSpectator = prop.has_spectator() && prop.spectator();
|
||||
if (prop.has_judge() || prop.has_spectator()) {
|
||||
if (prop.has_judge() && prop.judge()) {
|
||||
player->setIcon(1, judgeIcon);
|
||||
} else if (isSpectator) {
|
||||
player->setIcon(1, spectatorIcon);
|
||||
} else {
|
||||
player->setIcon(1, playerIcon);
|
||||
}
|
||||
player->setData(1, Qt::UserRole, !isSpectator);
|
||||
}
|
||||
|
||||
if (!isSpectator) {
|
||||
if (prop.has_conceded()) {
|
||||
player->setData(2, Qt::UserRole, prop.conceded());
|
||||
}
|
||||
if (prop.has_ready_start()) {
|
||||
player->setData(2, Qt::UserRole + 1, prop.ready_start());
|
||||
}
|
||||
if (prop.has_conceded() || prop.has_ready_start()) {
|
||||
player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon())
|
||||
: (prop.ready_start() ? readyIcon : notReadyIcon));
|
||||
}
|
||||
}
|
||||
if (prop.has_user_info()) {
|
||||
player->setData(3, Qt::UserRole, prop.user_info().user_level());
|
||||
player->setIcon(3, UserLevelPixmapGenerator::generateIcon(
|
||||
12, UserLevelFlags(prop.user_info().user_level()), prop.user_info().pawn_colors(), false,
|
||||
QString::fromStdString(prop.user_info().privlevel())));
|
||||
player->setText(4, QString::fromStdString(prop.user_info().name()));
|
||||
const QString country = QString::fromStdString(prop.user_info().country());
|
||||
if (!country.isEmpty()) {
|
||||
player->setIcon(4, QIcon(CountryPixmapGenerator::generatePixmap(12, country)));
|
||||
}
|
||||
player->setData(4, Qt::UserRole, QString::fromStdString(prop.user_info().name()));
|
||||
}
|
||||
|
||||
if (prop.has_player_id()) {
|
||||
player->setData(4, Qt::UserRole + 1, prop.player_id());
|
||||
}
|
||||
|
||||
if (!isSpectator) {
|
||||
if (prop.has_deck_hash()) {
|
||||
player->setText(5, QString::fromStdString(prop.deck_hash()));
|
||||
}
|
||||
if (prop.has_sideboard_locked()) {
|
||||
player->setIcon(5, prop.sideboard_locked() ? lockIcon : QIcon());
|
||||
}
|
||||
}
|
||||
if (prop.has_ping_seconds()) {
|
||||
player->setIcon(0, QIcon(PingPixmapGenerator::generatePixmap(12, prop.ping_seconds(), 10)));
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerListWidget::removePlayer(int playerId)
|
||||
{
|
||||
QTreeWidgetItem *player = players.value(playerId, 0);
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
players.remove(playerId);
|
||||
delete takeTopLevelItem(indexOfTopLevelItem(player));
|
||||
}
|
||||
|
||||
void PlayerListWidget::setActivePlayer(int playerId)
|
||||
{
|
||||
QMapIterator<int, QTreeWidgetItem *> i(players);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
QTreeWidgetItem *twi = i.value();
|
||||
if (i.key() == playerId) {
|
||||
twi->setBackground(4, QColor(150, 255, 150));
|
||||
twi->setForeground(4, QColor(0, 0, 0));
|
||||
} else {
|
||||
twi->setBackground(4, palette().base().color());
|
||||
twi->setForeground(4, palette().text().color());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerListWidget::setGameStarted(bool _gameStarted, bool resuming)
|
||||
{
|
||||
gameStarted = _gameStarted;
|
||||
QMapIterator<int, QTreeWidgetItem *> i(players);
|
||||
while (i.hasNext()) {
|
||||
QTreeWidgetItem *twi = i.next().value();
|
||||
|
||||
bool isPlayer = twi->data(1, Qt::UserRole).toBool();
|
||||
if (!isPlayer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gameStarted) {
|
||||
if (resuming) {
|
||||
twi->setIcon(2, twi->data(2, Qt::UserRole).toBool() ? concededIcon : QIcon());
|
||||
} else {
|
||||
twi->setData(2, Qt::UserRole, false);
|
||||
twi->setIcon(2, QIcon());
|
||||
}
|
||||
} else {
|
||||
twi->setIcon(2, notReadyIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
||||
{
|
||||
if (!userContextMenu) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString &userName = index.sibling(index.row(), 4).data(Qt::UserRole).toString();
|
||||
int playerId = index.sibling(index.row(), 4).data(Qt::UserRole + 1).toInt();
|
||||
UserLevelFlags userLevel(index.sibling(index.row(), 3).data(Qt::UserRole).toInt());
|
||||
QString deckHash = index.sibling(index.row(), 5).data().toString();
|
||||
|
||||
userContextMenu->showContextMenu(pos, userName, userLevel, true, playerId, deckHash);
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/**
|
||||
* @file player_list_widget.h
|
||||
* @ingroup GameWidgets
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef PLAYERLISTWIDGET_H
|
||||
#define PLAYERLISTWIDGET_H
|
||||
|
||||
#include "player_logic.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QMap>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTreeWidget>
|
||||
|
||||
class ServerInfo_PlayerProperties;
|
||||
class TabSupervisor;
|
||||
class AbstractClient;
|
||||
class AbstractGame;
|
||||
class UserContextMenu;
|
||||
|
||||
class PlayerListItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
explicit PlayerListItemDelegate(QObject *parent);
|
||||
bool editorEvent(QEvent *event,
|
||||
QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) override;
|
||||
};
|
||||
|
||||
class PlayerListTWI : public QTreeWidgetItem
|
||||
{
|
||||
public:
|
||||
PlayerListTWI();
|
||||
bool operator<(const QTreeWidgetItem &other) const override;
|
||||
};
|
||||
|
||||
class PlayerListWidget : public QTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
PlayerListItemDelegate *itemDelegate;
|
||||
QMap<int, QTreeWidgetItem *> players;
|
||||
TabSupervisor *tabSupervisor;
|
||||
AbstractClient *client;
|
||||
AbstractGame *game;
|
||||
UserContextMenu *userContextMenu;
|
||||
QIcon readyIcon, notReadyIcon, concededIcon, playerIcon, judgeIcon, spectatorIcon, lockIcon;
|
||||
bool gameStarted;
|
||||
signals:
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
|
||||
public:
|
||||
PlayerListWidget(TabSupervisor *_tabSupervisor,
|
||||
AbstractClient *_client,
|
||||
AbstractGame *_game,
|
||||
QWidget *parent = nullptr);
|
||||
void retranslateUi();
|
||||
void setActivePlayer(int playerId);
|
||||
void setGameStarted(bool _gameStarted, bool resuming);
|
||||
void showContextMenu(const QPoint &pos, const QModelIndex &index);
|
||||
|
||||
public slots:
|
||||
void addPlayer(const ServerInfo_PlayerProperties &player);
|
||||
void removePlayer(int playerId);
|
||||
void updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId = -1);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,19 +1,21 @@
|
|||
#include "player_logic.h"
|
||||
|
||||
#include "../../game_graphics/board/arrow_item.h"
|
||||
#include "../../game_graphics/board/card_item.h"
|
||||
#include "../../game_graphics/board/counter_general.h"
|
||||
#include "../../game_graphics/game_scene.h"
|
||||
#include "../../game_graphics/player/player_target.h"
|
||||
#include "../../game_graphics/zones/hand_zone.h"
|
||||
#include "../../game_graphics/zones/pile_zone.h"
|
||||
#include "../../game_graphics/zones/stack_zone.h"
|
||||
#include "../../game_graphics/zones/table_zone.h"
|
||||
#include "../../interface/theme_manager.h"
|
||||
#include "../../interface/widgets/tabs/tab_game.h"
|
||||
#include "../board/arrow_item.h"
|
||||
#include "../board/card_item.h"
|
||||
#include "../board/card_list.h"
|
||||
#include "../board/counter_general.h"
|
||||
#include "../game_scene.h"
|
||||
#include "../keyboard_card_navigator.h"
|
||||
#include "player_actions.h"
|
||||
#include "player_target.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include "../../game_graphics/player/player_area.h"
|
||||
#include "../../interface/widgets/menus/tearoff_menu.h"
|
||||
#include "../board/arrow_data.h"
|
||||
#include "../interface/deck_loader/loaded_deck.h"
|
||||
|
|
@ -14,10 +15,7 @@
|
|||
#include "../zones/pile_zone_logic.h"
|
||||
#include "../zones/stack_zone_logic.h"
|
||||
#include "../zones/table_zone_logic.h"
|
||||
#include "menu/player_menu.h"
|
||||
#include "player_area.h"
|
||||
#include "player_event_handler.h"
|
||||
#include "player_graphics_item.h"
|
||||
#include "player_info.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
|
|
@ -54,6 +52,7 @@ class PlayerMenu;
|
|||
class QAction;
|
||||
class QMenu;
|
||||
class ServerInfo_Arrow;
|
||||
class ServerInfo_Card;
|
||||
class ServerInfo_Counter;
|
||||
class ServerInfo_Player;
|
||||
class ServerInfo_User;
|
||||
|
|
|
|||
|
|
@ -1,169 +0,0 @@
|
|||
#include "player_target.h"
|
||||
|
||||
#include "../../interface/pixel_map_generator.h"
|
||||
#include "player_logic.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
#include <QtMath>
|
||||
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
|
||||
|
||||
PlayerCounter::PlayerCounter(CounterState *state, PlayerLogic *player, QGraphicsItem *parent)
|
||||
: AbstractCounter(state, player, false, false, parent)
|
||||
{
|
||||
}
|
||||
|
||||
QRectF PlayerCounter::boundingRect() const
|
||||
{
|
||||
return {0, 0, 50, 30};
|
||||
}
|
||||
|
||||
void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
const int radius = 8;
|
||||
const qreal border = 1;
|
||||
QPainterPath path(QPointF(50 - border / 2, border / 2));
|
||||
path.lineTo(radius, border / 2);
|
||||
path.arcTo(border / 2, border / 2, 2 * radius, 2 * radius, 90, 90);
|
||||
path.lineTo(border / 2, 30 - border / 2);
|
||||
path.lineTo(50 - border / 2, 30 - border / 2);
|
||||
path.closeSubpath();
|
||||
|
||||
QPen pen(QColor(100, 100, 100));
|
||||
pen.setWidth(border);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(hovered ? QColor(50, 50, 50, 160) : QColor(0, 0, 0, 160));
|
||||
|
||||
painter->drawPath(path);
|
||||
|
||||
QRectF translatedRect = path.controlPointRect();
|
||||
QSize translatedSize = translatedRect.size().toSize();
|
||||
QFont font("Serif");
|
||||
font.setWeight(QFont::Bold);
|
||||
font.setPixelSize(qMax(qRound(translatedSize.height() / 1.3), 9));
|
||||
painter->setFont(font);
|
||||
painter->setPen(Qt::white);
|
||||
painter->drawText(translatedRect, Qt::AlignCenter, QString::number(value));
|
||||
}
|
||||
|
||||
PlayerTarget::PlayerTarget(PlayerLogic *_owner, QGraphicsItem *parentItem)
|
||||
: ArrowTarget(_owner, parentItem), playerCounter(nullptr)
|
||||
{
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
|
||||
const std::string &bmp = _owner->getPlayerInfo()->getUserInfo()->avatar_bmp();
|
||||
if (!fullPixmap.loadFromData((const uchar *)bmp.data(), static_cast<uint>(bmp.size()))) {
|
||||
fullPixmap = QPixmap();
|
||||
}
|
||||
}
|
||||
|
||||
PlayerTarget::~PlayerTarget()
|
||||
{
|
||||
// Explicit deletion is necessary in spite of parent/child relationship
|
||||
// as we need this object to be alive to receive the destroyed() signal.
|
||||
delete playerCounter;
|
||||
}
|
||||
|
||||
QRectF PlayerTarget::boundingRect() const
|
||||
{
|
||||
return {0, 0, 160, 64};
|
||||
}
|
||||
|
||||
void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
const ServerInfo_User *const info = owner->getPlayerInfo()->getUserInfo();
|
||||
|
||||
const qreal border = 2;
|
||||
|
||||
QRectF avatarBoundingRect = boundingRect().adjusted(border, border, -border, -border);
|
||||
QRectF translatedRect = painter->combinedTransform().mapRect(avatarBoundingRect);
|
||||
QSize translatedSize = translatedRect.size().toSize();
|
||||
QPixmap cachedPixmap;
|
||||
const QString cacheKey = "avatar" + QString::number(translatedSize.width()) + "_" +
|
||||
QString::number(info->user_level()) + "_" + QString::number(fullPixmap.cacheKey());
|
||||
if (!QPixmapCache::find(cacheKey, &cachedPixmap)) {
|
||||
cachedPixmap = QPixmap(translatedSize.width(), translatedSize.height());
|
||||
|
||||
QPainter tempPainter(&cachedPixmap);
|
||||
// pow(foo, 0.5) equals to sqrt(foo), but using sqrt(foo) in this context will produce a compile error with
|
||||
// MSVC++
|
||||
QRadialGradient grad(translatedRect.center(), qPow(translatedSize.width() * translatedSize.width() +
|
||||
translatedSize.height() * translatedSize.height(),
|
||||
0.5) /
|
||||
2);
|
||||
grad.setColorAt(1, Qt::black);
|
||||
grad.setColorAt(0, QColor(180, 180, 180));
|
||||
tempPainter.fillRect(QRectF(0, 0, translatedSize.width(), translatedSize.height()), grad);
|
||||
|
||||
if (fullPixmap.isNull()) {
|
||||
int sideLength = translatedSize.height();
|
||||
QPixmap tempPixmap = UserLevelPixmapGenerator::generatePixmap(
|
||||
sideLength, UserLevelFlags(info->user_level()), info->pawn_colors(), false,
|
||||
QString::fromStdString(info->privlevel()));
|
||||
int x = (translatedSize.width() - sideLength) / 2;
|
||||
int y = 0;
|
||||
tempPainter.drawPixmap(x, y, tempPixmap);
|
||||
} else {
|
||||
QPixmap tempPixmap = fullPixmap.scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
int x = (translatedSize.width() - tempPixmap.width()) / 2;
|
||||
int y = (translatedSize.height() - tempPixmap.height()) / 2;
|
||||
tempPainter.drawPixmap(x, y, tempPixmap);
|
||||
}
|
||||
|
||||
QPixmapCache::insert(cacheKey, cachedPixmap);
|
||||
}
|
||||
|
||||
painter->save();
|
||||
resetPainterTransform(painter);
|
||||
painter->translate((translatedSize.width() - cachedPixmap.width()) / 2.0, 0);
|
||||
painter->drawPixmap(translatedRect, cachedPixmap, cachedPixmap.rect());
|
||||
painter->restore();
|
||||
|
||||
QRectF nameRect = QRectF(0, boundingRect().height() - 20, 110, 20);
|
||||
painter->fillRect(nameRect, QColor(0, 0, 0, 160));
|
||||
QRectF translatedNameRect = painter->combinedTransform().mapRect(nameRect);
|
||||
|
||||
painter->save();
|
||||
resetPainterTransform(painter);
|
||||
|
||||
QString name = QString::fromStdString(info->name());
|
||||
if (name.size() > 13) {
|
||||
name = name.mid(0, 10) + "...";
|
||||
}
|
||||
|
||||
QFont font;
|
||||
font.setPixelSize(qMax(qRound(translatedNameRect.height() / 1.5), 9));
|
||||
painter->setFont(font);
|
||||
painter->setPen(Qt::white);
|
||||
painter->drawText(translatedNameRect, Qt::AlignVCenter | Qt::AlignLeft, " " + name);
|
||||
painter->restore();
|
||||
|
||||
QPen pen(QColor(100, 100, 100));
|
||||
pen.setWidth(border);
|
||||
pen.setJoinStyle(Qt::RoundJoin);
|
||||
painter->setPen(pen);
|
||||
painter->drawRect(boundingRect().adjusted(border / 2, border / 2, -border / 2, -border / 2));
|
||||
|
||||
if (getBeingPointedAt()) {
|
||||
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
|
||||
}
|
||||
}
|
||||
|
||||
AbstractCounter *PlayerTarget::addCounter(CounterState *state)
|
||||
{
|
||||
if (playerCounter) {
|
||||
disconnect(playerCounter, nullptr, this, nullptr);
|
||||
playerCounter->delCounter();
|
||||
}
|
||||
playerCounter = new PlayerCounter(state, owner, this);
|
||||
playerCounter->setPos(boundingRect().width() - playerCounter->boundingRect().width(),
|
||||
boundingRect().height() - playerCounter->boundingRect().height());
|
||||
connect(playerCounter, &PlayerCounter::destroyed, this, &PlayerTarget::counterDeleted);
|
||||
return playerCounter;
|
||||
}
|
||||
|
||||
void PlayerTarget::counterDeleted()
|
||||
{
|
||||
playerCounter = nullptr;
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
/**
|
||||
* @file player_target.h
|
||||
* @ingroup GameGraphicsPlayers
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef PLAYERTARGET_H
|
||||
#define PLAYERTARGET_H
|
||||
|
||||
#include "../../game_graphics/board/graphics_item_type.h"
|
||||
#include "../board/abstract_counter.h"
|
||||
#include "../board/arrow_target.h"
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
class PlayerLogic;
|
||||
|
||||
class PlayerCounter : public AbstractCounter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PlayerCounter(CounterState *state, PlayerLogic *player, QGraphicsItem *parent);
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
};
|
||||
|
||||
class PlayerTarget : public ArrowTarget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QPixmap fullPixmap;
|
||||
PlayerCounter *playerCounter;
|
||||
public slots:
|
||||
void counterDeleted();
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
Type = typePlayerTarget
|
||||
};
|
||||
int type() const override
|
||||
{
|
||||
return Type;
|
||||
}
|
||||
|
||||
explicit PlayerTarget(PlayerLogic *_player = nullptr, QGraphicsItem *parentItem = nullptr);
|
||||
~PlayerTarget() override;
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
AbstractCounter *addCounter(CounterState *state);
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue