2
0

CStackQueue.cpp 2.7 KB

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