AdventureMapButton.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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); //todo: moze cieknac
  29. for (int i=0;i<temp->ourImages.size();i++)
  30. {
  31. imgs.resize(1);
  32. imgs[0].push_back(temp->ourImages[i].bitmap);
  33. CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
  34. }
  35. if (add)
  36. {
  37. imgs.resize(imgs.size()+add->size());
  38. for (int i=0; i<add->size();i++)
  39. {
  40. temp = CGI->spriteh->giveDef((*add)[i]);
  41. for (int j=0;j<temp->ourImages.size();j++)
  42. {
  43. imgs[i+1].push_back(temp->ourImages[j].bitmap);
  44. CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
  45. }
  46. }
  47. delete add;
  48. }
  49. function = Function;
  50. pos.x=x;
  51. pos.y=y;
  52. pos.w = imgs[curimg][0]->w;
  53. pos.h = imgs[curimg][0]->h -1;
  54. if (activ)
  55. activate();
  56. }
  57. template <typename T>
  58. void AdventureMapButton<T>::clickLeft (tribool down)
  59. {
  60. if (down)
  61. {
  62. state=1;
  63. }
  64. else
  65. {
  66. state=0;
  67. }
  68. show();
  69. if (pressedL && (down==false))
  70. {
  71. pressedL=state;
  72. (owner->*function)();
  73. }
  74. else
  75. {
  76. pressedL=state;
  77. }
  78. }
  79. template <typename T>
  80. void AdventureMapButton<T>::clickRight (tribool down)
  81. {
  82. LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
  83. }
  84. template <typename T>
  85. void AdventureMapButton<T>::hover (bool on)
  86. {
  87. Hoverable::hover(on);
  88. if (on)
  89. LOCPLINT->adventureInt->statusbar.print(name);
  90. else if (LOCPLINT->adventureInt->statusbar.current==name)
  91. LOCPLINT->adventureInt->statusbar.clear();
  92. }
  93. template <typename T>
  94. void AdventureMapButton<T>::activate()
  95. {
  96. if (active) return;
  97. active=true;
  98. ClickableL::activate();
  99. ClickableR::activate();
  100. Hoverable::activate();
  101. KeyInterested::activate();
  102. }
  103. template <typename T>
  104. void AdventureMapButton<T>::keyPressed (SDL_KeyboardEvent & key)
  105. {
  106. //TODO: check if it's shortcut
  107. }
  108. template <typename T>
  109. void AdventureMapButton<T>::deactivate()
  110. {
  111. if (!active) return;
  112. active=false;
  113. ClickableL::deactivate();
  114. ClickableR::deactivate();
  115. Hoverable::deactivate();
  116. KeyInterested::deactivate();
  117. }