Compare commits

..

No commits in common. "f3370a4f52b3a419ac47ea0b848fbb0d3cbf05e0" and "bc219191dbdcf5e870c36470b9c633558f483de9" have entirely different histories.

53 changed files with 3935 additions and 4895 deletions

View file

@ -27,8 +27,6 @@ Available pre-compiled binaries for installation:
<sub>We are also packaged in <kbd>Arch Linux</kbd>'s <a href="https://archlinux.org/packages/extra/x86_64/cockatrice">official extra repository</a>, courtesy of @FFY00.</sub> <sub>We are also packaged in <kbd>Arch Linux</kbd>'s <a href="https://archlinux.org/packages/extra/x86_64/cockatrice">official extra repository</a>, courtesy of @FFY00.</sub>
<sub>General Linux support is available via a <kbd>flatpak</kbd> package at <a href="https://flathub.org/apps/io.github.Cockatrice.cockatrice">Flathub</a>!</sub> <sub>General Linux support is available via a <kbd>flatpak</kbd> package at <a href="https://flathub.org/apps/io.github.Cockatrice.cockatrice">Flathub</a>!</sub>
<sub>We provide a <kbd>Docker</kbd> image for "Servatrice" in <a href="https://github.com/Cockatrice/Cockatrice/pkgs/container/servatrice">GHCR</a>. You can docker pull it or use our Docker Compose files!</sub>
</pre> </pre>

View file

@ -2,18 +2,19 @@
version: 2 version: 2
updates: updates:
# Enable version updates for git submodules # # Enable version updates for git submodules
# If SemVer is used, updates will happen to new releases only (not HEAD) # Not yet possible to bump only on tags or releases, see:
# https://github.com/dependabot/dependabot-core/issues/1639 # https://github.com/dependabot/dependabot-core/issues/1639
# https://github.com/dependabot/dependabot-core/issues/2192 # https://github.com/dependabot/dependabot-core/issues/2192
- package-ecosystem: "gitsubmodule" # Alternative: Action that updates submodule and can be manually run on demand (workflow_dispatch)
# Look for `.gitmodules` in the `root` directory # - package-ecosystem: "gitsubmodule"
directory: "/" # # Look for `.gitmodules` in the `root` directory
# Check for updates once a month # directory: "/"
schedule: # # Check for updates once a month
interval: "monthly" # schedule:
# Limit the amout of open PR's (default = 5, disabled = 0, security updates are not impacted) # interval: "monthly"
open-pull-requests-limit: 2 # # Limit the amout of open PR's (default = 5, disabled = 0, security updates are not impacted)
# open-pull-requests-limit: 1
# # Enable version updates for Docker # # Enable version updates for Docker
# Not yet possible to bump from one LTS version to the next and skip others, see: # Not yet possible to bump from one LTS version to the next and skip others, see:

View file

@ -341,7 +341,7 @@ jobs:
- name: Add msbuild to PATH - name: Add msbuild to PATH
if: matrix.os == 'Windows' if: matrix.os == 'Windows'
id: add-msbuild id: add-msbuild
uses: microsoft/setup-msbuild@v3 uses: microsoft/setup-msbuild@v2
with: with:
msbuild-architecture: x64 msbuild-architecture: x64

View file

@ -48,7 +48,7 @@ jobs:
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
if: github.ref_type == 'tag' if: github.ref_type == 'tag'
uses: docker/login-action@v4 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}

View file

@ -11,8 +11,6 @@ CardCounterSettings::CardCounterSettings(const QString &settingsPath, QObject *p
void CardCounterSettings::setColor(int counterId, const QColor &color) void CardCounterSettings::setColor(int counterId, const QColor &color)
{ {
QSettings settings = getSettings();
QString key = QString("cards/counters/%1/color").arg(counterId); QString key = QString("cards/counters/%1/color").arg(counterId);
if (settings.value(key).value<QColor>() == color) if (settings.value(key).value<QColor>() == color)
@ -38,7 +36,7 @@ QColor CardCounterSettings::color(int counterId) const
defaultColor = QColor::fromHsv(h, s, v); defaultColor = QColor::fromHsv(h, s, v);
} }
return getSettings().value(QString("cards/counters/%1/color").arg(counterId), defaultColor).value<QColor>(); return settings.value(QString("cards/counters/%1/color").arg(counterId), defaultColor).value<QColor>();
} }
QString CardCounterSettings::displayName(int counterId) const QString CardCounterSettings::displayName(int counterId) const

View file

@ -501,7 +501,7 @@ private:
{"Player/aUntapAll", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Untap All"), {"Player/aUntapAll", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Untap All"),
parseSequenceString("Ctrl+U"), parseSequenceString("Ctrl+U"),
ShortcutGroup::Playing_Area)}, ShortcutGroup::Playing_Area)},
{"Player/aDoesntUntap", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Toggle Skip Untapping"), {"Player/aDoesntUntap", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Toggle Untap"),
parseSequenceString("Alt+U"), parseSequenceString("Alt+U"),
ShortcutGroup::Playing_Area)}, ShortcutGroup::Playing_Area)},
{"Player/aFlip", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Turn Card Over"), {"Player/aFlip", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Turn Card Over"),
@ -563,9 +563,6 @@ private:
{"Player/aMoveToTopLibrary", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Top of Library"), {"Player/aMoveToTopLibrary", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Top of Library"),
parseSequenceString(""), parseSequenceString(""),
ShortcutGroup::Move_selected)}, ShortcutGroup::Move_selected)},
{"Player/aMoveToTable", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Battlefield"),
parseSequenceString(""),
ShortcutGroup::Move_selected)},
{"Player/aViewHand", {"Player/aViewHand",
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Hand"), parseSequenceString(""), ShortcutGroup::View)}, ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Hand"), parseSequenceString(""), ShortcutGroup::View)},
{"Player/aViewGraveyard", {"Player/aViewGraveyard",

View file

@ -8,7 +8,6 @@
#define COUNTER_H #define COUNTER_H
#include "../../interface/widgets/menus/tearoff_menu.h" #include "../../interface/widgets/menus/tearoff_menu.h"
#include "../player/menu/abstract_player_component.h"
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QInputDialog> #include <QInputDialog>
@ -19,7 +18,7 @@ class QKeyEvent;
class QMenu; class QMenu;
class QString; class QString;
class AbstractCounter : public QObject, public QGraphicsItem, public AbstractPlayerComponent class AbstractCounter : public QObject, public QGraphicsItem
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(QGraphicsItem) Q_INTERFACES(QGraphicsItem)
@ -57,10 +56,10 @@ public:
QGraphicsItem *parent = nullptr); QGraphicsItem *parent = nullptr);
~AbstractCounter() override; ~AbstractCounter() override;
void retranslateUi() override; void retranslateUi();
void setValue(int _value); void setValue(int _value);
void setShortcutsActive() override; void setShortcutsActive();
void setShortcutsInactive() override; void setShortcutsInactive();
void delCounter(); void delCounter();
QMenu *getMenu() const QMenu *getMenu() const

View file

