mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +02:00
classes for buttons group and functionlist with arg
This commit is contained in:
parent
c00d0e4aca
commit
16303ab1df
@ -201,6 +201,68 @@ CHighlightableButton::CHighlightableButton( const CFunctionList<void()> &onSelec
|
|||||||
init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,activ);
|
init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,activ);
|
||||||
callback2 = onDeselect;
|
callback2 = onDeselect;
|
||||||
}
|
}
|
||||||
|
void CHighlightableButtonsGroup::addButton(CHighlightableButton* bt)
|
||||||
|
{
|
||||||
|
bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID);
|
||||||
|
buttons.push_back(bt);
|
||||||
|
}
|
||||||
|
void CHighlightableButtonsGroup::addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect)
|
||||||
|
{
|
||||||
|
CHighlightableButton *bt = new CHighlightableButton(OnSelect,0,tooltip,HelpBox,false,defName,0,x,y,0);
|
||||||
|
bt->ID = uid;
|
||||||
|
bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID);
|
||||||
|
bt->onlyOn = true;
|
||||||
|
buttons.push_back(bt);
|
||||||
|
}
|
||||||
|
CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange)
|
||||||
|
{
|
||||||
|
onChange = OnChange;
|
||||||
|
}
|
||||||
|
CHighlightableButtonsGroup::~CHighlightableButtonsGroup()
|
||||||
|
{
|
||||||
|
for(int i=0;i<buttons.size();i++)
|
||||||
|
delete buttons[i];
|
||||||
|
}
|
||||||
|
void CHighlightableButtonsGroup::activate()
|
||||||
|
{
|
||||||
|
for(int i=0;i<buttons.size();i++)
|
||||||
|
buttons[i]->activate();
|
||||||
|
}
|
||||||
|
void CHighlightableButtonsGroup::deactivate()
|
||||||
|
{
|
||||||
|
for(int i=0;i<buttons.size();i++)
|
||||||
|
buttons[i]->deactivate();
|
||||||
|
}
|
||||||
|
void CHighlightableButtonsGroup::select(int id, bool mode)
|
||||||
|
{
|
||||||
|
CHighlightableButton *bt = NULL;
|
||||||
|
if(mode)
|
||||||
|
{
|
||||||
|
for(int i=0;i<buttons.size() && !bt;i++)
|
||||||
|
if (buttons[i]->ID == id)
|
||||||
|
bt = buttons[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bt = buttons[id];
|
||||||
|
}
|
||||||
|
bt->select(true);
|
||||||
|
selectionChanged(bt->ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHighlightableButtonsGroup::selectionChanged(int to)
|
||||||
|
{
|
||||||
|
for(int i=0;i<buttons.size();i++)
|
||||||
|
if(buttons[i]->ID!=to && buttons[i]->selected)
|
||||||
|
buttons[i]->select(false);
|
||||||
|
onChange(to);
|
||||||
|
}
|
||||||
|
void CHighlightableButtonsGroup::show(SDL_Surface * to )
|
||||||
|
{
|
||||||
|
for(int i=0;i<buttons.size();i++)
|
||||||
|
buttons[i]->show();
|
||||||
|
}
|
||||||
|
|
||||||
void CSlider::sliderClicked()
|
void CSlider::sliderClicked()
|
||||||
{
|
{
|
||||||
if(!moving)
|
if(!moving)
|
||||||
|
@ -40,8 +40,25 @@ public:
|
|||||||
void clickLeft (tribool down);
|
void clickLeft (tribool down);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CHighlightableButtonsGroup
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
|
||||||
|
std::vector<CHighlightableButton*> buttons;
|
||||||
|
|
||||||
|
//void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid);
|
||||||
|
void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor
|
||||||
|
void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect=0); //creates new button
|
||||||
|
CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange);
|
||||||
|
~CHighlightableButtonsGroup();
|
||||||
|
void activate();
|
||||||
|
void deactivate();
|
||||||
|
void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id
|
||||||
|
void selectionChanged(int to);
|
||||||
|
void show(SDL_Surface * to = NULL);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//template<typename T>
|
|
||||||
class CSlider : public IShowable, public MotionInterested, public ClickableL
|
class CSlider : public IShowable, public MotionInterested, public ClickableL
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -48,9 +48,12 @@ CHeroWindow::CHeroWindow(int playerColor):
|
|||||||
dismissButton = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[28], boost::bind(&CHeroWindow::dismissCurrent,this), 519, 437, "hsbtns2.def", false, NULL, false);
|
dismissButton = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[28], boost::bind(&CHeroWindow::dismissCurrent,this), 519, 437, "hsbtns2.def", false, NULL, false);
|
||||||
questlogButton = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CHeroWindow::questlog,this), 379, 437, "hsbtns4.def", false, NULL, false);
|
questlogButton = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CHeroWindow::questlog,this), 379, 437, "hsbtns4.def", false, NULL, false);
|
||||||
|
|
||||||
gar1button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[23]), CGI->generaltexth->heroscrn[29], false, "hsbtns6.def" , NULL,546, 491, false);
|
formations = new CHighlightableButtonsGroup(0);
|
||||||
gar3button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[24]), CGI->generaltexth->heroscrn[30], false, "hsbtns7.def", NULL, 546, 527, false);
|
formations->addButton(map_list_of(0,CGI->generaltexth->heroscrn[23]),CGI->generaltexth->heroscrn[29], "hsbtns6.def",546, 491, 0);
|
||||||
gar1button->onlyOn = gar3button->onlyOn = true;
|
formations->addButton(map_list_of(0,CGI->generaltexth->heroscrn[24]),CGI->generaltexth->heroscrn[30], "hsbtns7.def",546, 527, 1);
|
||||||
|
//gar1button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[23]), CGI->generaltexth->heroscrn[29], false, "hsbtns6.def" , NULL,546, 491, false);
|
||||||
|
//gar3button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[24]), CGI->generaltexth->heroscrn[30], false, "hsbtns7.def", NULL, 546, 527, false);
|
||||||
|
|
||||||
|
|
||||||
gar2button = new CHighlightableButton(0, 0, map_list_of(0,CGI->generaltexth->heroscrn[26])(3,CGI->generaltexth->heroscrn[25]), CGI->generaltexth->heroscrn[31], false, "hsbtns8.def", NULL, 604, 491, false);
|
gar2button = new CHighlightableButton(0, 0, map_list_of(0,CGI->generaltexth->heroscrn[26])(3,CGI->generaltexth->heroscrn[25]), CGI->generaltexth->heroscrn[31], false, "hsbtns8.def", NULL, 604, 491, false);
|
||||||
gar4button = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::function<void()>(), 604, 527, "hsbtns9.def", false, NULL, false);
|
gar4button = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::function<void()>(), 604, 527, "hsbtns9.def", false, NULL, false);
|
||||||
@ -120,9 +123,8 @@ CHeroWindow::~CHeroWindow()
|
|||||||
delete quitButton;
|
delete quitButton;
|
||||||
delete dismissButton;
|
delete dismissButton;
|
||||||
delete questlogButton;
|
delete questlogButton;
|
||||||
delete gar1button;
|
delete formations;
|
||||||
delete gar2button;
|
delete gar2button;
|
||||||
delete gar3button;
|
|
||||||
delete gar4button;
|
delete gar4button;
|
||||||
delete leftArtRoll;
|
delete leftArtRoll;
|
||||||
delete rightArtRoll;
|
delete rightArtRoll;
|
||||||
@ -171,9 +173,8 @@ void CHeroWindow::show(SDL_Surface *to)
|
|||||||
quitButton->show();
|
quitButton->show();
|
||||||
dismissButton->show();
|
dismissButton->show();
|
||||||
questlogButton->show();
|
questlogButton->show();
|
||||||
gar1button->show();
|
formations->show();
|
||||||
gar2button->show();
|
gar2button->show();
|
||||||
gar3button->show();
|
|
||||||
gar4button->show();
|
gar4button->show();
|
||||||
leftArtRoll->show();
|
leftArtRoll->show();
|
||||||
rightArtRoll->show();
|
rightArtRoll->show();
|
||||||
@ -312,16 +313,10 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
|
|||||||
gar2button->callback = vstd::assigno(hero->tacticFormationEnabled,true);
|
gar2button->callback = vstd::assigno(hero->tacticFormationEnabled,true);
|
||||||
gar2button->callback2 = vstd::assigno(hero->tacticFormationEnabled,false);
|
gar2button->callback2 = vstd::assigno(hero->tacticFormationEnabled,false);
|
||||||
}
|
}
|
||||||
gar1button->callback.clear();
|
|
||||||
gar1button->callback += boost::bind(&CHighlightableButton::select, gar3button, false);
|
formations->onChange = boost::bind(&CCallback::setFormation, LOCPLINT->cb, Hero, _1);
|
||||||
gar1button->callback += boost::bind(&CCallback::setFormation, LOCPLINT->cb, Hero, false);
|
formations->select(hero->army.formation,true);
|
||||||
gar3button->callback.clear();
|
|
||||||
gar3button->callback += boost::bind(&CHighlightableButton::select, gar1button, false);
|
|
||||||
gar3button->callback += boost::bind(&CCallback::setFormation, LOCPLINT->cb, Hero, true);
|
|
||||||
if(hero->army.formation)
|
|
||||||
gar3button->select(true);
|
|
||||||
else
|
|
||||||
gar1button->select(true);
|
|
||||||
redrawCurBack();
|
redrawCurBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,9 +352,8 @@ void CHeroWindow::activate()
|
|||||||
quitButton->activate();
|
quitButton->activate();
|
||||||
dismissButton->activate();
|
dismissButton->activate();
|
||||||
questlogButton->activate();
|
questlogButton->activate();
|
||||||
gar1button->activate();
|
|
||||||
gar2button->activate();
|
gar2button->activate();
|
||||||
gar3button->activate();
|
formations->activate();
|
||||||
gar4button->activate();
|
gar4button->activate();
|
||||||
leftArtRoll->activate();
|
leftArtRoll->activate();
|
||||||
rightArtRoll->activate();
|
rightArtRoll->activate();
|
||||||
@ -403,9 +397,8 @@ void CHeroWindow::deactivate()
|
|||||||
quitButton->deactivate();
|
quitButton->deactivate();
|
||||||
dismissButton->deactivate();
|
dismissButton->deactivate();
|
||||||
questlogButton->deactivate();
|
questlogButton->deactivate();
|
||||||
gar1button->deactivate();
|
|
||||||
gar2button->deactivate();
|
gar2button->deactivate();
|
||||||
gar3button->deactivate();
|
formations->deactivate();
|
||||||
gar4button->deactivate();
|
gar4button->deactivate();
|
||||||
leftArtRoll->deactivate();
|
leftArtRoll->deactivate();
|
||||||
rightArtRoll->deactivate();
|
rightArtRoll->deactivate();
|
||||||
@ -450,19 +443,6 @@ void CHeroWindow::dismissCurrent()
|
|||||||
void CHeroWindow::questlog()
|
void CHeroWindow::questlog()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHeroWindow::gar1()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CHeroWindow::gar3()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CHeroWindow::gar4()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CHeroWindow::leftArtRoller()
|
void CHeroWindow::leftArtRoller()
|
||||||
{
|
{
|
||||||
if(curHero->artifacts.size()>5) //if it is <=5, we have nothing to scroll
|
if(curHero->artifacts.size()>5) //if it is <=5, we have nothing to scroll
|
||||||
|
@ -106,7 +106,8 @@ class CHeroWindow: public IShowActivable, public virtual CIntObject
|
|||||||
public:
|
public:
|
||||||
AdventureMapButton * quitButton, * dismissButton, * questlogButton, //general
|
AdventureMapButton * quitButton, * dismissButton, * questlogButton, //general
|
||||||
* leftArtRoll, * rightArtRoll;
|
* leftArtRoll, * rightArtRoll;
|
||||||
CHighlightableButton *gar2button, *gar1button, *gar3button; //garrison / formation handling;
|
CHighlightableButton *gar2button; //garrison / formation handling;
|
||||||
|
CHighlightableButtonsGroup *formations;
|
||||||
int player;
|
int player;
|
||||||
CHeroWindow(int playerColor); //c-tor
|
CHeroWindow(int playerColor); //c-tor
|
||||||
~CHeroWindow(); //d-tor
|
~CHeroWindow(); //d-tor
|
||||||
@ -118,10 +119,6 @@ public:
|
|||||||
void quit(); //stops displaying hero window
|
void quit(); //stops displaying hero window
|
||||||
void dismissCurrent(); //dissmissed currently displayed hero (curHero)
|
void dismissCurrent(); //dissmissed currently displayed hero (curHero)
|
||||||
void questlog(); //show quest log in hero window
|
void questlog(); //show quest log in hero window
|
||||||
void gar1(); //garrison / formation handling
|
|
||||||
void gar2(); //garrison / formation handling
|
|
||||||
void gar3(); //garrison / formation handling
|
|
||||||
void gar4(); //garrison / formation handling
|
|
||||||
void leftArtRoller(); //scrolls artifacts in bag left
|
void leftArtRoller(); //scrolls artifacts in bag left
|
||||||
void rightArtRoller(); //scrolls artifacts in bag right
|
void rightArtRoller(); //scrolls artifacts in bag right
|
||||||
void switchHero(); //changes displayed hero
|
void switchHero(); //changes displayed hero
|
||||||
|
@ -27,11 +27,6 @@ public:
|
|||||||
funcs.push_back(first);
|
funcs.push_back(first);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
//CFunctionList<Signature> & operator=(const boost::function<Signature> &first)
|
|
||||||
//{
|
|
||||||
// funcs.push_back(first);
|
|
||||||
// return first;
|
|
||||||
//}
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
funcs.clear();
|
funcs.clear();
|
||||||
@ -54,3 +49,46 @@ public:
|
|||||||
funcs2[i](a);
|
funcs2[i](a);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Signature>
|
||||||
|
class CFunctionList2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::vector<boost::function<Signature> > funcs;
|
||||||
|
|
||||||
|
CFunctionList2(int){};
|
||||||
|
CFunctionList2(){};
|
||||||
|
template <typename Functor>
|
||||||
|
CFunctionList2(const Functor &f)
|
||||||
|
{
|
||||||
|
funcs.push_back(boost::function<Signature>(f));
|
||||||
|
}
|
||||||
|
CFunctionList2(const boost::function<Signature> &first)
|
||||||
|
{
|
||||||
|
funcs.push_back(first);
|
||||||
|
}
|
||||||
|
CFunctionList2(boost::function<Signature> &first)
|
||||||
|
{
|
||||||
|
funcs.push_back(first);
|
||||||
|
}
|
||||||
|
CFunctionList2 & operator+=(const boost::function<Signature> &first)
|
||||||
|
{
|
||||||
|
funcs.push_back(first);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
funcs.clear();
|
||||||
|
}
|
||||||
|
operator bool() const
|
||||||
|
{
|
||||||
|
return funcs.size();
|
||||||
|
}
|
||||||
|
template <typename Arg>
|
||||||
|
void operator()(const Arg & a) const
|
||||||
|
{
|
||||||
|
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
|
||||||
|
for(int i=0;i<funcs2.size(); i++)
|
||||||
|
funcs2[i](a);
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user