unimportant changes
This commit is contained in:
parent
4054afc759
commit
7f659573bc
21 changed files with 89 additions and 51 deletions
|
@ -43,6 +43,7 @@ public:
|
|||
CardItem *takeCard(int position, int cardId, const QString &cardName);
|
||||
void setCardAttr(int cardId, const QString &aname, const QString &avalue);
|
||||
void hoverCardEvent(CardItem *card);
|
||||
ZoneViewZone *getView() const { return view; }
|
||||
void setView(ZoneViewZone *_view);
|
||||
virtual void reorganizeCards() = 0;
|
||||
void moveAllToZone(const QString &targetZone, int targetX);
|
||||
|
|
|
@ -43,6 +43,7 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a
|
|||
connect(aDraw, SIGNAL(triggered()), this, SLOT(actDrawCard()));
|
||||
aDrawCards = new QAction(tr("D&raw cards..."), this);
|
||||
connect(aDrawCards, SIGNAL(triggered()), this, SLOT(actDrawCards()));
|
||||
aDrawCards->setShortcut(tr("Ctrl+C"));
|
||||
aRollDice = new QAction(tr("R&oll dice..."), this);
|
||||
aRollDice->setShortcut(tr("Ctrl+I"));
|
||||
connect(aRollDice, SIGNAL(triggered()), this, SLOT(actRollDice()));
|
||||
|
@ -182,10 +183,8 @@ void Game::gameEvent(const ServerEventData &msg)
|
|||
if (started) {
|
||||
started = false;
|
||||
emit logReadyStart(p->getName());
|
||||
if (!p->getLocal()) {
|
||||
// XXX Zoneviews schließen
|
||||
if (!p->getLocal())
|
||||
restartGameDialog();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case eventGameStart:
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "cardzone.h"
|
||||
#include "playerarea.h"
|
||||
#include "counter.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include <QGraphicsScene>
|
||||
#include <QMenu>
|
||||
|
||||
|
@ -85,7 +86,7 @@ void Player::actMoveHandToBottomLibrary()
|
|||
|
||||
void Player::actViewLibrary()
|
||||
{
|
||||
emit addZoneView(this, "deck", 0);
|
||||
emit toggleZoneView(this, "deck", 0);
|
||||
}
|
||||
|
||||
void Player::actViewTopCards()
|
||||
|
@ -94,23 +95,23 @@ void Player::actViewTopCards()
|
|||
int number = QInputDialog::getInteger(0, tr("View top cards of library"), tr("Number of cards:"), defaultNumberTopCards, 1, 2000000000, 1, &ok);
|
||||
if (ok) {
|
||||
defaultNumberTopCards = number;
|
||||
emit addZoneView(this, "deck", number);
|
||||
emit toggleZoneView(this, "deck", number);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::actViewGraveyard()
|
||||
{
|
||||
emit addZoneView(this, "grave", 0);
|
||||
emit toggleZoneView(this, "grave", 0);
|
||||
}
|
||||
|
||||
void Player::actViewRfg()
|
||||
{
|
||||
emit addZoneView(this, "rfg", 0);
|
||||
emit toggleZoneView(this, "rfg", 0);
|
||||
}
|
||||
|
||||
void Player::actViewSideboard()
|
||||
{
|
||||
emit addZoneView(this, "sb", 0);
|
||||
emit toggleZoneView(this, "sb", 0);
|
||||
}
|
||||
|
||||
void Player::addZone(CardZone *z)
|
||||
|
@ -155,8 +156,11 @@ void Player::gameEvent(const ServerEventData &event)
|
|||
// XXX Fehlerbehandlung
|
||||
|
||||
// Clean up existing zones first
|
||||
for (int i = 0; i < zones.size(); i++)
|
||||
for (int i = 0; i < zones.size(); i++) {
|
||||
if (ZoneViewZone *view = zones.at(i)->getView())
|
||||
emit closeZoneView(view);
|
||||
zones.at(i)->clearContents();
|
||||
}
|
||||
|
||||
area->clearCounters();
|
||||
|
||||
|
|
|
@ -11,13 +11,15 @@ class CardDatabase;
|
|||
class QMenu;
|
||||
class QAction;
|
||||
class PlayerArea;
|
||||
class ZoneViewZone;
|
||||
|
||||
class Player : public QObject {
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void moveCard(int cardId, QString startZone, QString targetZone, int x, int y);
|
||||
void hoverCard(QString name);
|
||||
void addZoneView(Player *player, QString zoneName, int number);
|
||||
void closeZoneView(ZoneViewZone *zone);
|
||||
void toggleZoneView(Player *player, QString zoneName, int number);
|
||||
void sigShowCardMenu(QPoint p);
|
||||
// Log events
|
||||
void logMoveCard(QString playerName, QString cardName, QString startZone, QString targetZone);
|
||||
|
|
|
@ -43,7 +43,8 @@ void MainWindow::hoverCard(QString name)
|
|||
void MainWindow::playerAdded(Player *player)
|
||||
{
|
||||
menuBar()->addMenu(player->getPlayerMenu());
|
||||
connect(player, SIGNAL(addZoneView(Player *, QString, int)), zoneLayout, SLOT(addItem(Player *, QString, int)));
|
||||
connect(player, SIGNAL(toggleZoneView(Player *, QString, int)), zoneLayout, SLOT(toggleZoneView(Player *, QString, int)));
|
||||
connect(player, SIGNAL(closeZoneView(ZoneViewZone *)), zoneLayout, SLOT(removeItem(ZoneViewZone *)));
|
||||
}
|
||||
|
||||
void MainWindow::playerRemoved(Player *player)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "zoneviewlayout.h"
|
||||
#include "zoneviewwidget.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include "player.h"
|
||||
|
||||
ZoneViewLayout::ZoneViewLayout(CardDatabase *_db, QGraphicsItem *parent)
|
||||
|
@ -30,8 +31,17 @@ void ZoneViewLayout::reorganize()
|
|||
emit sizeChanged();
|
||||
}
|
||||
|
||||
void ZoneViewLayout::addItem(Player *player, const QString &zoneName, int numberCards)
|
||||
void ZoneViewLayout::toggleZoneView(Player *player, const QString &zoneName, int numberCards)
|
||||
{
|
||||
for (int i = 0; i < views.size(); i++) {
|
||||
ZoneViewZone *temp = views[i]->getZone();
|
||||
if ((temp->getName() == zoneName) && (temp->getPlayer() == player)) { // view is already open
|
||||
removeItem(views[i]);
|
||||
if (temp->getNumberCards() == numberCards)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ZoneViewWidget *item = new ZoneViewWidget(db, player, player->getZones()->findZone(zoneName), numberCards, this);
|
||||
views.append(item);
|
||||
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeItem(ZoneViewWidget *)));
|
||||
|
@ -46,6 +56,11 @@ void ZoneViewLayout::removeItem(ZoneViewWidget *item)
|
|||
reorganize();
|
||||
}
|
||||
|
||||
void ZoneViewLayout::removeItem(ZoneViewZone *item)
|
||||
{
|
||||
removeItem(dynamic_cast<ZoneViewWidget *>(item->parentItem()));
|
||||
}
|
||||
|
||||
void ZoneViewLayout::closeMostRecentZoneView()
|
||||
{
|
||||
if (views.isEmpty())
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
class CardDatabase;
|
||||
class ZoneViewWidget;
|
||||
class ZoneViewZone;
|
||||
class Player;
|
||||
|
||||
class ZoneViewLayout : public QGraphicsWidget {
|
||||
|
@ -18,8 +19,9 @@ public:
|
|||
ZoneViewLayout(CardDatabase *_db, QGraphicsItem *parent = 0);
|
||||
void reorganize();
|
||||
public slots:
|
||||
void addItem(Player *player, const QString &zoneName, int numberCards = 0);
|
||||
void toggleZoneView(Player *player, const QString &zoneName, int numberCards = 0);
|
||||
void removeItem(ZoneViewWidget *item);
|
||||
void removeItem(ZoneViewZone *item);
|
||||
void closeMostRecentZoneView();
|
||||
void clear();
|
||||
};
|
||||
|
|
|
@ -30,6 +30,7 @@ private slots:
|
|||
void zoneDumpReceived(int commandId, QList<ServerZoneCard *> cards);
|
||||
public:
|
||||
ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_origZone, int numberCards = 0, QGraphicsItem *parent = 0);
|
||||
ZoneViewZone *getZone() const { return zone; }
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
};
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
bool initializeCards();
|
||||
void removeCard(int position);
|
||||
void setHeight(int _height) { height = _height; }
|
||||
int getNumberCards() const { return numberCards; }
|
||||
protected:
|
||||
void addCardImpl(CardItem *card, int x, int y);
|
||||
};
|
||||
|
|
|
@ -19,7 +19,8 @@ HEADERS += src/server.h src/servergame.h src/serversocket.h \
|
|||
src/card.h \
|
||||
src/version.h \
|
||||
src/counter.h \
|
||||
src/random.h \
|
||||
src/abstractrng.h \
|
||||
src/rng_qt.h \
|
||||
src/returnmessage.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/server.cpp \
|
||||
|
@ -28,5 +29,5 @@ SOURCES += src/main.cpp \
|
|||
src/playerzone.cpp \
|
||||
src/card.cpp \
|
||||
src/counter.cpp \
|
||||
src/random.cpp \
|
||||
src/rng_qt.cpp \
|
||||
src/returnmessage.cpp
|
||||
|
|
13
servatrice/src/abstractrng.h
Normal file
13
servatrice/src/abstractrng.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef ABSTRACTRNG_H
|
||||
#define ABSTRACTRNG_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class AbstractRNG : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AbstractRNG(QObject *parent = 0) : QObject(parent) { }
|
||||
virtual unsigned int getNumber(unsigned int min, unsigned int max) = 0;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,7 +18,7 @@
|
|||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "playerzone.h"
|
||||
#include "random.h"
|
||||
#include "abstractrng.h"
|
||||
#include "card.h"
|
||||
|
||||
PlayerZone::PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _is_private, bool _id_access)
|
||||
|
@ -32,7 +32,7 @@ PlayerZone::~PlayerZone()
|
|||
clear();
|
||||
}
|
||||
|
||||
void PlayerZone::shuffle(Random *rnd)
|
||||
void PlayerZone::shuffle(AbstractRNG *rnd)
|
||||
{
|
||||
QList<Card *> temp;
|
||||
for (int i = cards.size(); i; i--)
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <QString>
|
||||
|
||||
class Card;
|
||||
class Random;
|
||||
class AbstractRNG;
|
||||
|
||||
class PlayerZone {
|
||||
private:
|
||||
|
@ -52,7 +52,7 @@ public:
|
|||
|
||||
QList<Card *> cards;
|
||||
void insertCard(Card *card, int x, int y);
|
||||
void shuffle(Random *rnd);
|
||||
void shuffle(AbstractRNG *rnd);
|
||||
void clear();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef RANDOM_H
|
||||
#define RANDOM_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Random : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Random(QObject *parent = 0);
|
||||
unsigned int getNumber(unsigned int min, unsigned int max);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,16 +1,16 @@
|
|||
#include "random.h"
|
||||
#include "rng_qt.h"
|
||||
#include <QDateTime>
|
||||
#include <stdlib.h>
|
||||
|
||||
Random::Random(QObject *parent)
|
||||
: QObject(parent)
|
||||
RNG_Qt::RNG_Qt(QObject *parent)
|
||||
: AbstractRNG(parent)
|
||||
{
|
||||
int seed = QDateTime::currentDateTime().toTime_t();
|
||||
qDebug(QString("qsrand(%1)").arg(seed).toLatin1());
|
||||
qsrand(seed);
|
||||
}
|
||||
|
||||
unsigned int Random::getNumber(unsigned int min, unsigned int max)
|
||||
unsigned int RNG_Qt::getNumber(unsigned int min, unsigned int max)
|
||||
{
|
||||
int r = qrand();
|
||||
return min + (unsigned int) (((double) (max + 1 - min)) * r / (RAND_MAX + 1.0));
|
13
servatrice/src/rng_qt.h
Normal file
13
servatrice/src/rng_qt.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef RNG_QT_H
|
||||
#define RNG_QT_H
|
||||
|
||||
#include "abstractrng.h"
|
||||
|
||||
class RNG_Qt : public AbstractRNG {
|
||||
Q_OBJECT
|
||||
public:
|
||||
RNG_Qt(QObject *parent = 0);
|
||||
unsigned int getNumber(unsigned int min, unsigned int max);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -21,12 +21,15 @@
|
|||
#include "servergame.h"
|
||||
#include "serversocket.h"
|
||||
#include "counter.h"
|
||||
#include "rng_qt.h"
|
||||
#include <QtSql>
|
||||
#include <QSettings>
|
||||
|
||||
Server::Server(QObject *parent)
|
||||
: QTcpServer(parent), nextGameId(0)
|
||||
{
|
||||
rng = new RNG_Qt(this);
|
||||
|
||||
settings = new QSettings("servatrice.ini", QSettings::IniFormat, this);
|
||||
|
||||
QString dbType = settings->value("database/type").toString();
|
||||
|
|
|
@ -26,6 +26,7 @@ class ServerGame;
|
|||
class ServerSocket;
|
||||
class QSqlDatabase;
|
||||
class QSettings;
|
||||
class AbstractRNG;
|
||||
|
||||
enum AuthenticationResult { PasswordWrong = 0, PasswordRight = 1, UnknownUser = 2 };
|
||||
|
||||
|
@ -45,10 +46,12 @@ public:
|
|||
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
||||
QList<ServerGame *> listOpenGames();
|
||||
ServerGame *getGame(int gameId);
|
||||
AbstractRNG *getRNG() const { return rng; }
|
||||
private:
|
||||
void incomingConnection(int SocketId);
|
||||
QList<ServerGame *> games;
|
||||
int nextGameId;
|
||||
AbstractRNG *rng;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,19 +18,17 @@
|
|||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "servergame.h"
|
||||
#include "random.h"
|
||||
#include "serversocket.h"
|
||||
#include <QSqlQuery>
|
||||
|
||||
ServerGame::ServerGame(ServerSocket *_creator, int _gameId, QString _description, QString _password, int _maxPlayers, QObject *parent)
|
||||
: QObject(parent), gameStarted(false), rnd(0), creator(_creator), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers)
|
||||
: QObject(parent), gameStarted(false), creator(_creator), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers)
|
||||
{
|
||||
}
|
||||
|
||||
ServerGame::~ServerGame()
|
||||
{
|
||||
emit gameClosing();
|
||||
delete rnd;
|
||||
qDebug("ServerGame destructor");
|
||||
}
|
||||
|
||||
|
@ -103,11 +101,6 @@ void ServerGame::startGameIfReady()
|
|||
query.exec();
|
||||
}
|
||||
|
||||
if (!rnd) {
|
||||
rnd = new Random(this);
|
||||
rnd->init();
|
||||
}
|
||||
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
players.at(i)->setupZones();
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <QStringList>
|
||||
|
||||
class ServerSocket;
|
||||
class Random;
|
||||
|
||||
class ServerGame : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -37,7 +36,6 @@ signals:
|
|||
public slots:
|
||||
void broadcastEvent(const QString &event, ServerSocket *player);
|
||||
public:
|
||||
Random *rnd;
|
||||
ServerSocket *creator;
|
||||
int gameId;
|
||||
QString description;
|
||||
|
@ -57,7 +55,6 @@ public:
|
|||
int getActivePhase() { return activePhase; }
|
||||
void setActivePlayer(int _activePlayer);
|
||||
void setActivePhase(int _activePhase);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "playerzone.h"
|
||||
#include "counter.h"
|
||||
#include "card.h"
|
||||
#include "random.h"
|
||||
#include "abstractrng.h"
|
||||
|
||||
ServerSocket::ServerSocket(Server *_server, QObject *parent)
|
||||
: QTcpSocket(parent), server(_server), game(0), authState(PasswordWrong)
|
||||
|
@ -105,7 +105,7 @@ void ServerSocket::setupZones()
|
|||
int i = 0;
|
||||
while (DeckIterator.hasNext())
|
||||
deck->cards.append(new Card(DeckIterator.next(), i++, 0, 0));
|
||||
deck->shuffle(game->rnd);
|
||||
deck->shuffle(server->getRNG());
|
||||
|
||||
QListIterator<QString> SBIterator(SideboardList);
|
||||
while (SBIterator.hasNext())
|
||||
|
@ -315,7 +315,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdReadyStart(const QList<QVariant> &par
|
|||
ReturnMessage::ReturnCode ServerSocket::cmdShuffle(const QList<QVariant> ¶ms)
|
||||
{
|
||||
Q_UNUSED(params);
|
||||
getZone("deck")->shuffle(game->rnd);
|
||||
getZone("deck")->shuffle(server->getRNG());
|
||||
emit broadcastEvent("shuffle", this);
|
||||
return ReturnMessage::ReturnOk;
|
||||
}
|
||||
|
@ -367,6 +367,8 @@ ReturnMessage::ReturnCode ServerSocket::cmdMoveCard(const QList<QVariant> ¶m
|
|||
if (!card)
|
||||
return ReturnMessage::ReturnContextError;
|
||||
int x = params[3].toInt();
|
||||
if (x == -1)
|
||||
x = targetzone->cards.size();
|
||||
int y = 0;
|
||||
if (targetzone->hasCoords())
|
||||
y = params[4].toInt();
|
||||
|
@ -571,7 +573,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpZone(const QList<QVariant> ¶m
|
|||
ReturnMessage::ReturnCode ServerSocket::cmdRollDice(const QList<QVariant> ¶ms)
|
||||
{
|
||||
int sides = params[0].toInt();
|
||||
emit broadcastEvent(QString("roll_dice|%1|%2").arg(sides).arg(game->rnd->getNumber(1, sides)), this);
|
||||
emit broadcastEvent(QString("roll_dice|%1|%2").arg(sides).arg(server->getRNG()->getNumber(1, sides)), this);
|
||||
return ReturnMessage::ReturnOk;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue