mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
More code for halls.
This commit is contained in:
parent
b95551a0be
commit
eed2a2b54c
@ -10,6 +10,7 @@
|
||||
#include "hch/CBuildingHandler.h"
|
||||
#include <sstream>
|
||||
#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<std::string> 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<CHallInterface>
|
||||
(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; j<CGI->buildh->hall[owner->town->subID].second[i].size();j++) //for each box
|
||||
{
|
||||
int k=0;
|
||||
for(;k<CGI->buildh->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;j<boxes[i].size();j++)
|
||||
boxes[i][j]->show();
|
||||
}
|
||||
}
|
||||
void CHallInterface::activate()
|
||||
{
|
||||
for(int i=0;i<5;i++)
|
||||
for(int j=0;j<boxes[i].size();j++)
|
||||
boxes[i][j]->activate();
|
||||
exit->activate();
|
||||
}
|
||||
void CHallInterface::deactivate()
|
||||
{
|
||||
for(int i=0;i<5;i++)
|
||||
{
|
||||
for(int j=0;j<boxes[i].size();j++)
|
||||
{
|
||||
boxes[i][j]->deactivate();
|
||||
delete boxes[i][j];
|
||||
}
|
||||
}
|
||||
exit->deactivate();
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
//#include "boost/tuple/tuple.hpp"
|
||||
class CGTownInstance;
|
||||
class CTownHandler;
|
||||
class CHallInterface;
|
||||
struct Structure;
|
||||
template <typename T> 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<CBuildingBox*> boxes[5];
|
||||
|
||||
AdventureMapButton<CHallInterface> * exit;
|
||||
|
8
CMT.cpp
8
CMT.cpp
@ -832,13 +832,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
}
|
||||
std::cout<<"done."<<std::endl;
|
||||
|
||||
#define CHOOSE
|
||||
#ifdef CHOOSE
|
||||
CAmbarCendamo * ac = new CAmbarCendamo(initTable); //4gryf
|
||||
#else
|
||||
CAmbarCendamo * ac = new CAmbarCendamo("RoEtest"); //4gryf
|
||||
#endif
|
||||
//CMapHeader * mmhh = new CMapHeader(ac->bufor); //czytanie nag³ówka
|
||||
cgi->ac = ac;
|
||||
THC std::cout<<"Reading file: "<<tmh.getDif()<<std::endl;
|
||||
ac->deh3m();
|
||||
@ -853,7 +847,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
THC std::cout<<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
|
||||
|
||||
initGameState(cgi);
|
||||
THC std::cout<<"Initializing GameState: "<<tmh.getDif()<<std::endl;
|
||||
THC std::cout<<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
|
||||
|
||||
/*for(int d=0; d<PLAYER_LIMIT; ++d)
|
||||
{
|
||||
|
@ -469,7 +469,6 @@ SDL_Surface * SComponent::getImg()
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SComponent::clickRight (tribool down)
|
||||
{
|
||||
LOCPLINT->adventureInt->handleRightClick(description,down,this);
|
||||
|
@ -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
|
||||
|
@ -48,6 +48,15 @@ void CTownHandler::loadNames()
|
||||
tcommands.push_back(tmp);
|
||||
}
|
||||
|
||||
strs = CGI->bitmaph->getTextFile("HALLINFO.TXT");
|
||||
itr=0;
|
||||
while(itr<strs.length()-1)
|
||||
{
|
||||
std::string tmp;
|
||||
CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
|
||||
hcommands.push_back(tmp);
|
||||
}
|
||||
|
||||
//read buildings coords
|
||||
std::ifstream of("config/buildings.txt");
|
||||
while(!of.eof())
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
CTownHandler();
|
||||
~CTownHandler();
|
||||
std::vector<CTown> towns;
|
||||
std::vector<std::string> tcommands;
|
||||
std::vector<std::string> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user