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

* next part of exchange window

* corrected typo in constructors of CSndHandler and CVidHandler causing compilation errors under MSVC
This commit is contained in:
mateuszb 2009-06-19 12:10:36 +00:00
parent 7bb09341a0
commit d2003d59c7
5 changed files with 200 additions and 97 deletions

View File

@ -67,18 +67,14 @@ CHeroWindow::CHeroWindow(int playerColor):
gar2button = new CHighlightableButton(0, 0, map_list_of(0,CGI->generaltexth->heroscrn[26])(3,CGI->generaltexth->heroscrn[25]), CGI->generaltexth->heroscrn[31], false, "hsbtns8.def", NULL, pos.x+604, pos.y+491, SDLK_b);
gar4button = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::function<void()>(), pos.x+604, pos.y+527, "hsbtns9.def", false, NULL, false);
boost::algorithm::replace_first(gar4button->hoverTexts[0],"%s",CGI->generaltexth->allTexts[43]);
leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::scrollBackpack,this,-1), pos.x+379, pos.y+364, "hsbtns3.def", SDLK_LEFT);
rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::scrollBackpack,this,+1), pos.x+632, pos.y+364, "hsbtns5.def", SDLK_RIGHT);
//right list of heroes
for(int g=0; g<8; ++g)
{
//heroList.push_back(new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::switchHero, 677, 95+g*54, "hsbtns5.def", this));
heroListMi.push_back(new LClickableAreaHero());
heroListMi[g]->pos.x = pos.x+677;
heroListMi[g]->pos.y = pos.y + 95+g*54;
heroListMi[g]->pos.h = 32;
heroListMi[g]->pos.w = 48;
heroListMi[g]->pos = genRect(32, 48, pos.x+677, pos.y + 95+g*54);
heroListMi[g]->owner = this;
heroListMi[g]->id = g;
}
@ -87,27 +83,19 @@ CHeroWindow::CHeroWindow(int playerColor):
flags = CDefHandler::giveDefEss("CREST58.DEF");
//areas
portraitArea = new LRClickableAreaWText();
portraitArea->pos.x = pos.x+83;
portraitArea->pos.y = pos.y + 26;
portraitArea->pos.w = 58;
portraitArea->pos.h = 64;
portraitArea->pos = genRect(64, 58, pos.x+83, pos.y + 26);
for(int v=0; v<4; ++v)
{
primSkillAreas.push_back(new LRClickableAreaWTextComp());
primSkillAreas[v]->pos.x = pos.x+95 + 70*v;
primSkillAreas[v]->pos.y = pos.y + 111;
primSkillAreas[v]->pos.w = 42;
primSkillAreas[v]->pos.h = 42;
primSkillAreas[v]->pos = genRect(42, 42, pos.x+95 + 70*v, pos.y + 111);
primSkillAreas[v]->text = CGI->generaltexth->arraytxt[2+v];
primSkillAreas[v]->type = v;
primSkillAreas[v]->bonus = -1; // to be initilized when hero is being set
primSkillAreas[v]->baseType = 0;
}
expArea = new LRClickableAreaWText();
expArea->pos.x = pos.x+83;
expArea->pos.y = pos.y + 236;
expArea->pos.w = 136;
expArea->pos.h = 42;
expArea->pos = genRect(42, 136, pos.x+83, pos.y + 236);
expArea->hoverText = CGI->generaltexth->heroscrn[9];
morale = new LRClickableAreaWTextComp();
@ -117,19 +105,13 @@ CHeroWindow::CHeroWindow(int playerColor):
luck->pos = genRect(45,53,pos.x+298,pos.y+187);
spellPointsArea = new LRClickableAreaWText();
spellPointsArea->pos.x = pos.x+227;
spellPointsArea->pos.y = pos.y + 236;
spellPointsArea->pos.w = 136;
spellPointsArea->pos.h = 42;
spellPointsArea->pos = genRect(42, 136, pos.x+227, pos.y + 236);
spellPointsArea->hoverText = CGI->generaltexth->heroscrn[22];
for(int i=0; i<8; ++i)
{
secSkillAreas.push_back(new LRClickableAreaWTextComp());
secSkillAreas[i]->pos.x = pos.x + ((i%2==0) ? (83) : (227));
secSkillAreas[i]->pos.y = pos.y + (284 + 48 * (i/2));
secSkillAreas[i]->pos.w = 136;
secSkillAreas[i]->pos.h = 42;
secSkillAreas[i]->pos = genRect(42, 136, pos.x + ((i%2==0) ? (83) : (227)), pos.y + (284 + 48 * (i/2)));
secSkillAreas[i]->baseType = 1;
}
pos.x += 65;
@ -145,8 +127,6 @@ CHeroWindow::~CHeroWindow()
delete formations;
delete gar2button;
delete gar4button;
delete leftArtRoll;
delete rightArtRoll;
for(size_t g=0; g<heroListMi.size(); ++g)
{
@ -190,8 +170,6 @@ void CHeroWindow::show(SDL_Surface *to)
formations->show(to);
gar2button->show(to);
gar4button->show(to);
leftArtRoll->show(to);
rightArtRoll->show(to);
garr->show(to);
ourBar->show(to);
@ -199,10 +177,10 @@ void CHeroWindow::show(SDL_Surface *to)
artifs->show(to);
}
void CHeroWindow::setHero(const CGHeroInstance *Hero)
void CHeroWindow::setHero(const CGHeroInstance *hero)
{
char bufor[400];
CGHeroInstance *hero = const_cast<CGHeroInstance*>(Hero); //but don't modify hero! - it's only for easy map reading
//CGHeroInstance *hero = const_cast<CGHeroInstance*>(Hero); //but don't modify hero! - it's only for easy map reading
if(!hero) //something strange... no hero? it shouldn't happen
{
return;
@ -229,10 +207,12 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
garr->update = false;
gar4button->callback = boost::bind(&CGarrisonInt::splitClick,garr);//actualization of callback function
//primary skills support
for(size_t g=0; g<primSkillAreas.size(); ++g)
{
primSkillAreas[g]->bonus = hero->getPrimSkillLevel(g);
}
//secondary skills support
for(size_t g=0; g<hero->secSkills.size(); ++g)
{
secSkillAreas[g]->type = hero->secSkills[g].first;
@ -244,17 +224,17 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
secSkillAreas[g]->hoverText = std::string(bufor);
}
//printing experience
sprintf(bufor, CGI->generaltexth->allTexts[2].c_str(), hero->level, CGI->heroh->reqExp(hero->level+1), hero->exp);
expArea->text = std::string(bufor);
//printing spell points
sprintf(bufor, CGI->generaltexth->allTexts[205].c_str(), hero->name.c_str(), hero->mana, hero->manaLimit());
spellPointsArea->text = std::string(bufor);
artifs->setHero(Hero);
artifs->setHero(hero);
dismissButton->block(!!hero->visitedTown);
leftArtRoll->block(hero->artifacts.size()<6);
rightArtRoll->block(hero->artifacts.size()<6);
if(hero->getSecSkillLevel(19)==0)
gar2button->block(true);
else
@ -264,10 +244,12 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
gar2button->callback2 = vstd::assigno(hero->tacticFormationEnabled,false);
}
//setting formations
formations->onChange = 0;
formations->select(hero->army.formation,true);
formations->onChange = boost::bind(&CCallback::setFormation, LOCPLINT->cb, Hero, _1);
formations->onChange = boost::bind(&CCallback::setFormation, LOCPLINT->cb, hero, _1);
//setting morale
std::vector<std::pair<int,std::string> > mrl = hero->getCurrentMoraleModifiers();
int mrlv = hero->getCurrentMorale();
int mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad morale, 0 - neutral, 1 - good
@ -279,6 +261,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
for(int it=0; it < mrl.size(); it++)
morale->text += mrl[it].second;
//setting luck
mrl = hero->getCurrentLuckModifiers();
mrlv = hero->getCurrentLuck();
mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad luck, 0 - neutral, 1 - good
@ -290,6 +273,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
for(int it=0; it < mrl.size(); it++)
luck->text += mrl[it].second;
//restoring pos
pos.x += 65;
pos.y += 8;
@ -310,8 +294,6 @@ void CHeroWindow::activate()
gar2button->activate();
formations->activate();
gar4button->activate();
leftArtRoll->activate();
rightArtRoll->activate();
portraitArea->activate();
expArea->activate();
spellPointsArea->activate();
@ -347,8 +329,6 @@ void CHeroWindow::deactivate()
gar2button->deactivate();
formations->deactivate();
gar4button->deactivate();
leftArtRoll->deactivate();
rightArtRoll->deactivate();
portraitArea->deactivate();
expArea->deactivate();
spellPointsArea->deactivate();
@ -385,11 +365,6 @@ void CHeroWindow::questlog()
{
}
void CHeroWindow::scrollBackpack(int dir)
{
artifs->scrollBackpack(dir);
}
void CHeroWindow::redrawCurBack()
{
if(curBack)

View File

@ -51,14 +51,14 @@ class CHeroWindow: public CWindowWithGarrison, public virtual CIntObject
std::vector<LRClickableAreaWTextComp *> secSkillAreas;
public:
const CGHeroInstance * curHero;
AdventureMapButton * quitButton, * dismissButton, * questlogButton, //general
* leftArtRoll, * rightArtRoll;
AdventureMapButton * quitButton, * dismissButton, * questlogButton; //general
CHighlightableButton *gar2button; //garrison / formation handling;
CHighlightableButtonsGroup *formations;
int player;
CHeroWindow(int playerColor); //c-tor
~CHeroWindow(); //d-tor
void setHero(const CGHeroInstance * Hero); //sets main displayed hero
void setHero(const CGHeroInstance * hero); //sets main displayed hero
void activate(); //activates hero window;
void deactivate(); //activates hero window;
virtual void show(SDL_Surface * to); //shows hero window
@ -67,7 +67,6 @@ public:
void quit(); //stops displaying hero window and disposes
void dismissCurrent(); //dissmissed currently displayed hero (curHero)
void questlog(); //show quest log in hero window
void scrollBackpack(int dir); //dir==-1 => to left; dir==-2 => to right
void switchHero(); //changes displayed hero
//friends

View File

@ -3449,6 +3449,9 @@ void CArtifactsOfHero::activate()
if(backpack[f])
backpack[f]->activate();
}
leftArtRoll->activate();
rightArtRoll->activate();
}
void CArtifactsOfHero::deactivate()
@ -3463,6 +3466,9 @@ void CArtifactsOfHero::deactivate()
if(backpack[f])
backpack[f]->deactivate();
}
leftArtRoll->deactivate();
rightArtRoll->deactivate();
}
void CArtifactsOfHero::show(SDL_Surface * to)
@ -3475,6 +3481,9 @@ void CArtifactsOfHero::show(SDL_Surface * to)
{
backpack[d]->show(to);
}
leftArtRoll->show(to);
rightArtRoll->show(to);
}
void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
@ -3556,6 +3565,10 @@ void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
backpack.push_back(add);
}
activeArtPlace = NULL;
//blocking scrolling if there is not enough artifacts to scroll
leftArtRoll->block(hero->artifacts.size()<6);
rightArtRoll->block(hero->artifacts.size()<6);
}
void CArtifactsOfHero::dispose()
@ -3598,20 +3611,18 @@ CArtifactsOfHero::CArtifactsOfHero(const SDL_Rect & position) :
{
pos = position;
artWorn.resize(19);
leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CArtifactsOfHero::scrollBackpack,this,-1), pos.x+379, pos.y+364, "hsbtns3.def", SDLK_LEFT);
rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CArtifactsOfHero::scrollBackpack,this,+1), pos.x+632, pos.y+364, "hsbtns5.def", SDLK_RIGHT);
}
CArtifactsOfHero::~CArtifactsOfHero()
{
for(size_t g=0; g<artWorn.size(); ++g)
{
delete artWorn[g];
}
dispose();
artWorn.clear();
for(size_t g=0; g<backpack.size(); ++g)
{
delete backpack[g];
}
backpack.clear();
delete leftArtRoll;
delete rightArtRoll;
}
void CExchangeWindow::close()
@ -3623,16 +3634,54 @@ void CExchangeWindow::activate()
{
quit->activate();
art1->activate();
art2->activate();
artifs[0]->activate();
artifs[1]->activate();
for(int g=0; g<ARRAY_COUNT(secSkillAreas); g++)
{
for(int b=0; b<secSkillAreas[g].size(); ++b)
{
secSkillAreas[g][b]->activate();
}
}
for(int b=0; b<primSkillAreas.size(); ++b)
{
primSkillAreas[b]->activate();
}
LOCPLINT->statusbar = ourBar;
for(int g=0; g<ARRAY_COUNT(questlogButton); g++)
{
questlogButton[g]->activate();
}
}
void CExchangeWindow::deactivate()
{
quit->deactivate();
art1->deactivate();
art2->deactivate();
artifs[0]->deactivate();
artifs[1]->deactivate();
for(int g=0; g<ARRAY_COUNT(secSkillAreas); g++)
{
for(int b=0; b<secSkillAreas[g].size(); ++b)
{
secSkillAreas[g][b]->deactivate();
}
}
for(int b=0; b<primSkillAreas.size(); ++b)
{
primSkillAreas[b]->deactivate();
}
for(int g=0; g<ARRAY_COUNT(questlogButton); g++)
{
questlogButton[g]->deactivate();
}
}
void CExchangeWindow::show(SDL_Surface * to)
@ -3645,79 +3694,149 @@ void CExchangeWindow::show(SDL_Surface * to)
if(screen->w != 800 || screen->h !=600)
CMessage::drawBorder(LOCPLINT->playerID,to,828,628,pos.x-14,pos.y-15);
art1->show(to);
art2->show(to);
artifs[0]->show(to);
artifs[1]->show(to);
ourBar->show(to);
for(int g=0; g<ARRAY_COUNT(secSkillAreas); g++)
{
questlogButton[g]->show(to);
}
}
void CExchangeWindow::questlog(int whichHero)
{
}
CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) //c-tor
{
hero1inst = LOCPLINT->cb->getHeroInfo(hero1, 2);
hero2inst = LOCPLINT->cb->getHeroInfo(hero2, 2);
char bufor[400];
art1 = new CArtifactsOfHero(genRect(600, 800, -334, 150));
art1->setHero(hero1inst);
art2 = new CArtifactsOfHero(genRect(600, 800, 96, 150));
art2->setHero(hero2inst);
heroInst[0] = LOCPLINT->cb->getHeroInfo(hero1, 2);
heroInst[1] = LOCPLINT->cb->getHeroInfo(hero2, 2);
artifs[0] = new CArtifactsOfHero(genRect(600, 800, -334, 150));
artifs[0]->setHero(heroInst[0]);
artifs[1] = new CArtifactsOfHero(genRect(600, 800, 96, 150));
artifs[1]->setHero(heroInst[1]);
SDL_Surface * bgtemp; //loaded as 8bpp surface
bgtemp = BitmapHandler::loadBitmap("TRADE2.BMP");
graphics->blueToPlayersAdv(bgtemp, hero1inst->tempOwner);
graphics->blueToPlayersAdv(bgtemp, heroInst[0]->tempOwner);
bg = SDL_ConvertSurface(bgtemp, screen->format, screen->flags); //to 24 bpp
SDL_FreeSurface(bgtemp);
//printing heroes' names and levels
std::ostringstream os, os2;
os<<hero1inst->name<<", Level "<<hero1inst->level<<" "<<hero1inst->type->heroClass->name;
os<<heroInst[0]->name<<", Level "<<heroInst[0]->level<<" "<<heroInst[0]->type->heroClass->name;
CSDL_Ext::printAtMiddle(os.str(), 147, 23, GEOR13, zwykly, bg);
os2<<hero2inst->name<<", Level "<<hero2inst->level<<" "<<hero2inst->type->heroClass->name;
os2<<heroInst[1]->name<<", Level "<<heroInst[1]->level<<" "<<heroInst[1]->type->heroClass->name;
CSDL_Ext::printAtMiddle(os2.str(), 653, 23, GEOR13, zwykly, bg);
//printing primary skills' graphics
//printing primary skills
CDefHandler * skilldef = CDefHandler::giveDef("PSKIL32.DEF");
for(int g=0; g<4; ++g)
{
//graphics
blitAt(skilldef->ourImages[g].bitmap, genRect(32, 32, 385, 19 + 36 * g), bg);
//primary skill's clickable areas
primSkillAreas.push_back(new LRClickableAreaWTextComp());
primSkillAreas[g]->pos = genRect(32, 32, pos.x+385, pos.y + 19 + 36 * g);
primSkillAreas[g]->text = CGI->generaltexth->arraytxt[2+g];
primSkillAreas[g]->type = g;
primSkillAreas[g]->bonus = -1;
primSkillAreas[g]->baseType = 0;
}
delete skilldef;
const CGHeroInstance * curHero = NULL;
for(int b=0; b<2; ++b)
CDefHandler * un32 = CDefHandler::giveDef("UN32.DEF");
//heroes related thing
for(int b=0; b<ARRAY_COUNT(heroInst); b++)
{
//choosing hero
if(b == 0)
curHero = hero1inst;
else if(b == 1)
curHero = hero2inst;
//printing primary skills' amounts
for(int m=0; m<4; ++m)
{
std::ostringstream primarySkill;
primarySkill<<curHero->getPrimSkillLevel(m);
primarySkill<<heroInst[b]->getPrimSkillLevel(m);
CSDL_Ext::printAtMiddle(primarySkill.str(), 353 + 93 * b, 35 + 36 * m, TNRB16, zwykly, bg);
}
//printing secondary skills
for(int m=0; m<curHero->secSkills.size(); ++m)
for(int m=0; m<heroInst[b]->secSkills.size(); ++m)
{
blitAt(graphics->abils32->ourImages[curHero->secSkills[m].first * 3 + curHero->secSkills[m].second + 2].bitmap, genRect(32, 32, 32 + 36 * m + 454 * b, 88), bg);
blitAt(graphics->abils32->ourImages[heroInst[b]->secSkills[m].first * 3 + heroInst[b]->secSkills[m].second + 2].bitmap, genRect(32, 32, pos.x + 32 + 36 * m + 454 * b, pos.y + 88), bg);
}
//secondary skill's clickable areas
for(int g=0; g<heroInst[b]->secSkills.size(); ++g)
{
secSkillAreas[b].push_back(new LRClickableAreaWTextComp());
secSkillAreas[b][g]->pos = genRect(32, 32, pos.x + 32 + g*36 + b*454 , pos.y + 88);
secSkillAreas[b][g]->baseType = 1;
secSkillAreas[b][g]->type = heroInst[b]->secSkills[g].first;
secSkillAreas[b][g]->bonus = heroInst[b]->secSkills[g].second;
std::string hlp = CGI->generaltexth->skillInfoTexts[ heroInst[b]->secSkills[g].first ][heroInst[b]->secSkills[g].second-1];
secSkillAreas[b][g]->text = hlp.substr(1, hlp.size()-2);
sprintf(bufor, CGI->generaltexth->heroscrn[21].c_str(), CGI->generaltexth->levels[heroInst[b]->secSkills[g].second-1].c_str(), CGI->generaltexth->skillName[heroInst[b]->secSkills[g].first].c_str());
secSkillAreas[b][g]->hoverText = std::string(bufor);
}
//hero's specialty
blitAt(un32->ourImages[heroInst[b]->subID].bitmap, 67 + 490*b, 45, bg);
//experience
blitAt(skilldef->ourImages[4].bitmap, 103 + 490*b, 45, bg);
//mana points
blitAt(skilldef->ourImages[5].bitmap, 139 + 490*b, 45, bg);
}
//printing portraits
blitAt(graphics->portraitLarge[hero1inst->portrait], 257, 13, bg);
blitAt(graphics->portraitLarge[hero2inst->portrait], 485, 13, bg);
blitAt(graphics->portraitLarge[heroInst[0]->portrait], 257, 13, bg);
blitAt(graphics->portraitLarge[heroInst[1]->portrait], 485, 13, bg);
//buttons
quit = new AdventureMapButton(CGI->generaltexth->tcommands[8], "", boost::bind(&CExchangeWindow::close, this), pos.x+732, pos.y+567, "IOKAY.DEF", SDLK_RETURN);
questlogButton[0] = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CExchangeWindow::questlog,this, 0), pos.x+10, pos.y+44, "hsbtns4.def");
questlogButton[1] = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CExchangeWindow::questlog,this, 1), pos.x+740, pos.y+44, "hsbtns4.def");
//statusbar
ourBar = new CStatusBar(pos.x + 3, pos.y + 577, "TSTATBAR.bmp", 726);
delete un32;
delete skilldef;
}
CExchangeWindow::~CExchangeWindow() //d-tor
{
SDL_FreeSurface(bg);
delete quit;
delete art1;
delete art2;
delete artifs[0];
delete artifs[1];
delete ourBar;
for(int g=0; g<ARRAY_COUNT(secSkillAreas); g++)
{
for(int b=0; b<secSkillAreas[g].size(); ++b)
{
delete secSkillAreas[g][b];
}
}
for(int b=0; b<primSkillAreas.size(); ++b)
{
delete primSkillAreas[b];
}
for(int g=0; g<ARRAY_COUNT(questlogButton); g++)
{
delete questlogButton[g];
}
}

