#pragma once #include "SDL_Extensions.h" #include "hch\CDefHandler.h" #include "CGameInfo.h" #include "hch\CLodHandler.h" template AdventureMapButton::AdventureMapButton () { type=2; abs=true; active=false; ourObj=NULL; state=0; } template AdventureMapButton::AdventureMapButton ( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ, std::vector * add ) { owner = Owner; type=2; abs=true; active=false; ourObj=NULL; state=0; name=Name; helpBox=HelpBox; int est = LOCPLINT->playerID; CDefHandler * temp = CGI->spriteh->giveDef(defName); temp->notFreeImgs = true; for (int i=0;iourImages.size();i++) { imgs.resize(1); imgs[0].push_back(temp->ourImages[i].bitmap); CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID); } delete temp; if (add) { imgs.resize(imgs.size()+add->size()); for (int i=0; isize();i++) { temp = CGI->spriteh->giveDef((*add)[i]); temp->notFreeImgs = true; for (int j=0;jourImages.size();j++) { imgs[i+1].push_back(temp->ourImages[j].bitmap); CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID); } delete temp; } delete add; } function = Function; pos.x=x; pos.y=y; pos.w = imgs[curimg][0]->w; pos.h = imgs[curimg][0]->h -1; if (activ) activate(); } template void AdventureMapButton::clickLeft (tribool down) { if (down) { state=1; } else { state=0; } show(); if (pressedL && (down==false)) { pressedL=state; (owner->*function)(); } else { pressedL=state; } } template void AdventureMapButton::clickRight (tribool down) { LOCPLINT->adventureInt->handleRightClick(helpBox,down,this); } template void AdventureMapButton::hover (bool on) { Hoverable::hover(on); if (on) LOCPLINT->statusbar->print(name); else if (LOCPLINT->statusbar->getCurrent()==name) LOCPLINT->statusbar->clear(); } template void AdventureMapButton::activate() { if (active) return; active=true; ClickableL::activate(); ClickableR::activate(); Hoverable::activate(); KeyInterested::activate(); } template void AdventureMapButton::keyPressed (SDL_KeyboardEvent & key) { //TODO: check if it's shortcut } template void AdventureMapButton::deactivate() { if (!active) return; active=false; ClickableL::deactivate(); ClickableR::deactivate(); Hoverable::deactivate(); KeyInterested::deactivate(); }