mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 19:13:25 -08:00
fix: keep only the roll-die shortcut active in the lobby (#6754)
Player menu shortcuts were bound as soon as a local player was added in the deck-selection lobby. Defer full activation until GameMetaInfo reports the game has started, and bind only Player/aRollDie while in the lobby. Counters follow the deactivation signal, so they cannot re-enable shortcuts before the game starts.
This commit is contained in:
parent
d9cd308a2e
commit
257a584971
4 changed files with 52 additions and 2 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <libcockatrice/game/abstract_game.h>
|
#include <libcockatrice/game/abstract_game.h>
|
||||||
|
#include <libcockatrice/game/game_meta_info.h>
|
||||||
#include <libcockatrice/game/player/player_info.h>
|
#include <libcockatrice/game/player/player_info.h>
|
||||||
#include <libcockatrice/game/player/player_logic.h>
|
#include <libcockatrice/game/player/player_logic.h>
|
||||||
#include <libcockatrice/game/player/player_manager.h>
|
#include <libcockatrice/game/player/player_manager.h>
|
||||||
|
|
@ -70,6 +71,11 @@ PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_
|
||||||
|
|
||||||
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
||||||
&PlayerMenu::refreshShortcuts);
|
&PlayerMenu::refreshShortcuts);
|
||||||
|
|
||||||
|
// Re-evaluate shortcuts when the game starts or ends, so the lobby only exposes the roll-die shortcut.
|
||||||
|
connect(player->getLogic()->getGame()->getGameMetaInfo(), &GameMetaInfo::startedChanged, this,
|
||||||
|
&PlayerMenu::refreshShortcuts);
|
||||||
|
|
||||||
refreshShortcuts();
|
refreshShortcuts();
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
|
@ -144,6 +150,12 @@ void PlayerMenu::refreshShortcuts()
|
||||||
void PlayerMenu::setShortcutsActive()
|
void PlayerMenu::setShortcutsActive()
|
||||||
{
|
{
|
||||||
shortcutsActive = true;
|
shortcutsActive = true;
|
||||||
|
|
||||||
|
if (!isGameStarted()) {
|
||||||
|
applyLobbyShortcuts();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto *c : managedComponents) {
|
for (auto *c : managedComponents) {
|
||||||
c->setShortcutsActive();
|
c->setShortcutsActive();
|
||||||
}
|
}
|
||||||
|
|
@ -158,3 +170,22 @@ void PlayerMenu::setShortcutsInactive()
|
||||||
}
|
}
|
||||||
emit shortcutsDeactivated();
|
emit shortcutsDeactivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlayerMenu::isGameStarted() const
|
||||||
|
{
|
||||||
|
return player->getLogic()->getGame()->getGameMetaInfo()->started();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerMenu::applyLobbyShortcuts()
|
||||||
|
{
|
||||||
|
// Everything stays unbound until the game starts; only the roll-die shortcut is usable in the lobby.
|
||||||
|
for (auto *c : managedComponents) {
|
||||||
|
c->setShortcutsInactive();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utilityMenu) {
|
||||||
|
utilityMenu->setLobbyShortcutsActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit shortcutsDeactivated();
|
||||||
|
}
|
||||||
|
|
@ -73,17 +73,24 @@ public:
|
||||||
return utilityMenu;
|
return utilityMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Whether this player currently holds its shortcuts and the game has started. */
|
||||||
[[nodiscard]] bool getShortcutsActive() const
|
[[nodiscard]] bool getShortcutsActive() const
|
||||||
{
|
{
|
||||||
return shortcutsActive;
|
return shortcutsActive && isGameStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Bind keyboard shortcuts. Called when this player gains focus. */
|
/** @brief Bind keyboard shortcuts. Only the roll-die shortcut is bound before the game starts. */
|
||||||
void setShortcutsActive();
|
void setShortcutsActive();
|
||||||
/** @brief Unbind keyboard shortcuts. Called when this player loses focus. */
|
/** @brief Unbind keyboard shortcuts. Called when this player loses focus. */
|
||||||
void setShortcutsInactive();
|
void setShortcutsInactive();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** @brief True once the game has started; false while players are still in the deck-selection lobby. */
|
||||||
|
[[nodiscard]] bool isGameStarted() const;
|
||||||
|
|
||||||
|
/** @brief Unbinds everything except the shortcuts that remain usable before the game starts. */
|
||||||
|
void applyLobbyShortcuts();
|
||||||
|
|
||||||
PlayerGraphicsItem *player;
|
PlayerGraphicsItem *player;
|
||||||
TearOffMenu *playerMenu;
|
TearOffMenu *playerMenu;
|
||||||
QMenu *countersMenu;
|
QMenu *countersMenu;
|
||||||
|
|
|
||||||
|
|
@ -151,3 +151,12 @@ void UtilityMenu::setShortcutsInactive()
|
||||||
aIncrementAllCardCounters->setShortcut(QKeySequence());
|
aIncrementAllCardCounters->setShortcut(QKeySequence());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UtilityMenu::setLobbyShortcutsActive()
|
||||||
|
{
|
||||||
|
if (!player->getLogic()->getPlayerInfo()->getLocalOrJudge()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
aRollDie->setShortcuts(SettingsCache::instance().shortcuts().getShortcut("Player/aRollDie"));
|
||||||
|
}
|
||||||
|
|
@ -32,6 +32,9 @@ public slots:
|
||||||
public:
|
public:
|
||||||
explicit UtilityMenu(PlayerGraphicsItem *player, QMenu *playerMenu);
|
explicit UtilityMenu(PlayerGraphicsItem *player, QMenu *playerMenu);
|
||||||
|
|
||||||
|
/** @brief Binds only the shortcuts that remain usable before the game starts. */
|
||||||
|
void setLobbyShortcutsActive();
|
||||||
|
|
||||||
[[nodiscard]] bool createAnotherTokenActionExists() const
|
[[nodiscard]] bool createAnotherTokenActionExists() const
|
||||||
{
|
{
|
||||||
return aCreateAnotherToken != nullptr;
|
return aCreateAnotherToken != nullptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue