AdventureMapButton.h 4.6 KB

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