2
0

CStackQueue.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include "StdInc.h"
  2. #include "CStackQueue.h"
  3. #include "CBattleInterface.h"
  4. #include "../../lib/BattleState.h"
  5. #include "../Graphics.h"
  6. #include "../SDL_Extensions.h"
  7. #include "../CPlayerInterface.h"
  8. #include "../CBitmapHandler.h"
  9. #include "../../CCallback.h"
  10. #include "../UIFramework/CGuiHandler.h"
  11. void CStackQueue::update()
  12. {
  13. stacksSorted.clear();
  14. owner->curInt->cb->getStackQueue(stacksSorted, QUEUE_SIZE);
  15. for (int i = 0; i < QUEUE_SIZE ; i++)
  16. {
  17. stackBoxes[i]->setStack(stacksSorted[i]);
  18. }
  19. }
  20. CStackQueue::CStackQueue(bool Embedded, CBattleInterface * _owner)
  21. :embedded(Embedded), owner(_owner)
  22. {
  23. OBJ_CONSTRUCTION_CAPTURING_ALL;
  24. if(embedded)
  25. {
  26. box = NULL;
  27. bg = NULL;
  28. pos.w = QUEUE_SIZE * 37;
  29. pos.h = 32; //height of small creature img
  30. pos.x = screen->w/2 - pos.w/2;
  31. pos.y = (screen->h - 600)/2 + 10;
  32. }
  33. else
  34. {
  35. box = BitmapHandler::loadBitmap("CHRROP.pcx");
  36. bg = BitmapHandler::loadBitmap("DIBOXPI.pcx");
  37. pos.w = 600;
  38. pos.h = bg->h;
  39. }
  40. stackBoxes.resize(QUEUE_SIZE);
  41. for (int i = 0; i < QUEUE_SIZE; i++)
  42. {
  43. stackBoxes[i] = new StackBox(box);
  44. stackBoxes[i]->pos.x += 6 + (embedded ? 37 : 79)*i;
  45. }
  46. }
  47. CStackQueue::~CStackQueue()
  48. {
  49. SDL_FreeSurface(box);
  50. }
  51. void CStackQueue::showAll( SDL_Surface *to )
  52. {
  53. blitBg(to);
  54. CIntObject::showAll(to);
  55. }
  56. void CStackQueue::blitBg( SDL_Surface * to )
  57. {
  58. if(bg)
  59. {
  60. for (int w = 0; w < pos.w; w += bg->w)
  61. {
  62. blitAtLoc(bg, w, 0, to);
  63. }
  64. }
  65. }
  66. void CStackQueue::StackBox::showAll( SDL_Surface *to )
  67. {
  68. assert(my);
  69. if(bg)
  70. {
  71. graphics->blueToPlayersAdv(bg, my->owner);
  72. //SDL_UpdateRect(bg, 0, 0, 0, 0);
  73. SDL_Rect temp_rect = genRect(bg->h, bg->w, pos.x, pos.y);
  74. CSDL_Ext::blit8bppAlphaTo24bpp(bg, NULL, to, &temp_rect);
  75. //blitAt(bg, pos, to);
  76. blitAt(graphics->bigImgs[my->getCreature()->idNumber], pos.x +9, pos.y + 1, to);
  77. printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 12, FONT_MEDIUM, zwykly, to);
  78. }
  79. else
  80. {
  81. blitAt(graphics->smallImgs[-2], pos, to);
  82. blitAt(graphics->smallImgs[my->getCreature()->idNumber], pos, to);
  83. const SDL_Color &ownerColor = (my->owner == 255 ? *graphics->neutralColor : graphics->playerColors[my->owner]);
  84. CSDL_Ext::drawBorder(to, pos, int3(ownerColor.r, ownerColor.g, ownerColor.b));
  85. printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 8, FONT_TINY, zwykly, to);
  86. }
  87. }
  88. void CStackQueue::StackBox::setStack( const CStack *nStack )
  89. {
  90. my = nStack;
  91. }
  92. CStackQueue::StackBox::StackBox(SDL_Surface *BG)
  93. :my(NULL), bg(BG)
  94. {
  95. if(bg)
  96. {
  97. pos.w = bg->w;
  98. pos.h = bg->h;
  99. }
  100. else
  101. {
  102. pos.w = pos.h = 32;
  103. }
  104. pos.y += 2;
  105. }
  106. CStackQueue::StackBox::~StackBox()
  107. {
  108. }
  109. void CStackQueue::StackBox::hover( bool on )
  110. {
  111. }