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

* fixed a few problems with refreshing screen during blitting using CSDL_Ext::printAtMiddle

* fixed drawbacks in displaying secondary skills in hero window
* fixed two bugs with spellBook
* corrected order of spells in spellBook
* spellBook is opened when hero in battle is left-clicked
This commit is contained in:
mateuszb 2008-09-16 15:23:44 +00:00
parent cc1b5f37cd
commit c5c9127673
7 changed files with 108 additions and 39 deletions

View File

@ -101,7 +101,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
//loading hero animations
if(hero1) // attacking hero
{
attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner);
attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner, hero1->tempOwner == LOCPLINT->playerID ? hero1 : NULL);
attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0);
}
else
@ -110,7 +110,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
}
if(hero2) // defending hero
{
defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner);
defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner, hero2->tempOwner == LOCPLINT->playerID ? hero2 : NULL);
defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0);
}
else
@ -243,6 +243,10 @@ void CBattleInterface::activate()
{
bfield[b].activate();
}
if(attackingHero)
attackingHero->activate();
if(defendingHero)
defendingHero->activate();
}
void CBattleInterface::deactivate()
@ -260,6 +264,10 @@ void CBattleInterface::deactivate()
{
bfield[b].deactivate();
}
if(attackingHero)
attackingHero->deactivate();
if(defendingHero)
defendingHero->deactivate();
}
void CBattleInterface::show(SDL_Surface * to)
@ -1311,7 +1319,28 @@ void CBattleHero::show(SDL_Surface *to)
}
}
CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG, unsigned char player): phase(phaseG), image(imageG), flip(flipG), flagAnim(0)
void CBattleHero::activate()
{
ClickableL::activate();
}
void CBattleHero::deactivate()
{
ClickableL::deactivate();
}
void CBattleHero::clickLeft(boost::logic::tribool down)
{
if(!down && myHero)
{
CGI->curh->changeGraphic(0,0);
LOCPLINT->curint->deactivate();
CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), myHero);
spellWindow->activate();
LOCPLINT->objsToBlit.push_back(spellWindow);
}
}
CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG, unsigned char player, const CGHeroInstance * hero): phase(phaseG), image(imageG), flip(flipG), flagAnim(0), myHero(hero)
{
dh = CDefHandler::giveDef( defName );
for(int i=0; i<dh->ourImages.size(); ++i) //transforming images

View File

@ -12,16 +12,20 @@ class AdventureMapButton;
struct BattleResult;
template <typename T> struct CondSh;
class CBattleHero : public IShowable, public CIntObject
class CBattleHero : public IShowable, public ClickableL
{
public:
bool flip; //false if it's attacking hero, true otherwise
CDefHandler * dh, *flag; //animation and flag
const CGHeroInstance * myHero; //this animation's hero instance
int phase; //stage of animation
int image; //frame of animation
unsigned char flagAnim, flagAnimCount; //for flag animation
void show(SDL_Surface * to); //prints next frame of animation to to
CBattleHero(std::string defName, int phaseG, int imageG, bool filpG, unsigned char player); //c-tor
void activate();
void deactivate();
void clickLeft(boost::logic::tribool down);
CBattleHero(std::string defName, int phaseG, int imageG, bool filpG, unsigned char player, const CGHeroInstance * hero); //c-tor
~CBattleHero(); //d-tor
};

View File

@ -225,12 +225,12 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
for(int g=0; g<hero->secSkills.size(); ++g)
{
secSkillAreas[g]->type = hero->secSkills[g].first;
secSkillAreas[g]->bonus = hero->secSkills[g].second;
secSkillAreas[g]->bonus = hero->secSkills[g].second-1;
std::string hlp = CGI->abilh->abilities[ hero->secSkills[g].first ]->infoTexts[hero->secSkills[g].second-1];
secSkillAreas[g]->text = hlp.substr(1, hlp.size()-2);
char * hlpp = new char[200];
sprintf(hlpp, CGI->generaltexth->heroscrn[21].c_str(), CGI->abilh->levels[hero->secSkills[g].second].c_str(), CGI->abilh->abilities[hero->secSkills[g].first]->name.c_str());
sprintf(hlpp, CGI->generaltexth->heroscrn[21].c_str(), CGI->abilh->levels[hero->secSkills[g].second-1].c_str(), CGI->abilh->abilities[hero->secSkills[g].first]->name.c_str());
secSkillAreas[g]->hoverText = std::string(hlpp);
delete [] hlpp;
}
@ -256,7 +256,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
std::vector<SDL_Rect> slotPos;
slotPos += genRect(44,44,509,30), genRect(44,44,567,240), genRect(44,44,509,30), genRect(44,44,383,68),
slotPos += genRect(44,44,509,30), genRect(44,44,567,240), genRect(44,44,509,80), genRect(44,44,383,68),
genRect(44,44,564,183), genRect(44,44,509,130), genRect(44,44,431,68), genRect(44,44,610,183),
genRect(44,44,515,295), genRect(44,44,383,143), genRect(44,44,399,194), genRect(44,44,415,245),
genRect(44,44,431,296), genRect(44,44,564,30), genRect(44,44,610,30), genRect(44,44,610,76),
@ -597,50 +597,50 @@ void CHeroWindow::redrawCurBack()
//secondary skills
if(curHero->secSkills.size()>=1)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[0].first*3+3+curHero->secSkills[0].second].bitmap, 18, 276, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[0].second], 69, 279, GEOR13, zwykly, curBack);
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[0].first*3+3+curHero->secSkills[0].second-1].bitmap, 18, 276, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[0].second-1], 69, 279, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[0].first]->name, 69, 299, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=2)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[1].first*3+3+curHero->secSkills[1].second].bitmap, 161, 276, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[1].second], 213, 279, GEOR13, zwykly, curBack);
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[1].first*3+3+curHero->secSkills[1].second-1].bitmap, 161, 276, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[1].second-1], 213, 279, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[1].first]->name, 213, 299, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=3)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[2].first*3+3+curHero->secSkills[2].second].bitmap, 18, 324, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[2].second], 69, 327, GEOR13, zwykly, curBack);
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[2].first*3+3+curHero->secSkills[2].second-1].bitmap, 18, 324, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[2].second-1], 69, 327, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[2].first]->name, 69, 347, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=4)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[3].first*3+3+curHero->secSkills[3].second].bitmap, 161, 324, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[3].second], 213, 327, GEOR13, zwykly, curBack);
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[3].first*3+3+curHero->secSkills[3].second-1].bitmap, 161, 324, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[3].second-1], 213, 327, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[3].first]->name, 213, 347, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=5)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[4].first*3+3+curHero->secSkills[4].second].bitmap, 18, 372, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[4].second], 69, 375, GEOR13, zwykly, curBack);
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[4].first*3+3+curHero->secSkills[4].second-1].bitmap, 18, 372, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[4].second-1], 69, 375, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[4].first]->name, 69, 395, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=6)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[5].first*3+3+curHero->secSkills[5].second].bitmap, 161, 372, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[5].second], 213, 375, GEOR13, zwykly, curBack);
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[5].first*3+3+curHero->secSkills[5].second-1].bitmap, 161, 372, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[5].second-1], 213, 375, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[5].first]->name, 213, 395, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=7)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[6].first*3+3+curHero->secSkills[6].second].bitmap, 18, 420, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[6].second], 69, 423, GEOR13, zwykly, curBack);
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[6].first*3+3+curHero->secSkills[6].second-1].bitmap, 18, 420, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[6].second-1], 69, 423, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[6].first]->name, 69, 443, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=8)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[7].first*3+3+curHero->secSkills[7].second].bitmap, 161, 420, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[7].second], 213, 423, GEOR13, zwykly, curBack);
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[7].first*3+3+curHero->secSkills[7].second-1].bitmap, 161, 420, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[7].second-1], 213, 423, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[7].first]->name, 213, 443, GEOR13, zwykly, curBack);
}

