1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-13 11:40:38 +02:00

Major changes to the GUI. Introduced list of interfaces (listInt) containing pointers to all shown interfaces / windows. Only top layer is active and regularly updated.

Windows should be shown using pushInt and closed with popInt or PopIntTotally (if interface needs to be also deleted).
Some things are not working yet properly, I'll try to fix them ASAP.
This commit is contained in:
Michał W. Urbańczyk 2009-04-14 12:47:09 +00:00
parent 049b4de2b2
commit 985b4930e4
19 changed files with 823 additions and 980 deletions

View File

@ -55,7 +55,7 @@ void AdventureMapButton::clickLeft (tribool down)
state=1;
else
state=0;
show();
show(screen2);
if (actOnDown && down)
{
pressedL=state;
@ -88,7 +88,7 @@ void AdventureMapButton::hover (bool on)
: (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL);
if(name && blocked!=1) //if there is no name, there is nohing to display also
{
if (LOCPLINT->curint == static_cast<CMainInterface*>(LOCPLINT->battleInt)) //for battle buttons
if (LOCPLINT->battleInt) //for battle buttons
{
if(on && LOCPLINT->battleInt->console->alterTxt == "")
{
@ -185,7 +185,7 @@ void AdventureMapButton::block( ui8 on )
blocked = on;
state = 0;
bitmapOffset = on ? 2 : 0;
show();
show(screen2);
}
void CHighlightableButton::select(bool on)
{
@ -210,7 +210,7 @@ void CHighlightableButton::clickLeft( tribool down )
state=1;
else
state = selected ? 3 : 0;
show();
show(screen2);
if (pressedL && (down==false))
{
pressedL=state;
@ -290,9 +290,10 @@ void CHighlightableButtonsGroup::selectionChanged(int to)
}
void CHighlightableButtonsGroup::show(SDL_Surface * to )
{
for(size_t i=0;i<buttons.size(); ++i) {
buttons[i]->show();
}
for(size_t i=0;i<buttons.size(); ++i)
{
buttons[i]->show(to);
}
}
void CSlider::sliderClicked()
@ -321,7 +322,7 @@ void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent)
void CSlider::redrawSlider()
{
slider.show();
slider.show(screen2);
}
void CSlider::moveLeft()
@ -388,9 +389,9 @@ void CSlider::clickLeft (tribool down)
void CSlider::show(SDL_Surface * to)
{
left.show();
right.show();
slider.show();
left.show(to);
right.show(to);
slider.show(to);
}
CSlider::~CSlider()

View File

@ -63,7 +63,7 @@ public:
void deactivate();
void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id
void selectionChanged(int to);
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
};
@ -92,7 +92,7 @@ public:
void block(bool on);
void activate(); // makes button active
void deactivate(); // makes button inactive (but doesn't delete)
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount,
int Value=0, bool Horizontal=true);
~CSlider();

View File

@ -106,7 +106,7 @@ CMinimap::~CMinimap()
SDL_FreeSurface(radar);
SDL_FreeSurface(temps);
}
void CMinimap::draw()
void CMinimap::draw(SDL_Surface * to)
{
int3 mapSizes = LOCPLINT->cb->getMapSize();
//draw terrain
@ -142,8 +142,7 @@ void CMinimap::draw()
int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)mapSizes.x)))*pos.w,
by = (((float)LOCPLINT->adventureInt->position.y)/(((float)mapSizes.y)))*pos.h;
blitAt(radar,bx,by,temps);
blitAt(temps,pos.x,pos.y);
//SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
blitAt(temps,pos.x,pos.y,to);
}
void CMinimap::redraw(int level)// (level==-1) => redraw all levels
{
@ -530,7 +529,7 @@ void CTerrainRect::clickRight(tribool down)
LOCPLINT->current->motion.x-graphics->heroWins[obj->subID]->w,
LOCPLINT->current->motion.y-graphics->heroWins[obj->subID]->h,false
);
ip->activate();
LOCPLINT->pushInt(ip);
break;
}
case TOWNI_TYPE:
@ -544,7 +543,7 @@ void CTerrainRect::clickRight(tribool down)
LOCPLINT->current->motion.x-graphics->townWins[obj->id]->w,
LOCPLINT->current->motion.y-graphics->townWins[obj->id]->h,false
);
ip->activate();
LOCPLINT->pushInt(ip);
break;
}
default:
@ -938,13 +937,13 @@ void CTerrainRect::showPath(const SDL_Rect * extRect)
}
} //for (int i=0;i<currentPath->nodes.size()-1;i++)
}
void CTerrainRect::show()
void CTerrainRect::show(SDL_Surface * to)
{
CGI->mh->terrainRect
(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
&LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
screen, &genRect(pos.h, pos.w, pos.x, pos.y), moveX, moveY, ADVOPT.smoothMove && (moveX != 0 || moveY != 0)
to, &genRect(pos.h, pos.w, pos.x, pos.y), moveX, moveY, ADVOPT.smoothMove && (moveX != 0 || moveY != 0)
);
//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
@ -1018,20 +1017,20 @@ CResDataBar::~CResDataBar()
{
SDL_FreeSurface(bg);
}
void CResDataBar::draw()
void CResDataBar::draw(SDL_Surface * to)
{
blitAt(bg,pos.x,pos.y);
blitAt(bg,pos.x,pos.y,to);
char * buf = new char[15];
for (int i=0;i<7;i++)
{
SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly,to);
}
std::vector<std::string> temp;
SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly,to);
temp.clear();
//updateRect(&pos,screen);
delete[] buf;
@ -1057,7 +1056,7 @@ CInfoBar::~CInfoBar()
delete week3;
delete week4;
}
void CInfoBar::draw(const CGObjectInstance * specific)
void CInfoBar::draw(SDL_Surface * to, const CGObjectInstance * specific)
{
if ((mode>=0) && mode<5)
{
@ -1067,7 +1066,7 @@ void CInfoBar::draw(const CGObjectInstance * specific)
else if (mode==5)
{
mode = -1;
draw(LOCPLINT->adventureInt->selection);
draw(to,LOCPLINT->adventureInt->selection);
}
if (!specific)
specific = LOCPLINT->adventureInt->selection;
@ -1078,20 +1077,14 @@ void CInfoBar::draw(const CGObjectInstance * specific)
if(specific->ID == HEROI_TYPE) //hero
{
if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
blitAt(graphics->heroWins[specific->subID],pos.x,pos.y);
blitAt(graphics->heroWins[specific->subID],pos.x,pos.y,to);
}
else if (specific->ID == TOWNI_TYPE)
{
const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
if(graphics->townWins.find(t->id)!=graphics->townWins.end())
blitAt(graphics->townWins[t->id],pos.x,pos.y);
blitAt(graphics->townWins[t->id],pos.x,pos.y,to);
}
//SDL_Surface * todr = LOCPLINT->infoWin(specific);
//if (!todr)
// return;
//blitAt(todr,pos.x,pos.y);
//SDL_FreeSurface(todr);
}
CDefHandler * CInfoBar::getAnim(int mode)
@ -1193,7 +1186,7 @@ void CInfoBar::tick()
TimeInterested::deactivate();
toNextTick = -1;
mode = 5;
draw();
draw(screen2);
return;
}
toNextTick = 150;
@ -1204,7 +1197,7 @@ void CInfoBar::tick()
TimeInterested::deactivate();
toNextTick = -1;
mode = 5;
draw();
draw(screen2);
}
}
@ -1292,16 +1285,16 @@ void CAdvMapInt::fswitchLevel()
{
position.z--;
underground.curimg=0;
underground.show();
underground.show(screen2);
}
else
{
underground.curimg=1;
position.z++;
underground.show();
underground.show(screen2);
}
updateScreen = true;
minimap.draw();
minimap.draw(screen2);
}
void CAdvMapInt::fshowQuestlog()
{
@ -1325,22 +1318,17 @@ void CAdvMapInt::fshowSpellbok()
if (selection->ID!=HEROI_TYPE) //checking necessary values
return;
LOCPLINT->curint->deactivate();
CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), ((const CGHeroInstance*)LOCPLINT->adventureInt->selection));
spellWindow->activate();
LOCPLINT->objsToBlit.push_back(spellWindow);
LOCPLINT->pushInt(spellWindow);
}
void CAdvMapInt::fadventureOPtions()
{
}
void CAdvMapInt::fsystemOptions()
{
LOCPLINT->curint->deactivate();
CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(genRect(487, 481, 159, 57), LOCPLINT);
sysopWindow->activate();
LOCPLINT->objsToBlit.push_back(sysopWindow);
LOCPLINT->pushInt(sysopWindow);
}
void CAdvMapInt::fnextHero()
{
@ -1375,7 +1363,6 @@ void CAdvMapInt::activate()
active--;
return;
}
LOCPLINT->curint = this;
LOCPLINT->statusbar = &statusbar;
kingOverview.activate();
underground.activate();
@ -1393,7 +1380,6 @@ void CAdvMapInt::activate()
townList.activate();
terrain.activate();
KeyInterested::activate();
show();
LOCPLINT->cingconsole->activate();
}
@ -1415,33 +1401,33 @@ void CAdvMapInt::deactivate()
deactivate();
}
}
void CAdvMapInt::show(SDL_Surface *to)
void CAdvMapInt::showAll(SDL_Surface *to)
{
blitAt(bg,0,0);
blitAt(bg,0,0,to);
kingOverview.show();
underground.show();
questlog.show();
sleepWake.show();
moveHero.show();
spellbook.show();
advOptions.show();
sysOptions.show();
nextHero.show();
endTurn.show();
kingOverview.show(to);
underground.show(to);
questlog.show(to);
sleepWake.show(to);
moveHero.show(to);
spellbook.show(to);
advOptions.show(to);
sysOptions.show(to);
nextHero.show(to);
endTurn.show(to);
minimap.draw();
heroList.draw();
townList.draw();
minimap.draw(to);
heroList.draw(to);
townList.draw(to);
updateScreen = true;
update();
show(to);
resdatabar.draw();
resdatabar.draw(to);
statusbar.show();
statusbar.show(to);
infoBar.draw();
LOCPLINT->cingconsole->show();
infoBar.draw(to);
LOCPLINT->cingconsole->show(to);
}
void CAdvMapInt::hide()
{
@ -1465,7 +1451,7 @@ void CAdvMapInt::hide()
infoBar.mode=-1;
}
void CAdvMapInt::update()
void CAdvMapInt::show(SDL_Surface *to)
{
++animValHitCount; //for animations
if(animValHitCount == 8)
@ -1480,8 +1466,7 @@ void CAdvMapInt::update()
//if advmap needs updating AND (no dialog is shown OR ctrl is pressed)
if((animValHitCount % (4/LOCPLINT->mapScrollingSpeed)) == 0
&&
(!LOCPLINT->showingDialog->get()
&& !LOCPLINT->curint->subInt)
(LOCPLINT->topInt() == this)
|| SDL_GetKeyState(NULL)[SDLK_LCTRL]
|| SDL_GetKeyState(NULL)[SDLK_RCTRL]
)
@ -1506,15 +1491,15 @@ void CAdvMapInt::update()
}
if(updateScreen)
{
terrain.show();
terrain.show(to);
for(int i=0;i<4;i++)
blitAt(gems[i]->ourImages[LOCPLINT->playerID].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i]);
blitAt(gems[i]->ourImages[LOCPLINT->playerID].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to);
updateScreen=false;
LOCPLINT->cingconsole->show();
LOCPLINT->cingconsole->show(to);
}
if (updateMinimap)
{
minimap.draw();
minimap.draw(to);
updateMinimap=false;
}
}
@ -1580,29 +1565,13 @@ void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * c
{
if (down)
{
boost::algorithm::erase_all(text,"\"");
//boost::algorithm::erase_all(text,"\"");
CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
temp->pos.x=screen->w/2-(temp->pos.w/2);
temp->pos.y=screen->h/2-(temp->pos.h/2);
temp->owner = client;
LOCPLINT->objsToBlit.push_back(temp);
}
else
{
for (size_t i=0; i < LOCPLINT->objsToBlit.size(); ++i)
{
//TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);
if (!pom)
continue;
if (pom->owner==client)
{
LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i));
delete pom;
if((LOCPLINT->curint == LOCPLINT->castleInt) && !LOCPLINT->castleInt->subInt)
LOCPLINT->castleInt->showAll(0,true);
}
}
CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true);
LOCPLINT->pushInt(rcpi);
}
}
int3 CAdvMapInt::verifyPos(int3 ver)
@ -1639,7 +1608,7 @@ void CAdvMapInt::select(const CArmedInstance *sel )
heroList.selected = pos;
terrain.currentPath = heroList.items[pos].second;
}
townList.draw();
heroList.draw();
infoBar.draw(NULL);
townList.draw(screen2);
heroList.draw(screen2);
infoBar.draw(screen2);
}

View File

@ -27,7 +27,7 @@ public:
CMinimap(bool draw=true);
~CMinimap();
void draw();
void draw(SDL_Surface * to);
void redraw(int level=-1);// (level==-1) => redraw all levels
void updateRadar();
@ -58,7 +58,7 @@ public:
void clickRight(tribool down);
void hover(bool on);
void mouseMoved (const SDL_MouseMotionEvent & sEvent);
void show();
void show(SDL_Surface * to);
void showPath(const SDL_Rect * extRect);
int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
int3 whichTileIsIt(); //uses current cursor pos
@ -78,7 +78,7 @@ public:
CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist);
~CResDataBar();
void draw();
void draw(SDL_Surface * to);
};
class CInfoBar
:public virtual CIntObject, public TimeInterested
@ -94,7 +94,7 @@ public:
void newDay(int Day);
void showComp(SComponent * comp, int time=5000);
void tick();
void draw(const CGObjectInstance * specific=NULL); // if specific==0 function draws info about selected hero/town
void draw(SDL_Surface * to, const CGObjectInstance * specific=NULL); // if specific==0 function draws info about selected hero/town
void blitAnim(int mode);//0 - day, 1 - week
CDefHandler * getAnim(int mode);
};
@ -163,8 +163,8 @@ public:
void activate();
void deactivate();
void show(SDL_Surface * to=NULL); //shows and activates adv. map interface
void update(); //redraws terrain
void show(SDL_Surface * to); //redraws terrain
void showAll(SDL_Surface * to); //shows and activates adv. map interface
void select(const CArmedInstance *sel);
void selectionChanged();

View File

@ -292,7 +292,6 @@ CBattleInterface::~CBattleInterface()
delete bConsoleUp;
delete bConsoleDown;
delete console;
delete resWindow;
delete givenCommand;
delete attackingHero;
@ -309,6 +308,8 @@ CBattleInterface::~CBattleInterface()
for(std::map< int, CDefHandler * >::iterator g=idToObstacle.begin(); g!=idToObstacle.end(); ++g)
delete g->second;
LOCPLINT->battleInt = NULL;
}
void CBattleInterface::setPrintCellBorders(bool set)
@ -660,7 +661,7 @@ void CBattleInterface::show(SDL_Surface * to)
}
//showing in-gmae console
LOCPLINT->cingconsole->show();
LOCPLINT->cingconsole->show(to);
//printing border around interface
if(screen->w != 800 || screen->h !=600)
@ -898,8 +899,8 @@ bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
//for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(8) + firstFrame - 1; ++g)
while(!creAnims[number]->onLastFrameInGroup())
{
show();
CSDL_Ext::update();
show(screen);
CSDL_Ext::update(screen);
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
creDir[number] = !creDir[number];
@ -928,8 +929,8 @@ bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
//for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(7) + firstFrame - 1; ++g)
while(!creAnims[number]->onLastFrameInGroup())
{
show();
CSDL_Ext::update();
show(screen);
CSDL_Ext::update(screen);
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
creAnims[number]->setType(2);
@ -941,8 +942,8 @@ void CBattleInterface::handleStartMoving(int number)
{
for(int i=0; i<creAnims[number]->framesInGroup(20)*getAnimSpeedMultiplier()-1; ++i)
{
show();
CSDL_Ext::update();
show(screen);
CSDL_Ext::update(screen);
SDL_framerateDelay(LOCPLINT->mainFPSmng);
if((animCount+1)%(4/settings.animSpeed)==0)
creAnims[number]->incrementFrame();
@ -966,9 +967,8 @@ void CBattleInterface::bSurrenderf()
void CBattleInterface::bFleef()
{
CFunctionList<void()> ony = boost::bind(&CBattleInterface::activate,this);
ony += boost::bind(&CBattleInterface::reallyFlee,this);
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector<SComponent*>(), ony, boost::bind(&CBattleInterface::activate,this), true, false);
CFunctionList<void()> ony = boost::bind(&CBattleInterface::reallyFlee,this);
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector<SComponent*>(), ony, 0, false);
}
void CBattleInterface::reallyFlee()
@ -1151,8 +1151,8 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving, int d
posY += stepY;
creAnims[number]->pos.y = posY;
show();
CSDL_Ext::update();
show(screen);
CSDL_Ext::update(screen);
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
//unit moved
@ -1166,8 +1166,8 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving, int d
//for(int i=0; i<creAnims[number]->framesInGroup(21)*getAnimSpeedMultiplier()-1; ++i)
while(!creAnims[number]->onLastFrameInGroup())
{
show();
CSDL_Ext::update();
show(screen);
CSDL_Ext::update(screen);
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
}
@ -1195,7 +1195,7 @@ void CBattleInterface::stacksAreAttacked(std::vector<CBattleInterface::SStackAtt
//restoring default state of battleWindow by calling show func
while(true)
{
show();
show(screen);
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
@ -1232,8 +1232,8 @@ void CBattleInterface::stacksAreAttacked(std::vector<CBattleInterface::SStackAtt
break;
else
{
show();
CSDL_Ext::update();
show(screen);
CSDL_Ext::update(screen);
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
}
@ -1255,8 +1255,8 @@ void CBattleInterface::stacksAreAttacked(std::vector<CBattleInterface::SStackAtt
bool continueLoop = true;
while(continueLoop)
{
show();
CSDL_Ext::update();
show(screen);
CSDL_Ext::update(screen);
SDL_framerateDelay(LOCPLINT->mainFPSmng);
for(size_t g=0; g<attackedInfos.size(); ++g)
{
@ -1303,8 +1303,8 @@ void CBattleInterface::stackAttacking(int ID, int dest)
}
while(attackingInfo != NULL || creAnims[ID]->getType()!=2)
{
show();
CSDL_Ext::update();
show(screen);
CSDL_Ext::update(screen);
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
@ -1734,16 +1734,18 @@ void CBattleInterface::stackIsShooting(int ID, int dest)
void CBattleInterface::battleFinished(const BattleResult& br)
{
deactivate();
CGI->curh->changeGraphic(0,0);
SDL_Rect temp_rect = genRect(561, 470, (screen->w - 800)/2 + 165, (screen->h - 600)/2 + 19);
resWindow = new CBattleReslutWindow(br, temp_rect, this);
resWindow->activate();
LOCPLINT->pushInt(resWindow);
}
void CBattleInterface::spellCasted(SpellCasted * sc)
{
if(sc->side == !LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned)
bSpell->block(true);
std::vector< std::string > anims; //for magic arrow and ice bolt
switch(sc->id)
@ -1796,11 +1798,11 @@ void CBattleInterface::spellCasted(SpellCasted * sc)
SDL_SetClipRect(screen, &pos); //setting rect we can blit to
for(int g=0; g<steps; ++g)
{
show();
show(screen);
SDL_Rect & srcr = animDef->ourImages[g%animDef->ourImages.size()].bitmap->clip_rect;
SDL_Rect dstr = genRect(srcr.h, srcr.w, srccoord.first + g*dx, srccoord.second + g*dy);
SDL_BlitSurface(animDef->ourImages[g%animDef->ourImages.size()].bitmap, &srcr, screen, &dstr);
CSDL_Ext::update();
CSDL_Ext::update(screen);
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
SDL_SetClipRect(screen, &buf); //restoring previous clip rect
@ -2328,11 +2330,9 @@ void CBattleHero::clickLeft(boost::logic::tribool down)
return;
}
CGI->curh->changeGraphic(0,0);
LOCPLINT->curint->deactivate();
CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero);
spellWindow->activate();
LOCPLINT->objsToBlit.push_back(spellWindow);
LOCPLINT->pushInt(spellWindow);
}
}
@ -2499,8 +2499,7 @@ void CBattleHex::clickRight(boost::logic::tribool down)
pom->effects.insert(myst.effects[vb].id);
}
pom->currentHealth = myst.firstHPleft;
(new CCreInfoWindow(myst.creature->idNumber,0,myst.amount,pom,boost::function<void()>(),boost::function<void()>(),NULL))
->activate();
LOCPLINT->pushInt(new CCreInfoWindow(myst.creature->idNumber,0,myst.amount,pom,0,0,NULL));
}
delete pom;
}
@ -2749,7 +2748,8 @@ void CBattleReslutWindow::show(SDL_Surface *to)
void CBattleReslutWindow::bExitf()
{
LOCPLINT->battleResultQuited();
LOCPLINT->popInts(2); //first - we; second - battle interface
LOCPLINT->showingDialog->setn(false);
}
CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner)
@ -2858,17 +2858,5 @@ void CBattleOptionsWindow::bDefaultf()
void CBattleOptionsWindow::bExitf()
{
deactivate();
for(size_t g=0; g<LOCPLINT->objsToBlit.size(); ++g)
{
if(dynamic_cast<CBattleOptionsWindow*>(LOCPLINT->objsToBlit[g]))
{
LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
break;
}
}
delete this;
LOCPLINT->curint->activate();
LOCPLINT->popIntTotally(this);
}

View File

@ -84,7 +84,7 @@ public:
void scrollDown(unsigned int by = 1); //scrolls console up by 'by' positions
};
class CBattleReslutWindow : public IShowable, public CIntObject, public IActivable
class CBattleReslutWindow : public IShowActivable, public CIntObject
{
private:
SDL_Surface * background;
@ -100,7 +100,7 @@ public:
void show(SDL_Surface * to = 0);
};
class CBattleOptionsWindow : public IShowable, public CIntObject, public IActivable
class CBattleOptionsWindow : public IShowActivable, public CIntObject
{
private:
CBattleInterface * myInt;
@ -198,7 +198,7 @@ private:
bool reverse; //if true, projectile will be flipped by vertical asix
};
std::list<SProjectileInfo> projectiles; //projectiles flying on battlefield
void projectileShowHelper(SDL_Surface * to=NULL); //prints projectiles present on the battlefield
void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield
void giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional=-1);
bool isTileAttackable(const int & number) const; //returns true if tile 'number' is neighbouring any tile from active stack's range or is one of these tiles
@ -246,7 +246,7 @@ public:
//napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
void keyPressed(const SDL_KeyboardEvent & key);
void mouseMoved(const SDL_MouseMotionEvent &sEvent);
bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing

View File

@ -146,7 +146,7 @@ public:
bool verifyPath(CPath * path, bool blockSea) const;
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap() const; //returns visibility map (TODO: make it const)
const CGHeroInstance * getHeroInfo(int val, int mode=2) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
const CGHeroInstance * getHeroInfo(int val, int mode=2) const; //mode = 0 -> val = serial; mode = 1 -> val = hero type id (subID); mode = 2 -> val = global object serial id (id)
int getResourceAmount(int type) const;
std::vector<si32> getResourceAmount() const;
int howManyHeroes(bool includeGarrisoned = true) const;

View File

@ -148,7 +148,7 @@ void CBuildingRect::clickRight (tribool down)
CGI->buildh->buildings[str->townID][str->ID]->Name());
vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
vinya->activate();
LOCPLINT->pushInt(vinya);
}
}
void CBuildingRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
@ -236,10 +236,12 @@ void CHeroGSlot::hover (bool on)
if(temp.size())
LOCPLINT->statusbar->print(temp);
}
void CHeroGSlot::clickRight (boost::logic::tribool down)
{
}
void CHeroGSlot::clickLeft(boost::logic::tribool down)
{
CHeroGSlot *other = upg ? &owner->hslotup : &owner->hslotdown;
@ -249,7 +251,6 @@ void CHeroGSlot::clickLeft(boost::logic::tribool down)
{
highlight = false;
LOCPLINT->openHeroWindow(hero);
LOCPLINT->adventureInt->heroWindow->quitButton->callback += boost::bind(&CCastleInterface::showAll,owner,screen,true);
}
else if(other->hero && other->highlight)
{
@ -277,22 +278,24 @@ void CHeroGSlot::clickLeft(boost::logic::tribool down)
{
highlight = true;
owner->garr->highlighted = NULL;
owner->showAll();
//LOCPLINT->totalRedraw();
}
hover(false);hover(true); //refresh statusbar
}
if(indeterminate(down) && !isItIn(&other->pos,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
{
other->highlight = highlight = false;
show();
//LOCPLINT->totalRedraw();
}
}
void CHeroGSlot::activate()
{
ClickableL::activate();
ClickableR::activate();
Hoverable::activate();
}
void CHeroGSlot::deactivate()
{
highlight = false;
@ -300,15 +303,17 @@ void CHeroGSlot::deactivate()
ClickableR::deactivate();
Hoverable::deactivate();
}
void CHeroGSlot::show()
void CHeroGSlot::show(SDL_Surface * to)
{
if(hero) //there is hero
blitAt(graphics->portraitLarge[hero->portrait],pos);
blitAt(graphics->portraitLarge[hero->portrait],pos,to);
else if(!upg) //up garrison
blitAt(graphics->flags->ourImages[(static_cast<CCastleInterface*>(LOCPLINT->curint))->town->getOwner()].bitmap,pos);
blitAt(graphics->flags->ourImages[LOCPLINT->castleInt->town->getOwner()].bitmap,pos,to);
if(highlight)
blitAt(graphics->bigImgs[-1],pos);
blitAt(graphics->bigImgs[-1],pos,to);
}
CHeroGSlot::CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, CCastleInterface * Owner)
{
owner = Owner;
@ -320,9 +325,11 @@ CHeroGSlot::CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, CCastl
upg = updown;
highlight = false;
}
CHeroGSlot::~CHeroGSlot()
{
}
std::string getBgName(int type) //TODO - co z tym zrobi�?
{
switch (type)
@ -364,11 +371,12 @@ public:
}
} srthlp ;
CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
CCastleInterface::CCastleInterface(const CGTownInstance * Town)
:hslotup(241,387,0,Town->garrisonHero,this),hslotdown(241,483,1,Town->visitingHero,this)
{
bars = CDefHandler::giveDefEss("TPTHBAR.DEF");
status = CDefHandler::giveDefEss("TPTHCHK.DEF");
LOCPLINT->castleInt = this;
subInt = NULL;
hall = NULL;
townInt = BitmapHandler::loadBitmap("TOWNSCRN.bmp");
cityBg = BitmapHandler::loadBitmap(getBgName(Town->subID));
@ -410,13 +418,6 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
recreateBuildings();
if(Activate)
{
LOCPLINT->objsToBlit.push_back(this);
activate();
}
std::string defname;
switch (town->subID)
{
@ -452,8 +453,11 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
}
bicons = CDefHandler::giveDefEss(defname);
}
CCastleInterface::~CCastleInterface()
{
delete bars;
delete status;
SDL_FreeSurface(townInt);
SDL_FreeSurface(cityBg);
delete exit;
@ -471,19 +475,19 @@ CCastleInterface::~CCastleInterface()
delete bicons;
}
void CCastleInterface::close()
{
LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
deactivate();
LOCPLINT->castleInt = NULL;
if(town->visitingHero)
LOCPLINT->adventureInt->select(town->visitingHero);
LOCPLINT->adventureInt->activate();
delete this;
LOCPLINT->castleInt = NULL;
LOCPLINT->popIntTotally(this);
}
void CCastleInterface::splitF()
{
}
void CCastleInterface::buildingClicked(int building)
{
tlog5<<"You've clicked on "<<building<<std::endl;
@ -497,7 +501,6 @@ void CCastleInterface::buildingClicked(int building)
}
if(building >= 30)
{
LOCPLINT->curint->deactivate();
showRecruitmentWindow(building);
}
else
@ -517,14 +520,11 @@ void CCastleInterface::buildingClicked(int building)
CFunctionList<void()> fl = boost::bind(&CCallback::buyArtifact,LOCPLINT->cb,town->visitingHero,0);
fl += boost::bind(&CCastleInterface::enterMageGuild,this);
std::vector<SComponent*> vvv(1,new SComponent(SComponent::artifact,0,0));
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[214],vvv,
fl,boost::bind(&CCastleInterface::activate,this),
true,true);
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[214],vvv,fl,0,true);
}
}
else
{
deactivate();
enterMageGuild();
}
break;
@ -533,16 +533,13 @@ void CCastleInterface::buildingClicked(int building)
{
std::vector<const CGHeroInstance*> h = LOCPLINT->cb->getAvailableHeroes(town);
CTavernWindow *tv = new CTavernWindow(h[0],h[1],"GOSSIP TEST");
deactivate();
tv->activate();
LOCPLINT->pushInt(tv);
break;
}
case 7: case 8: case 9: //fort/citadel/castle
{
deactivate();
CFortScreen *fs = new CFortScreen(this);
fs->activate();
fs->show();
LOCPLINT->pushInt(fs);
break;
}
case 10: case 11: case 12: case 13: //hall
@ -550,9 +547,8 @@ void CCastleInterface::buildingClicked(int building)
break;
case 14: //marketplace
{
deactivate();
CMarketplaceWindow *cmw = new CMarketplaceWindow(0);
cmw->activate();
LOCPLINT->pushInt(cmw);
break;
}
case 15: //resource silo
@ -584,28 +580,23 @@ void CCastleInterface::buildingClicked(int building)
}
}
}
void CCastleInterface::enterHall()
{
deactivate();
CHallInterface *h = new CHallInterface(this);
subInt = h;
h->activate();
h->show();
LOCPLINT->pushInt(h);
}
void CCastleInterface::showAll( SDL_Surface * to/*=NULL*/, bool forceTotalRedraw /*= false*/)
void CCastleInterface::showAll( SDL_Surface * to/*=NULL*/)
{
if (!to)
to=screen;
blitAt(cityBg,pos,to);
blitAt(townInt,pos.x,pos.y+374,to);
LOCPLINT->adventureInt->resdatabar.draw();
townlist->draw();
statusbar->show();
resdatabar->draw();
LOCPLINT->adventureInt->resdatabar.draw(to);
townlist->draw(to);
statusbar->show(to);
resdatabar->draw(to);
garr->show();
garr->show(to);
int pom;
//draw fort icon
@ -665,33 +656,26 @@ void CCastleInterface::showAll( SDL_Surface * to/*=NULL*/, bool forceTotalRedraw
pom++;
blitAt(graphics->bigTownPic->ourImages[pom].bitmap,pos.x+15,pos.y+387,to);
hslotup.show();
hslotdown.show();
hslotup.show(to);
hslotdown.show(to);
pom=false;
if(forceTotalRedraw && !showing)
pom = showing = true;
show();
if(pom)
showing = false;
show(to);
if(screen->w != 800 || screen->h !=600)
CMessage::drawBorder(LOCPLINT->playerID,to,828,628,pos.x-14,pos.y-15);
exit->show(to);
split->show(to);
}
void CCastleInterface::townChange()
{
const CGTownInstance * nt = townlist->items[townlist->selected];
deactivate();
LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
delete this;
LOCPLINT->castleInt = new CCastleInterface(nt,true);
LOCPLINT->popIntTotally(this);
LOCPLINT->pushInt(new CCastleInterface(nt));
}
void CCastleInterface::show(SDL_Surface * to)
{
if(!showing)
return;
if (!to)
to=screen;
count++;
if(count==8)
{
@ -717,19 +701,13 @@ void CCastleInterface::show(SDL_Surface * to)
if(hBuild==buildings[i] && hBuild->border) //if this this higlighted structure and has border we'll blit it
blitAt(hBuild->border,hBuild->pos,to);
}
}
void CCastleInterface::activate()
{
if(subInt)
{
subInt->activate();
return;
}
showing = true;
townlist->activate();
garr->activate();
LOCPLINT->curint = this;
LOCPLINT->statusbar = statusbar;
exit->activate();
split->activate();
@ -739,15 +717,10 @@ void CCastleInterface::activate()
}
hslotdown.activate();
hslotup.activate();
showAll(0,true);
}
void CCastleInterface::deactivate()
{
if(subInt)
{
subInt->deactivate();
return;
}
showing = false;
townlist->deactivate();
garr->deactivate();
@ -906,13 +879,13 @@ CRecrutationWindow * CCastleInterface::showRecruitmentWindow( int building )
crs.push_back(std::make_pair(town->town->basicCreatures[building-30],amount));
CRecrutationWindow *rw = new CRecrutationWindow(crs,boost::bind(&CCallback::recruitCreatures,LOCPLINT->cb,town,_1,_2));
rw->activate();
LOCPLINT->pushInt(rw);
return rw;
}
void CCastleInterface::enterMageGuild()
{
(new CMageGuildScreen(this))->activate();
LOCPLINT->pushInt(new CMageGuildScreen(this));
}
void CHallInterface::CBuildingBox::hover(bool on)
{
@ -935,8 +908,7 @@ void CHallInterface::CBuildingBox::clickLeft (tribool down)
{
if(pressedL && (!down))
{
LOCPLINT->castleInt->subInt->deactivate();
new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,0);
LOCPLINT->pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,0));
}
ClickableL::clickLeft(down);
}
@ -944,15 +916,14 @@ void CHallInterface::CBuildingBox::clickRight (tribool down)
{
if(down)
{
LOCPLINT->castleInt->subInt->deactivate();
new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,1);
LOCPLINT->pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,1));
}
ClickableR::clickRight(down);
}
void CHallInterface::CBuildingBox::show(SDL_Surface * to)
{
CHallInterface *hi = static_cast<CHallInterface*>(LOCPLINT->castleInt->subInt);
blitAt(LOCPLINT->castleInt->bicons->ourImages[BID].bitmap,pos.x,pos.y);
CCastleInterface *ci = LOCPLINT->castleInt;
blitAt(ci->bicons->ourImages[BID].bitmap,pos.x,pos.y,to);
int pom, pom2=-1;
switch (state)
{
@ -975,10 +946,10 @@ void CHallInterface::CBuildingBox::show(SDL_Surface * to)
pom = 3;
break;
}
blitAt(hi->bars->ourImages[pom].bitmap,pos.x-1,pos.y+71);
blitAt(ci->bars->ourImages[pom].bitmap,pos.x-1,pos.y+71,to);
if(pom2>=0)
blitAt(hi->status->ourImages[pom2].bitmap,pos.x+135, pos.y+54);
CSDL_Ext::printAtMiddle(CGI->buildh->buildings[LOCPLINT->castleInt->town->subID][BID]->Name(),pos.x-1+hi->bars->ourImages[0].bitmap->w/2,pos.y+71+hi->bars->ourImages[0].bitmap->h/2, GEOR13,zwykly);
blitAt(ci->status->ourImages[pom2].bitmap,pos.x+135, pos.y+54,to);
CSDL_Ext::printAtMiddle(CGI->buildh->buildings[ci->town->subID][BID]->Name(),pos.x-1+ci->bars->ourImages[0].bitmap->w/2,pos.y+71+ci->bars->ourImages[0].bitmap->h/2, GEOR13,zwykly,to);
}
void CHallInterface::CBuildingBox::activate()
{
@ -1018,8 +989,6 @@ CHallInterface::CHallInterface(CCastleInterface * owner)
resdatabar.pos.y += pos.y;
bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first);
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
bars = CDefHandler::giveDefEss("TPTHBAR.DEF");
status = CDefHandler::giveDefEss("TPTHCHK.DEF");
exit = new AdventureMapButton
(CGI->generaltexth->tcommands[8],"",boost::bind(&CHallInterface::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);
@ -1079,8 +1048,6 @@ CHallInterface::CHallInterface(CCastleInterface * owner)
}
CHallInterface::~CHallInterface()
{
delete bars;
delete status;
SDL_FreeSurface(bg);
for(size_t i=0;i<boxes.size();i++)
for(size_t j=0;j<boxes[i].size();j++)
@ -1089,20 +1056,17 @@ CHallInterface::~CHallInterface()
}
void CHallInterface::close()
{
LOCPLINT->castleInt->subInt = NULL;
deactivate();
delete this;
LOCPLINT->castleInt->activate();
LOCPLINT->popIntTotally(this);
}
void CHallInterface::show(SDL_Surface * to)
{
blitAt(bg,pos);
resdatabar.show();
exit->show();
blitAt(bg,pos,to);
resdatabar.show(to);
exit->show(to);
for(int i=0; i<5; i++)
{
for(size_t j=0;j<boxes[i].size(); ++j)
boxes[i][j]->show();
boxes[i][j]->show(to);
}
}
void CHallInterface::activate()
@ -1130,7 +1094,6 @@ void CHallInterface::deactivate()
void CHallInterface::CBuildWindow::activate()
{
LOCPLINT->objsToBlit.push_back(this);
ClickableR::activate();
if(mode)
return;
@ -1138,9 +1101,9 @@ void CHallInterface::CBuildWindow::activate()
buy->activate();
cancel->activate();
}
void CHallInterface::CBuildWindow::deactivate()
{
LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
ClickableR::deactivate();
if(mode)
return;
@ -1148,38 +1111,37 @@ void CHallInterface::CBuildWindow::deactivate()
buy->deactivate();
cancel->deactivate();
}
void CHallInterface::CBuildWindow::Buy()
{
deactivate();
LOCPLINT->castleInt->subInt = NULL;
LOCPLINT->castleInt->activate();
LOCPLINT->cb->buildBuilding(LOCPLINT->castleInt->town,bid);
delete this;
delete LOCPLINT->castleInt->subInt;
int building = bid;
LOCPLINT->popInts(2); //we - build window and hall screen
LOCPLINT->cb->buildBuilding(LOCPLINT->castleInt->town,building);
}
void CHallInterface::CBuildWindow::close()
{
deactivate();
delete this;
LOCPLINT->castleInt->subInt->activate();
LOCPLINT->castleInt->subInt->show();
LOCPLINT->popIntTotally(this);
}
void CHallInterface::CBuildWindow::clickRight (tribool down)
{
if((!down || indeterminate(down)) && mode)
close();
}
void CHallInterface::CBuildWindow::show(SDL_Surface * to)
{
SDL_Rect pom = genRect(bitmap->h-1,bitmap->w-1,pos.x,pos.y);
SDL_Rect poms = pom; poms.x=0;poms.y=0;
SDL_BlitSurface(bitmap,&poms,to?to:screen,&pom);
SDL_BlitSurface(bitmap,&poms,to,&pom);
if(!mode)
{
buy->show();
cancel->show();
buy->show(to);
cancel->show(to);
}
}
std::string CHallInterface::CBuildWindow::getTextForState(int state)
{
std::string ret;
@ -1244,6 +1206,7 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state)
}
return ret;
}
CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mode)
:tid(Tid), bid(Bid), state(State), mode(Mode)
{
@ -1300,8 +1263,8 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod
if(state!=7)
buy->state=2;
}
activate();
}
CHallInterface::CBuildWindow::~CBuildWindow()
{
SDL_FreeSurface(bitmap);
@ -1312,10 +1275,8 @@ CHallInterface::CBuildWindow::~CBuildWindow()
}
}
CFortScreen::~CFortScreen()
{
LOCPLINT->curint->subInt = NULL;
for(size_t i=0;i<crePics.size();i++)
delete crePics[i];
for (size_t i=0;i<recAreas.size();i++)
@ -1326,29 +1287,26 @@ CFortScreen::~CFortScreen()
void CFortScreen::show( SDL_Surface * to)
{
blitAt(bg,pos);
blitAt(bg,pos,to);
static unsigned char anim = 1;
for (int i=0; i<CREATURES_PER_TOWN; i++)
{
crePics[i]->blitPic(screen,pos.x+positions[i].x+159,pos.y+positions[i].y+4,!(anim%4));
crePics[i]->blitPic(to,pos.x+positions[i].x+159,pos.y+positions[i].y+4,!(anim%4));
}
anim++;
exit->show();
resdatabar.show();
LOCPLINT->statusbar->show();
exit->show(to);
resdatabar.show(to);
LOCPLINT->statusbar->show(to);
}
void CFortScreen::activate()
{
LOCPLINT->curint->subInt = this;
LOCPLINT->statusbar = LOCPLINT->castleInt->statusbar;
exit->activate();
for (size_t i=0;i<recAreas.size(); ++i)
{
recAreas[i]->activate();
}
LOCPLINT->objsToBlit -= LOCPLINT->castleInt;
LOCPLINT->objsToBlit += this;
}
void CFortScreen::deactivate()
@ -1358,20 +1316,16 @@ void CFortScreen::deactivate()
{
recAreas[i]->deactivate();
}
LOCPLINT->objsToBlit -= this;
LOCPLINT->objsToBlit += LOCPLINT->castleInt;
}
void CFortScreen::close()
{
deactivate();
delete this;
LOCPLINT->castleInt->activate();
LOCPLINT->popIntTotally(this);
}
CFortScreen::CFortScreen( CCastleInterface * owner )
{
pos = owner->pos;
LOCPLINT->curint->subInt = this;
bg = NULL;
exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CFortScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
positions += genRect(126,386,10,22),genRect(126,386,404,22),
@ -1464,8 +1418,7 @@ void CFortScreen::RecArea::clickLeft (tribool down)
{
if(!down && pressedL)
{
LOCPLINT->curint->deactivate();
CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid); //do not touch me
LOCPLINT->castleInt->showRecruitmentWindow(bid);
}
ClickableL::clickLeft(down);
}
@ -1492,7 +1445,6 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
bg = BitmapHandler::loadBitmap("TPMAGE.bmp");
exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CMageGuildScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);
scrolls = CDefHandler::giveDefEss("SPELLSCR.DEF");
scrolls2 = CDefHandler::giveDefEss("TPMAGES.DEF");
SDL_Surface *view = BitmapHandler::loadBitmap(graphics->guildBgs[owner->town->subID]);
SDL_SetColorKey(view,SDL_SRCCOLORKEY,SDL_MapRGB(view->format,0,255,255));
@ -1512,7 +1464,7 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
{
spells.push_back(Scroll(&CGI->spellh->spells[owner->town->spells[i][j]]));
spells[spells.size()-1].pos = positions[i][j];
blitAt(scrolls->ourImages[owner->town->spells[i][j]].bitmap,positions[i][j],bg);
blitAt(graphics->spellscr->ourImages[owner->town->spells[i][j]].bitmap,positions[i][j],bg);
}
else
{
@ -1528,56 +1480,55 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
}
delete scrolls2;
}
CMageGuildScreen::~CMageGuildScreen()
{
delete exit;
delete scrolls;
SDL_FreeSurface(bg);
}
void CMageGuildScreen::close()
{
deactivate();
delete this;
LOCPLINT->castleInt->subInt = NULL;
LOCPLINT->castleInt->activate();
LOCPLINT->popIntTotally(this);
}
void CMageGuildScreen::show(SDL_Surface * to)
{
blitAt(bg,pos);
resdatabar.show();
LOCPLINT->statusbar->show();
exit->show();
blitAt(bg,pos,to);
resdatabar.show(to);
LOCPLINT->statusbar->show(to);
exit->show(to);
}
void CMageGuildScreen::activate()
{
LOCPLINT->objsToBlit += this;
LOCPLINT->castleInt->subInt = this;
exit->activate();
for(size_t i=0;i<spells.size();i++)
{
spells[i].activate();
}
}
void CMageGuildScreen::deactivate()
{
LOCPLINT->objsToBlit -= this;
exit->deactivate();
for(size_t i=0;i<spells.size();i++)
{
spells[i].deactivate();
}
}
void CMageGuildScreen::Scroll::clickLeft (tribool down)
{
if(down)
{
std::vector<SComponent*> comps(1,
new CCustomImgComponent(SComponent::spell,spell->id,0,
static_cast<CMageGuildScreen*>(LOCPLINT->castleInt->subInt)->scrolls->ourImages[spell->id].bitmap,false)
new CCustomImgComponent(SComponent::spell,spell->id,0,graphics->spellscr->ourImages[spell->id].bitmap,false)
);
LOCPLINT->showInfoDialog(spell->descriptions[0],comps);
}
}
void CMageGuildScreen::Scroll::clickRight (tribool down)
{
if(down)
@ -1586,14 +1537,14 @@ void CMageGuildScreen::Scroll::clickRight (tribool down)
vinya->free = true;
vinya->bitmap = CMessage::drawBoxTextBitmapSub
(LOCPLINT->playerID,
spell->descriptions[0],
static_cast<CMageGuildScreen*>(LOCPLINT->castleInt->subInt)->scrolls->ourImages[spell->id].bitmap,
spell->descriptions[0],graphics->spellscr->ourImages[spell->id].bitmap,
spell->name,30,30);
vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
vinya->activate();
LOCPLINT->pushInt(vinya);
}
}
void CMageGuildScreen::Scroll::hover(bool on)
{
Hoverable::hover(on);
@ -1603,12 +1554,14 @@ void CMageGuildScreen::Scroll::hover(bool on)
LOCPLINT->statusbar->clear();
}
void CMageGuildScreen::Scroll::activate()
{
ClickableL::activate();
ClickableR::activate();
Hoverable::activate();
}
void CMageGuildScreen::Scroll::deactivate()
{
ClickableL::deactivate();
@ -1647,16 +1600,15 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, i
blitAt(graphics->resources32->ourImages[6].bitmap,148,244,bmp);
}
void CBlacksmithDialog::show( SDL_Surface * to/*=NULL*/ )
void CBlacksmithDialog::show( SDL_Surface * to )
{
blitAt(bmp,pos);
buy->show();
cancel->show();
blitAt(bmp,pos,to);
buy->show(to);
cancel->show(to);
}
void CBlacksmithDialog::activate()
{
LOCPLINT->objsToBlit += this;
if(!buy->bitmapOffset)
buy->activate();
cancel->activate();
@ -1664,7 +1616,6 @@ void CBlacksmithDialog::activate()
void CBlacksmithDialog::deactivate()
{
LOCPLINT->objsToBlit -= this;
if(!buy->bitmapOffset)
buy->deactivate();
cancel->deactivate();
@ -1679,7 +1630,5 @@ CBlacksmithDialog::~CBlacksmithDialog()
void CBlacksmithDialog::close()
{
deactivate();
delete this;
LOCPLINT->curint->activate();
LOCPLINT->popIntTotally(this);
}

View File

@ -46,12 +46,12 @@ public:
void clickLeft(boost::logic::tribool down);
void activate();
void deactivate();
void show();
void show(SDL_Surface * to);
CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h,CCastleInterface * Owner);
~CHeroGSlot();
};
class CCastleInterface : public CMainInterface
class CCastleInterface : public CWindowWithGarrison
{
public:
SDL_Rect pos;
@ -64,22 +64,23 @@ public:
CResDataBar *resdatabar;
unsigned char animval, count;
CDefEssential *bars, //0 - yellow, 1 - green, 2 - red, 3 - gray
*status; //0 - already, 1 - can't, 2 - lack of resources
CDefHandler *hall,*fort;
CDefEssential* bicons; //150x70 buildings imgs
CTownList * townlist;
CHeroGSlot hslotup, hslotdown;
CGarrisonInt * garr;
AdventureMapButton *exit;
AdventureMapButton *split;
std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling
CCastleInterface(const CGTownInstance * Town, bool Activate=true);
CCastleInterface(const CGTownInstance * Town);
~CCastleInterface();
void townChange();
void show(SDL_Surface * to=NULL);
void showAll(SDL_Surface * to=NULL, bool forceTotalRedraw = false);
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void buildingClicked(int building);
void enterMageGuild();
CRecrutationWindow * showRecruitmentWindow(int building);
@ -107,7 +108,7 @@ public:
void hover(bool on);
void clickLeft (tribool down);
void clickRight (tribool down);
void show(SDL_Surface * to=NULL);
void show(SDL_Surface * to);
void activate();
void deactivate();
CBuildingBox(int id);
@ -115,7 +116,7 @@ public:
~CBuildingBox();
};
class CBuildWindow: public IShowable, public ClickableR
class CBuildWindow: public IShowActivable, public ClickableR
{
public:
int tid, bid, state; //town id, building id, state
@ -127,15 +128,13 @@ public:
void deactivate();
std::string getTextForState(int state);
void clickRight (tribool down);
void show(SDL_Surface * to=NULL);
void show(SDL_Surface * to);
void Buy();
void close();
CBuildWindow(int Tid, int Bid, int State, bool Mode);
~CBuildWindow();
};
CDefEssential *bars, //0 - yellow, 1 - green, 2 - red, 3 - gray
*status; //0 - already, 1 - can't, 2 - lack of resources
std::vector< std::vector<CBuildingBox*> >boxes;
AdventureMapButton *exit;
@ -146,12 +145,12 @@ public:
CHallInterface(CCastleInterface * owner);
~CHallInterface();
void close();
void show(SDL_Surface * to=NULL);
void show(SDL_Surface * to);
void activate();
void deactivate();
};
class CFortScreen : public CMainInterface, public CIntObject
class CFortScreen : public IShowActivable, public CIntObject
{
class RecArea : public ClickableL, public ClickableR
{
@ -176,7 +175,7 @@ public:
void draw( CCastleInterface * owner, bool first);
~CFortScreen();
void close();
void show(SDL_Surface * to=NULL);
void show(SDL_Surface * to);
void activate();
void deactivate();
};
@ -208,12 +207,12 @@ public:
CMageGuildScreen(CCastleInterface * owner);
~CMageGuildScreen();
void close();
void show(SDL_Surface * to=NULL);
void show(SDL_Surface * to);
void activate();
void deactivate();
};
class CBlacksmithDialog : public IShowable, public CIntObject
class CBlacksmithDialog : public IShowActivable, public CIntObject
{
public:
AdventureMapButton *buy, *cancel;
@ -222,7 +221,7 @@ public:
CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid);
~CBlacksmithDialog();
void close();
void show(SDL_Surface * to=NULL);
void show(SDL_Surface * to);
void activate();
void deactivate();
};

