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:
Mmonge123 2026-11-07 16:38:33 +00:00 • committed by GitHub
parent d9cd308a2e
commit 257a584971
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 52 additions and 2 deletions

View file

@ -23,6 +23,7 @@
#include <QMenu>
#include <QString>
#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_logic.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,
&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();
retranslateUi();
@ -144,6 +150,12 @@ void PlayerMenu::refreshShortcuts()
void PlayerMenu::setShortcutsActive()
{
shortcutsActive = true;
if (!isGameStarted()) {
applyLobbyShortcuts();
return;
}
for (auto *c : managedComponents) {
c->setShortcutsActive();
}
@ -156,5 +168,24 @@ void PlayerMenu::setShortcutsInactive()
for (auto *c : managedComponents) {
c->setShortcutsInactive();
}
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();
}