1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-21 00:19:29 +02:00

Large refactoring of button classes:

- renamed CAdventureMapButton to more expectable CButton
- merged CButtonBase into CButton
- created more generic class for clickable elements
- created more generic class for selectable elements
- renamed CHighlightableButton to CToggleButton
- renamed CHighlightableButtonsGrous to CToggleGroup
- minimized differences between API of all these classes
- removed all but one contructors in buttons, with same parameters across all classes
This commit is contained in:
Ivan Savenko
2014-08-03 14:16:19 +03:00
parent 731aedf3a1
commit 10fc1892a8
37 changed files with 937 additions and 929 deletions

View File

@ -370,35 +370,6 @@ void CResDataBar::showAll(SDL_Surface * to)
CAdvMapInt::CAdvMapInt():
minimap(Rect(ADVOPT.minimapX, ADVOPT.minimapY, ADVOPT.minimapW, ADVOPT.minimapH)),
statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
kingOverview(CGI->generaltexth->zelp[293].first,CGI->generaltexth->zelp[293].second,
boost::bind(&CAdvMapInt::fshowOverview,this),&ADVOPT.kingOverview, SDLK_k),
underground(CGI->generaltexth->zelp[294].first,CGI->generaltexth->zelp[294].second,
boost::bind(&CAdvMapInt::fswitchLevel,this),&ADVOPT.underground, SDLK_u),
questlog(CGI->generaltexth->zelp[295].first,CGI->generaltexth->zelp[295].second,
boost::bind(&CAdvMapInt::fshowQuestlog,this),&ADVOPT.questlog, SDLK_q),
sleepWake(CGI->generaltexth->zelp[296].first,CGI->generaltexth->zelp[296].second,
boost::bind(&CAdvMapInt::fsleepWake,this), &ADVOPT.sleepWake, SDLK_w),
moveHero(CGI->generaltexth->zelp[297].first,CGI->generaltexth->zelp[297].second,
boost::bind(&CAdvMapInt::fmoveHero,this), &ADVOPT.moveHero, SDLK_m),
spellbook(CGI->generaltexth->zelp[298].first,CGI->generaltexth->zelp[298].second,
boost::bind(&CAdvMapInt::fshowSpellbok,this), &ADVOPT.spellbook, SDLK_c),
advOptions(CGI->generaltexth->zelp[299].first,CGI->generaltexth->zelp[299].second,
boost::bind(&CAdvMapInt::fadventureOPtions,this), &ADVOPT.advOptions, SDLK_a),
sysOptions(CGI->generaltexth->zelp[300].first,CGI->generaltexth->zelp[300].second,
boost::bind(&CAdvMapInt::fsystemOptions,this), &ADVOPT.sysOptions, SDLK_o),
nextHero(CGI->generaltexth->zelp[301].first,CGI->generaltexth->zelp[301].second,
boost::bind(&CAdvMapInt::fnextHero,this), &ADVOPT.nextHero, SDLK_h),
endTurn(CGI->generaltexth->zelp[302].first,CGI->generaltexth->zelp[302].second,
boost::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e),
heroList(ADVOPT.hlistSize, Point(ADVOPT.hlistX, ADVOPT.hlistY), ADVOPT.hlistAU, ADVOPT.hlistAD),
townList(ADVOPT.tlistSize, Point(ADVOPT.tlistX, ADVOPT.tlistY), ADVOPT.tlistAU, ADVOPT.tlistAD),
@ -427,9 +398,28 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[g]));
}
auto makeButton = [&] (int textID, std::function<void()> callback, config::ButtonInfo info, int key) -> CButton *
{
auto button = new CButton(Point(info.x, info.y), info.defName, CGI->generaltexth->zelp[textID], callback, key, info.playerColoured);
for (auto image : info.additionalDefs)
button->addImage(image);
return button;
};
kingOverview = makeButton(293, boost::bind(&CAdvMapInt::fshowOverview,this), ADVOPT.kingOverview, SDLK_k);
underground = makeButton(294, boost::bind(&CAdvMapInt::fswitchLevel,this), ADVOPT.underground, SDLK_u);
questlog = makeButton(295, boost::bind(&CAdvMapInt::fshowQuestlog,this), ADVOPT.questlog, SDLK_q);
sleepWake = makeButton(296, boost::bind(&CAdvMapInt::fsleepWake,this), ADVOPT.sleepWake, SDLK_w);
moveHero = makeButton(297, boost::bind(&CAdvMapInt::fmoveHero,this), ADVOPT.moveHero, SDLK_m);
spellbook = makeButton(298, boost::bind(&CAdvMapInt::fshowSpellbok,this), ADVOPT.spellbook, SDLK_c);
advOptions = makeButton(299, boost::bind(&CAdvMapInt::fadventureOPtions,this), ADVOPT.advOptions, SDLK_a);
sysOptions = makeButton(300, boost::bind(&CAdvMapInt::fsystemOptions,this), ADVOPT.sysOptions, SDLK_o);
nextHero = makeButton(301, boost::bind(&CAdvMapInt::fnextHero,this), ADVOPT.nextHero, SDLK_h);
endTurn = makeButton(302, boost::bind(&CAdvMapInt::fendTurn,this), ADVOPT.endTurn, SDLK_e);
setPlayer(LOCPLINT->playerID);
underground.block(!CGI->mh->map->twoLevel);
underground->block(!CGI->mh->map->twoLevel);
addUsedEvents(MOVE);
}
@ -452,14 +442,14 @@ void CAdvMapInt::fswitchLevel()
if (position.z)
{
position.z--;
underground.setIndex(0,true);
underground.showAll(screenBuf);
underground->setIndex(0,true);
underground->showAll(screenBuf);
}
else
{
underground.setIndex(1,true);
underground->setIndex(1,true);
position.z++;
underground.showAll(screenBuf);
underground->showAll(screenBuf);
}
updateScreen = true;
minimap.setLevel(position.z);
@ -544,14 +534,13 @@ void CAdvMapInt::fendTurn()
void CAdvMapInt::updateSleepWake(const CGHeroInstance *h)
{
sleepWake.block(!h);
sleepWake->block(!h);
if (!h)
return;
bool state = isHeroSleeping(h);
sleepWake.setIndex(state ? 1 : 0, true);
sleepWake.assignedKeys.clear();
sleepWake.assignedKeys.insert(state ? SDLK_w : SDLK_z);
sleepWake.update();
sleepWake->setIndex(state ? 1 : 0, true);
sleepWake->assignedKeys.clear();
sleepWake->assignedKeys.insert(state ? SDLK_w : SDLK_z);
}
void CAdvMapInt::updateMoveHero(const CGHeroInstance *h, tribool hasPath)
@ -561,10 +550,10 @@ void CAdvMapInt::updateMoveHero(const CGHeroInstance *h, tribool hasPath)
hasPath = LOCPLINT->paths[h].nodes.size() ? true : false;
if (!h)
{
moveHero.block(true);
moveHero->block(true);
return;
}
moveHero.block(!hasPath || (h->movement == 0));
moveHero->block(!hasPath || (h->movement == 0));
}
int CAdvMapInt::getNextHeroIndex(int startIndex)
@ -594,12 +583,12 @@ void CAdvMapInt::updateNextHero(const CGHeroInstance *h)
int next = getNextHeroIndex(start);
if (next < 0)
{
nextHero.block(true);
nextHero->block(true);
return;
}
const CGHeroInstance *nextH = LOCPLINT->wanderingHeroes[next];
bool noActiveHeroes = (next == start) && ((nextH->movement == 0) || isHeroSleeping(nextH));
nextHero.block(noActiveHeroes);
nextHero->block(noActiveHeroes);
}
void CAdvMapInt::activate()
@ -612,16 +601,16 @@ void CAdvMapInt::activate()
GH.statusbar = &statusbar;
if(!duringAITurn)
{
kingOverview.activate();
underground.activate();
questlog.activate();
sleepWake.activate();
moveHero.activate();
spellbook.activate();
sysOptions.activate();
advOptions.activate();
nextHero.activate();
endTurn.activate();
kingOverview->activate();
underground->activate();
questlog->activate();
sleepWake->activate();
moveHero->activate();
spellbook->activate();
sysOptions->activate();
advOptions->activate();
nextHero->activate();
endTurn->activate();
minimap.activate();
heroList.activate();
@ -642,16 +631,16 @@ void CAdvMapInt::deactivate()
scrollingDir = 0;
CCS->curh->changeGraphic(ECursor::ADVENTURE,0);
kingOverview.deactivate();
underground.deactivate();
questlog.deactivate();
sleepWake.deactivate();
moveHero.deactivate();
spellbook.deactivate();
advOptions.deactivate();
sysOptions.deactivate();
nextHero.deactivate();
endTurn.deactivate();
kingOverview->deactivate();
underground->deactivate();
questlog->deactivate();
sleepWake->deactivate();
moveHero->deactivate();
spellbook->deactivate();
advOptions->deactivate();
sysOptions->deactivate();
nextHero->deactivate();
endTurn->deactivate();
minimap.deactivate();
heroList.deactivate();
townList.deactivate();
@ -668,16 +657,16 @@ void CAdvMapInt::showAll(SDL_Surface * to)
if(state != INGAME)
return;
kingOverview.showAll(to);
underground.showAll(to);
questlog.showAll(to);
sleepWake.showAll(to);
moveHero.showAll(to);
spellbook.showAll(to);
advOptions.showAll(to);
sysOptions.showAll(to);
nextHero.showAll(to);
endTurn.showAll(to);
kingOverview->showAll(to);
underground->showAll(to);
questlog->showAll(to);
sleepWake->showAll(to);
moveHero->showAll(to);
spellbook->showAll(to);
advOptions->showAll(to);
sysOptions->showAll(to);
nextHero->showAll(to);
endTurn->showAll(to);
minimap.showAll(to);
heroList.showAll(to);
@ -788,8 +777,8 @@ void CAdvMapInt::centerOn(int3 on)
position = on;
updateScreen=true;
underground.setIndex(on.z,true); //change underground switch button image
underground.redraw();
underground->setIndex(on.z,true); //change underground switch button image
underground->redraw();
if (switchedLevels)
minimap.setLevel(position.z);
}
@ -1103,16 +1092,16 @@ void CAdvMapInt::setPlayer(PlayerColor Player)
player = Player;
graphics->blueToPlayersAdv(bg,player);
kingOverview.setPlayerColor(player);
underground.setPlayerColor(player);
questlog.setPlayerColor(player);
sleepWake.setPlayerColor(player);
moveHero.setPlayerColor(player);
spellbook.setPlayerColor(player);
sysOptions.setPlayerColor(player);
advOptions.setPlayerColor(player);
nextHero.setPlayerColor(player);
endTurn.setPlayerColor(player);
kingOverview->setPlayerColor(player);
underground->setPlayerColor(player);
questlog->setPlayerColor(player);
sleepWake->setPlayerColor(player);
moveHero->setPlayerColor(player);
spellbook->setPlayerColor(player);
sysOptions->setPlayerColor(player);
advOptions->setPlayerColor(player);
nextHero->setPlayerColor(player);
endTurn->setPlayerColor(player);
graphics->blueToPlayersAdv(resdatabar.bg,player);
//heroList.updateHList();
@ -1536,19 +1525,20 @@ CAdventureOptions::CAdventureOptions():
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
exit = new CAdventureMapButton("","",boost::bind(&CAdventureOptions::close, this), 204, 313, "IOK6432.DEF",SDLK_RETURN);
exit = new CButton(Point(204, 313), "IOK6432.DEF", CButton::tooltip(), boost::bind(&CAdventureOptions::close, this), SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);
scenInfo = new CAdventureMapButton("","", boost::bind(&CAdventureOptions::close, this), 24, 198, "ADVINFO.DEF",SDLK_i);
scenInfo->callback += CAdventureOptions::showScenarioInfo;
//viewWorld = new CAdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN);
scenInfo = new CButton(Point(24, 198), "ADVINFO.DEF", CButton::tooltip(), [&]{ close(); }, SDLK_i);
scenInfo->addCallback(CAdventureOptions::showScenarioInfo);
puzzle = new CAdventureMapButton("","", boost::bind(&CAdventureOptions::close, this), 24, 81, "ADVPUZ.DEF");
puzzle->callback += boost::bind(&CPlayerInterface::showPuzzleMap, LOCPLINT);
//viewWorld = new CButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 204, 313, "IOK6432.DEF",SDLK_RETURN);
dig = new CAdventureMapButton("","", boost::bind(&CAdventureOptions::close, this), 24, 139, "ADVDIG.DEF");
puzzle = new CButton(Point(24, 81), "ADVPUZ.DEF", CButton::tooltip(), [&]{ close(); }, SDLK_p);
puzzle->addCallback(boost::bind(&CPlayerInterface::showPuzzleMap, LOCPLINT));
dig = new CButton(Point(24, 139), "ADVDIG.DEF", CButton::tooltip(), [&]{ close(); }, SDLK_d);
if(const CGHeroInstance *h = adventureInt->curHero())
dig->callback += boost::bind(&CPlayerInterface::tryDiggging, LOCPLINT, h);
dig->addCallback(boost::bind(&CPlayerInterface::tryDiggging, LOCPLINT, h));
else
dig->block(true);
}