@ -460,9 +460,6 @@ void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
bool CardItem::animationEvent() bool CardItem::animationEvent()
{ {
if (owner == nullptr) {
return false;
}
int rotation = ROTATION_DEGREES_PER_FRAME; int rotation = ROTATION_DEGREES_PER_FRAME;
bool animationIncomplete = true; bool animationIncomplete = true;
if (!tapped) if (!tapped)

View file

@ -9,20 +9,17 @@
enum CardMenuActionType enum CardMenuActionType
{ {
// Per-card attribute actions (must be <= cmClone for cardMenuAction() dispatch)
cmTap, cmTap,
cmUntap, cmUntap,
cmDoesntUntap, cmDoesntUntap,
cmFlip, cmFlip,
cmPeek, cmPeek,
cmClone, cmClone,
// Move actions (must be > cmClone for cardMenuAction() dispatch)
cmMoveToTopLibrary, cmMoveToTopLibrary,
cmMoveToBottomLibrary, cmMoveToBottomLibrary,
cmMoveToHand, cmMoveToHand,
cmMoveToGraveyard, cmMoveToGraveyard,
cmMoveToExile, cmMoveToExile
cmMoveToTable
}; };
#endif // COCKATRICE_CARD_MENU_ACTION_TYPE_H #endif // COCKATRICE_CARD_MENU_ACTION_TYPE_H

View file

@ -1,32 +0,0 @@
/**
* @file abstract_player_component.h
* @ingroup GameMenusPlayers
* @brief Polymorphic interface for player-bound UI components managed by PlayerMenu.
*/
#ifndef COCKATRICE_ABSTRACT_PLAYER_COMPONENT_H
#define COCKATRICE_ABSTRACT_PLAYER_COMPONENT_H
/**
* @brief Interface for player-bound UI components that need shortcut and translation lifecycle management.
*
* Not a QObject avoids diamond inheritance with Qt's MOC. Each concrete component
* inherits QObject through its Qt base class (QMenu, TearOffMenu, QGraphicsItem, etc.)
* and this interface through regular multiple inheritance.
*/
class AbstractPlayerComponent
{
public:
virtual ~AbstractPlayerComponent() = default;
/// Bind keyboard shortcuts. Called when this player gains focus.
virtual void setShortcutsActive() = 0;
/// Unbind keyboard shortcuts. Called when this player loses focus.
virtual void setShortcutsInactive() = 0;
/// Retranslate all user-visible strings. Called on language change.
virtual void retranslateUi() = 0;
};
#endif // COCKATRICE_ABSTRACT_PLAYER_COMPONENT_H

View file

@ -35,8 +35,6 @@ CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive
connect(aTap, &QAction::triggered, playerActions, &PlayerActions::cardMenuAction); connect(aTap, &QAction::triggered, playerActions, &PlayerActions::cardMenuAction);
aDoesntUntap = new QAction(this); aDoesntUntap = new QAction(this);
aDoesntUntap->setData(cmDoesntUntap); aDoesntUntap->setData(cmDoesntUntap);
aDoesntUntap->setCheckable(true);
aDoesntUntap->setChecked(card != nullptr && card->getDoesntUntap());
connect(aDoesntUntap, &QAction::triggered, playerActions, &PlayerActions::cardMenuAction); connect(aDoesntUntap, &QAction::triggered, playerActions, &PlayerActions::cardMenuAction);
aAttach = new QAction(this); aAttach = new QAction(this);
connect(aAttach, &QAction::triggered, playerActions, &PlayerActions::actAttach); connect(aAttach, &QAction::triggered, playerActions, &PlayerActions::actAttach);
@ -110,7 +108,6 @@ CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive
if (revealedCard) { if (revealedCard) {
addAction(aHide); addAction(aHide);
addSeparator();
addAction(aClone); addAction(aClone);
addSeparator(); addSeparator();
addAction(aSelectAll); addAction(aSelectAll);
@ -149,14 +146,16 @@ void CardMenu::createTableMenu(bool canModifyCard)
{ {
// Card is on the battlefield // Card is on the battlefield
if (!canModifyCard) { if (!canModifyCard) {
addRelatedCardView();
addRelatedCardActions();
addSeparator();
addAction(aDrawArrow); addAction(aDrawArrow);
addSeparator(); addSeparator();
addAction(aClone); addAction(aClone);
addSeparator(); addSeparator();
addAction(aSelectAll); addAction(aSelectAll);
addAction(aSelectRow); addAction(aSelectRow);
addRelatedCardView();
addRelatedCardActions();
return; return;
} }
@ -166,9 +165,10 @@ void CardMenu::createTableMenu(bool canModifyCard)
if (card->getFaceDown()) { if (card->getFaceDown()) {
addAction(aPeek); addAction(aPeek);
} }
addSeparator();
addAction(aClone); addRelatedCardView();
addMenu(new MoveMenu(player)); addRelatedCardActions();
addSeparator(); addSeparator();
addAction(aAttach); addAction(aAttach);
if (card->getAttachedTo()) { if (card->getAttachedTo()) {
@ -179,6 +179,9 @@ void CardMenu::createTableMenu(bool canModifyCard)
addMenu(new PtMenu(player)); addMenu(new PtMenu(player));
addAction(aSetAnnotation); addAction(aSetAnnotation);
addSeparator(); addSeparator();
addAction(aClone);
addMenu(new MoveMenu(player));
addSeparator();
addAction(aSelectAll); addAction(aSelectAll);
addAction(aSelectRow); addAction(aSelectRow);
@ -194,34 +197,27 @@ void CardMenu::createTableMenu(bool canModifyCard)
} }
addSeparator(); addSeparator();
addMenu(mCardCounters); addMenu(mCardCounters);
addRelatedCardView();
addRelatedCardActions();
} }
void CardMenu::createStackMenu(bool canModifyCard) void CardMenu::createStackMenu(bool canModifyCard)
{ {
// Card is on the stack // Card is on the stack
if (!canModifyCard) { if (canModifyCard) {
addAction(aAttach);
addAction(aDrawArrow); addAction(aDrawArrow);
addSeparator(); addSeparator();
addAction(aClone); addAction(aClone);
addSeparator();
addAction(aSelectAll);
addRelatedCardView();
addRelatedCardActions();
return;
}
addAction(aPlay);
addAction(aPlayFacedown);
addSeparator();
addAction(aClone);
addMenu(new MoveMenu(player)); addMenu(new MoveMenu(player));
addSeparator(); addSeparator();
addAction(aAttach); addAction(aSelectAll);
} else {
addAction(aDrawArrow); addAction(aDrawArrow);
addSeparator(); addSeparator();
addAction(aClone);
addSeparator();
addAction(aSelectAll); addAction(aSelectAll);
}
addRelatedCardView(); addRelatedCardView();
addRelatedCardActions(); addRelatedCardActions();
} }
@ -229,29 +225,29 @@ void CardMenu::createStackMenu(bool canModifyCard)
void CardMenu::createGraveyardOrExileMenu(bool canModifyCard) void CardMenu::createGraveyardOrExileMenu(bool canModifyCard)
{ {
// Card is in the graveyard or exile // Card is in the graveyard or exile
if (!canModifyCard) { if (canModifyCard) {
addAction(aDrawArrow);
addSeparator();
addAction(aClone);
addSeparator();
addAction(aSelectAll);
addAction(aSelectColumn);
addRelatedCardView();
addRelatedCardActions();
return;
}
addAction(aPlay); addAction(aPlay);
addAction(aPlayFacedown); addAction(aPlayFacedown);
addSeparator(); addSeparator();
addAction(aClone); addAction(aClone);
addMenu(new MoveMenu(player)); addMenu(new MoveMenu(player));
addSeparator();
addAction(aSelectAll);
addAction(aSelectColumn);
addSeparator(); addSeparator();
addAction(aAttach); addAction(aAttach);
addAction(aDrawArrow); addAction(aDrawArrow);
} else {
addAction(aClone);
addSeparator(); addSeparator();
addAction(aSelectAll); addAction(aSelectAll);
addAction(aSelectColumn); addAction(aSelectColumn);
addSeparator();
addAction(aDrawArrow);
}
addRelatedCardView(); addRelatedCardView();
addRelatedCardActions(); addRelatedCardActions();
} }
@ -261,11 +257,12 @@ void CardMenu::createHandOrCustomZoneMenu(bool canModifyCard)
if (!canModifyCard) { if (!canModifyCard) {
addAction(aDrawArrow); addAction(aDrawArrow);
addSeparator(); addSeparator();
addRelatedCardView();
addRelatedCardActions();
addSeparator();
addAction(aClone); addAction(aClone);
addSeparator(); addSeparator();
addAction(aSelectAll); addAction(aSelectAll);
addRelatedCardView();
addRelatedCardActions();
return; return;
} }
@ -452,7 +449,7 @@ void CardMenu::retranslateUi()
aRevealToAll->setText(tr("&All players")); aRevealToAll->setText(tr("&All players"));
//: Turn sideways or back again //: Turn sideways or back again
aTap->setText(tr("&Tap / Untap")); aTap->setText(tr("&Tap / Untap"));
aDoesntUntap->setText(tr("Skip &untapping")); aDoesntUntap->setText(tr("Toggle &normal untapping"));
//: Turn face up/face down //: Turn face up/face down
aFlip->setText(tr("T&urn Over")); // Only the user facing names in client got renamed to "turn over" aFlip->setText(tr("T&urn Over")); // Only the user facing names in client got renamed to "turn over"
// All code and proto bits are still unchanged (flip) for compatibility reasons // All code and proto bits are still unchanged (flip) for compatibility reasons

View file

@ -7,23 +7,15 @@
#ifndef COCKATRICE_CUSTOM_ZONE_MENU_H #ifndef COCKATRICE_CUSTOM_ZONE_MENU_H
#define COCKATRICE_CUSTOM_ZONE_MENU_H #define COCKATRICE_CUSTOM_ZONE_MENU_H
#include "abstract_player_component.h"
#include <QMenu> #include <QMenu>
class Player; class Player;
class CustomZoneMenu : public QMenu, public AbstractPlayerComponent class CustomZoneMenu : public QMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CustomZoneMenu(Player *player); explicit CustomZoneMenu(Player *player);
void retranslateUi() override; void retranslateUi();
void setShortcutsActive() override
{
}
void setShortcutsInactive() override
{
}
private: private:
Player *player; Player *player;

View file

@ -8,13 +8,12 @@
#define COCKATRICE_GRAVE_MENU_H #define COCKATRICE_GRAVE_MENU_H
#include "../../../interface/widgets/menus/tearoff_menu.h" #include "../../../interface/widgets/menus/tearoff_menu.h"
#include "abstract_player_component.h"
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
class Player; class Player;
class GraveyardMenu : public TearOffMenu, public AbstractPlayerComponent class GraveyardMenu : public TearOffMenu
{ {
Q_OBJECT Q_OBJECT
signals: signals:
@ -26,9 +25,9 @@ public:
void createViewActions(); void createViewActions();
void populateRevealRandomMenuWithActivePlayers(); void populateRevealRandomMenuWithActivePlayers();
void onRevealRandomTriggered(); void onRevealRandomTriggered();
void retranslateUi() override; void retranslateUi();
void setShortcutsActive() override; void setShortcutsActive();
void setShortcutsInactive() override; void setShortcutsInactive();
QMenu *mRevealRandomGraveyardCard = nullptr; QMenu *mRevealRandomGraveyardCard = nullptr;
QMenu *moveGraveMenu = nullptr; QMenu *moveGraveMenu = nullptr;

View file

@ -8,7 +8,6 @@
#define COCKATRICE_HAND_MENU_H #define COCKATRICE_HAND_MENU_H
#include "../../../interface/widgets/menus/tearoff_menu.h" #include "../../../interface/widgets/menus/tearoff_menu.h"
#include "abstract_player_component.h"
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
@ -16,7 +15,7 @@
class Player; class Player;
class PlayerActions; class PlayerActions;
class HandMenu : public TearOffMenu, public AbstractPlayerComponent class HandMenu : public TearOffMenu
{ {
Q_OBJECT Q_OBJECT
@ -32,9 +31,9 @@ public:
return mRevealRandomHandCard; return mRevealRandomHandCard;
} }
void retranslateUi() override; void retranslateUi();
void setShortcutsActive() override; void setShortcutsActive();
void setShortcutsInactive() override; void setShortcutsInactive();
private slots: private slots:
void populateRevealHandMenuWithActivePlayers(); void populateRevealHandMenuWithActivePlayers();

View file

@ -8,7 +8,6 @@
#define COCKATRICE_LIBRARY_MENU_H #define COCKATRICE_LIBRARY_MENU_H
#include "../../../interface/widgets/menus/tearoff_menu.h" #include "../../../interface/widgets/menus/tearoff_menu.h"
#include "abstract_player_component.h"
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
@ -16,7 +15,7 @@
class Player; class Player;
class PlayerActions; class PlayerActions;
class LibraryMenu : public TearOffMenu, public AbstractPlayerComponent class LibraryMenu : public TearOffMenu
{ {
Q_OBJECT Q_OBJECT
public slots: public slots:
@ -29,15 +28,15 @@ public:
void createShuffleActions(); void createShuffleActions();
void createMoveActions(); void createMoveActions();
void createViewActions(); void createViewActions();
void retranslateUi() override; void retranslateUi();
void populateRevealLibraryMenuWithActivePlayers(); void populateRevealLibraryMenuWithActivePlayers();
void populateLendLibraryMenuWithActivePlayers(); void populateLendLibraryMenuWithActivePlayers();
void populateRevealTopCardMenuWithActivePlayers(); void populateRevealTopCardMenuWithActivePlayers();
void onRevealLibraryTriggered(); void onRevealLibraryTriggered();
void onLendLibraryTriggered(); void onLendLibraryTriggered();
void onRevealTopCardTriggered(); void onRevealTopCardTriggered();
void setShortcutsActive() override; void setShortcutsActive();
void setShortcutsInactive() override; void setShortcutsInactive();
[[nodiscard]] bool isAlwaysRevealTopCardChecked() const [[nodiscard]] bool isAlwaysRevealTopCardChecked() const
{ {

View file

@ -11,8 +11,6 @@ MoveMenu::MoveMenu(Player *player) : QMenu(tr("Move to"))
aMoveToBottomLibrary = new QAction(this); aMoveToBottomLibrary = new QAction(this);
aMoveToBottomLibrary->setData(cmMoveToBottomLibrary); aMoveToBottomLibrary->setData(cmMoveToBottomLibrary);
aMoveToXfromTopOfLibrary = new QAction(this); aMoveToXfromTopOfLibrary = new QAction(this);
aMoveToTable = new QAction(this);
aMoveToTable->setData(cmMoveToTable);
aMoveToGraveyard = new QAction(this); aMoveToGraveyard = new QAction(this);
aMoveToHand = new QAction(this); aMoveToHand = new QAction(this);
aMoveToHand->setData(cmMoveToHand); aMoveToHand->setData(cmMoveToHand);
@ -24,7 +22,6 @@ MoveMenu::MoveMenu(Player *player) : QMenu(tr("Move to"))
connect(aMoveToBottomLibrary, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); connect(aMoveToBottomLibrary, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction);
connect(aMoveToXfromTopOfLibrary, &QAction::triggered, player->getPlayerActions(), connect(aMoveToXfromTopOfLibrary, &QAction::triggered, player->getPlayerActions(),
&PlayerActions::actMoveCardXCardsFromTop); &PlayerActions::actMoveCardXCardsFromTop);
connect(aMoveToTable, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction);
connect(aMoveToHand, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); connect(aMoveToHand, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction);
connect(aMoveToGraveyard, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); connect(aMoveToGraveyard, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction);
connect(aMoveToExile, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); connect(aMoveToExile, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction);
@ -33,8 +30,6 @@ MoveMenu::MoveMenu(Player *player) : QMenu(tr("Move to"))
addAction(aMoveToXfromTopOfLibrary); addAction(aMoveToXfromTopOfLibrary);
addAction(aMoveToBottomLibrary); addAction(aMoveToBottomLibrary);
addSeparator(); addSeparator();
addAction(aMoveToTable);
addSeparator();
addAction(aMoveToHand); addAction(aMoveToHand);
addSeparator(); addSeparator();
addAction(aMoveToGraveyard); addAction(aMoveToGraveyard);
@ -52,7 +47,6 @@ void MoveMenu::setShortcutsActive()
aMoveToTopLibrary->setShortcuts(shortcuts.getShortcut("Player/aMoveToTopLibrary")); aMoveToTopLibrary->setShortcuts(shortcuts.getShortcut("Player/aMoveToTopLibrary"));
aMoveToBottomLibrary->setShortcuts(shortcuts.getShortcut("Player/aMoveToBottomLibrary")); aMoveToBottomLibrary->setShortcuts(shortcuts.getShortcut("Player/aMoveToBottomLibrary"));
aMoveToTable->setShortcuts(shortcuts.getShortcut("Player/aMoveToTable"));
aMoveToHand->setShortcuts(shortcuts.getShortcut("Player/aMoveToHand")); aMoveToHand->setShortcuts(shortcuts.getShortcut("Player/aMoveToHand"));
aMoveToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveToGraveyard")); aMoveToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveToGraveyard"));
aMoveToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveToExile")); aMoveToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveToExile"));
@ -63,7 +57,6 @@ void MoveMenu::retranslateUi()
aMoveToTopLibrary->setText(tr("&Top of library in random order")); aMoveToTopLibrary->setText(tr("&Top of library in random order"));
aMoveToXfromTopOfLibrary->setText(tr("X cards from the top of library...")); aMoveToXfromTopOfLibrary->setText(tr("X cards from the top of library..."));
aMoveToBottomLibrary->setText(tr("&Bottom of library in random order")); aMoveToBottomLibrary->setText(tr("&Bottom of library in random order"));
aMoveToTable->setText(tr("T&able"));
aMoveToHand->setText(tr("&Hand")); aMoveToHand->setText(tr("&Hand"));
aMoveToGraveyard->setText(tr("&Graveyard")); aMoveToGraveyard->setText(tr("&Graveyard"));
aMoveToExile->setText(tr("&Exile")); aMoveToExile->setText(tr("&Exile"));

View file

@ -23,7 +23,6 @@ public:
QAction *aMoveToBottomLibrary = nullptr; QAction *aMoveToBottomLibrary = nullptr;
QAction *aMoveToHand = nullptr; QAction *aMoveToHand = nullptr;
QAction *aMoveToTable = nullptr;
QAction *aMoveToGraveyard = nullptr; QAction *aMoveToGraveyard = nullptr;
QAction *aMoveToExile = nullptr; QAction *aMoveToExile = nullptr;
}; };

View file

@ -15,24 +15,33 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
playerMenu = new TearOffMenu(); playerMenu = new TearOffMenu();
if (player->getPlayerInfo()->getLocalOrJudge()) { if (player->getPlayerInfo()->getLocalOrJudge()) {
handMenu = addManagedMenu<HandMenu>(player, player->getPlayerActions(), playerMenu); handMenu = new HandMenu(player, player->getPlayerActions(), playerMenu);
libraryMenu = addManagedMenu<LibraryMenu>(player, playerMenu); playerMenu->addMenu(handMenu);
libraryMenu = new LibraryMenu(player, playerMenu);
playerMenu->addMenu(libraryMenu);
} else { } else {
handMenu = nullptr; handMenu = nullptr;
libraryMenu = nullptr; libraryMenu = nullptr;
} }
graveMenu = addManagedMenu<GraveyardMenu>(player, playerMenu); graveMenu = new GraveyardMenu(player, playerMenu);
rfgMenu = addManagedMenu<RfgMenu>(player, playerMenu); playerMenu->addMenu(graveMenu);
rfgMenu = new RfgMenu(player, playerMenu);
playerMenu->addMenu(rfgMenu);
if (player->getPlayerInfo()->getLocalOrJudge()) { if (player->getPlayerInfo()->getLocalOrJudge()) {
sideboardMenu = addManagedMenu<SideboardMenu>(player, playerMenu); sideboardMenu = new SideboardMenu(player, playerMenu);
customZonesMenu = addManagedMenu<CustomZoneMenu>(player); playerMenu->addMenu(sideboardMenu);
customZonesMenu = new CustomZoneMenu(player);
playerMenu->addMenu(customZonesMenu);
playerMenu->addSeparator(); playerMenu->addSeparator();
countersMenu = playerMenu->addMenu(QString()); countersMenu = playerMenu->addMenu(QString());
utilityMenu = createManagedComponent<UtilityMenu>(player, playerMenu); utilityMenu = new UtilityMenu(player, playerMenu);
} else { } else {
sideboardMenu = nullptr; sideboardMenu = nullptr;
customZonesMenu = nullptr; customZonesMenu = nullptr;
@ -41,7 +50,8 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
} }
if (player->getPlayerInfo()->getLocal()) { if (player->getPlayerInfo()->getLocal()) {
sayMenu = addManagedMenu<SayMenu>(player); sayMenu = new SayMenu(player);
playerMenu->addMenu(sayMenu);
} else { } else {
sayMenu = nullptr; sayMenu = nullptr;
} }
@ -89,18 +99,40 @@ void PlayerMenu::retranslateUi()
{ {
playerMenu->setTitle(tr("Player \"%1\"").arg(player->getPlayerInfo()->getName())); playerMenu->setTitle(tr("Player \"%1\"").arg(player->getPlayerInfo()->getName()));
for (auto *component : managedComponents) { if (handMenu) {
component->retranslateUi(); handMenu->retranslateUi();
}
if (libraryMenu) {
libraryMenu->retranslateUi();
}
graveMenu->retranslateUi();
rfgMenu->retranslateUi();
if (sideboardMenu) {
sideboardMenu->retranslateUi();
} }
if (countersMenu) { if (countersMenu) {
countersMenu->setTitle(tr("&Counters")); countersMenu->setTitle(tr("&Counters"));
} }
if (customZonesMenu) {
customZonesMenu->retranslateUi();
}
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters()); QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
while (counterIterator.hasNext()) { while (counterIterator.hasNext()) {
counterIterator.next().value()->retranslateUi(); counterIterator.next().value()->retranslateUi();
} }
if (utilityMenu) {
utilityMenu->retranslateUi();
}
if (sayMenu) {
sayMenu->setTitle(tr("S&ay"));
}
} }
void PlayerMenu::refreshShortcuts() void PlayerMenu::refreshShortcuts()
@ -121,29 +153,52 @@ void PlayerMenu::setShortcutsActive()
{ {
shortcutsActive = true; shortcutsActive = true;
for (auto *component : managedComponents) { if (handMenu) {
component->setShortcutsActive(); handMenu->setShortcutsActive();
}
if (libraryMenu) {
libraryMenu->setShortcutsActive();
}
graveMenu->setShortcutsActive();
// No shortcuts for RfgMenu yet
if (sideboardMenu) {
sideboardMenu->setShortcutsActive();
} }
// Counters implement AbstractPlayerComponent but are iterated via Player::counters
// (the authoritative source) rather than managedComponents to avoid a redundant
// list that must stay in sync with the map.
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters()); QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
while (counterIterator.hasNext()) { while (counterIterator.hasNext()) {
counterIterator.next().value()->setShortcutsActive(); counterIterator.next().value()->setShortcutsActive();
} }
if (utilityMenu) {
utilityMenu->setShortcutsActive();
}
} }
void PlayerMenu::setShortcutsInactive() void PlayerMenu::setShortcutsInactive()
{ {
shortcutsActive = false; shortcutsActive = false;
for (auto *component : managedComponents) { if (handMenu) {
component->setShortcutsInactive(); handMenu->setShortcutsInactive();
}
if (libraryMenu) {
libraryMenu->setShortcutsInactive();
}
graveMenu->setShortcutsInactive();
// No shortcuts for RfgMenu yet
if (sideboardMenu) {
sideboardMenu->setShortcutsInactive();
} }
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters()); QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
while (counterIterator.hasNext()) { while (counterIterator.hasNext()) {
counterIterator.next().value()->setShortcutsInactive(); counterIterator.next().value()->setShortcutsInactive();
} }
if (utilityMenu) {
utilityMenu->setShortcutsInactive();
}
} }

View file

@ -1,7 +1,7 @@
/** /**
* @file player_menu.h * @file player_menu.h
* @ingroup GameMenusPlayers * @ingroup GameMenusPlayers
* @brief Orchestrates lifecycle management for all player-bound UI components. * @brief TODO: Document this.
*/ */
#ifndef COCKATRICE_PLAYER_MENU_H #ifndef COCKATRICE_PLAYER_MENU_H
@ -18,7 +18,6 @@
#include "sideboard_menu.h" #include "sideboard_menu.h"
#include "utility_menu.h" #include "utility_menu.h"
#include <QList>
#include <QMenu> #include <QMenu>
#include <QObject> #include <QObject>
@ -38,7 +37,6 @@ private slots:
public: public:
PlayerMenu(Player *player); PlayerMenu(Player *player);
/// Lifecycle methods: delegate to all managedComponents, plus counters separately via player->getCounters().
void retranslateUi(); void retranslateUi();
QMenu *updateCardMenu(const CardItem *card); QMenu *updateCardMenu(const CardItem *card);
@ -68,9 +66,7 @@ public:
return shortcutsActive; return shortcutsActive;
} }
/// Delegates to all managedComponents, plus counters separately.
void setShortcutsActive(); void setShortcutsActive();
/// Delegates to all managedComponents, plus counters separately.
void setShortcutsInactive(); void setShortcutsInactive();
private: private:
@ -86,26 +82,9 @@ private:
SayMenu *sayMenu; SayMenu *sayMenu;
CustomZoneMenu *customZonesMenu; CustomZoneMenu *customZonesMenu;
/// Drives AbstractPlayerComponent lifecycle delegation. Counters are iterated separately via player->getCounters(). bool shortcutsActive;
QList<AbstractPlayerComponent *> managedComponents;
bool shortcutsActive = false;
/// Creates component, adds it as a submenu of playerMenu, and registers in managedComponents. void initSayMenu();
template <typename MenuT, typename... Args> MenuT *addManagedMenu(Args &&...args)
{
auto *menu = new MenuT(std::forward<Args>(args)...);
playerMenu->addMenu(menu);
managedComponents.append(menu);
return menu;
}
/// Creates component and registers in managedComponents, but does NOT add it as a submenu.
template <typename ComponentT, typename... Args> ComponentT *createManagedComponent(Args &&...args)
{
auto *component = new ComponentT(std::forward<Args>(args)...);
managedComponents.append(component);
return component;
}
}; };
#endif // COCKATRICE_PLAYER_MENU_H #endif // COCKATRICE_PLAYER_MENU_H

