AdventureMapButton.h 6.8 KB

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