View File

@ -42,7 +42,7 @@ CHeroWindow::CHeroWindow(int playerColor):
curHero = NULL;
activeArtPlace = NULL;
garInt = NULL;
garr = NULL;
ourBar = new CStatusBar(pos.x+72, pos.y+567, "ADROLLVR.bmp", 660);
quitButton = new AdventureMapButton(CGI->generaltexth->heroscrn[17], std::string(), boost::function<void()>(), pos.x+674, pos.y+524, "hsbtns.def", SDLK_RETURN);
@ -150,7 +150,7 @@ CHeroWindow::~CHeroWindow()
delete flags;
delete garInt;
delete garr;
delete ourBar;
for(size_t g=0; g<artWorn.size(); ++g)
@ -181,21 +181,19 @@ CHeroWindow::~CHeroWindow()
void CHeroWindow::show(SDL_Surface *to)
{
if(!to)
to=screen;
if(curBack)
blitAt(curBack,pos.x,pos.y,to);
quitButton->show();
dismissButton->show();
questlogButton->show();
formations->show();
gar2button->show();
gar4button->show();
leftArtRoll->show();
rightArtRoll->show();
quitButton->show(to);
dismissButton->show(to);
questlogButton->show(to);
formations->show(to);
gar2button->show(to);
gar4button->show(to);
leftArtRoll->show(to);
rightArtRoll->show(to);
garInt->show();
ourBar->show();
garr->show(to);
ourBar->show(to);
for(size_t d=0; d<artWorn.size(); ++d)
{
@ -231,10 +229,10 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
portraitArea->text = hero->getBiography();
delete garInt;
/*gar4button->owner = */garInt = new CGarrisonInt(pos.x+80, pos.y+493, 8, 0, curBack, 15, 485, curHero);
garInt->update = false;
gar4button->callback = boost::bind(&CGarrisonInt::splitClick,garInt);//actualization of callback function
delete garr;
/*gar4button->owner = */garr = new CGarrisonInt(pos.x+80, pos.y+493, 8, 0, curBack, 15, 485, curHero);
garr->update = false;
gar4button->callback = boost::bind(&CGarrisonInt::splitClick,garr);//actualization of callback function
for(size_t g=0; g<primSkillAreas.size(); ++g)
{
@ -254,7 +252,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
sprintf(bufor, CGI->generaltexth->allTexts[2].c_str(), hero->level, CGI->heroh->reqExp(hero->level+1), hero->exp);
expArea->text = std::string(bufor);
sprintf(bufor, CGI->generaltexth->allTexts[205].substr(1, CGI->generaltexth->allTexts[205].size()-2).c_str(), hero->name.c_str(), hero->mana, hero->manaLimit());
sprintf(bufor, CGI->generaltexth->allTexts[205].c_str(), hero->name.c_str(), hero->mana, hero->manaLimit());
spellPointsArea->text = std::string(bufor);
for(size_t g=0; g<artWorn.size(); ++g)
@ -377,15 +375,11 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
void CHeroWindow::quit()
{
LOCPLINT->curint->subInt = NULL;
LOCPLINT->objsToBlit -= this;
if(LOCPLINT->curint == LOCPLINT->castleInt)
LOCPLINT->castleInt->subInt = NULL;
LOCPLINT->curint->activate();
LOCPLINT->popInt(this);
SDL_FreeSurface(curBack);
curBack = NULL;
curHero = NULL;
for(size_t g=0; g<artWorn.size(); ++g)
{
@ -403,7 +397,6 @@ void CHeroWindow::quit()
void CHeroWindow::activate()
{
LOCPLINT->curint->subInt = this;
quitButton->activate();
dismissButton->activate();
questlogButton->activate();
@ -418,7 +411,7 @@ void CHeroWindow::activate()
morale->activate();
luck->activate();
garInt->activate();
garr->activate();
LOCPLINT->statusbar = ourBar;
for(size_t v=0; v<primSkillAreas.size(); ++v)
@ -445,8 +438,6 @@ void CHeroWindow::activate()
{
heroListMi[e]->activate();
}
//LOCPLINT->lclickable.push_back(artFeet);
}
void CHeroWindow::deactivate()
@ -465,7 +456,7 @@ void CHeroWindow::deactivate()
morale->deactivate();
luck->deactivate();
garInt->deactivate();
garr->deactivate();
for(size_t v=0; v<primSkillAreas.size(); ++v)
{
@ -496,7 +487,7 @@ void CHeroWindow::dismissCurrent()
{
CFunctionList<void()> ony = boost::bind(&CHeroWindow::quit,this);
ony += boost::bind(&CCallback::dismissHero,LOCPLINT->cb,curHero);
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[22],std::vector<SComponent*>(), ony, boost::bind(&CHeroWindow::activate,this), true, false);
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[22],std::vector<SComponent*>(), ony, 0, false);
}
void CHeroWindow::questlog()
@ -701,11 +692,8 @@ void CArtPlace::clickLeft(boost::logic::tribool down)
{
if(ourArt->id == 0)
{
ourWindow->deactivate();
CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), ourWindow->curHero);
spellWindow->activate();
LOCPLINT->objsToBlit.push_back(spellWindow);
LOCPLINT->pushInt(spellWindow);
}
}
if(!down && !clicked && pressedL) //not clicked before

View File

@ -77,16 +77,14 @@ public:
void clickRight (tribool down);
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
bool fitsHere(const CArtifact * art); //returns true if given artifact can be placed here
~CArtPlace();
};
class CHeroWindow: public IShowActivable, public virtual CIntObject
class CHeroWindow: public CWindowWithGarrison, public virtual CIntObject
{
SDL_Surface * background, * curBack;
const CGHeroInstance * curHero;
CGarrisonInt * garInt;
CStatusBar * ourBar; //heroWindow's statusBar
//general graphics
@ -109,6 +107,7 @@ class CHeroWindow: public IShowActivable, public virtual CIntObject
LRClickableAreaWTextComp * morale;
std::vector<LRClickableAreaWTextComp *> secSkillAreas;
public:
const CGHeroInstance * curHero;
AdventureMapButton * quitButton, * dismissButton, * questlogButton, //general
* leftArtRoll, * rightArtRoll;
CHighlightableButton *gar2button; //garrison / formation handling;
@ -119,7 +118,7 @@ public:
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 = NULL); //shows hero window
virtual void show(SDL_Surface * to); //shows hero window
void redrawCurBack(); //redraws curBAck from scratch
void quit(); //stops displaying hero window
void dismissCurrent(); //dissmissed currently displayed hero (curHero)

52
CMT.cpp
View File

@ -46,7 +46,7 @@
#undef main
#endif
std::string NAME = NAME_VER + std::string(" (client)"); //application name
SDL_Surface * screen; //main screen surface
SDL_Surface *screen = NULL, *screen2 = NULL; //main screen surface and hlp surface (used to store not-active interfaces layer)
std::queue<SDL_Event*> events;
boost::mutex eventsM;
@ -54,6 +54,8 @@ boost::mutex eventsM;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
void processCommand(const std::string &message, CClient *&client);
void setScreenRes(int w, int h, int bpp, bool fullscreen);
#ifndef __GNUC__
int _tmain(int argc, _TCHAR* argv[])
#else
@ -82,11 +84,8 @@ int main(int argc, char** argv)
CGameInfo * cgi = CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.)
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO)==0)
{
SDL_EnableUNICODE(1);
screen = SDL_SetVideoMode(800,600,conf.cc.bpp,SDL_SWSURFACE|SDL_DOUBLEBUF|(conf.cc.fullscreen?SDL_FULLSCREEN:0)); //initializing important global surface
tlog0 <<"\tInitializing screen: "<<pomtime.getDif();
tlog0 << std::endl;
SDL_WM_SetCaption(NAME.c_str(),""); //set window title
setScreenRes(800,600,conf.cc.bpp,conf.cc.fullscreen);
tlog0 <<"\tInitializing screen: "<<pomtime.getDif() << std::endl;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff;
#else
@ -142,12 +141,7 @@ int main(int argc, char** argv)
if(screen->w != conf.cc.resx || screen->h != conf.cc.resy)
{
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(conf.cc.resx,conf.cc.resy,conf.cc.bpp,SDL_SWSURFACE|SDL_DOUBLEBUF|(conf.cc.fullscreen?SDL_FULLSCREEN:0)); //initializing important global surface
SDL_EnableUNICODE(1);
SDL_WM_SetCaption(NAME.c_str(),""); //set window title
SDL_ShowCursor(SDL_DISABLE);
setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,conf.cc.fullscreen);
}
CClient cl;
if(options->mode == 0) //new game
@ -211,21 +205,10 @@ int main(int argc, char** argv)
}
else if(ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4)
{
LOCPLINT->pim->lock();
boost::unique_lock<boost::recursive_mutex> lock(*LOCPLINT->pim);
bool full = !(screen->flags&SDL_FULLSCREEN);
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(conf.cc.resx,conf.cc.resy,conf.cc.bpp,SDL_SWSURFACE|SDL_DOUBLEBUF|(full?SDL_FULLSCREEN:0)); //initializing important global surface
SDL_WM_SetCaption(NAME.c_str(),""); //set window title
SDL_ShowCursor(SDL_DISABLE);
LOCPLINT->curint->show();
if(LOCPLINT->curint != LOCPLINT->adventureInt)
LOCPLINT->adventureInt->show();
if(LOCPLINT->curint == LOCPLINT->castleInt)
LOCPLINT->castleInt->showAll(0,true);
if(LOCPLINT->curint->subInt)
LOCPLINT->curint->subInt->show();
LOCPLINT->pim->unlock();
setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,full);
LOCPLINT->totalRedraw();
}
eventsM.lock();
events.push(ev);
@ -262,7 +245,7 @@ void processCommand(const std::string &message, CClient *&client)
switch (what)
{
case 0:
LOCPLINT->curint->activate();
LOCPLINT->topInt()->activate();
break;
case 1:
LOCPLINT->adventureInt->activate();
@ -338,4 +321,19 @@ void processCommand(const std::string &message, CClient *&client)
PlayerMessage pm(LOCPLINT->playerID,message);
*client->serv << &pm;
}
}
void setScreenRes(int w, int h, int bpp, bool fullscreen)
{
if(screen) //screen has been already inited
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(conf.cc.resx,conf.cc.resy,conf.cc.bpp,SDL_SWSURFACE|SDL_DOUBLEBUF|(conf.cc.fullscreen?SDL_FULLSCREEN:0)); //initializing important global surface
if(screen2)
SDL_FreeSurface(screen2);
screen2 = CSDL_Ext::copySurface(screen);
SDL_EnableUNICODE(1);
SDL_WM_SetCaption(NAME.c_str(),""); //set window title
SDL_ShowCursor(SDL_DISABLE);
}