View File

@ -637,6 +637,9 @@ class CArtifactsOfHero : public IShowActivable, public CIntObject
CArtPlace * activeArtPlace;
public:
AdventureMapButton * leftArtRoll, * rightArtRoll;
void activate();
void deactivate();
void show(SDL_Surface * to);
@ -667,18 +670,25 @@ public:
class CExchangeWindow : public CIntObject, public IShowActivable
{
public:
SDL_Surface *bg; //background
AdventureMapButton *quit;
CStatusBar * ourBar; //internal statusbar
const CGHeroInstance *hero1inst, *hero2inst;
CArtifactsOfHero * art1, * art2;
SDL_Surface *bg; //background
AdventureMapButton * quit, * questlogButton[2];
const CGHeroInstance * heroInst[2];
CArtifactsOfHero * artifs[2];
std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
public:
void close();
void activate();
void deactivate();
void show(SDL_Surface * to);
void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
CExchangeWindow(si32 hero1, si32 hero2); //c-tor
~CExchangeWindow(); //d-tor
};

View File

@ -125,7 +125,7 @@ const char * CMediaHandler::extract (std::string srcName, int &size)
return NULL;
}
CSndHandler::CSndHandler(std::string fname) : CMediaHandler::CMediaHandler(fname)
CSndHandler::CSndHandler(std::string fname) : CMediaHandler(fname)
{
const unsigned char *data = (const unsigned char *)mfile->data();
@ -165,7 +165,7 @@ CSndHandler::CSndHandler(std::string fname) : CMediaHandler::CMediaHandler(fname
}
}
CVidHandler::CVidHandler(std::string fname) : CMediaHandler::CMediaHandler(fname)
CVidHandler::CVidHandler(std::string fname) : CMediaHandler(fname)
{
const unsigned char *data = (const unsigned char *)mfile->data();