View file

@ -8,26 +8,19 @@
#define COCKATRICE_RFG_MENU_H #define COCKATRICE_RFG_MENU_H
#include "../../../interface/widgets/menus/tearoff_menu.h" #include "../../../interface/widgets/menus/tearoff_menu.h"
#include "abstract_player_component.h"
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
class Player; class Player;
class RfgMenu : public TearOffMenu, public AbstractPlayerComponent class RfgMenu : public TearOffMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit RfgMenu(Player *player, QWidget *parent = nullptr); explicit RfgMenu(Player *player, QWidget *parent = nullptr);
void createMoveActions(); void createMoveActions();
void createViewActions(); void createViewActions();
void retranslateUi() override; void retranslateUi();
void setShortcutsActive() override
{
}
void setShortcutsInactive() override
{
}
QMenu *moveRfgMenu = nullptr; QMenu *moveRfgMenu = nullptr;

View file

@ -8,31 +8,6 @@ SayMenu::SayMenu(Player *_player) : player(_player)
{ {
connect(&SettingsCache::instance().messages(), &MessageSettings::messageMacrosChanged, this, &SayMenu::initSayMenu); connect(&SettingsCache::instance().messages(), &MessageSettings::messageMacrosChanged, this, &SayMenu::initSayMenu);
initSayMenu(); initSayMenu();
retranslateUi();
}
void SayMenu::retranslateUi()
{
setTitle(tr("S&ay"));
}
void SayMenu::setShortcutsActive()
{
shortcutsActive = true;
const auto menuActions = actions();
for (int i = 0; i < menuActions.size() && i < 10; ++i) {
menuActions[i]->setShortcut(QKeySequence("Ctrl+" + QString::number((i + 1) % 10)));
}
}
void SayMenu::setShortcutsInactive()
{
shortcutsActive = false;
for (auto *action : actions()) {
action->setShortcut(QKeySequence());
}
} }
void SayMenu::initSayMenu() void SayMenu::initSayMenu()
@ -44,11 +19,10 @@ void SayMenu::initSayMenu()
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
auto *newAction = new QAction(SettingsCache::instance().messages().getMessageAt(i), this); auto *newAction = new QAction(SettingsCache::instance().messages().getMessageAt(i), this);
if (i < 10) {
newAction->setShortcut(QKeySequence("Ctrl+" + QString::number((i + 1) % 10)));
}
connect(newAction, &QAction::triggered, player->getPlayerActions(), &PlayerActions::actSayMessage); connect(newAction, &QAction::triggered, player->getPlayerActions(), &PlayerActions::actSayMessage);
addAction(newAction); addAction(newAction);
} }
if (shortcutsActive) {
setShortcutsActive();
}
} }

