2009-05-19 21:23:04 +03:00
|
|
|
#include "AdventureMapButton.h"
|
2008-05-18 20:33:39 +03:00
|
|
|
#include "CAdvmapInterface.h"
|
|
|
|
#include "SDL_Extensions.h"
|
2008-07-01 11:01:02 +03:00
|
|
|
#include "hch/CDefHandler.h"
|
2008-05-18 20:33:39 +03:00
|
|
|
#include "CGameInfo.h"
|
2008-07-01 11:01:02 +03:00
|
|
|
#include "hch/CLodHandler.h"
|
2008-11-28 03:36:34 +02:00
|
|
|
#include "hch/CGeneralTextHandler.h"
|
2008-05-18 20:33:39 +03:00
|
|
|
#include "hch/CTownHandler.h"
|
|
|
|
#include "CCallback.h"
|
2008-11-12 20:26:23 +02:00
|
|
|
#include "client/CConfigHandler.h"
|
2008-06-30 03:06:41 +03:00
|
|
|
#include "client/Graphics.h"
|
2009-01-29 20:07:31 +02:00
|
|
|
#include "CBattleInterface.h"
|
2009-05-20 12:02:50 +03:00
|
|
|
#include "CPlayerInterface.h"
|
2009-04-15 17:03:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AdevntureMapButton.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-05-18 20:33:39 +03:00
|
|
|
AdventureMapButton::AdventureMapButton ()
|
|
|
|
{
|
|
|
|
type=2;
|
|
|
|
abs=true;
|
|
|
|
active=false;
|
|
|
|
ourObj=NULL;
|
|
|
|
state=0;
|
2008-08-27 13:19:18 +03:00
|
|
|
blocked = actOnDown = false;
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
2008-08-25 13:25:16 +03:00
|
|
|
//AdventureMapButton::AdventureMapButton( std::string Name, std::string HelpBox, boost::function<void()> Callback, int x, int y, std::string defName, bool activ, std::vector<std::string> * add, bool playerColoredButton)
|
|
|
|
//{
|
|
|
|
// init(Callback, Name, HelpBox, playerColoredButton, defName, add, x, y, activ);
|
|
|
|
//}
|
2008-10-19 16:17:32 +03:00
|
|
|
AdventureMapButton::AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName,int key, std::vector<std::string> * add, bool playerColoredButton )
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
2008-08-28 20:36:34 +03:00
|
|
|
std::map<int,std::string> pom;
|
|
|
|
pom[0] = Name;
|
2008-10-19 16:17:32 +03:00
|
|
|
init(Callback, pom, HelpBox, playerColoredButton, defName, add, x, y, key);
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
|
|
|
|
2008-10-19 16:17:32 +03:00
|
|
|
AdventureMapButton::AdventureMapButton( const std::map<int,std::string> &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key, std::vector<std::string> * add /*= NULL*/, bool playerColoredButton /*= false */ )
|
2008-08-28 20:36:34 +03:00
|
|
|
{
|
2008-10-19 16:17:32 +03:00
|
|
|
init(Callback, Name, HelpBox, playerColoredButton, defName, add, x, y, key);
|
2008-08-28 20:36:34 +03:00
|
|
|
}
|
2008-05-18 20:33:39 +03:00
|
|
|
|
2008-11-12 20:26:23 +02:00
|
|
|
AdventureMapButton::AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, config::ButtonInfo *info, int key/*=0*/ )
|
|
|
|
{
|
|
|
|
std::map<int,std::string> pom;
|
|
|
|
pom[0] = Name;
|
|
|
|
init(Callback, pom, HelpBox, info->playerColoured, info->defName, &info->additionalDefs, info->x, info->y, key);
|
|
|
|
}
|
2009-02-06 13:15:39 +02:00
|
|
|
|
|
|
|
AdventureMapButton::AdventureMapButton( const std::pair<std::string, std::string> help, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key/*=0*/, std::vector<std::string> * add /*= NULL*/, bool playerColoredButton /*= false */ )
|
|
|
|
{
|
|
|
|
std::map<int,std::string> pom;
|
|
|
|
pom[0] = help.first;
|
|
|
|
init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key);
|
|
|
|
}
|
2009-05-20 12:02:50 +03:00
|
|
|
void AdventureMapButton::clickLeft (boost::logic::tribool down)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2008-08-27 13:19:18 +03:00
|
|
|
if(blocked)
|
|
|
|
return;
|
2008-05-18 20:33:39 +03:00
|
|
|
if (down)
|
|
|
|
state=1;
|
2008-08-02 18:08:03 +03:00
|
|
|
else
|
2008-05-18 20:33:39 +03:00
|
|
|
state=0;
|
2009-04-14 15:47:09 +03:00
|
|
|
show(screen2);
|
2008-05-18 20:33:39 +03:00
|
|
|
if (actOnDown && down)
|
|
|
|
{
|
|
|
|
pressedL=state;
|
2008-08-15 15:11:42 +03:00
|
|
|
//if(!callback.empty())
|
2008-05-23 22:50:11 +03:00
|
|
|
callback();
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
2009-02-04 05:55:12 +02:00
|
|
|
else if (!actOnDown && pressedL && (down==false))
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
|
|
|
pressedL=state;
|
2008-08-15 15:11:42 +03:00
|
|
|
//if(!callback.empty())
|
2008-05-23 22:50:11 +03:00
|
|
|
callback();
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pressedL=state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-20 12:02:50 +03:00
|
|
|
void AdventureMapButton::clickRight (boost::logic::tribool down)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
|
|
|
if(helpBox.size()) //there is no point to show window with nothing inside...
|
|
|
|
LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapButton::hover (bool on)
|
|
|
|
{
|
|
|
|
Hoverable::hover(on);
|
2008-08-28 20:36:34 +03:00
|
|
|
std::string *name = (vstd::contains(hoverTexts,state))
|
|
|
|
? (&hoverTexts[state])
|
|
|
|
: (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL);
|
2009-02-09 18:18:48 +02:00
|
|
|
if(name && blocked!=1) //if there is no name, there is nohing to display also
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2009-04-14 15:47:09 +03:00
|
|
|
if (LOCPLINT->battleInt) //for battle buttons
|
2009-01-29 20:07:31 +02:00
|
|
|
{
|
|
|
|
if(on && LOCPLINT->battleInt->console->alterTxt == "")
|
|
|
|
{
|
|
|
|
LOCPLINT->battleInt->console->alterTxt = *name;
|
|
|
|
LOCPLINT->battleInt->console->whoSetAlter = 1;
|
|
|
|
}
|
|
|
|
else if (LOCPLINT->battleInt->console->alterTxt == *name)
|
|
|
|
{
|
|
|
|
LOCPLINT->battleInt->console->alterTxt = "";
|
|
|
|
LOCPLINT->battleInt->console->whoSetAlter = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //for other buttons
|
|
|
|
{
|
|
|
|
if (on)
|
|
|
|
LOCPLINT->statusbar->print(*name);
|
|
|
|
else if ( LOCPLINT->statusbar->getCurrent()==(*name) )
|
|
|
|
LOCPLINT->statusbar->clear();
|
|
|
|
}
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapButton::activate()
|
|
|
|
{
|
|
|
|
if (active) return;
|
|
|
|
active=true;
|
|
|
|
ClickableL::activate();
|
|
|
|
ClickableR::activate();
|
|
|
|
Hoverable::activate();
|
|
|
|
KeyInterested::activate();
|
|
|
|
}
|
|
|
|
void AdventureMapButton::deactivate()
|
|
|
|
{
|
|
|
|
if (!active) return;
|
|
|
|
active=false;
|
|
|
|
ClickableL::deactivate();
|
|
|
|
ClickableR::deactivate();
|
|
|
|
Hoverable::deactivate();
|
|
|
|
KeyInterested::deactivate();
|
|
|
|
}
|
|
|
|
|
2008-10-19 16:17:32 +03:00
|
|
|
void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
callback = Callback;
|
2008-08-27 13:19:18 +03:00
|
|
|
blocked = actOnDown = false;
|
2008-08-15 15:11:42 +03:00
|
|
|
type=2;
|
|
|
|
abs=true;
|
|
|
|
active=false;
|
|
|
|
ourObj=NULL;
|
2008-11-02 00:32:56 +02:00
|
|
|
assignedKeys.insert(key);
|
2008-08-15 15:11:42 +03:00
|
|
|
state=0;
|
2008-08-28 20:36:34 +03:00
|
|
|
hoverTexts = Name;
|
2008-08-15 15:11:42 +03:00
|
|
|
helpBox=HelpBox;
|
2008-12-21 21:17:35 +02:00
|
|
|
//int est = LOCPLINT->playerID; //TODO use me
|
2008-08-15 15:11:42 +03:00
|
|
|
CDefHandler * temp = CDefHandler::giveDef(defName);
|
|
|
|
temp->notFreeImgs = true;
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0;i<temp->ourImages.size();i++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
imgs.resize(1);
|
|
|
|
imgs[0].push_back(temp->ourImages[i].bitmap);
|
2009-01-29 20:07:31 +02:00
|
|
|
if(playerColoredButton)
|
|
|
|
{
|
2008-08-15 15:11:42 +03:00
|
|
|
graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
|
2009-01-29 20:07:31 +02:00
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
delete temp;
|
2008-11-12 20:26:23 +02:00
|
|
|
if (add && add->size())
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
imgs.resize(imgs.size()+add->size());
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i<add->size();i++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
temp = CDefHandler::giveDef((*add)[i]);
|
|
|
|
temp->notFreeImgs = true;
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<temp->ourImages.size();j++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
imgs[i+1].push_back(temp->ourImages[j].bitmap);
|
2009-01-29 20:07:31 +02:00
|
|
|
if(playerColoredButton)
|
|
|
|
{
|
2008-08-15 15:11:42 +03:00
|
|
|
graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
|
2009-01-29 20:07:31 +02:00
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
delete temp;
|
|
|
|
}
|
2008-11-12 20:26:23 +02:00
|
|
|
//delete add;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
pos.x=x;
|
|
|
|
pos.y=y;
|
|
|
|
pos.w = imgs[curimg][0]->w;
|
|
|
|
pos.h = imgs[curimg][0]->h -1;
|
|
|
|
}
|
2008-05-18 20:33:39 +03:00
|
|
|
|
2009-02-09 18:18:48 +02:00
|
|
|
void AdventureMapButton::block( ui8 on )
|
2008-08-27 13:19:18 +03:00
|
|
|
{
|
|
|
|
blocked = on;
|
|
|
|
state = 0;
|
|
|
|
bitmapOffset = on ? 2 : 0;
|
2009-04-14 15:47:09 +03:00
|
|
|
show(screen2);
|
2008-08-27 13:19:18 +03:00
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
|
2008-09-18 16:54:54 +03:00
|
|
|
void CHighlightableButton::select(bool on)
|
|
|
|
{
|
|
|
|
selected = on;
|
|
|
|
state = selected ? 3 : 0;
|
|
|
|
if(selected)
|
|
|
|
callback();
|
|
|
|
else
|
|
|
|
callback2();
|
|
|
|
if(hoverTexts.size()>1)
|
|
|
|
{
|
|
|
|
hover(false);
|
|
|
|
hover(true);
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 13:19:18 +03:00
|
|
|
|
2008-08-28 20:36:34 +03:00
|
|
|
void CHighlightableButton::clickLeft( tribool down )
|
|
|
|
{
|
|
|
|
if(blocked)
|
|
|
|
return;
|
|
|
|
if (down)
|
|
|
|
state=1;
|
|
|
|
else
|
|
|
|
state = selected ? 3 : 0;
|
2009-04-14 15:47:09 +03:00
|
|
|
show(screen2);
|
2008-08-28 20:36:34 +03:00
|
|
|
if (pressedL && (down==false))
|
|
|
|
{
|
|
|
|
pressedL=state;
|
2008-09-19 11:16:19 +03:00
|
|
|
if(!onlyOn || !selected)
|
|
|
|
select(!selected);
|
2008-08-28 20:36:34 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pressedL=state;
|
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
}
|
2008-08-28 20:36:34 +03:00
|
|
|
|
2009-05-06 13:14:48 +03:00
|
|
|
CHighlightableButton::CHighlightableButton( const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key)
|
|
|
|
: onlyOn(false), selected(false), callback2(onDeselect)
|
2008-08-28 20:36:34 +03:00
|
|
|
{
|
2008-10-19 16:17:32 +03:00
|
|
|
init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,key);
|
2008-08-28 20:36:34 +03:00
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
|
2008-09-24 11:15:49 +03:00
|
|
|
void CHighlightableButtonsGroup::addButton(CHighlightableButton* bt)
|
|
|
|
{
|
|
|
|
bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID);
|
|
|
|
buttons.push_back(bt);
|
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
|
2008-10-19 16:17:32 +03:00
|
|
|
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, int key)
|
2008-09-24 11:15:49 +03:00
|
|
|
{
|
2009-05-06 13:14:48 +03:00
|
|
|
CHighlightableButton *bt = new CHighlightableButton(OnSelect, 0, tooltip, HelpBox, false, defName, 0, x, y, key);
|
|
|
|
if(musicLike)
|
|
|
|
{
|
|
|
|
bt->bitmapOffset = buttons.size() - 3;
|
|
|
|
}
|
2008-09-24 11:15:49 +03:00
|
|
|
bt->ID = uid;
|
|
|
|
bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID);
|
|
|
|
bt->onlyOn = true;
|
|
|
|
buttons.push_back(bt);
|
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
|
|
|
|
CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange, bool musicLikeButtons)
|
|
|
|
: musicLike(musicLikeButtons), onChange(OnChange)
|
|
|
|
{}
|
|
|
|
|
2008-09-24 11:15:49 +03:00
|
|
|
CHighlightableButtonsGroup::~CHighlightableButtonsGroup()
|
|
|
|
{
|
2009-05-06 13:14:48 +03:00
|
|
|
for(size_t i=0;i<buttons.size();i++)
|
|
|
|
{
|
|
|
|
delete buttons[i];
|
|
|
|
}
|
2008-09-24 11:15:49 +03:00
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
|
2008-09-24 11:15:49 +03:00
|
|
|
void CHighlightableButtonsGroup::activate()
|
|
|
|
{
|
2009-05-06 13:14:48 +03:00
|
|
|
for(size_t i=0;i<buttons.size();i++)
|
|
|
|
{
|
2008-09-24 11:15:49 +03:00
|
|
|
buttons[i]->activate();
|
2009-05-06 13:14:48 +03:00
|
|
|
}
|
2008-09-24 11:15:49 +03:00
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
|
2008-09-24 11:15:49 +03:00
|
|
|
void CHighlightableButtonsGroup::deactivate()
|
|
|
|
{
|
2009-05-06 13:14:48 +03:00
|
|
|
for(size_t i=0;i<buttons.size();i++)
|
|
|
|
{
|
2008-09-24 11:15:49 +03:00
|
|
|
buttons[i]->deactivate();
|
2009-05-06 13:14:48 +03:00
|
|
|
}
|
2008-09-24 11:15:49 +03:00
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
|
2008-09-24 11:15:49 +03:00
|
|
|
void CHighlightableButtonsGroup::select(int id, bool mode)
|
|
|
|
{
|
|
|
|
CHighlightableButton *bt = NULL;
|
|
|
|
if(mode)
|
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t i=0;i<buttons.size() && !bt; ++i)
|
2008-09-24 11:15:49 +03:00
|
|
|
if (buttons[i]->ID == id)
|
|
|
|
bt = buttons[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bt = buttons[id];
|
|
|
|
}
|
|
|
|
bt->select(true);
|
|
|
|
selectionChanged(bt->ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHighlightableButtonsGroup::selectionChanged(int to)
|
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t i=0;i<buttons.size(); ++i)
|
2008-09-24 11:15:49 +03:00
|
|
|
if(buttons[i]->ID!=to && buttons[i]->selected)
|
|
|
|
buttons[i]->select(false);
|
|
|
|
onChange(to);
|
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
|
2008-09-24 11:15:49 +03:00
|
|
|
void CHighlightableButtonsGroup::show(SDL_Surface * to )
|
|
|
|
{
|
2009-04-14 15:47:09 +03:00
|
|
|
for(size_t i=0;i<buttons.size(); ++i)
|
|
|
|
{
|
2009-05-06 13:21:05 +03:00
|
|
|
if(!musicLike || (musicLike && buttons[i]->selected)) //if musicLike, print only selected button
|
2009-05-06 13:14:48 +03:00
|
|
|
buttons[i]->show(to);
|
2009-04-14 15:47:09 +03:00
|
|
|
}
|
2008-09-24 11:15:49 +03:00
|
|
|
}
|
|
|
|
|
2008-05-18 20:33:39 +03:00
|
|
|
void CSlider::sliderClicked()
|
|
|
|
{
|
|
|
|
if(!moving)
|
|
|
|
{
|
|
|
|
MotionInterested::activate();
|
|
|
|
moving = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-25 17:09:31 +03:00
|
|
|
void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2008-11-15 15:27:05 +02:00
|
|
|
if( std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2+40 || std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2 )
|
|
|
|
return;
|
2008-05-18 20:33:39 +03:00
|
|
|
float v = sEvent.x - pos.x - 24;
|
|
|
|
v*=amount;
|
2009-03-27 01:05:40 +02:00
|
|
|
v/= (pos.w - 48);
|
|
|
|
v += 0.5f;
|
2008-05-18 20:33:39 +03:00
|
|
|
if(v!=value)
|
|
|
|
{
|
|
|
|
moveTo(v);
|
|
|
|
redrawSlider();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSlider::redrawSlider()
|
|
|
|
{
|
2009-04-14 15:47:09 +03:00
|
|
|
slider.show(screen2);
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSlider::moveLeft()
|
|
|
|
{
|
|
|
|
moveTo(value-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSlider::moveRight()
|
|
|
|
{
|
|
|
|
moveTo(value+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSlider::moveTo(int to)
|
|
|
|
{
|
|
|
|
if(to<0)
|
|
|
|
to=0;
|
|
|
|
else if(to>amount)
|
|
|
|
to=amount;
|
|
|
|
value = to;
|
2008-05-31 23:37:54 +03:00
|
|
|
if(amount)
|
|
|
|
{
|
|
|
|
float part = (float)to/amount;
|
|
|
|
part*=(pos.w-48);
|
|
|
|
slider.pos.x = part + pos.x + 16;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
slider.pos.x = pos.x+16;
|
2008-05-18 20:33:39 +03:00
|
|
|
moved(to);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSlider::activate() // makes button active
|
|
|
|
{
|
|
|
|
left.activate();
|
|
|
|
right.activate();
|
|
|
|
slider.activate();
|
|
|
|
ClickableL::activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSlider::deactivate() // makes button inactive (but doesn't delete)
|
|
|
|
{
|
|
|
|
left.deactivate();
|
|
|
|
right.deactivate();
|
|
|
|
slider.deactivate();
|
|
|
|
ClickableL::deactivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSlider::clickLeft (tribool down)
|
|
|
|
{
|
|
|
|
if(down)
|
|
|
|
{
|
2009-03-27 01:05:40 +02:00
|
|
|
float pw = LOCPLINT->current->motion.x-pos.x-24;
|
|
|
|
float rw = pw / ((float)(pos.w-48));
|
2008-05-18 20:33:39 +03:00
|
|
|
if (rw>1) return;
|
|
|
|
if (rw<0) return;
|
2009-03-27 01:05:40 +02:00
|
|
|
moveTo(rw*amount+0.5f);
|
2008-05-18 20:33:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(moving)
|
|
|
|
{
|
|
|
|
MotionInterested::deactivate();
|
|
|
|
moving = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSlider::show(SDL_Surface * to)
|
|
|
|
{
|
2009-04-14 15:47:09 +03:00
|
|
|
left.show(to);
|
|
|
|
right.show(to);
|
|
|
|
slider.show(to);
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CSlider::~CSlider()
|
|
|
|
{
|
|
|
|
delete imgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSlider::CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount, int Value, bool Horizontal)
|
|
|
|
:capacity(Capacity),amount(Amount),value(Value),horizontal(Horizontal), moved(Moved)
|
|
|
|
{
|
|
|
|
moving = false;
|
|
|
|
strongInterest = true;
|
2008-06-12 09:45:51 +03:00
|
|
|
imgs = CDefHandler::giveDefEss("IGPCRDIV.DEF");
|
2008-05-18 20:33:39 +03:00
|
|
|
|
|
|
|
left.pos.y = slider.pos.y = right.pos.y = pos.y = y;
|
|
|
|
left.pos.x = pos.x = x;
|
|
|
|
right.pos.x = x + totalw - 16;
|
|
|
|
left.callback = boost::bind(&CSlider::moveLeft,this);
|
2008-05-23 22:50:11 +03:00
|
|
|
right.callback = boost::bind(&CSlider::moveRight,this);
|
|
|
|
slider.callback = boost::bind(&CSlider::sliderClicked,this);
|
2008-05-18 20:33:39 +03:00
|
|
|
left.pos.w = left.pos.h = right.pos.w = right.pos.h = slider.pos.w = slider.pos.h = pos.h = 16;
|
|
|
|
pos.w = totalw;
|
|
|
|
left.imgs.resize(1); right.imgs.resize(1); slider.imgs.resize(1);
|
|
|
|
left.imgs[0].push_back(imgs->ourImages[0].bitmap); left.imgs[0].push_back(imgs->ourImages[1].bitmap);
|
|
|
|
right.imgs[0].push_back(imgs->ourImages[2].bitmap); right.imgs[0].push_back(imgs->ourImages[3].bitmap);
|
|
|
|
slider.imgs[0].push_back(imgs->ourImages[4].bitmap);
|
|
|
|
left.notFreeButton = right.notFreeButton = slider.notFreeButton = true;
|
|
|
|
slider.actOnDown = true;
|
|
|
|
|
|
|
|
moveTo(value);
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2008-09-07 06:38:37 +03:00
|
|
|
|
|
|
|
void CSlider::block( bool on )
|
|
|
|
{
|
|
|
|
left.block(on);
|
|
|
|
right.block(on);
|
|
|
|
slider.block(on);
|
|
|
|
}
|