single player fixes

This commit is contained in:
Max-Wilhelm Bruker 2010-09-07 02:46:54 +02:00
parent 4d0c9962f4
commit 90ffc76730
4 changed files with 39 additions and 30 deletions

View file

@ -343,7 +343,7 @@ Player *TabGame::addPlayer(int playerId, const QString &playerName)
return newPlayer;
}
void TabGame::processGameEventContainer(GameEventContainer *cont)
void TabGame::processGameEventContainer(GameEventContainer *cont, AbstractClient *client)
{
const QList<GameEvent *> &eventList = cont->getEventList();
GameEventContext *context = cont->getContext();
@ -359,24 +359,30 @@ void TabGame::processGameEventContainer(GameEventContainer *cont)
break;
}
}
} else switch (event->getItemId()) {
case ItemId_Event_GameStateChanged: eventGameStateChanged(qobject_cast<Event_GameStateChanged *>(event), context); break;
case ItemId_Event_PlayerPropertiesChanged: eventPlayerPropertiesChanged(qobject_cast<Event_PlayerPropertiesChanged *>(event), context); break;
case ItemId_Event_Join: eventJoin(qobject_cast<Event_Join *>(event), context); break;
case ItemId_Event_Leave: eventLeave(qobject_cast<Event_Leave *>(event), context); break;
case ItemId_Event_GameClosed: eventGameClosed(qobject_cast<Event_GameClosed *>(event), context); break;
case ItemId_Event_SetActivePlayer: eventSetActivePlayer(qobject_cast<Event_SetActivePlayer *>(event), context); break;
case ItemId_Event_SetActivePhase: eventSetActivePhase(qobject_cast<Event_SetActivePhase *>(event), context); break;
case ItemId_Event_Ping: eventPing(qobject_cast<Event_Ping *>(event), context); break;
default: {
Player *player = players.value(event->getPlayerId(), 0);
if (!player) {
qDebug() << "unhandled game event: invalid player id";
break;
} else {
if ((clients.size() > 1) && (event->getPlayerId() != -1))
if (clients.at(event->getPlayerId()) != client)
continue;
switch (event->getItemId()) {
case ItemId_Event_GameStateChanged: eventGameStateChanged(qobject_cast<Event_GameStateChanged *>(event), context); break;
case ItemId_Event_PlayerPropertiesChanged: eventPlayerPropertiesChanged(qobject_cast<Event_PlayerPropertiesChanged *>(event), context); break;
case ItemId_Event_Join: eventJoin(qobject_cast<Event_Join *>(event), context); break;
case ItemId_Event_Leave: eventLeave(qobject_cast<Event_Leave *>(event), context); break;
case ItemId_Event_GameClosed: eventGameClosed(qobject_cast<Event_GameClosed *>(event), context); break;
case ItemId_Event_SetActivePlayer: eventSetActivePlayer(qobject_cast<Event_SetActivePlayer *>(event), context); break;
case ItemId_Event_SetActivePhase: eventSetActivePhase(qobject_cast<Event_SetActivePhase *>(event), context); break;
case ItemId_Event_Ping: eventPing(qobject_cast<Event_Ping *>(event), context); break;
default: {
Player *player = players.value(event->getPlayerId(), 0);
if (!player) {
qDebug() << "unhandled game event: invalid player id";
break;
}
player->processGameEvent(event, context);
emit userEvent();
}
player->processGameEvent(event, context);
emit userEvent();
}
}
}

View file

@ -153,7 +153,7 @@ public:
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
Player *getActiveLocalPlayer() const;
void processGameEventContainer(GameEventContainer *cont);
void processGameEventContainer(GameEventContainer *cont, AbstractClient *client);
public slots:
void sendGameCommand(GameCommand *command, int playerId);
void sendCommandContainer(CommandContainer *cont, int playerId);

View file

@ -181,7 +181,7 @@ void TabSupervisor::processGameEventContainer(GameEventContainer *cont)
TabGame *tab = gameTabs.value(cont->getGameId());
if (tab) {
qDebug() << "gameEvent gameId =" << cont->getGameId();
tab->processGameEventContainer(cont);
tab->processGameEventContainer(cont, qobject_cast<AbstractClient *>(sender()));
} else
qDebug() << "gameEvent: invalid gameId";
}

View file

@ -111,9 +111,7 @@ void TableZone::reorganizeCards()
QPointF mapPoint = mapFromGrid(gridPoint);
qreal x = mapPoint.x();
qreal y = mapPoint.y();
if (player->getMirrored())
y = height - CARD_HEIGHT - y;
qDebug() << "gridPos=" << gridPoint << "mapPoint=" << mapPoint;
int numberAttachedCards = cards[i]->getAttachedCards().size();
qreal actualX = x + numberAttachedCards * CARD_WIDTH / 3.0;
@ -207,7 +205,6 @@ CardItem *TableZone::getCardFromCoords(const QPointF &point) const
return getCardFromGrid(gridPoint);
}
QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const
{
if ((gridPoint.y() == 3) && (settingsCache->getEconomicGrid()))
@ -219,18 +216,24 @@ QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const
qreal x = marginX + 0.5 * CARD_WIDTH * gridPoint.x();
for (int i = 0; i < gridPoint.x(); ++i)
x += gridPointWidth.value(gridPoint.y() * 1000 + i, CARD_WIDTH);
return QPointF(
x,
boxLineWidth + (CARD_HEIGHT + paddingY) * gridPoint.y()
);
qreal y = boxLineWidth + (CARD_HEIGHT + paddingY) * gridPoint.y();
if (player->getMirrored())
y = height - CARD_HEIGHT - y;
return QPointF(x, y);
}
}
QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
{
qreal x = mapPoint.x() - marginX;
qreal y = mapPoint.y() + paddingY / 2 - boxLineWidth;
qreal y = mapPoint.y();
if (player->getMirrored())
y = height - y;
y += paddingY / 2 - boxLineWidth;
if (x < 0)
x = 0;
else if (x > width - CARD_WIDTH - marginX)