diff --git a/cockatrice/src/tab.h b/cockatrice/src/tab.h index 445dc9b7..b265867b 100644 --- a/cockatrice/src/tab.h +++ b/cockatrice/src/tab.h @@ -7,12 +7,16 @@ class QMenu; class Tab : public QWidget { Q_OBJECT +signals: + void userEvent(); protected: QMenu *tabMenu; public: Tab(QWidget *parent = 0) : QWidget(parent), tabMenu(0) { } QMenu *getTabMenu() const { return tabMenu; } + virtual QString getTabText() const = 0; + virtual void retranslateUi() = 0; }; #endif diff --git a/cockatrice/src/tab_chatchannel.cpp b/cockatrice/src/tab_chatchannel.cpp index 5602e7bb..cd8e9c51 100644 --- a/cockatrice/src/tab_chatchannel.cpp +++ b/cockatrice/src/tab_chatchannel.cpp @@ -80,6 +80,7 @@ void TabChatChannel::processJoinChannelEvent(Event_ChatJoinChannel *event) { textEdit->append(tr("%1 has joined the channel.").arg(event->getPlayerName())); playerList->addItem(event->getPlayerName()); + emit userEvent(); } void TabChatChannel::processLeaveChannelEvent(Event_ChatLeaveChannel *event) @@ -90,6 +91,7 @@ void TabChatChannel::processLeaveChannelEvent(Event_ChatLeaveChannel *event) delete playerList->takeItem(i); break; } + emit userEvent(); } void TabChatChannel::processSayEvent(Event_ChatSay *event) @@ -98,5 +100,5 @@ void TabChatChannel::processSayEvent(Event_ChatSay *event) textEdit->append(QString("%1getMessage())); else textEdit->append(QString("%1: %2").arg(event->getPlayerName()).arg(event->getMessage())); - QApplication::alert(this); + emit userEvent(); } diff --git a/cockatrice/src/tab_chatchannel.h b/cockatrice/src/tab_chatchannel.h index 73cf3030..7552043a 100644 --- a/cockatrice/src/tab_chatchannel.h +++ b/cockatrice/src/tab_chatchannel.h @@ -40,6 +40,7 @@ public: void retranslateUi(); void processChatEvent(ChatEvent *event); QString getChannelName() const { return channelName; } + QString getTabText() const { return channelName; } }; #endif diff --git a/cockatrice/src/tab_deck_storage.h b/cockatrice/src/tab_deck_storage.h index 89ad2ba6..dd47a6c9 100644 --- a/cockatrice/src/tab_deck_storage.h +++ b/cockatrice/src/tab_deck_storage.h @@ -47,6 +47,7 @@ private slots: public: TabDeckStorage(Client *_client); void retranslateUi(); + QString getTabText() const { return tr("Deck storage"); } }; #endif diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 45c4a30c..9751c174 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -20,8 +20,8 @@ #include "arrowitem.h" #include "main.h" -TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator, bool _resuming) - : Tab(), client(_client), gameId(_gameId), localPlayerId(_localPlayerId), spectator(_spectator), started(false), resuming(_resuming), currentPhase(-1) +TabGame::TabGame(Client *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _resuming) + : Tab(), client(_client), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), started(false), resuming(_resuming), currentPhase(-1) { zoneLayout = new ZoneViewLayout; scene = new GameScene(zoneLayout, this); @@ -244,6 +244,7 @@ void TabGame::processGameEvent(GameEvent *event) break; } player->processGameEvent(event); + emit userEvent(); } } } @@ -307,6 +308,7 @@ void TabGame::eventGameStateChanged(Event_GameStateChanged *event) stopGame(); zoneLayout->clear(); } + emit userEvent(); } void TabGame::eventJoin(Event_Join *event) @@ -321,6 +323,7 @@ void TabGame::eventJoin(Event_Join *event) messageLog->logJoin(newPlayer); playerListWidget->addPlayer(playerInfo); } + emit userEvent(); } void TabGame::eventLeave(Event_Leave *event) @@ -338,12 +341,14 @@ void TabGame::eventLeave(Event_Leave *event) playerListWidget->removePlayer(playerId); spectators.remove(playerId); } + emit userEvent(); } void TabGame::eventGameClosed(Event_GameClosed * /*event*/) { started = false; messageLog->logGameClosed(); + emit userEvent(); } Player *TabGame::setActivePlayer(int id) @@ -358,6 +363,7 @@ Player *TabGame::setActivePlayer(int id) i.value()->setActive(i.value() == player); } currentPhase = -1; + emit userEvent(); return player; } @@ -367,6 +373,7 @@ void TabGame::eventSetActivePlayer(Event_SetActivePlayer *event) if (!player) return; messageLog->logSetActivePlayer(player); + emit userEvent(); } void TabGame::setActivePhase(int phase) @@ -383,6 +390,7 @@ void TabGame::eventSetActivePhase(Event_SetActivePhase *event) if (currentPhase != phase) messageLog->logSetActivePhase(phase); setActivePhase(phase); + emit userEvent(); } void TabGame::eventPing(Event_Ping *event) diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index 68a8bfdf..00cea0f8 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -40,6 +40,7 @@ class TabGame : public Tab { private: Client *client; int gameId; + QString gameDescription; int localPlayerId; bool spectator; QMap players; @@ -95,11 +96,12 @@ private slots: void actNextPhase(); void actNextTurn(); public: - TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator, bool _resuming); + TabGame(Client *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _resuming); ~TabGame(); void retranslateUi(); const QMap &getPlayers() const { return players; } int getGameId() const { return gameId; } + QString getTabText() const { return tr("Game %1: %2").arg(gameId).arg(gameDescription); } void processGameEvent(GameEvent *event); public slots: diff --git a/cockatrice/src/tab_server.h b/cockatrice/src/tab_server.h index 2695a314..9ba12b2d 100644 --- a/cockatrice/src/tab_server.h +++ b/cockatrice/src/tab_server.h @@ -85,6 +85,7 @@ private: public: TabServer(Client *_client, QWidget *parent = 0); void retranslateUi(); + QString getTabText() const { return tr("Server"); } }; #endif diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index 35d80718..be8f0f17 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -1,3 +1,4 @@ +#include #include "tab_supervisor.h" #include "client.h" #include "tab_server.h" @@ -16,22 +17,28 @@ TabSupervisor:: TabSupervisor(QWidget *parent) void TabSupervisor::retranslateUi() { - if (tabServer) { - setTabText(0, tr("Server")); - tabServer->retranslateUi(); - } - if (tabDeckStorage) { - setTabText(1, tr("Deck storage")); - tabDeckStorage->retranslateUi(); - } - + QList tabs; + if (tabServer) + tabs.append(tabServer); + if (tabDeckStorage) + tabs.append(tabDeckStorage); QMapIterator chatChannelIterator(chatChannelTabs); while (chatChannelIterator.hasNext()) - chatChannelIterator.next().value()->retranslateUi(); - + tabs.append(chatChannelIterator.next().value()); QMapIterator gameIterator(gameTabs); while (gameIterator.hasNext()) - gameIterator.next().value()->retranslateUi(); + tabs.append(gameIterator.next().value()); + + for (int i = 0; i < tabs.size(); ++i) { + setTabText(indexOf(tabs[i]), tabs[i]->getTabText()); + tabs[i]->retranslateUi(); + } +} + +void TabSupervisor::myAddTab(Tab *tab) +{ + connect(tab, SIGNAL(userEvent()), this, SLOT(tabUserEvent())); + addTab(tab, tab->getTabText()); } void TabSupervisor::start(Client *_client) @@ -44,11 +51,11 @@ void TabSupervisor::start(Client *_client) tabServer = new TabServer(client); connect(tabServer, SIGNAL(chatChannelJoined(const QString &)), this, SLOT(addChatChannelTab(const QString &))); - addTab(tabServer, QString()); + myAddTab(tabServer); updatePingTime(0, -1); tabDeckStorage = new TabDeckStorage(client); - addTab(tabDeckStorage, QString()); + myAddTab(tabDeckStorage); retranslateUi(); } @@ -89,9 +96,9 @@ void TabSupervisor::updatePingTime(int value, int max) void TabSupervisor::gameJoined(Event_GameJoined *event) { - TabGame *tab = new TabGame(client, event->getGameId(), event->getPlayerId(), event->getSpectator(), event->getResuming()); + TabGame *tab = new TabGame(client, event->getGameId(), event->getGameDescription(), event->getPlayerId(), event->getSpectator(), event->getResuming()); connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *))); - addTab(tab, tr("Game %1").arg(event->getGameId())); + myAddTab(tab); gameTabs.insert(event->getGameId(), tab); setCurrentWidget(tab); } @@ -108,7 +115,7 @@ void TabSupervisor::addChatChannelTab(const QString &channelName) { TabChatChannel *tab = new TabChatChannel(client, channelName); connect(tab, SIGNAL(channelClosing(TabChatChannel *)), this, SLOT(chatChannelLeft(TabChatChannel *))); - addTab(tab, channelName); + myAddTab(tab); chatChannelTabs.insert(channelName, tab); setCurrentWidget(tab); } @@ -121,6 +128,13 @@ void TabSupervisor::chatChannelLeft(TabChatChannel *tab) removeTab(indexOf(tab)); } +void TabSupervisor::tabUserEvent() +{ + Tab *tab = static_cast(sender()); + // XXX Mark tab as changed (exclamation mark icon?) + QApplication::alert(this); +} + void TabSupervisor::processChatEvent(ChatEvent *event) { TabChatChannel *tab = chatChannelTabs.value(event->getChannel(), 0); diff --git a/cockatrice/src/tab_supervisor.h b/cockatrice/src/tab_supervisor.h index 47014b85..4d66722d 100644 --- a/cockatrice/src/tab_supervisor.h +++ b/cockatrice/src/tab_supervisor.h @@ -6,6 +6,7 @@ class QMenu; class Client; +class Tab; class TabServer; class TabChatChannel; class TabGame; @@ -22,6 +23,7 @@ private: TabDeckStorage *tabDeckStorage; QMap chatChannelTabs; QMap gameTabs; + void myAddTab(Tab *tab); public: TabSupervisor(QWidget *parent = 0); void retranslateUi(); @@ -36,6 +38,7 @@ private slots: void gameLeft(TabGame *tab); void addChatChannelTab(const QString &channelName); void chatChannelLeft(TabChatChannel *tab); + void tabUserEvent(); void processChatEvent(ChatEvent *event); void processGameEvent(GameEvent *event); }; diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index c3ddddb5..7e887b45 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -145,6 +145,8 @@ void MainWindow::retranslateUi() aExit->setText(tr("&Exit")); cockatriceMenu->setTitle(tr("&Cockatrice")); + + tabSupervisor->retranslateUi(); } void MainWindow::createActions() diff --git a/cockatrice/translations/cockatrice_de.ts b/cockatrice/translations/cockatrice_de.ts index 4f886b4b..cd5a6acf 100644 --- a/cockatrice/translations/cockatrice_de.ts +++ b/cockatrice/translations/cockatrice_de.ts @@ -2149,12 +2149,12 @@ - + Number: Anzahl: - + Set counters Setze Zählmarken @@ -2295,7 +2295,7 @@ %1 hat den Raum betreten. - + %1 has left the channel. %1 hat den Raum verlassen. @@ -2362,6 +2362,11 @@ Bitte geben Sie einen Namen ein: Name of new folder: Name für den neuen Ordner: + + + Deck storage + Deckspeicherplatz + TabGame @@ -2475,23 +2480,33 @@ Bitte geben Sie einen Namen ein: Load deck Deck laden + + + Game %1: %2 + Spiel %1: %2 + + + + TabServer + + + Server + Server + TabSupervisor - Server - Server + Server - Deck storage - Deckspeicherplatz + Deckspeicherplatz - Game %1 - Spiel %1 + Spiel %1 diff --git a/cockatrice/translations/cockatrice_en.ts b/cockatrice/translations/cockatrice_en.ts index c516dd4e..69f1e67c 100644 --- a/cockatrice/translations/cockatrice_en.ts +++ b/cockatrice/translations/cockatrice_en.ts @@ -1440,7 +1440,7 @@ - + Number: @@ -1465,7 +1465,7 @@ - + Set counters @@ -1578,7 +1578,7 @@ - + %1 has left the channel. @@ -1644,6 +1644,11 @@ Please enter a name: Name of new folder: + + + Deck storage + + TabGame @@ -1757,24 +1762,19 @@ Please enter a name: Load deck + + + Game %1: %2 + + - TabSupervisor + TabServer - + Server - - - Deck storage - - - - - Game %1 - - WndDeckEditor diff --git a/common/protocol_items.cpp b/common/protocol_items.cpp index 7343a655..5dac9d98 100644 --- a/common/protocol_items.cpp +++ b/common/protocol_items.cpp @@ -309,10 +309,11 @@ Event_ServerMessage::Event_ServerMessage(const QString &_message) { insertItem(new SerializableItem_String("message", _message)); } -Event_GameJoined::Event_GameJoined(int _gameId, int _playerId, bool _spectator, bool _resuming) +Event_GameJoined::Event_GameJoined(int _gameId, const QString &_gameDescription, int _playerId, bool _spectator, bool _resuming) : GenericEvent("game_joined") { insertItem(new SerializableItem_Int("game_id", _gameId)); + insertItem(new SerializableItem_String("game_description", _gameDescription)); insertItem(new SerializableItem_Int("player_id", _playerId)); insertItem(new SerializableItem_Bool("spectator", _spectator)); insertItem(new SerializableItem_Bool("resuming", _resuming)); diff --git a/common/protocol_items.dat b/common/protocol_items.dat index 0e41958e..9f7a95d8 100644 --- a/common/protocol_items.dat +++ b/common/protocol_items.dat @@ -52,7 +52,7 @@ 3:dump_zone:i,zone_owner_id:s,zone:i,number_cards 3:stop_dump_zone:i,zone_owner_id:s,zone 4:server_message:s,message -4:game_joined:i,game_id:i,player_id:b,spectator:b,resuming +4:game_joined:i,game_id:s,game_description:i,player_id:b,spectator:b,resuming 5:chat_join_channel:s,player_name 5:chat_leave_channel:s,player_name 5:chat_say:s,player_name:s,message diff --git a/common/protocol_items.h b/common/protocol_items.h index 1ffbfa85..6373cc60 100644 --- a/common/protocol_items.h +++ b/common/protocol_items.h @@ -476,8 +476,9 @@ public: class Event_GameJoined : public GenericEvent { Q_OBJECT public: - Event_GameJoined(int _gameId = -1, int _playerId = -1, bool _spectator = false, bool _resuming = false); + Event_GameJoined(int _gameId = -1, const QString &_gameDescription = QString(), int _playerId = -1, bool _spectator = false, bool _resuming = false); int getGameId() const { return static_cast(itemMap.value("game_id"))->getData(); }; + QString getGameDescription() const { return static_cast(itemMap.value("game_description"))->getData(); }; int getPlayerId() const { return static_cast(itemMap.value("player_id"))->getData(); }; bool getSpectator() const { return static_cast(itemMap.value("spectator"))->getData(); }; bool getResuming() const { return static_cast(itemMap.value("resuming"))->getData(); }; diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 2181bb79..cf72158d 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -193,7 +193,7 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd) if (gamePlayers[j]->getPlayerName() == playerName) { gamePlayers[j]->setProtocolHandler(this); games.insert(serverGames[i]->getGameId(), QPair(serverGames[i], gamePlayers[j])); - enqueueProtocolItem(new Event_GameJoined(serverGames[i]->getGameId(), gamePlayers[j]->getPlayerId(), gamePlayers[j]->getSpectator(), true)); + enqueueProtocolItem(new Event_GameJoined(serverGames[i]->getGameId(), serverGames[i]->getDescription(), gamePlayers[j]->getPlayerId(), gamePlayers[j]->getSpectator(), true)); enqueueProtocolItem(new Event_GameStateChanged(serverGames[i]->getGameId(), serverGames[i]->getGameStarted(), serverGames[i]->getActivePlayer(), serverGames[i]->getActivePhase(), serverGames[i]->getGameState(gamePlayers[j]))); } } @@ -279,7 +279,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd) Server_Player *creator = game->getCreator(); games.insert(game->getGameId(), QPair(game, creator)); - enqueueProtocolItem(new Event_GameJoined(game->getGameId(), creator->getPlayerId(), false, false)); + enqueueProtocolItem(new Event_GameJoined(game->getGameId(), game->getDescription(), creator->getPlayerId(), false, false)); enqueueProtocolItem(new Event_GameStateChanged(game->getGameId(), game->getGameStarted(), game->getActivePlayer(), game->getActivePhase(), game->getGameState(creator))); return RespOk; } @@ -297,7 +297,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd) if (result == RespOk) { Server_Player *player = g->addPlayer(this, cmd->getSpectator()); games.insert(cmd->getGameId(), QPair(g, player)); - enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), player->getPlayerId(), cmd->getSpectator(), false)); + enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), g->getDescription(), player->getPlayerId(), cmd->getSpectator(), false)); enqueueProtocolItem(new Event_GameStateChanged(cmd->getGameId(), g->getGameStarted(), g->getActivePlayer(), g->getActivePhase(), g->getGameState(player))); } return result; diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example index 4f742995..1a8f0ac6 100644 --- a/servatrice/servatrice.ini.example +++ b/servatrice/servatrice.ini.example @@ -22,5 +22,5 @@ size=1 1\joinmessage="This is the general chat channel. This message is only here to show that channels can have a join message." [game] -max_game_inactivity_time=300 +max_game_inactivity_time=120 max_player_inactivity_time=15