AdventureMapButton.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 select(bool on);
  36. void clickLeft (tribool down);
  37. };
  38. //template<typename T>
  39. class CSlider : public IShowable, public MotionInterested, public ClickableL
  40. {
  41. public:
  42. AdventureMapButton left, right, slider; //if vertical then left=up
  43. int capacity,//how many elements can be active at same time
  44. amount, //how many elements
  45. value; //first active element
  46. bool horizontal, moving;
  47. CDefEssential *imgs ;
  48. boost::function<void(int)> moved;
  49. //void(T::*moved)(int to);
  50. //T* owner;
  51. void redrawSlider();
  52. void sliderClicked();
  53. void moveLeft();
  54. void clickLeft (tribool down);
  55. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  56. void moveRight();
  57. void moveTo(int to);
  58. void block(bool on);
  59. void activate(); // makes button active
  60. void deactivate(); // makes button inactive (but doesn't delete)
  61. void show(SDL_Surface * to = NULL);
  62. CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount,
  63. int Value=0, bool Horizontal=true);
  64. ~CSlider();
  65. };