[atlantik-cvs] CVS: kdegames/atlantik/client atlantik.cpp,1.121.6.19,1.121.6.20 atlantik.h,1.51.6.2,1.51.6.3

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

Modified Files:
      Tag: KDE_3_1_BRANCH
	atlantik.cpp atlantik.h 
Log Message:
better portfolio handling: show when we're in the same game, also when that's no game

Index: atlantik.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/atlantik.cpp,v
retrieving revision 1.121.6.19
retrieving revision 1.121.6.20
diff -u -d -r1.121.6.19 -r1.121.6.20
--- atlantik.cpp	12 Jul 2003 17:49:21 -0000	1.121.6.19
+++ atlantik.cpp	13 Jul 2003 04:43:40 -0000	1.121.6.20
@@ -169,9 +169,12 @@
 {
 	initBoard();
 	m_board->addToken(player);
-
 	addPortfolioView(player);
 
+	// Player::changed() is not connected until later this method, so
+	// we'd better force an update.
+	playerChanged(player);
+
 	if (player->isSelf())
 		m_playerSelf = player;
 
@@ -252,7 +255,7 @@
 //		delete m_board;
 //		m_board = 0;
 
-		m_portfolioViews.clear();
+		// m_portfolioViews.clear();
 		m_atlanticCore->reset();
 	}
 
@@ -509,13 +512,25 @@
 void Atlantik::playerChanged(Player *player)
 {
 	PortfolioView *portfolioView = findPortfolioView(player);
-	if (portfolioView && player->gameId() == -1)
-		m_portfolioViews.remove(portfolioView);
-	else if (!portfolioView && player->gameId() != -1)
-		addPortfolioView(player);
+	if (!portfolioView)
+		portfolioView = addPortfolioView(player);
 
 	if (player == m_playerSelf)
 	{
+		// We changed ourselves, see if other players (that we know
+		// about) have the same gameId..
+
+		PortfolioView *portfolioView = 0;
+		for (QPtrListIterator<PortfolioView> it(m_portfolioViews); *it; ++it)
+			if ((portfolioView = dynamic_cast<PortfolioView*>(*it)))
+			{
+				Player *pTmp = portfolioView->player();
+				if (pTmp->gameId() == m_playerSelf->gameId())
+					portfolioView->show();
+				else
+					portfolioView->hide();
+			}
+
 		if (m_selectConfiguration)
 			m_selectConfiguration->setCanStart(player->master());
 
@@ -529,6 +544,20 @@
 		m_jailPay->setEnabled(player->hasTurn() && player->inJail());
 		m_jailRoll->setEnabled(player->hasTurn() && player->inJail());
 	}
+	else
+	{
+		// Another player changed, check if we need to show or hide
+		// his/her portfolioView.
+		if (m_playerSelf)
+		{
+			if (player->gameId() == m_playerSelf->gameId())
+				portfolioView->show();
+			else
+				portfolioView->hide();
+		}
+		else if (player->gameId() == -1)
+			portfolioView->hide();
+	}
 }
 
 void Atlantik::initNetworkObject()
@@ -591,7 +620,7 @@
 	config->sync();
 }
 
-void Atlantik::addPortfolioView(Player *player)
+PortfolioView *Atlantik::addPortfolioView(Player *player)
 {
 	PortfolioView *portfolioView = new PortfolioView(m_atlanticCore, player, m_config.activeColor, m_config.inactiveColor, m_portfolioWidget);
 	m_portfolioViews.append(portfolioView);
@@ -602,6 +631,8 @@
 
 	m_portfolioLayout->addWidget(portfolioView);
 	portfolioView->show();
+
+	return portfolioView;
 }
 
 PortfolioView *Atlantik::findPortfolioView(Player *player)

Index: atlantik.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/atlantik.h,v
retrieving revision 1.51.6.2
retrieving revision 1.51.6.3
diff -u -d -r1.51.6.2 -r1.51.6.3
--- atlantik.h	18 Jun 2003 00:58:49 -0000	1.51.6.2
+++ atlantik.h	13 Jul 2003 04:43:42 -0000	1.51.6.3
@@ -184,7 +184,7 @@
 
 private:
 	void initNetworkObject();
-	void addPortfolioView(Player *player);
+	PortfolioView *addPortfolioView(Player *player);
 	PortfolioView *findPortfolioView(Player *player);
 
 	QWidget *m_mainWidget, *m_portfolioWidget;
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.