AdventureMapButton.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include "CPlayerInterface.h"
  3. #include "client/FunctionList.h"
  4. #include <boost/bind.hpp>
  5. class AdventureMapButton
  6. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CButtonBase
  7. {
  8. public:
  9. std::map<int,std::string> hoverTexts; //state -> text for statusbar
  10. std::string helpBox; //for right-click help
  11. char key; //key shortcut
  12. CFunctionList<void()> callback;
  13. bool colorChange, blocked,
  14. actOnDown; //runs when mouse is pressed down over it, not when up
  15. void clickRight (tribool down);
  16. virtual void clickLeft (tribool down);
  17. void hover (bool on);
  18. 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
  19. void keyPressed (SDL_KeyboardEvent & key);
  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, bool activ=false, 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, bool activ=false, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
  25. //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
  26. 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, bool activ );
  27. };
  28. class CHighlightableButton
  29. : public AdventureMapButton
  30. {
  31. public:
  32. 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, bool activ );
  33. bool selected;
  34. CFunctionList<void()> callback2; //when disselecting
  35. void clickLeft (tribool down);
  36. };
  37. //template<typename T>
  38. class CSlider : public IShowable, public MotionInterested, public ClickableL
  39. {
  40. public:
  41. AdventureMapButton left, right, slider; //if vertical then left=up
  42. int capacity,//how many elements can be active at same time
  43. amount, //how many elements
  44. value; //first active element
  45. bool horizontal, moving;
  46. CDefEssential *imgs ;
  47. boost::function<void(int)> moved;
  48. //void(T::*moved)(int to);
  49. //T* owner;
  50. void redrawSlider();
  51. void sliderClicked();
  52. void moveLeft();
  53. void clickLeft (tribool down);
  54. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  55. void moveRight();
  56. void moveTo(int to);
  57. void block(bool on);
  58. void activate(); // makes button active
  59. void deactivate(); // makes button inactive (but doesn't delete)
  60. void show(SDL_Surface * to = NULL);
  61. CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount,
  62. int Value=0, bool Horizontal=true);
  63. ~CSlider();
  64. };