This commit is contained in:
Mmonge123 2026-04-23 05:27:51 +00:00 committed by GitHub
commit b473e0e943
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 55 additions and 1 deletions

View file

@ -2,6 +2,7 @@
#include "../../../interface/widgets/tabs/tab_game.h"
#include "../../board/card_item.h"
#include "../../game_meta_info.h"
#include "../../zones/hand_zone.h"
#include "../../zones/pile_zone.h"
#include "../../zones/table_zone.h"
@ -48,6 +49,13 @@ PlayerMenu::PlayerMenu(Player *_player) : QObject(_player), player(_player)
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
&PlayerMenu::refreshShortcuts);
// Monitor game state to re-evaluate shortcuts when game starts/stops
if (player->getGame() && player->getGame()->getGameMetaInfo()) {
connect(player->getGame()->getGameMetaInfo(), &GameMetaInfo::startedChanged, this,
&PlayerMenu::onGameStartedChanged);
}
refreshShortcuts();
retranslateUi();
@ -117,10 +125,40 @@ void PlayerMenu::refreshShortcuts()
}
}
void PlayerMenu::onGameStartedChanged(bool started)
{
Q_UNUSED(started);
// Re-evaluate shortcuts when game state transitions
if (shortcutsActive) {
setShortcutsActive();
}
}
void PlayerMenu::setShortcutsActive()
{
shortcutsActive = true;
// Null-safety checks
if (!player->getGame() || !player->getGame()->getGameMetaInfo()) {
return;
}
if (!player->getGame()->getGameMetaInfo()->started()) {
for (auto *component : managedComponents) {
component->setShortcutsInactive();
}
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
while (counterIterator.hasNext()) {
counterIterator.next().value()->setShortcutsInactive();
}
if (utilityMenu) {
utilityMenu->setLobbyShortcutsActive();
}
return;
}
for (auto *component : managedComponents) {
component->setShortcutsActive();
}

View file

@ -69,10 +69,15 @@ public:
}
/// Delegates to all managedComponents, plus counters separately.
/// Stop full activation until game has started; only roll-die shortcut is active in lobby.
void setShortcutsActive();
/// Delegates to all managedComponents, plus counters separately.
void setShortcutsInactive();
private slots:
/// Re-evaluate shortcut state when game started/stopped state changes.
void onGameStartedChanged(bool started);
private:
Player *player;
TearOffMenu *playerMenu;

View file

@ -117,4 +117,14 @@ void UtilityMenu::setShortcutsInactive()
aCreateAnotherToken->setShortcut(QKeySequence());
aIncrementAllCardCounters->setShortcut(QKeySequence());
}
}
}
void UtilityMenu::setLobbyShortcutsActive()
{
if (!player->getPlayerInfo()->getLocalOrJudge()) {
return;
}
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
aRollDie->setShortcuts(shortcuts.getShortcut("Player/aRollDie"));
}

View file

@ -23,6 +23,7 @@ public slots:
public:
explicit UtilityMenu(Player *player, QMenu *playerMenu);
void setLobbyShortcutsActive();
[[nodiscard]] bool createAnotherTokenActionExists() const
{