Merge branch 'master' into tooomm-qt5

This commit is contained in:
tooomm 2026-08-27 06:33:34 +02:00
commit 3bc08ef94c
357 changed files with 23069 additions and 2916 deletions

View file

@ -0,0 +1,63 @@
#include "lag_monitor.h"
#include <QCoreApplication>
#include <QEvent>
#include <QTimer>
LagMonitor::LagMonitor(QObject *parent) : QObject(parent)
{
qApp->installEventFilter(this);
timer = new QTimer(this);
timer->setInterval(TICK_INTERVAL_MS);
connect(timer, &QTimer::timeout, this, &LagMonitor::checkTick);
tickClock.start();
timer->start();
}
QList<LagMonitor::StallRecord> LagMonitor::recentStalls() const
{
return stalls;
}
void LagMonitor::clearStalls()
{
stalls.clear();
}
bool LagMonitor::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::ApplicationStateChange) {
// The transition may span a suspend or an arbitrary unfocused period;
// discard the gap so it cannot be mistaken for a stall.
tickClock.restart();
}
return QObject::eventFilter(obj, event);
}
void LagMonitor::checkTick()
{
recordGap(tickClock.restart());
}
void LagMonitor::recordGap(qint64 gapMs)
{
if (gapMs <= STALL_THRESHOLD_MS) {
return;
}
if (gapMs > MAX_PLAUSIBLE_STALL_MS) {
qCDebug(LagMonitorLog, "Ignoring implausible %lld ms gap (likely suspend)", static_cast<long long>(gapMs));
return;
}
const StallRecord record{.timestampMsSinceEpoch = QDateTime::currentMSecsSinceEpoch(), .durationMs = gapMs};
stalls.append(record);
while (stalls.size() > MAX_RECORDED_STALLS) {
stalls.removeFirst();
}
qCWarning(LagMonitorLog, "Event loop stalled for %lld ms (threshold: %d ms)", static_cast<long long>(gapMs),
STALL_THRESHOLD_MS);
}

View file

@ -0,0 +1,87 @@
/**
* @file lag_monitor.h
* @ingroup Client
*/
#ifndef LAG_MONITOR_H
#define LAG_MONITOR_H
#include <QDateTime>
#include <QElapsedTimer>
#include <QList>
#include <QLoggingCategory>
#include <QObject>
inline Q_LOGGING_CATEGORY(LagMonitorLog, "lag_monitor");
class QEvent;
class QTimer;
/**
* @brief Detects main-thread event loop stalls ("UI freezes") from the inside.
*
* A timer is expected to fire every TICK_INTERVAL_MS of wall time. When the
* observed gap greatly exceeds that interval, some other task blocked the
* event loop for roughly the overshooting duration. This is what separates
* "my client froze" from "the network is lagging" in user reports.
*
* Gaps that span an application state change (suspend, minimize, focus
* loss) are discarded, and implausibly huge gaps are dropped, so operating
* system power events do not fabricate stalls. This handling is load-bearing
* on Windows, where the monotonic clock used by Qt counts sleep time.
*
* Healthy operation costs one timer wakeup per tick and two integer
* comparisons. Allocations happen only when a stall is actually recorded.
*/
class LagMonitor : public QObject
{
Q_OBJECT
public:
struct StallRecord
{
qint64 timestampMsSinceEpoch = 0; ///< when the stalled period ended
qint64 durationMs = 0; ///< approximate length of the freeze; measured tick to tick, so it can exceed the true
///< stall by up to TICK_INTERVAL_MS
};
static constexpr int TICK_INTERVAL_MS = 500;
static constexpr int STALL_THRESHOLD_MS = 2000;
static constexpr int MAX_RECORDED_STALLS = 32;
/// Gaps beyond this are treated as suspend artifacts rather than stalls.
static constexpr qint64 MAX_PLAUSIBLE_STALL_MS = 600000;
explicit LagMonitor(QObject *parent = nullptr);
/**
* @brief Stalls recorded during this session, oldest first.
*
* Intended consumers are log output and the diagnostics export. The list
* holds at most MAX_RECORDED_STALLS entries.
*/
QList<StallRecord> recentStalls() const;
void clearStalls();
/**
* @brief Feeds a measured tick-to-tick gap through the detection logic.
*
* Split out of checkTick so threshold, plausibility, and trim behavior
* stay unit-testable without real timing.
*/
void recordGap(qint64 gapMs);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private slots:
void checkTick();
private:
QTimer *timer;
QElapsedTimer tickClock; ///< monotonic clock, so wall clock steps do not fabricate stalls
QList<StallRecord> stalls;
};
#endif

View file

@ -0,0 +1,51 @@
/**
* @file latency_graph_widget.cpp
* @ingroup Client
*/
#include "latency_graph_widget.h"
#include <QPainter>
LatencyGraphWidget::LatencyGraphWidget(QWidget *parent) : QWidget(parent)
{
}
void LatencyGraphWidget::setSamples(const QList<int> &samplesMs)
{
samples = samplesMs;
update();
}
void LatencyGraphWidget::paintEvent(QPaintEvent * /* event */)
{
if (samples.isEmpty()) {
return;
}
QPainter painter(this);
// Heights are relative to the window's own worst sample (floored at
// MinScaleMs) so the shape of the variance stays readable even when every
// value is small.
qint64 heightScaleMs = MinScaleMs;
for (int sample : samples) {
heightScaleMs = qMax(heightScaleMs, static_cast<qint64>(sample));
}
const qreal widthPerBar = static_cast<qreal>(width()) / samples.size();
for (int i = 0; i < samples.size(); ++i) {
const qreal heightRatio = qBound(0.0, static_cast<double>(samples.at(i)) / heightScaleMs, 1.0);
const qreal barHeight = heightRatio * height();
// Colors follow an absolute quality ramp: a steady good ping stays
// green no matter how uniform the window is.
const qreal colorRatio = qBound(0.0, static_cast<double>(samples.at(i)) / ColorScaleMs, 1.0);
QColor color;
color.setHsv(qRound(120.0 * (1.0 - colorRatio)), 255, 255);
const QRectF bar(static_cast<qreal>(i) * widthPerBar + 1.0, static_cast<qreal>(height()) - barHeight,
qMax(1.0, widthPerBar - 2.0), barHeight);
painter.fillRect(bar, color);
}
}

View file

@ -0,0 +1,43 @@
/**
* @file latency_graph_widget.h
* @ingroup Client
*/
#ifndef LATENCY_GRAPH_WIDGET_H
#define LATENCY_GRAPH_WIDGET_H
#include <QList>
#include <QWidget>
/**
* @brief Bar graph of recent network round-trip samples.
*
* Draws one bar per sample, oldest on the left. Bar height is relative to the
* window's own scale so the shape of the variance stays readable, while bar
* color maps each sample onto an absolute quality ramp (green at rest through
* red at ColorScaleMs) so a steady good ping never looks alarming. Size
* agnostic: the status bar embeds a small instance while the latency detail
* popup shows a large one.
*/
class LatencyGraphWidget : public QWidget
{
Q_OBJECT
public:
explicit LatencyGraphWidget(QWidget *parent = nullptr);
/// Sample in milliseconds that maps to a fully red bar.
static constexpr qint64 ColorScaleMs = 500;
void setSamples(const QList<int> &samplesMs);
protected:
void paintEvent(QPaintEvent *event) override;
private:
/// Floor of the vertical scale in milliseconds. Keeps small windows readable.
static constexpr qint64 MinScaleMs = 100;
QList<int> samples;
};
#endif

View file

@ -0,0 +1,111 @@
/**
* @file latency_status_widget.cpp
* @ingroup Client
*/
#include "latency_status_widget.h"
#include "latency_graph_widget.h"
#include <QEvent>
#include <QHBoxLayout>
#include <QLabel>
#include <QVBoxLayout>
LatencyStatusWidget::LatencyStatusWidget(QWidget *parent) : QWidget(parent)
{
pingLabel = new QLabel(this);
pingLabel->setAccessibleName(tr("Ping"));
latencyGraph = new LatencyGraphWidget(this);
latencyGraph->setFixedSize(90, 14);
auto *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(4);
layout->addWidget(latencyGraph);
layout->addWidget(pingLabel);
// Clicking anywhere in the area opens the detail view.
for (QObject *child : QList<QObject *>{pingLabel, latencyGraph}) {
child->installEventFilter(this);
}
setCursor(Qt::PointingHandCursor);
hide();
}
void LatencyStatusWidget::updateData(const LatencyTracker::Stats &stats, const QList<int> &samplesMs)
{
latestSamples = samplesMs;
latencyGraph->setSamples(samplesMs);
if (popup && popup->isVisible() && detailGraph) {
detailGraph->setSamples(samplesMs);
}
if (stats.sampleCount == 0) {
hide();
return;
}
const QString statsStr = statsText(stats);
pingLabel->setText(tr("Ping: %1 ms").arg(stats.lastMs));
pingLabel->setToolTip(statsStr);
pingLabel->setAccessibleDescription(statsStr);
if (popup && popup->isVisible() && detailLabel) {
detailLabel->setText(statsStr);
}
show();
}
bool LatencyStatusWidget::eventFilter(QObject *watched, QEvent *event)
{
if ((watched == pingLabel || watched == latencyGraph) && event->type() == QEvent::MouseButtonPress) {
togglePopup();
return true;
}
return QWidget::eventFilter(watched, event);
}
void LatencyStatusWidget::togglePopup()
{
if (!popup) {
popup = new QWidget(this, Qt::Popup | Qt::FramelessWindowHint);
auto *layout = new QVBoxLayout(popup);
layout->setContentsMargins(8, 8, 8, 8);
detailLabel = new QLabel(popup);
detailLabel->setAccessibleName(tr("Connection latency details"));
detailLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
detailGraph = new LatencyGraphWidget(popup);
detailGraph->setFixedSize(280, 80);
layout->addWidget(detailLabel, 0, Qt::AlignLeft);
layout->addWidget(detailGraph, 0, Qt::AlignHCenter);
}
if (popup->isVisible()) {
popup->hide();
return;
}
// Qt::Popup closes itself on any outside click, so just position and show.
if (latestSamples.isEmpty()) {
return;
}
detailGraph->setSamples(latestSamples);
detailLabel->setText(pingLabel->toolTip());
popup->adjustSize();
const QPoint anchor = mapToGlobal(QPoint(width() / 2, 0));
popup->move(anchor.x() - popup->width() / 2, anchor.y() - popup->height() - 6);
popup->show();
}
QString LatencyStatusWidget::statsText(const LatencyTracker::Stats &stats) const
{
return tr("Connection quality over the last %n sample(s):", "", stats.sampleCount) + "\n" +
tr("Last: %1 ms").arg(stats.lastMs) + "\n" + tr("Median: %1 ms").arg(stats.medianMs) + "\n" +
tr("95th percentile: %1 ms").arg(stats.p95Ms) + "\n" + tr("Maximum: %1 ms").arg(stats.maxMs);
}

View file

@ -0,0 +1,50 @@
/**
* @file latency_status_widget.h
* @ingroup Client
*/
#ifndef LATENCY_STATUS_WIDGET_H
#define LATENCY_STATUS_WIDGET_H
#include <QList>
#include <QWidget>
#include <libcockatrice/network/client/abstract/latency_tracker.h>
class QLabel;
class LatencyGraphWidget;
/**
* @brief Status bar presentation of server round-trip health.
*
* Combines the textual "Ping" readout with a small LatencyGraphWidget
* sparkline of the rolling sample window. Clicking anywhere in the area opens
* a popup with a larger graph and the numeric statistics. It closes on any
* outside click. Stays hidden while disconnected or before any samples exist.
* Owns all latency display state so MainWindow only needs to forward one
* signal here.
*/
class LatencyStatusWidget : public QWidget
{
Q_OBJECT
public:
explicit LatencyStatusWidget(QWidget *parent = nullptr);
public slots:
void updateData(const LatencyTracker::Stats &stats, const QList<int> &samplesMs);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private:
void togglePopup();
QString statsText(const LatencyTracker::Stats &stats) const;
QLabel *pingLabel = nullptr;
LatencyGraphWidget *latencyGraph = nullptr;
QWidget *popup = nullptr;
LatencyGraphWidget *detailGraph = nullptr;
QLabel *detailLabel = nullptr;
QList<int> latestSamples;
};
#endif

View file

