AdventureMapButton.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef __ADVENTUREMAPBUTTON_H__
  2. #define __ADVENTUREMAPBUTTON_H__
  3. #include "FunctionList.h"
  4. #include <boost/bind.hpp>
  5. #include "GUIBase.h"
  6. /*
  7. * AdventureMapButton.h, part of VCMI engine
  8. *
  9. * Authors: listed in file AUTHORS in main folder
  10. *
  11. * License: GNU General Public License v2.0 or later
  12. * Full text of license available in license.txt file, in main folder
  13. *
  14. */
  15. class CDefEssential;
  16. namespace config{struct ButtonInfo;}
  17. class AdventureMapButton : public CButtonBase
  18. {
  19. public:
  20. std::map<int,std::string> hoverTexts; //state -> text for statusbar
  21. std::string helpBox; //for right-click help
  22. CFunctionList<void()> callback;
  23. bool colorChange,
  24. actOnDown; //runs when mouse is pressed down over it, not when up
  25. ui8 blocked;
  26. void clickRight(tribool down, bool previousState);
  27. virtual void clickLeft(tribool down, bool previousState);
  28. void hover (bool on);
  29. void block(ui8 on); //if button is blocked then it'll change it's graphic to inactive (offset==2) and won't react on l-clicks
  30. void activate(); // makes button active
  31. void deactivate(); // makes button inactive (but doesn't delete)
  32. AdventureMapButton(); //c-tor
  33. AdventureMapButton( const std::map<int,std::string> &, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
  34. AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
  35. 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 );//c-tor
  36. AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, config::ButtonInfo *info, int key=0);//c-tor
  37. //AdventureMapButton( std::string Name, std::string HelpBox, boost::function<void()> Callback, int x, int y, std::string defName, bool activ=false, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
  38. void 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 );
  39. };
  40. class CHighlightableButton
  41. : public AdventureMapButton
  42. {
  43. public:
  44. 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);
  45. bool selected, onlyOn;
  46. CFunctionList<void()> callback2; //when disselecting
  47. void select(bool on);
  48. void clickLeft(tribool down, bool previousState);
  49. };
  50. class CHighlightableButtonsGroup
  51. {
  52. public:
  53. CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
  54. std::vector<CHighlightableButton*> buttons;
  55. bool musicLike; //determines the behaviour of this group
  56. //void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid);
  57. void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor
  58. 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
  59. CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange, bool musicLikeButtons = false);
  60. ~CHighlightableButtonsGroup();
  61. void activate();
  62. void deactivate();
  63. void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id
  64. void selectionChanged(int to);
  65. void show(SDL_Surface * to);
  66. };
  67. class CSlider : public CIntObject
  68. {
  69. public:
  70. AdventureMapButton left, right, slider; //if vertical then left=up
  71. int capacity,//how many elements can be active at same time
  72. amount, //how many elements
  73. value; //first active element
  74. bool horizontal, moving;
  75. CDefEssential *imgs ;
  76. boost::function<void(int)> moved;
  77. //void(T::*moved)(int to);
  78. //T* owner;
  79. void redrawSlider();
  80. void sliderClicked();
  81. void moveLeft();
  82. void clickLeft(tribool down, bool previousState);
  83. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  84. void moveRight();
  85. void moveTo(int to);
  86. void block(bool on);
  87. void activate(); // makes button active
  88. void deactivate(); // makes button inactive (but doesn't delete)
  89. void show(SDL_Surface * to);
  90. CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount,
  91. int Value=0, bool Horizontal=true);
  92. ~CSlider();
  93. };
  94. #endif // __ADVENTUREMAPBUTTON_H__