فهرست منبع

* music volume buttons in system options window (unfortunately seems not to affect volume at all despite appropriate music handler call)

mateuszb 16 سال پیش
والد
کامیت
bf2fec8e64
4فایلهای تغییر یافته به همراه50 افزوده شده و 20 حذف شده
  1. 32 18
      AdventureMapButton.cpp
  2. 3 2
      AdventureMapButton.h
  3. 14 0
      CPlayerInterface.cpp
  4. 1 0
      CPlayerInterface.h

+ 32 - 18
AdventureMapButton.cpp

@@ -198,6 +198,7 @@ void AdventureMapButton::block( ui8 on )
 	bitmapOffset = on ? 2 : 0;
 	show(screen2);
 }
+
 void CHighlightableButton::select(bool on)
 {
 	selected = on;
@@ -232,50 +233,61 @@ void CHighlightableButton::clickLeft( tribool down )
 	{
 		pressedL=state;
 	}
-} 
+}
 
-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 )
+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)
 {
-	onlyOn = false;
-	selected = false;
 	init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,key);
-	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, int key)
 {
-	CHighlightableButton *bt = new CHighlightableButton(OnSelect,0,tooltip,HelpBox,false,defName,0,x,y,key);
+	CHighlightableButton *bt = new CHighlightableButton(OnSelect, 0, tooltip, HelpBox, false, defName, 0, x, y, key);
+	if(musicLike)
+	{
+		bt->bitmapOffset = buttons.size() - 3;
+	}
 	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(const CFunctionList2<void(int)> &OnChange, bool musicLikeButtons)
+: musicLike(musicLikeButtons), onChange(OnChange)
+{}
+
 CHighlightableButtonsGroup::~CHighlightableButtonsGroup()
 {
-	for(size_t i=0;i<buttons.size();i++) {
-		delete buttons[i]; //TODO smartpointers
-        }
+	for(size_t i=0;i<buttons.size();i++)
+	{
+		delete buttons[i];
+	}
 }
+
 void CHighlightableButtonsGroup::activate()
 {
-	for(size_t i=0;i<buttons.size();i++) {
+	for(size_t i=0;i<buttons.size();i++)
+	{
 		buttons[i]->activate();
-        }
+	}
 }
+
 void CHighlightableButtonsGroup::deactivate()
 {
-	for(size_t i=0;i<buttons.size();i++) {
+	for(size_t i=0;i<buttons.size();i++)
+	{
 		buttons[i]->deactivate();
-        }
+	}
 }
+
 void CHighlightableButtonsGroup::select(int id, bool mode)
 {
 	CHighlightableButton *bt = NULL;
@@ -300,11 +312,13 @@ void CHighlightableButtonsGroup::selectionChanged(int to)
 			buttons[i]->select(false);
 	onChange(to);
 }
+
 void CHighlightableButtonsGroup::show(SDL_Surface * to )
 {
 	for(size_t i=0;i<buttons.size(); ++i) 
 	{
-		buttons[i]->show(to);
+		if(musicLike && buttons[i]->selected) //if musicLike, print only selected button
+			buttons[i]->show(to);
 	}
 }
 

+ 3 - 2
AdventureMapButton.h

@@ -51,7 +51,7 @@ class CHighlightableButton
 	: public AdventureMapButton
 {
 public:
-	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=0 );
+	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=0);
 	bool selected, onlyOn;
 	CFunctionList<void()> callback2; //when disselecting
 	void select(bool on);
@@ -63,11 +63,12 @@ class CHighlightableButtonsGroup
 public:
 	CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
 	std::vector<CHighlightableButton*> buttons;
+	bool musicLike; //determines the behaviour of this group
 
 	//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, int key=0); //creates new button
-	CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange);
+	CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange, bool musicLikeButtons = false);
 	~CHighlightableButtonsGroup();
 	void activate();
 	void deactivate();

+ 14 - 0
CPlayerInterface.cpp

@@ -997,6 +997,7 @@ CButtonBase::~CButtonBase()
 void CButtonBase::show(SDL_Surface * to)
 {
 	int img = std::min(state+bitmapOffset,int(imgs[curimg].size()-1));
+	img = std::max(0, img);
 
 	if (abs)
 	{
@@ -4435,6 +4436,15 @@ CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &pos, CPlayerInterface
 	mapScrollSpeed->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[359].first),CGI->generaltexth->zelp[359].second, "sysob11.def", 315, 267, 4);
 	mapScrollSpeed->select(owner->mapScrollingSpeed, 1);
 	mapScrollSpeed->onChange = boost::bind(&CPlayerInterface::setMapScrollingSpeed, owner, _1);
+
+	musicVolume = new CHighlightableButtonsGroup(0, true);
+	for(int i=1; i<=10; ++i)
+	{
+		musicVolume->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[359+i].first),CGI->generaltexth->zelp[359+i].second, "syslb.def", 188 + 19*(i-1), 415, i*10);
+	}
+	musicVolume->select(CGI->audioh->getMusicVolume(), 1);
+	musicVolume->onChange = boost::bind(&CAudioHandler::setMusicVolume, CGI->audioh, _1);
+
 }
 
 CSystemOptionsWindow::~CSystemOptionsWindow()
@@ -4446,6 +4456,7 @@ CSystemOptionsWindow::~CSystemOptionsWindow()
 	delete backToMap;
 	delete heroMoveSpeed;
 	delete mapScrollSpeed;
+	delete musicVolume;
 }
 
 void CSystemOptionsWindow::bquitf()
@@ -4477,6 +4488,7 @@ void CSystemOptionsWindow::activate()
 	backToMap->activate();
 	heroMoveSpeed->activate();
 	mapScrollSpeed->activate();
+	musicVolume->activate();
 }
 
 void CSystemOptionsWindow::deactivate()
@@ -4486,6 +4498,7 @@ void CSystemOptionsWindow::deactivate()
 	backToMap->deactivate();
 	heroMoveSpeed->deactivate();
 	mapScrollSpeed->deactivate();
+	musicVolume->deactivate();
 }
 
 void CSystemOptionsWindow::show(SDL_Surface *to)
@@ -4497,6 +4510,7 @@ void CSystemOptionsWindow::show(SDL_Surface *to)
 	backToMap->show(to);
 	heroMoveSpeed->show(to);
 	mapScrollSpeed->show(to);
+	musicVolume->show(to);
 }
 
 CTavernWindow::CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip)

+ 1 - 0
CPlayerInterface.h

@@ -902,6 +902,7 @@ private:
 	AdventureMapButton *load, *save, *restart, *mainMenu, * quitGame, * backToMap; //load, restart and main menu are not used yet
 	CHighlightableButtonsGroup * heroMoveSpeed;
 	CHighlightableButtonsGroup * mapScrollSpeed;
+	CHighlightableButtonsGroup * musicVolume, * effectsVolume;
 public:
 	CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
 	~CSystemOptionsWindow(); //d-tor