View File

@ -259,7 +259,7 @@ void CGarrisonSlot::show()
char* buf = new char[15];
SDL_itoa(count,buf,10);
blitAt(graphics->bigImgs[creature->idNumber],pos);
printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly);
printToWR(buf,pos.x+56,pos.y+62,GEOR16,zwykly);
if(owner->highlighted==this)
blitAt(graphics->bigImgs[-1],pos);
//if(owner->update)

View File

@ -116,7 +116,7 @@ void CSDL_Ext::printAtWB(std::string text, int x, int y, TTF_Font * font, int ch
SDL_FreeSurface(wesu[i]);
delete ws;
}
void CSDL_Ext::printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
void CSDL_Ext::printAtMiddle(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;
SDL_Surface * temp;
@ -141,7 +141,8 @@ void CSDL_Ext::printAtMiddle(std::string text, int x, int y, TTF_Font * font, SD
break;
}
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x-(temp->w/2),y-(temp->h/2)));
//SDL_UpdateRect(dst,x-(temp->w/2),y-(temp->h/2),temp->w,temp->h);
if(refresh)
SDL_UpdateRect(dst,x-(temp->w/2),y-(temp->h/2),temp->w,temp->h);
SDL_FreeSurface(temp);
}
void CSDL_Ext::printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
@ -170,7 +171,7 @@ void CSDL_Ext::printAt(std::string text, int x, int y, TTF_Font * font, SDL_Colo
break;
}
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x,y));
//SDL_UpdateRect(dst,x,y,temp->w,temp->h);
SDL_UpdateRect(dst,x,y,temp->w,temp->h);
SDL_FreeSurface(temp);
}
void CSDL_Ext::printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
@ -199,7 +200,7 @@ void CSDL_Ext::printTo(std::string text, int x, int y, TTF_Font * font, SDL_Colo
break;
}
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x-temp->w,y-temp->h));
//SDL_UpdateRect(dst,x-temp->w,y-temp->h,temp->w,temp->h);
SDL_UpdateRect(dst,x-temp->w,y-temp->h,temp->w,temp->h);
SDL_FreeSurface(temp);
}

