Selaa lähdekoodia

Dialog windows when upgrading/dismissing creature.

Michał W. Urbańczyk 17 vuotta sitten
vanhempi
sitoutus
8a6cfa2590
3 muutettua tiedostoa jossa 38 lisäystä ja 19 poistoa
  1. 1 1
      CBattleInterface.cpp
  2. 33 15
      CPlayerInterface.cpp
  3. 4 3
      CPlayerInterface.h

+ 1 - 1
CBattleInterface.cpp

@@ -1237,7 +1237,7 @@ void CBattleHex::clickRight(boost::logic::tribool down)
 				pom->morale = h->getCurrentMorale();
 				pom->currentHealth = myst.firstHPleft;
 			}
-			(new CCreInfoWindow(myst.creature->idNumber,0,pom,boost::function<void()>(),boost::function<void()>()))
+			(new CCreInfoWindow(myst.creature->idNumber,0,pom,boost::function<void()>(),boost::function<void()>(),NULL))
 					->activate();
 		}
 		delete pom;

+ 33 - 15
CPlayerInterface.cpp

@@ -137,7 +137,7 @@ void CGarrisonSlot::clickRight (tribool down)
 			pom->luck = h->getCurrentLuck();
 			pom->morale = h->getCurrentMorale();
 		}
-		(new CCreInfoWindow(creature->idNumber,0,pom,boost::function<void()>(),boost::function<void()>()))
+		(new CCreInfoWindow(creature->idNumber,0,pom,boost::function<void()>(),boost::function<void()>(),NULL))
 				->activate();
 	}
 	delete pom;
@@ -162,13 +162,13 @@ void CGarrisonSlot::clickLeft(tribool down)
 					(new CCreInfoWindow
 						(creature->idNumber,1,NULL,
 						boost::bind(&CCallback::upgradeCreature,LOCPLINT->cb,getObj(),ID,pom.newID[0]), //if upgrade is possible we'll bind proper function in callback
-						 boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID)))
+						 boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID),&pom))
 							->activate();
 				}
 				else
 				{
 					(new CCreInfoWindow
-						(creature->idNumber,1,NULL,0, boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID)) )
+						(creature->idNumber,1,NULL,0, boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID),NULL) )
 						->activate();
 				}
 				owner->highlighted = NULL;
@@ -2108,13 +2108,18 @@ void CPlayerInterface::showInfoDialog(std::string &text, std::vector<SComponent*
 	temp->activate();
 	LOCPLINT->objsToBlit.push_back(temp);
 }
-void CPlayerInterface::showYesNoDialog(std::string &text, std::vector<SComponent*> & components, CFunctionList<void()> funcs[2])
+void CPlayerInterface::showYesNoDialog(std::string &text, std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur)
 {
-	curint->deactivate(); //dezaktywacja starego interfejsu
+	if(deactivateCur)
+		curint->deactivate(); //dezaktywacja starego interfejsu
 	std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
-	pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",funcs[0]));
-	pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",funcs[1]));
+	pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",onYes));
+	pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",onNo));
 	CInfoWindow * temp = new CInfoWindow(text,playerID,32,components,pom);
+	if(onYes)
+		temp->buttons[0]->callback += boost::bind(&CInfoWindow::close,temp);
+	if(onNo)
+		temp->buttons[1]->callback += boost::bind(&CInfoWindow::close,temp);
 	temp->activate();
 	LOCPLINT->objsToBlit.push_back(temp);
 }
@@ -2961,8 +2966,8 @@ void CCreInfoWindow::show(SDL_Surface * to)
 {
 	char pom[15];
 	blitAt(bitmap,pos.x,pos.y,screen);
-	anim->blitPic(screen,pos.x+21,pos.y+48,(type) && anf);
-	anf=!anf;
+	anim->blitPic(screen,pos.x+21,pos.y+48,(type) && anf%4);
+	anf++;
 	if(upgrade)
 		upgrade->show();
 	if(dismiss)
@@ -2971,8 +2976,7 @@ void CCreInfoWindow::show(SDL_Surface * to)
 		ok->show();
 }
 
-CCreInfoWindow::CCreInfoWindow
-		(int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm)
+CCreInfoWindow::CCreInfoWindow(int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui)
 :ok(0),dismiss(0),upgrade(0),type(Type),dsm(Dsm),dependant(0)
 {
 	c = &CGI->creh->creatures[Cid];
@@ -3057,13 +3061,27 @@ CCreInfoWindow::CCreInfoWindow
 	//print abilities text - if r-click popup
 	if(type)
 	{
-		if(Upg)
+		if(Upg && ui)
 		{
-			upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,Upg,pos.x+76,pos.y+237,"IVIEWCR.DEF");
-			upgrade->callback += boost::bind(&CCreInfoWindow::close,this);
+			CFunctionList<void()> fs[2];
+			fs[0] += Upg;
+			fs[0] += boost::bind(&CCreInfoWindow::close,this);
+			std::vector<SComponent*> upgResCost;
+			for(std::set<std::pair<int,int> >::iterator i=ui->cost[0].begin(); i!=ui->cost[0].end(); i++)
+			{
+				upgResCost.push_back(new SComponent(SComponent::resource,i->first,i->second)); //will be deleted by CInfoWindow::close
+			}
+			boost::function<void()> fff = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[207],upgResCost,fs[0],fs[1],false);
+			upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,fff,pos.x+76,pos.y+237,"IVIEWCR.DEF");
 		}
 		if(Dsm)
-			dismiss = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::dismissF,this),pos.x+21,pos.y+237,"IVIEWCR2.DEF");
+		{
+			CFunctionList<void()> fs[2];
+			fs[0] += Dsm;
+			fs[0] += boost::bind(&CCreInfoWindow::close,this);
+			boost::function<void()> fff = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],std::vector<SComponent*>(),fs[0],fs[1],false);
+			dismiss = new AdventureMapButton("",CGI->preth->zelp[445].second,fff,pos.x+21,pos.y+237,"IVIEWCR2.DEF");
+		}
 		ok = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::close,this),pos.x+216,pos.y+237,"IOKAY.DEF");
 	}
 	else

+ 4 - 3
CPlayerInterface.h

@@ -23,6 +23,7 @@ class CSelectableComponent;
 class CCreatureSet;
 class CGObjectInstance;
 class CSlider;
+struct UpgradeInfo;
 namespace boost
 {
 	class mutex;
@@ -366,7 +367,7 @@ public:
 	int3 repairScreenPos(int3 pos);
 	void removeObjToBlit(IShowable* obj);	
 	void showInfoDialog(std::string &text, std::vector<SComponent*> & components);
-	void showYesNoDialog(std::string &text, std::vector<SComponent*> & components, CFunctionList<void()> funcs[2]);
+	void showYesNoDialog(std::string &text, std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur);
 
 	CPlayerInterface(int Player, int serial);//c-tor
 	~CPlayerInterface();//d-tor
@@ -522,7 +523,7 @@ class CCreInfoWindow : public IShowable, public KeyInterested, public ClickableR
 public:
 	int type;//0 - rclick popup; 1 - normal window
 	SDL_Surface *bitmap;
-	bool anf;
+	char anf;
 
 	boost::function<void()> dsm;
 	CCreaturePic *anim;
@@ -530,7 +531,7 @@ public:
 	CInfoWindow *dependant; //it may be dialog asking whther upgrade/dismiss stack (if opened)
 
 	AdventureMapButton *dismiss, *upgrade, *ok;
-	CCreInfoWindow(int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm);
+	CCreInfoWindow(int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui);
 	~CCreInfoWindow();
 	void activate();
 	void close();