@ -44,6 +44,8 @@ void ConnectionController::wireClientSignals()
connect(remoteClient, &RemoteClient::statusChanged, this, &ConnectionController::onStatusChanged);
connect(remoteClient, &AbstractClient::pingStatsUpdated, this, &ConnectionController::pingStatsUpdated);
connect(remoteClient, &RemoteClient::userInfoChanged, this, &ConnectionController::onUserInfoReceived,
Qt::BlockingQueuedConnection);
@ -296,6 +298,15 @@ void ConnectionController::onLoginError(int r,
return;
}
case Response::RespPasswordChangeRequired: {
QMessageBox::information(
dialogParent, tr("Password Change Required"),
tr("An administrator has reset your password. Please contact your server administrator to obtain "
"your temporary password, then log in and change it via Account -> Change Password."));
remoteClient->disconnectFromServer();
return;
}
case Response::RespServerFull: {
QMessageBox::critical(dialogParent, tr("Server Full"),
tr("The server has reached its maximum user capacity, please check back later."));

View file

@ -54,6 +54,10 @@ signals:
// action enable/disable logic
void statusChanged(ClientStatus status);
// Forwarded from AbstractClient::pingStatsUpdated. See that signal for the
// meaning of the parameters.
void pingStatsUpdated(const LatencyTracker::Stats &stats, const QList<int> &samplesMs);
private slots:
// Slots wired directly to RemoteClient signals
void onStatusChanged(ClientStatus status);

View file

@ -72,7 +72,7 @@ void DeckStatsInterface::copyDeckWithoutTokens(const DeckList &source, DeckList
{
auto copyIfNotAToken = [&destination](const auto node, const auto card) {
CardInfoPtr dbCard = CardDatabaseManager::query()->getCardInfo(card->getName());
if (dbCard && !dbCard->getIsToken()) {
if (dbCard && !dbCard->getIsToken() && node->getName() != DECK_ZONE_MAYBEBOARD) {
DecklistCardNode *addedCard = destination.addCard(card->getName(), node->getName(), -1);
addedCard->setNumber(card->getNumber());
}

View file

@ -99,7 +99,7 @@ void TappedOutInterface::copyDeckSplitMainAndSide(const DeckList &source, DeckLi
{
auto copyMainOrSide = [&mainboard, &sideboard](const auto node, const auto card) {
CardInfoPtr dbCard = CardDatabaseManager::query()->getCardInfo(card->getName());
if (!dbCard || dbCard->getIsToken()) {
if (!dbCard || dbCard->getIsToken() || node->getName() == DECK_ZONE_MAYBEBOARD) {
return;
}

View file

@ -786,6 +786,10 @@ private:
ShortcutGroup::Tabs)},
{"Tabs/aTabLogs",
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Logs"), parseSequenceString(""), ShortcutGroup::Tabs)},
{"Tabs/aTabReport",
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Report Queue"), parseSequenceString(""), ShortcutGroup::Tabs)},
{"Tabs/aTabModeration",
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Moderation"), parseSequenceString(""), ShortcutGroup::Tabs)},
};
};

View file

@ -52,18 +52,14 @@ static void setupParserRules()
search["Start"] = passthru;
search["QueryPartList"] = [](const peg::SemanticValues &sv) -> DeckFilter {
return [=](const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &info) {
auto matchesFilter = [&deck, &info](const std::any &query) {
return std::any_cast<DeckFilter>(query)(deck, info);
};
return [=](const DeckSearchData &data) {
auto matchesFilter = [&data](const std::any &query) { return std::any_cast<DeckFilter>(query)(data); };
return std::all_of(sv.begin(), sv.end(), matchesFilter);
};
};
search["ComplexQueryPart"] = [](const peg::SemanticValues &sv) -> DeckFilter {
return [=](const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &info) {
auto matchesFilter = [&deck, &info](const std::any &query) {
return std::any_cast<DeckFilter>(query)(deck, info);
};
return [=](const DeckSearchData &data) {
auto matchesFilter = [&data](const std::any &query) { return std::any_cast<DeckFilter>(query)(data); };
return std::any_of(sv.begin(), sv.end(), matchesFilter);
};
};
@ -71,9 +67,7 @@ static void setupParserRules()
search["QueryPart"] = passthru;
search["NotQuery"] = [](const peg::SemanticValues &sv) -> DeckFilter {
const auto dependent = std::any_cast<DeckFilter>(sv[0]);
return [=](const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &info) -> bool {
return !dependent(deck, info);
};
return [=](const DeckSearchData &data) -> bool { return !dependent(data); };
};
search["String"] = [](const peg::SemanticValues &sv) -> QString {
@ -125,9 +119,9 @@ static void setupParserRules()
auto cardFilter = FilterString(std::any_cast<QString>(sv[0]));
auto numberMatcher = sv.size() > 1 ? std::any_cast<NumberMatcher>(sv[1]) : [](int count) { return count > 0; };
return [=](const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &) -> bool {
return [=](const DeckSearchData &data) -> bool {
int count = 0;
auto cardNodes = deck->deckLoader->getDeck().deckList.getCardNodes();
auto cardNodes = data.deck->deckList.getCardNodes();
for (auto node : cardNodes) {
auto cardInfoPtr = CardDatabaseManager::query()->getCardInfo(node->getName());
if (!cardInfoPtr.isNull() && cardFilter.check(cardInfoPtr)) {
@ -146,53 +140,49 @@ static void setupParserRules()
search["DeckNameQuery"] = [](const peg::SemanticValues &sv) -> DeckFilter {
auto name = std::any_cast<QString>(sv[0]);
return [=](const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &) {
return deck->deckLoader->getDeck().deckList.getName().contains(name, Qt::CaseInsensitive);
return [=](const DeckSearchData &data) {
return data.deck->deckList.getName().contains(name, Qt::CaseInsensitive);
};
};
search["FileNameQuery"] = [](const peg::SemanticValues &sv) -> DeckFilter {
auto name = std::any_cast<QString>(sv[0]);
return [=](const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &) {
auto filename = QFileInfo(deck->filePath).fileName();
return [=](const DeckSearchData &data) {
auto filename = QFileInfo(data.filePath).fileName();
return filename.contains(name, Qt::CaseInsensitive);
};
};
search["PathQuery"] = [](const peg::SemanticValues &sv) -> DeckFilter {
auto name = std::any_cast<QString>(sv[0]);
return [=](const DeckPreviewWidget *, const ExtraDeckSearchInfo &info) {
return info.relativeFilePath.contains(name, Qt::CaseInsensitive);
};
return [=](const DeckSearchData &data) { return data.relativeFilePath.contains(name, Qt::CaseInsensitive); };
};
search["FormatQuery"] = [](const peg::SemanticValues &sv) -> DeckFilter {
auto format = std::any_cast<QString>(sv[0]);
return [=](const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &) {
auto gameFormat = deck->deckLoader->getDeck().deckList.getGameFormat();
return [=](const DeckSearchData &data) {
auto gameFormat = data.deck->deckList.getGameFormat();
return QString::compare(format, gameFormat, Qt::CaseInsensitive) == 0;
};
};
search["CommentQuery"] = [](const peg::SemanticValues &sv) -> DeckFilter {
auto value = std::any_cast<QString>(sv[0]);
return [=](const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &) {
auto comments = deck->deckLoader->getDeck().deckList.getComments();
return [=](const DeckSearchData &data) {
auto comments = data.deck->deckList.getComments();
return comments.contains(value, Qt::CaseInsensitive);
};
};
search["GenericQuery"] = [](const peg::SemanticValues &sv) -> DeckFilter {
auto name = std::any_cast<QString>(sv[0]);
return [=](const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &) {
return deck->getDisplayName().contains(name, Qt::CaseInsensitive);
};
return [=](const DeckSearchData &data) { return data.displayName.contains(name, Qt::CaseInsensitive); };
};
}
DeckFilterString::DeckFilterString()
{
filter = [](const DeckPreviewWidget *, const ExtraDeckSearchInfo &) { return false; };
filter = [](const DeckSearchData &) { return false; };
_error = "Not initialized";
}
@ -205,7 +195,7 @@ DeckFilterString::DeckFilterString(const QString &expr)
_error = QString();
if (ba.isEmpty()) {
filter = [](const DeckPreviewWidget *, const ExtraDeckSearchInfo &) { return true; };
filter = [](const DeckSearchData &) { return true; };
return;
}
@ -215,6 +205,6 @@ DeckFilterString::DeckFilterString(const QString &expr)
if (!search.parse(ba.data(), filter)) {
qCInfo(DeckFilterStringLog).nospace() << "DeckFilterString error for " << expr << "; " << qPrintable(_error);
filter = [](const DeckPreviewWidget *, const ExtraDeckSearchInfo &) { return false; };
filter = [](const DeckSearchData &) { return false; };
}
}
}

View file

@ -7,7 +7,7 @@
#ifndef DECK_FILTER_STRING_H
#define DECK_FILTER_STRING_H
#include "../interface/widgets/visual_deck_storage/deck_preview/deck_preview_widget.h"
#include "../interface/deck_loader/loaded_deck.h"
#include <QLoggingCategory>
#include <QString>
@ -16,26 +16,29 @@
inline Q_LOGGING_CATEGORY(DeckFilterStringLog, "deck_filter_string");
/**
* Extra info relevant to filtering that isn't present in the DeckPreviewWidget
* The data a deck search expression is evaluated against.
*
* This is a data view rather than a widget pointer, so the same filter
* expression can be evaluated against a model or a live widget.
*/
struct ExtraDeckSearchInfo
struct DeckSearchData
{
/**
* The relative filepath starting from the deck folder
*/
QString relativeFilePath;
const LoadedDeck *deck = nullptr; ///< The loaded deck. Must not be null.
QString filePath; ///< Absolute path of the deck file.
QString displayName; ///< Deck name, or the file name if the deck has no name.
QString relativeFilePath; ///< File path relative to the deck folder.
};
typedef std::function<bool(const DeckPreviewWidget *, const ExtraDeckSearchInfo &)> DeckFilter;
typedef std::function<bool(const DeckSearchData &data)> DeckFilter;
class DeckFilterString
{
public:
DeckFilterString();
explicit DeckFilterString(const QString &expr);
bool check(const DeckPreviewWidget *deck, const ExtraDeckSearchInfo &info) const
bool check(const DeckSearchData &data) const
{
return filter(deck, info);
return filter(data);
}
[[nodiscard]] bool valid() const

View file

@ -229,7 +229,11 @@ void GameEventHandler::handleArrowDeletion(int creatorId, int arrowId)
void GameEventHandler::handleArrowDeletionFinished(const Response &response, int creatorId, int arrowId)
{
if (response.response_code() == Response::RespNameNotFound) {
// The server confirms the arrow no longer exists whether it deleted it itself
// (RespOk, followed by an Event_DeleteArrow broadcast) or never had it
// (RespNameNotFound). In both cases the local copy has to go. deleteArrow is
// a no-op if the arrow was already removed by the event broadcast.
if (response.response_code() == Response::RespOk || response.response_code() == Response::RespNameNotFound) {
emit arrowDeleted(creatorId, arrowId);
}
}
@ -281,12 +285,19 @@ void GameEventHandler::eventGameStateChanged(const Event_GameStateChanged &event
emit playerJoined(prop);
}
player->processPlayerInfo(playerInfo);
// Extract playmat from player properties for opponent display
if (prop.has_playmat_params()) {
player->setPlaymatFromProperties(prop);
}
if (player->getPlayerInfo()->getLocal()) {
emit localPlayerDeckSelected(player, playerId, playerInfo);
} else {
if (!game->getGameMetaInfo()->proto().share_decklists_on_load()) {
continue;
}
if (!playerInfo.has_deck_list()) {
continue;
}
opponentDecksToDisplay.append(
qMakePair(playerId, qMakePair(playerName, QString::fromStdString(playerInfo.deck_list()))));
@ -344,6 +355,11 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
const ServerInfo_PlayerProperties &prop = event.player_properties();
emit playerPropertiesChanged(prop, eventPlayerId);
// Update playmat from player properties
if (prop.has_playmat_params()) {
player->setPlaymatFromProperties(prop);
}
const auto contextType = static_cast<GameEventContext::ContextType>(getPbExtension(context));
switch (contextType) {
case GameEventContext::READY_START: {

View file

@ -250,6 +250,22 @@ void PlayerLogic::setDeck(const DeckList &_deck)
emit deckChanged();
}
void PlayerLogic::setPlaymatFromProperties(const ServerInfo_PlayerProperties &props)
{
if (props.has_playmat_params() && !props.playmat_params().card_name().empty()) {
const auto &pp = props.playmat_params();
remotePlaymatCard = {QString::fromStdString(pp.card_name()), QString::fromStdString(pp.card_provider_id())};
remotePlaymatParams = {qBound(0.0, pp.margin_pct_l(), 0.95), qBound(0.0, pp.margin_pct_r(), 0.95),
qBound(0.0, pp.vertical_offset(), 1.0), qBound(0.1, pp.zoom(), 4.0)};
hasRemotePlaymat = true;
} else {
remotePlaymatCard = CardRef{};
remotePlaymatParams = PlaymatParams{};
hasRemotePlaymat = false;
}
emit playmatChanged();
}
CounterState *PlayerLogic::addCounter(const ServerInfo_Counter &counter)
{
return addCounter(counter.id(), QString::fromStdString(counter.name()),

View file

@ -17,6 +17,7 @@
#include "../zones/table_zone_logic.h"
#include "player_event_handler.h"
#include "player_info.h"
#include "player_manager.h"
#include <QInputDialog>
#include <QLoggingCategory>
@ -72,6 +73,8 @@ signals:
const QList<const ServerInfo_Card *> &cardList,
bool withWritePermission);
void deckChanged();
/** @brief Emitted when the remote playmat (card/params) is updated from player properties. */
void playmatChanged();
void newCardAdded(AbstractCardItem *card);
void requestCardMenuUpdate(const CardItem *card);
void counterAdded(CounterState *state);
@ -226,6 +229,20 @@ public:
void setZoneId(int _zoneId);
void setPlaymatFromProperties(const ServerInfo_PlayerProperties &props);
const CardRef &getRemotePlaymatCard() const
{
return remotePlaymatCard;
}
const PlaymatParams &getRemotePlaymatParams() const
{
return remotePlaymatParams;
}
bool getHasRemotePlaymat() const
{
return hasRemotePlaymat;
}
private:
AbstractGame *game;
PlayerInfo *playerInfo;
@ -243,6 +260,11 @@ private:
bool dialogSemaphore;
QList<CardItem *> cardsToDelete;
// Playmat from player properties (for opponent display)
CardRef remotePlaymatCard;
PlaymatParams remotePlaymatParams;
bool hasRemotePlaymat = false;
};
class AnnotationDialog : public QInputDialog

View file

@ -0,0 +1,26 @@
#ifndef ANIMATED_ITEM_H
#define ANIMATED_ITEM_H
/**
* @file animated_item.h
* @ingroup GameGraphics
* @brief Interface for scene items driven by GameScene's shared animation timer.
*
* Items that want per-tick animation while a single QBasicTimer runs (instead of
* owning their own QTimer) implement this interface and register with the scene
* via GameScene::registerAnimationItem.
*/
class IAnimatedItem
{
public:
virtual ~IAnimatedItem() = default;
/**
* @brief Advances the item's animation by one timer tick.
* @return true while the animation is still running, false once it has finished.
*/
virtual bool animationEvent() = 0;
};
#endif

View file

@ -305,6 +305,11 @@ void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
}
}
bool AbstractCardItem::animationEvent()
{
return false;
}
void AbstractCardItem::setFaceDown(bool _facedown)
{
facedown = _facedown;

View file

@ -7,6 +7,7 @@
#ifndef ABSTRACTCARDITEM_H
#define ABSTRACTCARDITEM_H
#include "../animated_item.h"
#include "../card_dimensions.h"
#include "arrow_target.h"
#include "graphics_item_type.h"
@ -16,7 +17,7 @@
class PlayerLogic;
class AbstractCardItem : public ArrowTarget
class AbstractCardItem : public ArrowTarget, public IAnimatedItem
{
Q_OBJECT
protected:
@ -126,6 +127,9 @@ public:
emit deleteCardInfoPopup(cardRef.name);
}
/** @brief Default: no per-tick animation. Subclasses override to animate. */
bool animationEvent() override;
protected:
void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle);
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;

View file

@ -29,8 +29,9 @@ AbstractCounter::AbstractCounter(CounterState *state,
{
setAcceptHoverEvents(true);
connect(state, &CounterState::valueChanged, this, [this](int, int newValue) {
connect(state, &CounterState::valueChanged, this, [this](int oldValue, int newValue) {
value = newValue;
onValueChanged(oldValue, newValue);
update();
});
@ -228,3 +229,9 @@ void AbstractCounterDialog::changeValue(int diff)
curValue += diff;
setTextValue(QString::number(curValue));
}
void AbstractCounter::onValueChanged(int /*oldValue*/, int /*newValue*/)
{
// Default: no feedback. Subclasses such as PlayerCounter override this to
// flash the counter on meaningful changes (life gain/loss).
}

View file

@ -35,6 +35,13 @@ protected:
bool hovered = false;
bool useNameForShortcut;
/**
* @brief Hook for subclasses that need per-value-change feedback (e.g. life-total flash).
*
* Called whenever the counter's value changes, before the item repaints.
*/
virtual void onValueChanged(int oldValue, int newValue);
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;

View file

@ -4,12 +4,14 @@
#include "../../client/settings/cache_settings.h"
#include "../../game/player/player_actions.h"
#include "../../game/player/player_logic.h"
#include "../game_scene.h"
#include "../player/player_target.h"
#include "../z_values.h"
#include "../zones/card_zone.h"
#include "card_item.h"
#include <QDebug>
#include <QElapsedTimer>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
@ -18,10 +20,27 @@
#include <libcockatrice/protocol/pb/command_attach_card.pb.h>
#include <libcockatrice/protocol/pb/command_create_arrow.pb.h>
#include <libcockatrice/protocol/pb/command_delete_arrow.pb.h>
#include <libcockatrice/settings/cards_display_settings.h>
#include <libcockatrice/settings/interface_settings.h>
#include <libcockatrice/utility/color.h>
#include <libcockatrice/utility/zone_names.h>
namespace
{
constexpr qreal kMinStrokeDurationMs = 200.0;
constexpr qreal kMaxStrokeDurationMs = 450.0;
constexpr qreal kMsPerPixel = 0.8;
constexpr qreal kGlowFadeDurationMs = 120.0;
constexpr qreal kSheenHalfWidth = 14.0;
/// @brief Ease-out cubic, for a natural "slow in / slow out" reveal.
qreal easeOutCubic(qreal t)
{
const qreal inverse = 1.0 - t;
return 1.0 - inverse * inverse * inverse;
}
} // namespace
ArrowItem::ArrowItem(QSharedPointer<const ArrowData> _data, ArrowTarget *_startItem, ArrowTarget *_targetItem)
: data(std::move(_data)), startItem(_startItem), targetItem(_targetItem)
{
@ -47,8 +66,23 @@ ArrowItem::ArrowItem(QSharedPointer<const ArrowData> _data, ArrowTarget *_startI
}
}
ArrowItem::~ArrowItem()
{
if (auto *scene = qobject_cast<GameScene *>(this->scene())) {
scene->unregisterAnimationItem(this);
}
}
void ArrowItem::onTargetDestroyed()
{
if (data->id == -1) {
// Drag and attach arrows are never inserted into the arrow registry and
// have no server-side counterpart, so no deletion event can clean them
// up. Delete them locally when either endpoint is destroyed.
delArrow();
return;
}
emit requestDeletion(data->creatorId, data->id);
}
@ -91,16 +125,21 @@ void ArrowItem::updatePath(const QPointF &endPoint)
prepareGeometryChange();
if (lineLength < 30) {
path = QPainterPath();
bodyPath = QPainterPath();
headPath = QPainterPath();
shaftOutlinePath = QPainterPath();
centerLine = QPainterPath();
headBaseFraction = 1.0;
} else {
QPointF c(lineLength / 2, qTan(phi * M_PI / 180) * lineLength);
QPainterPath centerLine;
centerLine = QPainterPath();
centerLine.moveTo(0, 0);
centerLine.quadTo(c, QPointF(lineLength, 0));
double percentage = 1 - headLength / lineLength;
QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage);
QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001));
headBaseFraction = 1 - headLength / lineLength;
QPointF arrowBodyEndPoint = centerLine.pointAtPercent(headBaseFraction);
QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(headBaseFraction + 0.001));
qreal alpha = testLine.angle() - 90;
QPointF endPoint1 =
arrowBodyEndPoint + arrowWidth / 2 * QPointF(qCos(alpha * M_PI / 180), -qSin(alpha * M_PI / 180));
@ -111,20 +150,89 @@ void ArrowItem::updatePath(const QPointF &endPoint)
QPointF point2 =
endPoint2 + (headWidth - arrowWidth) / 2 * QPointF(-qCos(alpha * M_PI / 180), qSin(alpha * M_PI / 180));
path = QPainterPath(-arrowWidth / 2 * QPointF(qCos((phi - 90) * M_PI / 180), qSin((phi - 90) * M_PI / 180)));
QPointF start1 = -arrowWidth / 2 * QPointF(qCos((phi - 90) * M_PI / 180), qSin((phi - 90) * M_PI / 180));
QPointF start2 = arrowWidth / 2 * QPointF(qCos((phi - 90) * M_PI / 180), qSin((phi - 90) * M_PI / 180));
path = QPainterPath(start1);
path.quadTo(c, endPoint1);
path.lineTo(point1);
path.lineTo(QPointF(lineLength, 0));
path.lineTo(point2);
path.lineTo(endPoint2);
path.quadTo(c, arrowWidth / 2 * QPointF(qCos((phi - 90) * M_PI / 180), qSin((phi - 90) * M_PI / 180)));
path.lineTo(-arrowWidth / 2 * QPointF(qCos((phi - 90) * M_PI / 180), qSin((phi - 90) * M_PI / 180)));
path.quadTo(c, start2);
path.lineTo(start1);
bodyPath = QPainterPath(start1);
bodyPath.quadTo(c, endPoint1);
bodyPath.lineTo(endPoint2);
bodyPath.quadTo(c, start2);
bodyPath.lineTo(start1);
headPath = QPainterPath(endPoint1);
headPath.lineTo(point1);
headPath.lineTo(QPointF(lineLength, 0));
headPath.lineTo(point2);
headPath.lineTo(endPoint2);
shaftOutlinePath = QPainterPath(start1);
shaftOutlinePath.quadTo(c, endPoint1);
shaftOutlinePath.moveTo(endPoint2);
shaftOutlinePath.quadTo(c, start2);
shaftOutlinePath.lineTo(start1);
}
setPos(startPoint);
setTransform(QTransform().rotate(-line.angle()));
}
void ArrowItem::startDrawAnimation()
{
if (!SettingsCache::instance().cardsDisplay().getArrowDrawAnimation() || centerLine.isEmpty()) {
return;
}
strokeDurationMs = qBound(kMinStrokeDurationMs, centerLine.length() * kMsPerPixel, kMaxStrokeDurationMs);
glowFadeDurationMs = kGlowFadeDurationMs;
// The clock is started on the first animationEvent() tick so that t=0
// corresponds to the first rendered frame. Starting it here would count
// the time spent before the item's first paint (event-loop delays, bursts
// of arrows created together), making the arrow appear already partway
// drawn when it first shows up.
animationStarted = false;
drawProgress = 0.0;
glowAlpha = 1.0;
update();
if (auto *scene = qobject_cast<GameScene *>(this->scene())) {
scene->registerAnimationItem(this);
}
}
bool ArrowItem::animationEvent()
{
if (!animationStarted) {
animationClock.start();
animationStarted = true;
}
const qint64 elapsed = animationClock.elapsed();
if (elapsed >= strokeDurationMs + glowFadeDurationMs) {
drawProgress = 1.0;
glowAlpha = 0.0;
update();
return false;
}
if (elapsed < strokeDurationMs) {
drawProgress = easeOutCubic(qBound<qreal>(0.0, elapsed / strokeDurationMs, 1.0));
glowAlpha = 1.0;
} else {
drawProgress = 1.0;
glowAlpha = 1.0 - (elapsed - strokeDurationMs) / glowFadeDurationMs;
}
update();
return true;
}
void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
QColor paintColor(data->color);
@ -133,8 +241,66 @@ void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*opti
} else {
paintColor.setAlpha(150);
}
painter->save();
const QPen outlinePen = painter->pen();
painter->setBrush(paintColor);
painter->drawPath(path);
const auto drawShaft = [this, painter, &outlinePen, paintColor]() {
painter->setPen(Qt::NoPen);
painter->drawPath(bodyPath);
painter->setPen(outlinePen);
painter->setBrush(Qt::NoBrush);
painter->drawPath(shaftOutlinePath);
painter->setBrush(paintColor);
};
if (drawProgress >= 1.0 || path.isEmpty()) {
painter->drawPath(path);
} else if (drawProgress < headBaseFraction) {
// The reveal edge and the sheen share the same arc-length parameterization,
// so the stroke stays exactly in sync with the trailing sheen.
const qreal revealX = centerLine.pointAtPercent(drawProgress).x();
QPainterPath clip;
clip.addRect(QRectF(-glowExtent, path.boundingRect().top() - glowExtent, revealX + glowExtent,
path.boundingRect().height() + 2 * glowExtent));
painter->setClipPath(clip);
drawShaft();
} else {
// Once the reveal reaches the head base, pop the whole head in with a fade
// instead of slicing the triangle into a growing stub.
drawShaft();
const qreal headFadeIn = (drawProgress - headBaseFraction) / (1.0 - headBaseFraction);
painter->setOpacity(headFadeIn);
painter->setPen(Qt::NoPen);
painter->drawPath(headPath);
painter->setPen(outlinePen);
painter->setBrush(Qt::NoBrush);
painter->drawPath(headPath);
painter->setOpacity(1.0);
painter->setBrush(paintColor);
}
if (glowAlpha > 0.0 && !centerLine.isEmpty()) {
// Sweep a bright band across the arrow. Clipping to the
// silhouette keeps it flat against the shaft so it reads as a light reflection.
const qreal anticipation = qMin<qreal>(1.0, drawProgress / 0.08);
const QPointF sweep = centerLine.pointAtPercent(qMin<qreal>(drawProgress, 1.0));
QLinearGradient sheen(sweep.x() - kSheenHalfWidth, 0.0, sweep.x() + kSheenHalfWidth, 0.0);
sheen.setColorAt(0.0, QColor(paintColor.red(), paintColor.green(), paintColor.blue(), 0));
sheen.setColorAt(0.5, QColor(255, 255, 255, 200));
sheen.setColorAt(1.0, QColor(paintColor.red(), paintColor.green(), paintColor.blue(), 0));
painter->save();
painter->setPen(Qt::NoPen);
painter->setClipPath(path);
painter->setBrush(sheen);
painter->setOpacity(glowAlpha * anticipation);
painter->drawRect(QRectF(sweep.x() - kSheenHalfWidth - glowExtent, path.boundingRect().top() - glowExtent,
(kSheenHalfWidth + glowExtent) * 2.0,
path.boundingRect().height() + glowExtent * 2.0));
painter->restore();
}
painter->restore();
}
void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
@ -226,6 +392,12 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (!startItem) {
// The source card was destroyed while the arrow was being drawn.
// Clean up the arrow and its children instead of leaking them.
delArrow();
for (auto *child : childArrows) {
child->mouseReleaseEvent(event);
}
return;
}
@ -349,6 +521,12 @@ void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (!startItem) {
// The source card was destroyed while the arrow was being drawn.
// Clean up the arrow and its children instead of leaking them.
delArrow();
for (auto *child : childArrows) {
child->mouseReleaseEvent(event);
}
return;
}

View file

@ -2,9 +2,13 @@
#define ARROWITEM_H
#include "../../game/board/arrow_data.h"
#include "../animated_item.h"
#include "arrow_target.h"
#include "graphics_item_type.h"
#include <QElapsedTimer>
#include <QGraphicsItem>
#include <QPainterPath>
#include <QPointer>
#include <QSharedPointer>
@ -12,7 +16,7 @@ class CardItem;
class QGraphicsSceneMouseEvent;
class PlayerLogic;
class ArrowItem : public QObject, public QGraphicsItem
class ArrowItem : public QObject, public QGraphicsItem, public IAnimatedItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
@ -21,6 +25,19 @@ signals:
private:
QPainterPath path;
QPainterPath bodyPath;
QPainterPath headPath;
QPainterPath shaftOutlinePath;
QPainterPath centerLine;
qreal headBaseFraction = 1.0;
QElapsedTimer animationClock;
qreal strokeDurationMs = 0;
qreal glowFadeDurationMs = 0;
qreal drawProgress = 1.0;
qreal glowAlpha = 0.0;
bool animationStarted = false;
static constexpr qreal glowExtent = 12.0;
protected:
QSharedPointer<const ArrowData> data;
@ -32,17 +49,28 @@ protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
public:
enum
{
Type = typeArrow
};
[[nodiscard]] int type() const override
{
return Type;
}
ArrowItem(QSharedPointer<const ArrowData> _data, ArrowTarget *_startItem, ArrowTarget *_targetItem);
~ArrowItem() override;
void onTargetDestroyed();
void delArrow();
void updatePath();
void updatePath(const QPointF &endPoint);
void startDrawAnimation();
bool animationEvent() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
[[nodiscard]] QRectF boundingRect() const override
{
return path.boundingRect();
return path.boundingRect().adjusted(-glowExtent, -glowExtent, glowExtent, glowExtent);
}
[[nodiscard]] QPainterPath shape() const override
{
@ -106,4 +134,4 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
};
#endif
#endif

View file

@ -137,7 +137,7 @@ public:
void resetState(bool keepAnnotations = false);
void processCardInfo(const ServerInfo_Card &_info);
bool animationEvent();
bool animationEvent() override;
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool forceFaceDown);
void deleteDragItem();
void drawArrow(const QColor &arrowColor);

View file

@ -16,7 +16,8 @@ enum GraphicsItemType
typeZone = QGraphicsItem::UserType + 3,
typePlayerTarget = QGraphicsItem::UserType + 4,
typeDeckViewCardContainer = QGraphicsItem::UserType + 5,
typeOther = QGraphicsItem::UserType + 6
typeOther = QGraphicsItem::UserType + 6,
typeArrow = QGraphicsItem::UserType + 7
};
#endif // COCKATRICE_GRAPHICS_ITEM_TYPE_H

View file

@ -9,17 +9,21 @@
#include "../../interface/widgets/dialogs/dlg_load_deck_from_website.h"
#include "../../interface/widgets/dialogs/dlg_load_remote_deck.h"
#include "../../interface/widgets/tabs/tab_game.h"
#include "../../interface/widgets/visual_deck_storage/visual_deck_storage_widget.h"
#include "deck_view.h"
#include <QMessageBox>
#include <libcockatrice/card/database/card_database.h>
#include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/deck_list/playmat_resolver.h>
#include <libcockatrice/protocol/pb/command_deck_select.pb.h>
#include <libcockatrice/protocol/pb/command_ready_start.pb.h>
#include <libcockatrice/protocol/pb/command_set_playmat.pb.h>
#include <libcockatrice/protocol/pb/command_set_sideboard_lock.pb.h>
#include <libcockatrice/protocol/pb/command_set_sideboard_plan.pb.h>
#include <libcockatrice/protocol/pb/response_deck_download.pb.h>
#include <libcockatrice/protocol/pending_command.h>
#include <libcockatrice/settings/interface_settings.h>
#include <libcockatrice/settings/visual_deck_storage_settings.h>
#include <libcockatrice/utility/string_limits.h>
@ -100,6 +104,9 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
connect(&SettingsCache::instance().visualDeckStorage(), &VisualDeckStorageSettings::visualDeckStorageInGameChanged,
this, &DeckViewContainer::setVisualDeckStorageExists);
connect(&SettingsCache::instance().userInterface(), &InterfaceSettings::playmatSettingsChanged, this,
&DeckViewContainer::onPlaymatSettingsChanged);
switchToDeckSelectView();
}
@ -277,6 +284,8 @@ void DeckViewContainer::loadDeckFromFile(const QString &filePath)
void DeckViewContainer::loadDeckFromDeckList(const DeckList &deck)
{
currentDeck = deck;
QString deckString = deck.writeToString_Native();
if (deckString.length() > MAX_FILE_LENGTH) {
@ -289,6 +298,52 @@ void DeckViewContainer::loadDeckFromDeckList(const DeckList &deck)
PendingCommand *pend = parentGame->getGame()->getGameEventHandler()->prepareGameCommand(cmd);
connect(pend, &PendingCommand::finished, this, &DeckViewContainer::deckSelectFinished);
parentGame->getGame()->getGameEventHandler()->sendGameCommand(pend, playerId);
resolveAndSendPlaymat();
}
void DeckViewContainer::resolveAndSendPlaymat()
{
if (currentDeck.getCardRefList().isEmpty() && currentDeck.getPlaymat().card.isEmpty()) {
return;
}
const auto &settings = SettingsCache::instance().userInterface();
const auto fallbackBehavior = static_cast<PlaymatFallbackMode>(settings.getPlaymatFallbackBehavior());
QList<PlaymatInfo> fallbackList = settings.getPlaymatFallbackList();
// In random mode with 2+ entries, remove the last-resolved mat to avoid repeats.
if (fallbackBehavior == PlaymatFallbackModeRandom && fallbackList.size() > 1) {
fallbackList.removeAll(lastResolvedPlaymat);
}
const PlaymatInfo resolved =
resolvePlaymatForDeck(currentDeck, fallbackList, static_cast<PlaymatMode>(settings.getPlaymatMode()),
fallbackBehavior, playmatRotationIndex);
lastResolvedPlaymat = resolved;
Command_SetPlaymat playmatCmd;
auto *pp = playmatCmd.mutable_playmat_params();
pp->set_card_name(resolved.card.name.toStdString());
pp->set_card_provider_id(resolved.card.providerId.toStdString());
pp->set_margin_pct_l(resolved.params.marginPctL);
pp->set_margin_pct_r(resolved.params.marginPctR);
pp->set_vertical_offset(resolved.params.verticalOffset);
pp->set_zoom(resolved.params.zoom);
PendingCommand *playmatPend = parentGame->getGame()->getGameEventHandler()->prepareGameCommand(playmatCmd);
parentGame->getGame()->getGameEventHandler()->sendGameCommand(playmatPend, playerId);
}
void DeckViewContainer::onPlaymatSettingsChanged()
{
resolveAndSendPlaymat();
}
void DeckViewContainer::advancePlaymatRotation()
{
playmatRotationIndex++;
}
void DeckViewContainer::loadRemoteDeck()
@ -379,6 +434,10 @@ void DeckViewContainer::sideboardPlanChanged()
*/
void DeckViewContainer::sendReadyStartCommand(bool ready)
{
if (ready) {
resolveAndSendPlaymat();
}
Command_ReadyStart cmd;
cmd.set_ready(ready);
parentGame->getGame()->getGameEventHandler()->sendGameCommand(cmd, playerId);
@ -416,6 +475,7 @@ void DeckViewContainer::setSideboardLocked(bool locked)
void DeckViewContainer::setDeck(const DeckList &deck)
{
currentDeck = deck;
deckView->setDeck(deck);
switchToDeckLoadedView();
}

View file

@ -57,6 +57,9 @@ private:
VisualDeckStorageWidget *visualDeckStorageWidget;
TabGame *parentGame;
int playerId;
int playmatRotationIndex = 0; ///< Per-match cursor for round-robin playmat mode.
DeckList currentDeck; ///< Cached deck for live settings re-resolution.
PlaymatInfo lastResolvedPlaymat; ///< Tracks last sent playmat to avoid repeats in random mode.
void tryCreateVisualDeckStorageWidget();
void sendReadyStartCommand(bool ready);
@ -75,6 +78,7 @@ private slots:
void sideboardLockButtonClicked();
void updateSideboardLockButtonText();
void refreshShortcuts();
void onPlaymatSettingsChanged();
signals:
void newCardAdded(AbstractCardItem *card);
void notIdle();
@ -87,6 +91,8 @@ public:
void setSideboardLocked(bool locked);
void setDeck(const DeckList &deck);
void setVisualDeckStorageExists(bool exists);
void advancePlaymatRotation();
void resolveAndSendPlaymat();
public slots:
void loadDeckFromFile(const QString &filePath);

View file

@ -17,7 +17,6 @@
#include <QDebug>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QSet>
#include <QtMath>
#include <libcockatrice/settings/interface_settings.h>
#include <libcockatrice/utility/zone_names.h>
@ -45,7 +44,14 @@ GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent)
GameScene::~GameScene()
{
// Sever all incoming connections (animated item destroy-tracking) before the
// members below are destroyed: the base QGraphicsScene destructor destroys the
// remaining items, and their destroyed() signals must not reach slots that
// reference members that no longer exist.
QObject::disconnect(nullptr, nullptr, this, nullptr);
delete animationTimer;
animationTimer = nullptr;
// Delete all ArrowItems before QGraphicsScene's base destructor runs.
// QGraphicsScene::~QGraphicsScene() destroys items in arbitrary order.
@ -246,17 +252,27 @@ void GameScene::adjustPlayerRotation(int rotationAdjustment)
*/
void GameScene::rearrange()
{
int firstPlayerIndex = 0;
auto playersPlaying = collectActivePlayers(firstPlayerIndex);
playersPlaying = rotatePlayers(playersPlaying, firstPlayerIndex);
if (rearranging) {
needsReArrange = true;
return;
}
rearranging = true;
do {
needsReArrange = false;
int columns = determineColumnCount(playersPlaying.size());
QSizeF sceneSize = computeSceneSizeAndPlayerLayout(playersPlaying, columns);
int firstPlayerIndex = 0;
auto playersPlaying = collectActivePlayers(firstPlayerIndex);
playersPlaying = rotatePlayers(playersPlaying, firstPlayerIndex);
phasesToolbar->setHeight(sceneSize.height());
setSceneRect(0, 0, sceneSize.width(), sceneSize.height());
int columns = determineColumnCount(playersPlaying.size());
QSizeF sceneSize = computeSceneSizeAndPlayerLayout(playersPlaying, columns);
processViewSizeChange(viewSize);
phasesToolbar->setHeight(sceneSize.height());
setSceneRect(0, 0, sceneSize.width(), sceneSize.height());
processViewSizeChange(viewSize);
} while (needsReArrange);
rearranging = false;
}
// ---------- View Size ----------
@ -453,8 +469,14 @@ void GameScene::resizeColumnsAndPlayers(const QList<qreal> &minWidthByColumn, qr
qreal extraWidthPerColumn = (newWidth - minWidth) / playersByColumn.size();
qreal newx = phasesToolbar->getWidth();
for (int col = 0; col < playersByColumn.size(); ++col) {
for (PlayerGraphicsItem *player : playersByColumn[col]) {
// Snapshot the columns: resizing a player's table can synchronously trigger
// GameScene::rearrange (table width -> sizeChanged -> updateBoundingRect ->
// sizeChanged -> rearrange), and rearrange rebuilds playersByColumn. Iterating
// the live container across that re-entrant call would use invalidated iterators.
const QList<QList<PlayerGraphicsItem *>> columns = playersByColumn;
for (int col = 0; col < columns.size(); ++col) {
for (PlayerGraphicsItem *player : columns[col]) {
player->processSceneSizeChange(minWidthByColumn[col] + extraWidthPerColumn);
player->setPos(newx, player->y());
}
@ -496,6 +518,7 @@ void GameScene::addArrow(QSharedPointer<ArrowData> data)
auto *arrow = new ArrowItem(data, startCard, targetItem);
addItem(arrow);
arrow->startDrawAnimation();
arrowRegistry.insert(data, arrow);
connect(arrow, &ArrowItem::requestDeletion, this, &GameScene::requestArrowDeletion);
}
@ -736,30 +759,45 @@ bool GameScene::event(QEvent *event)
void GameScene::timerEvent(QTimerEvent * /*event*/)
{
QMutableSetIterator<CardItem *> i(cardsToAnimate);
QMutableHashIterator<QObject *, IAnimatedItem *> i(animatedItems);
while (i.hasNext()) {
i.next();
if (!i.value()->animationEvent()) {
i.remove();
}
}
if (cardsToAnimate.isEmpty()) {
if (animatedItems.isEmpty()) {
animationTimer->stop();
}
}
void GameScene::registerAnimationItem(AbstractCardItem *card)
void GameScene::registerAnimationItem(IAnimatedItem *item)
{
cardsToAnimate.insert(static_cast<CardItem *>(card));
if (!animationTimer->isActive()) {
auto *object = dynamic_cast<QObject *>(item);
if (!object) {
return;
}
if (!animatedItems.contains(object)) {
connect(object, &QObject::destroyed, this, &GameScene::removeAnimatedItem);
}
animatedItems.insert(object, item);
if (animationTimer && !animationTimer->isActive()) {
animationTimer->start(10, this);
}
}
void GameScene::unregisterAnimationItem(AbstractCardItem *card)
void GameScene::unregisterAnimationItem(IAnimatedItem *item)
{
cardsToAnimate.remove(static_cast<CardItem *>(card));
if (cardsToAnimate.isEmpty()) {
animatedItems.remove(dynamic_cast<QObject *>(item));
if (animationTimer && animatedItems.isEmpty()) {
animationTimer->stop();
}
}
void GameScene::removeAnimatedItem(QObject *item)
{
animatedItems.remove(item);
if (animationTimer && animatedItems.isEmpty()) {
animationTimer->stop();
}
}

View file

@ -4,13 +4,14 @@
#include "../game/arrow_registry.h"
#include "../game/board/arrow_data.h"
#include "../game/zones/card_zone_logic.h"
#include "animated_item.h"
#include "board/arrow_item.h"
#include <QGraphicsScene>
#include <QHash>
#include <QList>
#include <QLoggingCategory>
#include <QPointer>
#include <QSet>
inline Q_LOGGING_CATEGORY(GameSceneLog, "game_scene");
inline Q_LOGGING_CATEGORY(GameScenePlayerAdditionRemovalLog, "game_scene.player_addition_removal");
@ -24,6 +25,7 @@ class CardItem;
class ServerInfo_Card;
class PhasesToolbar;
class QBasicTimer;
class QObject;
/**
* @class GameScene
@ -50,9 +52,11 @@ private:
QList<ZoneViewWidget *> zoneViews; ///< Active zone view widgets
QSize viewSize; ///< Current view size
QPointer<CardItem> hoveredCard; ///< Currently hovered card
QBasicTimer *animationTimer; ///< Timer for card animations
QSet<CardItem *> cardsToAnimate; ///< Cards currently animating
QBasicTimer *animationTimer; ///< Timer for scene animations
QHash<QObject *, IAnimatedItem *> animatedItems; ///< Items currently animating
int playerRotation; ///< Rotation offset for player layout
bool rearranging = false; ///< Guard against re-entrant rearrange
bool needsReArrange = false; ///< Pending rearrange requested during a pass
/**
* @brief Updates which card is currently hovered based on scene coordinates.
@ -182,15 +186,24 @@ public:
/** @brief Updates hovered card highlighting. */
void updateHoveredCard(CardItem *newCard);
/** @brief Registers a card for animation updates. */
void registerAnimationItem(AbstractCardItem *card);
/**
* @brief Registers an item for animation updates with the shared scene timer.
*
* The item must inherit QObject; it is unregistered automatically when it is
* destroyed, so it may be deleted mid-animation without a dangling pointer.
*/
void registerAnimationItem(IAnimatedItem *item);
/** @brief Unregisters a card from animation updates. */
void unregisterAnimationItem(AbstractCardItem *card);
/** @brief Unregisters an item from animation updates. */
void unregisterAnimationItem(IAnimatedItem *item);
void startRubberBand(const QPointF &selectionOrigin);
void resizeRubberBand(const QPointF &cursorPoint, int selectedCount);
void stopRubberBand();
private slots:
/** @brief Removes a destroyed item from the animation set. */
void removeAnimatedItem(QObject *item);
public slots:
void onCardSelectionChanged(AbstractCardItem *card, bool selected);
void onCardRightClicked(AbstractCardItem *card, QPoint screenPos);

View file

@ -114,6 +114,7 @@ void GameView::startRubberBand(const QPointF &_selectionOrigin)
}
selectionOrigin = _selectionOrigin;
previousBandRect = QRect();
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), QSize(0, 0)));
rubberBand->show();
}
@ -128,7 +129,17 @@ void GameView::resizeRubberBand(const QPointF &cursorPoint, int selectedCount)
QPoint cursor = cursorPoint.toPoint();
QRect rect = QRect(mapFromScene(selectionOrigin), cursor).normalized();
rubberBand->setGeometry(rect);
if (viewport()) {
// Repaint the union of the previous and current band rects: the vacated
// strip of a child widget is not reliably invalidated on all platforms
// (notably macOS), leaving stale pixels under the selection.
QRect dirty = previousBandRect.isNull() ? rect : previousBandRect.united(rect);
dirty.adjust(-1, -1, 1, 1);
viewport()->update(dirty);
previousBandRect = rect;
}
if (!SettingsCache::instance().userInterface().getShowDragSelectionCount()) {
dragCountLabel->hide();
@ -171,7 +182,13 @@ void GameView::stopRubberBand()
return;
}
// Same rationale as resizeRubberBand: repaint the last known band area
// since hiding a child widget doesn't reliably invalidate its region.
rubberBand->hide();
if (viewport() && !previousBandRect.isNull()) {
viewport()->update(previousBandRect.adjusted(-1, -1, 1, 1));
previousBandRect = QRect();
}
dragCountLabel->hide();
}

View file

@ -27,6 +27,7 @@ private:
QWidget *tallyContainer;
QGridLayout *tallyLayout;
QPointF selectionOrigin;
QRect previousBandRect; ///< Last rubber-band rect for targeted repaint
QList<TallyRow> cachedTallyRows; ///< Cached entries to avoid redundant rebuilds
QSize rebuildTallyLabels(const QList<TallyRow> &entries);

View file

@ -1,6 +1,9 @@
#include "player_graphics_item.h"
#include "../../game/player/player_actions.h"
#include "../../interface/card_picture_loader/card_picture_loader.h"
#include "../../interface/widgets/cards/art_crop_attribution.h"
#include "../../interface/widgets/playmat/playmat_utils.h"
#include "../../interface/widgets/tabs/tab_game.h"
#include "../board/abstract_card_item.h"
#include "../board/counter_general.h"
@ -13,6 +16,9 @@
#include "player_dialogs.h"
#include <QGraphicsView>
#include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/deck_list/deck_list.h>
#include <libcockatrice/deck_list/playmat_resolver.h>
#include <libcockatrice/settings/interface_settings.h>
PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player)
@ -28,6 +34,10 @@ PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player)
connect(player, &PlayerLogic::counterAdded, this, &PlayerGraphicsItem::onCounterAdded);
connect(player, &PlayerLogic::counterRemoved, this, &PlayerGraphicsItem::onCounterRemoved);
connect(player, &PlayerLogic::deckChanged, this, &PlayerGraphicsItem::updatePlaymat);
connect(player, &PlayerLogic::playmatChanged, this, &PlayerGraphicsItem::updatePlaymat);
connect(&SettingsCache::instance().userInterface(), &InterfaceSettings::playmatVisibilityChanged, this,
[this](int) { updatePlaymat(); });
playerMenu = new PlayerMenu(this);
@ -67,6 +77,9 @@ PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player)
connect(tableZoneGraphicsItem, &TableZone::sizeChanged, this, &PlayerGraphicsItem::updateBoundingRect);
connect(this, &PlayerGraphicsItem::playmatChanged, tableZoneGraphicsItem, &TableZone::onPlaymatChanged);
connect(this, &PlayerGraphicsItem::playmatChanged, stackZoneGraphicsItem, &StackZone::onPlaymatChanged);
updateBoundingRect();
rearrangeZones();
@ -112,7 +125,6 @@ void PlayerGraphicsItem::initializeZones()
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 =
@ -155,10 +167,61 @@ qreal PlayerGraphicsItem::getMinimumWidth() const
return result;
}
void PlayerGraphicsItem::paint(QPainter * /*painter*/,
const QStyleOptionGraphicsItem * /*option*/,
QWidget * /*widget*/)
void PlayerGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
if (!hasPlaymat || playmatPixmap.isNull()) {
return;
}
// Calculate the combined bounding rect of stack + table zones
QPointF stackPos = stackZoneGraphicsItem->pos();
QPointF tablePos = tableZoneGraphicsItem->pos();
QSizeF stackSize = stackZoneGraphicsItem->boundingRect().size();
QSizeF tableSize = tableZoneGraphicsItem->boundingRect().size();
// Combined area: from stack left edge to table right edge
double combinedLeft = qMin(stackPos.x(), tablePos.x());
double combinedTop = qMin(stackPos.y(), tablePos.y());
double combinedRight = qMax(stackPos.x() + stackSize.width(), tablePos.x() + tableSize.width());
double combinedBottom = qMax(stackPos.y() + stackSize.height(), tablePos.y() + tableSize.height());
QRectF combinedArea(combinedLeft, combinedTop, combinedRight - combinedLeft, combinedBottom - combinedTop);
const QRectF srcRect = PlaymatUtils::computeArtSourceRect(playmatPixmap.size(), playmatParams);
const QRectF dstRect = PlaymatUtils::coverFitRect(combinedArea, srcRect.size());
painter->save();
painter->setClipRect(combinedArea);
painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
// Render from a down-scaled copy of the art so the full-resolution source
// pixmap is never re-sampled at a tiny device size (also much cheaper than
// scaling it on every frame).
const QPixmap scaledPixmap = scaledPlaymatFor(srcRect, painter->worldTransform().mapRect(dstRect).size());
painter->drawPixmap(dstRect, scaledPixmap, QRectF(scaledPixmap.rect()));
painter->restore();
if (!playmatAttribution.isEmpty()) {
paintArtAttribution(*painter, combinedArea, playmatAttribution, Qt::AlignRight | Qt::AlignBottom, 0.8);
}
}
QPixmap PlayerGraphicsItem::scaledPlaymatFor(const QRectF &srcRect, const QSizeF &deviceDstSize)
{
// Bucket the render size so the source pixmap is re-scaled at most once per
// zoom step instead of once per frame.
constexpr int bucketSize = 32;
const QSize target = QSize(qMax(1, qRound(deviceDstSize.width() / bucketSize) * bucketSize),
qMax(1, qRound(deviceDstSize.height() / bucketSize) * bucketSize))
.boundedTo(srcRect.toAlignedRect().size());
if (scaledPlaymatKey != target) {
const QPixmap crop = playmatPixmap.copy(srcRect.toAlignedRect());
scaledPlaymatPixmap = crop.scaled(target, Qt::KeepAspectRatio, Qt::SmoothTransformation);
scaledPlaymatKey = target;
}
return scaledPlaymatPixmap;
}
void PlayerGraphicsItem::processSceneSizeChange(int newPlayerWidth)
@ -188,6 +251,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);
}
@ -298,3 +366,100 @@ void PlayerGraphicsItem::updateBoundingRect()
emit sizeChanged();
}
void PlayerGraphicsItem::updatePlaymat()
{
int visibility = SettingsCache::instance().userInterface().getPlaymatVisibility();
// "Don't use playmats" — never show
if (visibility == PlaymatVisibilityNone) {
clearPlaymat();
return;
}
// "Show own playmat only" — hide playmats for remote players
if (visibility == PlaymatVisibilityOwnOnly && !player->getPlayerInfo()->getLocal()) {
clearPlaymat();
return;
}
CardRef playmatCard;
PlaymatParams params;
if (player->getHasRemotePlaymat()) {
// Prefer the server-confirmed playmat (updated by Command_SetPlaymat).
playmatCard = player->getRemotePlaymatCard();
params = player->getRemotePlaymatParams();
} else if (player->getPlayerInfo()->getLocal()) {
// Local player without a server broadcast yet: apply the full
// settings-based resolution chain (mode, fallback list, behavior).
const auto &settings = SettingsCache::instance().userInterface();
const PlaymatInfo resolved = resolvePlaymatForDeck(
player->getDeck(), settings.getPlaymatFallbackList(), static_cast<PlaymatMode>(settings.getPlaymatMode()),
static_cast<PlaymatFallbackMode>(settings.getPlaymatFallbackBehavior()), 0);
playmatCard = resolved.card;
params = resolved.params;
} else {
// Opponent without a server broadcast: use the deck-embedded playmat.
const DeckList &deck = player->getDeck();
const PlaymatInfo &deckPlaymat = deck.getPlaymat();
if (!deckPlaymat.card.isEmpty()) {
playmatCard = deckPlaymat.card;
params = deckPlaymat.params;
}
}
if (playmatCard.isEmpty()) {
clearPlaymat();
return;
}
playmatParams = params;
scaledPlaymatKey = QSize(); // the art crop depends on the params, drop any cached scale
ExactCard card = CardDatabaseManager::query()->getCard(playmatCard);
if (!card) {
clearPlaymat();
return;
}
playmatAttribution = buildArtAttribution(card);
QPixmap fullRes;
CardPictureLoader::getPixmap(fullRes, card, QSize(745, 1040));
if (fullRes.isNull()) {
disconnect(playmatPixmapConnection);
CardInfo *cardInfo = card.getCardPtr().data();
if (cardInfo) {
playmatPixmapConnection =
connect(cardInfo, &CardInfo::pixmapUpdated, this, &PlayerGraphicsItem::onPlaymatPixmapReady);
}
return;
}
if (!hasPlaymat) {
hasPlaymat = true;
emit playmatChanged(true);
}
playmatPixmap = fullRes;
update();
}
void PlayerGraphicsItem::clearPlaymat()
{
disconnect(playmatPixmapConnection);
playmatAttribution.clear();
if (hasPlaymat) {
hasPlaymat = false;
playmatPixmap = QPixmap();
scaledPlaymatKey = QSize();
emit playmatChanged(false);
update();
}
}
void PlayerGraphicsItem::onPlaymatPixmapReady()
{
updatePlaymat();
}

View file

@ -11,6 +11,7 @@
#include "../game_scene.h"
#include <QGraphicsObject>
#include <libcockatrice/deck_list/deck_list.h>
class HandZone;
class PileZone;
@ -126,6 +127,7 @@ signals:
void playerCountChanged();
void mirroredChanged(bool isMirrored);
void cardInfoRequested(const CardRef &cardRef);
void playmatChanged(bool hasPlaymat);
private:
PlayerLogic *player;
@ -146,9 +148,23 @@ private:
bool mirrored;
bool handVisible = false;
QPixmap playmatPixmap;
QPixmap scaledPlaymatPixmap; // down-scaled copy of playmatPixmap for the current render size
QSize scaledPlaymatKey; // size bucket scaledPlaymatPixmap was rendered for
PlaymatParams playmatParams;
QString playmatAttribution;
bool hasPlaymat = false;
QMetaObject::Connection playmatPixmapConnection;
private slots:
void updateBoundingRect();
void rearrangeZones();
void clearPlaymat();
void updatePlaymat();
void onPlaymatPixmapReady();
private:
QPixmap scaledPlaymatFor(const QRectF &srcRect, const QSizeF &deviceDstSize);
};
#endif // COCKATRICE_PLAYER_GRAPHICS_ITEM_H

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

View file

@ -31,8 +31,22 @@ QRectF StackZone::boundingRect() const
void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
QBrush brush = themeManager->getExtraBgBrush(ThemeManager::Stack, getLogic()->getPlayer()->getZoneId());
painter->fillRect(boundingRect(), brush);
if (playmatActive) {
// Subtle overlay to distinguish stack zone from table zone (slightly darker)
painter->fillRect(boundingRect(), QColor(0, 0, 0, 80));
} else {
QBrush brush = themeManager->getExtraBgBrush(ThemeManager::Stack, getLogic()->getPlayer()->getZoneId());
painter->fillRect(boundingRect(), brush);
}
}
void StackZone::onPlaymatChanged(bool active)
{
playmatActive = active;
// See TableZone::onPlaymatChanged for the rationale. Translucent overlay
// over a dynamic playmat should not be held in the device cache.
setCacheMode(active ? QGraphicsItem::NoCache : QGraphicsItem::DeviceCoordinateCache);
update();
}
void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems,

View file

@ -15,9 +15,13 @@ class StackZone : public SelectZone
Q_OBJECT
private:
qreal zoneHeight;
bool playmatActive = false;
private slots:
void updateBg();
public slots:
void onPlaymatChanged(bool active);
public:
StackZone(StackZoneLogic *_logic, int _zoneHeight, QGraphicsItem *parent);
/** @brief Resizes the stack zone height, e.g. when sharing vertical space with the command zone. */

View file

@ -8,6 +8,7 @@
#include "../board/arrow_item.h"
#include "../board/card_drag_item.h"
#include "../board/card_item.h"
#include "../game_scene.h"
#include "../z_values.h"
#include <QGraphicsScene>
@ -47,6 +48,31 @@ void TableZone::updateBg()
update();
}
void TableZone::triggerDamageShimmer()
{
if (!SettingsCache::instance().userInterface().getBattlefieldFlashEnabled()) {
damageShimmerAlpha = 0.0;
return;
}
damageShimmerAlpha = 1.0;
shimmerClock.start();
if (scene()) {
static_cast<GameScene *>(scene())->registerAnimationItem(this);
}
}
bool TableZone::animationEvent()
{
damageShimmerAlpha = 1.0 - shimmerClock.elapsed() / shimmerDurationMs;
if (damageShimmerAlpha <= 0.0) {
damageShimmerAlpha = 0.0;
return false;
}
update();
return true;
}
QRectF TableZone::boundingRect() const
{
return QRectF(0, 0, width, height);
@ -66,20 +92,43 @@ bool TableZone::isInverted() const
void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
QBrush brush = themeManager->getExtraBgBrush(ThemeManager::Table, getLogic()->getPlayer()->getZoneId());
painter->fillRect(boundingRect(), brush);
if (playmatActive) {
// Subtle overlay to distinguish table zone from stack zone
painter->fillRect(boundingRect(), QColor(0, 0, 0, 60));
} else {
QBrush brush = themeManager->getExtraBgBrush(ThemeManager::Table, getLogic()->getPlayer()->getZoneId());
painter->fillRect(boundingRect(), brush);
}
if (active) {
paintZoneOutline(painter);
} else {
// inactive player gets a darker table zone with a semi transparent black mask
// this means if the user provides a custom background it will fade
// this means if the user provides a custom background or playmat it will fade
painter->fillRect(boundingRect(), FADE_MASK);
}
// Decaying crimson wash from taking damage.
if (damageShimmerAlpha > 0.0) {
QColor shimmerColor(239, 68, 68);
shimmerColor.setAlphaF(0.22 * damageShimmerAlpha);
painter->fillRect(boundingRect(), shimmerColor);
}
paintLandDivider(painter);
}
void TableZone::onPlaymatChanged(bool active)
{
playmatActive = active;
// While a playmat is shown the zone paints a translucent overlay over the
// dynamic playmat behind it. Keep it out of the device cache so the cached
// pixels are never stale relative to the playmat (and to avoid compositing
// artifacts of cached translucent content on some platforms).
setCacheMode(active ? QGraphicsItem::NoCache : QGraphicsItem::DeviceCoordinateCache);
update();
}
/**
Render a soft outline around the edge of the TableZone.

View file

@ -8,16 +8,19 @@
#define TABLEZONE_H
#include "../../game/zones/table_zone_logic.h"
#include "../animated_item.h"
#include "../board/abstract_card_item.h"
#include "select_zone.h"
#include <QElapsedTimer>
/**
* @brief TableZone is the grid based rect where CardItems may be placed.
*
* It is the main play zone and can be customized with background images.
*/
//! \todo Refactor methods to make more readable, extract logic to private methods (especially reorganizeCards()).
class TableZone : public SelectZone
class TableZone : public SelectZone, public IAnimatedItem
{
Q_OBJECT
@ -83,6 +86,7 @@ private:
*/
bool active = false;
bool mirrored = false;
bool playmatActive = false;
[[nodiscard]] bool isInverted() const;
@ -92,6 +96,9 @@ private slots:
*/
void updateBg();
public slots:
void onPlaymatChanged(bool active);
public slots:
/**
Reorganizes CardItems in the TableZone
@ -121,6 +128,16 @@ public:
*/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
/**
Flashes the table surface after a player loses life.
Wired up through the life counter so the battlefield glows when life drops.
*/
void triggerDamageShimmer();
/** @brief Decays the damage shimmer by one timer tick. */
bool animationEvent() override;
/**
Toggles the selected items as tapped.
*/
@ -171,8 +188,17 @@ public:
}
void setWidth(qreal _width)
{
// The width is stored as an int; truncate to match the previous implicit conversion.
const int newWidth = static_cast<int>(_width);
if (width == newWidth) {
return;
}
prepareGeometryChange();
width = _width;
width = newWidth;
// The parent player item's boundingRect (which clips the playmat painting) is
// derived from this zone's size. Without this signal the playmat is cut off at
// the stale boundingRect edge whenever the scene is resized wider.
emit sizeChanged();
}
[[nodiscard]] qreal getWidth() const
{
@ -185,6 +211,11 @@ public:
}
private:
static constexpr qreal shimmerDurationMs = 450.0;
QElapsedTimer shimmerClock;
qreal damageShimmerAlpha = 0.0;
void paintZoneOutline(QPainter *painter);
void paintLandDivider(QPainter *painter);

View file

@ -6,6 +6,7 @@ struct ContextJoinGame
{
ContextJoinRoom roomContext;
int gameId;
bool asSpectator = false;
};
#endif // COCKATRICE_CONTEXT_JOIN_GAME_H

View file

@ -55,7 +55,7 @@ bool IntentJoinServerGame::tryJoinGame(TabRoom *room)
return false;
}
if (room->getGameSelector()->joinGameById(context->gameId)) {
if (room->getGameSelector()->joinGameById(context->gameId, context->asSpectator)) {
emitFinished();
return true;
}

View file

@ -0,0 +1,183 @@
#include "intent_open_server_room_by_name.h"
#include "../widgets/tabs/tab_room.h"
#include "../widgets/tabs/tab_supervisor.h"
#include "intent_connect_to_server.h"
#include <libcockatrice/protocol/pb/event_list_rooms.pb.h>
#include <libcockatrice/protocol/pb/response_join_room.pb.h>
#include <libcockatrice/protocol/pb/session_commands.pb.h>
#include <libcockatrice/protocol/pending_command.h>
IntentOpenServerRoomByName::IntentOpenServerRoomByName(TabSupervisor *_tabSupervisor,
RemoteClient *_remoteClient,
std::unique_ptr<ContextJoinRoom> _context,
const QString &_roomName)
: Intent(), tabSupervisor(_tabSupervisor), remoteClient(_remoteClient), context(_context.release()),
roomName(_roomName)
{
checkTimer.setInterval(250);
connect(&checkTimer, &QTimer::timeout, this, [this]() {
if (selectOpenRoom()) {
checkTimer.stop();
}
});
}
bool IntentOpenServerRoomByName::checkPrecondition() const
{
if (remoteClient->getStatus() != ClientStatus::StatusLoggedIn) {
return false;
}
// peerPort() reflects the actual TCP peer, which may differ from the
// configured server port (e.g. when connecting through a proxy), so only
// the hostname is compared here.
if (remoteClient->peerName() != context->serverContext.hostname) {
return false;
}
if (QString::number(remoteClient->peerPort()) != context->serverContext.port) {
return false;
}
return true;
}
void IntentOpenServerRoomByName::onPreconditionSatisfied()
{
if (listening) {
return;
}
listening = true;
if (selectOpenRoom()) {
return;
}
// The room selector is the component that requests the room list, so the
// server tab must exist for the room to be resolved by name.
if (!tabSupervisor->getTabServer()) {
tabSupervisor->openTabServer();
}
if (!tabSupervisor->getTabServer()) {
emitFailed(tr("No server tab available"));
return;
}
connect(remoteClient, &RemoteClient::listRoomsEventReceived, this, &IntentOpenServerRoomByName::processListRooms);
connect(remoteClient, &RemoteClient::statusChanged, this, &IntentOpenServerRoomByName::onClientStatusChanged);
// The room tab may be opened by our own join, by the room selector's auto-join, or by a
// join that was already in flight. Poll until it shows up.
checkTimer.start();
// While no join has been sent yet, keep the room list fresh: the list may have been
// requested before we subscribed to it, or a response may have been dropped during a
// busy login burst. A stale list would otherwise leave the room unresolved forever.
connect(&refreshTimer, &QTimer::timeout, this, [this]() {
if (!joinPending) {
remoteClient->sendCommand(remoteClient->prepareSessionCommand(Command_ListRooms()));
}
});
refreshTimer.setInterval(5000);
refreshTimer.start();
// Last-resort failure for "the room genuinely is not in a fresh list". This must NOT
// fire while a join is in flight: a loaded server may take longer than that to answer
// during a login burst, and killing the intent early would leave the connection
// registered in the room with no tab to display it and every later join attempt
// would then be rejected with RespContextError.
QTimer::singleShot(20000, this, [this]() {
if (!joinPending) {
emitFailed(tr("Timed out while looking for the server room %1").arg(roomName));
}
});
}
void IntentOpenServerRoomByName::onPreconditionNotSatisfied()
{
runDependency(new IntentConnectToServer(remoteClient, &context->serverContext));
}
void IntentOpenServerRoomByName::onClientStatusChanged(ClientStatus status)
{
if (status != ClientStatus::StatusLoggedIn) {
emitFailed(tr("Disconnected while looking for the server room %1").arg(roomName));
}
}
bool IntentOpenServerRoomByName::selectOpenRoom()
{
const auto &roomTabs = tabSupervisor->getRoomTabs();
for (auto i = roomTabs.cbegin(), end = roomTabs.cend(); i != end; ++i) {
TabRoom *room = i.value();
if (room->getRoomName() == roomName) {
tabSupervisor->setCurrentWidget(room);
emitFinished();
return true;
}
}
return false;
}
void IntentOpenServerRoomByName::processListRooms(const Event_ListRooms &event)
{
if (selectOpenRoom()) {
return;
}
for (int i = 0; i < event.room_list_size(); ++i) {
const ServerInfo_Room &room = event.room_list(i);
if (room.has_name() && QString::fromStdString(room.name()) == roomName) {
openRoom(room);
return;
}
}
}
void IntentOpenServerRoomByName::openRoom(const ServerInfo_Room &roomInfo)
{
if (joinPending) {
return;
}
joinPending = true;
// Rooms flagged auto_join are joined by the room selector automatically. Sending our own
// Command_JoinRoom on top of that would be answered with RespContextError.
if (roomInfo.has_auto_join() && roomInfo.auto_join()) {
return;
}
Command_JoinRoom cmd;
cmd.set_room_id(roomInfo.room_id());
PendingCommand *pend = remoteClient->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this,
[this](const Response &r, const CommandContainer &, const QVariant &) { handleJoinResponse(r); });
remoteClient->sendCommand(pend);
}
void IntentOpenServerRoomByName::handleJoinResponse(const Response &response)
{
switch (response.response_code()) {
case Response::RespOk: {
const Response_JoinRoom &resp = response.GetExtension(Response_JoinRoom::ext);
if (!tabSupervisor->getRoomTabs().contains(resp.room_info().room_id())) {
tabSupervisor->addRoomTab(resp.room_info(), true);
}
emitFinished();
return;
}
case Response::RespNameNotFound:
emitFailed(tr("Failed to join the server room %1: it doesn't exist on the server.").arg(roomName));
return;
case Response::RespUserLevelTooLow:
emitFailed(tr("You do not have the required permission to join the server room %1.").arg(roomName));
return;
case Response::RespContextError:
// The room was already joined by someone else (e.g. the room selector's
// auto-join). It will show up in the room tabs shortly, so keep waiting.
return;
default:
emitFailed(tr("Failed to join the server room %1 due to an unknown error.").arg(roomName));
return;
}
}

View file

@ -0,0 +1,61 @@
#ifndef COCKATRICE_INTENT_OPEN_SERVER_ROOM_BY_NAME_H
#define COCKATRICE_INTENT_OPEN_SERVER_ROOM_BY_NAME_H
#include "contexts/context_join_room.h"
#include "intent.h"
#include "remote_client.h"
#include <QScopedPointer>
#include <QString>
#include <QTimer>
#include <memory>
class TabRoom;
class TabSupervisor;
class Event_ListRooms;
class ServerInfo_Room;
/**
* @brief Connects to the configured server and opens a room identified by its name.
*
* Room ids are assigned by the server per session, so the room is resolved by name from the
* room list once the client is logged in. If the room is already open it is simply selected.
*
* The join itself is sent directly through the client instead of `TabServer::joinRoom`, so a
* failed join only fails the intent silently instead of popping a modal error box during
* startup. Success is routed to `TabSupervisor::addRoomTab`, the same tab-creation machinery
* the normal join flow uses.
*/
class IntentOpenServerRoomByName : public Intent
{
Q_OBJECT
public:
IntentOpenServerRoomByName(TabSupervisor *_tabSupervisor,
RemoteClient *_remoteClient,
std::unique_ptr<ContextJoinRoom> _context,
const QString &_roomName);
protected:
bool checkPrecondition() const override;
void onPreconditionSatisfied() override;
void onPreconditionNotSatisfied() override;
private:
void processListRooms(const Event_ListRooms &event);
void openRoom(const ServerInfo_Room &roomInfo);
void handleJoinResponse(const Response &response);
void onClientStatusChanged(ClientStatus status);
bool selectOpenRoom();
TabSupervisor *tabSupervisor;
RemoteClient *remoteClient;
QScopedPointer<ContextJoinRoom> context;
QString roomName;
bool listening = false;
bool joinPending = false;
QTimer checkTimer;
QTimer refreshTimer;
};
#endif // COCKATRICE_INTENT_OPEN_SERVER_ROOM_BY_NAME_H

View file

@ -1,5 +1,7 @@
#include "url_parser.h"
#include "../widgets/tabs/tab_room.h"
#include "../widgets/tabs/tab_supervisor.h"
#include "../window_main.h"
#include "contexts/context_join_game.h"
#include "intent_join_server_game.h"
@ -9,6 +11,7 @@
#include <QMessageBox>
#include <QUrl>
#include <QUrlQuery>
#include <libcockatrice/network/client/abstract/abstract_client.h>
#include <memory>
IntentUrlParser::IntentUrlParser(QObject *parent, MainWindow *_mainWindow) : QObject(parent), mainWindow(_mainWindow)
@ -71,6 +74,15 @@ void IntentUrlParser::handleJoinGame(const QUrlQuery &query)
return;
}
const QString gameDescription = query.queryItemValue("game", QUrl::FullyDecoded);
const QString message = generateJoinGameMessage(*ctx, gameDescription);
const QMessageBox::StandardButton answer = QMessageBox::question(
mainWindow, tr("Join game"), message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (answer != QMessageBox::Yes) {
return;
}
// The join game intent owns the context and the credential lookup; once the
// chain finishes (or fails) it deletes the whole tree.
ContextConnectToServer *serverContext = &ctx->roomContext.serverContext;
@ -87,3 +99,38 @@ void IntentUrlParser::handleJoinGame(const QUrlQuery &query)
getLoginCredentialsIntent->execute();
}
QString IntentUrlParser::generateJoinGameMessage(const ContextJoinGame &context, const QString &gameDescription)
{
const QString hostname = context.roomContext.serverContext.hostname;
const QString port = context.roomContext.serverContext.port;
const int roomId = context.roomContext.roomId;
const int gameId = context.gameId;
const QString server = QStringLiteral("%1:%2").arg(hostname, port);
// Prefer the room name over the raw numeric id: it means something to the
// user. The name is only known when we are already connected to the same
// server and sitting in that room — otherwise fall back to a plain prompt.
AbstractClient *client = mainWindow->getTabSupervisor()->getClient();
const bool sameServer = client != nullptr && client->getStatus() == StatusLoggedIn &&
hostname.compare(client->serverName(), Qt::CaseInsensitive) == 0 &&
QString::number(client->serverPort()) == port;
TabRoom *roomTab = sameServer ? mainWindow->getTabSupervisor()->getRoomTabs().value(roomId) : nullptr;
const QString gameIdStr = QString::number(gameId);
// Links built by newer clients embed the game description ("game" item);
// restate it in the confirm so it matches what the chat anchor showed.
// Unknown query items are ignored, so old links without it keep working.
// The multi-arg .arg() overloads replace in a single pass, so a description
// containing "%…" cannot corrupt later placeholders.
// FullyDecoded undoes every %XX escape and must match the chat anchor's
// decode mode, so a description containing "%" reads identically in both.
if (gameDescription.isEmpty()) {
return roomTab ? tr("Join game #%1 in \"%2\" on %3?").arg(gameIdStr, roomTab->getRoomName(), server)
: tr("Join game #%1 on %2?").arg(gameIdStr, server);
}
return roomTab ? tr("Join game \"%1\" (#%2) in \"%3\" on %4?")
.arg(gameDescription, gameIdStr, roomTab->getRoomName(), server)
: tr("Join game \"%1\" (#%2) on %3?").arg(gameDescription, gameIdStr, server);
}

