[prev in list] [next in list] [prev in thread] [next in thread]
List: atlantik-devel
Subject: [atlantik-cvs] CVS: kdegames/atlantik/libatlantikui board.cpp,1.98,1.99 board.h,1.60,1.61 token.cpp,
From: kde () office ! kde ! org
Date: 2002-11-28 21:38:26
[Download RAW message or body]
Update of /home/kde/kdegames/atlantik/libatlantikui
In directory office:/tmp/cvs-serv27349/libatlantikui
Modified Files:
board.cpp board.h token.cpp token.h
Log Message:
cleanup in token geometry, animation works again
Index: board.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikui/board.cpp,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- board.cpp 2002/11/28 11:59:25 1.98
+++ board.cpp 2002/11/28 21:38:24 1.99
@@ -30,6 +30,7 @@
#include "auction_widget.h"
#include "estatedetails.h"
#include "estateview.h"
+#include "token.h"
#include "board.h"
#include "board.moc"
@@ -44,7 +45,8 @@
int sideLen = maxEstates/4;
- // Timer for token movement
+ // Animated token movement
+ m_movingToken = 0;
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotMoveToken()));
m_resumeTimer = false;
@@ -69,48 +71,6 @@
m_displayQueue.setAutoDelete(true);
displayDefault();
-
- QColor color;
- QString icon;
- bool canBeOwned;
-
- for (int i=0;i<maxEstates;i++)
- {
- color = QColor();
- icon = QString();
- canBeOwned = false;
-
- switch(i)
- {
- case 5: case 15: case 25: case 35:
- icon = QString("train.png");
- canBeOwned = true;
- break;
- case 12:
- icon = QString("energy.png");
- canBeOwned = true;
- break;
- case 28:
- icon = QString("water.png");
- canBeOwned = true;
- break;
- case 2: case 17: case 33:
- icon = QString("box.png");
- break;
- case 7: case 36:
- icon = QString("qmark-red.png");
- break;
- case 22:
- icon = QString("qmark-blue.png");
- break;
- case 0:
- icon = QString("arrow.png");
- break;
- case 38:
- icon = QString("ring.png");
- break;
- }
- }
}
void AtlantikBoard::setViewProperties(bool indicateUnowned, bool highliteUnowned, \
bool darkenMortgaged, bool quartzEffects, bool animateTokens) @@ -129,14 +89,8 @@
{
return width;
}
-
-QPtrList<EstateView> AtlantikBoard::estateViews()
-{
- return m_estateViews;
-}
-
-EstateView *AtlantikBoard::getEstateView(Estate *estate)
+EstateView *AtlantikBoard::findEstateView(Estate *estate)
{
EstateView *estateView;
for (QPtrListIterator<EstateView> i(m_estateViews); *i; ++i)
@@ -209,147 +163,180 @@
connect(auction, SIGNAL(completed()), this, SLOT(displayDefault()));
}
-void AtlantikBoard::addToken(Player *player, EstateView *estateView)
+void AtlantikBoard::addToken(Player *player)
{
- EstateView *evTmp = 0;
- if (!estateView)
- {
- for (QPtrListIterator<EstateView> it(m_estateViews); (evTmp = *it) ; ++it)
- if (evTmp->estate() == player->location())
- {
- estateView = evTmp;
- break;
- }
- }
-
- if (!estateView)
+ if (!player->location())
{
kdDebug() << "addToken - estateView null\n";
return;
}
- Token *token = new Token(player, estateView, this, "token");
+ Token *token = new Token(player, this, "token");
tokenMap[player] = token;
connect(player, SIGNAL(changed(Player *)), token, SLOT(playerChanged()));
+
+ jumpToken(token);
// Timer to reinit the gameboard _after_ event loop
QTimer::singleShot(100, this, SLOT(slotResizeAftermath()));
}
-void AtlantikBoard::playerChanged()
+void AtlantikBoard::playerChanged(Player *player)
{
- kdDebug() << "Board::playerChanged()" << endl;
- // TODO: implement decent AtlantikBoard::playerChanged to update tokens
-/*
- kdDebug() << "new geometry for token: " << m_player->location() << endl;
- this->show();
-// setGeometry(100, 100, 125, 125);
-
- EstateView *estateView = estateViewMap[estateId];
+ // Update token
Token *token = tokenMap[player];
-
- if (estateView && token)
+ if (token)
{
- // Only take action when location has changed
- if (token->location() != estateId)
+ if (player->hasTurn())
+ token->raise();
+
+ bool jump = false, move = false;
+
+ if (token->inJail() != player->inJail())
{
- if (directMove)
- token->setLocation(estateView, false);
- else if (m_animateTokens==false)
- token->setLocation(estateView);
+ token->setInJail(player->inJail());
+ jump = true;
+ }
+
+ else if (token->location() != player->location())
+ {
+ token->setLocation(player->location());
+ jump = true;
+ }
+
+ if (player->destination() && token->destination() != player->destination())
+ {
+ if (m_animateTokens)
+ {
+ token->setDestination(player->destination());
+ move = true;
+ }
else
- moveToken(token, estateId);
+ {
+ token->setLocation(player->destination());
+ jump = true;
+ }
}
+
+ if (jump)
+ jumpToken(token);
+ if (move)
+ moveToken(token);
}
-*/
+ else
+ addToken(player);
}
-void AtlantikBoard::moveToken(Token *token, int estateId)
+void AtlantikBoard::jumpToken(Token *token)
{
- if ( token==0 )
- return;
-
- kdDebug() << "moving piece from " << token->location() << " to " << estateId << \
endl; + kdDebug() << "jumpToken to " << token->location()->name() << endl;
- // Set token destination
- move_token = token;
- // TODO: port
- // move_token->setDestination(estateId);
+ QPoint tGeom = calculateTokenDestination(token);
+ token->setGeometry(tGeom.x(), tGeom.y(), token->width(), token->height());
+ emit tokenConfirmation(token->location());
+}
+
+void AtlantikBoard::moveToken(Token *token)
+{
+ kdDebug() << "moveToken to " << token->destination()->name() << endl;
+
+ m_movingToken = token;
// Start timer
m_timer->start(15);
}
+QPoint AtlantikBoard::calculateTokenDestination(Token *token, Estate *eDest)
+{
+ if (!eDest)
+ eDest = token->player()->location();
+ EstateView *evDest = findEstateView(eDest);
+
+ int x = 0, y = 0;
+ if (token->player()->inJail())
+ {
+ x = evDest->geometry().right() - token->width() - 2;
+ y = evDest->geometry().top();
+ }
+ else
+ {
+ x = evDest->geometry().center().x() - (token->width()/2);
+ y = evDest->geometry().center().y() - (token->height()/2);
+
+/*
+ // Re-center because of EstateView headers
+ switch(evDest->orientation())
+ {
+ case North:
+ y += evDest->height()/8; break;
+ case East:
+ x -= evDest->width()/8; break;
+ case South:
+ y -= evDest->height()/8; break;
+ case West:
+ x += evDest->width()/8; break;
+ }
+*/
+ }
+ return QPoint(x, y);
+}
+
void AtlantikBoard::slotMoveToken()
{
// Do we actually have a token to move?
- if (move_token==0)
+ if (!m_movingToken)
{
m_timer->stop();
return;
}
// Where are we?
- int xCurrent = move_token->geometry().x();
- int yCurrent = move_token->geometry().y();
+ int xCurrent = m_movingToken->geometry().x();
+ int yCurrent = m_movingToken->geometry().y();
// Where do we want to go today?
- int dest = 0; // move_token->location() + 1;
- if (dest==(m_gridLayout->numRows() - 1)*4)
- dest = 0;
- kdDebug() << "going from " << move_token->location() << " to " << dest << endl;
+ Estate *eDest = m_atlanticCore->estateAfter(m_movingToken->location());
+ QPoint tGeom = calculateTokenDestination(m_movingToken, eDest);
- // TODO: port
-/*
- if (EstateView *estateView = getEstateView(dest))
- {
- int xFinal = estateView->geometry().center().x() - (move_token->width()/2);
- int yFinal = estateView->geometry().center().y() - (move_token->height()/2);
- int xDest, yDest;
+ int xDest = tGeom.x();
+ int yDest = tGeom.y();
- if (xFinal - xCurrent > 1)
- xDest = xCurrent + 2;
- else if (xCurrent - xFinal > 1)
- xDest = xCurrent - 2;
- else
- xDest = xCurrent;
+ if (xDest - xCurrent > 1)
+ xDest = xCurrent + 2;
+ else if (xCurrent - xDest > 1)
+ xDest = xCurrent - 2;
+ else
+ xDest = xCurrent;
- if (yFinal - yCurrent > 1)
- yDest = yCurrent + 2;
- else if (yCurrent - yFinal > 1)
- yDest = yCurrent - 2;
- else
- yDest = yCurrent;
+ if (yDest - yCurrent > 1)
+ yDest = yCurrent + 2;
+ else if (yCurrent - yDest > 1)
+ yDest = yCurrent - 2;
+ else
+ yDest = yCurrent;
- kdDebug() << "TOKEN: we are @ " << xCurrent << "," << yCurrent << endl;
- kdDebug() << "TOKEN: final to " << xFinal << "," << yFinal << endl;
- kdDebug() << "TOKEN: going to " << xDest << "," << yDest << endl;
+ kdDebug() << "TOKEN: at " << xCurrent << "," << yCurrent << " and going to " << \
xDest << "," << yDest << endl;
- if (xCurrent == xDest && yCurrent == yDest)
- {
- // We have arrived at our destination!
- move_token->setLocation(estateView);
+ if (xCurrent != xDest || yCurrent != yDest)
+ {
+ m_movingToken->setGeometry(xDest, yDest, m_movingToken->width(), \
m_movingToken->height()); + return;
+ }
+
+ // We have arrived at our destination!
+ m_movingToken->setLocation(eDest);
+ m_movingToken->player()->setLocation(eDest);
+ emit tokenConfirmation(eDest);
- // We need to confirm passing Go and arriving at our final
- // destination to the server.
- if (move_token->destination() == move_token->location())
- {
- // We have arrived at our _final_ destination!
- // TODO: port
- // emit tokenConfirmation(move_token->location());
- m_timer->stop();
- move_token = 0;
- }
- // TODO: port
- // else if (move_token->location() == 0)
- // emit tokenConfirmation(move_token->location());
+ // We have arrived at our _final_ destination!
+ if (eDest == m_movingToken->destination())
+ {
+ m_movingToken->setDestination(0);
+ m_movingToken->player()->setDestination(0);
- return;
- }
-
- move_token->setGeometry(xDest, yDest, move_token->width(), move_token->height());
+ m_timer->stop();
+ m_movingToken = 0;
}
-*/
}
void AtlantikBoard::resizeEvent(QResizeEvent *e)
@@ -388,7 +375,7 @@
Token *token = 0;
for (QMap<Player *, Token *>::Iterator it=tokenMap.begin() ; it != tokenMap.end() \
&& (token = *it) ; ++it)
- token->updateGeometry();
+ jumpToken(token);
// Restart the timer that was stopped in resizeEvent
if (m_resumeTimer && m_timer!=0 && !m_timer->isActive())
Index: board.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikui/board.h,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- board.h 2002/11/27 21:08:56 1.60
+++ board.h 2002/11/28 21:38:24 1.61
@@ -22,12 +22,13 @@
#include <qlayout.h>
#include <qptrlist.h>
-#include "token.h"
+class QPoint;
class AtlanticCore;
class Auction;
class Estate;
class Player;
+class Token;
class EstateView;
@@ -43,9 +44,9 @@
int heightForWidth(int);
void addEstateView(Estate *estate, bool indicateUnowned = false, bool \
highliteUnowned = false, bool darkenMortgaged = false, bool quartzEffects = false); \
void addAuctionWidget(Auction *auction);
- void addToken(Player *player, EstateView *location = 0);
+ void addToken(Player *player);
void indicateUnownedChanged();
- QPtrList<EstateView> estateViews();
+ EstateView *findEstateView(Estate *estate);
QWidget *centerWidget();
public slots:
@@ -53,7 +54,7 @@
void slotResizeAftermath();
private slots:
- void playerChanged();
+ void playerChanged(Player *player);
void displayDefault();
void displayButton(QString command, QString caption, bool enabled);
void prependEstateDetails(Estate *);
@@ -68,8 +69,10 @@
void resizeEvent(QResizeEvent *);
private:
- EstateView *getEstateView(Estate *estate);
- void moveToken(Token *, int destination);
+ void jumpToken(Token *token);
+ void moveToken(Token *token);
+ QPoint calculateTokenDestination(Token *token, Estate *estate = 0);
+
void updateCenter();
AtlanticCore *m_atlanticCore;
@@ -77,7 +80,7 @@
QWidget *spacer, *m_lastServerDisplay;
QGridLayout *m_gridLayout;
- Token *move_token;
+ Token *m_movingToken;
QTimer *m_timer;
bool m_resumeTimer;
Index: token.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikui/token.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- token.cpp 2002/11/28 11:59:25 1.31
+++ token.cpp 2002/11/28 21:38:24 1.32
@@ -29,23 +29,19 @@
#include "player.h"
#include "token.moc"
-#include "estateview.h"
-Token::Token(Player *player, EstateView *location, AtlantikBoard *parent, const char \
*name) : QWidget(parent, name) +Token::Token(Player *player, AtlantikBoard *parent, \
const char *name) : QWidget(parent, name) {
setBackgroundMode(NoBackground); // avoid flickering
m_parentBoard = parent;
- connect(this, SIGNAL(tokenConfirmation(Estate *)), m_parentBoard, \
SIGNAL(tokenConfirmation(Estate *)));
m_player = player;
connect(m_player, SIGNAL(changed(Player *)), this, SLOT(playerChanged()));
-
- m_location = 0;
- setLocation(location, false);
+ m_inJail = m_player->inJail();
+ m_location = m_player->location();
m_destination = 0;
- m_inJail = false;
qpixmap = 0;
b_recreate = true;
@@ -58,98 +54,22 @@
return m_player;
}
-void Token::setLocation(EstateView *location, bool confirm)
+void Token::setLocation(Estate *location)
{
if (m_location != location)
- {
m_location = location;
- updateGeometry();
-
- if (confirm)
- emit tokenConfirmation(m_player->location());
- }
}
-void Token::setDestination(EstateView *estateView)
+void Token::setDestination(Estate *estateView)
{
if (m_destination != estateView)
- {
m_destination = estateView;
- updateGeometry();
- }
- emit tokenConfirmation(m_player->location());
}
void Token::playerChanged()
{
- if (m_player->hasTurn())
- raise();
-
- if (Estate *estate = m_player->location())
- {
- EstateView *estateView;
- QPtrList<EstateView> estateViews = m_parentBoard->estateViews();
- for (QPtrListIterator<EstateView> it(estateViews); *it; ++it)
- {
- if ((estateView = dynamic_cast<EstateView*>(*it)))
- {
- if (estateView->estate() == estate)
- {
- setLocation(estateView);
- if (m_player->inJail() != m_inJail)
- {
- m_inJail = m_player->inJail();
- updateGeometry();
- }
- break;
- }
- }
- }
- }
-
b_recreate = true;
update();
-}
-
-void Token::updateGeometry()
-{
- if (!m_location)
- {
- hide();
- return;
- }
-
- int x, y;
- if (m_inJail)
- {
- x = m_location->geometry().x() + m_location->width() - width() - 2;
- y = m_location->geometry().y() + 2;
- }
- else
- {
- x = m_location->geometry().center().x() - (width()/2);
- y = m_location->geometry().center().y() - (height()/2);
-
- if (m_location->estate()->color().isValid())
- {
- switch(m_location->orientation())
- {
- case North:
- y += m_location->height()/8; break;
- case East:
- x -= m_location->width()/8; break;
- case South:
- y -= m_location->height()/8; break;
- case West:
- x += m_location->width()/8; break;
- }
- }
- }
-
- kdDebug() << "Token::updateGeometry, x:" << x << " y:" << y << endl;
- setGeometry(x, y, width(), height());
- if (isHidden())
- show();
}
void Token::paintEvent(QPaintEvent *)
Index: token.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikui/token.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- token.h 2002/07/07 18:05:10 1.17
+++ token.h 2002/11/28 21:38:24 1.18
@@ -22,7 +22,6 @@
class Player;
class Estate;
-class EstateView;
class AtlantikBoard;
class Token : public QWidget
@@ -30,13 +29,14 @@
Q_OBJECT
public:
- Token (Player *player, EstateView *location, AtlantikBoard *parent, const char \
*name = 0); + Token (Player *player, AtlantikBoard *parent, const char *name = 0);
Player *player();
- void setLocation(EstateView *estateView, bool confirm = true);
- EstateView *location() { return m_location; }
- void setDestination(EstateView *estateView);
- EstateView *destination() { return m_destination; }
- void updateGeometry();
+ void setLocation(Estate *estate);
+ Estate *location() { return m_location; }
+ void setDestination(Estate *estate);
+ Estate *destination() { return m_destination; }
+ void setInJail (bool inJail) { m_inJail = inJail; }
+ bool inJail() { return m_inJail; }
private slots:
void playerChanged();
@@ -45,14 +45,12 @@
void paintEvent(QPaintEvent *);
void resizeEvent(QResizeEvent *);
-signals:
- void tokenConfirmation(Estate *);
-
private:
Player *m_player;
- EstateView *m_location, *m_destination;
+ Estate *m_location, *m_destination;
+ bool m_inJail;
AtlantikBoard *m_parentBoard;
- bool b_recreate, m_inJail;
+ bool b_recreate;
QPixmap *qpixmap;
};
_______________________________________________
atlantik-cvs mailing list
atlantik-cvs@mail.kde.org
http://mail.kde.org/mailman/listinfo/atlantik-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic