mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-17 04:27:45 -07:00
[Game] Add Command Zone support with commander tax tracking
- Add CommandZone and CommandZoneLogic for commander - Add CommanderTaxCounter - Add counter active state protocol (show/hide tax counters) - Add "Enable Command Zone" option in game creation dialogs - Add context menu actions for command zone operations Took 9 minutes Took 11 minutes
This commit is contained in:
parent
694adc9e64
commit
9b030a3d6b
73 changed files with 1540 additions and 86 deletions
184
cockatrice/src/game_graphics/player/menu/command_zone_menu.cpp
Normal file
184
cockatrice/src/game_graphics/player/menu/command_zone_menu.cpp
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
#include "command_zone_menu.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
#include "../../board/abstract_counter.h"
|
||||
#include "../../game_scene.h"
|
||||
#include "../../zones/command_zone.h"
|
||||
#include "../player_actions.h"
|
||||
#include "../player_graphics_item.h"
|
||||
#include "../player_logic.h"
|
||||
|
||||
#include <libcockatrice/utility/counter_ids.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
CommandZoneMenu::CommandZoneMenu(PlayerLogic *_player, QMenu *playerMenu) : QMenu(playerMenu), player(_player)
|
||||
{
|
||||
viewZoneShortcutKey = QStringLiteral("Player/aViewCommandZone");
|
||||
incTaxShortcutKey = QStringLiteral("Player/aAddCommanderTax");
|
||||
decTaxShortcutKey = QStringLiteral("Player/aRemoveCommanderTax");
|
||||
incPartnerTaxShortcutKey = QStringLiteral("Player/aAddPartnerTax");
|
||||
decPartnerTaxShortcutKey = QStringLiteral("Player/aRemovePartnerTax");
|
||||
|
||||
aViewZone = new QAction(this);
|
||||
connect(aViewZone, &QAction::triggered, this,
|
||||
[this]() { player->getGameScene()->toggleZoneView(player, ZoneNames::COMMAND, -1); });
|
||||
|
||||
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||
addAction(aViewZone);
|
||||
addSeparator();
|
||||
|
||||
PlayerActions *playerActions = player->getPlayerActions();
|
||||
|
||||
aIncreaseCommanderTax = new QAction(this);
|
||||
connect(aIncreaseCommanderTax, &QAction::triggered, this,
|
||||
[playerActions]() { playerActions->actModifyTaxCounter(CounterIds::CommanderTax, 1); });
|
||||
addAction(aIncreaseCommanderTax);
|
||||
|
||||
aDecreaseCommanderTax = new QAction(this);
|
||||
connect(aDecreaseCommanderTax, &QAction::triggered, this,
|
||||
[playerActions]() { playerActions->actModifyTaxCounter(CounterIds::CommanderTax, -1); });
|
||||
addAction(aDecreaseCommanderTax);
|
||||
|
||||
addSeparator();
|
||||
|
||||
aIncreasePartnerTax = new QAction(this);
|
||||
connect(aIncreasePartnerTax, &QAction::triggered, this,
|
||||
[playerActions]() { playerActions->actModifyTaxCounter(CounterIds::PartnerTax, 1); });
|
||||
addAction(aIncreasePartnerTax);
|
||||
|
||||
aDecreasePartnerTax = new QAction(this);
|
||||
connect(aDecreasePartnerTax, &QAction::triggered, this,
|
||||
[playerActions]() { playerActions->actModifyTaxCounter(CounterIds::PartnerTax, -1); });
|
||||
addAction(aDecreasePartnerTax);
|
||||
|
||||
addSeparator();
|
||||
|
||||
aToggleCommanderTaxCounter = new QAction(this);
|
||||
connect(aToggleCommanderTaxCounter, &QAction::triggered, this,
|
||||
[playerActions]() { playerActions->actToggleTaxCounter(CounterIds::CommanderTax); });
|
||||
addAction(aToggleCommanderTaxCounter);
|
||||
|
||||
aTogglePartnerTaxCounter = new QAction(this);
|
||||
connect(aTogglePartnerTaxCounter, &QAction::triggered, this,
|
||||
[playerActions]() { playerActions->actToggleTaxCounter(CounterIds::PartnerTax); });
|
||||
addAction(aTogglePartnerTaxCounter);
|
||||
|
||||
addSeparator();
|
||||
|
||||
aToggleMinimized = new QAction(this);
|
||||
connect(aToggleMinimized, &QAction::triggered, this, &CommandZoneMenu::actToggleMinimized);
|
||||
addAction(aToggleMinimized);
|
||||
|
||||
connect(this, &QMenu::aboutToShow, this, &CommandZoneMenu::updateTaxCounterActionStates);
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void CommandZoneMenu::retranslateUi()
|
||||
{
|
||||
setTitle(tr("Co&mmander"));
|
||||
if (aViewZone) {
|
||||
aViewZone->setText(tr("&View command zone"));
|
||||
}
|
||||
if (aIncreaseCommanderTax) {
|
||||
aIncreaseCommanderTax->setText(tr("&Increase Commander Tax (+1)"));
|
||||
}
|
||||
if (aDecreaseCommanderTax) {
|
||||
aDecreaseCommanderTax->setText(tr("&Decrease Commander Tax (-1)"));
|
||||
}
|
||||
if (aToggleCommanderTaxCounter) {
|
||||
aToggleCommanderTaxCounter->setText(tr("&Remove Commander Tax"));
|
||||
}
|
||||
if (aIncreasePartnerTax) {
|
||||
aIncreasePartnerTax->setText(tr("Increase &Partner Tax (+1)"));
|
||||
}
|
||||
if (aDecreasePartnerTax) {
|
||||
aDecreasePartnerTax->setText(tr("Decrease P&artner Tax (-1)"));
|
||||
}
|
||||
if (aTogglePartnerTaxCounter) {
|
||||
aTogglePartnerTaxCounter->setText(tr("&Add Partner Tax"));
|
||||
}
|
||||
if (aToggleMinimized) {
|
||||
aToggleMinimized->setText(tr("&Minimize"));
|
||||
}
|
||||
}
|
||||
|
||||
void CommandZoneMenu::actToggleMinimized()
|
||||
{
|
||||
CommandZone *zone = player->getGraphicsItem()->getCommandZoneGraphicsItem();
|
||||
if (zone) {
|
||||
zone->toggleMinimized();
|
||||
}
|
||||
}
|
||||
|
||||
void CommandZoneMenu::updateTaxCounterActionStates()
|
||||
{
|
||||
AbstractCounter *cmdTax = player->getCounterWidget(CounterIds::CommanderTax);
|
||||
bool cmdActive = cmdTax && cmdTax->isActive();
|
||||
|
||||
AbstractCounter *partnerTax = player->getCounterWidget(CounterIds::PartnerTax);
|
||||
bool partnerActive = partnerTax && partnerTax->isActive();
|
||||
|
||||
if (aIncreaseCommanderTax) {
|
||||
aIncreaseCommanderTax->setVisible(cmdActive);
|
||||
}
|
||||
if (aDecreaseCommanderTax) {
|
||||
aDecreaseCommanderTax->setVisible(cmdActive);
|
||||
}
|
||||
if (aToggleCommanderTaxCounter) {
|
||||
aToggleCommanderTaxCounter->setText(cmdActive ? tr("&Remove Commander Tax") : tr("&Add Commander Tax"));
|
||||
aToggleCommanderTaxCounter->setVisible(!cmdActive || (cmdTax && cmdTax->getValue() == 0));
|
||||
}
|
||||
|
||||
if (aIncreasePartnerTax) {
|
||||
aIncreasePartnerTax->setVisible(partnerActive);
|
||||
}
|
||||
if (aDecreasePartnerTax) {
|
||||
aDecreasePartnerTax->setVisible(partnerActive);
|
||||
}
|
||||
if (aTogglePartnerTaxCounter) {
|
||||
aTogglePartnerTaxCounter->setText(partnerActive ? tr("R&emove Partner Tax") : tr("&Add Partner Tax"));
|
||||
aTogglePartnerTaxCounter->setVisible(!partnerActive || (partnerTax && partnerTax->getValue() == 0));
|
||||
}
|
||||
}
|
||||
|
||||
void CommandZoneMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
||||
if (aViewZone) {
|
||||
aViewZone->setShortcuts(shortcuts.getShortcut(viewZoneShortcutKey));
|
||||
}
|
||||
if (aIncreaseCommanderTax) {
|
||||
aIncreaseCommanderTax->setShortcuts(shortcuts.getShortcut(incTaxShortcutKey));
|
||||
}
|
||||
if (aDecreaseCommanderTax) {
|
||||
aDecreaseCommanderTax->setShortcuts(shortcuts.getShortcut(decTaxShortcutKey));
|
||||
}
|
||||
if (aIncreasePartnerTax) {
|
||||
aIncreasePartnerTax->setShortcuts(shortcuts.getShortcut(incPartnerTaxShortcutKey));
|
||||
}
|
||||
if (aDecreasePartnerTax) {
|
||||
aDecreasePartnerTax->setShortcuts(shortcuts.getShortcut(decPartnerTaxShortcutKey));
|
||||
}
|
||||
}
|
||||
|
||||
void CommandZoneMenu::setShortcutsInactive()
|
||||
{
|
||||
if (aViewZone) {
|
||||
aViewZone->setShortcut(QKeySequence());
|
||||
}
|
||||
if (aIncreaseCommanderTax) {
|
||||
aIncreaseCommanderTax->setShortcut(QKeySequence());
|
||||
}
|
||||
if (aDecreaseCommanderTax) {
|
||||
aDecreaseCommanderTax->setShortcut(QKeySequence());
|
||||
}
|
||||
if (aIncreasePartnerTax) {
|
||||
aIncreasePartnerTax->setShortcut(QKeySequence());
|
||||
}
|
||||
if (aDecreasePartnerTax) {
|
||||
aDecreasePartnerTax->setShortcut(QKeySequence());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue