From 11bd2444d8c35a8a7cab59211ec6952cb88d5fdf Mon Sep 17 00:00:00 2001 From: Gavin Bises Date: Fri, 20 Feb 2015 20:29:36 -0500 Subject: [PATCH] Do not alert the application for game events when spectating. Add a configuration toggle to enable alerts when spectating. Default behavior is to not alert. --- cockatrice/src/settingscache.cpp | 6 ++++++ cockatrice/src/settingscache.h | 4 ++++ cockatrice/src/tab_game.cpp | 25 +++++++++++++++---------- cockatrice/src/tab_game.h | 1 + 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 027c23e1..2377113c 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -35,6 +35,7 @@ SettingsCache::SettingsCache() mainWindowGeometry = settings->value("interface/main_window_geometry").toByteArray(); notificationsEnabled = settings->value("interface/notificationsenabled", true).toBool(); + spectatorNotificationsEnabled = settings->value("interface/specnotificationsenabled", false).toBool(); doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool(); playToStack = settings->value("interface/playtostack", false).toBool(); cardInfoMinimized = settings->value("interface/cardinfominimized", 0).toInt(); @@ -183,6 +184,11 @@ void SettingsCache::setNotificationsEnabled(int _notificationsEnabled) settings->setValue("interface/notificationsenabled", notificationsEnabled); } +void SettingsCache::setSpectatorNotificationsEnabled(int _spectatorNotificationsEnabled) { + spectatorNotificationsEnabled = _spectatorNotificationsEnabled; + settings->setValue("interface/specnotificationsenabled", spectatorNotificationsEnabled); +} + void SettingsCache::setDoubleClickToPlay(int _doubleClickToPlay) { doubleClickToPlay = _doubleClickToPlay; diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index d2153713..f21d2951 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -48,6 +48,7 @@ private: bool picDownload; bool picDownloadHq; bool notificationsEnabled; + bool spectatorNotificationsEnabled; bool doubleClickToPlay; bool playToStack; int cardInfoMinimized; @@ -91,6 +92,8 @@ public: bool getPicDownload() const { return picDownload; } bool getPicDownloadHq() const { return picDownloadHq; } bool getNotificationsEnabled() const { return notificationsEnabled; } + bool getSpectatorNotificationsEnabled() const { return spectatorNotificationsEnabled; } + bool getDoubleClickToPlay() const { return doubleClickToPlay; } bool getPlayToStack() const { return playToStack; } int getCardInfoMinimized() const { return cardInfoMinimized; } @@ -139,6 +142,7 @@ public slots: void setPicDownload(int _picDownload); void setPicDownloadHq(int _picDownloadHq); void setNotificationsEnabled(int _notificationsEnabled); + void setSpectatorNotificationsEnabled(int _spectatorNotificationsEnabled); void setDoubleClickToPlay(int _doubleClickToPlay); void setPlayToStack(int _playToStack); void setCardInfoMinimized(int _cardInfoMinimized); diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 4cd941af..92c50c1b 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -514,6 +514,11 @@ void TabGame::addMentionTag(QString value) { sayEdit->setFocus(); } +void TabGame::emitUserEvent() { + bool globalEvent = !spectator || settingsCache->getSpectatorNotificationsEnabled(); + emit userEvent(globalEvent); +} + TabGame::~TabGame() { delete replay; @@ -806,7 +811,7 @@ void TabGame::processGameEventContainer(const GameEventContainer &cont, Abstract break; } player->processGameEvent(eventType, event, context); - emit userEvent(); + emitUserEvent(); } } } @@ -929,7 +934,7 @@ void TabGame::eventSpectatorLeave(const Event_Leave & /*event*/, int eventPlayer playerListWidget->removePlayer(eventPlayerId); spectators.remove(eventPlayerId); - emit userEvent(); + emitUserEvent(); } void TabGame::eventGameStateChanged(const Event_GameStateChanged &event, int /*eventPlayerId*/, const GameEventContext & /*context*/) @@ -988,7 +993,7 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event, int /*e scene->clearViews(); } gameStateKnown = true; - emit userEvent(); + emitUserEvent(); } void TabGame::eventPlayerPropertiesChanged(const Event_PlayerPropertiesChanged &event, int eventPlayerId, const GameEventContext &context) @@ -1056,7 +1061,7 @@ void TabGame::eventJoin(const Event_Join &event, int /*eventPlayerId*/, const Ga messageLog->logJoin(newPlayer); } playerListWidget->addPlayer(playerInfo); - emit userEvent(); + emitUserEvent(); } void TabGame::eventLeave(const Event_Leave & /*event*/, int eventPlayerId, const GameEventContext & /*context*/) @@ -1077,7 +1082,7 @@ void TabGame::eventLeave(const Event_Leave & /*event*/, int eventPlayerId, const while (playerIterator.hasNext()) playerIterator.next().value()->updateZones(); - emit userEvent(); + emitUserEvent(); } void TabGame::eventKicked(const Event_Kicked & /*event*/, int /*eventPlayerId*/, const GameEventContext & /*context*/) @@ -1092,7 +1097,7 @@ void TabGame::eventKicked(const Event_Kicked & /*event*/, int /*eventPlayerId*/, msgBox.setIcon(QMessageBox::Information); msgBox.exec(); - emit userEvent(); + emitUserEvent(); } void TabGame::eventGameHostChanged(const Event_GameHostChanged & /*event*/, int eventPlayerId, const GameEventContext & /*context*/) @@ -1104,7 +1109,7 @@ void TabGame::eventGameClosed(const Event_GameClosed & /*event*/, int /*eventPla { closeGame(); messageLog->logGameClosed(); - emit userEvent(); + emitUserEvent(); } Player *TabGame::setActivePlayer(int id) @@ -1128,7 +1133,7 @@ Player *TabGame::setActivePlayer(int id) } } currentPhase = -1; - emit userEvent(); + emitUserEvent(); return player; } @@ -1138,7 +1143,7 @@ void TabGame::eventSetActivePlayer(const Event_SetActivePlayer &event, int /*eve if (!player) return; messageLog->logSetActivePlayer(player); - emit userEvent(); + emitUserEvent(); } void TabGame::setActivePhase(int phase) @@ -1155,7 +1160,7 @@ void TabGame::eventSetActivePhase(const Event_SetActivePhase &event, int /*event if (currentPhase != phase) messageLog->logSetActivePhase(phase); setActivePhase(phase); - emit userEvent(); + emitUserEvent(); } void TabGame::newCardAdded(AbstractCardItem *card) diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index 0725f373..1b9bff5f 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -164,6 +164,7 @@ private: void setActivePhase(int phase); void eventSetActivePhase(const Event_SetActivePhase &event, int eventPlayerId, const GameEventContext &context); void eventPing(const Event_Ping &event, int eventPlayerId, const GameEventContext &context); + void emitUserEvent(); signals: void gameClosing(TabGame *tab); void playerAdded(Player *player);