mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-26 16:43:55 -07:00
blah
This commit is contained in:
parent
55482246dd
commit
59e9416f57
29 changed files with 332 additions and 187 deletions
|
|
@ -74,14 +74,12 @@ void CardItem::resetState()
|
|||
|
||||
void CardItem::processCardInfo(ServerInfo_Card *info)
|
||||
{
|
||||
id = info->getId();
|
||||
name = info->getName();
|
||||
attacking = info->getAttacking();
|
||||
counters = info->getCounters();
|
||||
annotation = info->getAnnotation();
|
||||
tapped = info->getTapped();
|
||||
|
||||
update();
|
||||
setId(info->getId());
|
||||
setName(info->getName());
|
||||
setAttacking(info->getAttacking());
|
||||
setCounters(info->getCounters());
|
||||
setAnnotation(info->getAnnotation());
|
||||
setTapped(info->getTapped());
|
||||
}
|
||||
|
||||
CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown)
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
|
||||
void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
||||
{
|
||||
dumpObjectInfo();
|
||||
if (view)
|
||||
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1))
|
||||
view->addCard(new CardItem(player, card->getName(), card->getId()), reorganize, x, y);
|
||||
|
|
@ -90,7 +91,6 @@ void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
|||
|
||||
if (reorganize) {
|
||||
qDebug("------------ emitting");
|
||||
dumpObjectInfo();
|
||||
emit contentsChanged();
|
||||
reorganizeCards();
|
||||
}
|
||||
|
|
@ -111,6 +111,15 @@ CardItem *CardZone::getCard(int cardId, const QString &cardName)
|
|||
|
||||
CardItem *CardZone::takeCard(int position, int cardId, const QString &cardName, bool /*canResize*/)
|
||||
{
|
||||
if (position == -1) {
|
||||
for (int i = 0; i < cards.size(); ++i)
|
||||
if (cards[i]->getId() == cardId) {
|
||||
position = i;
|
||||
break;
|
||||
}
|
||||
if (position == -1)
|
||||
return 0;
|
||||
}
|
||||
Q_ASSERT(position < cards.size());
|
||||
|
||||
CardItem *c = cards.takeAt(position);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ Client::~Client()
|
|||
|
||||
void Client::slotSocketError(QAbstractSocket::SocketError /*error*/)
|
||||
{
|
||||
emit logSocketError(socket->errorString());
|
||||
emit socketError(socket->errorString());
|
||||
disconnectFromServer();
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ void Client::loginResponse(ResponseCode response)
|
|||
setStatus(StatusLoggedIn);
|
||||
else {
|
||||
emit serverError(response);
|
||||
disconnectFromServer();
|
||||
setStatus(StatusDisconnecting);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,10 +82,13 @@ void Client::readData()
|
|||
connect(cmdLogin, SIGNAL(finished(ResponseCode)), this, SLOT(loginResponse(ResponseCode)));
|
||||
sendCommand(cmdLogin);
|
||||
|
||||
topLevelItem->read(xmlReader);
|
||||
if (topLevelItem)
|
||||
topLevelItem->read(xmlReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status == StatusDisconnecting)
|
||||
disconnectFromServer();
|
||||
}
|
||||
|
||||
void Client::processProtocolItem(ProtocolItem *item)
|
||||
|
|
@ -96,10 +99,9 @@ void Client::processProtocolItem(ProtocolItem *item)
|
|||
if (!cmd)
|
||||
return;
|
||||
|
||||
pendingCommands.remove(cmd->getCmdId());
|
||||
cmd->processResponse(response);
|
||||
delete response;
|
||||
|
||||
pendingCommands.remove(cmd->getCmdId());
|
||||
delete cmd;
|
||||
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ class Event_GameJoined;
|
|||
|
||||
enum ClientStatus {
|
||||
StatusDisconnected,
|
||||
StatusDisconnecting,
|
||||
StatusConnecting,
|
||||
StatusAwaitingWelcome,
|
||||
StatusLoggingIn,
|
||||
|
|
@ -36,7 +37,7 @@ signals:
|
|||
void statusChanged(ClientStatus _status);
|
||||
void maxPingTime(int seconds, int maxSeconds);
|
||||
void serverTimeout();
|
||||
void logSocketError(const QString &errorString);
|
||||
void socketError(const QString &errorString);
|
||||
void serverError(ResponseCode resp);
|
||||
void protocolVersionMismatch(int clientVersion, int serverVersion);
|
||||
void protocolError();
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ DlgConnect::DlgConnect(QWidget *parent)
|
|||
|
||||
setWindowTitle(tr("Connect to server"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
setMinimumWidth(300);
|
||||
|
||||
connect(okButton, SIGNAL(clicked()), this, SLOT(actOk()));
|
||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||||
|
|
|
|||
|
|
@ -546,14 +546,18 @@ void Player::eventMoveCard(Event_MoveCard *event)
|
|||
if (!startZone || !targetZone)
|
||||
return;
|
||||
|
||||
qDebug("Player::eventMoveCard --- startZone");
|
||||
startZone->dumpObjectInfo();
|
||||
qDebug("Player::eventMoveCard --- targetZone");
|
||||
targetZone->dumpObjectInfo();
|
||||
qDebug("---");
|
||||
|
||||
int position = event->getPosition();
|
||||
int x = event->getX();
|
||||
int y = event->getY();
|
||||
|
||||
int logPosition = position;
|
||||
int logX = x;
|
||||
if (position == -1)
|
||||
position = 0;
|
||||
if (x == -1)
|
||||
x = 0;
|
||||
CardItem *card = startZone->takeCard(position, event->getCardId(), event->getCardName(), startZone != targetZone);
|
||||
|
|
@ -702,8 +706,8 @@ void Player::processPlayerInfo(ServerInfo_Player *info)
|
|||
} else {
|
||||
for (int j = 0; j < cardList.size(); ++j) {
|
||||
CardItem *card = new CardItem(this);
|
||||
card->processCardInfo(cardList[i]);
|
||||
zone->addCard(card, false, cardList[i]->getX(), cardList[i]->getY());
|
||||
card->processCardInfo(cardList[j]);
|
||||
zone->addCard(card, false, cardList[j]->getX(), cardList[j]->getY());
|
||||
}
|
||||
}
|
||||
zone->reorganizeCards();
|
||||
|
|
|
|||
|
|
@ -22,11 +22,25 @@ TabChatChannel::TabChatChannel(Client *_client, const QString &_channelName)
|
|||
hbox->addLayout(vbox);
|
||||
hbox->addWidget(playerList);
|
||||
|
||||
aLeaveChannel = new QAction(this);
|
||||
connect(aLeaveChannel, SIGNAL(triggered()), this, SLOT(actLeaveChannel()));
|
||||
|
||||
tabMenu = new QMenu(this);
|
||||
tabMenu->addAction(aLeaveChannel);
|
||||
|
||||
retranslateUi();
|
||||
setLayout(hbox);
|
||||
}
|
||||
|
||||
TabChatChannel::~TabChatChannel()
|
||||
{
|
||||
emit channelClosing(this);
|
||||
}
|
||||
|
||||
void TabChatChannel::retranslateUi()
|
||||
{
|
||||
tabMenu->setTitle(tr("C&hat channel"));
|
||||
aLeaveChannel->setText(tr("&Leave channel"));
|
||||
}
|
||||
|
||||
void TabChatChannel::sendMessage()
|
||||
|
|
@ -38,6 +52,12 @@ void TabChatChannel::sendMessage()
|
|||
sayEdit->clear();
|
||||
}
|
||||
|
||||
void TabChatChannel::actLeaveChannel()
|
||||
{
|
||||
client->sendCommand(new Command_ChatLeaveChannel(channelName));
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
void TabChatChannel::processChatEvent(ChatEvent *event)
|
||||
{
|
||||
switch (event->getItemId()) {
|
||||
|
|
|
|||
|
|
@ -22,8 +22,13 @@ private:
|
|||
QListWidget *playerList;
|
||||
QTextEdit *textEdit;
|
||||
QLineEdit *sayEdit;
|
||||
|
||||
QAction *aLeaveChannel;
|
||||
signals:
|
||||
void channelClosing(TabChatChannel *tab);
|
||||
private slots:
|
||||
void sendMessage();
|
||||
void actLeaveChannel();
|
||||
|
||||
void processListPlayersEvent(Event_ChatListPlayers *event);
|
||||
void processJoinChannelEvent(Event_ChatJoinChannel *event);
|
||||
|
|
@ -31,8 +36,10 @@ private slots:
|
|||
void processSayEvent(Event_ChatSay *event);
|
||||
public:
|
||||
TabChatChannel(Client *_client, const QString &_channelName);
|
||||
~TabChatChannel();
|
||||
void retranslateUi();
|
||||
void processChatEvent(ChatEvent *event);
|
||||
QString getChannelName() const { return channelName; }
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -88,6 +88,8 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
|
|||
connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn()));
|
||||
aRemoveLocalArrows = new QAction(this);
|
||||
connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows()));
|
||||
aLeaveGame = new QAction(this);
|
||||
connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame()));
|
||||
|
||||
tabMenu = new QMenu(this);
|
||||
playersSeparator = tabMenu->addSeparator();
|
||||
|
|
@ -95,6 +97,8 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
|
|||
tabMenu->addAction(aNextTurn);
|
||||
tabMenu->addSeparator();
|
||||
tabMenu->addAction(aRemoveLocalArrows);
|
||||
tabMenu->addSeparator();
|
||||
tabMenu->addAction(aLeaveGame);
|
||||
|
||||
retranslateUi();
|
||||
setLayout(mainLayout);
|
||||
|
|
@ -102,6 +106,11 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
|
|||
messageLog->logGameJoined(gameId);
|
||||
}
|
||||
|
||||
TabGame::~TabGame()
|
||||
{
|
||||
emit gameClosing(this);
|
||||
}
|
||||
|
||||
void TabGame::retranslateUi()
|
||||
{
|
||||
tabMenu->setTitle(tr("&Game"));
|
||||
|
|
@ -111,6 +120,7 @@ void TabGame::retranslateUi()
|
|||
aNextTurn->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Return")) << QKeySequence(tr("Ctrl+Enter")));
|
||||
aRemoveLocalArrows->setText(tr("&Remove all local arrows"));
|
||||
aRemoveLocalArrows->setShortcut(tr("Ctrl+R"));
|
||||
aLeaveGame->setText(tr("&Leave game"));
|
||||
|
||||
loadLocalButton->setText(tr("Load &local deck"));
|
||||
loadRemoteButton->setText(tr("Load deck from &server"));
|
||||
|
|
@ -126,6 +136,15 @@ void TabGame::retranslateUi()
|
|||
i.next().value()->retranslateUi();
|
||||
}
|
||||
|
||||
void TabGame::actLeaveGame()
|
||||
{
|
||||
if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
sendGameCommand(new Command_LeaveGame);
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
void TabGame::actSay()
|
||||
{
|
||||
if (!sayEdit->text().isEmpty()) {
|
||||
|
|
@ -175,7 +194,6 @@ Player *TabGame::addPlayer(int playerId, const QString &playerName)
|
|||
tabMenu->insertMenu(playersSeparator, newPlayer->getPlayerMenu());
|
||||
|
||||
players.insert(playerId, newPlayer);
|
||||
emit playerAdded(newPlayer);
|
||||
|
||||
return newPlayer;
|
||||
}
|
||||
|
|
@ -207,15 +225,21 @@ void TabGame::sendGameCommand(GameCommand *command)
|
|||
client->sendCommand(command);
|
||||
}
|
||||
|
||||
void TabGame::eventGameStart(Event_GameStart * /*event*/)
|
||||
void TabGame::startGame()
|
||||
{
|
||||
currentPhase = -1;
|
||||
|
||||
|
||||
started = true;
|
||||
deckViewContainer->hide();
|
||||
gameView->show();
|
||||
phasesToolbar->show();
|
||||
}
|
||||
|
||||
void TabGame::eventGameStart(Event_GameStart * /*event*/)
|
||||
{
|
||||
startGame();
|
||||
messageLog->logGameStart();
|
||||
|
||||
|
||||
QMapIterator<int, Player *> i(players);
|
||||
while (i.hasNext())
|
||||
i.next().value()->prepareForGame();
|
||||
|
|
@ -233,26 +257,35 @@ void TabGame::eventGameStateChanged(Event_GameStateChanged *event)
|
|||
}
|
||||
player->processPlayerInfo(pl);
|
||||
}
|
||||
if (event->getGameStarted() && !started) {
|
||||
startGame();
|
||||
setActivePlayer(event->getActivePlayer());
|
||||
setActivePhase(event->getActivePhase());
|
||||
}
|
||||
}
|
||||
|
||||
void TabGame::eventJoin(Event_Join *event)
|
||||
{
|
||||
if (event->getSpectator()) {
|
||||
spectatorList.append(event->getPlayerName());
|
||||
messageLog->logJoinSpectator(event->getPlayerName());
|
||||
ServerInfo_Player *playerInfo = event->getPlayer();
|
||||
if (playerInfo->getSpectator()) {
|
||||
spectatorList.append(playerInfo->getName());
|
||||
messageLog->logJoinSpectator(playerInfo->getName());
|
||||
} else {
|
||||
Player *newPlayer = addPlayer(event->getPlayerId(), event->getPlayerName());
|
||||
Player *newPlayer = addPlayer(playerInfo->getPlayerId(), playerInfo->getName());
|
||||
messageLog->logJoin(newPlayer);
|
||||
playerListWidget->addPlayer(playerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void TabGame::eventLeave(Event_Leave *event)
|
||||
{
|
||||
Player *player = players.value(event->getPlayerId(), 0);
|
||||
int playerId = event->getPlayerId();
|
||||
Player *player = players.value(playerId, 0);
|
||||
if (!player)
|
||||
return;
|
||||
|
||||
messageLog->logLeave(player);
|
||||
playerListWidget->removePlayer(playerId);
|
||||
}
|
||||
|
||||
void TabGame::eventGameClosed(Event_GameClosed * /*event*/)
|
||||
|
|
@ -261,29 +294,43 @@ void TabGame::eventGameClosed(Event_GameClosed * /*event*/)
|
|||
messageLog->logGameClosed();
|
||||
}
|
||||
|
||||
void TabGame::eventSetActivePlayer(Event_SetActivePlayer *event)
|
||||
Player *TabGame::setActivePlayer(int id)
|
||||
{
|
||||
Player *player = players.value(event->getActivePlayerId(), 0);
|
||||
Player *player = players.value(id, 0);
|
||||
if (!player)
|
||||
return;
|
||||
playerListWidget->setActivePlayer(event->getActivePlayerId());
|
||||
return 0;
|
||||
playerListWidget->setActivePlayer(id);
|
||||
QMapIterator<int, Player *> i(players);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
i.value()->setActive(i.value() == player);
|
||||
}
|
||||
messageLog->logSetActivePlayer(player);
|
||||
currentPhase = -1;
|
||||
return player;
|
||||
}
|
||||
|
||||
void TabGame::eventSetActivePlayer(Event_SetActivePlayer *event)
|
||||
{
|
||||
Player *player = setActivePlayer(event->getActivePlayerId());
|
||||
if (!player)
|
||||
return;
|
||||
messageLog->logSetActivePlayer(player);
|
||||
}
|
||||
|
||||
void TabGame::setActivePhase(int phase)
|
||||
{
|
||||
if (currentPhase != phase) {
|
||||
currentPhase = phase;
|
||||
phasesToolbar->setActivePhase(phase);
|
||||
}
|
||||
}
|
||||
|
||||
void TabGame::eventSetActivePhase(Event_SetActivePhase *event)
|
||||
{
|
||||
const int phase = event->getPhase();
|
||||
if (currentPhase != phase) {
|
||||
currentPhase = phase;
|
||||
phasesToolbar->setActivePhase(phase);
|
||||
int phase = event->getPhase();
|
||||
if (currentPhase != phase)
|
||||
messageLog->logSetActivePhase(phase);
|
||||
}
|
||||
setActivePhase(phase);
|
||||
}
|
||||
|
||||
void TabGame::loadLocalDeck()
|
||||
|
|
|
|||
|
|
@ -61,22 +61,22 @@ private:
|
|||
QAction *playersSeparator;
|
||||
QMenu *playersMenu;
|
||||
QAction *aCloseMostRecentZoneView,
|
||||
*aNextPhase, *aNextTurn, *aRemoveLocalArrows;
|
||||
*aLeaveGame, *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
|
||||
|
||||
Player *addPlayer(int playerId, const QString &playerName);
|
||||
|
||||
void startGame();
|
||||
void eventGameStart(Event_GameStart *event);
|
||||
void eventGameStateChanged(Event_GameStateChanged *event);
|
||||
void eventJoin(Event_Join *event);
|
||||
void eventLeave(Event_Leave *event);
|
||||
void eventGameClosed(Event_GameClosed *event);
|
||||
Player *setActivePlayer(int id);
|
||||
void eventSetActivePlayer(Event_SetActivePlayer *event);
|
||||
void setActivePhase(int phase);
|
||||
void eventSetActivePhase(Event_SetActivePhase *event);
|
||||
signals:
|
||||
// -- XXX --
|
||||
void playerAdded(Player *player);
|
||||
void playerRemoved(Player *player);
|
||||
// -- XXX --
|
||||
void gameClosing(TabGame *tab);
|
||||
private slots:
|
||||
void loadLocalDeck();
|
||||
void loadRemoteDeck();
|
||||
|
|
@ -84,14 +84,17 @@ private slots:
|
|||
void deckSelectFinished(ProtocolResponse *r);
|
||||
void newCardAdded(CardItem *card);
|
||||
|
||||
void actLeaveGame();
|
||||
void actRemoveLocalArrows();
|
||||
void actSay();
|
||||
void actNextPhase();
|
||||
void actNextTurn();
|
||||
public:
|
||||
TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator);
|
||||
~TabGame();
|
||||
void retranslateUi();
|
||||
const QMap<int, Player *> &getPlayers() const { return players; }
|
||||
int getGameId() const { return gameId; }
|
||||
|
||||
void processGameEvent(GameEvent *event);
|
||||
public slots:
|
||||
|
|
|
|||
|
|
@ -103,19 +103,37 @@ void TabSupervisor::updatePingTime(int value, int max)
|
|||
void TabSupervisor::gameJoined(Event_GameJoined *event)
|
||||
{
|
||||
TabGame *tab = new TabGame(client, event->getGameId(), event->getPlayerId(), event->getSpectator());
|
||||
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
|
||||
addTab(tab, tr("Game %1").arg(event->getGameId()));
|
||||
gameTabs.insert(event->getGameId(), tab);
|
||||
setCurrentWidget(tab);
|
||||
}
|
||||
|
||||
void TabSupervisor::gameLeft(TabGame *tab)
|
||||
{
|
||||
emit setMenu(0);
|
||||
|
||||
gameTabs.remove(tab->getGameId());
|
||||
removeTab(indexOf(tab));
|
||||
}
|
||||
|
||||
void TabSupervisor::addChatChannelTab(const QString &channelName)
|
||||
{
|
||||
TabChatChannel *tab = new TabChatChannel(client, channelName);
|
||||
connect(tab, SIGNAL(channelClosing(TabChatChannel *)), this, SLOT(chatChannelLeft(TabChatChannel *)));
|
||||
addTab(tab, channelName);
|
||||
chatChannelTabs.insert(channelName, tab);
|
||||
setCurrentWidget(tab);
|
||||
}
|
||||
|
||||
void TabSupervisor::chatChannelLeft(TabChatChannel *tab)
|
||||
{
|
||||
emit setMenu(0);
|
||||
|
||||
chatChannelTabs.remove(tab->getChannelName());
|
||||
removeTab(indexOf(tab));
|
||||
}
|
||||
|
||||
void TabSupervisor::processChatEvent(ChatEvent *event)
|
||||
{
|
||||
TabChatChannel *tab = chatChannelTabs.value(event->getChannel(), 0);
|
||||
|
|
|
|||
|
|
@ -33,9 +33,11 @@ private slots:
|
|||
void updateMenu(int index);
|
||||
void updatePingTime(int value, int max);
|
||||
void gameJoined(Event_GameJoined *event);
|
||||
void gameLeft(TabGame *tab);
|
||||
void addChatChannelTab(const QString &channelName);
|
||||
void chatChannelLeft(TabChatChannel *tab);
|
||||
void processChatEvent(ChatEvent *event);
|
||||
void processGameEvent(GameEvent *event);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@
|
|||
#include "window_deckeditor.h"
|
||||
#include "tab_supervisor.h"
|
||||
|
||||
const QString MainWindow::appName = "Cockatrice";
|
||||
|
||||
void MainWindow::updateTabMenu(QMenu *menu)
|
||||
{
|
||||
if (tabMenu)
|
||||
|
|
@ -36,60 +38,24 @@ void MainWindow::updateTabMenu(QMenu *menu)
|
|||
|
||||
void MainWindow::statusChanged(ClientStatus _status)
|
||||
{
|
||||
setClientStatusTitle();
|
||||
switch (_status) {
|
||||
case StatusConnecting:
|
||||
emit logConnecting(client->peerName());
|
||||
break;
|
||||
case StatusDisconnected:
|
||||
tabSupervisor->stop();
|
||||
// if (game) {
|
||||
// zoneLayout->clear();
|
||||
// delete game;
|
||||
// game = 0;
|
||||
// }
|
||||
aConnect->setEnabled(true);
|
||||
aDisconnect->setEnabled(false);
|
||||
// aRestartGame->setEnabled(false);
|
||||
// aLeaveGame->setEnabled(false);
|
||||
// phasesToolbar->setActivePhase(-1);
|
||||
// phasesToolbar->hide();
|
||||
emit logDisconnected();
|
||||
break;
|
||||
case StatusLoggingIn:
|
||||
emit logConnected();
|
||||
aConnect->setEnabled(false);
|
||||
aDisconnect->setEnabled(true);
|
||||
break;
|
||||
case StatusLoggedIn: {
|
||||
tabSupervisor->start(client);
|
||||
|
||||
/* if (game) {
|
||||
zoneLayout->clear();
|
||||
delete game;
|
||||
game = 0;
|
||||
}
|
||||
aRestartGame->setEnabled(false);
|
||||
aLeaveGame->setEnabled(false);
|
||||
phasesToolbar->setActivePhase(-1);
|
||||
phasesToolbar->hide();
|
||||
|
||||
view->hide();
|
||||
gameSelector->enableGameList();
|
||||
chatWidget->enableChat();
|
||||
*/ break;
|
||||
}
|
||||
// case StatusPlaying: {
|
||||
/* chatWidget->disableChat();
|
||||
|
||||
aRestartGame->setEnabled(true);
|
||||
aLeaveGame->setEnabled(true);
|
||||
|
||||
|
||||
phasesToolbar->show();
|
||||
view->show();
|
||||
break;
|
||||
}
|
||||
*/ default:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -107,18 +73,7 @@ void MainWindow::actDisconnect()
|
|||
{
|
||||
client->disconnectFromServer();
|
||||
}
|
||||
/*
|
||||
void MainWindow::actRestartGame()
|
||||
{
|
||||
zoneLayout->clear();
|
||||
game->restartGameDialog();
|
||||
}
|
||||
|
||||
void MainWindow::actLeaveGame()
|
||||
{
|
||||
client->leaveGame();
|
||||
}
|
||||
*/
|
||||
void MainWindow::actDeckEditor()
|
||||
{
|
||||
WndDeckEditor *deckEditor = new WndDeckEditor(this);
|
||||
|
|
@ -149,15 +104,40 @@ void MainWindow::serverTimeout()
|
|||
QMessageBox::critical(this, tr("Error"), tr("Server timeout"));
|
||||
}
|
||||
|
||||
void MainWindow::serverError(ResponseCode r)
|
||||
{
|
||||
switch (r) {
|
||||
case RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Invalid login data.")); break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::socketError(const QString &errorStr)
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"), tr("Socket error: %1").arg(errorStr));
|
||||
}
|
||||
|
||||
void MainWindow::protocolVersionMismatch(int localVersion, int remoteVersion)
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"), tr("Protocol version mismatch. Local version: %1, remote version: %2.").arg(localVersion).arg(remoteVersion));
|
||||
}
|
||||
|
||||
void MainWindow::setClientStatusTitle()
|
||||
{
|
||||
switch (client->getStatus()) {
|
||||
case StatusConnecting: setWindowTitle(appName + " - " + tr("Connecting to %1...").arg(client->peerName())); break;
|
||||
case StatusDisconnected: setWindowTitle(appName + " - " + tr("Disconnected")); break;
|
||||
case StatusLoggedIn: setWindowTitle(appName + " - " + tr("Logged in at %1").arg(client->peerName())); break;
|
||||
default: setWindowTitle(appName);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::retranslateUi()
|
||||
{
|
||||
setWindowTitle(tr("Cockatrice"));
|
||||
setClientStatusTitle();
|
||||
|
||||
aConnect->setText(tr("&Connect..."));
|
||||
aDisconnect->setText(tr("&Disconnect"));
|
||||
// aRestartGame->setText(tr("&Restart game..."));
|
||||
// aRestartGame->setShortcut(tr("F2"));
|
||||
// aLeaveGame->setText(tr("&Leave game"));
|
||||
aDeckEditor->setText(tr("&Deck editor"));
|
||||
aFullScreen->setText(tr("&Full screen"));
|
||||
aFullScreen->setShortcut(tr("Ctrl+F"));
|
||||
|
|
@ -174,13 +154,7 @@ void MainWindow::createActions()
|
|||
aDisconnect = new QAction(this);
|
||||
aDisconnect->setEnabled(false);
|
||||
connect(aDisconnect, SIGNAL(triggered()), this, SLOT(actDisconnect()));
|
||||
/* aRestartGame = new QAction(this);
|
||||
aRestartGame->setEnabled(false);
|
||||
connect(aRestartGame, SIGNAL(triggered()), this, SLOT(actRestartGame()));
|
||||
aLeaveGame = new QAction(this);
|
||||
aLeaveGame->setEnabled(false);
|
||||
connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame()));
|
||||
*/ aDeckEditor = new QAction(this);
|
||||
aDeckEditor = new QAction(this);
|
||||
connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor()));
|
||||
aFullScreen = new QAction(this);
|
||||
aFullScreen->setCheckable(true);
|
||||
|
|
@ -212,22 +186,16 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
QPixmapCache::setCacheLimit(200000);
|
||||
|
||||
client = new Client(this);
|
||||
connect(client, SIGNAL(serverError(ResponseCode)), this, SLOT(serverError(ResponseCode)));
|
||||
connect(client, SIGNAL(socketError(const QString &)), this, SLOT(socketError(const QString &)));
|
||||
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
|
||||
connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus)));
|
||||
connect(client, SIGNAL(protocolVersionMismatch(int, int)), this, SLOT(protocolVersionMismatch(int, int)));
|
||||
|
||||
tabSupervisor = new TabSupervisor;
|
||||
connect(tabSupervisor, SIGNAL(setMenu(QMenu *)), this, SLOT(updateTabMenu(QMenu *)));
|
||||
|
||||
setCentralWidget(tabSupervisor);
|
||||
/*
|
||||
|
||||
connect(this, SIGNAL(logConnecting(QString)), messageLog, SLOT(logConnecting(QString)));
|
||||
connect(this, SIGNAL(logConnected()), messageLog, SLOT(logConnected()));
|
||||
connect(this, SIGNAL(logDisconnected()), messageLog, SLOT(logDisconnected()));
|
||||
connect(client, SIGNAL(logSocketError(const QString &)), messageLog, SLOT(logSocketError(const QString &)));
|
||||
connect(client, SIGNAL(serverError(ResponseCode)), messageLog, SLOT(logServerError(ResponseCode)));
|
||||
connect(client, SIGNAL(protocolVersionMismatch(int, int)), messageLog, SLOT(logProtocolVersionMismatch(int, int)));
|
||||
connect(client, SIGNAL(protocolError()), messageLog, SLOT(logProtocolError()));
|
||||
*/
|
||||
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
|
||||
connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus)));
|
||||
|
||||
createActions();
|
||||
createMenus();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <QMainWindow>
|
||||
#include "client.h"
|
||||
#include "protocol_datastructures.h"
|
||||
|
||||
class TabSupervisor;
|
||||
|
||||
|
|
@ -31,6 +32,9 @@ private slots:
|
|||
void updateTabMenu(QMenu *menu);
|
||||
void statusChanged(ClientStatus _status);
|
||||
void serverTimeout();
|
||||
void serverError(ResponseCode r);
|
||||
void socketError(const QString &errorStr);
|
||||
void protocolVersionMismatch(int localVersion, int remoteVersion);
|
||||
|
||||
void actConnect();
|
||||
void actDisconnect();
|
||||
|
|
@ -38,11 +42,9 @@ private slots:
|
|||
void actFullScreen(bool checked);
|
||||
void actSettings();
|
||||
void actExit();
|
||||
signals:
|
||||
void logConnecting(QString hostname);
|
||||
void logConnected();
|
||||
void logDisconnected();
|
||||
private:
|
||||
static const QString appName;
|
||||
void setClientStatusTitle();
|
||||
void retranslateUi();
|
||||
void createActions();
|
||||
void createMenus();
|
||||
|
|
|
|||
|
|
@ -80,8 +80,8 @@ void ZoneViewWidget::resizeToZoneContents()
|
|||
int cardCount = zone->getCards().size();
|
||||
const QRectF &playersRect = static_cast<GameScene *>(scene())->getPlayersRect();
|
||||
int h = 0;
|
||||
if (cardCount * CARD_HEIGHT / 5 < playersRect.height() * 1.5)
|
||||
h = cardCount * CARD_HEIGHT / 5;
|
||||
if (cardCount * CARD_HEIGHT / 3 < playersRect.height() * 1.5)
|
||||
h = cardCount * CARD_HEIGHT / 3;
|
||||
else
|
||||
h = playersRect.height() * 1.5;
|
||||
qDebug(QString("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx resizing to %1").arg(h).toLatin1());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue