1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-23 21:29:13 +02:00

- a bit nicer stack queue. Check forum for graphics.

- warning fix
This commit is contained in:
Ivan Savenko 2012-08-28 16:28:21 +00:00
parent 0b85cfaf78
commit 8fac276922
5 changed files with 60 additions and 78 deletions

@ -918,7 +918,7 @@ void CBattleInterface::show(SDL_Surface * to)
if(!bresult) if(!bresult)
queue->showAll(to); queue->showAll(to);
else else
queue->blitBg(to); //blit only background, stacks are deleted queue->blitBg(to);
} }
//printing border around interface //printing border around interface

@ -616,8 +616,8 @@ void CClickableHex::clickRight(tribool down, bool previousState)
void CStackQueue::update() void CStackQueue::update()
{ {
stacksSorted.clear(); stacksSorted.clear();
owner->curInt->cb->battleGetStackQueue(stacksSorted, QUEUE_SIZE); owner->curInt->cb->battleGetStackQueue(stacksSorted, stackBoxes.size());
for (int i = 0; i < QUEUE_SIZE ; i++) for (int i = 0; i < stackBoxes.size() ; i++)
{ {
stackBoxes[i]->setStack(stacksSorted[i]); stackBoxes[i]->setStack(stacksSorted[i]);
} }
@ -629,32 +629,30 @@ CStackQueue::CStackQueue(bool Embedded, CBattleInterface * _owner)
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
if(embedded) if(embedded)
{ {
box = NULL;
bg = NULL; bg = NULL;
pos.w = QUEUE_SIZE * 37; pos.w = QUEUE_SIZE * 37;
pos.h = 32; //height of small creature img pos.h = 46;
pos.x = screen->w/2 - pos.w/2; pos.x = screen->w/2 - pos.w/2;
pos.y = (screen->h - 600)/2 + 10; pos.y = (screen->h - 600)/2 + 10;
} }
else else
{ {
box = BitmapHandler::loadBitmap("CHRROP.pcx"); bg = BitmapHandler::loadBitmap("DIBOXBCK");
bg = BitmapHandler::loadBitmap("DIBOXPI.pcx"); pos.w = 800;
pos.w = 600; pos.h = 85;
pos.h = bg->h;
} }
stackBoxes.resize(QUEUE_SIZE); stackBoxes.resize(QUEUE_SIZE);
for (int i = 0; i < QUEUE_SIZE; i++) for (int i = 0; i < stackBoxes.size(); i++)
{ {
stackBoxes[i] = new StackBox(box); stackBoxes[i] = new StackBox(embedded);
stackBoxes[i]->pos.x += 6 + (embedded ? 37 : 79)*i; stackBoxes[i]->moveBy(Point(1 + (embedded ? 36 : 80)*i, 0));
} }
} }
CStackQueue::~CStackQueue() CStackQueue::~CStackQueue()
{ {
SDL_FreeSurface(box); SDL_FreeSurface(bg);
} }
void CStackQueue::showAll(SDL_Surface * to) void CStackQueue::showAll(SDL_Surface * to)
@ -668,62 +666,45 @@ void CStackQueue::blitBg( SDL_Surface * to )
{ {
if(bg) if(bg)
{ {
for (int w = 0; w < pos.w; w += bg->w) SDL_SetClipRect(to, &pos);
{ CSDL_Ext::fillTexture(to, bg);
blitAtLoc(bg, w, 0, to); SDL_SetClipRect(to, nullptr);
}
} }
} }
void CStackQueue::StackBox::showAll(SDL_Surface * to) void CStackQueue::StackBox::showAll(SDL_Surface * to)
{ {
assert(my); assert(stack);
if(bg) bg->colorize(stack->owner);
CIntObject::showAll(to);
if(small)
printAtMiddleLoc(makeNumberShort(stack->count), pos.w/2, pos.h - 7, FONT_SMALL, Colors::Cornsilk, to);
else
printAtMiddleLoc(makeNumberShort(stack->count), pos.w/2, pos.h - 8, FONT_MEDIUM, Colors::Cornsilk, to);
}
void CStackQueue::StackBox::setStack( const CStack *stack )
{
this->stack = stack;
assert(stack);
icon->setFrame(stack->getCreature()->idNumber + 2);
}
CStackQueue::StackBox::StackBox(bool small):
stack(nullptr),
small(small)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
bg = new CPicture(small ? "StackQueueBgSmall" : "StackQueueBgBig" );
if (small)
{ {
graphics->blueToPlayersAdv(bg, my->owner); icon = new CAnimImage("CPRSMALL", 0, 0, 5, 2);
//SDL_UpdateRect(bg, 0, 0, 0, 0);
//SDL_Rect temp_rect = genRect(bg->h, bg->w, pos.x, pos.y);
//CSDL_Ext::blit8bppAlphaTo24bpp(bg, NULL, to, &temp_rect);
blitAt(bg, pos, to);
blitAt(graphics->bigImgs[my->getCreature()->idNumber], pos.x +9, pos.y + 1, to);
printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 12, FONT_MEDIUM, Colors::Cornsilk, to);
} }
else else
{ icon = new CAnimImage("TWCRPORT", 0, 0, 9, 1);
blitAt(graphics->smallImgs[-2], pos, to);
blitAt(graphics->smallImgs[my->getCreature()->idNumber], pos, to); pos.w = bg->pos.w;
const SDL_Color &ownerColor = (my->owner == 255 ? *graphics->neutralColor : graphics->playerColors[my->owner]); pos.h = bg->pos.h;
CSDL_Ext::drawBorder(to, pos, int3(ownerColor.r, ownerColor.g, ownerColor.b));
printAtMiddleLoc(makeNumberShort(my->count), pos.w/2, pos.h - 8, FONT_TINY, Colors::Cornsilk, to);
}
}
void CStackQueue::StackBox::setStack( const CStack *nStack )
{
my = nStack;
}
CStackQueue::StackBox::StackBox(SDL_Surface *BG)
:my(NULL), bg(BG)
{
if(bg)
{
pos.w = bg->w;
pos.h = bg->h;
}
else
{
pos.w = pos.h = 32;
}
pos.y += 2;
}
CStackQueue::StackBox::~StackBox()
{
}
void CStackQueue::StackBox::hover( bool on )
{
} }

