[atlantik-cvs] CVS: kdegames/atlantik/libatlantikui board.cpp,1.103,1.104 board.h,1.62,1.63

[email protected]
Newsgroups gmane.comp.kde.devel.atlantik
Message-ID <[email protected]>
Update of /home/kde/kdegames/atlantik/libatlantikui
In directory office:/tmp/cvs-serv27333/libatlantikui

Modified Files:
	board.cpp board.h 
Log Message:
small token fixes that benefit designer

Index: board.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikui/board.cpp,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- board.cpp	23 Dec 2002 04:03:55 -0000	1.103
+++ board.cpp	31 Jan 2003 05:44:17 -0000	1.104
@@ -72,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)
@@ -165,16 +172,26 @@
 	connect(auction, SIGNAL(completed()), this, SLOT(displayDefault()));
 }
 
+Token *AtlantikBoard::findToken(Player *player)
+{
+	Token *token = 0;
+	for (QPtrListIterator<Token> it(m_tokens); (token = *it) ; ++it)
+		if (token->player() == player)
+			return token;
+	return 0;
+}
+
 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, this, "token");
-	tokenMap[player] = token;
+	m_tokens.append(token);
 	connect(player, SIGNAL(changed(Player *)), token, SLOT(playerChanged()));
 	
 	jumpToken(token);
@@ -186,7 +203,7 @@
 void AtlantikBoard::playerChanged(Player *player)
 {
 	// Update token
-	Token *token = tokenMap[player];
+	Token *token = findToken(player);
 	if (token)
 	{
 		if (player->hasTurn())
@@ -231,10 +248,15 @@
 
 void AtlantikBoard::jumpToken(Token *token)
 {
+	if (!token || !token->location())
+		return;
+
 	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)
 	{
@@ -259,7 +281,10 @@
 {
 		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())
@@ -383,7 +408,7 @@
 	// adjusted estate geometries.
 
 	Token *token = 0;
-	for (QMap<Player *, Token *>::Iterator it=tokenMap.begin() ; it != tokenMap.end() && (token = *it) ; ++it)
+	for (QPtrListIterator<Token> it(m_tokens); (token = *it) ; ++it)
 		jumpToken(token);
 
 	// Restart the timer that was stopped in resizeEvent

Index: board.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikui/board.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- board.h	23 Dec 2002 04:03:55 -0000	1.62
+++ board.h	31 Jan 2003 05:44:17 -0000	1.63
@@ -40,11 +40,15 @@
 	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);
+
 	void indicateUnownedChanged();
 	EstateView *findEstateView(Estate *estate);
 	QWidget *centerWidget();
@@ -69,6 +73,7 @@
 	void resizeEvent(QResizeEvent *);
 
 private:
+	Token *findToken(Player *player);
 	void jumpToken(Token *token);
 	void moveToken(Token *token);
 	QPoint calculateTokenDestination(Token *token, Estate *estate = 0);
@@ -88,7 +93,7 @@
 	int m_maxEstates;
 
 	QPtrList<EstateView> m_estateViews;
-	QMap<Player *, Token *> tokenMap;
+	QPtrList<Token> m_tokens;
 	QPtrList<QWidget> m_displayQueue;
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.