1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* next part of hero exchange window

* minor changes
This commit is contained in:
mateuszb 2009-06-26 15:41:19 +00:00
parent 20676e8f95
commit 0919235948
7 changed files with 125 additions and 4 deletions

View File

@ -371,7 +371,7 @@ void CHeroWindow::redrawCurBack()
SDL_FreeSurface(curBack); SDL_FreeSurface(curBack);
curBack = SDL_DisplayFormat(background); curBack = SDL_DisplayFormat(background);
//primary skills & morale and luck graphics //primary skills & exp and mana
blitAt(graphics->pskillsm->ourImages[0].bitmap, 32, 111, curBack); blitAt(graphics->pskillsm->ourImages[0].bitmap, 32, 111, curBack);
blitAt(graphics->pskillsm->ourImages[1].bitmap, 102, 111, curBack); blitAt(graphics->pskillsm->ourImages[1].bitmap, 102, 111, curBack);
blitAt(graphics->pskillsm->ourImages[2].bitmap, 172, 111, curBack); blitAt(graphics->pskillsm->ourImages[2].bitmap, 172, 111, curBack);
@ -429,6 +429,7 @@ void CHeroWindow::redrawCurBack()
CSDL_Ext::printAtMiddle(primarySkill.str(), 53 + 70 * m, 165, TNRB16, zwykly, curBack); CSDL_Ext::printAtMiddle(primarySkill.str(), 53 + 70 * m, 165, TNRB16, zwykly, curBack);
} }
//morale and luck printing
blitAt(graphics->luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack); blitAt(graphics->luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack);
blitAt(graphics->morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack); blitAt(graphics->morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack);

View File

@ -3670,6 +3670,16 @@ void CExchangeWindow::activate()
{ {
questlogButton[g]->activate(); questlogButton[g]->activate();
} }
for(int g=0; g<ARRAY_COUNT(morale); g++)
{
morale[g]->activate();
}
for(int g=0; g<ARRAY_COUNT(luck); g++)
{
luck[g]->activate();
}
} }
void CExchangeWindow::deactivate() void CExchangeWindow::deactivate()
@ -3696,6 +3706,16 @@ void CExchangeWindow::deactivate()
{ {
questlogButton[g]->deactivate(); questlogButton[g]->deactivate();
} }
for(int g=0; g<ARRAY_COUNT(morale); g++)
{
morale[g]->deactivate();
}
for(int g=0; g<ARRAY_COUNT(luck); g++)
{
luck[g]->deactivate();
}
} }
void CExchangeWindow::show(SDL_Surface * to) void CExchangeWindow::show(SDL_Surface * to)
@ -3803,9 +3823,43 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) //c-tor
//experience //experience
blitAt(skilldef->ourImages[4].bitmap, 103 + 490*b, 45, bg); blitAt(skilldef->ourImages[4].bitmap, 103 + 490*b, 45, bg);
printAtMiddle( makeNumberShort(heroInst[b]->exp), 119 + 490*b, 71, GEOR13, zwykly, bg );
//mana points //mana points
blitAt(skilldef->ourImages[5].bitmap, 139 + 490*b, 45, bg); blitAt(skilldef->ourImages[5].bitmap, 139 + 490*b, 45, bg);
printAtMiddle( makeNumberShort(heroInst[b]->mana), 155 + 490*b, 71, GEOR13, zwykly, bg );
//setting morale
morale[b] = new LRClickableAreaWTextComp();
morale[b]->pos = genRect(32, 32, pos.x + 177 + 490*b, pos.y + 45);
blitAt(graphics->morale30->ourImages[heroInst[b]->getCurrentMorale()+3].bitmap, 177 + 490*b, 45, bg);
std::vector<std::pair<int,std::string> > mrl = heroInst[b]->getCurrentMoraleModifiers();
int mrlv = heroInst[b]->getCurrentMorale();
int mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad morale[b], 0 - neutral, 1 - good
morale[b]->hoverText = CGI->generaltexth->heroscrn[4 - mrlt];
morale[b]->baseType = SComponent::morale;
morale[b]->bonus = mrlv;
morale[b]->text = CGI->generaltexth->arraytxt[88];
boost::algorithm::replace_first(morale[b]->text,"%s",CGI->generaltexth->arraytxt[86-mrlt]);
for(int it=0; it < mrl.size(); it++)
morale[b]->text += mrl[it].second;
//setting luck
luck[b] = new LRClickableAreaWTextComp();
luck[b]->pos = genRect(32, 32, pos.x + 213 + 490*b, pos.y + 45);
blitAt(graphics->luck30->ourImages[heroInst[b]->getCurrentLuck()+3].bitmap, 213 + 490*b, 45, bg);
mrl = heroInst[b]->getCurrentLuckModifiers();
mrlv = heroInst[b]->getCurrentLuck();
mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad luck[b], 0 - neutral, 1 - good
luck[b]->hoverText = CGI->generaltexth->heroscrn[7 - mrlt];
luck[b]->baseType = SComponent::luck;
luck[b]->bonus = mrlv;
luck[b]->text = CGI->generaltexth->arraytxt[62];
boost::algorithm::replace_first(luck[b]->text,"%s",CGI->generaltexth->arraytxt[60-mrlt]);
for(int it=0; it < mrl.size(); it++)
luck[b]->text += mrl[it].second;
} }
//printing portraits //printing portraits
@ -3851,6 +3905,16 @@ CExchangeWindow::~CExchangeWindow() //d-tor
{ {
delete questlogButton[g]; delete questlogButton[g];
} }
for(int g=0; g<ARRAY_COUNT(morale); g++)
{
delete morale[g];
}
for(int g=0; g<ARRAY_COUNT(luck); g++)
{
delete luck[g];
}
} }