@ -13,6 +13,7 @@ class CHighlightableButtonsGroup;
class CLabel; class CLabel;
struct BattleResult; struct BattleResult;
class CStack; class CStack;
class CAnimImage;
/* /*
* CBattleInterfaceClasses.h, part of VCMI engine * CBattleInterfaceClasses.h, part of VCMI engine
@ -125,14 +126,14 @@ class CStackQueue : public CIntObject
class StackBox : public CIntObject class StackBox : public CIntObject
{ {
public: public:
const CStack *my; CPicture * bg;
SDL_Surface *bg; CAnimImage * icon;
const CStack *stack;
bool small;
void hover (bool on);
void showAll(SDL_Surface * to); void showAll(SDL_Surface * to);
void setStack(const CStack *nStack); void setStack(const CStack *nStack);
StackBox(SDL_Surface *BG); StackBox(bool small);
~StackBox();
}; };
public: public:
@ -141,14 +142,13 @@ public:
std::vector<const CStack *> stacksSorted; std::vector<const CStack *> stacksSorted;
std::vector<StackBox *> stackBoxes; std::vector<StackBox *> stackBoxes;
SDL_Surface *box; SDL_Surface * bg;
SDL_Surface *bg;
CBattleInterface * owner; CBattleInterface * owner;
void showAll(SDL_Surface * to);
CStackQueue(bool Embedded, CBattleInterface * _owner); CStackQueue(bool Embedded, CBattleInterface * _owner);
~CStackQueue(); ~CStackQueue();
void update(); void update();
void blitBg( SDL_Surface * to ); void showAll(SDL_Surface *to);
//void showAll(SDL_Surface * to); void blitBg(SDL_Surface * to);
}; };

@ -1281,11 +1281,13 @@ void CSDL_Ext::fillTexture(SDL_Surface *dst, SDL_Surface * src)
SDL_GetClipRect(src, &srcRect); SDL_GetClipRect(src, &srcRect);
SDL_GetClipRect(dst, &dstRect); SDL_GetClipRect(dst, &dstRect);
for (int y=dstRect.y; y<dstRect.h; y+=srcRect.h) for (int y=dstRect.y; y < dstRect.y + dstRect.h; y+=srcRect.h)
{ {
for (int x=dstRect.x; x<dstRect.w; x+=srcRect.w) for (int x=dstRect.x; x < dstRect.x + dstRect.w; x+=srcRect.w)
{ {
Rect currentDest(x, y, srcRect.w, srcRect.h); int xLeft = std::min<int>(srcRect.w, dstRect.x + dstRect.w - x);
int yLeft = std::min<int>(srcRect.h, dstRect.y + dstRect.h - y);
Rect currentDest(x, y, xLeft, yLeft);
SDL_BlitSurface(src, &srcRect, dst, &currentDest); SDL_BlitSurface(src, &srcRect, dst, &currentDest);
} }
} }

@ -5798,7 +5798,6 @@ void CGameHandler::runBattle()
removeObstacle(*obstPtr); removeObstacle(*obstPtr);
} }
std::vector<CStack*> & stacks = (gs->curB->stacks);
const BattleInfo & curB = *gs->curB; const BattleInfo & curB = *gs->curB;
//stack loop //stack loop
@ -5890,7 +5889,7 @@ void CGameHandler::runBattle()
{ {
std::vector< const CStack * > possibleStacks; std::vector< const CStack * > possibleStacks;
//is there any clean algorithm for that? (boost.range seems to lack copy_if) //is there any clean algorithm for that? (boost.range seems to lack copy_if) -> remove_copy_if?
BOOST_FOREACH(const CStack *s, battleGetAllStacks()) BOOST_FOREACH(const CStack *s, battleGetAllStacks())
if(s->owner == next->owner && s->canBeHealed()) if(s->owner == next->owner && s->canBeHealed())
possibleStacks.push_back(s); possibleStacks.push_back(s);