View file

@ -4,6 +4,7 @@
#include <QUrlQuery>
class MainWindow;
struct ContextJoinGame;
class IntentUrlParser : public QObject
{
Q_OBJECT
@ -14,6 +15,8 @@ public:
void handleJoinGame(const QUrlQuery &query);
private:
QString generateJoinGameMessage(const ContextJoinGame &context, const QString &gameDescription);
MainWindow *mainWindow;
};

View file

@ -290,28 +290,42 @@ void PaletteEditorDialog::onSave()
// Persist every scheme that changed, not just the one on screen. Each scheme
// has its own file, so edits to the non-active scheme would otherwise be
// silently discarded when the dialog closes.
//
// Save the loaded scheme last so commitPalette's global colour-scheme
// update (ThemeConfig::colorScheme) points at the active scheme.
for (auto it = workingConfig.begin(); it != workingConfig.end(); ++it) {
const QString &scheme = it.key();
if (it.value().colors == savedConfig.value(scheme).colors) {
continue; // unchanged — leave the on-disk file alone
if (it.key() == loadedScheme) {
continue;
}
if (!ThemeManager::savePaletteConfig(saveDir, scheme, it.value())) {
if (it.value().colors == savedConfig.value(it.key()).colors) {
continue;
}
if (!ThemeManager::commitPalette(saveDir, it.key(), it.value())) {
QMessageBox::warning(this, tr("Save failed"),
tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(scheme), saveDir));
tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(it.key()), saveDir));
return;
}
}
// Commit the active scheme last so the global colour scheme matches.
if (workingConfig[loadedScheme].colors != savedConfig.value(loadedScheme).colors) {
if (!ThemeManager::commitPalette(saveDir, loadedScheme, workingConfig[loadedScheme])) {
QMessageBox::warning(this, tr("Save failed"),
tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(loadedScheme), saveDir));
return;
}
} else {
// No palette change but scheme may have switched -- still update global config.
ThemeConfig globalCfg = ThemeConfig::fromThemeDir(saveDir);
globalCfg.colorScheme = loadedScheme;
globalCfg.save(saveDir);
}
// Keep the saved snapshot in sync so Reset behaves correctly afterwards.
for (auto it = workingConfig.begin(); it != workingConfig.end(); ++it) {
savedConfig[it.key()] = it.value();
}
ThemeConfig globalCfg = ThemeConfig::fromThemeDir(saveDir);
globalCfg.colorScheme = loadedScheme;
globalCfg.save(saveDir);
themeManager->reloadCurrentTheme();
accept();
}

View file

@ -3,6 +3,7 @@
#include <QApplication>
#include <QDomDocument>
#include <QFile>
#include <QImageReader>
#include <QPainter>
#include <QPalette>
#include <QSvgRenderer>
@ -14,6 +15,32 @@
#define DEFAULT_COLOR_MODERATOR_RIGHT "#000000";
#define DEFAULT_COLOR_ADMIN "#ff2701";
/**
* Clamps an svg render size so that rendering does not exceed a multiple of the requested size.
*
* Rendering at the full native size of an svg just to scale it down afterwards wastes memory,
* and canvases with extreme coordinates can exceed Qt's rasterizer coordinate limit which makes
* Qt silently drop shapes from the rendered image.
*
* @param renderSize The size the svg would be rendered at.
* @param requestedSize The size that was actually requested.
*
* @return A size with the aspect ratio of renderSize whose longest side is at most four times
* the longest side of requestedSize.
*/
static QSize capRenderSize(const QSize &renderSize, const QSize &requestedSize)
{
const int longestRequestedSide = qMax(requestedSize.width(), requestedSize.height());
if (longestRequestedSide <= 0) {
return renderSize;
}
const int longestRenderSide = qMax(renderSize.width(), renderSize.height());
const qreal scale = qMin<qreal>(1.0, static_cast<qreal>(longestRequestedSide * 4) / longestRenderSide);
return QSize(qMax(1, static_cast<int>(renderSize.width() * scale)),
qMax(1, static_cast<int>(renderSize.height() * scale)));
}
/**
* Loads in an svg from file and scales it without affecting image quality.
*
@ -35,6 +62,9 @@ static QPixmap loadSvg(const QString &svgPath, const QSize &size, bool expandOnl
// If expandOnly, make sure the pixmap is at least as large as the svg, so that we don't lose any detail.
// QIcon.pixmap(size) will automatically scale down the image, but it won't scale it up.
QSize pixmapSize = expandOnly ? svgRenderer.defaultSize().expandedTo(size) : size;
if (expandOnly) {
pixmapSize = capRenderSize(pixmapSize, size);
}
QPixmap pix(pixmapSize);
pix.fill(Qt::transparent);
@ -247,7 +277,9 @@ static QIcon loadAndColorSvg(const QString &iconPath,
QSvgRenderer svgRenderer(doc.toByteArray());
QPixmap pix(svgRenderer.defaultSize().expandedTo(QSize(minSize, minSize)));
const QSize pixmapSize =
capRenderSize(svgRenderer.defaultSize().expandedTo(QSize(minSize, minSize)), QSize(minSize, minSize));
QPixmap pix(pixmapSize);
pix.fill(Qt::transparent);
QPainter pixPainter(&pix);
@ -387,6 +419,57 @@ QPixmap DropdownIconPixmapGenerator::generatePixmap(int height, bool expanded)
QMap<QString, QPixmap> DropdownIconPixmapGenerator::pmCache;
namespace
{
/// Longest side mana symbols are rendered at before being scaled to their final size.
constexpr int MASTER_ICON_SIZE = 128;
QString manaSymbolCacheKey(const QString &symbol, const QSize &size)
{
return symbol + QLatin1Char('|') + QString::number(size.width()) + QLatin1Char('x') +
QString::number(size.height());
}
} // namespace
const QPixmap &ManaSymbolPixmapGenerator::masterIcon(const QString &symbol)
{
auto it = masterCache.constFind(symbol);
if (it != masterCache.constEnd()) {
return it.value();
}
QImageReader reader("theme:icons/mana/" + symbol);
QSize sourceSize = reader.size();
if (!sourceSize.isEmpty()) {
sourceSize.scale(QSize(MASTER_ICON_SIZE, MASTER_ICON_SIZE), Qt::KeepAspectRatio);
reader.setScaledSize(sourceSize);
}
const QPixmap rendered = QPixmap::fromImageReader(&reader);
return masterCache.insert(symbol, rendered).value();
}
QPixmap ManaSymbolPixmapGenerator::generatePixmap(const QString &symbol, const QSize &size)
{
const QString key = manaSymbolCacheKey(symbol, size);
auto it = scaledCache.constFind(key);
if (it != scaledCache.constEnd()) {
return it.value();
}
const QPixmap &icon = masterIcon(symbol);
if (icon.isNull()) {
return {};
}
QPixmap scaled = icon.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
scaledCache.insert(key, scaled);
return scaled;
}
QHash<QString, QPixmap> ManaSymbolPixmapGenerator::masterCache;
QHash<QString, QPixmap> ManaSymbolPixmapGenerator::scaledCache;
QPixmap loadColorAdjustedPixmap(const QString &name)
{
if (qApp->palette().windowText().color().lightness() > 200) {

View file

@ -7,6 +7,7 @@
#ifndef PIXMAPGENERATOR_H
#define PIXMAPGENERATOR_H
#include <QHash>
#include <QIcon>
#include <QLoggingCategory>
#include <QMap>
@ -125,6 +126,34 @@ public:
}
};
class ManaSymbolPixmapGenerator
{
private:
static QHash<QString, QPixmap> masterCache;
static QHash<QString, QPixmap> scaledCache;
/**
* @brief Renders \a symbol once at a fixed moderate size, so repeated scalings never
* re-rasterize the source file (SVG sources can be very expensive to rasterize).
*/
static const QPixmap &masterIcon(const QString &symbol);
public:
/**
* @brief Returns a smooth-scaled rendering of the given mana symbol icon.
*
* Results are shared between all callers via a process-wide cache keyed by symbol
* and size, so scaling work is done once per distinct combination instead of once
* per widget creation or resize.
*/
static QPixmap generatePixmap(const QString &symbol, const QSize &size);
static void clear()
{
masterCache.clear();
scaledCache.clear();
}
};
QPixmap loadColorAdjustedPixmap(const QString &name);
#endif

