AdventureMapButton.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 CButtonBase : public KeyShortcut//basic buttton class
  18. {
  19. public:
  20. struct TextOverlay
  21. {
  22. EFonts font;
  23. std::string text;
  24. int x, y;
  25. } *text;
  26. void addTextOverlay(const std::string Text, EFonts font);
  27. int bitmapOffset; //TODO: comment me
  28. int type; //advmapbutton=2 //TODO: comment me
  29. bool abs;//TODO: comment me
  30. //bool active; //if true, this button is active and can be pressed
  31. bool notFreeButton; //TODO: comment me
  32. CIntObject * ourObj; // "owner"
  33. int state; //TODO: comment me
  34. std::vector< std::vector<SDL_Surface*> > imgs; //images for this button
  35. int curimg; //curently displayed image from imgs
  36. virtual void show(SDL_Surface * to);
  37. virtual void showAll(SDL_Surface * to);
  38. //virtual void activate()=0;
  39. //virtual void deactivate()=0;
  40. CButtonBase(); //c-tor
  41. virtual ~CButtonBase(); //d-tor
  42. };
  43. class AdventureMapButton : public CButtonBase
  44. {
  45. public:
  46. std::map<int,std::string> hoverTexts; //state -> text for statusbar
  47. std::string helpBox; //for right-click help
  48. CFunctionList<void()> callback;
  49. bool actOnDown, //runs when mouse is pressed down over it, not when up
  50. hoverable; //if true, button will be highlighted when hovered
  51. ui8 blocked;
  52. void clickRight(tribool down, bool previousState);
  53. virtual void clickLeft(tribool down, bool previousState);
  54. void hover (bool on);
  55. 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
  56. //void activate(); // makes button active
  57. //void deactivate(); // makes button inactive (but doesn't delete)
  58. AdventureMapButton(); //c-tor
  59. 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
  60. 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
  61. 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
  62. AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, config::ButtonInfo *info, int key=0);//c-tor
  63. //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
  64. 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 );
  65. void setDef(const std::string & defName, bool playerColoredButton);
  66. };
  67. class CHighlightableButton
  68. : public AdventureMapButton
  69. {
  70. public:
  71. 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);
  72. CHighlightableButton(const std::pair<std::string, std::string> help, const CFunctionList<void()> &onSelect, int x, int y, const std::string &defName, int myid, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
  73. CHighlightableButton(const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &onSelect, int x, int y, const std::string &defName, int myid, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
  74. bool onlyOn, selected;
  75. CFunctionList<void()> callback2; //when de-selecting
  76. void select(bool on);
  77. void clickLeft(tribool down, bool previousState);
  78. };
  79. class CHighlightableButtonsGroup : public CIntObject
  80. {
  81. public:
  82. CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
  83. std::vector<CHighlightableButton*> buttons;
  84. bool musicLike; //determines the behaviour of this group
  85. //void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid);
  86. void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor
  87. 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
  88. CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange, bool musicLikeButtons = false);
  89. ~CHighlightableButtonsGroup();
  90. void activate();
  91. void deactivate();
  92. void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id
  93. void selectionChanged(int to);
  94. void show(SDL_Surface * to);
  95. void showAll(SDL_Surface * to);
  96. void block(ui8 on);
  97. };
  98. class CSlider : public CIntObject
  99. {
  100. public:
  101. AdventureMapButton *left, *right, *slider; //if vertical then left=up
  102. int capacity,//how many elements can be active at same time
  103. amount, //how many elements
  104. positions, //number of highest position (0 if there is only one)
  105. value; //first active element
  106. bool horizontal;
  107. CDefEssential *imgs ;
  108. boost::function<void(int)> moved;
  109. //void(T::*moved)(int to);
  110. //T* owner;
  111. void redrawSlider();
  112. void sliderClicked();
  113. void moveLeft();
  114. void clickLeft(tribool down, bool previousState);
  115. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  116. void moveRight();
  117. void moveTo(int to);
  118. void block(bool on);
  119. void setAmount(int to);
  120. //void activate(); // makes button active
  121. //void deactivate(); // makes button inactive (but doesn't delete)
  122. //void show(SDL_Surface * to);
  123. CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount,
  124. int Value=0, bool Horizontal=true, int style = 0); //style 0 - brown, 1 - blue
  125. ~CSlider();
  126. };
  127. #endif // __ADVENTUREMAPBUTTON_H__