Merge branch 'Cockatrice:master' into toggle-normal-untapping-once

This commit is contained in:
Skagra42 2026-08-13 13:09:08 -06:00 committed by GitHub
commit fdd7d4eac0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
543 changed files with 82935 additions and 48240 deletions

View file

@ -1,6 +1,7 @@
#include "card_menu.h"
#include "../../../client/settings/card_counter_settings.h"
#include "../../../client/settings/shortcuts_settings.h"
#include "../../../interface/widgets/tabs/tab_game.h"
#include "../../board/card_item.h"
#include "../../game/player/player_actions.h"

View file

@ -1,5 +1,6 @@
#include "grave_menu.h"
#include "../../../client/settings/shortcuts_settings.h"
#include "../../game/abstract_game.h"
#include "../../game/player/player_actions.h"
#include "../../game/player/player_logic.h"

View file

@ -1,5 +1,6 @@
#include "move_menu.h"
#include "../../../client/settings/shortcuts_settings.h"
#include "../../game/player/player_actions.h"
#include "../../game/player/player_logic.h"
#include "../card_menu_action_type.h"

View file

@ -1,5 +1,6 @@
#include "player_menu.h"
#include "../../../client/settings/shortcuts_settings.h"
#include "../../../game_graphics/zones/hand_zone.h"
#include "../../../game_graphics/zones/pile_zone.h"
#include "../../../game_graphics/zones/table_zone.h"
@ -44,6 +45,8 @@ PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_
utilityMenu = nullptr;
}
tallyMenu = addManagedMenu<TallyMenu>();
if (player->getLogic()->getPlayerInfo()->getLocal()) {
sayMenu = addManagedMenu<SayMenu>(player);
} else {

View file

@ -15,11 +15,13 @@
#include "rfg_menu.h"
#include "say_menu.h"
#include "sideboard_menu.h"
#include "tally_menu.h"
#include "utility_menu.h"
#include <QList>
#include <QMenu>
#include <QObject>
#include <libcockatrice/utility/card_ref.h>
class CardItem;
class CardMenu;
@ -87,6 +89,7 @@ private:
GraveyardMenu *graveMenu;
RfgMenu *rfgMenu;
UtilityMenu *utilityMenu;
TallyMenu *tallyMenu;
SayMenu *sayMenu;
CustomZoneMenu *customZonesMenu;

View file

@ -1,5 +1,6 @@
#include "pt_menu.h"
#include "../../../client/settings/shortcuts_settings.h"
#include "../../game/player/player_actions.h"
#include "../../game/player/player_logic.h"
#include "../player_graphics_item.h"

View file

@ -5,6 +5,7 @@
#include "../../game/player/player_logic.h"
#include "../player_graphics_item.h"
#include <libcockatrice/settings/message_settings.h>
SayMenu::SayMenu(PlayerGraphicsItem *_player) : player(_player)
{
connect(&SettingsCache::instance().messages(), &MessageSettings::messageMacrosChanged, this, &SayMenu::initSayMenu);

View file

@ -1,5 +1,6 @@
#include "sideboard_menu.h"
#include "../../../client/settings/shortcuts_settings.h"
#include "../../game/player/player_actions.h"
#include "../../game/player/player_logic.h"
#include "../player_graphics_item.h"

View file

@ -0,0 +1,57 @@
#include "tally_menu.h"
#include "../../../client/settings/cache_settings.h"
#include <QActionGroup>
TallyMenu::TallyMenu()
{
actionGroup = new QActionGroup(this);
actionGroup->setExclusive(true);
aTallyNone = createTallyAction(TallyType::None);
aTallySubtypes = createTallyAction(TallyType::Subtypes);
aTallyTotalPower = createTallyAction(TallyType::TotalPower);
addAction(aTallyNone);
addSeparator();
addAction(aTallySubtypes);
addAction(aTallyTotalPower);
retranslateUi();
}
QAction *TallyMenu::createTallyAction(TallyType tallyType)
{
TallyType currentType = Tally::intToType(SettingsCache::instance().userInterface().getTallyType());
QAction *action = new QAction(this);
action->setCheckable(true);
action->setChecked(tallyType == currentType);
connect(action, &QAction::triggered, &SettingsCache::instance().userInterface(),
[tallyType] { SettingsCache::instance().userInterface().setTallyType(static_cast<int>(tallyType)); });
actionGroup->addAction(action);
return action;
}
void TallyMenu::setShortcutsActive()
{
// no-op because we haven't decided if we're adding shortcuts for tally types
}
void TallyMenu::setShortcutsInactive()
{
// no-op because we haven't decided if we're adding shortcuts for tally types
}
void TallyMenu::retranslateUi()
{
setTitle(tr("Tally"));
aTallyNone->setText(tr("None"));
aTallySubtypes->setText(tr("Subtypes"));
aTallyTotalPower->setText(tr("Total Power"));
}

View file

@ -0,0 +1,31 @@
#ifndef COCKATRICE_TALLY_MENU_H
#define COCKATRICE_TALLY_MENU_H
#include "../../../interface/widgets/menus/tearoff_menu.h"
#include "../../tally/tally.h"
#include "abstract_player_component.h"
#include <QMenu>
class TallyMenu : public TearOffMenu, public AbstractPlayerComponent
{
Q_OBJECT
public:
TallyMenu();
void setShortcutsActive() override;
void setShortcutsInactive() override;
void retranslateUi() override;
private:
QActionGroup *actionGroup = nullptr;
QAction *aTallyNone = nullptr;
QAction *aTallySubtypes = nullptr;
QAction *aTallyTotalPower = nullptr;
QAction *createTallyAction(TallyType tallyType);
};
#endif // COCKATRICE_TALLY_MENU_H

View file

@ -1,5 +1,6 @@
#include "utility_menu.h"
#include "../../../client/settings/shortcuts_settings.h"
#include "../../../interface/deck_loader/deck_loader.h"
#include "../../game/player/player_actions.h"
#include "../../game/player/player_logic.h"

View file

@ -8,6 +8,7 @@
#include <QInputDialog>
#include <libcockatrice/card/relation/card_relation.h>
#include <libcockatrice/utility/string_limits.h>
PlayerDialogs::PlayerDialogs(PlayerGraphicsItem *_player, PlayerActions *_playerActions)
: QObject(_player), player(_player), playerActions(_playerActions)

View file

@ -13,12 +13,13 @@
#include "player_dialogs.h"
#include <QGraphicsView>
#include <libcockatrice/settings/interface_settings.h>
PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player)
{
connect(&SettingsCache::instance(), &SettingsCache::horizontalHandChanged, this,
connect(&SettingsCache::instance().userInterface(), &InterfaceSettings::horizontalHandChanged, this,
&PlayerGraphicsItem::rearrangeZones);
connect(&SettingsCache::instance(), &SettingsCache::handJustificationChanged, this,
connect(&SettingsCache::instance().userInterface(), &InterfaceSettings::handJustificationChanged, this,
&PlayerGraphicsItem::rearrangeZones);
connect(player, &PlayerLogic::rearrangeCounters, this, &PlayerGraphicsItem::rearrangeCounters);
connect(player, &PlayerLogic::activeChanged, this, &PlayerGraphicsItem::onPlayerActiveChanged);
@ -59,6 +60,9 @@ PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player)
initializeZones();
connect(player, &PlayerLogic::addViewCustomZoneActionToCustomZoneMenu, this,
&PlayerGraphicsItem::onCustomZoneAdded);
playerMenu->setMenusForGraphicItems();
connect(tableZoneGraphicsItem, &TableZone::sizeChanged, this, &PlayerGraphicsItem::updateBoundingRect);
@ -121,6 +125,19 @@ void PlayerGraphicsItem::initializeZones()
connect(handZoneGraphicsItem->getLogic(), &HandZoneLogic::cardCountChanged, handCounter,
&HandCounter::updateNumber);
connect(handCounter, &HandCounter::showContextMenu, handZoneGraphicsItem, &HandZone::showContextMenu);
zoneGraphicsItems.insert(player->getDeckZone()->getName(), deckZoneGraphicsItem);
zoneGraphicsItems.insert(player->getGraveZone()->getName(), graveyardZoneGraphicsItem);
zoneGraphicsItems.insert(player->getRfgZone()->getName(), rfgZoneGraphicsItem);
zoneGraphicsItems.insert(player->getSideboardZone()->getName(), sideboardGraphicsItem);
zoneGraphicsItems.insert(player->getTableZone()->getName(), tableZoneGraphicsItem);
zoneGraphicsItems.insert(player->getStackZone()->getName(), stackZoneGraphicsItem);
zoneGraphicsItems.insert(player->getHandZone()->getName(), handZoneGraphicsItem);
}
void PlayerGraphicsItem::onCustomZoneAdded(QString customZoneName)
{
zoneGraphicsItems.insert(customZoneName, nullptr); // Custom zone view goes here, if we ever implement it.
}
QRectF PlayerGraphicsItem::boundingRect() const
@ -132,7 +149,7 @@ qreal PlayerGraphicsItem::getMinimumWidth() const
{
qreal result = tableZoneGraphicsItem->getMinimumWidth() + CardDimensions::HEIGHT_F + 15 + counterAreaWidth +
stackZoneGraphicsItem->boundingRect().width();
if (!SettingsCache::instance().getHorizontalHand()) {
if (!SettingsCache::instance().userInterface().getHorizontalHand()) {
result += handZoneGraphicsItem->boundingRect().width();
}
return result;
@ -149,7 +166,7 @@ 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()) {
if (!SettingsCache::instance().userInterface().getHorizontalHand()) {
tableWidth -= handZoneGraphicsItem->boundingRect().width();
}
@ -171,6 +188,11 @@ void PlayerGraphicsItem::onCounterAdded(CounterState *state)
AbstractCounter *widget;
if (state->getName() == "life") {
widget = playerTarget->addCounter(state);
connect(state, &CounterState::valueChanged, this, [this](int oldValue, int newValue) {
if (newValue < oldValue) {
tableZoneGraphicsItem->triggerDamageShimmer();
}
});
} else {
widget = new GeneralCounter(state, player, true, this);
}
@ -217,7 +239,7 @@ void PlayerGraphicsItem::rearrangeCounters()
void PlayerGraphicsItem::rearrangeZones()
{
auto base = QPointF(CardDimensions::HEIGHT_F + counterAreaWidth + 15, 0);
if (SettingsCache::instance().getHorizontalHand()) {
if (SettingsCache::instance().userInterface().getHorizontalHand()) {
if (mirrored) {
if (player->getHandZone()->contentsKnown()) {
handVisible = true;
@ -268,7 +290,7 @@ void PlayerGraphicsItem::updateBoundingRect()
{
prepareGeometryChange();
qreal width = CardDimensions::HEIGHT_F + 15 + counterAreaWidth + stackZoneGraphicsItem->boundingRect().width();
if (SettingsCache::instance().getHorizontalHand()) {
if (SettingsCache::instance().userInterface().getHorizontalHand()) {
qreal handHeight = handVisible ? handZoneGraphicsItem->boundingRect().height() : 0;
bRect = QRectF(0, 0, width + tableZoneGraphicsItem->boundingRect().width(),
tableZoneGraphicsItem->boundingRect().height() + handHeight);

View file

@ -77,6 +77,11 @@ public:
return playerTarget;
}
CardZone *getZoneGraphicsItem(const QString &name) const
{
return zoneGraphicsItems.value(name, nullptr);
}
[[nodiscard]] PileZone *getDeckZoneGraphicsItem() const
{
return deckZoneGraphicsItem;
@ -110,6 +115,7 @@ public:
public slots:
void onPlayerActiveChanged(bool _active);
void onCustomZoneAdded(QString customZoneName);
void onCounterAdded(CounterState *state);
void onCounterRemoved(int counterId);
void rearrangeCounters();
@ -128,6 +134,7 @@ private:
PlayerArea *playerArea;
PlayerTarget *playerTarget;
QMap<int, AbstractCounter *> counterWidgets;
QMap<QString, CardZone *> zoneGraphicsItems;
PileZone *deckZoneGraphicsItem;
PileZone *sideboardGraphicsItem;
PileZone *graveyardZoneGraphicsItem;

View file

@ -25,11 +25,7 @@ bool PlayerListItemDelegate::editorEvent(QEvent *event,
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;
}
}

View file

@ -1,8 +1,11 @@
#include "player_target.h"
#include "../../client/settings/cache_settings.h"
#include "../../game/player/player_logic.h"
#include "../../interface/pixel_map_generator.h"
#include "../game_scene.h"
#include <QApplication>
#include <QDebug>
#include <QPainter>
#include <QPixmapCache>
@ -21,17 +24,24 @@ QRectF PlayerCounter::boundingRect() const
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();
const int radius = 15;
const qreal border = 1.5;
// The box is drawn with a border-wide stroke straddling the path, so the
// visible outline spans [inset, inset + border]. Fills that must not cover
// the outline (e.g. the life-change flash) use a path inset by `border`.
const auto makePath = [](qreal inset) {
QPainterPath path(QPointF(50 - inset, inset));
path.lineTo(radius, inset);
path.arcTo(inset, inset, 2 * radius, 2 * radius, 90, 90);
path.lineTo(inset, 30 - inset);
path.lineTo(50 - inset, 30 - inset);
path.closeSubpath();
return path;
};
QPainterPath path = makePath(border / 2);
QPen pen(QColor(100, 100, 100));
pen.setWidth(border);
pen.setWidthF(border);
painter->setPen(pen);
painter->setBrush(hovered ? QColor(50, 50, 50, 160) : QColor(0, 0, 0, 160));
@ -45,6 +55,48 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
painter->setFont(font);
painter->setPen(Qt::white);
painter->drawText(translatedRect, Qt::AlignCenter, QString::number(value));
// Life-change flash: emerald on gain, red on loss, decaying over a few ticks.
if (flashAlpha > 0) {
painter->save();
QColor flashColor = flashDelta > 0 ? QColor(52, 224, 122) : QColor(239, 68, 68);
flashColor.setAlphaF(0.45 * flashAlpha);
painter->setPen(Qt::NoPen);
painter->setBrush(flashColor);
painter->setOpacity(0.85);
painter->drawPath(makePath(border));
painter->restore();
}
}
void PlayerCounter::onValueChanged(int oldValue, int newValue)
{
flashDelta = newValue - oldValue;
if (flashDelta == 0) {
return;
}
if (!SettingsCache::instance().userInterface().getLifeCounterAnimationsEnabled()) {
flashAlpha = 0.0;
return;
}
flashAlpha = 1.0;
flashClock.start();
if (scene()) {
static_cast<GameScene *>(scene())->registerAnimationItem(this);
}
}
bool PlayerCounter::animationEvent()
{
flashAlpha = 1.0 - flashClock.elapsed() / flashDurationMs;
if (flashAlpha <= 0.0) {
flashAlpha = 0.0;
return false;
}
update();
return true;
}
PlayerTarget::PlayerTarget(PlayerLogic *_owner, QGraphicsItem *parentItem)

View file

@ -7,21 +7,34 @@
#ifndef PLAYERTARGET_H
#define PLAYERTARGET_H
#include "../animated_item.h"
#include "../board/abstract_counter.h"
#include "../board/arrow_target.h"
#include "../board/graphics_item_type.h"
#include <QElapsedTimer>
#include <QPixmap>
class PlayerLogic;
class PlayerCounter : public AbstractCounter
class PlayerCounter : public AbstractCounter, public IAnimatedItem
{
Q_OBJECT
protected:
void onValueChanged(int oldValue, int newValue) override;
private:
static constexpr qreal flashDurationMs = 450.0;
QElapsedTimer flashClock;
qreal flashAlpha = 0.0;
int flashDelta = 0;
public:
PlayerCounter(CounterState *state, PlayerLogic *player, QGraphicsItem *parent);
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
bool animationEvent() override;
};
class PlayerTarget : public ArrowTarget