View File

@ -38,7 +38,7 @@ namespace CSDL_Ext
Uint32 colorToUint32(const SDL_Color * color); //little endian only
void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
void printToWR(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
void printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
void printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2, bool refresh = false); // quality: 0 - lowest, 1 - medium, 2 - highest
void printAtMiddleWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
void printAtWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest

View File

@ -460,6 +460,37 @@ void CSpellWindow::show(SDL_Surface *to)
}
}
class SpellbookSpellSorter
{
public:
bool operator()(const int & a, const int & b)
{
CSpell A = CGI->spellh->spells[a];
CSpell B = CGI->spellh->spells[b];
if(A.level<B.level)
return true;
if(A.level>B.level)
return false;
if(A.air && !B.air)
return true;
if(!A.air && B.air)
return false;
if(A.fire && !B.fire)
return true;
if(!A.fire && B.fire)
return false;
if(A.water && !B.water)
return true;
if(!A.water && B.water)
return false;
if(A.earth && !B.earth)
return true;
if(!A.earth && B.earth)
return false;
return A.name < B.name;
}
} spellsorter;
void CSpellWindow::computeSpellsPerArea()
{
std::vector<ui32> spellsCurSite;
@ -476,6 +507,7 @@ void CSpellWindow::computeSpellsPerArea()
spellsCurSite.push_back(*it);
}
}
std::sort(spellsCurSite.begin(), spellsCurSite.end(), spellsorter);
if(selectedTab == 4)
{
if(spellsCurSite.size() > 12)
@ -587,7 +619,7 @@ void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down)
void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
{
if(down)
if(down && mySpell != -1)
{
CInfoPopup *vinya = new CInfoPopup();
vinya->free = true;
@ -605,6 +637,8 @@ void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
void CSpellWindow::SpellArea::hover(bool on)
{
Hoverable::hover(on);
if(mySpell != -1)
{
if(on)
{
std::stringstream ss;
@ -616,6 +650,7 @@ void CSpellWindow::SpellArea::hover(bool on)
owner->statusBar->clear();
}
}
}
void CSpellWindow::SpellArea::activate()
{