View file

@ -7,27 +7,18 @@
#ifndef COCKATRICE_SAY_MENU_H #ifndef COCKATRICE_SAY_MENU_H
#define COCKATRICE_SAY_MENU_H #define COCKATRICE_SAY_MENU_H
#include "abstract_player_component.h"
#include <QMenu> #include <QMenu>
class Player; class Player;
class SayMenu : public QMenu, public AbstractPlayerComponent class SayMenu : public QMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SayMenu(Player *player); explicit SayMenu(Player *player);
void retranslateUi() override;
void setShortcutsActive() override;
void setShortcutsInactive() override;
private slots:
void initSayMenu(); void initSayMenu();
private: private:
Player *player; Player *player;
bool shortcutsActive = false;
}; };
#endif // COCKATRICE_SAY_MENU_H #endif // COCKATRICE_SAY_MENU_H

View file

@ -7,20 +7,18 @@
#ifndef COCKATRICE_SIDEBOARD_MENU_H #ifndef COCKATRICE_SIDEBOARD_MENU_H
#define COCKATRICE_SIDEBOARD_MENU_H #define COCKATRICE_SIDEBOARD_MENU_H
#include "abstract_player_component.h"
#include <QMenu> #include <QMenu>
class Player; class Player;
class SideboardMenu : public QMenu, public AbstractPlayerComponent class SideboardMenu : public QMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SideboardMenu(Player *player, QMenu *playerMenu); explicit SideboardMenu(Player *player, QMenu *playerMenu);
void retranslateUi() override; void retranslateUi();
void setShortcutsActive() override; void setShortcutsActive();
void setShortcutsInactive() override; void setShortcutsInactive();
private: private:
Player *player; Player *player;

View file

@ -7,19 +7,17 @@
#ifndef COCKATRICE_UTILITY_MENU_H #ifndef COCKATRICE_UTILITY_MENU_H
#define COCKATRICE_UTILITY_MENU_H #define COCKATRICE_UTILITY_MENU_H
#include "abstract_player_component.h"
#include <QMenu> #include <QMenu>
class Player; class Player;
class UtilityMenu : public QMenu, public AbstractPlayerComponent class UtilityMenu : public QMenu
{ {
Q_OBJECT Q_OBJECT
public slots: public slots:
void populatePredefinedTokensMenu(); void populatePredefinedTokensMenu();
void retranslateUi() override; void retranslateUi();
void setShortcutsActive() override; void setShortcutsActive();
void setShortcutsInactive() override; void setShortcutsInactive();
public: public:
explicit UtilityMenu(Player *player, QMenu *playerMenu); explicit UtilityMenu(Player *player, QMenu *playerMenu);

View file

@ -64,7 +64,7 @@ void PlayerActions::playCard(CardItem *card, bool faceDown)
int tableRow = info.getUiAttributes().tableRow; int tableRow = info.getUiAttributes().tableRow;
bool playToStack = SettingsCache::instance().getPlayToStack(); bool playToStack = SettingsCache::instance().getPlayToStack();
QString currentZone = card->getZone()->getName(); QString currentZone = card->getZone()->getName();
if (!faceDown && currentZone == ZoneNames::STACK && tableRow == 3) { if (currentZone == ZoneNames::STACK && tableRow == 3) {
cmd.set_target_zone(ZoneNames::GRAVE); cmd.set_target_zone(ZoneNames::GRAVE);
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
@ -75,7 +75,7 @@ void PlayerActions::playCard(CardItem *card, bool faceDown)
cmd.set_y(0); cmd.set_y(0);
} else { } else {
tableRow = faceDown ? 2 : info.getUiAttributes().tableRow; tableRow = faceDown ? 2 : info.getUiAttributes().tableRow;
QPoint gridPoint = QPoint(-1, TableZone::tableRowToGridY(tableRow)); QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - tableRow));
cardToMove->set_face_down(faceDown); cardToMove->set_face_down(faceDown);
if (!faceDown) { if (!faceDown) {
cardToMove->set_pt(info.getPowTough().toStdString()); cardToMove->set_pt(info.getPowTough().toStdString());
@ -114,7 +114,12 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown)
const CardInfo &info = exactCard.getInfo(); const CardInfo &info = exactCard.getInfo();
int tableRow = faceDown ? 2 : info.getUiAttributes().tableRow; int tableRow = faceDown ? 2 : info.getUiAttributes().tableRow;
QPoint gridPoint = QPoint(-1, TableZone::tableRowToGridY(tableRow)); // default instant/sorcery cards to the noncreatures row
if (tableRow > 2) {
tableRow = 1;
}
QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - tableRow));
cardToMove->set_face_down(faceDown); cardToMove->set_face_down(faceDown);
if (!faceDown) { if (!faceDown) {
cardToMove->set_pt(info.getPowTough().toStdString()); cardToMove->set_pt(info.getPowTough().toStdString());
@ -861,7 +866,7 @@ void PlayerActions::actCreateToken()
ExactCard correctedCard = CardDatabaseManager::query()->guessCard({lastTokenInfo.name, lastTokenInfo.providerId}); ExactCard correctedCard = CardDatabaseManager::query()->guessCard({lastTokenInfo.name, lastTokenInfo.providerId});
if (correctedCard) { if (correctedCard) {
lastTokenInfo.name = correctedCard.getName(); lastTokenInfo.name = correctedCard.getName();
lastTokenTableRow = TableZone::tableRowToGridY(correctedCard.getInfo().getUiAttributes().tableRow); lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard.getInfo().getUiAttributes().tableRow);
if (lastTokenInfo.pt.isEmpty()) { if (lastTokenInfo.pt.isEmpty()) {
lastTokenInfo.pt = correctedCard.getInfo().getPowTough(); lastTokenInfo.pt = correctedCard.getInfo().getPowTough();
} }
@ -912,7 +917,7 @@ void PlayerActions::setLastToken(CardInfoPtr cardInfo)
.providerId = .providerId =
SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardInfo->getName())}; SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardInfo->getName())};
lastTokenTableRow = TableZone::tableRowToGridY(cardInfo->getUiAttributes().tableRow); lastTokenTableRow = TableZone::clampValidTableRow(2 - cardInfo->getUiAttributes().tableRow);
utilityMenu->setAndEnableCreateAnotherTokenAction(tr("C&reate another %1 token").arg(lastTokenInfo.name)); utilityMenu->setAndEnableCreateAnotherTokenAction(tr("C&reate another %1 token").arg(lastTokenInfo.name));
} }
@ -1080,7 +1085,9 @@ void PlayerActions::createCard(const CardItem *sourceCard,
return; return;
} }
QPoint gridPoint = QPoint(-1, TableZone::tableRowToGridY(cardInfo->getUiAttributes().tableRow)); // get the target token's location
// TODO: Define this QPoint into its own function along with the one below
QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - cardInfo->getUiAttributes().tableRow));
// create the token for the related card // create the token for the related card
Command_CreateToken cmd; Command_CreateToken cmd;
@ -1923,34 +1930,6 @@ void PlayerActions::cardMenuAction()
commandList.append(cmd); commandList.append(cmd);
break; break;
} }
case cmMoveToTable: {
// Each card needs its own command because table row, pt, and cipt vary per card
for (const auto &card : cardList) {
auto *cmd = new Command_MoveCard;
cmd->set_start_player_id(startPlayerId);
cmd->set_start_zone(startZone.toStdString());
cmd->set_target_player_id(player->getPlayerInfo()->getId());
cmd->set_target_zone(ZoneNames::TABLE);
cmd->set_x(-1);
CardToMove *ctm = cmd->mutable_cards_to_move()->add_card();
ctm->set_card_id(card->getId());
ctm->set_face_down(false);
int tableRow = 0;
ExactCard exactCard = card->getCard();
if (exactCard) {
const CardInfo &info = exactCard.getInfo();
tableRow = info.getUiAttributes().tableRow;
ctm->set_pt(info.getPowTough().toStdString());
ctm->set_tapped(info.getUiAttributes().cipt);
}
cmd->set_y(TableZone::tableRowToGridY(tableRow));
commandList.append(cmd);
}
break;
}
default: default:
break; break;
} }

View file

@ -382,11 +382,3 @@ int TableZone::clampValidTableRow(const int row)
return TABLEROWS - 1; return TABLEROWS - 1;
return row; return row;
} }
int TableZone::tableRowToGridY(int tableRow)
{
if (tableRow > 2) {
tableRow = 1;
}
return clampValidTableRow(2 - tableRow);
}

View file

