mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
* [Refactor] Move card item creation out of game logic * [Game] Rename signal to createCardRequested per review * [Game] Move attachment bookkeeping onto CardState CardState::setAttachedTo now maintains the attachedCards graph, resets the grid point and emits the zone events itself, so game logic no longer needs to reach into the CardItem graphics item. CardItem::setAttachedTo delegates to the state and keeps only the view teardown (deleteLater). --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
124 lines
3.2 KiB
C++
124 lines
3.2 KiB
C++
/**
|
|
* @file player_menu.h
|
|
* @ingroup GameMenusPlayers
|
|
* @brief Orchestrates lifecycle management for all player-bound UI components.
|
|
*/
|
|
|
|
#ifndef COCKATRICE_PLAYER_MENU_H
|
|
#define COCKATRICE_PLAYER_MENU_H
|
|
|
|
#include "../../../interface/widgets/menus/tearoff_menu.h"
|
|
|
|
#include <QList>
|
|
#include <QObject>
|
|
#include <qtmetamacros.h>
|
|
#include <utility>
|
|
|
|
class CardState;
|
|
class CardMenu;
|
|
class PlayerGraphicsItem;
|
|
class AbstractPlayerComponent;
|
|
class CustomZoneMenu;
|
|
class GraveyardMenu;
|
|
class HandMenu;
|
|
class LibraryMenu;
|
|
class QMenu;
|
|
class RfgMenu;
|
|
class SayMenu;
|
|
class SideboardMenu;
|
|
class TallyMenu;
|
|
class UtilityMenu;
|
|
struct CardRef;
|
|
|
|
class PlayerMenu : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
signals:
|
|
void cardMenuUpdated(CardMenu *cardMenu);
|
|
void cardInfoRequested(const CardRef &cardRef);
|
|
void shortcutsActivated();
|
|
void shortcutsDeactivated();
|
|
void retranslateRequested();
|
|
|
|
public slots:
|
|
void setMenusForGraphicItems();
|
|
QMenu *updateCardMenu(CardState *card);
|
|
|
|
private slots:
|
|
void refreshShortcuts();
|
|
|
|
public:
|
|
explicit PlayerMenu(PlayerGraphicsItem *player);
|
|
/** @brief Retranslate all user-visible strings. Called on language change. */
|
|
void retranslateUi();
|
|
|
|
[[nodiscard]] QMenu *getPlayerMenu() const
|
|
{
|
|
return playerMenu;
|
|
}
|
|
|
|
[[nodiscard]] QMenu *getCountersMenu()
|
|
{
|
|
return countersMenu;
|
|
}
|
|
|
|
[[nodiscard]] LibraryMenu *getLibraryMenu() const
|
|
{
|
|
return libraryMenu;
|
|
}
|
|
|
|
[[nodiscard]] UtilityMenu *getUtilityMenu() const
|
|
{
|
|
return utilityMenu;
|
|
}
|
|
|
|
[[nodiscard]] bool getShortcutsActive() const
|
|
{
|
|
return shortcutsActive;
|
|
}
|
|
|
|
/** @brief Bind keyboard shortcuts. Called when this player gains focus. */
|
|
void setShortcutsActive();
|
|
/** @brief Unbind keyboard shortcuts. Called when this player loses focus. */
|
|
void setShortcutsInactive();
|
|
|
|
private:
|
|
PlayerGraphicsItem *player;
|
|
TearOffMenu *playerMenu;
|
|
QMenu *countersMenu;
|
|
HandMenu *handMenu;
|
|
LibraryMenu *libraryMenu;
|
|
SideboardMenu *sideboardMenu;
|
|
GraveyardMenu *graveMenu;
|
|
RfgMenu *rfgMenu;
|
|
UtilityMenu *utilityMenu;
|
|
TallyMenu *tallyMenu;
|
|
SayMenu *sayMenu;
|
|
CustomZoneMenu *customZonesMenu;
|
|
|
|
/** @brief Drives AbstractPlayerComponent lifecycle delegation. Counters are iterated separately via
|
|
* player->getCounters().
|
|
*/
|
|
QList<AbstractPlayerComponent *> managedComponents;
|
|
bool shortcutsActive = false;
|
|
|
|
/** @brief Creates component, adds it as a submenu of playerMenu, and registers in managedComponents. */
|
|
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;
|
|
}
|
|
|
|
/** @brief 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
|