View file

@ -90,13 +90,17 @@ struct PaletteColorInfo
}
}
static QString usableDefaultStyle(const QString &style)
{
// The Windows 11 native style is broken: when the OS default
// ("Default" theme selection) would use it, fall back to the Vista style.
// Explicitly choosing "windows11" in a theme is still honored.
return style.compare("windows11", Qt::CaseInsensitive) == 0 ? QStringLiteral("windowsvista") : style;
}
ThemeManager::ThemeManager(QObject *parent) : QObject(parent)
{
defaultStyleName = qApp->style()->objectName();
//! \todo Workaround for windows11 style being broken.
if (defaultStyleName == "windows11") {
defaultStyleName = "windowsvista";
}
defaultStyleName = usableDefaultStyle(qApp->style()->objectName());
// Capture the untouched application palette before any theme is applied.
defaultPalette = qApp->palette();
ensureThemeDirectoryExists();
@ -119,7 +123,7 @@ void ThemeManager::ensureThemeDirectoryExists()
}
}
bool ThemeManager::isDarkMode(const QString &themeDirPath)
bool ThemeManager::isDarkMode(const QString &themeDirPath) const
{
ThemeConfig themeConfig = ThemeConfig::fromThemeDir(themeDirPath);
if (themeConfig.colorScheme.compare("Dark", Qt::CaseInsensitive) == 0) {
@ -268,6 +272,19 @@ PaletteConfig ThemeManager::loadDefaultPaletteConfig(const QString &themeDirPath
return cfg;
}
bool ThemeManager::commitPalette(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg)
{
if (!savePaletteConfig(themeDirPath, colorScheme, cfg)) {
return false;
}
ThemeConfig globalCfg = ThemeConfig::fromThemeDir(themeDirPath);
globalCfg.colorScheme = colorScheme;
globalCfg.save(themeDirPath);
return true;
}
void ThemeManager::setColorScheme(const QString &scheme)
{
const QString dirPath = getAvailableThemes().value(SettingsCache::instance().getThemeName());
@ -316,13 +333,13 @@ void ThemeManager::applyStyleAndPalette(const QString &themeName,
if (themeName == FUSION_THEME_NAME) {
styleName = "Fusion";
} else {
styleName = defaultStyleName;
styleName = usableDefaultStyle(defaultStyleName);
}
}
QStyle *style = QStyleFactory::create(styleName);
if (!style) {
style = QStyleFactory::create(defaultStyleName);
style = QStyleFactory::create(usableDefaultStyle(defaultStyleName));
}
// Base palette

View file

@ -66,7 +66,14 @@ protected:
public:
bool isBuiltInTheme();
bool isDarkMode(const QString &themeDirPath);
// Explicit color scheme of the theme: theme.cfg's ColorScheme setting
// (Dark/Light), falling back to the OS color scheme when it is "System".
bool isDarkMode(const QString &themeDirPath) const;
// The resolved scheme of the currently active theme.
bool isDarkModeActive() const
{
return isDarkMode(currentThemePath);
}
QStringMap &getAvailableThemes();
// Returns the path to the currently active theme directory (empty = default)
QString getCurrentThemePath() const
@ -84,6 +91,10 @@ public:
// theme directory when it is absent from the resolved (user) directory.
static PaletteConfig
loadDefaultPaletteConfig(const QString &themeDirPath, const QString &themeName, const QString &colorScheme);
/** @brief Writes cfg to disk as the theme's palette-<scheme>.toml and updates the
* theme's stored colour scheme to match. Shared by PaletteEditorDialog::onSave
* and FirstRunWizard's theme step so the two "generate + keep" paths can't drift. */
static bool commitPalette(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg);
void setColorScheme(const QString &scheme);
void setStyleName(const QString &styleName);

View file

@ -41,6 +41,11 @@ void ColorIdentityWidget::populateManaSymbolWidgets()
// clear old layout
QtUtils::clearLayoutRec(layout);
// The freshly created symbols haven't been sized yet, so force the next resize pass
// to apply the symbol size again.
lastIconSize = -1;
lastWidth = -1;
// populate mana symbols
if (SettingsCache::instance().visualDeckStorage().getVisualDeckStorageDrawUnusedColorIdentities()) {
for (const QString symbol : fullColorIdentity) {
@ -73,20 +78,33 @@ void ColorIdentityWidget::toggleUnusedVisibility()
void ColorIdentityWidget::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
QList<ManaSymbolWidget *> manaSymbols = findChildren<ManaSymbolWidget *>();
if (!manaSymbols.isEmpty()) {
int totalWidth = event->size().width();
int totalHeight = totalWidth / 6; // Set height to 1/4 of the width
setFixedHeight(totalHeight);
const int totalWidth = event->size().width();
if (totalWidth == lastWidth && lastIconSize != -1) {
return;
}
lastWidth = totalWidth;
int spacing = layout->spacing();
int count = manaSymbols.size();
int availableWidth = totalWidth - (spacing * (count - 1));
int iconSize = qMin(availableWidth / count, totalHeight); // Ensure icons fit within the new height
const int totalHeight = totalWidth / 6; // Set height to 1/4 of the width
setFixedHeight(totalHeight);
for (ManaSymbolWidget *manaSymbol : manaSymbols) {
manaSymbol->setFixedSize(iconSize, iconSize);
const int count = layout->count();
if (count == 0) {
return;
}
const int spacing = layout->spacing();
const int availableWidth = totalWidth - (spacing * (count - 1));
const int iconSize = qMin(availableWidth / count, totalHeight); // Ensure icons fit within the new height
if (iconSize == lastIconSize) {
return;
}
lastIconSize = iconSize;
for (int i = 0; i < count; ++i) {
if (auto *w = qobject_cast<ManaSymbolWidget *>(layout->itemAt(i)->widget())) {
w->setFixedSize(iconSize, iconSize);
}
}
}

View file

@ -30,6 +30,8 @@ public slots:
private:
QString colorIdentity;
QHBoxLayout *layout;
int lastIconSize = -1; ///< The symbol size last applied, to skip redundant resize passes.
int lastWidth = -1; ///< The width last processed, to skip redundant resize passes.
};
#endif // COLOR_IDENTITY_WIDGET_H

View file

@ -17,7 +17,7 @@ class ManaCostWidget : public QWidget
public:
explicit ManaCostWidget(QWidget *parent, CardInfoPtr card);
QStringList parseManaCost(const QString &manaString);
static QStringList parseManaCost(const QString &manaString);
public slots:
void resizeEvent(QResizeEvent *event) override;

View file

@ -1,15 +1,15 @@
#include "mana_symbol_widget.h"
#include "../../../../client/settings/cache_settings.h"
#include "../../../pixel_map_generator.h"
#include <QResizeEvent>
#include <libcockatrice/settings/visual_deck_storage_settings.h>
ManaSymbolWidget::ManaSymbolWidget(QWidget *parent, QString _symbol, bool _isActive, bool _mayBeToggled)
: QLabel(parent), symbol(_symbol), isActive(_isActive), mayBeToggled(_mayBeToggled)
: QLabel(parent), symbol(std::move(_symbol)), isActive(_isActive), mayBeToggled(_mayBeToggled)
{
loadManaIcon();
setPixmap(manaIcon.scaled(50, 50, Qt::KeepAspectRatio, Qt::SmoothTransformation));
setPixmap(ManaSymbolPixmapGenerator::generatePixmap(symbol, QSize(50, 50)));
setMaximumWidth(50);
// Initialize opacity effect
@ -64,16 +64,13 @@ void ManaSymbolWidget::mousePressEvent(QMouseEvent *event)
void ManaSymbolWidget::resizeEvent(QResizeEvent *event)
{
QLabel::resizeEvent(event);
setPixmap(manaIcon.scaled(event->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
const QSize newSize = event->size();
void ManaSymbolWidget::loadManaIcon()
{
QString filename = "theme:icons/mana/";
if (symbol == "W" || symbol == "U" || symbol == "B" || symbol == "R" || symbol == "G") {
filename += symbol;
// Skip the rescale when the size didn't actually change: layout passes resize these
// widgets repeatedly with identical sizes.
if (newSize.isEmpty() || pixmap().size() == newSize) {
return;
}
manaIcon = QPixmap(filename);
setPixmap(ManaSymbolPixmapGenerator::generatePixmap(symbol, newSize));
}

View file

@ -33,8 +33,6 @@ public:
return symbol[0];
}
void loadManaIcon();
public slots:
void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
@ -44,7 +42,6 @@ signals:
private:
QString symbol;
QPixmap manaIcon;
bool isActive;
bool mayBeToggled;
QGraphicsOpacityEffect *opacityEffect;

View file

@ -0,0 +1,61 @@
#include "art_crop_attribution.h"
#include <QFontMetrics>
#include <QObject>
#include <QPainter>
#include <libcockatrice/card/printing/exact_card.h>
QString buildArtAttribution(const ExactCard &card)
{
const QString artist = card.getPrinting().getArtist();
if (artist.isEmpty()) {
return QString();
}
return QObject::tr("Art: %1").arg(artist);
}
QRectF paintArtAttribution(QPainter &painter,
const QRectF &rect,
const QString &attribution,
Qt::Alignment anchor,
qreal scale)
{
if (attribution.isEmpty()) {
return QRectF();
}
painter.save();
QFont font = painter.font();
font.setPointSizeF(qMax(6.0, font.pointSizeF() * scale));
painter.setFont(font);
const QFontMetrics fm(font);
const qreal maxTextWidth = rect.width() * 0.45;
const QString elided = fm.elidedText(attribution, Qt::ElideRight, qMax(qreal(80.0) * scale, maxTextWidth));
const qreal pad = 6.0 * scale;
QRectF captionRect(QPointF(0, 0), QSizeF(fm.horizontalAdvance(elided) + pad * 2.0, fm.height() + pad * 2.0));
const qreal margin = 4.0 * scale;
if (anchor.testFlag(Qt::AlignLeft)) {
captionRect.moveLeft(rect.left() + margin);
} else {
captionRect.moveRight(rect.right() - margin);
}
if (anchor.testFlag(Qt::AlignTop)) {
captionRect.moveTop(rect.top() + margin);
} else {
captionRect.moveBottom(rect.bottom() - margin);
}
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(0, 0, 0, 120));
painter.drawRoundedRect(captionRect, 4, 4);
painter.setPen(QColor(255, 255, 255, 220));
painter.drawText(captionRect, Qt::AlignCenter, elided);
painter.restore();
return captionRect;
}

View file

@ -0,0 +1,41 @@
#ifndef COCKATRICE_ART_CROP_ATTRIBUTION_H
#define COCKATRICE_ART_CROP_ATTRIBUTION_H
#include <QStringView>
class ExactCard;
class QPainter;
class QRectF;
class QString;
/**
* @brief Builds an attribution caption for a cropped card art display.
*
* When a card image's art region is shown cropped (an "art crop"), the artist
* should be credited in the same interface. Returns an empty string when the
* database has no artist data for the card.
*
* @param card The card whose art is being displayed.
* @return Caption such as "Art: John Avon", or empty.
*/
QString buildArtAttribution(const ExactCard &card);
/**
* @brief Paints an attribution caption in a corner of a rect.
*
* Draws a subtle semi-transparent pill containing the caption, elided to fit.
*
* @param painter Painter to draw with.
* @param rect The area (e.g. the cropped art region) the caption belongs to.
* @param attribution Caption text (see buildArtAttribution()).
* @param anchor Corner of @p rect to pin the pill to (default bottom-right).
* @param scale Size multiplier for the pill (e.g. 0.8 for a smaller pill).
* @return The rect the pill was drawn in, or an empty rect if @p attribution is empty.
*/
QRectF paintArtAttribution(QPainter &painter,
const QRectF &rect,
const QString &attribution,
Qt::Alignment anchor = Qt::AlignRight | Qt::AlignBottom,
qreal scale = 1.0);
#endif // COCKATRICE_ART_CROP_ATTRIBUTION_H

View file

@ -52,12 +52,29 @@ void CardInfoPictureEnlargedWidget::loadPixmap(const QSize &size)
* @param size The desired size for the pixmap.
*
* Sets the widget's pixmap to the card image and resizes the widget to match the specified size. Triggers a repaint.
*
* When the image is not yet cached, the pixmap is cleared (instead of showing a stale previous card) and the widget
* refreshes automatically once the card image finishes loading.
*/
void CardInfoPictureEnlargedWidget::setCardPixmap(const ExactCard &_card, const QSize size)
{
if (card.getCardPtr()) {
disconnect(card.getCardPtr().data(), nullptr, this, nullptr);
}
card = _card;
// Clear any previous card's art so we never paint a stale pixmap while the new image loads
enlargedPixmap = QPixmap();
loadPixmap(size);
if (card.getCardPtr()) {
connect(card.getCardPtr().data(), &CardInfo::pixmapUpdated, this, [this]() {
loadPixmap(this->size());
update();
});
}
setFixedSize(size); // Set the widget size to the enlarged size
update(); // Trigger a repaint

View file

@ -2,6 +2,7 @@
#include "../../../client/settings/cache_settings.h"
#include "../../../client/settings/shortcuts_settings.h"
#include "../playmat/playmat_settings_dialog.h"
#include "../settings_page/user_interface_settings_page.h"
#include "../tabs/api/commander_spellbook/commander_bracket_widget.h"
#include "deck_list_style_proxy.h"
@ -11,10 +12,12 @@
#include <QDockWidget>
#include <QHeaderView>
#include <QLabel>
#include <QPushButton>
#include <QSplitter>
#include <QTextEdit>
#include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/settings/deck_editor_settings.h>
#include <libcockatrice/settings/interface_settings.h>
#include <libcockatrice/utility/macros.h>
#include <libcockatrice/utility/string_limits.h>
@ -228,10 +231,18 @@ void DeckEditorDeckDockWidget::createDeckDock()
upperLayout->addWidget(bannerCardLabel, 4, 0);
upperLayout->addWidget(bannerCardComboBox, 4, 1);
upperLayout->addWidget(deckTagsDisplayWidget, 5, 1);
playmatLabel = new QLabel();
playmatLabel->setObjectName("playmatLabel");
playmatLabel->setText(tr("Playmat"));
playmatSettingsButton = new QPushButton(tr("Edit Playmat..."));
connect(playmatSettingsButton, &QPushButton::clicked, this, &DeckEditorDeckDockWidget::openPlaymatSettings);
upperLayout->addWidget(playmatLabel, 5, 0);
upperLayout->addWidget(playmatSettingsButton, 5, 1);
upperLayout->addWidget(activeGroupCriteriaLabel, 6, 0);
upperLayout->addWidget(activeGroupCriteriaComboBox, 6, 1);
upperLayout->addWidget(deckTagsDisplayWidget, 6, 1);
upperLayout->addWidget(activeGroupCriteriaLabel, 7, 0);
upperLayout->addWidget(activeGroupCriteriaComboBox, 7, 1);
hashLabel1 = new QLabel();
hashLabel1->setObjectName("hashLabel1");
@ -440,6 +451,35 @@ void DeckEditorDeckDockWidget::writeBannerCard(int index)
deckStateManager->setBannerCard(bannerCard);
}
void DeckEditorDeckDockWidget::openPlaymatSettings()
{
PlaymatInfo current = deckStateManager->getMetadata().playmat;
PlaymatSettingsDialog dialog(current.card, current.params, this);
if (dialog.exec() == QDialog::Accepted) {
CardRef newCard = dialog.card();
PlaymatParams newParams = dialog.params();
if (newCard.isEmpty()) {
deckStateManager->setPlaymat(PlaymatInfo{});
} else {
deckStateManager->setPlaymat({newCard, newParams});
}
updatePlaymatLabel();
}
}
void DeckEditorDeckDockWidget::updatePlaymatLabel()
{
CardRef playmat = deckStateManager->getMetadata().playmat.card;
if (playmat.isEmpty()) {
playmatSettingsButton->setText(tr("Edit Playmat..."));
} else {
playmatSettingsButton->setText(tr("Edit Playmat (%1)").arg(playmat.name));
}
}
void DeckEditorDeckDockWidget::applyActiveGroupCriteria()
{
getModel()->setActiveGroupCriteria(
@ -497,6 +537,7 @@ void DeckEditorDeckDockWidget::syncDisplayWidgetsToModel()
syncBannerCardComboBoxSelectionWithDeck();
updateBannerCardComboBox();
bannerCardComboBox->blockSignals(false);
updatePlaymatLabel();
updateHash();
formatComboBox->blockSignals(true);

View file

@ -15,11 +15,15 @@
#include "deck_list_history_manager_widget.h"
#include "deck_list_style_proxy.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDockWidget>
#include <QLabel>
#include <QPushButton>
#include <QTextEdit>
#include <QTreeView>
#include <libcockatrice/card/card_info.h>
#include <libcockatrice/deck_list/deck_list.h>
class CommanderBracketWidget;
class DeckListModel;
@ -33,6 +37,8 @@ public:
DeckListStyleProxy *proxy;
QTreeView *deckView;
QComboBox *bannerCardComboBox;
QLabel *playmatLabel;
QPushButton *playmatSettingsButton;
void createDeckDock();
ExactCard getCurrentCard();
void retranslateUi();
@ -102,6 +108,8 @@ private slots:
void writeName();
void writeComments();
void writeBannerCard(int);
void openPlaymatSettings();
void updatePlaymatLabel();
void applyActiveGroupCriteria();
void setSelectedIndex(const QModelIndex &newCardIndex, bool preserveWidgetFocus);
void updateHash();

View file

@ -142,6 +142,19 @@ void DeckStateManager::setBannerCard(const CardRef &bannerCard)
doMetadataModified();
}
void DeckStateManager::setPlaymat(const PlaymatInfo &playmat)
{
PlaymatInfo previous = deckList->getPlaymat();
if (previous == playmat) {
return;
}
requestHistorySave(tr("Set playmat to %1").arg(playmat.card.name));
deckList->setPlaymat(playmat);
doMetadataModified();
}
void DeckStateManager::setTags(const QStringList &tags)
{
QStringList previous = deckList->getTags();

View file

@ -171,6 +171,7 @@ public:
void setName(const QString &name);
void setComments(const QString &comments);
void setBannerCard(const CardRef &bannerCard);
void setPlaymat(const PlaymatInfo &playmat);
void setTags(const QStringList &tags);
void setFormat(const QString &format);
///@}

View file

@ -214,6 +214,7 @@ DlgCreateGame::DlgCreateGame(const ServerInfo_Game &gameInfo, const QMap<int, QS
spectatorsNeedPasswordCheckBox->setChecked(gameInfo.spectators_need_password());
spectatorsCanTalkCheckBox->setChecked(gameInfo.spectators_can_chat());
spectatorsSeeEverythingCheckBox->setChecked(gameInfo.spectators_omniscient());
shareDecklistsOnLoadCheckBox->setChecked(gameInfo.share_decklists_on_load());
QSet<int> types;
for (int i = 0; i < gameInfo.game_types_size(); ++i) {

View file

@ -30,7 +30,7 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
hideFullGames = new QCheckBox(tr("Hide full games"));
hideFullGames->setChecked(filters.hideFullGames);
hideGamesThatStarted = new QCheckBox(tr("Hide games that have started"));
hideGamesThatStarted = new QCheckBox(tr("Hide started games"));
hideGamesThatStarted->setChecked(filters.hideGamesThatStarted);
hidePasswordProtectedGames = new QCheckBox(tr("Hide password protected games"));
@ -57,16 +57,16 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
gameNameFilterEdit->setText(filters.gameNameFilter);
auto *gameNameFilterLabel = new QLabel(tr("Game &description:"));
gameNameFilterLabel->setBuddy(gameNameFilterEdit);
creatorNameFilterEdit = new QLineEdit;
creatorNameFilterEdit->setText(filters.creatorNameFilters.join(", "));
auto *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
creatorNameFilterLabel->setBuddy(creatorNameFilterEdit);
hostNameFilterEdit = new QLineEdit;
hostNameFilterEdit->setText(filters.hostNameFilters.join(", "));
auto *hostNameFilterLabel = new QLabel(tr("&Host name:"));
hostNameFilterLabel->setBuddy(hostNameFilterEdit);
auto *generalGrid = new QGridLayout;
generalGrid->addWidget(gameNameFilterLabel, 0, 0);
generalGrid->addWidget(gameNameFilterEdit, 0, 1);
generalGrid->addWidget(creatorNameFilterLabel, 1, 0);
generalGrid->addWidget(creatorNameFilterEdit, 1, 1);
generalGrid->addWidget(hostNameFilterLabel, 1, 0);
generalGrid->addWidget(hostNameFilterEdit, 1, 1);
generalGrid->addWidget(maxGameAgeLabel, 2, 0);
generalGrid->addWidget(maxGameAgeComboBox, 2, 1);
generalGroupBox = new QGroupBox(tr("General"));
@ -193,7 +193,7 @@ GameFilterConfigs DlgFilterGames::getFilters() const
hideNotBuddyCreatedGames->isChecked(),
hideOpenDecklistGames->isChecked(),
gameNameFilterEdit->text(),
getCreatorNameFilters(),
getHostNameFilters(),
getGameTypeFilter(),
maxPlayersFilterMinSpinBox->value(),
maxPlayersFilterMaxSpinBox->value(),
@ -216,9 +216,9 @@ void DlgFilterGames::toggleSpectatorCheckboxEnabledness(bool spectatorsEnabled)
showOnlyIfSpectatorsCanSeeHands->setDisabled(!spectatorsEnabled);
}
QStringList DlgFilterGames::getCreatorNameFilters() const
QStringList DlgFilterGames::getHostNameFilters() const
{
return creatorNameFilterEdit->text().split(",", Qt::SkipEmptyParts);
return hostNameFilterEdit->text().split(",", Qt::SkipEmptyParts);
}
QSet<int> DlgFilterGames::getGameTypeFilter() const

View file

@ -35,7 +35,7 @@ private:
QCheckBox *hideNotBuddyCreatedGames;
QCheckBox *hideOpenDecklistGames;
QLineEdit *gameNameFilterEdit;
QLineEdit *creatorNameFilterEdit;
QLineEdit *hostNameFilterEdit;
QMap<int, QCheckBox *> gameTypeFilterCheckBoxes;
QSpinBox *maxPlayersFilterMinSpinBox;
QSpinBox *maxPlayersFilterMaxSpinBox;
@ -50,7 +50,7 @@ private:
const GamesProxyModel *gamesProxyModel;
const QMap<QTime, QString> gameAgeMap;
[[nodiscard]] QStringList getCreatorNameFilters() const;
[[nodiscard]] QStringList getHostNameFilters() const;
[[nodiscard]] QSet<int> getGameTypeFilter() const;
[[nodiscard]] QTime getMaxGameAge() const;
[[nodiscard]] bool getShowSpectatorPasswordProtected() const;

View file

@ -0,0 +1,112 @@
#include "dlg_invite_to_game.h"
#include "../server/user/user_list_manager.h"
#include "../server/user/user_list_widget.h"
#include "../tabs/tab_supervisor.h"
#include <QGuiApplication>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QScreen>
#include <QUrl>
#include <QUrlQuery>
#include <QVBoxLayout>
DlgInviteToGame::DlgInviteToGame(TabSupervisor *_tabSupervisor,
const QString &_inviteUrl,
bool _onlyBuddies,
const QStringList &_excludeUserNames,
QWidget *parent)
: QDialog(parent), tabSupervisor(_tabSupervisor), inviteUrl(_inviteUrl), onlyBuddies(_onlyBuddies),
excludeUserNames(_excludeUserNames)
{
setModal(true);
searchEdit = new QLineEdit(this);
searchEdit->setClearButtonEnabled(true);
connect(searchEdit, &QLineEdit::textChanged, this, &DlgInviteToGame::searchTextChanged);
// The embedded list is the real room user list without the hover popup:
// same manager, same delegate/painter, same sections, live via manager
// signals while the modal loop runs.
UserListManager *manager = tabSupervisor->getUserListManager();
userList = new UserListWidget(tabSupervisor, tabSupervisor->getClient(), UserListWidget::RoomList, this,
/*hasUserInfoPopup=*/false);
userList->setUserFilter([this, manager](const QString &name, bool online) {
return !excludeUserNames.contains(name) && online && !manager->isUserIgnored(name);
});
if (onlyBuddies) {
userList->setSectioned({UserListWidget::Section::Buddy});
} else {
userList->setSectioned({UserListWidget::Section::Buddy, UserListWidget::Section::Online});
}
userList->bind(manager);
userList->rebuild();
connect(userList, &UserListWidget::userActivated, this, &DlgInviteToGame::inviteCurrentUser);
connect(userList, &UserListWidget::currentUserChanged, this, [this](const QString &userName) {
currentUserName = userName;
inviteButton->setEnabled(!userName.isEmpty());
});
inviteButton = new QPushButton(this);
inviteButton->setEnabled(false);
inviteButton->setDefault(true);
connect(inviteButton, &QPushButton::clicked, this, [this] { inviteCurrentUser(currentUserName); });
cancelButton = new QPushButton(this);
connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
auto *buttonRow = new QHBoxLayout;
buttonRow->addStretch();
buttonRow->addWidget(inviteButton);
buttonRow->addWidget(cancelButton);
auto *layout = new QVBoxLayout(this);
layout->addWidget(searchEdit);
layout->addWidget(userList, 1);
layout->addLayout(buttonRow);
retranslateUi();
// Default to a comfortably tall dialog so the list has room to breathe,
// capped by the available screen. No minimum is enforced: small screens
// and manual resizing can go shorter than this.
const QRect availableScreen = QGuiApplication::primaryScreen()->availableGeometry();
resize(sizeHint().width(), qMin(sizeHint().height() * 3, availableScreen.height() * 4 / 5));
}
void DlgInviteToGame::searchTextChanged(const QString &text)
{
userList->setFilterText(text);
}
void DlgInviteToGame::inviteCurrentUser(const QString &userName)
{
if (userName.isEmpty()) {
return;
}
// The invite link carries the game's id and, when the game has one, its
// description (makeGameJoinLink embeds both). Read them back so the prefix
// names the game by description first, then its id — identical to the
// context-menu invite so recipients see one consistent message style.
const QUrl inviteUrlObj(inviteUrl);
const QUrlQuery inviteQuery(inviteUrlObj);
const int gameId = inviteQuery.queryItemValue("gameid").toInt();
const QString gameDescription = inviteQuery.queryItemValue("game");
const QString prefix = gameDescription.isEmpty()
? tr("Join my game (#%1):").arg(gameId)
: tr("Join my game \"%1\" (#%2):").arg(gameDescription).arg(gameId);
tabSupervisor->sendInviteToUser(userName, prefix + " " + inviteUrl);
accept();
}
void DlgInviteToGame::retranslateUi()
{
setWindowTitle(tr("Invite to Game"));
searchEdit->setPlaceholderText(tr("Search users..."));
inviteButton->setText(tr("Invite"));
cancelButton->setText(tr("Cancel"));
}

View file

@ -0,0 +1,46 @@
/**
* @file dlg_invite_to_game.h
* @ingroup RoomDialogs
*/
//! \todo Document this file.
#ifndef DLG_INVITE_TO_GAME_H
#define DLG_INVITE_TO_GAME_H
#include <QDialog>
#include <QStringList>
class QLineEdit;
class QPushButton;
class TabSupervisor;
class UserListWidget;
class DlgInviteToGame : public QDialog
{
Q_OBJECT
public:
DlgInviteToGame(TabSupervisor *_tabSupervisor,
const QString &_inviteUrl,
bool _onlyBuddies,
const QStringList &_excludeUserNames,
QWidget *parent = nullptr);
private slots:
void searchTextChanged(const QString &text);
void inviteCurrentUser(const QString &userName);
private:
TabSupervisor *tabSupervisor;
QString inviteUrl;
bool onlyBuddies;
QStringList excludeUserNames;
QString currentUserName;
QLineEdit *searchEdit;
UserListWidget *userList;
QPushButton *inviteButton;
QPushButton *cancelButton;
void retranslateUi();
};
#endif

View file

@ -0,0 +1,297 @@
#include "dlg_my_reports.h"
#include "../utility/report_utils.h"
#include "abstract_client.h"
#include <QFontDatabase>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSplitter>
#include <QTableWidget>
#include <QTextEdit>
#include <QVBoxLayout>
#include <libcockatrice/protocol/pb/command_report_add_comment.pb.h>
#include <libcockatrice/protocol/pb/command_report_details.pb.h>
#include <libcockatrice/protocol/pb/command_report_my_list.pb.h>
#include <libcockatrice/protocol/pb/response_report_details.pb.h>
#include <libcockatrice/protocol/pb/response_report_my_list.pb.h>
#include <libcockatrice/protocol/pending_command.h>
namespace
{
constexpr int COL_ID = 0;
constexpr int COL_TIME = 1;
constexpr int COL_REPORTED = 2;
constexpr int COL_CATEGORY = 3;
constexpr int COL_GAMEID = 4;
constexpr int COL_STATUS = 5;
constexpr int COL_ASSIGNED = 6;
constexpr int COL_COUNT = 7;
} // namespace
DlgMyReports::DlgMyReports(AbstractClient *_client, QWidget *parent)
: QDialog(parent), client(_client), selectedReportId(-1)
{
setWindowTitle(tr("My Reports"));
setMinimumSize(800, 500);
table = new QTableWidget(0, COL_COUNT);
table->setHorizontalHeaderLabels(
{tr("#"), tr("Time"), tr("Reported User"), tr("Category"), tr("Game ID"), tr("Status"), tr("Assigned To")});
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setSortingEnabled(true);
table->verticalHeader()->setVisible(false);
table->setAlternatingRowColors(true);
table->horizontalHeader()->setSectionResizeMode(COL_TIME, QHeaderView::ResizeToContents);
table->horizontalHeader()->setSectionResizeMode(COL_REPORTED, QHeaderView::Stretch);
connect(table, &QTableWidget::itemSelectionChanged, this, &DlgMyReports::onSelectionChanged);
auto *detailsGroup = new QGroupBox(tr("Report Details"));
descriptionEdit = new QTextEdit;
descriptionEdit->setReadOnly(true);
descriptionEdit->setFixedHeight(80);
auto *chatGroup = new QGroupBox(tr("Chat Log Context"));
chatLogEdit = new QTextEdit;
chatLogEdit->setReadOnly(true);
QFont monoFont("monospace");
monoFont.setStyleHint(QFont::Monospace);
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
if (systemPointSize > 0) {
monoFont.setPointSize(systemPointSize);
}
chatLogEdit->setFont(monoFont);
auto *chatLayout = new QVBoxLayout(chatGroup);
chatLayout->setContentsMargins(4, 4, 4, 4);
chatLayout->addWidget(chatLogEdit);
auto *commentsLabel = new QLabel(tr("Comments:"));
commentsEdit = new QTextEdit;
commentsEdit->setReadOnly(true);
commentsEdit->setFixedHeight(120);
auto *addCommentLabel = new QLabel(tr("Add a comment:"));
commentInput = new QLineEdit;
commentInput->setPlaceholderText(tr("Type your comment here..."));
commentButton = new QPushButton(tr("Send"));
commentButton->setEnabled(false);
connect(commentButton, &QPushButton::clicked, this, &DlgMyReports::addComment);
connect(commentInput, &QLineEdit::returnPressed, this, &DlgMyReports::addComment);
auto *detailsLayout = new QVBoxLayout(detailsGroup);
detailsLayout->setContentsMargins(4, 4, 4, 4);
detailsLayout->addWidget(descriptionEdit);
detailsLayout->addWidget(chatGroup);
detailsLayout->addWidget(commentsLabel);
detailsLayout->addWidget(commentsEdit);
detailsLayout->addWidget(addCommentLabel);
auto *commentRow = new QHBoxLayout;
commentRow->addWidget(commentInput);
commentRow->addWidget(commentButton);
detailsLayout->addLayout(commentRow);
closeButton = new QPushButton(tr("Close"));
connect(closeButton, &QPushButton::clicked, this, &QDialog::accept);
refreshButton = new QPushButton(tr("Refresh"));
connect(refreshButton, &QPushButton::clicked, this, &DlgMyReports::refreshList);
statusLabel = new QLabel;
auto *bottomBar = new QHBoxLayout;
bottomBar->addWidget(statusLabel);
bottomBar->addStretch();
bottomBar->addWidget(refreshButton);
bottomBar->addWidget(closeButton);
auto *layout = new QVBoxLayout(this);
layout->addWidget(table, 1);
layout->addWidget(detailsGroup);
layout->addLayout(bottomBar);
setActionsEnabled(false);
refreshList();
}
void DlgMyReports::refreshList()
{
selectedReportIdBeforeRefresh = selectedReportId;
commentDraftBeforeRefresh = commentInput->text();
statusLabel->setText(tr("Loading..."));
refreshButton->setEnabled(false);
table->setRowCount(0);
currentReports.clear();
descriptionEdit->clear();
chatLogEdit->clear();
commentsEdit->clear();
commentInput->clear();
setActionsEnabled(false);
selectedReportId = -1;
Command_ReportMyList cmd;
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &DlgMyReports::reportListResponse);
client->sendCommand(pend);
}
void DlgMyReports::reportListResponse(const Response &response)
{
refreshButton->setEnabled(true);
if (response.response_code() != Response::RespOk) {
statusLabel->setText(tr("Failed to load reports."));
return;
}
const Response_ReportMyList &resp = response.GetExtension(Response_ReportMyList::ext);
currentReports.clear();
for (int i = 0; i < resp.reports_size(); ++i) {
currentReports.append(resp.reports(i));
}
table->setSortingEnabled(false);
table->setRowCount(currentReports.size());
for (int row = 0; row < currentReports.size(); ++row) {
const ServerInfo_Report &r = currentReports[row];
report_utils::fillReportTableRow(table, row, r, COL_ID, COL_TIME, COL_REPORTED, COL_CATEGORY, COL_GAMEID,
COL_STATUS, COL_ASSIGNED);
}
table->setSortingEnabled(true);
table->resizeColumnsToContents();
table->horizontalHeader()->setSectionResizeMode(COL_REPORTED, QHeaderView::Stretch);
if (selectedReportIdBeforeRefresh >= 0) {
for (int row = 0; row < table->rowCount(); ++row) {
if (table->item(row, COL_ID) &&
table->item(row, COL_ID)->data(Qt::UserRole).toInt() == selectedReportIdBeforeRefresh) {
table->setCurrentCell(row, 0);
break;
}
}
}
if (commentInput->text().isEmpty()) {
commentInput->setText(commentDraftBeforeRefresh);
}
statusLabel->setText(tr("%1 report(s)").arg(currentReports.size()));
}
void DlgMyReports::onSelectionChanged()
{
const int row = table->currentRow();
if (row < 0 || !table->item(row, COL_ID)) {
descriptionEdit->clear();
chatLogEdit->clear();
commentsEdit->clear();
commentInput->clear();
commentButton->setEnabled(false);
selectedReportId = -1;
return;
}
const int reportId = table->item(row, COL_ID)->data(Qt::UserRole).toInt();
selectedReportId = reportId;
for (const ServerInfo_Report &r : currentReports) {
if (r.report_id() == reportId) {
descriptionEdit->setPlainText(QString::fromStdString(r.description()));
break;
}
}
chatLogEdit->setPlainText(tr("Loading..."));
commentsEdit->setPlainText(tr("Loading..."));
Command_ReportDetails cmd;
cmd.set_report_id(reportId);
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &DlgMyReports::reportDetailsResponse);
client->sendCommand(pend);
QString status = table->item(row, COL_STATUS)->text();
bool canComment = (status == "open" || status == "assigned");
commentButton->setEnabled(canComment);
commentInput->setEnabled(canComment);
if (!canComment) {
commentInput->setPlaceholderText(tr("This report is closed."));
} else {
commentInput->setPlaceholderText(tr("Type your comment here..."));
}
}
void DlgMyReports::reportDetailsResponse(const Response &response)
{
if (response.response_code() != Response::RespOk) {
if (selectedReportId == -1) {
return;
}
chatLogEdit->clear();
commentsEdit->setPlainText(tr("Failed to load report details."));
return;
}
const Response_ReportDetails &resp = response.GetExtension(Response_ReportDetails::ext);
const ServerInfo_Report &r = resp.report();
if (selectedReportId != r.report_id()) {
return;
}
loadReportDetails(r);
}
void DlgMyReports::loadReportDetails(const ServerInfo_Report &report)
{
report_utils::renderReportDetails(chatLogEdit, commentsEdit, report, tr("No comments yet."), tr("[Moderator]"),
tr("[You]"));
}
void DlgMyReports::addComment()
{
if (selectedReportId < 0) {
return;
}
QString text = commentInput->text().trimmed();
if (text.isEmpty()) {
return;
}
commentButton->setEnabled(false);
Command_ReportAddComment cmd;
cmd.set_report_id(selectedReportId);
cmd.set_comment(text.toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &DlgMyReports::addCommentResponse);
client->sendCommand(pend);
}
void DlgMyReports::addCommentResponse(const Response &response)
{
if (response.response_code() == Response::RespOk) {
commentInput->clear();
refreshList();
} else {
commentButton->setEnabled(true);
}
}
void DlgMyReports::setActionsEnabled(bool enabled)
{
commentButton->setEnabled(enabled);
commentInput->setEnabled(enabled);
}

View file

@ -0,0 +1,52 @@
#ifndef COCKATRICE_DLG_MY_REPORTS_H
#define COCKATRICE_DLG_MY_REPORTS_H
#include <QDialog>
#include <QList>
#include <libcockatrice/protocol/pb/response.pb.h>
#include <libcockatrice/protocol/pb/serverinfo_report.pb.h>
class AbstractClient;
class QTableWidget;
class QTextEdit;
class QLineEdit;
class QPushButton;
class QLabel;
class DlgMyReports : public QDialog
{
Q_OBJECT
public:
explicit DlgMyReports(AbstractClient *_client, QWidget *parent = nullptr);
private slots:
void refreshList();
void reportListResponse(const Response &response);
void onSelectionChanged();
void reportDetailsResponse(const Response &response);
void addComment();
void addCommentResponse(const Response &response);
private:
void loadReportDetails(const ServerInfo_Report &report);
void setActionsEnabled(bool enabled);
AbstractClient *client;
QTableWidget *table;
QTextEdit *descriptionEdit;
QTextEdit *chatLogEdit;
QTextEdit *commentsEdit;
QLineEdit *commentInput;
QPushButton *commentButton;
QPushButton *refreshButton;
QPushButton *closeButton;
QLabel *statusLabel;
QList<ServerInfo_Report> currentReports;
int selectedReportId;
int selectedReportIdBeforeRefresh = -1;
QString commentDraftBeforeRefresh;
};
#endif // COCKATRICE_DLG_MY_REPORTS_H

View file

@ -1,18 +1,62 @@
#include "dlg_register.h"
#include "../../../client/settings/cache_settings.h"
#include "../server/handle_public_servers.h"
#include "../server/user/user_info_connection.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QVBoxLayout>
#include <libcockatrice/settings/servers_settings.h>
#include <libcockatrice/utility/string_limits.h>
DlgRegister::DlgRegister(QWidget *parent) : QDialog(parent)
{
// ── Server picker ──────────────────────────────────────────────────
previousHostButton = new QRadioButton(tr("Known Hosts"), this);
previousHosts = new QComboBox(this);
btnDeleteServer = new QPushButton(this);
btnDeleteServer->setIcon(QPixmap("theme:icons/remove_row"));
btnDeleteServer->setToolTip(tr("Delete the currently selected saved server"));
btnDeleteServer->setFixedWidth(30);
connect(btnDeleteServer, &QPushButton::clicked, this, &DlgRegister::actRemoveSavedServer);
hps = new HandlePublicServers(this);
btnRefreshServers = new QPushButton(this);
btnRefreshServers->setIcon(QPixmap("theme:icons/sync"));
btnRefreshServers->setToolTip(tr("Refresh the server list with known public servers"));
btnRefreshServers->setFixedWidth(30);
connect(hps, &HandlePublicServers::sigPublicServersDownloadedSuccessfully, this, [this] { rebuildComboBoxList(); });
connect(hps, &HandlePublicServers::sigPublicServersDownloadedUnsuccessfully, this,
&DlgRegister::rebuildComboBoxList);
connect(btnRefreshServers, &QPushButton::released, this, &DlgRegister::downloadThePublicServers);
newHostButton = new QRadioButton(tr("New Host"), this);
auto *serverPickerRow = new QHBoxLayout;
serverPickerRow->addWidget(previousHosts);
serverPickerRow->addWidget(btnDeleteServer);
serverPickerRow->addWidget(btnRefreshServers);
auto *serverGroupLayout = new QVBoxLayout;
serverGroupLayout->addWidget(previousHostButton);
serverGroupLayout->addLayout(serverPickerRow);
serverGroupLayout->addWidget(newHostButton);
auto *serverGroupBox = new QGroupBox(tr("Server"));
serverGroupBox->setLayout(serverGroupLayout);
// ── Registration fields ────────────────────────────────────────────
ServersSettings &servers = SettingsCache::instance().servers();
infoLabel = new QLabel(tr("Enter your information and the information of the server you'd like to register to.\n"
"Your email will be used to verify your account."));
@ -321,26 +365,28 @@ DlgRegister::DlgRegister(QWidget *parent) : QDialog(parent)
realnameEdit->setMaxLength(MAX_NAME_LENGTH);
realnameLabel->setBuddy(realnameEdit);
// ── Layout ─────────────────────────────────────────────────────────
auto *grid = new QGridLayout;
grid->addWidget(infoLabel, 0, 0, 1, 2);
grid->addWidget(hostLabel, 1, 0);
grid->addWidget(hostEdit, 1, 1);
grid->addWidget(portLabel, 2, 0);
grid->addWidget(portEdit, 2, 1);
grid->addWidget(playernameLabel, 3, 0);
grid->addWidget(playernameEdit, 3, 1);
grid->addWidget(passwordLabel, 4, 0);
grid->addWidget(passwordEdit, 4, 1);
grid->addWidget(passwordConfirmationLabel, 5, 0);
grid->addWidget(passwordConfirmationEdit, 5, 1);
grid->addWidget(emailLabel, 6, 0);
grid->addWidget(emailEdit, 6, 1);
grid->addWidget(emailConfirmationLabel, 7, 0);
grid->addWidget(emailConfirmationEdit, 7, 1);
grid->addWidget(countryLabel, 9, 0);
grid->addWidget(countryEdit, 9, 1);
grid->addWidget(realnameLabel, 10, 0);
grid->addWidget(realnameEdit, 10, 1);
grid->addWidget(serverGroupBox, 0, 0, 1, 2);
grid->addWidget(infoLabel, 1, 0, 1, 2);
grid->addWidget(hostLabel, 2, 0);
grid->addWidget(hostEdit, 2, 1);
grid->addWidget(portLabel, 3, 0);
grid->addWidget(portEdit, 3, 1);
grid->addWidget(playernameLabel, 4, 0);
grid->addWidget(playernameEdit, 4, 1);
grid->addWidget(passwordLabel, 5, 0);
grid->addWidget(passwordEdit, 5, 1);
grid->addWidget(passwordConfirmationLabel, 6, 0);
grid->addWidget(passwordConfirmationEdit, 6, 1);
grid->addWidget(emailLabel, 7, 0);
grid->addWidget(emailEdit, 7, 1);
grid->addWidget(emailConfirmationLabel, 8, 0);
grid->addWidget(emailConfirmationEdit, 8, 1);
grid->addWidget(countryLabel, 10, 0);
grid->addWidget(countryEdit, 10, 1);
grid->addWidget(realnameLabel, 11, 0);
grid->addWidget(realnameEdit, 11, 1);
auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &DlgRegister::actOk);
@ -352,13 +398,115 @@ DlgRegister::DlgRegister(QWidget *parent) : QDialog(parent)
setLayout(mainLayout);
setWindowTitle(tr("Register to server"));
setFixedHeight(sizeHint().height());
setMinimumWidth(300);
setMinimumWidth(360);
connect(previousHostButton, &QRadioButton::toggled, this, &DlgRegister::previousHostSelected);
connect(newHostButton, &QRadioButton::toggled, this, &DlgRegister::newHostSelected);
connect(previousHosts, &QComboBox::currentTextChanged, this, &DlgRegister::updateDisplayInfo);
previousHostButton->setChecked(true);
preRebuildComboBoxList();
}
DlgRegister::~DlgRegister() = default;
void DlgRegister::downloadThePublicServers()
{
btnRefreshServers->setDisabled(true);
previousHosts->clear();
previousHosts->addItem(placeHolderText);
hps->downloadPublicServers();
}
void DlgRegister::preRebuildComboBoxList()
{
UserConnection_Information uci;
savedHostList = uci.getServerInfo();
if (savedHostList.size() == 1) {
downloadThePublicServers();
} else {
rebuildComboBoxList();
}
}
void DlgRegister::rebuildComboBoxList(int failure)
{
Q_UNUSED(failure);
previousHosts->clear();
UserConnection_Information uci;
savedHostList = uci.getServerInfo();
auto &servers = SettingsCache::instance().servers();
QString previousHostName = servers.getPrevioushostName();
for (const auto &pair : savedHostList) {
const auto &tmp = pair.second;
QString saveName = tmp.getSaveName();
if (saveName.size()) {
previousHosts->addItem(saveName);
if (saveName.compare(previousHostName) == 0) {
previousHosts->setCurrentIndex(previousHosts->count() - 1);
}
}
}
btnRefreshServers->setDisabled(false);
}
void DlgRegister::previousHostSelected(bool state)
{
if (state) {
previousHosts->setDisabled(false);
btnRefreshServers->setDisabled(false);
hostEdit->setDisabled(true);
portEdit->setDisabled(true);
}
}
void DlgRegister::newHostSelected(bool state)
{
if (state) {
previousHosts->setDisabled(true);
btnRefreshServers->setDisabled(true);
hostEdit->setDisabled(false);
hostEdit->clear();
hostEdit->setPlaceholderText(tr("Server URL"));
portEdit->setDisabled(false);
portEdit->clear();
portEdit->setPlaceholderText(tr("Communication Port"));
playernameEdit->setDisabled(false);
playernameEdit->clear();
} else {
// Rebuild the list so the previously selected host's details are
// repopulated (mirrors DlgConnect::newHostSelected).
preRebuildComboBoxList();
}
}
void DlgRegister::updateDisplayInfo(const QString &saveName)
{
if (saveName.isEmpty() || saveName == placeHolderText) {
return;
}
UserConnection_Information uci;
QStringList _data = uci.getServerInfo(saveName);
if (_data.size() < 7) {
return;
}
hostEdit->setText(_data.at(1));
portEdit->setText(_data.at(2));
playernameEdit->setText(_data.at(3));
}
void DlgRegister::actOk()
{
//! \todo This stuff should be using QValidators.
if (passwordEdit->text().length() < 8) {
QMessageBox::critical(this, tr("Registration Warning"), tr("Your password is too short."));
return;
@ -375,5 +523,29 @@ void DlgRegister::actOk()
return;
}
ServersSettings &servers = SettingsCache::instance().servers();
if (newHostButton->isChecked()) {
// Persist the new host so it shows up in the Connect dialog later.
// The password is never stored: the account is not verified yet.
const QString host = hostEdit->text().trimmed();
if (!host.isEmpty()) {
servers.addNewServer(host, host, portEdit->text().trimmed(), playernameEdit->text().trimmed(), QString(),
false);
servers.setPrevioushostName(host);
}
} else {
const QString saveName = previousHosts->currentText();
if (!saveName.isEmpty() && saveName != placeHolderText) {
servers.setPrevioushostName(saveName);
}
}
accept();
}
void DlgRegister::actRemoveSavedServer()
{
SettingsCache::instance().servers().removeServer(hostEdit->text());
previousHosts->removeItem(previousHosts->currentIndex());
}

View file

@ -1,25 +1,24 @@
/**
* @file dlg_register.h
* @ingroup AccountDialogs
*/
//! \todo Document this file.
#ifndef DLG_REGISTER_H
#define DLG_REGISTER_H
#include <QComboBox>
#include <QDialog>
#include <QLineEdit>
#include <QMap>
class HandlePublicServers;
class QLabel;
class QPushButton;
class QCheckBox;
class QRadioButton;
class UserConnection_Information;
class DlgRegister : public QDialog
{
Q_OBJECT
public:
explicit DlgRegister(QWidget *parent = nullptr);
~DlgRegister() override;
[[nodiscard]] QString getHost() const
{
return hostEdit->text();
@ -48,15 +47,35 @@ public:
{
return realnameEdit->text();
}
public slots:
void downloadThePublicServers();
private slots:
void actOk();
void previousHostSelected(bool state);
void newHostSelected(bool state);
void updateDisplayInfo(const QString &saveName);
void preRebuildComboBoxList();
void rebuildComboBoxList(int failure = -1);
void actRemoveSavedServer();
private:
QRadioButton *newHostButton;
QRadioButton *previousHostButton;
QComboBox *previousHosts;
QPushButton *btnDeleteServer;
QPushButton *btnRefreshServers;
HandlePublicServers *hps;
QLabel *infoLabel, *hostLabel, *portLabel, *playernameLabel, *passwordLabel, *passwordConfirmationLabel,
*emailLabel, *emailConfirmationLabel, *countryLabel, *realnameLabel;
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit, *passwordConfirmationEdit, *emailEdit,
*emailConfirmationEdit, *realnameEdit;
QComboBox *countryEdit;
QMap<QString, std::pair<QString, UserConnection_Information>> savedHostList;
const QString placeHolderText = tr("Downloading...");
};
#endif
#endif // DLG_REGISTER_H

View file

@ -0,0 +1,191 @@
#include "dlg_report_user.h"
#include "abstract_client.h"
#include <QComboBox>
#include <QDialogButtonBox>
#include <QFontDatabase>
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
#include <libcockatrice/protocol/pb/command_report.pb.h>
#include <libcockatrice/protocol/pending_command.h>
DlgReportUser::DlgReportUser(AbstractClient *_client,
const QString &_reportedUser,
int _gameId,
const QString &_autoChatLog,
QWidget *parent)
: QDialog(parent), client(_client), reportedUser(_reportedUser), gameId(_gameId)
{
setWindowTitle(tr("Report User"));
setMinimumWidth(500);
auto *infoLabel =
new QLabel(tr("Reports are reviewed by moderators. False reports may result in account penalties."));
infoLabel->setWordWrap(true);
infoLabel->setStyleSheet("color: palette(placeholderText); padding: 5px;");
auto *reportGroup = new QGroupBox(tr("Report Details"));
auto *reportGrid = new QGridLayout(reportGroup);
reportGrid->addWidget(new QLabel(tr("Reported User:")), 0, 0);
reportedUserLabel = new QLabel(reportedUser);
reportedUserLabel->setStyleSheet("font-weight: bold;");
reportGrid->addWidget(reportedUserLabel, 0, 1);
reportGrid->addWidget(new QLabel(tr("Game ID:")), 1, 0);
if (gameId >= 0) {
gameIdLabel = new QLabel(QString::number(gameId));
gameIdLabel->setStyleSheet("font-weight: bold;");
reportGrid->addWidget(gameIdLabel, 1, 1);
} else {
gameIdEdit = new QLineEdit;
gameIdEdit->setPlaceholderText(tr("(Optional) Enter game ID if available"));
gameIdEdit->setToolTip(tr("If the report is related to a specific game, enter its ID."));
reportGrid->addWidget(gameIdEdit, 1, 1);
gameIdLabel = nullptr;
}
auto *categoryGroup = new QGroupBox(tr("Category"));
auto *categoryGrid = new QGridLayout(categoryGroup);
categoryBox = new QComboBox;
categoryBox->addItem(tr("Cheating / Unsporting behavior"), "cheating");
categoryBox->setItemData(categoryBox->count() - 1,
tr("Using external tools, card marked manipulation, or exploiting game bugs"),
Qt::ToolTipRole);
categoryBox->addItem(tr("Harassment / Abuse"), "harassment");
categoryBox->setItemData(categoryBox->count() - 1, tr("Threatening, bullying, or persistent unwanted contact"),
Qt::ToolTipRole);
categoryBox->addItem(tr("Hate speech"), "hate_speech");
categoryBox->setItemData(categoryBox->count() - 1,
tr("Discriminatory language targeting race, gender, religion, etc."), Qt::ToolTipRole);
categoryBox->addItem(tr("Spam"), "spam");
categoryBox->setItemData(categoryBox->count() - 1, tr("Repeated unwanted messages or advertisements"),
Qt::ToolTipRole);
categoryBox->addItem(tr("Other"), "other");
categoryBox->setItemData(categoryBox->count() - 1, tr("Any behavior not covered by the above categories"),
Qt::ToolTipRole);
categoryGrid->addWidget(new QLabel(tr("Category:")), 0, 0);
categoryGrid->addWidget(categoryBox, 0, 1);
auto *descGroup = new QGroupBox(tr("Description"));
auto *descLayout = new QVBoxLayout(descGroup);
descriptionEdit = new QTextEdit;
descriptionEdit->setPlaceholderText(
tr("Please describe what happened. Include dates, game details, or any evidence if available."));
descriptionEdit->setFixedHeight(120);
descLayout->addWidget(descriptionEdit);
auto *chatGroup = new QGroupBox(tr("Chat Log Context"));
auto *chatLayout = new QVBoxLayout(chatGroup);
chatLogEdit = new QTextEdit;
chatLogEdit->setReadOnly(true);
QFont monoFont("monospace");
monoFont.setStyleHint(QFont::Monospace);
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
if (systemPointSize > 0) {
monoFont.setPointSize(systemPointSize);
}
chatLogEdit->setFont(monoFont);
if (!_autoChatLog.isEmpty()) {
chatLogEdit->setPlainText(_autoChatLog);
} else {
chatLogEdit->setPlaceholderText(tr("No chat context available (not triggered from chat)."));
}
chatLogEdit->setFixedHeight(100);
chatLayout->addWidget(chatLogEdit);
auto *chatNote = new QLabel(
tr("This chat log is captured from your local chat window and may not reflect the full conversation."));
chatNote->setWordWrap(true);
chatNote->setStyleSheet("color: palette(placeholderText);");
chatLayout->addWidget(chatNote);
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Submit Report"));
connect(buttonBox, &QDialogButtonBox::accepted, this, &DlgReportUser::actSubmit);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
auto *layout = new QVBoxLayout(this);
layout->addWidget(infoLabel);
layout->addWidget(reportGroup);
layout->addWidget(categoryGroup);
layout->addWidget(descGroup);
layout->addWidget(chatGroup);
layout->addWidget(buttonBox);
}
void DlgReportUser::actSubmit()
{
const QString description = descriptionEdit->toPlainText().trimmed();
if (description.isEmpty()) {
QMessageBox::warning(this, tr("Missing description"), tr("Please describe what happened before submitting."));
return;
}
QMessageBox::StandardButton reply =
QMessageBox::question(this, tr("Confirm Report"),
tr("Submit report against %1 for %2?").arg(reportedUser, categoryBox->currentText()),
QMessageBox::Yes | QMessageBox::No);
if (reply != QMessageBox::Yes) {
return;
}
buttonBox->setEnabled(false);
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Submitting..."));
Command_Report cmd;
cmd.set_reported_user(reportedUser.toStdString());
cmd.set_category(categoryBox->currentData().toString().toStdString());
cmd.set_description(description.toStdString());
if (gameId >= 0) {
cmd.set_game_id(gameId);
} else if (gameIdEdit && !gameIdEdit->text().trimmed().isEmpty()) {
bool ok;
int manualGameId = gameIdEdit->text().trimmed().toInt(&ok);
if (ok && manualGameId > 0) {
cmd.set_game_id(manualGameId);
}
}
const QString chatLog = chatLogEdit->toPlainText().trimmed();
if (!chatLog.isEmpty()) {
cmd.set_chat_log(chatLog.toStdString());
}
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &DlgReportUser::reportResponse);
client->sendCommand(pend);
}
void DlgReportUser::reportResponse(const Response &response)
{
buttonBox->setEnabled(true);
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Submit Report"));
if (response.response_code() == Response::RespOk) {
QMessageBox::information(this, tr("Report Submitted"),
tr("Your report has been submitted and will be reviewed by a moderator. Thank you."));
accept();
} else if (response.response_code() == Response::RespTooManyRequests) {
QMessageBox::warning(this, tr("Submission Failed"),
tr("You have reached the daily report limit. Please try again later."));
} else if (response.response_code() == Response::RespNameNotFound) {
QMessageBox::warning(
this, tr("Submission Failed"),
tr("The reported user could not be found. Guests (unregistered users) cannot be reported."));
} else {
QMessageBox::warning(this, tr("Submission Failed"), tr("Failed to submit report. Please try again."));
}
}

View file

@ -0,0 +1,42 @@
#ifndef COCKATRICE_DLG_REPORT_USER_H
#define COCKATRICE_DLG_REPORT_USER_H
#include <QDialog>
#include <libcockatrice/protocol/pb/response.pb.h>
class AbstractClient;
class QComboBox;
class QDialogButtonBox;
class QLineEdit;
class QTextEdit;
class QLabel;
class DlgReportUser : public QDialog
{
Q_OBJECT
public:
DlgReportUser(AbstractClient *_client,
const QString &_reportedUser,
int _gameId = -1,
const QString &_autoChatLog = QString(),
QWidget *parent = nullptr);
private slots:
void actSubmit();
void reportResponse(const Response &response);
private:
AbstractClient *client;
QString reportedUser;
int gameId;
QLabel *reportedUserLabel;
QLabel *gameIdLabel = nullptr;
QLineEdit *gameIdEdit = nullptr;
QComboBox *categoryBox;
QTextEdit *descriptionEdit;
QTextEdit *chatLogEdit;
QDialogButtonBox *buttonBox;
};
#endif // COCKATRICE_DLG_REPORT_USER_H

View file

@ -32,6 +32,7 @@ BannerWidget::BannerWidget(QWidget *parent, const QString &text, Qt::Orientation
// Set minimum height for the widget
setMinimumHeight(50);
setMaximumHeight(100);
connect(this, &BannerWidget::buddyVisibilityChanged, this, &BannerWidget::toggleBuddyVisibility);
updateDropdownIconState();

View file

@ -0,0 +1,49 @@
#ifndef COCKATRICE_HOME_TAB_BUTTON_COLOR_H
#define COCKATRICE_HOME_TAB_BUTTON_COLOR_H
#include <QList>
namespace HomeTabButtonColor
{
/**
* @brief Where to get the colors for the home tab buttons from
*/
enum Source
{
Automatic, ///< Extract color from background, or use theme color if no background
FromBackground, ///< Always extract color from background
};
struct Entry
{
Source source;
const char *trKey; ///< key for translation
};
inline QList<Entry> all()
{
static QList<Entry> entries = {{Automatic, QT_TR_NOOP("Automatic")},
{FromBackground, QT_TR_NOOP("Extract from background")}};
return entries;
}
/**
* Safely converts an int into the corresponding Source.
*
* @param value The int value
* @return The Source. Returns Source::Automatic if the value is not within range
*/
inline Source intToSource(int value)
{
if (value > FromBackground) {
return Automatic; // default
}
return static_cast<Source>(value);
}
} // namespace HomeTabButtonColor
#endif // COCKATRICE_HOME_TAB_BUTTON_COLOR_H

View file

@ -4,8 +4,10 @@
#include "../../../interface/widgets/tabs/tab_supervisor.h"
#include "../../theme_manager.h"
#include "../../window_main.h"
#include "../cards/art_crop_attribution.h"
#include "background_sources.h"
#include "home_styled_button.h"
#include "home_tab_button_color.h"
#include <QGroupBox>
#include <QPainter>
@ -24,7 +26,7 @@ HomeWidget::HomeWidget(QWidget *parent, TabSupervisor *_tabSupervisor)
backgroundSourceCard = new CardInfoPictureArtCropWidget(this);
gradientColors = extractDominantColors(background);
gradientColors = determineButtonColor();
layout->addWidget(createButtons(), 1, 1, Qt::AlignVCenter | Qt::AlignHCenter);
@ -54,6 +56,8 @@ HomeWidget::HomeWidget(QWidget *parent, TabSupervisor *_tabSupervisor)
&HomeWidget::initializeBackgroundFromSource);
connect(&SettingsCache::instance(), &SettingsCache::themeChanged, this,
&HomeWidget::updateButtonsToBackgroundColor);
connect(&SettingsCache::instance().appearance(), &AppearanceSettings::homeTabButtonColorChanged, this,
&HomeWidget::updateButtonsToBackgroundColor);
}
void HomeWidget::initializeBackgroundFromSource()
@ -96,6 +100,34 @@ void HomeWidget::loadBackgroundSourceDeck()
backgroundSourceDeck = deckOpt.has_value() ? deckOpt.value().deckList : DeckList();
}
static bool isDefaultBackgroundAndTheme()
{
QString sourceId = SettingsCache::instance().appearance().getHomeTabBackgroundSource();
return themeManager->isBuiltInTheme() && BackgroundSources::fromId(sourceId) == BackgroundSources::Theme;
}
QPair<QColor, QColor> HomeWidget::determineButtonColor() const
{
static QPair defaultColor = {QColor::fromRgb(20, 140, 60), QColor::fromRgb(120, 200, 80)};
auto colorSource =
HomeTabButtonColor::intToSource(SettingsCache::instance().appearance().getHomeTabButtonColorSourceIndex());
switch (colorSource) {
case HomeTabButtonColor::Automatic: {
if (isDefaultBackgroundAndTheme()) {
return defaultColor;
} else {
return extractDominantColors(background);
}
}
case HomeTabButtonColor::FromBackground:
return extractDominantColors(background);
}
return defaultColor;
}
void HomeWidget::setRandomCard(ExactCard &newCard)
{
static constexpr int ATTEMPTS = 10;
@ -170,7 +202,7 @@ void HomeWidget::updateBackgroundProperties()
void HomeWidget::updateButtonsToBackgroundColor()
{
gradientColors = extractDominantColors(background);
gradientColors = determineButtonColor();
for (HomeStyledButton *button : findChildren<HomeStyledButton *>()) {
button->updateStylesheet(gradientColors);
button->update();
@ -265,11 +297,6 @@ void HomeWidget::updateConnectButton(const ClientStatus status)
QPair<QColor, QColor> HomeWidget::extractDominantColors(const QPixmap &pixmap)
{
if (themeManager->isBuiltInTheme() && SettingsCache::instance().appearance().getHomeTabBackgroundSource() ==
BackgroundSources::toId(BackgroundSources::Theme)) {
return QPair<QColor, QColor>(QColor::fromRgb(20, 140, 60), QColor::fromRgb(120, 200, 80));
}
// Step 1: Downscale image for performance
QImage image = pixmap.toImage()
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation)
@ -341,8 +368,9 @@ void HomeWidget::paintEvent(QPaintEvent *event)
QColor semiTransparentBlack(0, 0, 0, static_cast<int>(255 * 0.33));
painter.fillPath(roundedRectPath, semiTransparentBlack);
// Card name overlay (bottom-right)
// Card name overlay (above the attribution, bottom-right)
QString cardName;
QString attribution;
ExactCard card = backgroundSourceCard->getCard();
if (card) {
cardName = card.getCardPtr()->getName();
@ -350,8 +378,27 @@ void HomeWidget::paintEvent(QPaintEvent *event)
cardName += " (" + card.getPrinting().getSet()->getCorrectedShortName() + ") " +
card.getPrinting().getProperty("num");
}
attribution = buildArtAttribution(card);
}
// Scryfall requires artist attribution wherever card art is shown cropped.
// Pin it to the bottom-right corner, using the same font as the card name pill,
// and align its right edge with the card name pill's right edge.
constexpr int margin = 15;
constexpr qreal attributionMargin = 4.0;
QFont attributionFont = painter.font();
attributionFont.setPointSize(14);
attributionFont.setBold(true);
painter.setFont(attributionFont);
// paintArtAttribution insets the pill 4px from the given rect's right edge,
// so nudge the rect's right edge to land exactly on the pill's right edge.
QRectF attributionArea = rect();
attributionArea.setRight(width() - margin + attributionMargin);
const QRectF attributionRect = paintArtAttribution(painter, attributionArea, attribution);
// Card name bubble above the attribution (when enabled).
if (!cardName.isEmpty() && SettingsCache::instance().appearance().getHomeTabDisplayCardName()) {
QFont font = painter.font();
font.setPointSize(14);
@ -360,23 +407,26 @@ void HomeWidget::paintEvent(QPaintEvent *event)
QFontMetrics fm(font);
constexpr int padding = 10;
constexpr int margin = 15;
QRect textRect = fm.boundingRect(cardName);
QRect bgRect(width() - textRect.width() - padding * 2 - margin,
height() - textRect.height() - padding * 2 - margin, textRect.width() + padding * 2,
textRect.height() + padding * 2);
int bubbleBottom = height() - margin;
if (!attributionRect.isEmpty()) {
bubbleBottom = attributionRect.top() - 6;
}
const QRect nameBubbleRect(width() - textRect.width() - padding * 2 - margin,
bubbleBottom - textRect.height() - padding * 2, textRect.width() + padding * 2,
textRect.height() + padding * 2);
// Background bubble
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(0, 0, 0, 160));
painter.drawRoundedRect(bgRect, 8, 8);
painter.drawRoundedRect(nameBubbleRect, 8, 8);
// Text
painter.setPen(Qt::white);
painter.drawText(bgRect.adjusted(padding, padding, -padding, -padding), Qt::AlignRight | Qt::AlignVCenter,
cardName);
painter.drawText(nameBubbleRect.adjusted(padding, padding, -padding, -padding),
Qt::AlignRight | Qt::AlignVCenter, cardName);
}
QWidget::paintEvent(event);

View file

@ -23,7 +23,7 @@ class HomeWidget : public QWidget
public:
HomeWidget(QWidget *parent, TabSupervisor *tabSupervisor);
void updateRandomCard();
QPair<QColor, QColor> extractDominantColors(const QPixmap &pixmap);
static QPair<QColor, QColor> extractDominantColors(const QPixmap &pixmap);
public slots:
void paintEvent(QPaintEvent *event) override;
@ -47,6 +47,7 @@ private:
void setRandomCard(ExactCard &newCard);
void loadBackgroundSourceDeck();
QPair<QColor, QColor> determineButtonColor() const;
};
#endif // HOME_WIDGET_H

View file

@ -0,0 +1,250 @@
#ifndef BANNER_SHADER_CONFIG_H
#define BANNER_SHADER_CONFIG_H
#include <QColor>
#include <QObject>
/**
* Uniform values fed to brand_banner.frag, exposed to QML as the
* "bannerConfig" context property.
*
* Two independent "banks" (A/B) each carry their own mode/speed/seed so
* BrandBanner.qml can render both simultaneously and crossfade between
* them via opacity -- see frontIsA. The shared palette (colorA/colorB/
* accent) and clock (time/aspect) apply to both banks identically, since
* only the foreground motif changes between onboarding pages, never the
* brand palette.
*
* Deliberately plain `property` (not `required property`) on the QML side
* -- a required-property shadowing bug bit the home-screen particle
* background before, and there's no reason to reintroduce that risk here.
*/
class BannerShaderConfig : public QObject
{
Q_OBJECT
Q_PROPERTY(qreal time READ time WRITE setTime NOTIFY timeChanged)
Q_PROPERTY(qreal aspect READ aspect WRITE setAspect NOTIFY aspectChanged)
Q_PROPERTY(qreal modeA READ modeA WRITE setModeA NOTIFY modeAChanged)
Q_PROPERTY(qreal speedA READ speedA WRITE setSpeedA NOTIFY speedAChanged)
Q_PROPERTY(qreal seedA READ seedA WRITE setSeedA NOTIFY seedAChanged)
Q_PROPERTY(qreal modeB READ modeB WRITE setModeB NOTIFY modeBChanged)
Q_PROPERTY(qreal speedB READ speedB WRITE setSpeedB NOTIFY speedBChanged)
Q_PROPERTY(qreal seedB READ seedB WRITE setSeedB NOTIFY seedBChanged)
Q_PROPERTY(bool frontIsA READ frontIsA WRITE setFrontIsA NOTIFY frontIsAChanged)
Q_PROPERTY(QColor colorA READ colorA WRITE setColorA NOTIFY colorAChanged)
Q_PROPERTY(QColor colorB READ colorB WRITE setColorB NOTIFY colorBChanged)
Q_PROPERTY(QColor accent READ accent WRITE setAccent NOTIFY accentChanged)
Q_PROPERTY(bool logoVisible READ logoVisible WRITE setLogoVisible NOTIFY logoVisibleChanged)
Q_PROPERTY(qreal logoGlow READ logoGlow WRITE setLogoGlow NOTIFY logoGlowChanged)
public:
explicit BannerShaderConfig(QObject *parent = nullptr) : QObject(parent)
{
}
qreal time() const
{
return m_time;
}
void setTime(qreal v)
{
if (v != m_time) {
m_time = v;
emit timeChanged();
}
}
qreal aspect() const
{
return m_aspect;
}
void setAspect(qreal v)
{
if (v != m_aspect) {
m_aspect = v;
emit aspectChanged();
}
}
qreal modeA() const
{
return m_modeA;
}
void setModeA(qreal v)
{
if (v != m_modeA) {
m_modeA = v;
emit modeAChanged();
}
}
qreal speedA() const
{
return m_speedA;
}
void setSpeedA(qreal v)
{
if (v != m_speedA) {
m_speedA = v;
emit speedAChanged();
}
}
qreal seedA() const
{
return m_seedA;
}
void setSeedA(qreal v)
{
if (v != m_seedA) {
m_seedA = v;
emit seedAChanged();
}
}
qreal modeB() const
{
return m_modeB;
}
void setModeB(qreal v)
{
if (v != m_modeB) {
m_modeB = v;
emit modeBChanged();
}
}
qreal speedB() const
{
return m_speedB;
}
void setSpeedB(qreal v)
{
if (v != m_speedB) {
m_speedB = v;
emit speedBChanged();
}
}
qreal seedB() const
{
return m_seedB;
}
void setSeedB(qreal v)
{
if (v != m_seedB) {
m_seedB = v;
emit seedBChanged();
}
}
bool frontIsA() const
{
return m_frontIsA;
}
void setFrontIsA(bool v)
{
if (v != m_frontIsA) {
m_frontIsA = v;
emit frontIsAChanged();
}
}
QColor colorA() const
{
return m_colorA;
}
void setColorA(const QColor &c)
{
if (c != m_colorA) {
m_colorA = c;
emit colorAChanged();
}
}
QColor colorB() const
{
return m_colorB;
}
void setColorB(const QColor &c)
{
if (c != m_colorB) {
m_colorB = c;
emit colorBChanged();
}
}
QColor accent() const
{
return m_accent;
}
void setAccent(const QColor &c)
{
if (c != m_accent) {
m_accent = c;
emit accentChanged();
}
}
bool logoVisible() const
{
return m_logoVisible;
}
void setLogoVisible(bool v)
{
if (v != m_logoVisible) {
m_logoVisible = v;
emit logoVisibleChanged();
}
}
qreal logoGlow() const
{
return m_logoGlow;
}
void setLogoGlow(qreal v)
{
if (v != m_logoGlow) {
m_logoGlow = v;
emit logoGlowChanged();
}
}
signals:
void timeChanged();
void aspectChanged();
void modeAChanged();
void speedAChanged();
void seedAChanged();
void modeBChanged();
void speedBChanged();
void seedBChanged();
void frontIsAChanged();
void colorAChanged();
void colorBChanged();
void accentChanged();
void logoVisibleChanged();
void logoGlowChanged();
private:
qreal m_time = 0.0;
qreal m_aspect = 16.0 / 9.0;
qreal m_modeA = 0.0;
qreal m_speedA = 1.0;
qreal m_seedA = 0.0;
qreal m_modeB = 0.0;
qreal m_speedB = 1.0;
qreal m_seedB = 0.0;
bool m_frontIsA = true;
QColor m_colorA{0x1A, 0x1A, 0x20};
QColor m_colorB{0x0E, 0x0E, 0x12};
QColor m_accent{0x8B, 0xDD, 0x6B};
bool m_logoVisible = false;
qreal m_logoGlow = 1.0;
};
#endif // BANNER_SHADER_CONFIG_H

View file

@ -0,0 +1,218 @@
#include "first_run_wizard.h"
#include "first_run_wizard_page.h"
#include "pages/account_setup_page.h"
#include "pages/card_database_setup_page.h"
#include "pages/finish_page.h"
#include "pages/preferences_setup_page.h"
#include "pages/theme_setup_page.h"
#include "pages/welcome_page.h"
#include "shader_banner_widget.h"
#include "step_indicator_widget.h"
#include <QCloseEvent>
#include <QEvent>
#include <QFont>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QStackedWidget>
#include <QVBoxLayout>
FirstRunWizard::FirstRunWizard(QWidget *parent) : QDialog(parent)
{
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
setMinimumSize(640, 490);
resize(720, 550);
bannerHost = new BannerHost(this);
titleLabel = new QLabel(this);
QFont titleFont = titleLabel->font();
titleFont.setPointSizeF(titleFont.pointSizeF() * 1.4);
titleFont.setBold(true);
titleLabel->setFont(titleFont);
subtitleLabel = new QLabel(this);
subtitleLabel->setWordWrap(true);
stack = new QStackedWidget(this);
stepIndicator = new StepIndicatorWidget(this);
backButton = new QPushButton(this);
skipButton = new QPushButton(this);
nextButton = new QPushButton(this);
nextButton->setDefault(true);
connect(backButton, &QPushButton::clicked, this, &FirstRunWizard::goBack);
connect(skipButton, &QPushButton::clicked, this, &FirstRunWizard::skip);
connect(nextButton, &QPushButton::clicked, this, &FirstRunWizard::goNext);
auto *headerLayout = new QVBoxLayout;
headerLayout->setContentsMargins(0, 0, 0, 0);
headerLayout->addWidget(bannerHost);
headerLayout->addSpacing(12);
headerLayout->addWidget(titleLabel);
headerLayout->addWidget(subtitleLabel);
auto *navLayout = new QHBoxLayout;
navLayout->addWidget(backButton);
navLayout->addWidget(skipButton);
navLayout->addStretch();
navLayout->addWidget(stepIndicator);
navLayout->addStretch();
navLayout->addWidget(nextButton);
auto *root = new QVBoxLayout(this);
root->addLayout(headerLayout);
root->addSpacing(8);
root->addWidget(stack, 1);
root->addSpacing(8);
root->addLayout(navLayout);
auto *welcome = new WelcomePage(this);
auto *cardDb = new CardDatabaseSetupPage(this);
auto *theme = new ThemeSetupPage(this);
auto *account = new AccountSetupPage(this);
auto *prefs = new PreferencesSetupPage(this);
auto *finishPg = new FinishPage(this);
cardDatabasePage = cardDb;
connect(cardDb, &CardDatabaseSetupPage::updateRequested, this, &FirstRunWizard::cardDatabaseUpdateRequested);
connect(cardDb, &CardDatabaseSetupPage::manualSetupRequested, this,
&FirstRunWizard::manualCardDatabaseSetupRequested);
connect(account, &AccountSetupPage::registerRequested, this, &FirstRunWizard::registerRequested);
connect(account, &AccountSetupPage::connectRequested, this, &FirstRunWizard::connectRequested);
connect(cardDb, &CardDatabaseSetupPage::advanceRequested, this, [this] {
if (stack->currentWidget() == cardDatabasePage) {
showPage(currentIndex + 1);
}
});
addPage(welcome);
addPage(cardDb);
addPage(theme);
addPage(account);
addPage(prefs);
addPage(finishPg);
stepIndicator->setStepCount(pages.count());
retranslateUi();
showPage(0);
}
void FirstRunWizard::addPage(FirstRunWizardPage *page)
{
pages.append(page);
stack->addWidget(page);
connect(page, &FirstRunWizardPage::completeChanged, this, &FirstRunWizard::updateChrome);
}
void FirstRunWizard::showPage(int index)
{
if (index < 0 || index >= pages.count()) {
return;
}
currentIndex = index;
stack->setCurrentIndex(index);
pages[index]->initializePage();
stepIndicator->setCurrentStep(index);
static const QList<BannerHost::Motif> motifs = {
BannerHost::Motif::Welcome, BannerHost::Motif::CardDatabase, BannerHost::Motif::Theming,
BannerHost::Motif::Account, BannerHost::Motif::Preferences, BannerHost::Motif::Finish,
};
if (index < motifs.size()) {
bannerHost->setMotif(motifs[index]);
}
titleLabel->setText(pages[index]->stepTitle());
subtitleLabel->setText(pages[index]->stepSubtitle());
subtitleLabel->setVisible(!pages[index]->stepSubtitle().isEmpty());
updateChrome();
}
void FirstRunWizard::updateChrome()
{
if (currentIndex < 0) {
return;
}
FirstRunWizardPage *page = pages[currentIndex];
const bool isLast = (currentIndex == pages.count() - 1);
backButton->setVisible(currentIndex > 0);
skipButton->setVisible(page->isSkippable());
nextButton->setEnabled(page->isComplete());
QString customText = page->nextButtonText();
if (!customText.isEmpty()) {
nextButton->setText(customText);
} else {
nextButton->setText(isLast ? tr("Finish") : tr("Next"));
}
}
void FirstRunWizard::goNext()
{
FirstRunWizardPage *page = pages[currentIndex];
if (!page->validatePage() || !page->handleNextClick()) {
return;
}
if (currentIndex == pages.count() - 1) {
finish();
return;
}
showPage(currentIndex + 1);
}
void FirstRunWizard::goBack()
{
showPage(currentIndex - 1);
}
void FirstRunWizard::skip()
{
showPage(currentIndex + 1);
}
void FirstRunWizard::onCardDatabaseUpdateFinished(bool success)
{
if (cardDatabasePage) {
cardDatabasePage->onUpdateFinished(success);
}
}
void FirstRunWizard::finish()
{
accept();
}
void FirstRunWizard::closeEvent(QCloseEvent *event)
{
// Every step persists its own choice as it's made, so closing early
// isn't destructive -- treat it exactly like reaching the end.
QDialog::closeEvent(event);
}
void FirstRunWizard::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange) {
retranslateUi();
}
QDialog::changeEvent(event);
}
void FirstRunWizard::retranslateUi()
{
setWindowTitle(tr("Welcome to Cockatrice"));
backButton->setText(tr("Back"));
skipButton->setText(tr("Skip"));
for (FirstRunWizardPage *page : std::as_const(pages)) {
page->retranslateUi();
}
if (currentIndex >= 0) {
titleLabel->setText(pages[currentIndex]->stepTitle());
subtitleLabel->setText(pages[currentIndex]->stepSubtitle());
}
updateChrome();
}

View file

@ -0,0 +1,71 @@
#ifndef FIRST_RUN_WIZARD_H
#define FIRST_RUN_WIZARD_H
#include <QDialog>
#include <QList>
class BannerHost;
class FirstRunWizardPage;
class StepIndicatorWidget;
class CardDatabaseSetupPage;
class QLabel;
class QPushButton;
class QStackedWidget;
/** @brief Polished first-run onboarding flow: card database setup, theme
* selection, server account setup, and a handful of key preferences.
*
* Deliberately ignorant of network/registration/download internals --
* pages that need them emit request signals for MainWindow to fulfill.
* Every choice is written to SettingsCache as it's made (via the pages
* themselves, same as AppearanceSettingsPage does), so "Skip" or closing
* the window never discards anything already confirmed. */
class FirstRunWizard : public QDialog
{
Q_OBJECT
public:
explicit FirstRunWizard(QWidget *parent = nullptr);
signals:
void registerRequested();
void connectRequested();
void cardDatabaseUpdateRequested();
void manualCardDatabaseSetupRequested();
public slots:
/** @brief Forwarded from MainWindow once the background card database update process exits. */
void onCardDatabaseUpdateFinished(bool success);
protected:
void closeEvent(QCloseEvent *event) override;
void changeEvent(QEvent *event) override;
private slots:
void goNext();
void goBack();
void skip();
void updateChrome();
private:
void addPage(FirstRunWizardPage *page);
void showPage(int index);
void retranslateUi();
void finish();
QStackedWidget *stack;
StepIndicatorWidget *stepIndicator;
BannerHost *bannerHost;
QLabel *titleLabel;
QLabel *subtitleLabel;
QPushButton *backButton;
QPushButton *skipButton;
QPushButton *nextButton;
CardDatabaseSetupPage *cardDatabasePage = nullptr;
QList<FirstRunWizardPage *> pages;
int currentIndex = -1;
};
#endif // FIRST_RUN_WIZARD_H

View file

@ -0,0 +1 @@
#include "first_run_wizard_page.h"

View file

@ -0,0 +1,75 @@
#ifndef FIRST_RUN_WIZARD_PAGE_H
#define FIRST_RUN_WIZARD_PAGE_H
#include <QWidget>
/** @brief Base class for a single step of FirstRunWizard.
*
* QWidget-based rather than QWizardPage-based: FirstRunWizard is a
* QDialog + QStackedWidget shell (not a QWizard) so it can own the
* banner/step-dot chrome that QWizard's native styles don't give us
* consistent control over. Naming mirrors OracleWizardPage for
* familiarity only -- the two hierarchies are unrelated. */
class FirstRunWizardPage : public QWidget
{
Q_OBJECT
public:
explicit FirstRunWizardPage(QWidget *parent = nullptr) : QWidget(parent)
{
}
/** @brief Called every time the page becomes visible, including navigating back to it. */
virtual void initializePage()
{
}
/** @brief Called before advancing past this page. Return false to block navigation;
the page itself is responsible for telling the user why. */
virtual bool validatePage()
{
return true;
}
/** @brief Whether Next/Finish should currently be enabled. Pages doing async work
can flip this mid-step; emit completeChanged() when they do. */
virtual bool isComplete() const
{
return true;
}
/** @brief Whether the wizard's "Skip" button should be offered on this page. */
virtual bool isSkippable() const
{
return false;
}
virtual QString stepTitle() const = 0;
virtual QString stepSubtitle() const
{
return {};
}
/** @brief Override to replace the "Next"/"Finish" button text on this page.
Return an empty string to use the default label. */
virtual QString nextButtonText() const
{
return {};
}
/** @brief Called when the user presses the Next button. Return true to allow
advancing to the next page, false to stay on this page (e.g. to
trigger an async action first). */
virtual bool handleNextClick()
{
return true;
}
virtual void retranslateUi() = 0;
signals:
void completeChanged();
void advanceRequested();
};
#endif // FIRST_RUN_WIZARD_PAGE_H

View file

@ -0,0 +1,56 @@
#include "account_setup_page.h"
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
AccountSetupPage::AccountSetupPage(QWidget *parent) : FirstRunWizardPage(parent)
{
bodyLabel = new QLabel(this);
bodyLabel->setWordWrap(true);
bodyLabel->setAlignment(Qt::AlignCenter);
registerButton = new QPushButton(this);
connectButton = new QPushButton(this);
skipHintLabel = new QLabel(this);
skipHintLabel->setWordWrap(true);
skipHintLabel->setAlignment(Qt::AlignCenter);
connect(registerButton, &QPushButton::clicked, this, &AccountSetupPage::registerRequested);
connect(connectButton, &QPushButton::clicked, this, &AccountSetupPage::connectRequested);
auto *layout = new QVBoxLayout(this);
layout->addStretch();
layout->addWidget(bodyLabel);
layout->addSpacing(16);
layout->addWidget(registerButton, 0, Qt::AlignHCenter);
layout->addWidget(connectButton, 0, Qt::AlignHCenter);
layout->addSpacing(16);
layout->addWidget(skipHintLabel);
layout->addStretch();
retranslateUi();
}
bool AccountSetupPage::isSkippable() const
{
return true;
}
QString AccountSetupPage::stepTitle() const
{
return tr("Join a Server");
}
QString AccountSetupPage::stepSubtitle() const
{
return tr("Optional — you can always do this later from the menu.");
}
void AccountSetupPage::retranslateUi()
{
bodyLabel->setText(tr("Playing online needs a server account."));
registerButton->setText(tr("Register a new account…"));
connectButton->setText(tr("I already have one — Connect…"));
skipHintLabel->setText(tr("Just want to play locally? Skip this and connect whenever you're ready."));
}

View file

@ -0,0 +1,38 @@
#ifndef ACCOUNT_SETUP_PAGE_H
#define ACCOUNT_SETUP_PAGE_H
#include "../first_run_wizard_page.h"
class QLabel;
class QPushButton;
/** @brief First-run account step. Does NOT embed DlgRegister's fields: they exist
* to be handed to ConnectionController's network registration flow, which
* this wizard has no visibility into. Reimplementing the fields here
* without that wiring would look functional and silently do nothing --
* worse than reuse. So: a friendly landing spot that opens the *existing*
* DlgRegister / connect flow via signals FirstRunWizard forwards. */
class AccountSetupPage : public FirstRunWizardPage
{
Q_OBJECT
public:
explicit AccountSetupPage(QWidget *parent = nullptr);
bool isSkippable() const override;
QString stepTitle() const override;
QString stepSubtitle() const override;
void retranslateUi() override;
signals:
void registerRequested();
void connectRequested();
private:
QLabel *bodyLabel;
QPushButton *registerButton;
QPushButton *connectButton;
QLabel *skipHintLabel;
};
#endif // ACCOUNT_SETUP_PAGE_H

View file

@ -0,0 +1,314 @@
#include "card_database_setup_page.h"
#include "../../client/settings/cache_settings.h"
#include <QComboBox>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QProgressBar>
#include <QPushButton>
#include <QSettings>
#include <QSpinBox>
#include <QTimer>
#include <QUrl>
#include <QVBoxLayout>
#include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/settings/updates_settings.h>
CardDatabaseSetupPage::CardDatabaseSetupPage(QWidget *parent) : FirstRunWizardPage(parent)
{
statusLabel = new QLabel(this);
statusLabel->setWordWrap(true);
statusLabel->setAlignment(Qt::AlignCenter);
progressBar = new QProgressBar(this);
progressBar->setRange(0, 0);
progressBar->setTextVisible(false);
progressBar->setFixedWidth(280);
retryButton = new QPushButton(this);
manualButton = new QPushButton(this);
connect(retryButton, &QPushButton::clicked, this, [this] {
setState(State::Running);
emit updateRequested();
});
connect(manualButton, &QPushButton::clicked, this, &CardDatabaseSetupPage::manualSetupRequested);
// ── Advanced: custom download source ───────────────────────────────
advancedToggleButton = new QPushButton(this);
advancedToggleButton->setCheckable(true);
advancedToggleButton->setChecked(false);
advancedToggleButton->setFlat(true);
advancedToggleButton->setStyleSheet("QPushButton { text-align: left; padding: 5px 12px; font-weight: bold; }"
"QPushButton:checked { }");
advancedPanel = new QWidget(this);
advancedPanel->setVisible(false);
urlLineEdit = new QLineEdit(advancedPanel);
urlHintLabel = new QLabel(advancedPanel);
urlHintLabel->setWordWrap(true);
restoreDefaultUrlButton = new QPushButton(advancedPanel);
applyAndRetryButton = new QPushButton(advancedPanel);
connect(advancedToggleButton, &QPushButton::toggled, this, &CardDatabaseSetupPage::onToggleAdvanced);
connect(restoreDefaultUrlButton, &QPushButton::clicked, this, &CardDatabaseSetupPage::onRestoreDefaultUrl);
connect(applyAndRetryButton, &QPushButton::clicked, this, &CardDatabaseSetupPage::onApplyCustomUrl);
auto *advancedButtonRow = new QHBoxLayout;
advancedButtonRow->addWidget(restoreDefaultUrlButton);
advancedButtonRow->addStretch();
advancedButtonRow->addWidget(applyAndRetryButton);
auto *advancedLayout = new QVBoxLayout(advancedPanel);
advancedLayout->setContentsMargins(12, 4, 12, 4);
advancedLayout->addWidget(urlLineEdit);
advancedLayout->addWidget(urlHintLabel);
advancedLayout->addLayout(advancedButtonRow);
// ── Startup card update check ───────────────────────────────────────
auto &upd = SettingsCache::instance().updates();
const auto updateBehavior = [this] {
auto &u = SettingsCache::instance().updates();
int idx = startupBehaviorCombo->currentIndex();
u.setStartupCardUpdateCheckPromptForUpdate(idx == 1);
u.setStartupCardUpdateCheckAlwaysUpdate(idx == 2);
};
startupBehaviorLabel = new QLabel(this);
startupBehaviorCombo = new QComboBox(this);
startupBehaviorCombo->addItem(QString()); // placeholder, filled in retranslateUi
startupBehaviorCombo->addItem(QString());
startupBehaviorCombo->addItem(QString());
if (upd.getStartupCardUpdateCheckPromptForUpdate()) {
startupBehaviorCombo->setCurrentIndex(1);
} else if (upd.getStartupCardUpdateCheckAlwaysUpdate()) {
startupBehaviorCombo->setCurrentIndex(2);
} else {
startupBehaviorCombo->setCurrentIndex(0);
}
connect(startupBehaviorCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, updateBehavior);
checkIntervalLabel = new QLabel(this);
checkIntervalSpinBox = new QSpinBox(this);
checkIntervalSpinBox->setMinimum(1);
checkIntervalSpinBox->setMaximum(30);
checkIntervalSpinBox->setValue(upd.getCardUpdateCheckInterval());
connect(checkIntervalSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), &upd,
&UpdatesSettings::setCardUpdateCheckInterval);
auto *checkGrid = new QGridLayout;
checkGrid->addWidget(startupBehaviorLabel, 0, 0);
checkGrid->addWidget(startupBehaviorCombo, 0, 1);
checkGrid->addWidget(checkIntervalLabel, 1, 0);
checkGrid->addWidget(checkIntervalSpinBox, 1, 1);
auto *layout = new QVBoxLayout(this);
layout->addStretch();
layout->addWidget(statusLabel);
layout->addSpacing(12);
layout->addWidget(progressBar, 0, Qt::AlignHCenter);
layout->addSpacing(12);
layout->addWidget(retryButton, 0, Qt::AlignHCenter);
layout->addWidget(manualButton, 0, Qt::AlignHCenter);
layout->addSpacing(16);
layout->addWidget(advancedToggleButton);
layout->addWidget(advancedPanel);
layout->addSpacing(8);
layout->addLayout(checkGrid);
layout->addStretch();
retranslateUi();
}
bool CardDatabaseSetupPage::alreadyHaveDatabase() const
{
return CardDatabaseManager::getInstance()->getCardList().count() > 0;
}
QString CardDatabaseSetupPage::oracleSettingsFilePath() const
{
return SettingsCache::instance().getSettingsPath() + "oracle.ini";
}
QString CardDatabaseSetupPage::readCustomUrl() const
{
QSettings oracleSettings(oracleSettingsFilePath(), QSettings::IniFormat);
return oracleSettings.value("allsetsurl").toString();
}
void CardDatabaseSetupPage::writeCustomUrl(const QString &url)
{
QSettings oracleSettings(oracleSettingsFilePath(), QSettings::IniFormat);
if (url.isEmpty()) {
oracleSettings.remove("allsetsurl");
} else {
oracleSettings.setValue("allsetsurl", url);
}
}
void CardDatabaseSetupPage::initializePage()
{
urlLineEdit->setText(readCustomUrl());
if (state != State::NotStarted) {
return;
}
if (alreadyHaveDatabase()) {
setState(State::Succeeded);
return;
}
// Don't auto-download — wait for the user to press "Download".
setState(State::NotStarted);
statusLabel->setText(tr("Press Download to fetch the card database, or Skip to do it later."));
}
void CardDatabaseSetupPage::onUpdateFinished(bool success)
{
setState(success ? State::Succeeded : State::Failed);
if (success) {
emit advanceRequested();
}
}
QString CardDatabaseSetupPage::nextButtonText() const
{
return state == State::NotStarted ? tr("Download") : QString();
}
bool CardDatabaseSetupPage::handleNextClick()
{
if (state == State::NotStarted) {
setState(State::Running);
emit updateRequested();
return false;
}
return true;
}
void CardDatabaseSetupPage::onToggleAdvanced(bool open)
{
advancedToggleButton->setText(open ? tr("▼ Advanced: custom download source")
: tr("▶ Advanced: custom download source"));
advancedPanel->setVisible(open);
QWidget *wizardWindow = window();
if (!wizardWindow) {
return;
}
if (open) {
windowSizeBeforeExpansion = wizardWindow->size();
QTimer::singleShot(0, this, [wizardWindow] {
wizardWindow->resize(wizardWindow->size().expandedTo(wizardWindow->sizeHint()));
});
} else {
QTimer::singleShot(0, this, [this, wizardWindow] {
wizardWindow->resize(wizardWindow->size().boundedTo(windowSizeBeforeExpansion));
});
}
}
void CardDatabaseSetupPage::onApplyCustomUrl()
{
const QString text = urlLineEdit->text().trimmed();
if (!text.isEmpty()) {
const QUrl url = QUrl::fromUserInput(text);
if (!url.isValid()) {
QMessageBox::warning(this, tr("Invalid URL"),
tr("That doesn't look like a valid URL. Double-check it and try again, "
"or clear the field to use the default source."));
return;
}
}
writeCustomUrl(text);
setState(State::Running);
emit updateRequested();
}
void CardDatabaseSetupPage::onRestoreDefaultUrl()
{
urlLineEdit->clear();
writeCustomUrl(QString());
}
void CardDatabaseSetupPage::setState(State newState)
{
state = newState;
progressBar->setVisible(state == State::Running);
retryButton->setVisible(state == State::Failed);
manualButton->setVisible(state == State::Failed);
applyAndRetryButton->setEnabled(state != State::Running);
switch (state) {
case State::NotStarted:
statusLabel->setText(tr("Press Download to fetch the card database, or Skip to do it later."));
break;
case State::Running:
statusLabel->setText(tr("Downloading the latest card database…"));
break;
case State::Succeeded:
statusLabel->setText(tr("Card database ready ✓"));
break;
case State::Failed:
statusLabel->setText(
tr("Couldn't download the card database automatically. Check your connection and retry, "
"set it up manually, or skip this for now — you can do it later from the Card Database menu."));
break;
}
emit completeChanged();
}
bool CardDatabaseSetupPage::isComplete() const
{
return state != State::Running;
}
bool CardDatabaseSetupPage::isSkippable() const
{
return state != State::Succeeded;
}
QString CardDatabaseSetupPage::stepTitle() const
{
return tr("Card Database");
}
QString CardDatabaseSetupPage::stepSubtitle() const
{
return tr("Cockatrice needs card data to know what you're playing with.");
}
void CardDatabaseSetupPage::retranslateUi()
{
retryButton->setText(tr("Retry"));
manualButton->setText(tr("Set up manually…"));
onToggleAdvanced(advancedToggleButton->isChecked());
urlLineEdit->setPlaceholderText(tr("Leave blank to use the default source"));
urlHintLabel->setText(tr("Only change this if you know you need a mirror or a custom card data source."));
restoreDefaultUrlButton->setText(tr("Restore default"));
applyAndRetryButton->setText(tr("Apply && retry"));
startupBehaviorLabel->setText(tr("Check for card database updates on startup"));
startupBehaviorCombo->setItemText(0, tr("Don't check"));
startupBehaviorCombo->setItemText(1, tr("Prompt for update"));
startupBehaviorCombo->setItemText(2, tr("Always update in the background"));
checkIntervalLabel->setText(tr("Check for card database updates every"));
checkIntervalSpinBox->setSuffix(tr(" days"));
setState(state);
}

View file

@ -0,0 +1,79 @@
#ifndef CARD_DATABASE_SETUP_PAGE_H
#define CARD_DATABASE_SETUP_PAGE_H
#include "../first_run_wizard_page.h"
#include <QSize>
class QComboBox;
class QLabel;
class QLineEdit;
class QProgressBar;
class QPushButton;
class QSpinBox;
class QWidget;
class CardDatabaseSetupPage : public FirstRunWizardPage
{
Q_OBJECT
public:
explicit CardDatabaseSetupPage(QWidget *parent = nullptr);
void initializePage() override;
bool isComplete() const override;
bool isSkippable() const override;
QString stepTitle() const override;
QString stepSubtitle() const override;
QString nextButtonText() const override;
bool handleNextClick() override;
void retranslateUi() override;
void onUpdateFinished(bool success);
signals:
void updateRequested();
void manualSetupRequested();
private:
enum class State
{
NotStarted,
Running,
Succeeded,
Failed,
};
void setState(State newState);
bool alreadyHaveDatabase() const;
QString oracleSettingsFilePath() const;
QString readCustomUrl() const;
void writeCustomUrl(const QString &url);
void onToggleAdvanced(bool open);
void onApplyCustomUrl();
void onRestoreDefaultUrl();
QLabel *statusLabel;
QProgressBar *progressBar;
QPushButton *retryButton;
QPushButton *manualButton;
QPushButton *advancedToggleButton;
QWidget *advancedPanel;
QLineEdit *urlLineEdit;
QLabel *urlHintLabel;
QPushButton *restoreDefaultUrlButton;
QPushButton *applyAndRetryButton;
QLabel *startupBehaviorLabel;
QComboBox *startupBehaviorCombo;
QLabel *checkIntervalLabel;
QSpinBox *checkIntervalSpinBox;
State state = State::NotStarted;
QSize windowSizeBeforeExpansion;
};
#endif // CARD_DATABASE_SETUP_PAGE_H

View file

@ -0,0 +1,30 @@
#include "finish_page.h"
#include <QLabel>
#include <QVBoxLayout>
FinishPage::FinishPage(QWidget *parent) : FirstRunWizardPage(parent)
{
bodyLabel = new QLabel(this);
bodyLabel->setWordWrap(true);
bodyLabel->setAlignment(Qt::AlignCenter);
auto *layout = new QVBoxLayout(this);
layout->addStretch();
layout->addWidget(bodyLabel);
layout->addStretch();
retranslateUi();
}
QString FinishPage::stepTitle() const
{
return tr("You're All Set");
}
void FinishPage::retranslateUi()
{
bodyLabel->setText(
tr("That's everything for now. Jump into Settings any time to change your mind about any of this.\n\n"
"Have fun!"));
}

View file

@ -0,0 +1,22 @@
#ifndef FINISH_PAGE_H
#define FINISH_PAGE_H
#include "../first_run_wizard_page.h"
class QLabel;
class FinishPage : public FirstRunWizardPage
{
Q_OBJECT
public:
explicit FinishPage(QWidget *parent = nullptr);
QString stepTitle() const override;
void retranslateUi() override;
private:
QLabel *bodyLabel;
};
#endif // FINISH_PAGE_H

View file

@ -0,0 +1,173 @@
#include "preferences_setup_page.h"
#include "../../client/settings/cache_settings.h"
#include "../../client/sound_engine.h"
#include "libcockatrice/settings/interface_settings.h"
#include "libcockatrice/settings/sound_settings.h"
#include "libcockatrice/settings/tabs_settings.h"
#include <QCheckBox>
#include <QComboBox>
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
#include <QScrollArea>
#include <QVBoxLayout>
namespace
{
// The server destinations are omitted: during first run their tabs are not
// open yet, and the wizard offers no way to fill in the server/room details.
QList<StartupTab> wizardStartupTabOrder()
{
return {StartupTabHome, StartupTabVisualDeckStorage, StartupTabDeckStorage,
StartupTabReplays, StartupTabDeckEditor, StartupTabVisualDeckEditor};
}
} // namespace
PreferencesSetupPage::PreferencesSetupPage(QWidget *parent) : FirstRunWizardPage(parent)
{
auto *content = new QWidget;
auto *contentLayout = new QVBoxLayout(content);
gameplayGroup = new QGroupBox(content);
auto *gameplayLayout = new QVBoxLayout(gameplayGroup);
contentLayout->addWidget(gameplayGroup);
doubleClickToPlayCheckBox = new QCheckBox(gameplayGroup);
horizontalHandCheckBox = new QCheckBox(gameplayGroup);
playToStackCheckBox = new QCheckBox(gameplayGroup);
gameplayLayout->addWidget(doubleClickToPlayCheckBox);
gameplayLayout->addWidget(horizontalHandCheckBox);
gameplayLayout->addWidget(playToStackCheckBox);
notificationsGroup = new QGroupBox(content);
auto *notificationsLayout = new QVBoxLayout(notificationsGroup);
contentLayout->addWidget(notificationsGroup);
notificationsEnabledCheckBox = new QCheckBox(notificationsGroup);
soundEnabledCheckBox = new QCheckBox(notificationsGroup);
notificationsLayout->addWidget(notificationsEnabledCheckBox);
notificationsLayout->addWidget(soundEnabledCheckBox);
startupGroup = new QGroupBox(content);
auto *startupForm = new QFormLayout(startupGroup);
contentLayout->addWidget(startupGroup);
startupTabLabel = new QLabel(startupGroup);
startupTabSelector = new QComboBox(startupGroup);
startupTabSelector->setSizeAdjustPolicy(QComboBox::AdjustToContents);
for (StartupTab tab : wizardStartupTabOrder()) {
startupTabSelector->addItem(QString(), tab); // texts set in retranslateUi
}
startupForm->addRow(startupTabLabel, startupTabSelector);
contentLayout->addStretch();
auto *scrollArea = new QScrollArea(this);
scrollArea->setWidget(content);
scrollArea->setWidgetResizable(true);
scrollArea->setFrameShape(QFrame::NoFrame);
auto *layout = new QVBoxLayout(this);
layout->addWidget(scrollArea);
SettingsCache &settings = SettingsCache::instance();
connect(doubleClickToPlayCheckBox, &QCheckBox::toggled, &settings.userInterface(),
&InterfaceSettings::setDoubleClickToPlay);
connect(horizontalHandCheckBox, &QCheckBox::toggled, &settings.userInterface(),
&InterfaceSettings::setHorizontalHand);
connect(playToStackCheckBox, &QCheckBox::toggled, &settings.userInterface(), &InterfaceSettings::setPlayToStack);
connect(notificationsEnabledCheckBox, &QCheckBox::toggled, &settings.userInterface(),
&InterfaceSettings::setNotificationsEnabled);
connect(soundEnabledCheckBox, &QCheckBox::toggled, &settings.sound(), &SoundSettings::setSoundEnabled);
connect(soundEnabledCheckBox, &QCheckBox::toggled, soundEngine, &SoundEngine::testSound);
connect(startupTabSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index) {
if (index < 0) {
return;
}
SettingsCache::instance().tabs().setStartupTabIndex(startupTabSelector->itemData(index).toInt());
});
retranslateUi();
}
void PreferencesSetupPage::initializePage()
{
SettingsCache &settings = SettingsCache::instance();
doubleClickToPlayCheckBox->setChecked(settings.userInterface().getDoubleClickToPlay());
horizontalHandCheckBox->setChecked(settings.userInterface().getHorizontalHand());
playToStackCheckBox->setChecked(settings.userInterface().getPlayToStack());
notificationsEnabledCheckBox->setChecked(settings.userInterface().getNotificationsEnabled());
soundEnabledCheckBox->setChecked(settings.sound().getSoundEnabled());
startupTabSelector->setCurrentIndex(startupTabSelector->findData(settings.tabs().getStartupTabIndex()));
}
bool PreferencesSetupPage::isSkippable() const
{
return true;
}
QString PreferencesSetupPage::stepTitle() const
{
return tr("A Few Preferences");
}
QString PreferencesSetupPage::stepSubtitle() const
{
return tr("Defaults are fine — tweak these now or from Settings anytime.");
}
void PreferencesSetupPage::retranslateUi()
{
gameplayGroup->setTitle(tr("Gameplay"));
doubleClickToPlayCheckBox->setText(tr("Double-click cards to play them"));
doubleClickToPlayCheckBox->setToolTip(tr("When disabled, a single click plays the selected card onto the table."));
horizontalHandCheckBox->setText(tr("Display hand horizontally"));
horizontalHandCheckBox->setToolTip(
tr("Shows your hand as a row along the bottom of the table instead of a column beside it."));
playToStackCheckBox->setText(tr("Play all nonlands onto the stack by default"));
playToStackCheckBox->setToolTip(
tr("Cards you play appear on the stack so other players can respond to them, as in a tabletop game."));
notificationsGroup->setTitle(tr("Notifications && Sound"));
notificationsEnabledCheckBox->setText(tr("Show desktop notifications"));
soundEnabledCheckBox->setText(tr("Play sound effects"));
startupGroup->setTitle(tr("Startup"));
startupTabLabel->setText(tr("Startup tab:"));
const QList<StartupTab> tabs = wizardStartupTabOrder();
for (int i = 0; i < tabs.size(); ++i) {
QString name;
switch (tabs[i]) {
case StartupTabHome:
name = tr("Home");
break;
case StartupTabVisualDeckStorage:
name = tr("Visual Deck Storage");
break;
case StartupTabDeckStorage:
name = tr("Deck Storage");
break;
case StartupTabReplays:
name = tr("Game Replays");
break;
case StartupTabDeckEditor:
name = tr("Deck Editor");
break;
case StartupTabVisualDeckEditor:
name = tr("Visual Deck Editor");
break;
case StartupTabServer:
name = tr("Server");
break;
case StartupTabServerRoom:
name = tr("Server Room");
break;
}
startupTabSelector->setItemText(i, name);
}
}

View file

@ -0,0 +1,41 @@
#ifndef PREFERENCES_SETUP_PAGE_H
#define PREFERENCES_SETUP_PAGE_H
#include "../first_run_wizard_page.h"
class QCheckBox;
class QComboBox;
class QGroupBox;
class QLabel;
/** @brief A curated subset of settings for the user to adjust.
**/
class PreferencesSetupPage : public FirstRunWizardPage
{
Q_OBJECT
public:
explicit PreferencesSetupPage(QWidget *parent = nullptr);
void initializePage() override;
bool isSkippable() const override;
QString stepTitle() const override;
QString stepSubtitle() const override;
void retranslateUi() override;
private:
QGroupBox *gameplayGroup;
QCheckBox *doubleClickToPlayCheckBox;
QCheckBox *horizontalHandCheckBox;
QCheckBox *playToStackCheckBox;
QGroupBox *notificationsGroup;
QCheckBox *notificationsEnabledCheckBox;
QCheckBox *soundEnabledCheckBox;
QGroupBox *startupGroup;
QLabel *startupTabLabel;
QComboBox *startupTabSelector;
};
#endif // PREFERENCES_SETUP_PAGE_H

View file

@ -0,0 +1,231 @@
#include "theme_setup_page.h"
#include "../../client/settings/cache_settings.h"
#include "../../interface/palette_editor/palette_generator.h"
#include "../../interface/palette_editor/quick_setup_panel.h"
#include "../../interface/theme_manager.h"
#include "../../interface/widgets/general/background_sources.h"
#include "libcockatrice/settings/appearance_settings.h"
#include <QComboBox>
#include <QDir>
#include <QFile>
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
#include <QMessageBox>
#include <QVBoxLayout>
#include <libcockatrice/settings/paths_settings.h>
#include <libcockatrice/settings/personal_settings.h>
ThemeSetupPage::ThemeSetupPage(QWidget *parent) : FirstRunWizardPage(parent)
{
themeCombo = new QComboBox(this);
schemeCombo = new QComboBox(this);
schemeCombo->addItem(tr("Light"), QStringLiteral("Light"));
schemeCombo->addItem(tr("Dark"), QStringLiteral("Dark"));
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
schemeCombo->addItem(tr("Match system"), QStringLiteral("System"));
#endif
quickSetupPanel = new QuickSetupPanel(this);
connect(themeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeSetupPage::onThemeChanged);
connect(schemeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeSetupPage::onSchemeChanged);
connect(quickSetupPanel, &QuickSetupPanel::valueChanged, this, &ThemeSetupPage::onGenerateFromAccent);
homeTabBackgroundCombo = new QComboBox(this);
for (const auto &entry : BackgroundSources::all()) {
homeTabBackgroundCombo->addItem(QObject::tr(entry.trKey), QVariant::fromValue(entry.type));
}
connect(homeTabBackgroundCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ThemeSetupPage::onHomeTabBackgroundChanged);
// Keep the scheme combo honest when the *theme* changes underneath it
// (switching theme reloads that theme's own stored colorScheme), and
// opportunistically seed a palette for themes that ship none at all.
// Mirrors AppearanceSettingsPage's identical listener for the combo-sync
// half of this.
connect(themeManager, &ThemeManager::themeChanged, this, [this] {
const QString newDir = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
const ThemeConfig cfg = ThemeConfig::fromThemeDir(newDir);
const QString current = cfg.colorScheme;
schemeCombo->blockSignals(true);
const int idx = schemeCombo->findData(current);
schemeCombo->setCurrentIndex(idx >= 0 ? idx : 0);
schemeCombo->blockSignals(false);
maybeAutoGeneratePalette();
});
auto *form = new QFormLayout;
form->addRow(tr("Theme:"), themeCombo);
form->addRow(tr("Appearance:"), schemeCombo);
form->addRow(tr("Home screen background:"), homeTabBackgroundCombo);
accentGroup = new QGroupBox(this);
auto *accentLayout = new QVBoxLayout(accentGroup);
accentLayout->addWidget(quickSetupPanel);
auto *layout = new QVBoxLayout(this);
layout->addLayout(form);
layout->addWidget(accentGroup);
layout->addStretch();
retranslateUi();
}
void ThemeSetupPage::initializePage()
{
themeCombo->blockSignals(true);
themeCombo->clear();
const QString currentTheme = SettingsCache::instance().getThemeName();
for (const QString &name : themeManager->getAvailableThemes().keys()) {
themeCombo->addItem(name);
}
const int idx = themeCombo->findText(currentTheme);
themeCombo->setCurrentIndex(idx >= 0 ? idx : 0);
themeCombo->blockSignals(false);
const QString dirPath = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
const ThemeConfig cfg = ThemeConfig::fromThemeDir(dirPath);
schemeCombo->blockSignals(true);
const int schemeIdx = schemeCombo->findData(cfg.colorScheme);
schemeCombo->setCurrentIndex(schemeIdx >= 0 ? schemeIdx : 0);
schemeCombo->blockSignals(false);
homeTabBackgroundCombo->blockSignals(true);
QString homeTabSource = SettingsCache::instance().appearance().getHomeTabBackgroundSource();
int homeTabIdx = homeTabBackgroundCombo->findData(BackgroundSources::fromId(homeTabSource));
homeTabBackgroundCombo->setCurrentIndex(homeTabIdx >= 0 ? homeTabIdx : 0);
homeTabBackgroundCombo->blockSignals(false);
// Opening the page must not touch the running application's palette:
// previews and auto-generation only happen in response to the user
// actually changing a control, never on mere page visibility.
paletteDirty = false;
}
QString ThemeSetupPage::currentScheme() const
{
return schemeCombo->currentData().toString();
}
QString ThemeSetupPage::resolvedScheme() const
{
const QString scheme = currentScheme();
if (scheme.isEmpty() || scheme == QStringLiteral("System")) {
return themeManager->isDarkMode(themeManager->getCurrentThemePath()) ? "Dark" : "Light";
}
return scheme;
}
void ThemeSetupPage::onThemeChanged(int index)
{
if (index < 0) {
return;
}
paletteDirty = false;
SettingsCache::instance().setThemeName(themeCombo->itemText(index));
// Scheme-combo sync and auto-generation both happen via the
// ThemeManager::themeChanged listener above, triggered by setThemeName.
}
void ThemeSetupPage::onSchemeChanged()
{
themeManager->setColorScheme(currentScheme());
}
void ThemeSetupPage::onHomeTabBackgroundChanged(int index)
{
if (index < 0) {
return;
}
auto type = homeTabBackgroundCombo->currentData().value<BackgroundSources::Type>();
SettingsCache::instance().appearance().setHomeTabBackgroundSource(BackgroundSources::toId(type));
}
void ThemeSetupPage::onGenerateFromAccent(const QColor &accent, int intensity)
{
PaletteConfig cfg = PaletteGenerator::fromAccent(accent, intensity, resolvedScheme());
themeManager->previewPalette(cfg, resolvedScheme());
paletteDirty = true;
}
void ThemeSetupPage::maybeAutoGeneratePalette()
{
const QString dirPath = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
const QString scheme = resolvedScheme();
if (PaletteConfig::fromScheme(dirPath, scheme).hasPalette() ||
PaletteConfig::fromDefault(dirPath, scheme).hasPalette()) {
return; // theme already has something real to show -- leave it alone
}
// The theme+scheme combination has nothing saved and nothing shipped, and
// the user just switched to it. Rather than leaving a flat, unstyled look,
// seed one from whatever accent QuickSetupPanel currently holds and mark
// it dirty so it's written to disk if the user moves on. Only ever reached
// through user interaction (theme/scheme change, accent drag) -- never on
// page open.
PaletteConfig generated =
PaletteGenerator::fromAccent(quickSetupPanel->accentColor(), quickSetupPanel->intensity(), scheme);
themeManager->previewPalette(generated, scheme);
paletteDirty = true;
}
bool ThemeSetupPage::validatePage()
{
if (paletteDirty) {
const QString scheme = resolvedScheme();
PaletteConfig cfg =
PaletteGenerator::fromAccent(quickSetupPanel->accentColor(), quickSetupPanel->intensity(), scheme);
if (!ThemeManager::commitPalette(writableThemeDir(), scheme, cfg)) {
QMessageBox::warning(this, tr("Save failed"),
tr("Could not write the theme palette to:\n%1").arg(writableThemeDir()));
return false;
}
themeManager->reloadCurrentTheme();
}
return true;
}
QString ThemeSetupPage::writableThemeDir() const
{
// Built-in themes resolve to the read-only system themes directory;
// palette edits must go to the user themes directory instead, exactly
// as PaletteEditorDialog does.
const QString dirPath = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
if (!dirPath.isEmpty()) {
const QString probe = QDir(dirPath).absoluteFilePath(".cockatrice_write_test");
QFile f(probe);
if (f.open(QIODevice::WriteOnly)) {
f.close();
f.remove();
return dirPath;
}
}
return QDir(SettingsCache::instance().paths().getThemesPath())
.absoluteFilePath(SettingsCache::instance().getThemeName());
}
bool ThemeSetupPage::isSkippable() const
{
return true;
}
QString ThemeSetupPage::stepTitle() const
{
return tr("Pick a Look");
}
QString ThemeSetupPage::stepSubtitle() const
{
return tr("You can fine-tune every colour later from Settings → Appearance.");
}
void ThemeSetupPage::retranslateUi()
{
accentGroup->setTitle(tr("Accent colour (optional)"));
}

View file

@ -0,0 +1,58 @@
#ifndef THEME_SETUP_PAGE_H
#define THEME_SETUP_PAGE_H
#include "../first_run_wizard_page.h"
class QComboBox;
class QGroupBox;
class QuickSetupPanel;
/** @brief First-run theme step. Reuses the same building blocks as Appearance
* settings and the Palette Editor (ThemeManager, PaletteConfig,
* PaletteGenerator, and the QuickSetupPanel widget itself) rather than
* reimplementing palette generation or preview here.
*
* Behavior specific to this page (deliberately not pushed down into
* ThemeManager, to avoid changing app-wide behaviour for existing installs):
* - Opening the page never changes the running palette; previews and
* auto-generation only happen when the user actually changes a control.
* - If a theme+scheme the user selects has no saved palette and no shipped
* default, one is generated from the QuickSetupPanel's current accent so
* the preview doesn't fall back to a flat, unstyled look. */
class ThemeSetupPage : public FirstRunWizardPage
{
Q_OBJECT
public:
explicit ThemeSetupPage(QWidget *parent = nullptr);
void initializePage() override;
bool validatePage() override;
bool isSkippable() const override;
QString stepTitle() const override;
QString stepSubtitle() const override;
void retranslateUi() override;
private slots:
void onThemeChanged(int index);
void onSchemeChanged();
void onGenerateFromAccent(const QColor &accent, int intensity);
void onHomeTabBackgroundChanged(int index);
private:
QString currentScheme() const;
QString resolvedScheme() const; // "System" -> actual Light/Dark
void maybeAutoGeneratePalette();
QString writableThemeDir() const;
QComboBox *themeCombo;
QComboBox *schemeCombo;
QGroupBox *accentGroup;
QuickSetupPanel *quickSetupPanel;
QComboBox *homeTabBackgroundCombo;
bool paletteDirty = false;
};
#endif // THEME_SETUP_PAGE_H

View file

@ -0,0 +1,79 @@
#include "welcome_page.h"
#include "../../../../main.h"
#include "../../client/settings/cache_settings.h"
#include "../../settings_page/general_settings_page.h"
#include "libcockatrice/settings/personal_settings.h"
#include <QApplication>
#include <QComboBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLocale>
#include <QTranslator>
#include <QVBoxLayout>
WelcomePage::WelcomePage(QWidget *parent) : FirstRunWizardPage(parent)
{
bodyLabel = new QLabel(this);
bodyLabel->setWordWrap(true);
bodyLabel->setAlignment(Qt::AlignCenter);
languageLabel = new QLabel(this);
langCombo = new QComboBox(this);
for (const QString &code : GeneralSettingsPage::findQmFiles()) {
langCombo->addItem(GeneralSettingsPage::languageName(code), code);
}
QString current = SettingsCache::instance().personal().getLang();
if (current.isEmpty()) {
current = QLocale::system().name();
}
int index = langCombo->findData(current);
if (index < 0) {
index = langCombo->findData(current.section('_', 0, 0));
}
if (index >= 0) {
langCombo->setCurrentIndex(index);
}
connect(langCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &WelcomePage::languageChanged);
auto *languageRow = new QHBoxLayout;
languageRow->addStretch();
languageRow->addWidget(languageLabel);
languageRow->addWidget(langCombo);
languageRow->addStretch();
auto *layout = new QVBoxLayout(this);
layout->addStretch();
layout->addWidget(bodyLabel);
layout->addStretch();
layout->addLayout(languageRow);
retranslateUi();
}
void WelcomePage::languageChanged(int index)
{
if (index < 0) {
return;
}
SettingsCache::instance().personal().setLang(langCombo->itemData(index).toString());
qApp->removeTranslator(translator); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
installNewTranslator();
}
QString WelcomePage::stepTitle() const
{
return tr("Welcome!");
}
void WelcomePage::retranslateUi()
{
bodyLabel->setText(tr("Let's get you set up. This will only take a minute — "
"we'll grab the card database, pick a look you like, "
"and get you ready to connect to a server.\n\n"
"You can change any of this later from Settings."));
languageLabel->setText(tr("Language:"));
}

View file

@ -0,0 +1,28 @@
#ifndef WELCOME_PAGE_H
#define WELCOME_PAGE_H
#include "../first_run_wizard_page.h"
class QComboBox;
class QLabel;
class WelcomePage : public FirstRunWizardPage
{
Q_OBJECT
public:
explicit WelcomePage(QWidget *parent = nullptr);
QString stepTitle() const override;
void retranslateUi() override;
private slots:
void languageChanged(int index);
private:
QLabel *bodyLabel;
QLabel *languageLabel;
QComboBox *langCombo;
};
#endif // WELCOME_PAGE_H

View file

@ -0,0 +1,62 @@
import QtQuick
Item {
id: root
ShaderEffect {
id: effectA
anchors.fill: parent
opacity: bannerConfig.frontIsA ? 1.0 : 0.0
Behavior on opacity { NumberAnimation { duration: 450; easing.type: Easing.InOutCubic } }
property real iTime: bannerConfig.time
property real uAspect: bannerConfig.aspect
property real uMode: bannerConfig.modeA
property real uSpeed: bannerConfig.speedA
property real uSeed: bannerConfig.seedA
property vector4d uColorA: Qt.vector4d(bannerConfig.colorA.r, bannerConfig.colorA.g, bannerConfig.colorA.b, 1.0)
property vector4d uColorB: Qt.vector4d(bannerConfig.colorB.r, bannerConfig.colorB.g, bannerConfig.colorB.b, 1.0)
property vector4d uAccent: Qt.vector4d(bannerConfig.accent.r, bannerConfig.accent.g, bannerConfig.accent.b, 1.0)
property real uLogoGlow: bannerConfig.logoGlow
fragmentShader: "qrc:/onboarding/shaders/brand_banner.frag.qsb"
}
ShaderEffect {
id: effectB
anchors.fill: parent
opacity: bannerConfig.frontIsA ? 0.0 : 1.0
Behavior on opacity { NumberAnimation { duration: 450; easing.type: Easing.InOutCubic } }
property real iTime: bannerConfig.time
property real uAspect: bannerConfig.aspect
property real uMode: bannerConfig.modeB
property real uSpeed: bannerConfig.speedB
property real uSeed: bannerConfig.seedB
property vector4d uColorA: Qt.vector4d(bannerConfig.colorA.r, bannerConfig.colorA.g, bannerConfig.colorA.b, 1.0)
property vector4d uColorB: Qt.vector4d(bannerConfig.colorB.r, bannerConfig.colorB.g, bannerConfig.colorB.b, 1.0)
property vector4d uAccent: Qt.vector4d(bannerConfig.accent.r, bannerConfig.accent.g, bannerConfig.accent.b, 1.0)
property real uLogoGlow: bannerConfig.logoGlow
fragmentShader: "qrc:/onboarding/shaders/brand_banner.frag.qsb"
}
// The hero logo itself — breathes cleanly over a 0.5–1.0 opacity range
Image {
id: logo
anchors.centerIn: parent
visible: bannerConfig.logoVisible
source: "qrc:/resources/cockatrice-logo-white.svg"
width: root.height * 0.6
height: width * (sourceSize.height > 0 ? sourceSize.height / Math.max(sourceSize.width, 1) : 1)
fillMode: Image.PreserveAspectFit
smooth: true
opacity: 0.5 + 0.5 * bannerConfig.logoGlow
sourceSize: Qt.size(256, 256)
Behavior on opacity { NumberAnimation { duration: 300; easing.type: Easing.InOutSine } }
transform: Scale {
origin.x: logo.width / 2
origin.y: logo.height / 2
xScale: 0.94 + 0.06 * bannerConfig.logoGlow
yScale: 0.94 + 0.06 * bannerConfig.logoGlow
}
}
}

View file

@ -0,0 +1,195 @@
#include "shader_banner_widget.h"
#include "banner_shader_config.h"
#include <QPainter>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickWidget>
#include <QResizeEvent>
#include <QStackedLayout>
namespace
{
// Near-black base palette -- the background is dark and quiet so the green
// accent stands out.
constexpr QRgb kColorA = 0x1A1A20;
constexpr QRgb kColorB = 0x0E0E12;
constexpr QRgb kAccent = 0x8BDD6B;
} // namespace
class GradientFallbackWidget : public QWidget
{
public:
using QWidget::QWidget;
protected:
void paintEvent(QPaintEvent *) override
{
QPainter painter(this);
QLinearGradient gradient(0, 0, width(), height());
gradient.setColorAt(0.0, QColor(kColorA));
gradient.setColorAt(1.0, QColor(kColorB));
painter.fillRect(rect(), gradient);
}
};
BannerHost::BannerHost(QWidget *parent) : QWidget(parent)
{
setFixedHeight(150);
stack = new QStackedLayout(this);
stack->setContentsMargins(0, 0, 0, 0);
fallback = new GradientFallbackWidget(this);
stack->addWidget(fallback);
quickWidget = new QQuickWidget(this);
quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
config = new BannerShaderConfig(quickWidget->engine());
quickWidget->rootContext()->setContextProperty("bannerConfig", config);
quickWidget->setSource(QUrl("qrc:/onboarding/qml/BrandBanner.qml"));
if (quickWidget->status() == QQuickWidget::Error) {
activateFallback();
} else {
connect(quickWidget, &QQuickWidget::sceneGraphError, this, &BannerHost::onSceneGraphFailed);
stack->addWidget(quickWidget);
stack->setCurrentWidget(quickWidget);
}
connect(&clock, &QTimer::timeout, this, &BannerHost::tick);
clock.setInterval(16); // ~60fps; the shader itself is cheap, this is just a wall clock
applyMotifPreset(currentMotif);
updateAspect();
}
void BannerHost::activateFallback()
{
if (usingFallback) {
return;
}
usingFallback = true;
clock.stop();
stack->setCurrentWidget(fallback);
if (quickWidget) {
quickWidget->deleteLater(); // takes BannerShaderConfig (parented to its engine) with it
quickWidget = nullptr;
config = nullptr;
}
}
void BannerHost::onSceneGraphFailed()
{
activateFallback();
}
void BannerHost::setMotif(Motif motif)
{
currentMotif = motif;
applyMotifPreset(motif);
}
BannerHost::Preset BannerHost::presetFor(Motif motif)
{
// speed/seed tuned per motif so e.g. the network "pulse" (Account) reads
// at a deliberately calmer cadence than the data "scan" lines
// (Preferences), even though both come from the same shader.
switch (motif) {
case Motif::Welcome:
return {0.0, 0.6, 0.15};
case Motif::CardDatabase:
return {1.0, 1.3, 0.42};
case Motif::Theming:
return {2.0, 1.2, 0.73};
case Motif::Account:
return {3.0, 0.8, 0.28};
case Motif::Preferences:
return {4.0, 1.0, 0.61};
case Motif::Finish:
return {5.0, 1.0, 0.91};
}
return {0.0, 0.6, 0.15};
}
void BannerHost::applyMotifPreset(Motif motif)
{
if (usingFallback || !config) {
return;
}
const Preset p = presetFor(motif);
config->setColorA(QColor(kColorA));
config->setColorB(QColor(kColorB));
config->setAccent(QColor(kAccent));
config->setLogoVisible(motif == Motif::Welcome);
if (isFirstApply) {
// Nothing on screen yet -- write straight into the front bank, no
// crossfade needed for the very first paint.
config->setModeA(p.mode);
config->setSpeedA(p.speed);
config->setSeedA(p.seed);
config->setFrontIsA(true);
isFirstApply = false;
return;
}
// Write the new preset into whichever bank is currently hidden, then
// flip which one is front. QML's opacity Behavior does the actual
// crossfade -- BannerHost never animates anything itself.
if (config->frontIsA()) {
config->setModeB(p.mode);
config->setSpeedB(p.speed);
config->setSeedB(p.seed);
config->setFrontIsA(false);
} else {
config->setModeA(p.mode);
config->setSpeedA(p.speed);
config->setSeedA(p.seed);
config->setFrontIsA(true);
}
}
void BannerHost::updateAspect()
{
if (config && height() > 0) {
config->setAspect(qreal(width()) / qreal(height()));
}
}
void BannerHost::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
updateAspect();
}
void BannerHost::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
if (!usingFallback) {
elapsed.restart();
clock.start();
}
}
void BannerHost::hideEvent(QHideEvent *event)
{
QWidget::hideEvent(event);
clock.stop();
}
void BannerHost::tick()
{
if (config) {
qreal t = elapsed.elapsed() / 1000.0;
config->setTime(t);
// Visible breathing for the logo: oscillates between 0.0 and 1.0
qreal glow = 0.5 + 0.5 * qSin(t * 0.4);
config->setLogoGlow(glow);
}
}

