mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Some code for town hall screen.
This commit is contained in:
parent
0379fbfc1d
commit
c3249d3fd7
@ -80,8 +80,11 @@ void CBuildingRect::hover(bool on)
|
||||
void CBuildingRect::clickLeft (tribool down)
|
||||
{
|
||||
|
||||
if(area && (CSDL_Ext::SDL_GetPixel(area,LOCPLINT->current->motion.x-pos.x,LOCPLINT->current->motion.y-pos.y) != 0)) //na polu
|
||||
if(area && (LOCPLINT->castleInt->hBuild==this) && !(indeterminate(down)) && (CSDL_Ext::SDL_GetPixel(area,LOCPLINT->current->motion.x-pos.x,LOCPLINT->current->motion.y-pos.y) != 0)) //na polu
|
||||
{
|
||||
if(pressedL && !down)
|
||||
LOCPLINT->castleInt->buildingClicked(str->ID);
|
||||
ClickableL::clickLeft(down);
|
||||
}
|
||||
|
||||
|
||||
@ -89,7 +92,7 @@ void CBuildingRect::clickLeft (tribool down)
|
||||
}
|
||||
void CBuildingRect::clickRight (tribool down)
|
||||
{
|
||||
if((!area) || (!((bool)down)))
|
||||
if((!area) || (!((bool)down)) || (this!=LOCPLINT->castleInt->hBuild))
|
||||
return;
|
||||
if((CSDL_Ext::SDL_GetPixel(area,LOCPLINT->current->motion.x-pos.x,LOCPLINT->current->motion.y-pos.y) != 0)) //na polu
|
||||
{
|
||||
@ -345,17 +348,33 @@ void CCastleInterface::close()
|
||||
void CCastleInterface::splitF()
|
||||
{
|
||||
}
|
||||
void CCastleInterface::buildingClicked(int building)
|
||||
{
|
||||
std::cout<<"You've clicked on "<<building<<std::endl;
|
||||
switch(building)
|
||||
{
|
||||
case 10: case 11: case 12: case 13:
|
||||
enterHall();
|
||||
break;
|
||||
default:
|
||||
std::cout<<"This building isn't handled...\n";
|
||||
}
|
||||
}
|
||||
void CCastleInterface::enterHall()
|
||||
{
|
||||
deactivate();
|
||||
}
|
||||
void CCastleInterface::showAll(SDL_Surface * to)
|
||||
{
|
||||
if (!to)
|
||||
to=ekran;
|
||||
statusbar->show();
|
||||
blitAt(cityBg,0,0,to);
|
||||
blitAt(townInt,0,374,to);
|
||||
LOCPLINT->adventureInt->resdatabar.draw();
|
||||
townlist->draw();
|
||||
statusbar->show();
|
||||
|
||||
garr->show();
|
||||
garr->show();
|
||||
int pom;
|
||||
|
||||
//draw fort icon
|
||||
@ -491,4 +510,56 @@ void CCastleInterface::deactivate()
|
||||
split->deactivate();
|
||||
for(int i=0;i<buildings.size();i++)
|
||||
buildings[i]->deactivate();
|
||||
}
|
||||
|
||||
|
||||
void CHallInterface::CResDataBar::show(SDL_Surface * to)
|
||||
{
|
||||
}
|
||||
CHallInterface::CResDataBar::CResDataBar()
|
||||
{
|
||||
}
|
||||
CHallInterface::CResDataBar::~CResDataBar()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CHallInterface::CBuildingBox::hover(bool on)
|
||||
{
|
||||
}
|
||||
void CHallInterface::CBuildingBox::clickLeft (tribool down)
|
||||
{
|
||||
}
|
||||
void CHallInterface::CBuildingBox::clickRight (tribool down)
|
||||
{
|
||||
}
|
||||
void CHallInterface::CBuildingBox::activate()
|
||||
{
|
||||
}
|
||||
void CHallInterface::CBuildingBox::deactivate()
|
||||
{
|
||||
}
|
||||
CHallInterface::CBuildingBox::~CBuildingBox()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CHallInterface::CHallInterface(CCastleInterface * owner)
|
||||
{
|
||||
|
||||
}
|
||||
CHallInterface::~CHallInterface()
|
||||
{
|
||||
}
|
||||
void CHallInterface::close()
|
||||
{
|
||||
}
|
||||
void CHallInterface::show(SDL_Surface * to)
|
||||
{
|
||||
}
|
||||
void CHallInterface::activate()
|
||||
{
|
||||
}
|
||||
void CHallInterface::deactivate()
|
||||
{
|
||||
}
|
@ -50,8 +50,50 @@ public:
|
||||
void townChange();
|
||||
void show(SDL_Surface * to=NULL);
|
||||
void showAll(SDL_Surface * to=NULL);
|
||||
void buildingClicked(int building);
|
||||
void enterHall();
|
||||
void close();
|
||||
void splitF();
|
||||
void activate();
|
||||
void deactivate();
|
||||
};
|
||||
|
||||
class CHallInterface : public IShowable, public IActivable
|
||||
{
|
||||
public:
|
||||
class CResDataBar : public IShowable, public CIntObject
|
||||
{
|
||||
public:
|
||||
SDL_Surface *bg;
|
||||
void show(SDL_Surface * to=NULL);
|
||||
CResDataBar();
|
||||
~CResDataBar();
|
||||
} resdatabar;
|
||||
|
||||
class CBuildingBox : public Hoverable, public ClickableL, public ClickableR
|
||||
{
|
||||
public:
|
||||
int ID;
|
||||
int state;//(-1) - forbidden in this town, 0 - possible, 1 - lack of res, 2 - requirements/buildings per turn limit, (3) - already exists
|
||||
void hover(bool on);
|
||||
void clickLeft (tribool down);
|
||||
void clickRight (tribool down);
|
||||
void activate();
|
||||
void deactivate();
|
||||
~CBuildingBox();
|
||||
};
|
||||
|
||||
std::vector<CBuildingBox*> boxes[5];
|
||||
|
||||
AdventureMapButton<CHallInterface> * exit;
|
||||
|
||||
SDL_Surface * bg;
|
||||
|
||||
|
||||
CHallInterface(CCastleInterface * owner);
|
||||
~CHallInterface();
|
||||
void close();
|
||||
void show(SDL_Surface * to=NULL);
|
||||
void activate();
|
||||
void deactivate();
|
||||
};
|
@ -5,17 +5,7 @@
|
||||
#include "SDL_Thread.h"
|
||||
#include "SDL_Extensions.h"
|
||||
|
||||
class CStack
|
||||
{
|
||||
public:
|
||||
int ID;
|
||||
CCreature * creature;
|
||||
int amount;
|
||||
int owner;
|
||||
int position;
|
||||
bool alive;
|
||||
CStack(CCreature * C, int A, int O, int I):creature(C),amount(A),owner(O), alive(true), position(-1), ID(I){};
|
||||
};
|
||||
|
||||
|
||||
class CMP_stack
|
||||
{
|
||||
|
11
CGameState.h
11
CGameState.h
@ -32,6 +32,17 @@ struct BattleInfo
|
||||
CCreatureSet * army1, * army2;
|
||||
std::vector<CStack*> stacks;
|
||||
};
|
||||
class CStack
|
||||
{
|
||||
public:
|
||||
int ID;
|
||||
CCreature * creature;
|
||||
int amount;
|
||||
int owner;
|
||||
int position;
|
||||
bool alive;
|
||||
CStack(CCreature * C, int A, int O, int I):creature(C),amount(A),owner(O), alive(true), position(-1), ID(I){};
|
||||
};
|
||||
class CGameState
|
||||
{
|
||||
private:
|
||||
|
1
CLua.cpp
1
CLua.cpp
@ -589,6 +589,7 @@ std::string CPickable::hoverText(CGObjectInstance *os)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> CPickable::yourObjects() //returns IDs of objects which are handled by script
|
||||
{
|
||||
std::vector<int> ret(3);
|
||||
|
@ -32,6 +32,7 @@ class IActivable
|
||||
public:
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
virtual ~IActivable(){};
|
||||
};
|
||||
|
||||
class CIntObject //interface object
|
||||
|
@ -48,6 +48,14 @@ GROUP
|
||||
25
|
||||
34
|
||||
41
|
||||
GROUP
|
||||
17
|
||||
21
|
||||
GROUP
|
||||
31
|
||||
18
|
||||
38
|
||||
19
|
||||
CASTLE 2
|
||||
GROUP
|
||||
18
|
||||
|
75
config/hall.txt
Normal file
75
config/hall.txt
Normal file
@ -0,0 +1,75 @@
|
||||
9
|
||||
0
|
||||
TPTHBKCS.BMP
|
||||
10 11 12 13 | 7 8 9 | 5 22 | 16
|
||||
14 15 | 0 1 2 3 4 | 6
|
||||
21 | 24
|
||||
30 37 | 31 38 | 32 39 | 33 40
|
||||
34 41 | 35 42 | 36 43
|
||||
1
|
||||
TPTHBKRM.BMP
|
||||
10 11 12 13 | 7 8 9 | 5 | 16
|
||||
14 15 | 0 1 2 3 4 | 17 21
|
||||
22 | 24 25 | 18 19
|
||||
30 37 | 31 38 | 32 39 | 33 40
|
||||
34 41 | 35 42 | 36 43
|
||||
2
|
||||
TPTHBKTW.BMP
|
||||
10 11 12 13 | 7 8 9 | 5 | 16
|
||||
14 15 | 0 1 2 3 4 | 22 | 23
|
||||
17 | 21 | 18 19
|
||||
30 37 | 31 38 | 32 39 | 33 40
|
||||
34 41 | 35 42 | 36 43
|
||||
3
|
||||
TPTHBKIN.BMP
|
||||
10 11 12 13 | 7 8 9 | 5 | 16
|
||||
14 15 | 0 1 2 3 4 | 23 | 21
|
||||
22 | 18 19 | 24 25
|
||||
30 37 | 31 38 | 32 39 | 33 40
|
||||
34 41 | 35 42 | 36 43
|
||||
4
|
||||
TPTHBKNC.BMP
|
||||
10 11 12 13 | 7 8 9 | 5 | 16
|
||||
14 15 | 0 1 2 3 4 | 21 | 6
|
||||
17 | 22 | 18 19
|
||||
30 37 | 31 38 | 32 39 | 33 40
|
||||
34 41 | 35 42 | 36 43
|
||||
5
|
||||
TPTHBKDG.BMP
|
||||
10 11 12 13 | 7 8 9 | 5 | 16
|
||||
14 15 | 0 1 2 3 4 | 21 | 22
|
||||
17 | 23 | 18 19
|
||||
30 37 | 31 38 | 32 39 | 33 40
|
||||
34 41 | 35 42 | 36 43
|
||||
6
|
||||
TPTHBKST.BMP
|
||||
10 11 12 13 | 7 8 9 | 5 | 16
|
||||
14 15 | 0 1 2 3 4 | 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
|
||||
17 | 22 | 18 19
|
||||
30 37 | 31 38 | 32 39 | 33 40
|
||||
34 41 | 35 42 | 36 43
|
||||
8
|
||||
TPTHBKFR.BMP
|
||||
10 11 12 13 | 7 8 9 | 5 | 16
|
||||
14 15 | 0 1 2 3 4 | 6
|
||||
21 | 17 | 18 19
|
||||
30 37 | 31 38 | 32 39 | 33 40
|
||||
34 41 | 35 42 | 36 43
|
||||
|
||||
|
||||
file format:
|
||||
numberof castles
|
||||
* for each castle:
|
||||
castle ID
|
||||
first row buildings (ids for each box, boxes are separated with '|')
|
||||
sencond row buildings
|
||||
etc...
|
||||
|
||||
Warning: file is whitespace sensitive, don't add any spaces at end of the lines, or remove spaces between numbers and separators
|
@ -3,14 +3,15 @@
|
||||
#include "CBuildingHandler.h"
|
||||
#include "CLodHandler.h"
|
||||
#include <sstream>
|
||||
std::string readTo(std::string in, unsigned int &it, char end)
|
||||
#include <fstream>
|
||||
std::string readTo(std::string &in, unsigned int &it, char end)
|
||||
{
|
||||
int pom = it;
|
||||
int last = in.find_first_of(end,it);
|
||||
it+=(1+last-it);
|
||||
return in.substr(pom,last-pom);
|
||||
}
|
||||
unsigned int readNr(std::string in, unsigned int &it)
|
||||
unsigned int readNr(std::string &in, unsigned int &it)
|
||||
{
|
||||
int last=it;
|
||||
for(;last<in.size();last++)
|
||||
@ -131,4 +132,48 @@ void CBuildingHandler::loadBuildings()
|
||||
buildings[f][30+b]->description = readTo(buf,it,'\n');
|
||||
}
|
||||
}
|
||||
|
||||
char line[100]; //bufor
|
||||
std::ifstream ofs("config/hall.txt");
|
||||
int castles;
|
||||
ofs>>castles;
|
||||
for(int i=0;i<castles;i++)
|
||||
{
|
||||
int tid;
|
||||
unsigned int it, box=0;
|
||||
std::string pom;
|
||||
ofs >> tid >> pom;
|
||||
hall[tid].first = pom;
|
||||
(hall[tid].second).resize(5); //rows
|
||||
for(int j=0;j<5;j++)
|
||||
{
|
||||
box = it = 0;
|
||||
ofs.getline(line,100);
|
||||
if(!line[0])
|
||||
ofs.getline(line,100);
|
||||
std::string linia(line);
|
||||
bool areboxes=true;
|
||||
while(areboxes) //read all boxes
|
||||
{
|
||||
(hall[tid].second)[j].push_back(std::vector<int>()); //push new box
|
||||
int seppos = linia.find_first_of('|',it); //position of end of this box data
|
||||
if(seppos<0)
|
||||
seppos = linia.length();
|
||||
while(it<seppos)
|
||||
{
|
||||
int last = linia.find_first_of(' ',it);
|
||||
std::stringstream ss(linia.substr(it,last-it));
|
||||
it = last + 1;
|
||||
ss >> last;
|
||||
(hall[tid].second)[j][box].push_back(last);
|
||||
areboxes = it; //wyzeruje jak nie znajdzie kolejnej zpasji = koniec linii
|
||||
if(!it)
|
||||
it = seppos+1;
|
||||
}
|
||||
box++;
|
||||
it+=2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
#include "../global.h"
|
||||
#include <map>
|
||||
//enum EbuildingType {NEUTRAL=-1, CASTLE, RAMPART, TOWER, INFERNO, NECROPOLIS, DUNGEON, STRONGHOLD, FORTRESS, CONFLUX};
|
||||
|
||||
class CBuilding //a typical building encountered in every castle ;]
|
||||
{
|
||||
public:
|
||||
@ -19,22 +18,8 @@ class CBuildingHandler
|
||||
{
|
||||
public:
|
||||
std::map<int, std::map<int, CBuilding*> > buildings; ///< first int is the castle ID, second the building ID (in ERM-U format)
|
||||
//std::vector<CBuilding> buildings; //vector of buildings
|
||||
//std::vector<CBuilding> resourceSilos; //vector with resource silos only - for castle profiled descriptions
|
||||
//std::vector<CBuilding> grails; //vector with grail - type buildings only - for castle profiled descriptions
|
||||
//std::vector<CBuilding> blacksmiths; //vector with names and descriptions for blacksmith (castle - dependent)
|
||||
//CBuilding blacksmith; //global name and description for blacksmiths
|
||||
//CBuilding moat; //description and name of moat
|
||||
//CBuilding shipyard; //castle - independent name and description of shipyard
|
||||
//CBuilding shipyardWithShip; //name and description for shipyard with ship
|
||||
//CBuilding artMerchant; //name and description of artifact merchant
|
||||
//CBuilding l1horde, l2horde, l3horde, l4horde, l5horde; //castle - independent horde names and descriptions
|
||||
//CBuilding grail; //castle - independent grail description
|
||||
//CBuilding resSilo; //castle - independent resource silo name and description
|
||||
void loadBuildings(); //main loader, calls loading functions below
|
||||
void loadNames(); //loads castle - specufuc names and descriptoins
|
||||
void loadNeutNames(); //loads castle independent names and descriptions
|
||||
void loadDwellingNames(); //load names for dwellgins
|
||||
std::map<int, std::pair<std::string,std::vector< std::vector< std::vector<int> > > > > hall; //map<castle ID, pair<hall bg name, std::vector< std::vector<building id> >[5]> - external vector is the vector of buildings in the row, internal is the list of buildings for the specific slot
|
||||
void loadBuildings(); //main loader
|
||||
};
|
||||
|
||||
#endif //CBUILDINGHANDLER_H
|
@ -7,7 +7,7 @@
|
||||
#include <boost/assign/std/vector.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include "SDL_Extensions.h"
|
||||
#include "../SDL_Extensions.h"
|
||||
|
||||
int CCreature::getQuantityID(int quantity)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user