AdventureMapButton.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #pragma once
  2. #include "SDL_Extensions.h"
  3. #include "hch\CDefHandler.h"
  4. #include "CGameInfo.h"
  5. #include "hch\CLodHandler.h"
  6. template <typename T>
  7. AdventureMapButton<T>::AdventureMapButton ()
  8. {
  9. type=2;
  10. abs=true;
  11. active=false;
  12. ourObj=NULL;
  13. state=0;
  14. }
  15. template <typename T>
  16. AdventureMapButton<T>::AdventureMapButton
  17. ( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ, std::vector<std::string> * add )
  18. {
  19. owner = Owner;
  20. type=2;
  21. abs=true;
  22. active=false;
  23. ourObj=NULL;
  24. state=0;
  25. name=Name;
  26. helpBox=HelpBox;
  27. int est = LOCPLINT->playerID;
  28. CDefHandler * temp = CGI->spriteh->giveDef(defName);
  29. temp->notFreeImgs = true;
  30. for (int i=0;i<temp->ourImages.size();i++)
  31. {
  32. imgs.resize(1);
  33. imgs[0].push_back(temp->ourImages[i].bitmap);
  34. CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
  35. }
  36. delete temp;
  37. if (add)
  38. {
  39. imgs.resize(imgs.size()+add->size());
  40. for (int i=0; i<add->size();i++)
  41. {
  42. temp = CGI->spriteh->giveDef((*add)[i]);
  43. temp->notFreeImgs = true;
  44. for (int j=0;j<temp->ourImages.size();j++)
  45. {
  46. imgs[i+1].push_back(temp->ourImages[j].bitmap);
  47. CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
  48. }
  49. delete temp;
  50. }
  51. delete add;
  52. }
  53. function = Function;
  54. pos.x=x;
  55. pos.y=y;
  56. pos.w = imgs[curimg][0]->w;
  57. pos.h = imgs[curimg][0]->h -1;
  58. if (activ)
  59. activate();
  60. }
  61. template <typename T>
  62. void AdventureMapButton<T>::clickLeft (tribool down)
  63. {
  64. if (down)
  65. {
  66. state=1;
  67. }
  68. else
  69. {
  70. state=0;
  71. }
  72. show();
  73. if (pressedL && (down==false))
  74. {
  75. pressedL=state;
  76. (owner->*function)();
  77. }
  78. else
  79. {
  80. pressedL=state;
  81. }
  82. }
  83. template <typename T>
  84. void AdventureMapButton<T>::clickRight (tribool down)
  85. {
  86. if(helpBox.size()) //there is no point to show window with nothing inside...
  87. LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
  88. }
  89. template <typename T>
  90. void AdventureMapButton<T>::hover (bool on)
  91. {
  92. Hoverable::hover(on);
  93. if (on)
  94. LOCPLINT->statusbar->print(name);
  95. else if (LOCPLINT->statusbar->getCurrent()==name)
  96. LOCPLINT->statusbar->clear();
  97. }
  98. template <typename T>
  99. void AdventureMapButton<T>::activate()
  100. {
  101. if (active) return;
  102. active=true;
  103. ClickableL::activate();
  104. ClickableR::activate();
  105. Hoverable::activate();
  106. KeyInterested::activate();
  107. }
  108. template <typename T>
  109. void AdventureMapButton<T>::keyPressed (SDL_KeyboardEvent & key)
  110. {
  111. //TODO: check if it's shortcut
  112. }
  113. template <typename T>
  114. void AdventureMapButton<T>::deactivate()
  115. {
  116. if (!active) return;
  117. active=false;
  118. ClickableL::deactivate();
  119. ClickableR::deactivate();
  120. Hoverable::deactivate();
  121. KeyInterested::deactivate();
  122. }