View file

@ -0,0 +1,83 @@
#ifndef SHADER_BANNER_WIDGET_H
#define SHADER_BANNER_WIDGET_H
#include <QElapsedTimer>
#include <QTimer>
#include <QWidget>
class BannerShaderConfig;
class QQuickWidget;
class GradientFallbackWidget;
class QStackedLayout;
/** @brief Onboarding banner: a subtle, looping brand-shader animation, one of six
* per-page "motifs" driving the same prebaked fragment shader
* (onboarding/shaders/brand_banner.frag) with different uniform values, so
* every page feels distinct but unmistakably part of the same family.
*
* Motif switches crossfade smoothly (see BrandBanner.qml's two stacked
* ShaderEffect layers + Behavior on opacity) rather than cutting instantly
* -- BannerHost just writes the new preset into whichever layer is
* currently hidden and flips BannerShaderConfig::frontIsA; QML handles the
* actual animation declaratively.
*
* Falls back to a static two-stop gradient (no shader, no QQuickWidget) if
* the platform's Qt Quick scenegraph can't initialize -- e.g. software
* rendering only, or a CI/VM environment with no GPU -- so onboarding
* never blocks or blanks out over a graphics driver problem. The fallback
* is permanent for the lifetime of this widget once triggered. */
class BannerHost : public QWidget
{
Q_OBJECT
public:
enum class Motif
{
Welcome,
CardDatabase,
Theming,
Account,
Preferences,
Finish,
};
explicit BannerHost(QWidget *parent = nullptr);
void setMotif(Motif motif);
protected:
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private slots:
void tick();
void onSceneGraphFailed();
private:
struct Preset
{
qreal mode;
qreal speed;
qreal seed;
};
static Preset presetFor(Motif motif);
void applyMotifPreset(Motif motif);
void updateAspect();
void activateFallback();
QStackedLayout *stack;
QQuickWidget *quickWidget = nullptr;
BannerShaderConfig *config = nullptr;
GradientFallbackWidget *fallback = nullptr;
QTimer clock;
QElapsedTimer elapsed;
Motif currentMotif = Motif::Welcome;
bool usingFallback = false;
bool isFirstApply = true;
};
#endif // SHADER_BANNER_WIDGET_H

