Browse Source

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

Ivan Savenko 13 years ago
parent
commit
8fac276922

+ 1 - 1
client/BattleInterface/CBattleInterface.cpp

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

+ 35 - 54
client/BattleInterface/CBattleInterfaceClasses.cpp

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

+ 10 - 10
client/BattleInterface/CBattleInterfaceClasses.h

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

+ 5 - 3
client/UIFramework/SDL_Extensions.cpp

@@ -1281,11 +1281,13 @@ void CSDL_Ext::fillTexture(SDL_Surface *dst, SDL_Surface * src)
 	SDL_GetClipRect(src, &srcRect);
 	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);
 		}
 	}

+ 1 - 2
server/CGameHandler.cpp

@@ -5798,7 +5798,6 @@ void CGameHandler::runBattle()
 					removeObstacle(*obstPtr);
 		}
 
-		std::vector<CStack*> & stacks = (gs->curB->stacks);
 		const BattleInfo & curB = *gs->curB;
 
 		//stack loop
@@ -5890,7 +5889,7 @@ void CGameHandler::runBattle()
 			{
 				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())
 					if(s->owner == next->owner  &&  s->canBeHealed())
 						possibleStacks.push_back(s);