@ -151,13 +151,6 @@ public:
static int clampValidTableRow(const int row); static int clampValidTableRow(const int row);
/**
* Converts a card's logical table row (0=creatures, 1=noncreatures, 2=lands)
* to the corresponding grid Y coordinate. Cards with tableRow > 2 (e.g.,
* instants/sorceries) default to the noncreatures row.
*/
static int tableRowToGridY(int tableRow);
/** /**
Resizes the TableZone in case CardItems are within or Resizes the TableZone in case CardItems are within or
outside of the TableZone constraints. outside of the TableZone constraints.

View file

@ -28,8 +28,8 @@ DlgLocalGameOptions::DlgLocalGameOptions(QWidget *parent) : QDialog(parent)
startingLifeTotalLabel = new QLabel(tr("Starting life total:"), this); startingLifeTotalLabel = new QLabel(tr("Starting life total:"), this);
startingLifeTotalEdit = new QSpinBox(this); startingLifeTotalEdit = new QSpinBox(this);
startingLifeTotalEdit->setMinimum(-999999999); startingLifeTotalEdit->setMinimum(1);
startingLifeTotalEdit->setMaximum(999999999); startingLifeTotalEdit->setMaximum(99999);
startingLifeTotalEdit->setValue(20); startingLifeTotalEdit->setValue(20);
startingLifeTotalLabel->setBuddy(startingLifeTotalEdit); startingLifeTotalLabel->setBuddy(startingLifeTotalEdit);

View file

@ -7,8 +7,8 @@
#include <QPainter> #include <QPainter>
#include <QVBoxLayout> #include <QVBoxLayout>
BannerWidget::BannerWidget(QWidget *parent, const QString &text, Qt::Orientation orientation, int transparency_) BannerWidget::BannerWidget(QWidget *parent, const QString &text, Qt::Orientation orientation, int transparency)
: QWidget(parent), gradientOrientation(orientation), transparency(qBound(0, transparency_, 100)) : QWidget(parent), gradientOrientation(orientation), transparency(qBound(0, transparency, 100))
{ {
auto layout = new QHBoxLayout(this); auto layout = new QHBoxLayout(this);
@ -18,12 +18,7 @@ BannerWidget::BannerWidget(QWidget *parent, const QString &text, Qt::Orientation
// Create the banner label and set properties // Create the banner label and set properties
bannerLabel = new QLabel(text, this); bannerLabel = new QLabel(text, this);
bannerLabel->setAlignment(Qt::AlignCenter); bannerLabel->setAlignment(Qt::AlignCenter);
bannerLabel->setStyleSheet("font-size: 24px; font-weight: bold; color: white;");
QString textColor;
if (transparency > 50) {
textColor = " color: white;";
}
bannerLabel->setStyleSheet("font-size: 24px; font-weight: bold;" + textColor);
layout->addWidget(iconLabel); layout->addWidget(iconLabel);
layout->addWidget(bannerLabel); layout->addWidget(bannerLabel);

@ -1 +1 @@
Subproject commit d52eafe3e9303399fda15661f3d7bb8fe3d7eabc Subproject commit 1f3620084ff75734ed192101acf40e9dff01d848

View file

@ -12,9 +12,9 @@ public:
virtual void setEnabled(QString shortName, bool enabled) = 0; virtual void setEnabled(QString shortName, bool enabled) = 0;
virtual void setIsKnown(QString shortName, bool isknown) = 0; virtual void setIsKnown(QString shortName, bool isknown) = 0;
virtual unsigned int getSortKey(QString shortName) const = 0; virtual unsigned int getSortKey(QString shortName) = 0;
virtual bool isEnabled(QString shortName) const = 0; virtual bool isEnabled(QString shortName) = 0;
virtual bool isKnown(QString shortName) const = 0; virtual bool isKnown(QString shortName) = 0;
}; };
#endif // COCKATRICE_INTERFACE_CARD_SET_PRIORITY_CONTROLLER_H #endif // COCKATRICE_INTERFACE_CARD_SET_PRIORITY_CONTROLLER_H

View file

@ -16,15 +16,15 @@ public:
{ {
} }
unsigned int getSortKey(QString /* shortName */) const override unsigned int getSortKey(QString /* shortName */) override
{ {
return 0; return 0;
} }
bool isEnabled(QString /* shortName */) const override bool isEnabled(QString /* shortName */) override
{ {
return true; return true;
} }
bool isKnown(QString /* shortName */) const override bool isKnown(QString /* shortName */) override
{ {
return true; return true;
} }

View file

@ -20,17 +20,17 @@ void CardDatabaseSettings::setIsKnown(QString shortName, bool isknown)
setValue(isknown, "isknown", "sets", std::move(shortName)); setValue(isknown, "isknown", "sets", std::move(shortName));
} }
unsigned int CardDatabaseSettings::getSortKey(QString shortName) const unsigned int CardDatabaseSettings::getSortKey(QString shortName)
{ {
return getValue("sortkey", "sets", std::move(shortName)).toUInt(); return getValue("sortkey", "sets", std::move(shortName)).toUInt();
} }
bool CardDatabaseSettings::isEnabled(QString shortName) const bool CardDatabaseSettings::isEnabled(QString shortName)
{ {
return getValue("enabled", "sets", std::move(shortName)).toBool(); return getValue("enabled", "sets", std::move(shortName)).toBool();
} }
bool CardDatabaseSettings::isKnown(QString shortName) const bool CardDatabaseSettings::isKnown(QString shortName)
{ {
return getValue("isknown", "sets", std::move(shortName)).toBool(); return getValue("isknown", "sets", std::move(shortName)).toBool();
} }

View file

@ -22,9 +22,9 @@ public:
void setEnabled(QString shortName, bool enabled) override; void setEnabled(QString shortName, bool enabled) override;
void setIsKnown(QString shortName, bool isknown) override; void setIsKnown(QString shortName, bool isknown) override;
unsigned int getSortKey(QString shortName) const override; unsigned int getSortKey(QString shortName) override;
bool isEnabled(QString shortName) const override; bool isEnabled(QString shortName) override;
bool isKnown(QString shortName) const override; bool isKnown(QString shortName) override;
private: private:
explicit CardDatabaseSettings(const QString &settingPath, QObject *parent = nullptr); explicit CardDatabaseSettings(const QString &settingPath, QObject *parent = nullptr);

View file

@ -15,7 +15,7 @@ void CardOverrideSettings::deleteCardPreferenceOverride(const QString &cardName)
deleteValue(cardName); deleteValue(cardName);
} }
QString CardOverrideSettings::getCardPreferenceOverride(const QString &cardName) const QString CardOverrideSettings::getCardPreferenceOverride(const QString &cardName)
{ {
return getValue(cardName).toString(); return getValue(cardName).toString();
} }

View file

@ -22,7 +22,7 @@ public:
void deleteCardPreferenceOverride(const QString &cardName); void deleteCardPreferenceOverride(const QString &cardName);
QString getCardPreferenceOverride(const QString &cardName) const; QString getCardPreferenceOverride(const QString &cardName);
private: private:
explicit CardOverrideSettings(const QString &settingPath, QObject *parent = nullptr); explicit CardOverrideSettings(const QString &settingPath, QObject *parent = nullptr);

View file

@ -11,22 +11,22 @@ DebugSettings::DebugSettings(const QString &settingPath, QObject *parent)
} }
} }
bool DebugSettings::getShowCardId() const bool DebugSettings::getShowCardId()
{ {
return getValue("showCardId").toBool(); return getValue("showCardId").toBool();
} }
bool DebugSettings::getLocalGameOnStartup() const bool DebugSettings::getLocalGameOnStartup()
{ {
return getValue("onStartup", "localgame").toBool(); return getValue("onStartup", "localgame").toBool();
} }
int DebugSettings::getLocalGamePlayerCount() const int DebugSettings::getLocalGamePlayerCount()
{ {
return getValue("playerCount", "localgame").toInt(); return getValue("playerCount", "localgame").toInt();
} }
QString DebugSettings::getDeckPathForPlayer(const QString &playerName) const QString DebugSettings::getDeckPathForPlayer(const QString &playerName)
{ {
return getValue(playerName, "localgame", "deck").toString(); return getValue(playerName, "localgame", "deck").toString();
} }

View file

@ -17,12 +17,12 @@ class DebugSettings : public SettingsManager
DebugSettings(const DebugSettings & /*other*/); DebugSettings(const DebugSettings & /*other*/);
public: public:
bool getShowCardId() const; bool getShowCardId();
bool getLocalGameOnStartup() const; bool getLocalGameOnStartup();
int getLocalGamePlayerCount() const; int getLocalGamePlayerCount();
QString getDeckPathForPlayer(const QString &playerName) const; QString getDeckPathForPlayer(const QString &playerName);
}; };
#endif // DEBUG_SETTINGS_H #endif // DEBUG_SETTINGS_H

View file

@ -18,7 +18,7 @@ void DownloadSettings::setDownloadUrls(const QStringList &downloadURLs)
setValue(QVariant::fromValue(downloadURLs), "urls"); setValue(QVariant::fromValue(downloadURLs), "urls");
} }
QStringList DownloadSettings::getAllURLs() const QStringList DownloadSettings::getAllURLs()
{ {
return getValue("urls").toStringList(); return getValue("urls").toStringList();
} }

View file

@ -19,7 +19,7 @@ class DownloadSettings : public SettingsManager
public: public:
explicit DownloadSettings(const QString &, QObject *); explicit DownloadSettings(const QString &, QObject *);
QStringList getAllURLs() const; QStringList getAllURLs();
void setDownloadUrls(const QStringList &downloadURLs); void setDownloadUrls(const QStringList &downloadURLs);
void resetToDefaultURLs(); void resetToDefaultURLs();
}; };

View file

