AdventureMapButton.h 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. int ourKey; //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 (const 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, 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( 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, int key );
  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, int key=0 );
  33. bool selected, onlyOn;
  34. CFunctionList<void()> callback2; //when disselecting
  35. void select(bool on);
  36. void clickLeft (tribool down);
  37. };
  38. class CHighlightableButtonsGroup
  39. {
  40. public:
  41. CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
  42. std::vector<CHighlightableButton*> buttons;
  43. //void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid);
  44. void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor
  45. 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
  46. CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange);
  47. ~CHighlightableButtonsGroup();
  48. void activate();
  49. void deactivate();
  50. void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id
  51. void selectionChanged(int to);
  52. void show(SDL_Surface * to = NULL);
  53. };
  54. class CSlider : public IShowable, public MotionInterested, public ClickableL
  55. {
  56. public:
  57. AdventureMapButton left, right, slider; //if vertical then left=up
  58. int capacity,//how many elements can be active at same time
  59. amount, //how many elements
  60. value; //first active element
  61. bool horizontal, moving;
  62. CDefEssential *imgs ;
  63. boost::function<void(int)> moved;
  64. //void(T::*moved)(int to);
  65. //T* owner;
  66. void redrawSlider();
  67. void sliderClicked();
  68. void moveLeft();
  69. void clickLeft (tribool down);
  70. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  71. void moveRight();
  72. void moveTo(int to);
  73. void block(bool on);
  74. void activate(); // makes button active
  75. void deactivate(); // makes button inactive (but doesn't delete)
  76. void show(SDL_Surface * to = NULL);
  77. CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount,
  78. int Value=0, bool Horizontal=true);
  79. ~CSlider();
  80. };