diff --git a/cockatrice/cockatrice.pro b/cockatrice/cockatrice.pro index 019fbcc6..0def3f23 100644 --- a/cockatrice/cockatrice.pro +++ b/cockatrice/cockatrice.pro @@ -15,5 +15,5 @@ QT += network #QTPLUGIN += qjpeg # Input -HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h setsmodel.h src/window_sets.h -SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp src/setsmodel.cpp src/window_sets.cpp +HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h setsmodel.h src/window_sets.h src/dlg_editmessages.h +SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp src/setsmodel.cpp src/window_sets.cpp src/dlg_editmessages.cpp diff --git a/cockatrice/src/dlg_editmessages.cpp b/cockatrice/src/dlg_editmessages.cpp new file mode 100644 index 00000000..7f2c99f3 --- /dev/null +++ b/cockatrice/src/dlg_editmessages.cpp @@ -0,0 +1,76 @@ +#include +#include "dlg_editmessages.h" + +DlgEditMessages::DlgEditMessages(QWidget *parent) + : QDialog(parent) +{ + aAdd = new QAction(tr("Add"), this); + connect(aAdd, SIGNAL(triggered()), this, SLOT(actAdd())); + aRemove = new QAction(tr("Remove"), this); + connect(aRemove, SIGNAL(triggered()), this, SLOT(actRemove())); + + messageList = new QListWidget; + QToolBar *messageToolBar = new QToolBar; + messageToolBar->setOrientation(Qt::Vertical); + messageToolBar->addAction(aAdd); + messageToolBar->addAction(aRemove); + + QSettings settings; + settings.beginGroup("messages"); + int count = settings.value("count", 0).toInt(); + for (int i = 0; i < count; i++) + messageList->addItem(settings.value(QString("msg%1").arg(i)).toString()); + + QHBoxLayout *listLayout = new QHBoxLayout; + listLayout->addWidget(messageList); + listLayout->addWidget(messageToolBar); + + cancelButton = new QPushButton(tr("&Cancel")); + okButton = new QPushButton(tr("O&K")); + okButton->setAutoDefault(true); + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addStretch(); + buttonLayout->addWidget(cancelButton); + buttonLayout->addWidget(okButton); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(listLayout); + mainLayout->addLayout(buttonLayout); + + setLayout(mainLayout); + + setWindowTitle(tr("Edit messages")); + setMinimumWidth(sizeHint().width()); + resize(300, 300); + + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); + connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); +} + +void DlgEditMessages::storeSettings() +{ + QSettings settings; + settings.beginGroup("messages"); + settings.setValue("count", messageList->count()); + for (int i = 0; i < messageList->count(); i++) + settings.setValue(QString("msg%1").arg(i), messageList->item(i)->text()); +} + +void DlgEditMessages::actAdd() +{ + bool ok; + QString msg = QInputDialog::getText(this, tr("Add message"), QString("Message:"), QLineEdit::Normal, QString(), &ok); + if (ok) { + messageList->addItem(msg); + storeSettings(); + } +} + +void DlgEditMessages::actRemove() +{ + if (messageList->currentItem()) { + delete messageList->takeItem(messageList->currentRow()); + storeSettings(); + } +} diff --git a/cockatrice/src/dlg_editmessages.h b/cockatrice/src/dlg_editmessages.h new file mode 100644 index 00000000..583f65f4 --- /dev/null +++ b/cockatrice/src/dlg_editmessages.h @@ -0,0 +1,24 @@ +#ifndef DLG_EDITMESSAGES_H +#define DLG_EDITMESSAGES_H + +#include + +class QListWidget; +class QPushButton; + +class DlgEditMessages: public QDialog { + Q_OBJECT +public: + DlgEditMessages(QWidget *parent = 0); +private slots: + void actAdd(); + void actRemove(); +private: + QListWidget *messageList; + QAction *aAdd, *aRemove; + QPushButton *cancelButton, *okButton; + + void storeSettings(); +}; + +#endif diff --git a/cockatrice/src/game.cpp b/cockatrice/src/game.cpp index fdf5c247..437e02e1 100644 --- a/cockatrice/src/game.cpp +++ b/cockatrice/src/game.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "serverplayer.h" #include "game.h" #include "servereventdata.h" @@ -9,6 +10,7 @@ #include "handzone.h" #include "carddatabase.h" #include "dlg_startgame.h" +#include "dlg_editmessages.h" #include "playerarea.h" #include "counter.h" @@ -51,6 +53,9 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a aCreateToken = new QAction(tr("&Create token..."), this); aCreateToken->setShortcut(tr("Ctrl+T")); connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken())); + + aEditMessages = new QAction(tr("&Edit messages..."), this); + connect(aEditMessages, SIGNAL(triggered()), this, SLOT(actEditMessages())); actionsMenu->addAction(aUntapAll); actionsMenu->addSeparator(); @@ -64,6 +69,9 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a actionsMenu->addAction(aRollDice); actionsMenu->addSeparator(); actionsMenu->addAction(aCreateToken); + actionsMenu->addSeparator(); + sayMenu = actionsMenu->addMenu(tr("S&ay")); + initSayMenu(); aTap = new QAction(tr("&Tap"), this); connect(aTap, SIGNAL(triggered()), this, SLOT(actTap())); @@ -108,6 +116,32 @@ Game::~Game() } } +void Game::initSayMenu() +{ + sayMenu->clear(); + sayMenu->addAction(aEditMessages); + sayMenu->addSeparator(); + + QSettings settings; + settings.beginGroup("messages"); + int count = settings.value("count", 0).toInt(); + for (int i = 0; i < count; i++) { + QAction *newAction = new QAction(settings.value(QString("msg%1").arg(i)).toString(), this); + QString shortcut; + switch (i) { + case 0: shortcut = tr("F5"); break; + case 1: shortcut = tr("F6"); break; + case 2: shortcut = tr("F7"); break; + case 3: shortcut = tr("F8"); break; + case 4: shortcut = tr("F9"); break; + case 5: shortcut = tr("F10"); break; + } + newAction->setShortcut(shortcut); + connect(newAction, SIGNAL(triggered()), this, SLOT(actSayMessage())); + sayMenu->addAction(newAction); + } +} + Player *Game::addPlayer(int playerId, const QString &playerName, QPointF base, bool local) { Player *newPlayer = new Player(playerName, playerId, base, local, db, client, scene); @@ -295,6 +329,13 @@ void Game::actCreateToken() client->createToken("table", cardname, QString(), 0, 0); } +void Game::actEditMessages() +{ + DlgEditMessages dlg; + if (dlg.exec()) + initSayMenu(); +} + void Game::showCardMenu(QPoint p) { cardMenu->exec(p); @@ -396,3 +437,9 @@ void Game::actRearrange() client->moveCard(temp->getId(), zoneName, zoneName, x, y); } } + +void Game::actSayMessage() +{ + QAction *a = qobject_cast(sender()); + client->say(a->text()); +} diff --git a/cockatrice/src/game.h b/cockatrice/src/game.h index 0d36cbe6..66d675bd 100644 --- a/cockatrice/src/game.h +++ b/cockatrice/src/game.h @@ -14,9 +14,9 @@ class DlgStartGame; class Game : public QObject { Q_OBJECT private: - QMenu *actionsMenu, *cardMenu; + QMenu *actionsMenu, *sayMenu, *cardMenu; QAction *aTap, *aUntap, *aDoesntUntap, *aFlip, *aAddCounter, *aRemoveCounter, *aSetCounters, *aRearrange, - *aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aShuffle, *aDraw, *aDrawCards, *aRollDice, *aCreateToken; + *aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aShuffle, *aDraw, *aDrawCards, *aRollDice, *aCreateToken, *aEditMessages; DlgStartGame *dlgStartGame; CardDatabase *db; @@ -26,6 +26,7 @@ private: Player *localPlayer; bool started; Player *addPlayer(int playerId, const QString &playerName, QPointF base, bool local); + void initSayMenu(); private slots: void actUntapAll(); void actIncLife(); @@ -36,6 +37,7 @@ private slots: void actDrawCards(); void actRollDice(); void actCreateToken(); + void actEditMessages(); void showCardMenu(QPoint p); void actTap(); @@ -46,6 +48,8 @@ private slots: void actRemoveCounter(); void actSetCounters(); void actRearrange(); + + void actSayMessage(); void gameEvent(const ServerEventData &msg); void playerListReceived(QList playerList); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index a0ef1879..8cd365bd 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -21,14 +21,14 @@ Player::Player(const QString &_name, int _id, QPointF _base, bool _local, CardDa aViewLibrary = new QAction(tr("&View library"), this); if (local) - aViewLibrary->setShortcut(tr("F5")); + aViewLibrary->setShortcut(tr("F3")); connect(aViewLibrary, SIGNAL(triggered()), this, SLOT(actViewLibrary())); aViewTopCards = new QAction(tr("View &top cards of library..."), this); connect(aViewTopCards, SIGNAL(triggered()), this, SLOT(actViewTopCards())); aViewGraveyard = new QAction(tr("&View graveyard"), this); if (local) - aViewGraveyard->setShortcut(tr("F6")); + aViewGraveyard->setShortcut(tr("F4")); connect(aViewGraveyard, SIGNAL(triggered()), this, SLOT(actViewGraveyard())); aViewRfg = new QAction(tr("&View removed cards"), this); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 446d9a83..0265f1c1 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -190,7 +190,7 @@ void MainWindow::createActions() aDeckEditor = new QAction(tr("&Deck editor"), this); connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor())); aFullScreen = new QAction(tr("&Full screen"), this); - aFullScreen->setShortcut(tr("F4")); + aFullScreen->setShortcut(tr("Ctrl+F4")); aFullScreen->setCheckable(true); connect(aFullScreen, SIGNAL(toggled(bool)), this, SLOT(actFullScreen(bool))); aExit = new QAction(tr("&Exit"), this);