@ -8,11 +8,11 @@ GameFiltersSettings::GameFiltersSettings(const QString &settingPath, QObject *pa
{ {
} }
/** /*
* The game type might contain special characters, so to use it in * The game type might contain special characters, so to use it in
* QSettings we just hash it. * QSettings we just hash it.
*/ */
static QString hashGameType(const QString &gameType) QString GameFiltersSettings::hashGameType(const QString &gameType) const
{ {
return QCryptographicHash::hash(gameType.toUtf8(), QCryptographicHash::Md5).toHex(); return QCryptographicHash::hash(gameType.toUtf8(), QCryptographicHash::Md5).toHex();
} }
@ -22,7 +22,7 @@ void GameFiltersSettings::setHideBuddiesOnlyGames(bool hide)
setValue(hide, "hide_buddies_only_games"); setValue(hide, "hide_buddies_only_games");
} }
bool GameFiltersSettings::isHideBuddiesOnlyGames() const bool GameFiltersSettings::isHideBuddiesOnlyGames()
{ {
QVariant previous = getValue("hide_buddies_only_games"); QVariant previous = getValue("hide_buddies_only_games");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -33,7 +33,7 @@ void GameFiltersSettings::setHideFullGames(bool hide)
setValue(hide, "hide_full_games"); setValue(hide, "hide_full_games");
} }
bool GameFiltersSettings::isHideFullGames() const bool GameFiltersSettings::isHideFullGames()
{ {
QVariant previous = getValue("hide_full_games"); QVariant previous = getValue("hide_full_games");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -44,7 +44,7 @@ void GameFiltersSettings::setHideGamesThatStarted(bool hide)
setValue(hide, "hide_games_that_started"); setValue(hide, "hide_games_that_started");
} }
bool GameFiltersSettings::isHideGamesThatStarted() const bool GameFiltersSettings::isHideGamesThatStarted()
{ {
QVariant previous = getValue("hide_games_that_started"); QVariant previous = getValue("hide_games_that_started");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -55,7 +55,7 @@ void GameFiltersSettings::setHidePasswordProtectedGames(bool hide)
setValue(hide, "hide_password_protected_games"); setValue(hide, "hide_password_protected_games");
} }
bool GameFiltersSettings::isHidePasswordProtectedGames() const bool GameFiltersSettings::isHidePasswordProtectedGames()
{ {
QVariant previous = getValue("hide_password_protected_games"); QVariant previous = getValue("hide_password_protected_games");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -66,7 +66,7 @@ void GameFiltersSettings::setHideIgnoredUserGames(bool hide)
setValue(hide, "hide_ignored_user_games"); setValue(hide, "hide_ignored_user_games");
} }
bool GameFiltersSettings::isHideIgnoredUserGames() const bool GameFiltersSettings::isHideIgnoredUserGames()
{ {
QVariant previous = getValue("hide_ignored_user_games"); QVariant previous = getValue("hide_ignored_user_games");
return previous == QVariant() ? true : previous.toBool(); return previous == QVariant() ? true : previous.toBool();
@ -77,7 +77,7 @@ void GameFiltersSettings::setHideNotBuddyCreatedGames(bool hide)
setValue(hide, "hide_not_buddy_created_games"); setValue(hide, "hide_not_buddy_created_games");
} }
bool GameFiltersSettings::isHideNotBuddyCreatedGames() const bool GameFiltersSettings::isHideNotBuddyCreatedGames()
{ {
QVariant previous = getValue("hide_not_buddy_created_games"); QVariant previous = getValue("hide_not_buddy_created_games");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -88,7 +88,7 @@ void GameFiltersSettings::setHideOpenDecklistGames(bool hide)
setValue(hide, "hide_open_decklist_games"); setValue(hide, "hide_open_decklist_games");
} }
bool GameFiltersSettings::isHideOpenDecklistGames() const bool GameFiltersSettings::isHideOpenDecklistGames()
{ {
QVariant previous = getValue("hide_open_decklist_games"); QVariant previous = getValue("hide_open_decklist_games");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -99,7 +99,7 @@ void GameFiltersSettings::setGameNameFilter(QString gameName)
setValue(gameName, "game_name_filter"); setValue(gameName, "game_name_filter");
} }
QString GameFiltersSettings::getGameNameFilter() const QString GameFiltersSettings::getGameNameFilter()
{ {
return getValue("game_name_filter").toString(); return getValue("game_name_filter").toString();
} }
@ -109,7 +109,7 @@ void GameFiltersSettings::setCreatorNameFilters(QStringList creatorName)
setValue(creatorName, "creator_name_filter"); setValue(creatorName, "creator_name_filter");
} }
QStringList GameFiltersSettings::getCreatorNameFilters() const QStringList GameFiltersSettings::getCreatorNameFilters()
{ {
return getValue("creator_name_filter").toStringList(); return getValue("creator_name_filter").toStringList();
} }
@ -119,7 +119,7 @@ void GameFiltersSettings::setMinPlayers(int min)
setValue(min, "min_players"); setValue(min, "min_players");
} }
int GameFiltersSettings::getMinPlayers() const int GameFiltersSettings::getMinPlayers()
{ {
QVariant previous = getValue("min_players"); QVariant previous = getValue("min_players");
return previous == QVariant() ? 1 : previous.toInt(); return previous == QVariant() ? 1 : previous.toInt();
@ -130,7 +130,7 @@ void GameFiltersSettings::setMaxPlayers(int max)
setValue(max, "max_players"); setValue(max, "max_players");
} }
int GameFiltersSettings::getMaxPlayers() const int GameFiltersSettings::getMaxPlayers()
{ {
QVariant previous = getValue("max_players"); QVariant previous = getValue("max_players");
return previous == QVariant() ? 99 : previous.toInt(); return previous == QVariant() ? 99 : previous.toInt();
@ -141,7 +141,7 @@ void GameFiltersSettings::setMaxGameAge(const QTime &maxGameAge)
setValue(maxGameAge, "max_game_age_time"); setValue(maxGameAge, "max_game_age_time");
} }
QTime GameFiltersSettings::getMaxGameAge() const QTime GameFiltersSettings::getMaxGameAge()
{ {
QVariant previous = getValue("max_game_age_time"); QVariant previous = getValue("max_game_age_time");
return previous.toTime(); return previous.toTime();
@ -157,7 +157,7 @@ void GameFiltersSettings::setGameHashedTypeEnabled(QString gametypeHASHED, bool
setValue(enabled, gametypeHASHED); setValue(enabled, gametypeHASHED);
} }
bool GameFiltersSettings::isGameTypeEnabled(QString gametype) const bool GameFiltersSettings::isGameTypeEnabled(QString gametype)
{ {
QVariant previous = getValue("game_type/" + hashGameType(gametype)); QVariant previous = getValue("game_type/" + hashGameType(gametype));
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -168,7 +168,7 @@ void GameFiltersSettings::setShowOnlyIfSpectatorsCanWatch(bool show)
setValue(show, "show_only_if_spectators_can_watch"); setValue(show, "show_only_if_spectators_can_watch");
} }
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanWatch() const bool GameFiltersSettings::isShowOnlyIfSpectatorsCanWatch()
{ {
QVariant previous = getValue("show_only_if_spectators_can_watch"); QVariant previous = getValue("show_only_if_spectators_can_watch");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -179,7 +179,7 @@ void GameFiltersSettings::setShowSpectatorPasswordProtected(bool show)
setValue(show, "show_spectator_password_protected"); setValue(show, "show_spectator_password_protected");
} }
bool GameFiltersSettings::isShowSpectatorPasswordProtected() const bool GameFiltersSettings::isShowSpectatorPasswordProtected()
{ {
QVariant previous = getValue("show_spectator_password_protected"); QVariant previous = getValue("show_spectator_password_protected");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -190,7 +190,7 @@ void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show)
setValue(show, "show_only_if_spectators_can_chat"); setValue(show, "show_only_if_spectators_can_chat");
} }
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanChat() const bool GameFiltersSettings::isShowOnlyIfSpectatorsCanChat()
{ {
QVariant previous = getValue("show_only_if_spectators_can_chat"); QVariant previous = getValue("show_only_if_spectators_can_chat");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
@ -201,7 +201,7 @@ void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show)
setValue(show, "show_only_if_spectators_can_see_hands"); setValue(show, "show_only_if_spectators_can_see_hands");
} }
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanSeeHands() const bool GameFiltersSettings::isShowOnlyIfSpectatorsCanSeeHands()
{ {
QVariant previous = getValue("show_only_if_spectators_can_see_hands"); QVariant previous = getValue("show_only_if_spectators_can_see_hands");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();

View file

@ -16,23 +16,23 @@ class GameFiltersSettings : public SettingsManager
friend class SettingsCache; friend class SettingsCache;
public: public:
bool isHideBuddiesOnlyGames() const; bool isHideBuddiesOnlyGames();
bool isHideFullGames() const; bool isHideFullGames();
bool isHideGamesThatStarted() const; bool isHideGamesThatStarted();
bool isHidePasswordProtectedGames() const; bool isHidePasswordProtectedGames();
bool isHideIgnoredUserGames() const; bool isHideIgnoredUserGames();
bool isHideNotBuddyCreatedGames() const; bool isHideNotBuddyCreatedGames();
bool isHideOpenDecklistGames() const; bool isHideOpenDecklistGames();
QString getGameNameFilter() const; QString getGameNameFilter();
QStringList getCreatorNameFilters() const; QStringList getCreatorNameFilters();
int getMinPlayers() const; int getMinPlayers();
int getMaxPlayers() const; int getMaxPlayers();
QTime getMaxGameAge() const; QTime getMaxGameAge();
bool isGameTypeEnabled(QString gametype) const; bool isGameTypeEnabled(QString gametype);
bool isShowOnlyIfSpectatorsCanWatch() const; bool isShowOnlyIfSpectatorsCanWatch();
bool isShowSpectatorPasswordProtected() const; bool isShowSpectatorPasswordProtected();
bool isShowOnlyIfSpectatorsCanChat() const; bool isShowOnlyIfSpectatorsCanChat();
bool isShowOnlyIfSpectatorsCanSeeHands() const; bool isShowOnlyIfSpectatorsCanSeeHands();
void setHideBuddiesOnlyGames(bool hide); void setHideBuddiesOnlyGames(bool hide);
void setHideIgnoredUserGames(bool hide); void setHideIgnoredUserGames(bool hide);
@ -56,6 +56,8 @@ public:
private: private:
explicit GameFiltersSettings(const QString &settingPath, QObject *parent = nullptr); explicit GameFiltersSettings(const QString &settingPath, QObject *parent = nullptr);
GameFiltersSettings(const GameFiltersSettings & /*other*/); GameFiltersSettings(const GameFiltersSettings & /*other*/);
[[nodiscard]] QString hashGameType(const QString &gameType) const;
}; };
#endif // GAMEFILTERSSETTINGS_H #endif // GAMEFILTERSSETTINGS_H

View file

