AdventureMapButton.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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
  18. : public ClickableR, public Hoverable, public KeyShortcut, public CButtonBase
  19. {
  20. public:
  21. std::map<int,std::string> hoverTexts; //state -> text for statusbar
  22. std::string helpBox; //for right-click help
  23. CFunctionList<void()> callback;
  24. bool colorChange,
  25. actOnDown; //runs when mouse is pressed down over it, not when up
  26. ui8 blocked;
  27. void clickRight (boost::logic::tribool down);
  28. virtual void clickLeft (boost::logic::tribool down);
  29. void hover (bool on);
  30. 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
  31. void activate(); // makes button active
  32. void deactivate(); // makes button inactive (but doesn't delete)
  33. AdventureMapButton(); //c-tor
  34. 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
  35. 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
  36. 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
  37. AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, config::ButtonInfo *info, int key=0);//c-tor
  38. //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
  39. 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 );
  40. };
  41. class CHighlightableButton
  42. : public AdventureMapButton
  43. {
  44. public:
  45. 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);
  46. bool selected, onlyOn;
  47. CFunctionList<void()> callback2; //when disselecting
  48. void select(bool on);
  49. void clickLeft (boost::logic::tribool down);
  50. };
  51. class CHighlightableButtonsGroup
  52. {
  53. public:
  54. CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
  55. std::vector<CHighlightableButton*> buttons;
  56. bool musicLike; //determines the behaviour of this group
  57. //void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid);
  58. void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor
  59. 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
  60. CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange, bool musicLikeButtons = false);
  61. ~CHighlightableButtonsGroup();
  62. void activate();
  63. void deactivate();
  64. void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id
  65. void selectionChanged(int to);
  66. void show(SDL_Surface * to);
  67. };
  68. class CSlider : public IShowable, public MotionInterested, public ClickableL
  69. {
  70. public:
  71. AdventureMapButton left, right, slider; //if vertical then left=up
  72. int capacity,//how many elements can be active at same time
  73. amount, //how many elements
  74. value; //first active element
  75. bool horizontal, moving;
  76. CDefEssential *imgs ;
  77. boost::function<void(int)> moved;
  78. //void(T::*moved)(int to);
  79. //T* owner;
  80. void redrawSlider();
  81. void sliderClicked();
  82. void moveLeft();
  83. void clickLeft (boost::logic::tribool down);
  84. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  85. void moveRight();
  86. void moveTo(int to);
  87. void block(bool on);
  88. void activate(); // makes button active
  89. void deactivate(); // makes button inactive (but doesn't delete)
  90. void show(SDL_Surface * to);
  91. CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount,
  92. int Value=0, bool Horizontal=true);
  93. ~CSlider();
  94. };
  95. #endif // __ADVENTUREMAPBUTTON_H__