Update of /home/kde/kdegames/atlantik/libatlantikui In directory office:/tmp/cvs-serv32291/libatlantikui Modified Files: Tag: KDE_3_1_BRANCH board.cpp board.h token.cpp token.h Log Message: backport of token animation fixes Index: board.cpp =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantikui/board.cpp,v retrieving revision 1.96.6.3 retrieving revision 1.96.6.4 diff -u -d -r1.96.6.3 -r1.96.6.4 --- board.cpp 21 Jan 2003 02:36:42 -0000 1.96.6.3 +++ board.cpp 31 Jan 2003 06:24:39 -0000 1.96.6.4 @@ -28,9 +28,9 @@ #include #include "auction_widget.h" -#include "display_widget.h" #include "estatedetails.h" #include "estateview.h" +#include "token.h" #include "board.h" #include "board.moc" @@ -48,6 +48,7 @@ int sideLen = maxEstates/4; // Animated token movement + m_movingToken = 0; m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(slotMoveToken())); m_resumeTimer = false; @@ -71,9 +72,16 @@ // m_gridLayout->addWidget(spacer, sideLen, sideLen); // SE m_displayQueue.setAutoDelete(true); + m_estateViews.setAutoDelete(true); + m_tokens.setAutoDelete(true); + displayDefault(); } +AtlantikBoard::~AtlantikBoard() +{ +} + void AtlantikBoard::setViewProperties(bool indicateUnowned, bool highliteUnowned, bool darkenMortgaged, bool quartzEffects, bool animateTokens) { if (m_animateTokens != animateTokens) @@ -91,11 +99,6 @@ return width; } -QPtrList AtlantikBoard::estateViews() -{ - return m_estateViews; -} - EstateView *AtlantikBoard::findEstateView(Estate *estate) { EstateView *estateView; @@ -169,28 +172,29 @@ connect(auction, SIGNAL(completed()), this, SLOT(displayDefault())); } -void AtlantikBoard::addToken(Player *player, EstateView *estateView) +Token *AtlantikBoard::findToken(Player *player) { - EstateView *evTmp = 0; - if (!estateView) - { - for (QPtrListIterator it(m_estateViews); (evTmp = *it) ; ++it) - if (evTmp->estate() == player->location()) - { - estateView = evTmp; - break; - } - } + Token *token = 0; + for (QPtrListIterator it(m_tokens); (token = *it) ; ++it) + if (token->player() == player) + return token; + return 0; +} - if (!estateView) +void AtlantikBoard::addToken(Player *player) +{ + kdDebug() << "addToken" << endl; + if (!player->location()) { - kdDebug() << "addToken - estateView null\n"; + kdDebug() << "addToken - estateView null" << endl; return; } - Token *token = new Token(player, estateView, this, "token"); - tokenMap[player] = token; + Token *token = new Token(player, this, "token"); + m_tokens.append(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())); @@ -198,121 +202,178 @@ 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]; - Token *token = tokenMap[player]; - - if (estateView && token) + // Update token + Token *token = findToken(player); + 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 ) + if (!token || !token->location()) return; - - kdDebug() << "moving piece from " << token->location() << " to " << estateId << endl; - // Set token destination - move_token = token; - // TODO: port - // move_token->setDestination(estateId); + kdDebug() << "jumpToken to " << token->location()->name() << endl; + + QPoint tGeom = calculateTokenDestination(token); + token->setGeometry(tGeom.x(), tGeom.y(), token->width(), token->height()); + if (token->isHidden()) + token->show(); + + if (token == m_movingToken) + { + m_timer->stop(); + m_movingToken = 0; + } + + 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); + if (!evDest) + return QPoint(0, 0); + + 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) +void AtlantikBoard::resizeEvent(QResizeEvent *) { // Stop moving tokens, slotResizeAftermath will re-enable this if (m_timer!=0 && m_timer->isActive()) @@ -347,8 +408,8 @@ // adjusted estate geometries. Token *token = 0; - for (QMap::Iterator it=tokenMap.begin() ; it != tokenMap.end() && (token = *it) ; ++it) - token->updateGeometry(); + for (QPtrListIterator it(m_tokens); (token = *it) ; ++it) + 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.59.6.1 retrieving revision 1.59.6.2 diff -u -d -r1.59.6.1 -r1.59.6.2 --- board.h 21 Jan 2003 02:36:42 -0000 1.59.6.1 +++ board.h 31 Jan 2003 06:24:39 -0000 1.59.6.2 @@ -22,12 +22,13 @@ #include #include -#include "token.h" +class QPoint; class AtlanticCore; class Auction; class Estate; class Player; +class Token; class EstateView; @@ -39,13 +40,16 @@ enum DisplayMode { Play, Edit }; AtlantikBoard(AtlanticCore *atlanticCore, int maxEstates, DisplayMode mode, QWidget *parent, const char *name=0); + ~AtlantikBoard(); + void setViewProperties(bool indicateUnowned, bool highliteUnowned, bool darkenMortgaged, bool quartzEffects, bool animateTokens); 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 estateViews(); EstateView *findEstateView(Estate *estate); QWidget *centerWidget(); @@ -69,7 +73,11 @@ void resizeEvent(QResizeEvent *); private: - void moveToken(Token *, int destination); + Token *findToken(Player *player); + void jumpToken(Token *token); + void moveToken(Token *token); + QPoint calculateTokenDestination(Token *token, Estate *estate = 0); + void updateCenter(); AtlanticCore *m_atlanticCore; @@ -77,7 +85,7 @@ QWidget *spacer, *m_lastServerDisplay; QGridLayout *m_gridLayout; - Token *move_token; + Token *m_movingToken; QTimer *m_timer; bool m_resumeTimer; @@ -85,7 +93,7 @@ int m_maxEstates; QPtrList m_estateViews; - QMap tokenMap; + QPtrList m_tokens; QPtrList m_displayQueue; }; Index: token.cpp =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantikui/token.cpp,v retrieving revision 1.30.4.1 retrieving revision 1.30.4.2 diff -u -d -r1.30.4.1 -r1.30.4.2 --- token.cpp 27 Dec 2002 01:37:20 -0000 1.30.4.1 +++ token.cpp 31 Jan 2003 06:24:39 -0000 1.30.4.2 @@ -1,4 +1,4 @@ -// Copyright (c) 2002 Rob Kaper +// Copyright (c) 2002-2003 Rob Kaper // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -29,28 +30,24 @@ #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_inJail = false; - m_location = location; + m_inJail = m_player->inJail(); + m_location = m_player->location(); m_destination = 0; qpixmap = 0; b_recreate = true; setFixedSize(QSize(26, 26)); - - updateGeometry(); } Player *Token::player() @@ -58,98 +55,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 estateViews = m_parentBoard->estateViews(); - for (QPtrListIterator it(estateViews); *it; ++it) - { - if ((estateView = dynamic_cast(*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.17.6.1 diff -u -d -r1.17 -r1.17.6.1 --- token.h 7 Jul 2002 18:05:10 -0000 1.17 +++ token.h 31 Jan 2003 06:24:39 -0000 1.17.6.1 @@ -1,4 +1,4 @@ -// Copyright (c) 2002 Rob Kaper +// Copyright (c) 2002-2003 Rob Kaper // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -18,11 +18,11 @@ #define ATLANTIK_TOKEN_H #include -#include + +class QPixmap; class Player; class Estate; -class EstateView; class AtlantikBoard; class Token : public QWidget @@ -30,13 +30,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 +46,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