@ -23,12 +23,12 @@ void LayoutsSettings::setMainWindowGeometry(const QByteArray &value)
setValue(value, GEOMETRY_PROP, GROUP_MAIN_WINDOW); setValue(value, GEOMETRY_PROP, GROUP_MAIN_WINDOW);
} }
QByteArray LayoutsSettings::getMainWindowGeometry() const QByteArray LayoutsSettings::getMainWindowGeometry()
{ {
return getValue(GEOMETRY_PROP, GROUP_MAIN_WINDOW).toByteArray(); return getValue(GEOMETRY_PROP, GROUP_MAIN_WINDOW).toByteArray();
} }
QByteArray LayoutsSettings::getDeckEditorLayoutState() const QByteArray LayoutsSettings::getDeckEditorLayoutState()
{ {
return getValue(STATE_PROP, GROUP_DECK_EDITOR).toByteArray(); return getValue(STATE_PROP, GROUP_DECK_EDITOR).toByteArray();
} }
@ -38,7 +38,7 @@ void LayoutsSettings::setDeckEditorLayoutState(const QByteArray &value)
setValue(value, STATE_PROP, GROUP_DECK_EDITOR); setValue(value, STATE_PROP, GROUP_DECK_EDITOR);
} }
QByteArray LayoutsSettings::getDeckEditorGeometry() const QByteArray LayoutsSettings::getDeckEditorGeometry()
{ {
return getValue(GEOMETRY_PROP, GROUP_DECK_EDITOR).toByteArray(); return getValue(GEOMETRY_PROP, GROUP_DECK_EDITOR).toByteArray();
} }
@ -48,7 +48,7 @@ void LayoutsSettings::setDeckEditorGeometry(const QByteArray &value)
setValue(value, GEOMETRY_PROP, GROUP_DECK_EDITOR); setValue(value, GEOMETRY_PROP, GROUP_DECK_EDITOR);
} }
QByteArray LayoutsSettings::getVisualDeckEditorLayoutState() const QByteArray LayoutsSettings::getVisualDeckEditorLayoutState()
{ {
return getValue(STATE_PROP, GROUP_VISUAL_DECK_EDITOR).toByteArray(); return getValue(STATE_PROP, GROUP_VISUAL_DECK_EDITOR).toByteArray();
} }
@ -58,7 +58,7 @@ void LayoutsSettings::setVisualDeckEditorLayoutState(const QByteArray &value)
setValue(value, STATE_PROP, GROUP_VISUAL_DECK_EDITOR); setValue(value, STATE_PROP, GROUP_VISUAL_DECK_EDITOR);
} }
QByteArray LayoutsSettings::getVisualDeckEditorGeometry() const QByteArray LayoutsSettings::getVisualDeckEditorGeometry()
{ {
return getValue(GEOMETRY_PROP, GROUP_VISUAL_DECK_EDITOR).toByteArray(); return getValue(GEOMETRY_PROP, GROUP_VISUAL_DECK_EDITOR).toByteArray();
} }
@ -68,7 +68,7 @@ void LayoutsSettings::setVisualDeckEditorGeometry(const QByteArray &value)
setValue(value, GEOMETRY_PROP, GROUP_VISUAL_DECK_EDITOR); setValue(value, GEOMETRY_PROP, GROUP_VISUAL_DECK_EDITOR);
} }
QByteArray LayoutsSettings::getDeckEditorDbHeaderState() const QByteArray LayoutsSettings::getDeckEditorDbHeaderState()
{ {
return getValue(STATE_PROP, GROUP_DECK_EDITOR_DB, "header").toByteArray(); return getValue(STATE_PROP, GROUP_DECK_EDITOR_DB, "header").toByteArray();
} }
@ -78,7 +78,7 @@ void LayoutsSettings::setDeckEditorDbHeaderState(const QByteArray &value)
setValue(value, STATE_PROP, GROUP_DECK_EDITOR_DB, "header"); setValue(value, STATE_PROP, GROUP_DECK_EDITOR_DB, "header");
} }
QByteArray LayoutsSettings::getSetsDialogHeaderState() const QByteArray LayoutsSettings::getSetsDialogHeaderState()
{ {
return getValue(STATE_PROP, GROUP_SETS_DIALOG, "header").toByteArray(); return getValue(STATE_PROP, GROUP_SETS_DIALOG, "header").toByteArray();
} }
@ -93,7 +93,7 @@ void LayoutsSettings::setSetsDialogGeometry(const QByteArray &value)
setValue(value, GEOMETRY_PROP, GROUP_SETS_DIALOG); setValue(value, GEOMETRY_PROP, GROUP_SETS_DIALOG);
} }
QByteArray LayoutsSettings::getSetsDialogGeometry() const QByteArray LayoutsSettings::getSetsDialogGeometry()
{ {
return getValue(GEOMETRY_PROP, GROUP_SETS_DIALOG).toByteArray(); return getValue(GEOMETRY_PROP, GROUP_SETS_DIALOG).toByteArray();
} }
@ -103,7 +103,7 @@ void LayoutsSettings::setTokenDialogGeometry(const QByteArray &value)
setValue(value, GEOMETRY_PROP, GROUP_TOKEN_DIALOG); setValue(value, GEOMETRY_PROP, GROUP_TOKEN_DIALOG);
} }
QByteArray LayoutsSettings::getTokenDialogGeometry() const QByteArray LayoutsSettings::getTokenDialogGeometry()
{ {
return getValue(GEOMETRY_PROP, GROUP_TOKEN_DIALOG).toByteArray(); return getValue(GEOMETRY_PROP, GROUP_TOKEN_DIALOG).toByteArray();
} }
@ -118,12 +118,12 @@ void LayoutsSettings::setGamePlayAreaState(const QByteArray &value)
setValue(value, STATE_PROP, GROUP_GAME_PLAY_AREA); setValue(value, STATE_PROP, GROUP_GAME_PLAY_AREA);
} }
QByteArray LayoutsSettings::getGamePlayAreaLayoutState() const QByteArray LayoutsSettings::getGamePlayAreaLayoutState()
{ {
return getValue(STATE_PROP, GROUP_GAME_PLAY_AREA).toByteArray(); return getValue(STATE_PROP, GROUP_GAME_PLAY_AREA).toByteArray();
} }
QByteArray LayoutsSettings::getGamePlayAreaGeometry() const QByteArray LayoutsSettings::getGamePlayAreaGeometry()
{ {
return getValue(GEOMETRY_PROP, GROUP_GAME_PLAY_AREA).toByteArray(); return getValue(GEOMETRY_PROP, GROUP_GAME_PLAY_AREA).toByteArray();
} }
@ -138,12 +138,12 @@ void LayoutsSettings::setReplayPlayAreaState(const QByteArray &value)
setValue(value, STATE_PROP, GROUP_REPLAY_PLAY_AREA); setValue(value, STATE_PROP, GROUP_REPLAY_PLAY_AREA);
} }
QByteArray LayoutsSettings::getReplayPlayAreaLayoutState() const QByteArray LayoutsSettings::getReplayPlayAreaLayoutState()
{ {
return getValue(STATE_PROP, GROUP_REPLAY_PLAY_AREA).toByteArray(); return getValue(STATE_PROP, GROUP_REPLAY_PLAY_AREA).toByteArray();
} }
QByteArray LayoutsSettings::getReplayPlayAreaGeometry() const QByteArray LayoutsSettings::getReplayPlayAreaGeometry()
{ {
return getValue(GEOMETRY_PROP, GROUP_REPLAY_PLAY_AREA).toByteArray(); return getValue(GEOMETRY_PROP, GROUP_REPLAY_PLAY_AREA).toByteArray();
} }

View file

@ -36,24 +36,24 @@ public:
void setReplayPlayAreaGeometry(const QByteArray &value); void setReplayPlayAreaGeometry(const QByteArray &value);
void setReplayPlayAreaState(const QByteArray &value); void setReplayPlayAreaState(const QByteArray &value);
QByteArray getMainWindowGeometry() const; QByteArray getMainWindowGeometry();
QByteArray getDeckEditorLayoutState() const; QByteArray getDeckEditorLayoutState();
QByteArray getDeckEditorGeometry() const; QByteArray getDeckEditorGeometry();
QByteArray getVisualDeckEditorLayoutState() const; QByteArray getVisualDeckEditorLayoutState();
QByteArray getVisualDeckEditorGeometry() const; QByteArray getVisualDeckEditorGeometry();
QByteArray getDeckEditorDbHeaderState() const; QByteArray getDeckEditorDbHeaderState();
QByteArray getSetsDialogHeaderState() const; QByteArray getSetsDialogHeaderState();
QByteArray getSetsDialogGeometry() const; QByteArray getSetsDialogGeometry();
QByteArray getTokenDialogGeometry() const; QByteArray getTokenDialogGeometry();
QByteArray getGamePlayAreaLayoutState() const; QByteArray getGamePlayAreaLayoutState();
QByteArray getGamePlayAreaGeometry() const; QByteArray getGamePlayAreaGeometry();
QByteArray getReplayPlayAreaLayoutState() const; QByteArray getReplayPlayAreaLayoutState();
QByteArray getReplayPlayAreaGeometry() const; QByteArray getReplayPlayAreaGeometry();
signals: signals:
public slots: public slots:

View file

@ -5,12 +5,12 @@ MessageSettings::MessageSettings(const QString &settingPath, QObject *parent)
{ {
} }
QString MessageSettings::getMessageAt(int index) const QString MessageSettings::getMessageAt(int index)
{ {
return getValue(QString("msg%1").arg(index)).toString(); return getValue(QString("msg%1").arg(index)).toString();
} }
int MessageSettings::getCount() const int MessageSettings::getCount()
{ {
return getValue("count").toInt(); return getValue("count").toInt();
} }

View file

@ -15,8 +15,8 @@ class MessageSettings : public SettingsManager
friend class SettingsCache; friend class SettingsCache;
public: public:
int getCount() const; int getCount();
QString getMessageAt(int index) const; QString getMessageAt(int index);
void setCount(int count); void setCount(int count);
void setMessageAt(int index, QString message); void setMessageAt(int index, QString message);

View file

@ -7,7 +7,7 @@ RecentsSettings::RecentsSettings(const QString &settingPath, QObject *parent)
{ {
} }
QStringList RecentsSettings::getRecentlyOpenedDeckPaths() const QStringList RecentsSettings::getRecentlyOpenedDeckPaths()
{ {
return getValue("deckpaths").toStringList(); return getValue("deckpaths").toStringList();
} }
@ -31,7 +31,7 @@ void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath)
emit recentlyOpenedDeckPathsChanged(); emit recentlyOpenedDeckPathsChanged();
} }
QString RecentsSettings::getLatestDeckDirPath() const QString RecentsSettings::getLatestDeckDirPath()
{ {
return getValue("latestDeckDir", "dirs").toString(); return getValue("latestDeckDir", "dirs").toString();
} }

View file

@ -18,11 +18,11 @@ class RecentsSettings : public SettingsManager
RecentsSettings(const RecentsSettings & /*other*/); RecentsSettings(const RecentsSettings & /*other*/);
public: public:
QStringList getRecentlyOpenedDeckPaths() const; QStringList getRecentlyOpenedDeckPaths();
void clearRecentlyOpenedDeckPaths(); void clearRecentlyOpenedDeckPaths();
void updateRecentlyOpenedDeckPaths(const QString &deckPath); void updateRecentlyOpenedDeckPaths(const QString &deckPath);
QString getLatestDeckDirPath() const; QString getLatestDeckDirPath();
void setLatestDeckDirPath(const QString &dirPath); void setLatestDeckDirPath(const QString &dirPath);
signals: signals:

View file

