AdventureMapButton.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
  87. }
  88. template <typename T>
  89. void AdventureMapButton<T>::hover (bool on)
  90. {
  91. Hoverable::hover(on);
  92. if (on)
  93. LOCPLINT->adventureInt->statusbar.print(name);
  94. else if (LOCPLINT->adventureInt->statusbar.current==name)
  95. LOCPLINT->adventureInt->statusbar.clear();
  96. }
  97. template <typename T>
  98. void AdventureMapButton<T>::activate()
  99. {
  100. if (active) return;
  101. active=true;
  102. ClickableL::activate();
  103. ClickableR::activate();
  104. Hoverable::activate();
  105. KeyInterested::activate();
  106. }
  107. template <typename T>
  108. void AdventureMapButton<T>::keyPressed (SDL_KeyboardEvent & key)
  109. {
  110. //TODO: check if it's shortcut
  111. }
  112. template <typename T>
  113. void AdventureMapButton<T>::deactivate()
  114. {
  115. if (!active) return;
  116. active=false;
  117. ClickableL::deactivate();
  118. ClickableR::deactivate();
  119. Hoverable::deactivate();
  120. KeyInterested::deactivate();
  121. }