File diff suppressed because it is too large Load Diff

View File

@ -41,6 +41,7 @@ class CSlider;
struct UpgradeInfo;
template <typename T> struct CondSh;
class CInGameConsole;
class CGarrisonInt;
namespace boost
{
@ -198,7 +199,11 @@ struct Rect : public SDL_Rect
class IShowable
{
public:
virtual void show(SDL_Surface * to = NULL)=0;
virtual void show(SDL_Surface * to)=0;
virtual void showAll(SDL_Surface * to)
{
show(to);
}
virtual ~IShowable(){};
};
@ -208,7 +213,7 @@ public:
virtual ~IStatusBar(){}; //d-tor
virtual void print(const std::string & text)=0; //prints text and refreshes statusbar
virtual void clear()=0;//clears statusbar and refreshes
virtual void show()=0; //shows statusbar (with current text)
virtual void show(SDL_Surface * to)=0; //shows statusbar (with current text)
virtual std::string getCurrent()=0; //returns currently displayed text
};
@ -222,8 +227,19 @@ public:
class IShowActivable : public IShowable, public IActivable
{
public:
enum {WITH_GARRISON = 1};
int type; //bin flags using etype
IShowActivable();
virtual ~IShowActivable(){};
};
class CWindowWithGarrison : public IShowActivable
{
public:
CGarrisonInt *garr;
CWindowWithGarrison();
};
class CMainInterface : public IShowActivable
{
public:
@ -241,14 +257,16 @@ public:
//}
virtual ~CIntObject(){}; //d-tor
};
class CSimpleWindow : public virtual CIntObject, public IShowable
class CSimpleWindow : public IShowActivable, public virtual CIntObject
{
public:
SDL_Surface * bitmap;
CIntObject * owner; //who made this window
virtual void show(SDL_Surface * to = NULL);
virtual void show(SDL_Surface * to);
CSimpleWindow():bitmap(NULL),owner(NULL){}; //c-tor
virtual ~CSimpleWindow(); //d-tor
void activate(){};
void deactivate(){};
};
class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
{
@ -262,7 +280,7 @@ public:
int state; //TODO: comment me
std::vector< std::vector<SDL_Surface*> > imgs; //images for this button
int curimg; //curently displayed image from imgs
virtual void show(SDL_Surface * to = NULL);
virtual void show(SDL_Surface * to);
virtual void activate()=0;
virtual void deactivate()=0;
CButtonBase(); //c-tor
@ -346,7 +364,7 @@ public:
std::vector<AdventureMapButton *> buttons;
std::vector<SComponent*> components;
virtual void close();
virtual void show(SDL_Surface * to = NULL);
virtual void show(SDL_Surface * to);
void activate();
void deactivate();
CInfoWindow(std::string text, int player, int charperline, const std::vector<SComponent*> &comps, std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons); //c-tor
@ -357,23 +375,33 @@ class CSelWindow : public CInfoWindow //component selection window
{ //warning - this window deletes its components by closing!
public:
void selectionChange(unsigned to);
void close();
void madeChoice(); //looks for selected component and calls callback
CSelWindow(const std::string& text, int player, int charperline ,const std::vector<CSelectableComponent*> &comps, const std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, int askID); //c-tor
CSelWindow(){}; //c-tor
//notification - this class inherits important destructor from CInfoWindow
};
class CRClickPopup : public IShowable, public ClickableR //popup displayed on R-click
class CRClickPopup : public IShowActivable, public ClickableR //popup displayed on R-click
{
public:
virtual void activate();
virtual void deactivate();
virtual void close()=0;
virtual void close();
void clickRight (boost::logic::tribool down);
virtual ~CRClickPopup(){}; //d-tor
};
class CRClickPopupInt : public CRClickPopup //popup displayed on R-click
{
public:
IShowActivable *inner;
bool delInner;
void show(SDL_Surface * to);
CRClickPopupInt(IShowActivable *our, bool deleteInt);
virtual ~CRClickPopupInt(); //d-tor
};
class CInfoPopup : public CRClickPopup
{
public:
@ -381,7 +409,7 @@ public:
SDL_Surface * bitmap; //popup background
CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
void close();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
CInfoPopup(){free=false;bitmap=NULL;} //default c-tor
~CInfoPopup(){}; //d-tor
};
@ -407,7 +435,7 @@ public:
void clickRight (boost::logic::tribool down); //call-in
virtual SDL_Surface * getImg();
virtual void show(SDL_Surface * to = NULL);
virtual void show(SDL_Surface * to);
virtual void activate();
virtual void deactivate();
};
@ -436,7 +464,7 @@ public:
CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
~CSelectableComponent(); //d-tor
virtual void show(SDL_Surface * to = NULL);
virtual void show(SDL_Surface * to);
void activate();
void deactivate();
void select(bool on);
@ -458,7 +486,7 @@ public:
void clickLeft(boost::logic::tribool down);
void activate();
void deactivate();
void show();
void show(SDL_Surface * to);
CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
~CGarrisonSlot();
};
@ -481,7 +509,7 @@ public:
void activate();
void deactivate();
void show();
void show(SDL_Surface * to);
void activeteSlots();
void deactiveteSlots();
void deleteSlots();
@ -500,26 +528,37 @@ class CPlayerInterface : public CGameInterface
public:
//minor interfaces
CondSh<bool> *showingDialog; //indicates if dialog box is displayed
boost::recursive_mutex *pim; //locks read/write of this
bool makingTurn; //indicates if player is already making his turn
boost::recursive_mutex *pim;
bool makingTurn; //if player is already making his turn
//TODO: exclude to some kind Settings struct
int heroMoveSpeed; //speed of player's hero movement
void setHeroMoveSpeed(int newSpeed) {heroMoveSpeed = newSpeed;} //set for the member above
int mapScrollingSpeed; //map scrolling speed
void setMapScrollingSpeed(int newSpeed) {mapScrollingSpeed = newSpeed;} //set the member above
SDL_Event * current; //current event
CMainInterface *curint;
CAdvMapInt * adventureInt;
CCastleInterface * castleInt;
CBattleInterface * battleInt;
CInGameConsole * cingconsole;
FPSmanager * mainFPSmng;
IStatusBar *statusbar; //advmap statusbar; should it be used by other windows with statusbar?
//to commucate with engine
CCallback * cb;
const BattleAction *curAction;
bool stillMoveHero;
std::list<CInfoWindow *> dialogs;
SDL_Event * current; //current event
//CMainInterface *curint;
CAdvMapInt * adventureInt;
CCastleInterface * castleInt; //NULL if castle window isn't opened
CBattleInterface * battleInt; //NULL if no battle
CInGameConsole * cingconsole;
FPSmanager * mainFPSmng; //to keep const framerate
IStatusBar *statusbar; //current statusbar - will be used to show hover tooltips
CCallback * cb; //to communicate with engine
const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL)
bool stillMoveHero; //during hero movement - setting this flag to false will stop movement
std::list<CInfoWindow *> dialogs; //queue of dialogs awaiting to be shown (not currently shown!)
std::list<IShowActivable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
void totalRedraw(); //forces total redraw (using showAll)
void popInt(IShowActivable *top); //removes given interface from the top and activates next
void popIntTotally(IShowActivable *top); //deactivates, deletes, removes given interface from the top and activates next
void pushInt(IShowActivable *newInt); //deactivate old top interface, activates this one and pushes to the top
void popInts(int howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front
IShowActivable *topInt(); //returns top interface
//GUI elements
std::list<ClickableL*> lclickable;
@ -563,7 +602,7 @@ public:
BattleAction activeStack(int stackID); //called when it's turn of that stack
void battleAttack(BattleAttack *ba); //stack performs attack
void battleEnd(BattleResult *br); //end of battle
void battleResultQuited();
//void battleResultQuited();
void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
void battleStackMoved(int ID, int dest, int distance, bool end);
void battleSpellCasted(SpellCasted *sc);
@ -587,9 +626,8 @@ public:
void handleMouseMotion(SDL_Event *sEvent);
void init(ICallback * CB);
int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
void removeObjToBlit(IShowable* obj);
void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, bool deactivateCur=true);
void showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components);
void showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
bool moveHero(const CGHeroInstance *h, CPath * path);
CPlayerInterface(int Player, int serial);//c-tor
@ -612,7 +650,7 @@ public:
~CStatusBar(); //d-tor
void print(const std::string & text); //prints text and refreshes statusbar
void clear();//clears statusbar and refreshes
void show(); //shows statusbar (with current text)
void show(SDL_Surface * to); //shows statusbar (with current text)
std::string getCurrent(); //getter for current
};
@ -637,7 +675,7 @@ public:
virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
virtual void genList()=0;
virtual void select(int which)=0;
virtual void draw()=0;
virtual void draw(SDL_Surface * to)=0;
};
class CHeroList
: public CList
@ -659,7 +697,7 @@ public:
void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
void updateMove(const CGHeroInstance* which); //draws move points bar
void redrawAllOne(int which); //not imeplemented
void draw();
void draw(SDL_Surface * to);
void init();
};
@ -680,7 +718,7 @@ public:
void clickRight(boost::logic::tribool down); //call-in
void hover (bool on); //call-in
void keyPressed (const SDL_KeyboardEvent & key); //call-in
void draw();
void draw(SDL_Surface * to);
};
class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
@ -695,7 +733,7 @@ public:
SDL_Surface * getPic(bool nextFrame); //returns frame of animation
};
class CRecrutationWindow : public IShowable, public ClickableL, public ClickableR
class CRecrutationWindow : public IShowActivable, public ClickableL, public ClickableR
{
public:
struct creinfo
@ -723,12 +761,12 @@ public:
void clickRight(boost::logic::tribool down);
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
CRecrutationWindow(const std::vector<std::pair<int,int> > & Creatures, const boost::function<void(int,int)> & Recruit); //creatures - pairs<creature_ID,amount> //c-tor
~CRecrutationWindow(); //d-tor
};
class CSplitWindow : public IShowable, public KeyInterested, public ClickableL
class CSplitWindow : public IShowActivable, public KeyInterested, public ClickableL
{
public:
CGarrisonInt *gar;
@ -746,16 +784,16 @@ public:
void split();
void close();
void deactivate();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
void clickLeft(boost::logic::tribool down); //call-in
void keyPressed (const SDL_KeyboardEvent & key); //call-in
void sliderMoved(int to);
};
class CCreInfoWindow : public IShowable, public KeyInterested, public ClickableR
class CCreInfoWindow : public IShowActivable, public KeyInterested, public ClickableR
{
public:
bool active; //TODO: comment me
//bool active; //TODO: comment me
int type;//0 - rclick popup; 1 - normal window
SDL_Surface *bitmap; //background
char anf; //TODO: comment me
@ -764,7 +802,6 @@ public:
boost::function<void()> dsm; //TODO: comment me
CCreaturePic *anim;
CCreature *c;
CInfoWindow *dependant; //it may be dialog asking whther upgrade/dismiss stack (if opened)
std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
AdventureMapButton *dismiss, *upgrade, *ok;
@ -776,12 +813,10 @@ public:
void dismissF();
void keyPressed (const SDL_KeyboardEvent & key); //call-in
void deactivate();
void show(SDL_Surface * to = NULL);
void onUpgradeYes();
void onUpgradeNo();
void show(SDL_Surface * to);
};
class CLevelWindow : public IShowable, public CIntObject
class CLevelWindow : public IShowActivable, public CIntObject
{
public:
int heroType;
@ -796,14 +831,14 @@ public:
void activate();
void deactivate();
void selectionChanged(unsigned to);
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
};
class CMinorResDataBar : public IShowable, public CIntObject
{
public:
SDL_Surface *bg; //background bitmap
void show(SDL_Surface * to=NULL);
void show(SDL_Surface * to);
CMinorResDataBar(); //c-tor
~CMinorResDataBar(); //d-tor
};
@ -821,7 +856,7 @@ public:
void activate();
void deactivate();
void show(SDL_Surface * to=NULL);
void show(SDL_Surface * to);
void clickLeft(boost::logic::tribool down);
SDL_Surface *getSurface();
CTradeableItem(int Type, int ID, bool Left);
@ -839,7 +874,7 @@ public:
void activate();
void deactivate();
void show(SDL_Surface * to=NULL);
void show(SDL_Surface * to);
void setMax();
void sliderMoved(int to);
void makeDeal();
@ -868,7 +903,7 @@ public:
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
};
class CTavernWindow : public IShowActivable, public CIntObject
@ -886,7 +921,7 @@ public:
void clickRight(boost::logic::tribool down);
void hover (bool on);
HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
} h1, h2; //recruitable heroes
SDL_Surface *bg; //background
@ -902,7 +937,7 @@ public:
void close();
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
};
class CInGameConsole : public IShowActivable, public KeyInterested
@ -917,7 +952,7 @@ public:
std::string enteredText;
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
void print(const std::string &txt);
void keyPressed (const SDL_KeyboardEvent & key); //call-in
@ -928,17 +963,16 @@ public:
CInGameConsole(); //c-tor
};
class CGarrisonWindow : public IShowActivable, public CIntObject
class CGarrisonWindow : public CWindowWithGarrison, public CIntObject
{
public:
CGarrisonInt *garr;
SDL_Surface *bg;
AdventureMapButton *split, *quit;
void close();
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down);
~CGarrisonWindow();
};