@ -13,7 +13,7 @@ void ServersSettings::setPreviousHostLogin(int previous)
setValue(previous, "previoushostlogin"); setValue(previous, "previoushostlogin");
} }
int ServersSettings::getPreviousHostLogin() const int ServersSettings::getPreviousHostLogin()
{ {
QVariant previous = getValue("previoushostlogin"); QVariant previous = getValue("previoushostlogin");
return previous == QVariant() ? 1 : previous.toInt(); return previous == QVariant() ? 1 : previous.toInt();
@ -24,7 +24,7 @@ void ServersSettings::setPreviousHostList(QStringList list)
setValue(list, "previoushosts"); setValue(list, "previoushosts");
} }
QStringList ServersSettings::getPreviousHostList() const QStringList ServersSettings::getPreviousHostList()
{ {
return getValue("previoushosts").toStringList(); return getValue("previoushosts").toStringList();
} }
@ -48,13 +48,13 @@ QString ServersSettings::getSite(QString defaultSite)
return site == QVariant() ? std::move(defaultSite) : site.toString(); return site == QVariant() ? std::move(defaultSite) : site.toString();
} }
QString ServersSettings::getPrevioushostName() const QString ServersSettings::getPrevioushostName()
{ {
QVariant value = getValue("previoushostName"); QVariant value = getValue("previoushostName");
return value == QVariant() ? "Rooster Ranges" : value.toString(); return value == QVariant() ? "Rooster Ranges" : value.toString();
} }
int ServersSettings::getPrevioushostindex(const QString &saveName) const int ServersSettings::getPrevioushostindex(const QString &saveName)
{ {
int size = getValue("totalServers", "server", "server_details").toInt(); int size = getValue("totalServers", "server", "server_details").toInt();
@ -65,14 +65,14 @@ int ServersSettings::getPrevioushostindex(const QString &saveName) const
return -1; return -1;
} }
QString ServersSettings::getHostname(QString defaultHost) const QString ServersSettings::getHostname(QString defaultHost)
{ {
int index = getPrevioushostindex(getPrevioushostName()); int index = getPrevioushostindex(getPrevioushostName());
QVariant hostname = getValue(QString("server%1").arg(index), "server", "server_details"); QVariant hostname = getValue(QString("server%1").arg(index), "server", "server_details");
return hostname == QVariant() ? std::move(defaultHost) : hostname.toString(); return hostname == QVariant() ? std::move(defaultHost) : hostname.toString();
} }
QString ServersSettings::getPort(QString defaultPort) const QString ServersSettings::getPort(QString defaultPort)
{ {
int index = getPrevioushostindex(getPrevioushostName()); int index = getPrevioushostindex(getPrevioushostName());
QVariant port = getValue(QString("port%1").arg(index), "server", "server_details"); QVariant port = getValue(QString("port%1").arg(index), "server", "server_details");
@ -80,7 +80,7 @@ QString ServersSettings::getPort(QString defaultPort) const
return port == QVariant() ? std::move(defaultPort) : port.toString(); return port == QVariant() ? std::move(defaultPort) : port.toString();
} }
QString ServersSettings::getPlayerName(QString defaultName) const QString ServersSettings::getPlayerName(QString defaultName)
{ {
int index = getPrevioushostindex(getPrevioushostName()); int index = getPrevioushostindex(getPrevioushostName());
QVariant name = getValue(QString("username%1").arg(index), "server", "server_details"); QVariant name = getValue(QString("username%1").arg(index), "server", "server_details");
@ -98,7 +98,7 @@ QString ServersSettings::getPassword()
return QString(); return QString();
} }
bool ServersSettings::getSavePassword() const bool ServersSettings::getSavePassword()
{ {
int index = getPrevioushostindex(getPrevioushostName()); int index = getPrevioushostindex(getPrevioushostName());
bool save = getValue(QString("savePassword%1").arg(index), "server", "server_details").toBool(); bool save = getValue(QString("savePassword%1").arg(index), "server", "server_details").toBool();
@ -110,7 +110,7 @@ void ServersSettings::setAutoConnect(int autoconnect)
setValue(autoconnect, "auto_connect"); setValue(autoconnect, "auto_connect");
} }
int ServersSettings::getAutoConnect() const int ServersSettings::getAutoConnect()
{ {
QVariant autoconnect = getValue("auto_connect"); QVariant autoconnect = getValue("auto_connect");
return autoconnect == QVariant() ? 0 : autoconnect.toInt(); return autoconnect == QVariant() ? 0 : autoconnect.toInt();
@ -121,7 +121,7 @@ void ServersSettings::setFPHostName(QString hostname)
setValue(hostname, "fphostname"); setValue(hostname, "fphostname");
} }
QString ServersSettings::getFPHostname(QString defaultHost) const QString ServersSettings::getFPHostname(QString defaultHost)
{ {
QVariant hostname = getValue("fphostname"); QVariant hostname = getValue("fphostname");
return hostname == QVariant() ? std::move(defaultHost) : hostname.toString(); return hostname == QVariant() ? std::move(defaultHost) : hostname.toString();
@ -132,7 +132,7 @@ void ServersSettings::setFPPort(QString port)
setValue(port, "fpport"); setValue(port, "fpport");
} }
QString ServersSettings::getFPPort(QString defaultPort) const QString ServersSettings::getFPPort(QString defaultPort)
{ {
QVariant port = getValue("fpport"); QVariant port = getValue("fpport");
return port == QVariant() ? std::move(defaultPort) : port.toString(); return port == QVariant() ? std::move(defaultPort) : port.toString();
@ -143,7 +143,7 @@ void ServersSettings::setFPPlayerName(QString playerName)
setValue(playerName, "fpplayername"); setValue(playerName, "fpplayername");
} }
QString ServersSettings::getFPPlayerName(QString defaultName) const QString ServersSettings::getFPPlayerName(QString defaultName)
{ {
QVariant name = getValue("fpplayername"); QVariant name = getValue("fpplayername");
return name == QVariant() ? std::move(defaultName) : name.toString(); return name == QVariant() ? std::move(defaultName) : name.toString();
@ -154,7 +154,7 @@ void ServersSettings::setClearDebugLogStatus(bool abIsChecked)
setValue(abIsChecked, "save_debug_log"); setValue(abIsChecked, "save_debug_log");
} }
bool ServersSettings::getClearDebugLogStatus(bool abDefaultValue) const bool ServersSettings::getClearDebugLogStatus(bool abDefaultValue)
{ {
QVariant cbFlushLog = getValue("save_debug_log"); QVariant cbFlushLog = getValue("save_debug_log");
return cbFlushLog == QVariant() ? abDefaultValue : cbFlushLog.toBool(); return cbFlushLog == QVariant() ? abDefaultValue : cbFlushLog.toBool();

View file

@ -22,21 +22,21 @@ class ServersSettings : public SettingsManager
friend class SettingsCache; friend class SettingsCache;
public: public:
int getPreviousHostLogin() const; int getPreviousHostLogin();
int getPrevioushostindex(const QString &) const; int getPrevioushostindex(const QString &);
QStringList getPreviousHostList() const; QStringList getPreviousHostList();
QString getPrevioushostName() const; QString getPrevioushostName();
QString getHostname(QString defaultHost = SERVERSETTINGS_DEFAULT_HOST) const; QString getHostname(QString defaultHost = SERVERSETTINGS_DEFAULT_HOST);
QString getPort(QString defaultPort = SERVERSETTINGS_DEFAULT_PORT) const; QString getPort(QString defaultPort = SERVERSETTINGS_DEFAULT_PORT);
QString getPlayerName(QString defaultName = "") const; QString getPlayerName(QString defaultName = "");
QString getFPHostname(QString defaultHost = SERVERSETTINGS_DEFAULT_HOST) const; QString getFPHostname(QString defaultHost = SERVERSETTINGS_DEFAULT_HOST);
QString getFPPort(QString defaultPort = SERVERSETTINGS_DEFAULT_PORT) const; QString getFPPort(QString defaultPort = SERVERSETTINGS_DEFAULT_PORT);
QString getFPPlayerName(QString defaultName = "") const; QString getFPPlayerName(QString defaultName = "");
QString getPassword(); QString getPassword();
QString getSaveName(QString defaultname = ""); QString getSaveName(QString defaultname = "");
QString getSite(QString defaultName = ""); QString getSite(QString defaultName = "");
bool getSavePassword() const; bool getSavePassword();
int getAutoConnect() const; int getAutoConnect();
void setPreviousHostLogin(int previous); void setPreviousHostLogin(int previous);
void setPrevioushostName(const QString &); void setPrevioushostName(const QString &);
@ -67,7 +67,7 @@ public:
QString port = QString(), QString port = QString(),
QString site = QString()); QString site = QString());
void setClearDebugLogStatus(bool abIsChecked); void setClearDebugLogStatus(bool abIsChecked);
bool getClearDebugLogStatus(bool abDefaultValue) const; bool getClearDebugLogStatus(bool abDefaultValue);
private: private:
explicit ServersSettings(const QString &settingPath, QObject *parent = nullptr); explicit ServersSettings(const QString &settingPath, QObject *parent = nullptr);

View file

@ -1,22 +1,16 @@
#include "settings_manager.h" #include "settings_manager.h"
SettingsManager::SettingsManager(const QString &_settingPath, SettingsManager::SettingsManager(const QString &settingPath,
const QString &_defaultGroup, const QString &_defaultGroup,
const QString &_defaultSubGroup, const QString &_defaultSubGroup,
QObject *parent) QObject *parent)
: QObject(parent), settingPath(_settingPath), defaultGroup(_defaultGroup), defaultSubGroup(_defaultSubGroup) : QObject(parent), settings(settingPath, QSettings::IniFormat), defaultGroup(_defaultGroup),
defaultSubGroup(_defaultSubGroup)
{ {
} }
QSettings SettingsManager::getSettings() const
{
return QSettings(settingPath, QSettings::IniFormat);
}
void SettingsManager::setValue(const QVariant &value, const QString &name) void SettingsManager::setValue(const QVariant &value, const QString &name)
{ {
auto settings = getSettings();
if (!defaultGroup.isEmpty()) { if (!defaultGroup.isEmpty()) {
settings.beginGroup(defaultGroup); settings.beginGroup(defaultGroup);
} }
@ -41,8 +35,6 @@ void SettingsManager::setValue(const QVariant &value,
const QString &group, const QString &group,
const QString &subGroup) const QString &subGroup)
{ {
auto settings = getSettings();
if (!group.isEmpty()) { if (!group.isEmpty()) {
settings.beginGroup(group); settings.beginGroup(group);
} }
@ -64,8 +56,6 @@ void SettingsManager::setValue(const QVariant &value,
void SettingsManager::deleteValue(const QString &name) void SettingsManager::deleteValue(const QString &name)
{ {
auto settings = getSettings();
if (!defaultGroup.isEmpty()) { if (!defaultGroup.isEmpty()) {
settings.beginGroup(defaultGroup); settings.beginGroup(defaultGroup);
} }
@ -87,8 +77,6 @@ void SettingsManager::deleteValue(const QString &name)
void SettingsManager::deleteValue(const QString &name, const QString &group, const QString &subGroup) void SettingsManager::deleteValue(const QString &name, const QString &group, const QString &subGroup)
{ {
auto settings = getSettings();
if (!group.isEmpty()) { if (!group.isEmpty()) {
settings.beginGroup(group); settings.beginGroup(group);
} }
@ -108,10 +96,8 @@ void SettingsManager::deleteValue(const QString &name, const QString &group, con
} }
} }
QVariant SettingsManager::getValue(const QString &name) const QVariant SettingsManager::getValue(const QString &name)
{ {
auto settings = getSettings();
if (!defaultGroup.isEmpty()) { if (!defaultGroup.isEmpty()) {
settings.beginGroup(defaultGroup); settings.beginGroup(defaultGroup);
} }
@ -133,10 +119,8 @@ QVariant SettingsManager::getValue(const QString &name) const
return value; return value;
} }
QVariant SettingsManager::getValue(const QString &name, const QString &group, const QString &subGroup) const QVariant SettingsManager::getValue(const QString &name, const QString &group, const QString &subGroup)
{ {
auto settings = getSettings();
if (!group.isEmpty()) { if (!group.isEmpty()) {
settings.beginGroup(group); settings.beginGroup(group);
} }
@ -163,7 +147,5 @@ QVariant SettingsManager::getValue(const QString &name, const QString &group, co
*/ */
void SettingsManager::sync() void SettingsManager::sync()
{ {
auto settings = getSettings();
settings.sync(); settings.sync();
} }

View file

@ -19,17 +19,14 @@ public:
const QString &defaultGroup = QString(), const QString &defaultGroup = QString(),
const QString &defaultSubGroup = QString(), const QString &defaultSubGroup = QString(),
QObject *parent = nullptr); QObject *parent = nullptr);
QVariant getValue(const QString &name) const; QVariant getValue(const QString &name);
QVariant getValue(const QString &name, const QString &group, const QString &subGroup = QString()) const; QVariant getValue(const QString &name, const QString &group, const QString &subGroup = QString());
void sync(); void sync();
protected: protected:
QString settingPath; QSettings settings;
QString defaultGroup; QString defaultGroup;
QString defaultSubGroup; QString defaultSubGroup;
QSettings getSettings() const;
void setValue(const QVariant &value, const QString &name); void setValue(const QVariant &value, const QString &name);
void void
setValue(const QVariant &value, const QString &name, const QString &group, const QString &subGroup = QString()); setValue(const QVariant &value, const QString &name, const QString &group, const QString &subGroup = QString());

File diff suppressed because it is too large Load diff