View file

@ -0,0 +1,461 @@
#version 440
// ════════════════════════════════════════════════════════════════════════
// brand_banner.frag
//
// One shader, six motifs (uMode 0..5). All motifs composite over a shared
// backgroundField() whose colour is flow-noise-modulated blend of uColorA
// and uColorB. SDFs operate in aspect-corrected space (ac.x = uv.x *
// uAspect) to preserve shape proportions on the wide banner.
//
// IMPORTANT: the uniform block below must list custom uniforms in EXACTLY
// the order they're declared as properties on each ShaderEffect instance in
// BrandBanner.qml (after the two Qt-supplied members, qt_Matrix/qt_Opacity).
// ════════════════════════════════════════════════════════════════════════
layout(location = 0) in vec2 qt_TexCoord0;
layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform buf
{
mat4 qt_Matrix;
float qt_Opacity;
float iTime;
float uAspect;
float uMode;
float uSpeed;
float uSeed;
vec4 uColorA;
vec4 uColorB;
vec4 uAccent;
float uLogoGlow;
};
// ── Primitives ──────────────────────────────────────────────────────────
float hash21(vec2 p)
{
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float valueNoise(vec2 p)
{
vec2 i = floor(p);
vec2 f = fract(p);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float fbm(vec2 p)
{
float v = 0.0;
float amp = 0.5;
for (int i = 0; i < 3; i++) {
v += amp * valueNoise(p);
p *= 2.03;
amp *= 0.5;
}
return v;
}
float flowNoise(vec2 p, float t)
{
vec2 warp1 = vec2(fbm(p + vec2(0.0, 0.0)), fbm(p + vec2(5.2, 1.3)));
vec2 warp2 = vec2(fbm(p + 4.0 * warp1 + vec2(1.7, 9.2) + t * 0.6),
fbm(p + 4.0 * warp1 + vec2(8.3, 2.8) - t * 0.5));
return fbm(p + 4.0 * warp2 + t * 0.15);
}
float bloom(float d, float coreRadius, float haloRadius)
{
float core = exp(-(d * d) / (coreRadius * coreRadius));
float halo = exp(-d / haloRadius) * 0.35;
return core + halo;
}
float roundedBoxSDF(vec2 p, vec2 halfSize, float radius)
{
vec2 d = abs(p) - halfSize + radius;
return length(max(d, 0.0)) - radius + min(max(d.x, d.y), 0.0);
}
// Rotated box SDF -- applies 2D rotation to p before evaluating roundedBoxSDF.
float rotatedBoxSDF(vec2 p, vec2 halfSize, float radius, float angle)
{
float c = cos(angle);
float s = sin(angle);
vec2 rp = vec2(p.x * c - p.y * s, p.x * s + p.y * c);
return roundedBoxSDF(rp, halfSize, radius);
}
float vignette(vec2 uv)
{
vec2 c = uv - 0.5;
c.x *= max(uAspect, 0.0001);
return smoothstep(1.0, 0.25, length(c));
}
// ── Shared background ───────────────────────────────────────────────────
vec3 backgroundField(vec2 uv, float time)
{
// Diagonal luminance gradient from (0,0) to (1,1) used as blend factor
// between uColorA and uColorB; modulated by flowNoise.
float baseD = smoothstep(0.0, 1.0, uv.y * 0.5 + uv.x * 0.2);
float painted = flowNoise(uv * 1.5, time * 0.04) - 0.5;
baseD = clamp(baseD + painted * 0.12, 0.0, 1.0);
vec3 col = mix(uColorA.rgb, uColorB.rgb, baseD);
// Low-frequency fBM noise pushes local colour toward uColorB for depth
float deep = fbm(uv * 1.0 + vec2(37.1, 12.4) + time * 0.015);
col = mix(col, uColorB.rgb, (deep - 0.5) * 0.08);
// Accent-coloured fog layer: flowNoise peaks above 0.6 contribute accent
float fog = flowNoise(uv * 0.8 + vec2(100.0, 50.0), time * 0.02);
col += uAccent.rgb * max(fog - 0.6, 0.0) * 0.10;
return col;
}
// ── Motifs ──────────────────────────────────────────────────────────────
// Centre bloom, flow-noise shimmer gated to centre, and 48 orbiting ember
// particles that deflect into a tight ring near the centre.
vec3 motifWelcome(vec2 uv, vec3 bg, float t)
{
vec3 col = bg;
float asp = max(uAspect, 0.001);
vec2 ac = vec2(uv.x * asp, uv.y);
vec2 center = vec2(asp * 0.5, 0.5);
float cDist = length(ac - center);
// Centre bloom at logo position; intensity scales with uLogoGlow
float centreLight = bloom(cDist, 0.08 * asp, 0.40 * asp);
col += centreLight * 0.20 * uLogoGlow;
// Flow-noise shimmer gated by Gaussian mask at centre
float shimmer = flowNoise(ac * 0.8 + vec2(55.0, 33.0), t * 0.05) * 0.5 + 0.5;
float shimmerMask = exp(-(cDist * cDist) / (0.18 * asp * 0.18 * asp));
col += shimmer * shimmerMask * 0.04 * uLogoGlow;
// 48 ember particles: hash-seeded position, speed, size, brightness.
// Embers within a distance threshold of centre are deflected into an
// orbital ring via tangent displacement perpendicular to the centre vector.
const int EMBERS = 48;
for (int i = 0; i < EMBERS; i++) {
float fi = float(i);
float baseX = hash21(vec2(fi * 7.31 + uSeed, fi * 3.17));
float baseY = hash21(vec2(fi * 11.9 + uSeed * 1.4, fi * 5.53));
float riseSpeed = 0.025 + hash21(vec2(fi * 1.7, uSeed * 2.1)) * 0.035;
float driftAmp = 0.04 + hash21(vec2(fi * 9.3, uSeed)) * 0.06;
float driftFreq = 0.3 + hash21(vec2(fi * 4.1, uSeed * 3.3)) * 0.5;
float pX = baseX * asp + sin(t * driftFreq + fi * 1.7) * driftAmp * asp;
float pY = fract(baseY + t * riseSpeed);
float size = 0.006 + hash21(vec2(fi * 2.9, uSeed * 4.7)) * 0.012;
float bright = 0.15 + hash21(vec2(fi * 6.1, uSeed * 0.9)) * 0.30;
// Fade out near top/bottom edges
float edgeFade = smoothstep(0.0, 0.12, pY) * smoothstep(1.0, 0.88, pY);
float twinkle = 0.6 + 0.4 * sin(t * (1.2 + fi * 0.37) + fi * 2.9);
vec2 ePos = vec2(pX, pY);
// Embers near centre: deflect into orbital ring via tangent displacement
vec2 toCenter = ePos - center;
float distToCenter = length(toCenter);
float ringWeight = smoothstep(0.38 * asp, 0.06 * asp, distToCenter);
float orbitPhase = t * (0.15 + fi * 0.020) + fi * 2.3;
float orbitAmount = 0.020 + hash21(vec2(fi * 12.3, uSeed * 2.7)) * 0.020;
vec2 tangent = vec2(-toCenter.y, toCenter.x);
vec2 deflected = ePos + tangent * ringWeight * orbitAmount * asp * sin(orbitPhase);
float pushOut = ringWeight * (0.008 + hash21(vec2(fi * 6.7, uSeed * 1.1)) * 0.012) * asp;
deflected += normalize(toCenter + 0.001) * pushOut;
float dist = length(ac - deflected);
float intensity = bright * edgeFade * twinkle;
col += uAccent.rgb * bloom(dist, size, size * 4.0) * intensity;
}
return col;
}
// 25 card-shaped box SDFs at parallax depths drifting horizontally across
// the banner; each card has a semi-transparent fill, accent outline, and
// card-back diamond pattern.
vec3 motifCardDatabase(vec2 uv, vec3 bg, float t)
{
vec3 col = bg;
float asp = max(uAspect, 0.001);
vec2 ac = vec2(uv.x * asp, uv.y);
const int CARDS = 25;
for (int i = 0; i < CARDS; i++) {
float fi = float(i);
// Parallax depth via hash; used to scale size, speed, brightness
float depth = hash21(vec2(fi * 1.37 + uSeed, fi * 0.91));
// Card dimensions in corrected space (portrait: height > width)
float cardH = mix(0.055, 0.15, depth);
cardH *= 0.85 + 0.30 * hash21(vec2(fi * 3.14, uSeed * 2.71));
float cardW = cardH * 0.71; // 5:7 ratio
// Horizontal drift; nearer cards (higher depth) move faster
float speed = mix(0.06, 0.18, depth);
float xPhase = hash21(vec2(fi * 7.13, uSeed * 4.37));
xPhase = fract(xPhase + t * speed);
float x = mix(-1.5, asp + 1.5, xPhase);
// Vertical position: hash distribution with sinusoidal oscillation
float yBase = hash21(vec2(fi * 2.91, uSeed * 1.63));
float y = yBase + sin(t * 0.6 + fi * 1.9) * 0.035;
y = clamp(y, cardH + 0.02, 1.0 - cardH - 0.02);
// Random rotation angle ±4 degrees
float tilt = (hash21(vec2(fi * 5.71, uSeed * 8.29)) - 0.5) * 0.14;
vec2 p = ac - vec2(x, y);
float d = rotatedBoxSDF(p, vec2(cardW, cardH), cardW * 0.14, tilt);
// Semi-transparent dark fill
float fill = smoothstep(0.015, -0.005, d);
col = mix(col, uColorB.rgb * 0.55, fill * 0.50);
// Accent outline
float edge = smoothstep(0.035, 0.0, abs(d));
col += uAccent.rgb * edge * mix(0.18, 0.50, 1.0 - depth);
// Card-back diamond: smaller rotated box inset from card edges
float innerD = rotatedBoxSDF(p, vec2(cardW * 0.45, cardH * 0.55), cardW * 0.08, tilt);
float innerEdge = smoothstep(0.012, 0.0, abs(innerD));
col += uAccent.rgb * innerEdge * fill * 0.12 * (1.0 - depth);
// Centre dot
float dotDist = length(p);
col += uAccent.rgb * bloom(dotDist, 0.008, 0.02) * fill * 0.15 * (1.0 - depth);
}
return col;
}
// 4 horizontal bands with multi-frequency sinusoidal warp and pulsing width.
vec3 motifTheming(vec2 uv, vec3 bg, float t)
{
vec3 col = bg;
const int BANDS = 4;
for (int i = 0; i < BANDS; i++) {
float fi = float(i);
float yCenter = 0.18 + fi * 0.22;
// Three summed sinusoids for horizontal undulation
float wave = sin(uv.x * 3.2 + t * 0.5 + fi * 2.1) * 0.08;
wave += sin(uv.x * 7.0 - t * 0.3 + fi * 1.3) * 0.035;
wave += sin(uv.x * 1.6 + t * 0.18 + fi * 3.7) * 0.05;
float bandDist = abs(uv.y - yCenter - wave);
float bandWidth = 0.04 + sin(t * 0.2 + fi * 0.8) * 0.012;
float band = smoothstep(bandWidth, 0.0, bandDist);
// Upper bands have higher intensity
float intensity = mix(0.15, 0.38, 1.0 - fi / float(BANDS));
col += uAccent.rgb * band * intensity;
}
return col;
}
// 14 nodes at pseudo-random positions with sinusoidal pulse; edges drawn
// between nodes within a threshold distance; central glow + periodic ring.
vec3 motifAccount(vec2 uv, vec3 bg, float t)
{
vec3 col = bg;
float asp = max(uAspect, 0.001);
vec2 ac = vec2(uv.x * asp, uv.y);
vec2 center = vec2(asp * 0.5, 0.5);
const int NODES = 14;
vec2 nodePos[14];
float nodePulse[14];
for (int i = 0; i < NODES; i++) {
float fi = float(i);
// Hash-seeded position with gentle sinusoidal drift
float nx = hash21(vec2(fi * 3.17 + uSeed, fi * 1.93)) * asp;
float ny = hash21(vec2(fi * 5.41 + uSeed * 1.7, fi * 2.79));
float dx = sin(t * 0.12 + fi * 1.7) * 0.08;
float dy = cos(t * 0.09 + fi * 2.3) * 0.04;
vec2 pos = vec2(nx + dx, ny + dy);
nodePos[i] = pos;
// Per-node pulse phase, normalised to [0, 1]
float pulsePhase = hash21(vec2(fi * 4.31, uSeed * 6.17));
float pulse = sin(t * 0.8 + pulsePhase * 6.283) * 0.5 + 0.5;
nodePulse[i] = pulse;
// Node glow via bloom; intensity modulated by pulse
float dist = length(ac - pos);
col += uAccent.rgb * bloom(dist, 0.018, 0.08) * mix(0.20, 0.45, pulse);
}
// Edges: connect nodes within a radius threshold
float connectDist = asp * 0.22;
for (int i = 0; i < NODES; i++) {
for (int j = i + 1; j < NODES; j++) {
float pairDist = length(nodePos[i] - nodePos[j]);
if (pairDist < connectDist) {
float strength = 1.0 - pairDist / connectDist;
vec2 pa = ac - nodePos[i];
vec2 ba = nodePos[j] - nodePos[i];
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
float lineDist = length(pa - ba * h);
col += uAccent.rgb * smoothstep(0.010, 0.0, lineDist) * strength * 0.10;
}
}
}
// Central bloom at banner centre
float cDist = length(ac - center);
col += uAccent.rgb * bloom(cDist, 0.04, 0.25) * 0.12;
// Periodic expanding ring from centre
float ripplePhase = t * 0.4;
float rippleDist = abs(cDist - fract(ripplePhase) * asp * 0.7);
col += uAccent.rgb * smoothstep(0.02, 0.0, rippleDist) * 0.10;
return col;
}
// 18x5 toggle-grid of rounded boxes with hash-driven on/off per cell;
// a scanning highlight sweeps L-to-R, brightening cells near the scan line.
vec3 motifPreferences(vec2 uv, vec3 bg, float t)
{
vec3 col = bg;
float cols = 18.0;
float rows = 5.0;
vec2 gridUV = uv * vec2(cols, rows);
vec2 cell = fract(gridUV) - 0.5;
vec2 cellId = floor(gridUV);
// On/off state per cell, hash-seeded for pseudo-randomness
float on = step(0.55, hash21(cellId + uSeed * 10.0));
float d = roundedBoxSDF(cell, vec2(0.28, 0.32), 0.06);
// Filled "on" cells
float cellFill = smoothstep(0.04, -0.02, d);
col += uAccent.rgb * cellFill * on * 0.18;
// Cell borders (drawn on all cells)
float border = smoothstep(0.025, 0.0, abs(d));
col += uAccent.rgb * border * 0.06;
// Scanning highlight: thin line + soft glow sweeping L-to-R
float scanX = fract(t * 0.15);
float scanDist = abs(uv.x - scanX);
float scanLine = smoothstep(0.015, 0.0, scanDist);
col += uAccent.rgb * scanLine * 0.40;
float scanGlow = smoothstep(0.08, 0.0, scanDist);
col += uAccent.rgb * scanGlow * 0.08;
// "On" cells near the scan line get extra brightness
float scanProximity = smoothstep(0.12, 0.0, scanDist);
col += uAccent.rgb * cellFill * on * scanProximity * 0.15;
return col;
}
// Centre radial bloom with sinusoidal pulse, 4 expanding ring halos with
// outer glow falloff, and 35 rising particles.
vec3 motifFinish(vec2 uv, vec3 bg, float t)
{
vec3 col = bg;
float asp = max(uAspect, 0.001);
vec2 ac = vec2(uv.x * asp, uv.y);
vec2 center = vec2(asp * 0.5, 0.5);
float cDist = length(ac - center);
// Centre bloom with sinusoidal pulse modulation
float pulse = 0.65 + 0.35 * sin(t * 0.4);
col += uAccent.rgb * bloom(cDist, 0.12, 0.55) * 0.10 * pulse;
// 4 expanding rings: radius increases via phase; ring width grows with
// expansion; combined with exponential outer glow falloff
for (int i = 0; i < 4; i++) {
float fi = float(i);
float phase = fract(t * 0.06 + fi * 0.25);
float ringRadius = phase * asp * 0.7;
float ringDist = abs(cDist - ringRadius);
float ringWidth = 0.025 + phase * 0.025;
float ring = smoothstep(ringWidth, 0.0, ringDist);
float outerGlow = exp(-ringDist / (0.03 + phase * 0.02)) * 0.3;
float combined = ring + outerGlow;
float fade = 1.0 - phase * 0.5;
col += uAccent.rgb * combined * fade * 0.15;
}
// 35 particles rising vertically with sinusoidal horizontal drift;
// each particle uses bloom with edge fade and twinkle animation
const int PARTICLES = 35;
for (int i = 0; i < PARTICLES; i++) {
float fi = float(i);
float baseX = hash21(vec2(fi * 13.7 + uSeed, fi * 7.31));
float baseY = hash21(vec2(fi * 23.1 + uSeed * 1.9, fi * 11.3));
float riseSpeed = 0.04 + hash21(vec2(fi * 3.1, uSeed * 2.7)) * 0.06;
float driftAmp = 0.03 + hash21(vec2(fi * 8.9, uSeed)) * 0.05;
float driftFreq = 0.4 + hash21(vec2(fi * 5.3, uSeed * 4.1)) * 0.6;
float pX = baseX * asp + sin(t * driftFreq + fi * 2.3) * driftAmp * asp;
float pY = fract(baseY + t * riseSpeed);
float size = 0.005 + hash21(vec2(fi * 4.7, uSeed * 3.9)) * 0.010;
float bright = 0.12 + hash21(vec2(fi * 7.1, uSeed * 1.3)) * 0.25;
float edgeFade = smoothstep(0.0, 0.1, pY) * smoothstep(1.0, 0.9, pY);
float twinkle = 0.5 + 0.5 * sin(t * (1.8 + fi * 0.43) + fi * 3.1);
vec2 pPos = vec2(pX, pY);
float dist = length(ac - pPos);
col += uAccent.rgb * bloom(dist, size, size * 3.5) * bright * edgeFade * twinkle;
}
return col;
}
// ── Main ────────────────────────────────────────────────────────────────
void main()
{
vec2 uv = qt_TexCoord0;
float t = iTime * uSpeed;
vec3 bg = backgroundField(uv, iTime);
vec3 col;
if (uMode < 0.5) col = motifWelcome(uv, bg, t);
else if (uMode < 1.5) col = motifCardDatabase(uv, bg, t);
else if (uMode < 2.5) col = motifTheming(uv, bg, t);
else if (uMode < 3.5) col = motifAccount(uv, bg, t);
else if (uMode < 4.5) col = motifPreferences(uv, bg, t);
else col = motifFinish(uv, bg, t);
col *= mix(0.62, 1.0, vignette(uv));
fragColor = vec4(col, 1.0) * qt_Opacity;
}

View file

@ -0,0 +1,84 @@
#include "step_indicator_widget.h"
#include <QPainter>
#include <QPainterPath>
StepIndicatorWidget::StepIndicatorWidget(QWidget *parent) : QWidget(parent)
{
setFixedHeight(kDotDiameter + 2 * kVerticalMargin);
}
void StepIndicatorWidget::setStepCount(int count)
{
stepCount = qMax(0, count);
currentStep = qBound(0, currentStep, qMax(0, stepCount - 1));
updateGeometry();
update();
}
void StepIndicatorWidget::setCurrentStep(int index)
{
if (stepCount == 0) {
return;
}
currentStep = qBound(0, index, stepCount - 1);
update();
}
QSize StepIndicatorWidget::sizeHint() const
{
return minimumSizeHint();
}
QSize StepIndicatorWidget::minimumSizeHint() const
{
if (stepCount == 0) {
return QSize(0, height());
}
int width = kActiveDotWidth + (stepCount - 1) * kDotDiameter + (stepCount - 1) * kDotSpacing;
return QSize(width, height());
}
void StepIndicatorWidget::paintEvent(QPaintEvent * /*event*/)
{
if (stepCount == 0) {
return;
}
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
const QColor activeColor = palette().color(QPalette::Highlight);
// QPalette::Mid alpha-blended against a dark Window background reads as
// near-invisible (Mid is itself a dark grey in dark palettes -- see
// PaletteGenerator's satShadeLo/Dark roles). WindowText is guaranteed to
// contrast against Window in any theme by definition, so alpha-blending
// *that* instead keeps the dots visibly dim-but-present in both light and
// dark schemes. Same trick PaletteGenerator uses for placeholder text.
QColor inactiveColor = palette().color(QPalette::WindowText);
inactiveColor.setAlpha(100);
int totalWidth = 0;
for (int i = 0; i < stepCount; ++i) {
totalWidth += (i == currentStep) ? kActiveDotWidth : kDotDiameter;
if (i > 0) {
totalWidth += kDotSpacing;
}
}
int x = (width() - totalWidth) / 2;
const int y = height() / 2;
for (int i = 0; i < stepCount; ++i) {
const bool active = (i == currentStep);
const int dotWidth = active ? kActiveDotWidth : kDotDiameter;
QPainterPath path;
QRectF rect(x, y - kDotDiameter / 2.0, dotWidth, kDotDiameter);
path.addRoundedRect(rect, kDotDiameter / 2.0, kDotDiameter / 2.0);
painter.fillPath(path, active ? activeColor : inactiveColor);
x += dotWidth + kDotSpacing;
}
}

View file

@ -0,0 +1,34 @@
#ifndef STEP_INDICATOR_WIDGET_H
#define STEP_INDICATOR_WIDGET_H
#include <QWidget>
/** @brief Row of dots showing progress through a fixed-length sequence of steps,
* in the style of a mobile/OS setup flow. Purely presentational. */
class StepIndicatorWidget : public QWidget
{
Q_OBJECT
public:
explicit StepIndicatorWidget(QWidget *parent = nullptr);
void setStepCount(int count);
void setCurrentStep(int index);
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
protected:
void paintEvent(QPaintEvent *event) override;
private:
int stepCount = 0;
int currentStep = 0;
static constexpr int kDotDiameter = 8;
static constexpr int kActiveDotWidth = 22;
static constexpr int kDotSpacing = 10;
static constexpr int kVerticalMargin = 6;
};
#endif // STEP_INDICATOR_WIDGET_H

Some files were not shown because too many files have changed in this diff Show more