mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 00:54:53 -07:00
Non-QObject polymorphic interface with setShortcutsActive(), setShortcutsInactive(), and retranslateUi(). Uses regular multiple inheritance to avoid diamond inheritance with Qt's MOC. All zone menus, SayMenu, and AbstractCounter implement this interface. PlayerMenu manages them via a managedComponents list with two template helpers (addManagedMenu/registerManagedComponent), replacing individual if-guarded lifecycle calls with a single polymorphic loop. SayMenu now owns its shortcut and translation lifecycle instead of having PlayerMenu manage its title and shortcuts externally. Counters are iterated via Player::getCounters() rather than managedComponents to avoid duplicating the authoritative owner's map.
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
/**
|
|
* @file utility_menu.h
|
|
* @ingroup GameMenusPlayers
|
|
* @brief TODO: Document this.
|
|
*/
|
|
|
|
#ifndef COCKATRICE_UTILITY_MENU_H
|
|
#define COCKATRICE_UTILITY_MENU_H
|
|
|
|
#include "abstract_player_component.h"
|
|
|
|
#include <QMenu>
|
|
|
|
class Player;
|
|
class UtilityMenu : public QMenu, public AbstractPlayerComponent
|
|
{
|
|
Q_OBJECT
|
|
public slots:
|
|
void populatePredefinedTokensMenu();
|
|
void retranslateUi() override;
|
|
void setShortcutsActive() override;
|
|
void setShortcutsInactive() override;
|
|
|
|
public:
|
|
explicit UtilityMenu(Player *player, QMenu *playerMenu);
|
|
|
|
[[nodiscard]] bool createAnotherTokenActionExists() const
|
|
{
|
|
return aCreateAnotherToken != nullptr;
|
|
}
|
|
|
|
void setAndEnableCreateAnotherTokenAction(QString text)
|
|
{
|
|
aCreateAnotherToken->setText(text);
|
|
aCreateAnotherToken->setEnabled(true);
|
|
}
|
|
|
|
QStringList getPredefinedTokens() const
|
|
{
|
|
return predefinedTokens;
|
|
}
|
|
|
|
private:
|
|
Player *player;
|
|
QStringList predefinedTokens;
|
|
|
|
QMenu *createPredefinedTokenMenu;
|
|
|
|
QAction *aIncrementAllCardCounters;
|
|
QAction *aUntapAll, *aRollDie;
|
|
QAction *aCreateToken, *aCreateAnotherToken;
|
|
};
|
|
|
|
#endif // COCKATRICE_UTILITY_MENU_H
|