View File

@ -139,63 +139,42 @@ 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)
return;
SDL_Surface * temp;
switch (quality)
{
case 0:
temp = TTF_RenderText_Solid(font,text.c_str(),kolor);
break;
case 1:
SDL_Color tem;
tem.b = 0xff-kolor.b;
tem.g = 0xff-kolor.g;
tem.r = 0xff-kolor.r;
tem.unused = 0xff-kolor.unused;
temp = TTF_RenderText_Shaded(font,text.c_str(),kolor,tem);
break;
case 2:
temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
break;
default:
temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
break;
}
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x,y));
if(refresh)
SDL_UpdateRect(dst,x,y,temp->w,temp->h);
SDL_FreeSurface(temp);
}
void CSDL_Ext::printAtWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
{
if (text.length()==0)
return;
SDL_Surface * temp;
switch (quality)
{
case 0:
temp = TTF_RenderText_Solid(font,text.c_str(),kolor);
break;
case 1:
SDL_Color tem;
tem.b = 0xff-kolor.b;
tem.g = 0xff-kolor.g;
tem.r = 0xff-kolor.r;
tem.unused = 0xff-kolor.unused;
temp = TTF_RenderText_Shaded(font,text.c_str(),kolor,tem);
break;
case 2:
temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
break;
default:
temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
break;
}
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x,y));
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)
{
if (text.length()==0)
return;
SDL_Surface * temp;
switch (quality)
{
case 0:
temp = TTF_RenderText_Solid(font,text.c_str(),kolor);
break;
case 1:
SDL_Color tem;
tem.b = 0xff-kolor.b;
tem.g = 0xff-kolor.g;
tem.r = 0xff-kolor.r;
tem.unused = 0xff-kolor.unused;
temp = TTF_RenderText_Shaded(font,text.c_str(),kolor,tem);
break;
case 2:
temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
break;
default:
temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
break;
}
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x,y));
SDL_UpdateRect(dst,x,y,temp->w,temp->h);
SDL_FreeSurface(temp);
printAt(text,x,y,font,kolor,dst,quality, true);
}
void CSDL_Ext::printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
{
if (text.length()==0)

View File

@ -3,7 +3,7 @@
#include "SDL.h"
#include "SDL_ttf.h"
extern SDL_Surface * screen;
extern SDL_Surface * screen, *screen2;
extern SDL_Color tytulowy, tlo, zwykly ;
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen);
@ -66,7 +66,7 @@ namespace CSDL_Ext
void printAtMiddle(const 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(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
void printAtWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
void printAt(const 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 printAt(const 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 printAtWR(const 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 update(SDL_Surface * what = screen); //updates whole surface (default - main screen)
void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color);

View File

@ -305,19 +305,7 @@ CSpellWindow::~CSpellWindow()
void CSpellWindow::fexitb()
{
deactivate();
for(size_t g=0; g<LOCPLINT->objsToBlit.size(); ++g) //TODO what about
{
if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
{
LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
break;
}
}
delete this;
LOCPLINT->curint->activate();
LOCPLINT->popIntTotally(this);
}
void CSpellWindow::fadvSpellsb()
@ -389,13 +377,10 @@ void CSpellWindow::fRcornerb()
void CSpellWindow::show(SDL_Surface *to)
{
if(to == NULL) //evaluating to
to = screen;
SDL_BlitSurface(background, NULL, to, &pos);
blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 94 + pos.y, to);
statusBar->show();
statusBar->show(to);
//printing school images
if(selectedTab!=4 && spellSite == 0)
@ -625,9 +610,9 @@ void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down)
if(!down && mySpell!=-1)
{
//we will cast a spell
if(dynamic_cast<CBattleInterface*>(LOCPLINT->curint)) //if battle window is open
if(LOCPLINT->battleInt) //if battle window is open
{
dynamic_cast<CBattleInterface*>(LOCPLINT->curint)->castThisSpell(mySpell);
LOCPLINT->battleInt->castThisSpell(mySpell);
}
owner->fexitb();
}
@ -639,14 +624,13 @@ void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
{
CInfoPopup *vinya = new CInfoPopup();
vinya->free = true;
vinya->bitmap = CMessage::drawBoxTextBitmapSub
(LOCPLINT->playerID,
CGI->spellh->spells[mySpell].descriptions[0], this->owner->spells->ourImages[mySpell].bitmap
,
vinya->bitmap = CMessage::drawBoxTextBitmapSub(
LOCPLINT->playerID,
CGI->spellh->spells[mySpell].descriptions[0], this->owner->spells->ourImages[mySpell].bitmap,
CGI->spellh->spells[mySpell].name,30,30);
vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
vinya->activate();
LOCPLINT->pushInt(vinya);
}
}

View File

@ -87,7 +87,7 @@ public:
void activate();
void deactivate();
void show(SDL_Surface * to = NULL);
void show(SDL_Surface * to);
};
#endif // __CSPELLWINDOW_H__

View File

@ -33,6 +33,13 @@ public:
funcs.push_back(first);
return *this;
}
void add(const CFunctionList<Signature> &first)
{
for (size_t i = 0; i < first.funcs.size(); i++)
{
funcs.push_back(first.funcs[i]);
}
}
void clear()
{
funcs.clear();
@ -44,17 +51,19 @@ public:
void operator()() const
{
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
for(size_t i=0;i<funcs2.size(); ++i) {
for(size_t i=0;i<funcs2.size(); ++i)
{
funcs2[i]();
}
}
}
template <typename Arg>
void operator()(const Arg & a) const
{
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
for(int i=0;i<funcs2.size(); i++) {
for(int i=0;i<funcs2.size(); i++)
{
funcs2[i](a);
}
}
}
};
@ -96,9 +105,10 @@ public:
void operator()(const Arg & a) const
{
std::vector<boost::function<Signature> > funcs2 = funcs; //backup
for(size_t i=0;i<funcs2.size(); ++i) {
for(size_t i=0;i<funcs2.size(); ++i)
{
funcs2[i](a);
}
}
}
};