From 09192359487dd04c5cc7f58f8187ade75bd5cd21 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Fri, 26 Jun 2009 15:41:19 +0000 Subject: [PATCH] * next part of hero exchange window * minor changes --- client/CHeroWindow.cpp | 3 +- client/GUIClasses.cpp | 64 +++++++++++++++++++++++++++++++++++++++ client/GUIClasses.h | 2 ++ client/SDL_Extensions.cpp | 10 ++++++ client/SDL_Extensions.h | 43 ++++++++++++++++++++++++++ hch/CLodHandler.h | 3 +- lib/Connection.cpp | 4 +-- 7 files changed, 125 insertions(+), 4 deletions(-) diff --git a/client/CHeroWindow.cpp b/client/CHeroWindow.cpp index 72c28716e..4a33dcf89 100644 --- a/client/CHeroWindow.cpp +++ b/client/CHeroWindow.cpp @@ -371,7 +371,7 @@ void CHeroWindow::redrawCurBack() SDL_FreeSurface(curBack); 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[1].bitmap, 102, 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); } + //morale and luck printing blitAt(graphics->luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack); blitAt(graphics->morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack); diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 9f713ceb5..1a4ad5dca 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -3670,6 +3670,16 @@ void CExchangeWindow::activate() { questlogButton[g]->activate(); } + + for(int g=0; gactivate(); + } + + for(int g=0; gactivate(); + } } void CExchangeWindow::deactivate() @@ -3696,6 +3706,16 @@ void CExchangeWindow::deactivate() { questlogButton[g]->deactivate(); } + + for(int g=0; gdeactivate(); + } + + for(int g=0; gdeactivate(); + } } void CExchangeWindow::show(SDL_Surface * to) @@ -3803,9 +3823,43 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) //c-tor //experience blitAt(skilldef->ourImages[4].bitmap, 103 + 490*b, 45, bg); + printAtMiddle( makeNumberShort(heroInst[b]->exp), 119 + 490*b, 71, GEOR13, zwykly, bg ); //mana points 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 > 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 @@ -3851,6 +3905,16 @@ CExchangeWindow::~CExchangeWindow() //d-tor { delete questlogButton[g]; } + + for(int g=0; g secSkillAreas[2], primSkillAreas; + LRClickableAreaWTextComp *morale[2], *luck[2]; + public: void close(); diff --git a/client/SDL_Extensions.cpp b/client/SDL_Extensions.cpp index 3d2e169d8..4b8a8fd80 100644 --- a/client/SDL_Extensions.cpp +++ b/client/SDL_Extensions.cpp @@ -31,6 +31,7 @@ SDL_Surface * CSDL_Ext::copySurface(SDL_Surface * mod) //returns copy of given s //return SDL_DisplayFormat(mod); return SDL_ConvertSurface(mod, mod->format, mod->flags); } + bool isItIn(const SDL_Rect * rect, int x, int y) { if ((x>rect->x && xx+rect->w) && (y>rect->y && yy+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_UpdateRect(dst,x,y,src->w,src->h); } + void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst) { if(!dst) dst = screen; SDL_Rect pom = genRect(src->h,src->w,x,y); SDL_BlitSurface(src,NULL,dst,&pom); } + void blitAtWR(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst) { blitAtWR(src,pos.x,pos.y,dst); } + void blitAt(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst) { blitAt(src,pos.x,pos.y,dst); } + SDL_Color genRGB(int r, int g, int b, int a=0) { SDL_Color ret; @@ -67,10 +72,12 @@ SDL_Color genRGB(int r, int g, int b, int a=0) ret.unused=a; return ret; } + void updateRect (SDL_Rect * rect, SDL_Surface * scr) { 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) { std::vector * 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]); 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) { std::vector * 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]); 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) { 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_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) { if (text.length()==0) diff --git a/client/SDL_Extensions.h b/client/SDL_Extensions.h index 0c9c86422..ec73c6bce 100644 --- a/client/SDL_Extensions.h +++ b/client/SDL_Extensions.h @@ -5,6 +5,8 @@ #include #include "../int3.h" #include +#include +#include /* * 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); bool isItIn(const SDL_Rect * rect, int x, int y); +template +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::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< 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) { SDL_Rect ret; diff --git a/hch/CLodHandler.h b/hch/CLodHandler.h index b0745f604..582933c87 100644 --- a/hch/CLodHandler.h +++ b/hch/CLodHandler.h @@ -49,7 +49,8 @@ struct Entry //Entry(unsigned char ): nameStr(con){}; Entry(){}; }; - class DLL_EXPORT CLodHandler + +class DLL_EXPORT CLodHandler { public: FILE* FLOD; diff --git a/lib/Connection.cpp b/lib/Connection.cpp index ca514b0e6..20a514d69 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -216,7 +216,7 @@ CLoadFile::CLoadFile( const std::string &fname ) if(std::memcmp(buffer,"VCMI",4)) { - tlog1 << "Error: wrong save format!\n"; + tlog1 << "Error: wrong save format! (file " << fname << " )\n"; delete sfile; sfile = NULL; return; @@ -225,7 +225,7 @@ CLoadFile::CLoadFile( const std::string &fname ) *this >> myVersion; if(myVersion != version) { - tlog1 << "Wrong save format!\n"; + tlog1 << "Wrong save format! (file " << fname << " )\n"; delete sfile; sfile = NULL; }