diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index fa9c1ea8e..276bc3108 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -10,6 +10,7 @@ #include "hch/CBuildingHandler.h" #include #include "CMessage.h" +#include "hch/CGeneralTextHandler.h" CBuildingRect::CBuildingRect(Structure *Str) :str(Str) { @@ -187,6 +188,7 @@ public: CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) { + hall = NULL; townInt = CGI->bitmaph->loadBitmap("TOWNSCRN.bmp"); cityBg = CGI->bitmaph->loadBitmap(getBgName(Town->subID)); hall = CGI->spriteh->giveDef("ITMTL.DEF"); @@ -363,6 +365,9 @@ void CCastleInterface::buildingClicked(int building) void CCastleInterface::enterHall() { deactivate(); + hallInt = new CHallInterface(this); + hallInt->activate(); + hallInt->show(); } void CCastleInterface::showAll(SDL_Surface * to) { @@ -462,6 +467,8 @@ void CCastleInterface::townChange() } void CCastleInterface::show(SDL_Surface * to) { + if(!showing) + return; if (!to) to=ekran; count++; @@ -493,6 +500,7 @@ void CCastleInterface::show(SDL_Surface * to) } void CCastleInterface::activate() { + showing = true; townlist->activate(); garr->activate(); LOCPLINT->curint = this; @@ -504,6 +512,7 @@ void CCastleInterface::activate() } void CCastleInterface::deactivate() { + showing = false; townlist->deactivate(); garr->deactivate(); exit->deactivate(); @@ -515,15 +524,43 @@ void CCastleInterface::deactivate() void CHallInterface::CResDataBar::show(SDL_Surface * to) { + blitAt(bg,pos.x,pos.y); + char * buf = new char[15]; + for (int i=0;i<7;i++) + { + itoa(LOCPLINT->cb->getResourceAmount(i),buf,10); + CSDL_Ext::printAtMiddle(buf,pos.x + 50 + 76*i,pos.y+pos.h/2,GEOR13,zwykly); + } + std::vector temp; + itoa(LOCPLINT->cb->getDate(3),buf,10); temp.push_back(std::string(buf)); + itoa(LOCPLINT->cb->getDate(2),buf,10); temp.push_back(buf); + itoa(LOCPLINT->cb->getDate(1),buf,10); temp.push_back(buf); + CSDL_Ext::printAtMiddle(CSDL_Ext::processStr( + CGI->generaltexth->allTexts[62] + +": %s, " + + CGI->generaltexth->allTexts[63] + + ": %s, " + + CGI->generaltexth->allTexts[64] + + ": %s",temp) + ,pos.x+545+(pos.w-545)/2,pos.y+pos.h/2,GEOR13,zwykly); + temp.clear(); + //updateRect(&pos,ekran); + delete[] buf; } CHallInterface::CResDataBar::CResDataBar() { + bg = CGI->bitmaph->loadBitmap("Z2ESBAR.bmp"); + CSDL_Ext::blueToPlayers(bg,LOCPLINT->playerID); + pos.x = 7; + pos.y = 575; + pos.w = bg->w; + pos.h = bg->h; } CHallInterface::CResDataBar::~CResDataBar() { + SDL_FreeSurface(bg); } - void CHallInterface::CBuildingBox::hover(bool on) { } @@ -533,6 +570,27 @@ void CHallInterface::CBuildingBox::clickLeft (tribool down) void CHallInterface::CBuildingBox::clickRight (tribool down) { } +void CHallInterface::CBuildingBox::show(SDL_Surface * to) +{ + blitAt(LOCPLINT->castleInt->bicons->ourImages[ID].bitmap,pos.x,pos.y); + int pom; + switch (state) + { + case 3: + pom = 0; + break; + case 0: + pom = 1; + break; + case 1: case 2: + pom = 2; + break; + default: + pom = 3; + } + blitAt(LOCPLINT->castleInt->hallInt->bars->ourImages[pom].bitmap,pos.x-1,pos.y+71); + CSDL_Ext::printAtMiddle(CGI->buildh->buildings[LOCPLINT->castleInt->town->subID][ID]->name,pos.x-1+LOCPLINT->castleInt->hallInt->bars->ourImages[0].bitmap->w/2,pos.y+71+LOCPLINT->castleInt->hallInt->bars->ourImages[0].bitmap->h/2, GEOR13,zwykly); +} void CHallInterface::CBuildingBox::activate() { } @@ -542,24 +600,124 @@ void CHallInterface::CBuildingBox::deactivate() CHallInterface::CBuildingBox::~CBuildingBox() { } +CHallInterface::CBuildingBox::CBuildingBox(int id) + :ID(id) +{ + pos.w = 150; + pos.h = 70; +} +CHallInterface::CBuildingBox::CBuildingBox(int id, int x, int y) + :ID(id) +{ + pos.x = x; + pos.y = y; +} CHallInterface::CHallInterface(CCastleInterface * owner) { + bg = CGI->bitmaph->loadBitmap(CGI->buildh->hall[owner->town->subID].first); + CSDL_Ext::blueToPlayers(bg,LOCPLINT->playerID); + bars = CGI->spriteh->giveDefEss("TPTHBAR.DEF"); + status = CGI->spriteh->giveDefEss("TPTHCHK.DEF"); + exit = new AdventureMapButton + (CGI->townh->tcommands[8],"",&CHallInterface::close,748,556,"TPMAGE1.DEF",this,false,NULL,false); + for(int i=0;i<5;i++) //for each row + { + for(int j=0; jbuildh->hall[owner->town->subID].second[i].size();j++) //for each box + { + int k=0; + for(;kbuildh->hall[owner->town->subID].second[i][j].size();k++)//we are looking for the first not build structure + { + if( + (owner->town->builtBuildings.find(CGI->buildh->hall[owner->town->subID].second[i][j][k])) + == + (owner->town->builtBuildings.end()) ) + { + int x = 34 + 194*j, + y = 37 + 104*i; + if(CGI->buildh->hall[owner->town->subID].second[i].size() == 2) + x+=194; + else if(CGI->buildh->hall[owner->town->subID].second[i].size() == 3) + x+=97; + boxes[i].push_back(new CBuildingBox(CGI->buildh->hall[owner->town->subID].second[i][j][k],x,y)); + + //can we build it? + if(owner->town->possibleBuildings.find(CGI->buildh->hall[owner->town->subID].second[i][j][k])==owner->town->possibleBuildings.end()) + boxes[i][boxes[i].size()-1]->state = -1; //forbidden + else if(owner->town->builded >= MAX_BUILDING_PER_TURN) + boxes[i][boxes[i].size()-1]->state = 2; //forbidden + //TODO: check requirements + //else if(owner->town->builded >= MAX_BUILDING_PER_TURN) + // boxes[i][boxes[i].size()-1]->state = 2; //forbidden + + else + { + CBuilding * pom = CGI->buildh->buildings[owner->town->subID][CGI->buildh->hall[owner->town->subID].second[i][j][k]]; + + boxes[i][boxes[i].size()-1]->state = 0; //allowed + + for(int res=0;res<7;res++) //TODO: support custom amount of resources + { + if(pom->resources[res]>LOCPLINT->cb->getResourceAmount(res)) + boxes[i][boxes[i].size()-1]->state = 1; //lack of res + } + } + + break; + } + } + if(k==CGI->buildh->hall[owner->town->subID].second[i][j].size()) //all buildings built - let's take the last one + { + int x = 34 + 194*j, + y = 37 + 104*i; + if(CGI->buildh->hall[owner->town->subID].second[i].size() == 2) + x+=194; + else if(CGI->buildh->hall[owner->town->subID].second[i].size() == 3) + x+=97; + boxes[i].push_back(new CBuildingBox(CGI->buildh->hall[owner->town->subID].second[i][j][k-1],x,y)); + boxes[i][boxes[i].size()-1]->state = 3; //already exists + } + } + } } CHallInterface::~CHallInterface() { } void CHallInterface::close() { + deactivate(); + LOCPLINT->castleInt->activate(); + LOCPLINT->castleInt->showAll(); } void CHallInterface::show(SDL_Surface * to) { + blitAt(bg,0,0); + resdatabar.show(); + exit->show(); + for(int i=0; i<5; i++) + { + for(int j=0;jshow(); + } } void CHallInterface::activate() { + for(int i=0;i<5;i++) + for(int j=0;jactivate(); + exit->activate(); } void CHallInterface::deactivate() { + for(int i=0;i<5;i++) + { + for(int j=0;jdeactivate(); + delete boxes[i][j]; + } + } + exit->deactivate(); } \ No newline at end of file diff --git a/CCastleInterface.h b/CCastleInterface.h index d8c0ce777..9381d98f0 100644 --- a/CCastleInterface.h +++ b/CCastleInterface.h @@ -5,6 +5,7 @@ //#include "boost/tuple/tuple.hpp" class CGTownInstance; class CTownHandler; +class CHallInterface; struct Structure; template class AdventureMapButton; class CBuildingRect : public Hoverable, public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested @@ -28,12 +29,13 @@ public: class CCastleInterface : public IShowable, public IActivable { public: + bool showing; CBuildingRect * hBuild; //highlighted building SDL_Surface * townInt; SDL_Surface * cityBg; const CGTownInstance * town; CStatusBar * statusbar; - + CHallInterface * hallInt; unsigned char animval, count; CDefHandler *hall,*fort, *flag; @@ -78,11 +80,16 @@ public: void hover(bool on); void clickLeft (tribool down); void clickRight (tribool down); + void show(SDL_Surface * to=NULL); void activate(); void deactivate(); + CBuildingBox(int id); + CBuildingBox(int id, int x, int y); ~CBuildingBox(); }; + CDefEssential *bars, //0 - yellow, 1 - green, 2 - red, 3 - gray + *status; //0 - already, 1 - can't, 2 - lack of resources std::vector boxes[5]; AdventureMapButton * exit; diff --git a/CMT.cpp b/CMT.cpp index 5fd766004..9a23652c4 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -832,13 +832,7 @@ int _tmain(int argc, _TCHAR* argv[]) } std::cout<<"done."<bufor); //czytanie nagłówka cgi->ac = ac; THC std::cout<<"Reading file: "<deh3m(); @@ -853,7 +847,7 @@ int _tmain(int argc, _TCHAR* argv[]) THC std::cout<<"Initializing mapHandler (together): "<adventureInt->handleRightClick(description,down,this); diff --git a/config/hall.txt b/config/hall.txt index 1f112da58..c1b7d1f0c 100644 --- a/config/hall.txt +++ b/config/hall.txt @@ -2,8 +2,8 @@ 0 TPTHBKCS.BMP 10 11 12 13 | 7 8 9 | 5 22 | 16 -14 15 | 0 1 2 3 4 | 6 -21 | 24 +14 15 | 0 1 2 3 | 6 +21 | 24 25 30 37 | 31 38 | 32 39 | 33 40 34 41 | 35 42 | 36 43 1 @@ -44,14 +44,14 @@ TPTHBKDG.BMP 6 TPTHBKST.BMP 10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 3 4 | 23 | 17 +14 15 | 0 1 2 | 23 | 17 21 | 22 | 18 19 30 37 | 31 38 | 32 39 | 33 40 34 41 | 35 42 | 36 43 7 TPTHBKFR.BMP 10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 3 4 | 6 +14 15 | 0 1 2 | 6 17 | 22 | 18 19 30 37 | 31 38 | 32 39 | 33 40 34 41 | 35 42 | 36 43 diff --git a/hch/CTownHandler.cpp b/hch/CTownHandler.cpp index c3e903e60..e55c94ec1 100644 --- a/hch/CTownHandler.cpp +++ b/hch/CTownHandler.cpp @@ -48,6 +48,15 @@ void CTownHandler::loadNames() tcommands.push_back(tmp); } + strs = CGI->bitmaph->getTextFile("HALLINFO.TXT"); + itr=0; + while(itr towns; - std::vector tcommands; + std::vector tcommands, hcommands; void loadNames(); SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //ID=-1 - blank; -2 - border; -3 - random static int getTypeByDefName(std::string name);