View File

@ -680,6 +680,8 @@ class CExchangeWindow : public CIntObject, public IShowActivable
std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas; std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
LRClickableAreaWTextComp *morale[2], *luck[2];
public: public:
void close(); void close();

View File

@ -31,6 +31,7 @@ SDL_Surface * CSDL_Ext::copySurface(SDL_Surface * mod) //returns copy of given s
//return SDL_DisplayFormat(mod); //return SDL_DisplayFormat(mod);
return SDL_ConvertSurface(mod, mod->format, mod->flags); return SDL_ConvertSurface(mod, mod->format, mod->flags);
} }
bool isItIn(const SDL_Rect * rect, int x, int y) bool isItIn(const SDL_Rect * rect, int x, int y)
{ {
if ((x>rect->x && x<rect->x+rect->w) && (y>rect->y && y<rect->y+rect->h)) if ((x>rect->x && x<rect->x+rect->w) && (y>rect->y && y<rect->y+rect->h))
@ -44,20 +45,24 @@ void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst)
SDL_BlitSurface(src,NULL,dst,&pom); SDL_BlitSurface(src,NULL,dst,&pom);
SDL_UpdateRect(dst,x,y,src->w,src->h); SDL_UpdateRect(dst,x,y,src->w,src->h);
} }
void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst) void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst)
{ {
if(!dst) dst = screen; if(!dst) dst = screen;
SDL_Rect pom = genRect(src->h,src->w,x,y); SDL_Rect pom = genRect(src->h,src->w,x,y);
SDL_BlitSurface(src,NULL,dst,&pom); SDL_BlitSurface(src,NULL,dst,&pom);
} }
void blitAtWR(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst) void blitAtWR(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst)
{ {
blitAtWR(src,pos.x,pos.y,dst); blitAtWR(src,pos.x,pos.y,dst);
} }
void blitAt(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst) void blitAt(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst)
{ {
blitAt(src,pos.x,pos.y,dst); blitAt(src,pos.x,pos.y,dst);
} }
SDL_Color genRGB(int r, int g, int b, int a=0) SDL_Color genRGB(int r, int g, int b, int a=0)
{ {
SDL_Color ret; SDL_Color ret;
@ -67,10 +72,12 @@ SDL_Color genRGB(int r, int g, int b, int a=0)
ret.unused=a; ret.unused=a;
return ret; return ret;
} }
void updateRect (SDL_Rect * rect, SDL_Surface * scr) void updateRect (SDL_Rect * rect, SDL_Surface * scr)
{ {
SDL_UpdateRect(scr,rect->x,rect->y,rect->w,rect->h); SDL_UpdateRect(scr,rect->x,rect->y,rect->w,rect->h);
} }
void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor, SDL_Surface * dst) void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor, SDL_Surface * dst)
{ {
std::vector<std::string> * ws = CMessage::breakText(text,charpr); std::vector<std::string> * ws = CMessage::breakText(text,charpr);
@ -101,6 +108,7 @@ void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font
SDL_FreeSurface(wesu[i]); SDL_FreeSurface(wesu[i]);
delete ws; delete ws;
} }
void CSDL_Ext::printAtWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor, SDL_Surface * dst) void CSDL_Ext::printAtWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor, SDL_Surface * dst)
{ {
std::vector<std::string> * ws = CMessage::breakText(text,charpr); std::vector<std::string> * ws = CMessage::breakText(text,charpr);
@ -120,6 +128,7 @@ void CSDL_Ext::printAtWB(const std::string & text, int x, int y, TTF_Font * font
SDL_FreeSurface(wesu[i]); SDL_FreeSurface(wesu[i]);
delete ws; delete ws;
} }
void CSDL_Ext::printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality, bool refresh) void CSDL_Ext::printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality, bool refresh)
{ {
if(text.length()==0) return; if(text.length()==0) return;
@ -149,6 +158,7 @@ void CSDL_Ext::printAtMiddle(const std::string & text, int x, int y, TTF_Font *
SDL_UpdateRect(dst,x-(temp->w/2),y-(temp->h/2),temp->w,temp->h); SDL_UpdateRect(dst,x-(temp->w/2),y-(temp->h/2),temp->w,temp->h);
SDL_FreeSurface(temp); SDL_FreeSurface(temp);
} }
void CSDL_Ext::printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality, bool refresh) void CSDL_Ext::printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality, bool refresh)
{ {
if (text.length()==0) if (text.length()==0)

View File

@ -5,6 +5,8 @@
#include <string> #include <string>
#include "../int3.h" #include "../int3.h"
#include <vector> #include <vector>
#include <sstream>
#include <boost/type_traits/is_integral.hpp>
/* /*
* SDL_Extensions.h, part of VCMI engine * SDL_Extensions.h, part of VCMI engine
@ -26,6 +28,47 @@ void blitAt(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst=screen);
void updateRect (SDL_Rect * rect, SDL_Surface * scr = screen); void updateRect (SDL_Rect * rect, SDL_Surface * scr = screen);
bool isItIn(const SDL_Rect * rect, int x, int y); bool isItIn(const SDL_Rect * rect, int x, int y);
template<typename IntType>
std::string makeNumberShort(IntType number) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k)
{
BOOST_MPL_ASSERT_MSG( boost::is_integral<IntType>::value, NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED, (IntType) ); //it should make noise if IntType is not integral type
int initialLength;
bool negative = (number < 0);
std::ostringstream ost, rets;
ost<<number;
initialLength = ost.str().size();
if(negative)
{
if(initialLength <= 4)
return ost.str();
}
else
{
if(initialLength <= 5)
return ost.str();
}
//make the number short
char symbol[] = {'G', 'M', 'k'};
if(negative) number = (-number); //absolute value
for(int divisor = 1000000000, it = 0; divisor > 1; divisor /= 1000, ++it)
{
if(number >= divisor)
{
if(negative) rets <<'-';
rets << (number / divisor) << symbol[it];
return rets.str();
}
}
throw std::string("We shouldn't be here - makeNumberShort");
}
inline SDL_Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy) inline SDL_Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy)
{ {
SDL_Rect ret; SDL_Rect ret;

View File

@ -49,7 +49,8 @@ struct Entry
//Entry(unsigned char ): nameStr(con){}; //Entry(unsigned char ): nameStr(con){};
Entry(){}; Entry(){};
}; };
class DLL_EXPORT CLodHandler
class DLL_EXPORT CLodHandler
{ {
public: public:
FILE* FLOD; FILE* FLOD;

View File

@ -216,7 +216,7 @@ CLoadFile::CLoadFile( const std::string &fname )
if(std::memcmp(buffer,"VCMI",4)) if(std::memcmp(buffer,"VCMI",4))
{ {
tlog1 << "Error: wrong save format!\n"; tlog1 << "Error: wrong save format! (file " << fname << " )\n";
delete sfile; delete sfile;
sfile = NULL; sfile = NULL;
return; return;
@ -225,7 +225,7 @@ CLoadFile::CLoadFile( const std::string &fname )
*this >> myVersion; *this >> myVersion;
if(myVersion != version) if(myVersion != version)
{ {
tlog1 << "Wrong save format!\n"; tlog1 << "Wrong save format! (file " << fname << " )\n";
delete sfile; delete sfile;
sfile = NULL; sfile = NULL;
} }