1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-09 13:14:02 +02:00

Dialog windows when upgrading/dismissing creature.

This commit is contained in:
Michał W. Urbańczyk 2008-08-15 14:08:39 +00:00
parent b83b80a71e
commit 8a6cfa2590
3 changed files with 38 additions and 19 deletions

View File

@ -1237,7 +1237,7 @@ void CBattleHex::clickRight(boost::logic::tribool down)
pom->morale = h->getCurrentMorale(); pom->morale = h->getCurrentMorale();
pom->currentHealth = myst.firstHPleft; 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(); ->activate();
} }
delete pom; delete pom;

View File

@ -137,7 +137,7 @@ void CGarrisonSlot::clickRight (tribool down)
pom->luck = h->getCurrentLuck(); pom->luck = h->getCurrentLuck();
pom->morale = h->getCurrentMorale(); 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(); ->activate();
} }
delete pom; delete pom;
@ -162,13 +162,13 @@ void CGarrisonSlot::clickLeft(tribool down)
(new CCreInfoWindow (new CCreInfoWindow
(creature->idNumber,1,NULL, (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::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(); ->activate();
} }
else else
{ {
(new CCreInfoWindow (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(); ->activate();
} }
owner->highlighted = NULL; owner->highlighted = NULL;
@ -2108,13 +2108,18 @@ void CPlayerInterface::showInfoDialog(std::string &text, std::vector<SComponent*
temp->activate(); temp->activate();
LOCPLINT->objsToBlit.push_back(temp); 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; 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()> >("IOKAY.DEF",onYes));
pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",funcs[1])); pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",onNo));
CInfoWindow * temp = new CInfoWindow(text,playerID,32,components,pom); 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(); temp->activate();
LOCPLINT->objsToBlit.push_back(temp); LOCPLINT->objsToBlit.push_back(temp);
} }
@ -2961,8 +2966,8 @@ void CCreInfoWindow::show(SDL_Surface * to)
{ {
char pom[15]; char pom[15];
blitAt(bitmap,pos.x,pos.y,screen); blitAt(bitmap,pos.x,pos.y,screen);
anim->blitPic(screen,pos.x+21,pos.y+48,(type) && anf); anim->blitPic(screen,pos.x+21,pos.y+48,(type) && anf%4);
anf=!anf; anf++;
if(upgrade) if(upgrade)
upgrade->show(); upgrade->show();
if(dismiss) if(dismiss)
@ -2971,8 +2976,7 @@ void CCreInfoWindow::show(SDL_Surface * to)
ok->show(); ok->show();
} }
CCreInfoWindow::CCreInfoWindow CCreInfoWindow::CCreInfoWindow(int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui)
(int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm)
:ok(0),dismiss(0),upgrade(0),type(Type),dsm(Dsm),dependant(0) :ok(0),dismiss(0),upgrade(0),type(Type),dsm(Dsm),dependant(0)
{ {
c = &CGI->creh->creatures[Cid]; c = &CGI->creh->creatures[Cid];
@ -3057,13 +3061,27 @@ CCreInfoWindow::CCreInfoWindow
//print abilities text - if r-click popup //print abilities text - if r-click popup
if(type) if(type)
{ {
if(Upg) if(Upg && ui)
{ {
upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,Upg,pos.x+76,pos.y+237,"IVIEWCR.DEF"); CFunctionList<void()> fs[2];
upgrade->callback += boost::bind(&CCreInfoWindow::close,this); 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) 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"); ok = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::close,this),pos.x+216,pos.y+237,"IOKAY.DEF");
} }
else else

View File

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