1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-01 00:45:26 +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; state=1;
else else
state=0; state=0;
show(); show(screen2);
if (actOnDown && down) if (actOnDown && down)
{ {
pressedL=state; pressedL=state;
@ -88,7 +88,7 @@ void AdventureMapButton::hover (bool on)
: (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL); : (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL);
if(name && blocked!=1) //if there is no name, there is nohing to display also 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 == "") if(on && LOCPLINT->battleInt->console->alterTxt == "")
{ {
@ -185,7 +185,7 @@ void AdventureMapButton::block( ui8 on )
blocked = on; blocked = on;
state = 0; state = 0;
bitmapOffset = on ? 2 : 0; bitmapOffset = on ? 2 : 0;
show(); show(screen2);
} }
void CHighlightableButton::select(bool on) void CHighlightableButton::select(bool on)
{ {
@ -210,7 +210,7 @@ void CHighlightableButton::clickLeft( tribool down )
state=1; state=1;
else else
state = selected ? 3 : 0; state = selected ? 3 : 0;
show(); show(screen2);
if (pressedL && (down==false)) if (pressedL && (down==false))
{ {
pressedL=state; pressedL=state;
@ -290,8 +290,9 @@ void CHighlightableButtonsGroup::selectionChanged(int to)
} }
void CHighlightableButtonsGroup::show(SDL_Surface * to ) void CHighlightableButtonsGroup::show(SDL_Surface * to )
{ {
for(size_t i=0;i<buttons.size(); ++i) { for(size_t i=0;i<buttons.size(); ++i)
buttons[i]->show(); {
buttons[i]->show(to);
} }
} }
@ -321,7 +322,7 @@ void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent)
void CSlider::redrawSlider() void CSlider::redrawSlider()
{ {
slider.show(); slider.show(screen2);
} }
void CSlider::moveLeft() void CSlider::moveLeft()
@ -388,9 +389,9 @@ void CSlider::clickLeft (tribool down)
void CSlider::show(SDL_Surface * to) void CSlider::show(SDL_Surface * to)
{ {
left.show(); left.show(to);
right.show(); right.show(to);
slider.show(); slider.show(to);
} }
CSlider::~CSlider() CSlider::~CSlider()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

52
CMT.cpp
View File

@ -46,7 +46,7 @@
#undef main #undef main
#endif #endif
std::string NAME = NAME_VER + std::string(" (client)"); //application name 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; std::queue<SDL_Event*> events;
boost::mutex eventsM; boost::mutex eventsM;
@ -54,6 +54,8 @@ boost::mutex eventsM;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
void processCommand(const std::string &message, CClient *&client); void processCommand(const std::string &message, CClient *&client);
void setScreenRes(int w, int h, int bpp, bool fullscreen);
#ifndef __GNUC__ #ifndef __GNUC__
int _tmain(int argc, _TCHAR* argv[]) int _tmain(int argc, _TCHAR* argv[])
#else #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.) 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) if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO)==0)
{ {
SDL_EnableUNICODE(1); setScreenRes(800,600,conf.cc.bpp,conf.cc.fullscreen);
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() << std::endl;
tlog0 <<"\tInitializing screen: "<<pomtime.getDif();
tlog0 << std::endl;
SDL_WM_SetCaption(NAME.c_str(),""); //set window title
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff; int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff;
#else #else
@ -142,12 +141,7 @@ int main(int argc, char** argv)
if(screen->w != conf.cc.resx || screen->h != conf.cc.resy) if(screen->w != conf.cc.resx || screen->h != conf.cc.resy)
{ {
SDL_QuitSubSystem(SDL_INIT_VIDEO); setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,conf.cc.fullscreen);
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);
} }
CClient cl; CClient cl;
if(options->mode == 0) //new game 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) 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); bool full = !(screen->flags&SDL_FULLSCREEN);
SDL_QuitSubSystem(SDL_INIT_VIDEO); setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,full);
SDL_InitSubSystem(SDL_INIT_VIDEO); LOCPLINT->totalRedraw();
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();
} }
eventsM.lock(); eventsM.lock();
events.push(ev); events.push(ev);
@ -262,7 +245,7 @@ void processCommand(const std::string &message, CClient *&client)
switch (what) switch (what)
{ {
case 0: case 0:
LOCPLINT->curint->activate(); LOCPLINT->topInt()->activate();
break; break;
case 1: case 1:
LOCPLINT->adventureInt->activate(); LOCPLINT->adventureInt->activate();
@ -339,3 +322,18 @@ void processCommand(const std::string &message, CClient *&client)
*client->serv << &pm; *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; struct UpgradeInfo;
template <typename T> struct CondSh; template <typename T> struct CondSh;
class CInGameConsole; class CInGameConsole;
class CGarrisonInt;
namespace boost namespace boost
{ {
@ -198,7 +199,11 @@ struct Rect : public SDL_Rect
class IShowable class IShowable
{ {
public: 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(){}; virtual ~IShowable(){};
}; };
@ -208,7 +213,7 @@ public:
virtual ~IStatusBar(){}; //d-tor virtual ~IStatusBar(){}; //d-tor
virtual void print(const std::string & text)=0; //prints text and refreshes statusbar virtual void print(const std::string & text)=0; //prints text and refreshes statusbar
virtual void clear()=0;//clears statusbar and refreshes 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 virtual std::string getCurrent()=0; //returns currently displayed text
}; };
@ -222,8 +227,19 @@ public:
class IShowActivable : public IShowable, public IActivable class IShowActivable : public IShowable, public IActivable
{ {
public: public:
enum {WITH_GARRISON = 1};
int type; //bin flags using etype
IShowActivable();
virtual ~IShowActivable(){}; virtual ~IShowActivable(){};
}; };
class CWindowWithGarrison : public IShowActivable
{
public:
CGarrisonInt *garr;
CWindowWithGarrison();
};
class CMainInterface : public IShowActivable class CMainInterface : public IShowActivable
{ {
public: public:
@ -241,14 +257,16 @@ public:
//} //}
virtual ~CIntObject(){}; //d-tor virtual ~CIntObject(){}; //d-tor
}; };
class CSimpleWindow : public virtual CIntObject, public IShowable class CSimpleWindow : public IShowActivable, public virtual CIntObject
{ {
public: public:
SDL_Surface * bitmap; SDL_Surface * bitmap;
CIntObject * owner; //who made this window 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 CSimpleWindow():bitmap(NULL),owner(NULL){}; //c-tor
virtual ~CSimpleWindow(); //d-tor virtual ~CSimpleWindow(); //d-tor
void activate(){};
void deactivate(){};
}; };
class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
{ {
@ -262,7 +280,7 @@ public:
int state; //TODO: comment me int state; //TODO: comment me
std::vector< std::vector<SDL_Surface*> > imgs; //images for this button std::vector< std::vector<SDL_Surface*> > imgs; //images for this button
int curimg; //curently displayed image from imgs 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 activate()=0;
virtual void deactivate()=0; virtual void deactivate()=0;
CButtonBase(); //c-tor CButtonBase(); //c-tor
@ -346,7 +364,7 @@ public:
std::vector<AdventureMapButton *> buttons; std::vector<AdventureMapButton *> buttons;
std::vector<SComponent*> components; std::vector<SComponent*> components;
virtual void close(); virtual void close();
virtual void show(SDL_Surface * to = NULL); virtual void show(SDL_Surface * to);
void activate(); void activate();
void deactivate(); 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 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! { //warning - this window deletes its components by closing!
public: public:
void selectionChange(unsigned to); void selectionChange(unsigned to);
void close();
void madeChoice(); //looks for selected component and calls callback 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(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 CSelWindow(){}; //c-tor
//notification - this class inherits important destructor from CInfoWindow //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: public:
virtual void activate(); virtual void activate();
virtual void deactivate(); virtual void deactivate();
virtual void close()=0; virtual void close();
void clickRight (boost::logic::tribool down); void clickRight (boost::logic::tribool down);
virtual ~CRClickPopup(){}; //d-tor 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 class CInfoPopup : public CRClickPopup
{ {
public: public:
@ -381,7 +409,7 @@ public:
SDL_Surface * bitmap; //popup background SDL_Surface * bitmap; //popup background
CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
void close(); void close();
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to);
CInfoPopup(){free=false;bitmap=NULL;} //default c-tor CInfoPopup(){free=false;bitmap=NULL;} //default c-tor
~CInfoPopup(){}; //d-tor ~CInfoPopup(){}; //d-tor
}; };
@ -407,7 +435,7 @@ public:
void clickRight (boost::logic::tribool down); //call-in void clickRight (boost::logic::tribool down); //call-in
virtual SDL_Surface * getImg(); virtual SDL_Surface * getImg();
virtual void show(SDL_Surface * to = NULL); virtual void show(SDL_Surface * to);
virtual void activate(); virtual void activate();
virtual void deactivate(); 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(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(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
~CSelectableComponent(); //d-tor ~CSelectableComponent(); //d-tor
virtual void show(SDL_Surface * to = NULL); virtual void show(SDL_Surface * to);
void activate(); void activate();
void deactivate(); void deactivate();
void select(bool on); void select(bool on);
@ -458,7 +486,7 @@ public:
void clickLeft(boost::logic::tribool down); void clickLeft(boost::logic::tribool down);
void activate(); void activate();
void deactivate(); 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(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
~CGarrisonSlot(); ~CGarrisonSlot();
}; };
@ -481,7 +509,7 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void show(); void show(SDL_Surface * to);
void activeteSlots(); void activeteSlots();
void deactiveteSlots(); void deactiveteSlots();
void deleteSlots(); void deleteSlots();
@ -500,26 +528,37 @@ class CPlayerInterface : public CGameInterface
public: public:
//minor interfaces //minor interfaces
CondSh<bool> *showingDialog; //indicates if dialog box is displayed 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 int heroMoveSpeed; //speed of player's hero movement
void setHeroMoveSpeed(int newSpeed) {heroMoveSpeed = newSpeed;} //set for the member above void setHeroMoveSpeed(int newSpeed) {heroMoveSpeed = newSpeed;} //set for the member above
int mapScrollingSpeed; //map scrolling speed int mapScrollingSpeed; //map scrolling speed
void setMapScrollingSpeed(int newSpeed) {mapScrollingSpeed = newSpeed;} //set the member above 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 //GUI elements
std::list<ClickableL*> lclickable; std::list<ClickableL*> lclickable;
@ -563,7 +602,7 @@ public:
BattleAction activeStack(int stackID); //called when it's turn of that stack BattleAction activeStack(int stackID); //called when it's turn of that stack
void battleAttack(BattleAttack *ba); //stack performs attack void battleAttack(BattleAttack *ba); //stack performs attack
void battleEnd(BattleResult *br); //end of battle 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 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 battleStackMoved(int ID, int dest, int distance, bool end);
void battleSpellCasted(SpellCasted *sc); void battleSpellCasted(SpellCasted *sc);
@ -587,9 +626,8 @@ public:
void handleMouseMotion(SDL_Event *sEvent); void handleMouseMotion(SDL_Event *sEvent);
void init(ICallback * CB); void init(ICallback * CB);
int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on 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);
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 DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
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
bool moveHero(const CGHeroInstance *h, CPath * path); bool moveHero(const CGHeroInstance *h, CPath * path);
CPlayerInterface(int Player, int serial);//c-tor CPlayerInterface(int Player, int serial);//c-tor
@ -612,7 +650,7 @@ public:
~CStatusBar(); //d-tor ~CStatusBar(); //d-tor
void print(const std::string & text); //prints text and refreshes statusbar void print(const std::string & text); //prints text and refreshes statusbar
void clear();//clears statusbar and refreshes 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 std::string getCurrent(); //getter for current
}; };
@ -637,7 +675,7 @@ public:
virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
virtual void genList()=0; virtual void genList()=0;
virtual void select(int which)=0; virtual void select(int which)=0;
virtual void draw()=0; virtual void draw(SDL_Surface * to)=0;
}; };
class CHeroList class CHeroList
: public CList : public CList
@ -659,7 +697,7 @@ public:
void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it 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 updateMove(const CGHeroInstance* which); //draws move points bar
void redrawAllOne(int which); //not imeplemented void redrawAllOne(int which); //not imeplemented
void draw(); void draw(SDL_Surface * to);
void init(); void init();
}; };
@ -680,7 +718,7 @@ public:
void clickRight(boost::logic::tribool down); //call-in void clickRight(boost::logic::tribool down); //call-in
void hover (bool on); //call-in void hover (bool on); //call-in
void keyPressed (const SDL_KeyboardEvent & key); //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 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 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: public:
struct creinfo struct creinfo
@ -723,12 +761,12 @@ public:
void clickRight(boost::logic::tribool down); void clickRight(boost::logic::tribool down);
void activate(); void activate();
void deactivate(); 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(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 ~CRecrutationWindow(); //d-tor
}; };
class CSplitWindow : public IShowable, public KeyInterested, public ClickableL class CSplitWindow : public IShowActivable, public KeyInterested, public ClickableL
{ {
public: public:
CGarrisonInt *gar; CGarrisonInt *gar;
@ -746,16 +784,16 @@ public:
void split(); void split();
void close(); void close();
void deactivate(); void deactivate();
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to);
void clickLeft(boost::logic::tribool down); //call-in void clickLeft(boost::logic::tribool down); //call-in
void keyPressed (const SDL_KeyboardEvent & key); //call-in void keyPressed (const SDL_KeyboardEvent & key); //call-in
void sliderMoved(int to); void sliderMoved(int to);
}; };
class CCreInfoWindow : public IShowable, public KeyInterested, public ClickableR class CCreInfoWindow : public IShowActivable, public KeyInterested, public ClickableR
{ {
public: public:
bool active; //TODO: comment me //bool active; //TODO: comment me
int type;//0 - rclick popup; 1 - normal window int type;//0 - rclick popup; 1 - normal window
SDL_Surface *bitmap; //background SDL_Surface *bitmap; //background
char anf; //TODO: comment me char anf; //TODO: comment me
@ -764,7 +802,6 @@ public:
boost::function<void()> dsm; //TODO: comment me boost::function<void()> dsm; //TODO: comment me
CCreaturePic *anim; CCreaturePic *anim;
CCreature *c; 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) std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
AdventureMapButton *dismiss, *upgrade, *ok; AdventureMapButton *dismiss, *upgrade, *ok;
@ -776,12 +813,10 @@ public:
void dismissF(); void dismissF();
void keyPressed (const SDL_KeyboardEvent & key); //call-in void keyPressed (const SDL_KeyboardEvent & key); //call-in
void deactivate(); void deactivate();
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to);
void onUpgradeYes();
void onUpgradeNo();
}; };
class CLevelWindow : public IShowable, public CIntObject class CLevelWindow : public IShowActivable, public CIntObject
{ {
public: public:
int heroType; int heroType;
@ -796,14 +831,14 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void selectionChanged(unsigned to); void selectionChanged(unsigned to);
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to);
}; };
class CMinorResDataBar : public IShowable, public CIntObject class CMinorResDataBar : public IShowable, public CIntObject
{ {
public: public:
SDL_Surface *bg; //background bitmap SDL_Surface *bg; //background bitmap
void show(SDL_Surface * to=NULL); void show(SDL_Surface * to);
CMinorResDataBar(); //c-tor CMinorResDataBar(); //c-tor
~CMinorResDataBar(); //d-tor ~CMinorResDataBar(); //d-tor
}; };
@ -821,7 +856,7 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to=NULL); void show(SDL_Surface * to);
void clickLeft(boost::logic::tribool down); void clickLeft(boost::logic::tribool down);
SDL_Surface *getSurface(); SDL_Surface *getSurface();
CTradeableItem(int Type, int ID, bool Left); CTradeableItem(int Type, int ID, bool Left);
@ -839,7 +874,7 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to=NULL); void show(SDL_Surface * to);
void setMax(); void setMax();
void sliderMoved(int to); void sliderMoved(int to);
void makeDeal(); void makeDeal();
@ -868,7 +903,7 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to);
}; };
class CTavernWindow : public IShowActivable, public CIntObject class CTavernWindow : public IShowActivable, public CIntObject
@ -886,7 +921,7 @@ public:
void clickRight(boost::logic::tribool down); void clickRight(boost::logic::tribool down);
void hover (bool on); void hover (bool on);
HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H); 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 } h1, h2; //recruitable heroes
SDL_Surface *bg; //background SDL_Surface *bg; //background
@ -902,7 +937,7 @@ public:
void close(); void close();
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to);
}; };
class CInGameConsole : public IShowActivable, public KeyInterested class CInGameConsole : public IShowActivable, public KeyInterested
@ -917,7 +952,7 @@ public:
std::string enteredText; std::string enteredText;
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to);
void print(const std::string &txt); void print(const std::string &txt);
void keyPressed (const SDL_KeyboardEvent & key); //call-in void keyPressed (const SDL_KeyboardEvent & key); //call-in
@ -928,17 +963,16 @@ public:
CInGameConsole(); //c-tor CInGameConsole(); //c-tor
}; };
class CGarrisonWindow : public IShowActivable, public CIntObject class CGarrisonWindow : public CWindowWithGarrison, public CIntObject
{ {
public: public:
CGarrisonInt *garr;
SDL_Surface *bg; SDL_Surface *bg;
AdventureMapButton *split, *quit; AdventureMapButton *split, *quit;
void close(); void close();
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to);
CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down); CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down);
~CGarrisonWindow(); ~CGarrisonWindow();
}; };

View File

@ -139,35 +139,7 @@ void CSDL_Ext::printAtMiddle(const std::string & text, int x, int y, TTF_Font *
SDL_UpdateRect(dst,x-(temp->w/2),y-(temp->h/2),temp->w,temp->h); SDL_UpdateRect(dst,x-(temp->w/2),y-(temp->h/2),temp->w,temp->h);
SDL_FreeSurface(temp); SDL_FreeSurface(temp);
} }
void CSDL_Ext::printAtWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality) 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));
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) if (text.length()==0)
return; return;
@ -193,9 +165,16 @@ void CSDL_Ext::printAt(const std::string & text, int x, int y, TTF_Font * font,
break; break;
} }
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x,y)); SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x,y));
if(refresh)
SDL_UpdateRect(dst,x,y,temp->w,temp->h); SDL_UpdateRect(dst,x,y,temp->w,temp->h);
SDL_FreeSurface(temp); 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)
{
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) 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) if (text.length()==0)

View File

@ -3,7 +3,7 @@
#include "SDL.h" #include "SDL.h"
#include "SDL_ttf.h" #include "SDL_ttf.h"
extern SDL_Surface * screen; extern SDL_Surface * screen, *screen2;
extern SDL_Color tytulowy, tlo, zwykly ; extern SDL_Color tytulowy, tlo, zwykly ;
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen); 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 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 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 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 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 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); 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() void CSpellWindow::fexitb()
{ {
deactivate(); LOCPLINT->popIntTotally(this);
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();
} }
void CSpellWindow::fadvSpellsb() void CSpellWindow::fadvSpellsb()
@ -389,13 +377,10 @@ void CSpellWindow::fRcornerb()
void CSpellWindow::show(SDL_Surface *to) void CSpellWindow::show(SDL_Surface *to)
{ {
if(to == NULL) //evaluating to
to = screen;
SDL_BlitSurface(background, NULL, to, &pos); SDL_BlitSurface(background, NULL, to, &pos);
blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 94 + pos.y, to); blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 94 + pos.y, to);
statusBar->show(); statusBar->show(to);
//printing school images //printing school images
if(selectedTab!=4 && spellSite == 0) if(selectedTab!=4 && spellSite == 0)
@ -625,9 +610,9 @@ void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down)
if(!down && mySpell!=-1) if(!down && mySpell!=-1)
{ {
//we will cast a spell //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(); owner->fexitb();
} }
@ -639,14 +624,13 @@ void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
{ {
CInfoPopup *vinya = new CInfoPopup(); CInfoPopup *vinya = new CInfoPopup();
vinya->free = true; vinya->free = true;
vinya->bitmap = CMessage::drawBoxTextBitmapSub vinya->bitmap = CMessage::drawBoxTextBitmapSub(
(LOCPLINT->playerID, LOCPLINT->playerID,
CGI->spellh->spells[mySpell].descriptions[0], this->owner->spells->ourImages[mySpell].bitmap CGI->spellh->spells[mySpell].descriptions[0], this->owner->spells->ourImages[mySpell].bitmap,
,
CGI->spellh->spells[mySpell].name,30,30); CGI->spellh->spells[mySpell].name,30,30);
vinya->pos.x = screen->w/2 - vinya->bitmap->w/2; vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
vinya->pos.y = screen->h/2 - vinya->bitmap->h/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 activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to);
}; };
#endif // __CSPELLWINDOW_H__ #endif // __CSPELLWINDOW_H__

View File

@ -33,6 +33,13 @@ public:
funcs.push_back(first); funcs.push_back(first);
return *this; 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() void clear()
{ {
funcs.clear(); funcs.clear();
@ -44,7 +51,8 @@ public:
void operator()() const void operator()() const
{ {
std::vector<boost::function<Signature> > funcs2 = funcs; //backup 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](); funcs2[i]();
} }
} }
@ -52,7 +60,8 @@ public:
void operator()(const Arg & a) const void operator()(const Arg & a) const
{ {
std::vector<boost::function<Signature> > funcs2 = funcs; //backup 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); funcs2[i](a);
} }
} }
@ -96,7 +105,8 @@ public:
void operator()(const Arg & a) const void operator()(const Arg & a) const
{ {
std::vector<boost::function<Signature> > funcs2 = funcs; //backup 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); funcs2[i](a);
} }
} }