mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Working windmill, water wheel, mystical garden (not tested).
Info windows. Minor changes.
This commit is contained in:
parent
d8103fd242
commit
736af28c05
@ -93,14 +93,14 @@ public:
|
||||
void draw();
|
||||
};
|
||||
class CResourceBar
|
||||
:public ClickableR, public CIntObject
|
||||
:public ClickableR
|
||||
{
|
||||
SDL_Surface * bg;
|
||||
void clickRight(tribool down);
|
||||
void refresh();
|
||||
};
|
||||
class CDataBar
|
||||
:public ClickableR, public CIntObject
|
||||
:public ClickableR
|
||||
{
|
||||
SDL_Surface * bg;
|
||||
void clickRight(tribool down);
|
||||
|
@ -38,6 +38,11 @@ void CCallback::newTurn()
|
||||
{
|
||||
//std::map<int, PlayerState>::iterator i = gs->players.begin() ;
|
||||
gs->day++;
|
||||
for (int i=0;i<CGI->objh->objInstances.size();i++)
|
||||
{
|
||||
if (CGI->objh->objInstances[i]->state)
|
||||
CGI->objh->objInstances[i]->state->newTurn();
|
||||
}
|
||||
for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||
{
|
||||
for (int j=0;j<(*i).second.heroes.size();j++)
|
||||
@ -373,6 +378,37 @@ int CScriptCallback::getSelectedHero()
|
||||
ret = -1;;
|
||||
return ret;
|
||||
}
|
||||
int CScriptCallback::getDate(int mode)
|
||||
{
|
||||
int temp;
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
return gs->day;
|
||||
break;
|
||||
case 1:
|
||||
temp = (gs->day)%7;
|
||||
if (temp)
|
||||
return temp;
|
||||
else return 7;
|
||||
break;
|
||||
case 2:
|
||||
temp = ((gs->day-1)/7)+1;
|
||||
if (!(temp%4))
|
||||
return 4;
|
||||
else
|
||||
return (temp%4);
|
||||
break;
|
||||
case 3:
|
||||
return ((gs->day-1)/28)+1;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void CScriptCallback::giveResource(int player, int which, int val)
|
||||
{
|
||||
gs->players[player].resources[which]+=val;
|
||||
}
|
||||
void CLuaCallback::registerFuncs(lua_State * L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
@ -397,7 +433,8 @@ void CLuaCallback::registerFuncs(lua_State * L)
|
||||
|
||||
|
||||
lua_setglobal(L, "vcmi");
|
||||
#undef REGISTER_C_FUNC(x)
|
||||
#undef REGISTER_C_FUNC(x)
|
||||
|
||||
}
|
||||
int CLuaCallback::getPos(lua_State * L)//(CGObjectInstance * object);
|
||||
{
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components);
|
||||
int getHeroOwner(int heroID);
|
||||
int getSelectedHero();
|
||||
int getDate(int mode=0);
|
||||
void giveResource(int player, int which, int val);
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
||||
class CLuaCallback : public CScriptCallback
|
||||
|
@ -5,7 +5,6 @@
|
||||
BOOST_TRIBOOL_THIRD_STATE(outOfRange)
|
||||
|
||||
using namespace boost::logic;
|
||||
class CAdvMapInt;
|
||||
class CCallback;
|
||||
class CGlobalAI;
|
||||
class CGHeroInstance;
|
||||
|
186
CLua.cpp
186
CLua.cpp
@ -15,6 +15,8 @@
|
||||
#include "CCallback.h"
|
||||
#include "hch/CGeneralTextHandler.h"
|
||||
#include <sstream>
|
||||
#include "CPlayerInterface.h"
|
||||
#pragma warning (disable : 4311)
|
||||
bool getGlobalFunc(lua_State * L, std::string fname)
|
||||
{
|
||||
unsigned int hash = lua_calchash(fname.c_str(), fname.size());
|
||||
@ -25,7 +27,7 @@ bool getGlobalFunc(lua_State * L, std::string fname)
|
||||
|
||||
CObjectScript::CObjectScript()
|
||||
{
|
||||
language == ESLan::UNDEF;
|
||||
language = ESLan::UNDEF;
|
||||
//std::cout << "Tworze obiekt objectscript "<<this<<std::endl;
|
||||
}
|
||||
|
||||
@ -107,7 +109,7 @@ void CLua::findFS(std::string fname)
|
||||
|
||||
CLuaObjectScript::CLuaObjectScript(std::string filename)
|
||||
{
|
||||
language == ESLan::LUA;
|
||||
language = ESLan::LUA;
|
||||
open(filename);
|
||||
//binit = bnewobject = bonherovisit = brightext = false;
|
||||
//std::cout << "Tworze obiekt CLuaObjectScript "<<this<<std::endl;
|
||||
@ -163,6 +165,7 @@ std::string CLuaObjectScript::hoverText(CGObjectInstance *os)
|
||||
}
|
||||
std::string ret = lua_tostring(is,1);
|
||||
lua_settop(is, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CCPPObjectScript::hoverText(CGObjectInstance *os)
|
||||
@ -197,6 +200,26 @@ void CVisitableOPH::onHeroVisit(CGObjectInstance *os, int heroID)
|
||||
};
|
||||
void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited)
|
||||
{
|
||||
int w=0, ot=0;
|
||||
switch(os->ID)
|
||||
{
|
||||
case 51:
|
||||
w=0;
|
||||
ot=80;
|
||||
break;
|
||||
case 23:
|
||||
w=1;
|
||||
ot=39;
|
||||
break;
|
||||
case 61:
|
||||
w=2;
|
||||
ot=100;
|
||||
break;
|
||||
case 32:
|
||||
w=3;
|
||||
ot=59;
|
||||
break;
|
||||
}
|
||||
if (!alreadyVisited)
|
||||
{
|
||||
switch (os->ID)
|
||||
@ -206,36 +229,21 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
|
||||
case 61:
|
||||
case 32:
|
||||
{
|
||||
int w=0, ot=0;
|
||||
switch(os->ID)
|
||||
{
|
||||
case 51:
|
||||
w=0;
|
||||
ot=80;
|
||||
break;
|
||||
case 23:
|
||||
w=1;
|
||||
ot=29;
|
||||
break;
|
||||
case 61:
|
||||
w=2;
|
||||
ot=100;
|
||||
break;
|
||||
case 32:
|
||||
w=3;
|
||||
ot=59;
|
||||
break;
|
||||
}
|
||||
cb->changePrimSkill(heroID,w,1);
|
||||
std::vector<SComponent*> weko;
|
||||
weko.push_back(new SComponent(SComponent::primskill,1,1));
|
||||
cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko);
|
||||
for (int ii=0; ii<weko.size();ii++)
|
||||
delete weko[ii];
|
||||
weko.push_back(new SComponent(SComponent::primskill,w,1));
|
||||
cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko); //TODO: maybe we have memory leak with these windows
|
||||
//for (int ii=0; ii<weko.size();ii++)
|
||||
// delete weko[ii];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ot++;
|
||||
cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&std::vector<SComponent*>());
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> CVisitableOPH::yourObjects()
|
||||
@ -282,6 +290,104 @@ std::string CVisitableOPH::hoverText(CGObjectInstance *os)
|
||||
return CGI->objh->objects[os->defInfo->id].name + add;
|
||||
}
|
||||
|
||||
void CVisitableOPW::onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited)
|
||||
{
|
||||
int mid;
|
||||
switch (os->ID)
|
||||
{
|
||||
case 55:
|
||||
mid = 92;
|
||||
break;
|
||||
case 112:
|
||||
mid = 170;
|
||||
break;
|
||||
case 109:
|
||||
mid = 164;
|
||||
break;
|
||||
}
|
||||
if (alreadyVisited)
|
||||
{
|
||||
if (os->ID!=112)
|
||||
mid++;
|
||||
else
|
||||
mid--;
|
||||
cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[mid],&std::vector<SComponent*>()); //TODO: maybe we have memory leak with these windows
|
||||
}
|
||||
else
|
||||
{
|
||||
int type, sub, val;
|
||||
type = SComponent::resource;
|
||||
switch (os->ID)
|
||||
{
|
||||
case 55:
|
||||
if (rand()%2)
|
||||
{
|
||||
sub = 5;
|
||||
val = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
sub = 6;
|
||||
val = 500;
|
||||
}
|
||||
break;
|
||||
case 112:
|
||||
mid = 170;
|
||||
sub = rand() % 6;
|
||||
val = (rand() % 4) + 3;
|
||||
break;
|
||||
case 109:
|
||||
mid = 164;
|
||||
sub = 6;
|
||||
if(cb->getDate(2)<2)
|
||||
val = 500;
|
||||
else
|
||||
val = 1000;
|
||||
}
|
||||
SComponent * com = new SComponent((SComponent::Etype)type,sub,val);
|
||||
std::vector<SComponent*> weko;
|
||||
weko.push_back(com);
|
||||
cb->giveResource(cb->getHeroOwner(heroID),sub,val);
|
||||
cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[mid],&weko);
|
||||
visited[os] = true;
|
||||
}
|
||||
}
|
||||
void CVisitableOPW::newTurn ()
|
||||
{
|
||||
if (cb->getDate(1)==1)
|
||||
{
|
||||
for (std::map<CGObjectInstance*,bool>::iterator i = visited.begin(); i != visited.end(); i++)
|
||||
{
|
||||
(*i).second = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
void CVisitableOPW::newObject(CGObjectInstance *os)
|
||||
{
|
||||
visited.insert(std::pair<CGObjectInstance*,bool>(os,false));
|
||||
}
|
||||
|
||||
void CVisitableOPW::onHeroVisit(CGObjectInstance *os, int heroID)
|
||||
{
|
||||
if(visited[os])
|
||||
onNAHeroVisit(os,heroID,true);
|
||||
else
|
||||
onNAHeroVisit(os,heroID,false);
|
||||
}
|
||||
|
||||
std::vector<int> CVisitableOPW::yourObjects() //returns IDs of objects which are handled by script
|
||||
{
|
||||
std::vector<int> ret(3);
|
||||
ret.push_back(55); //mystical garden
|
||||
ret.push_back(112); //windmill
|
||||
ret.push_back(109); //water wheel
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CVisitableOPW::hoverText(CGObjectInstance *os)
|
||||
{
|
||||
return CGI->objh->objects[os->defInfo->id].name + " " + ( (visited[os]) ? (CGI->generaltexth->allTexts[352]) : (CGI->generaltexth->allTexts[353])) ;
|
||||
}
|
||||
|
||||
//std::string SComponent::getSubtitle()
|
||||
//{
|
||||
@ -292,30 +398,4 @@ std::string CVisitableOPH::hoverText(CGObjectInstance *os)
|
||||
//}
|
||||
//void SComponent::getDescription(Etype Type, int Subtype)
|
||||
//{
|
||||
//}
|
||||
SComponent::SComponent(Etype Type, int Subtype, int Val)
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
case primskill:
|
||||
description = CGI->generaltexth->arraytxt[2+Subtype];
|
||||
std::ostringstream oss;
|
||||
oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
|
||||
subtitle = oss.str();
|
||||
break;
|
||||
}
|
||||
type = Type;
|
||||
subtype = Subtype;
|
||||
val = Val;
|
||||
}
|
||||
|
||||
SDL_Surface * SComponent::getImg()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case primskill:
|
||||
return CGI->heroh->pskillsb[subtype].ourImages[0].bitmap;
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
//}
|
26
CLua.h
26
CLua.h
@ -25,6 +25,8 @@ public:
|
||||
virtual void newObject(CGObjectInstance *os){};
|
||||
virtual void onHeroVisit(CGObjectInstance *os, int heroID){};
|
||||
virtual std::string hoverText(CGObjectInstance *os){return "";};
|
||||
virtual void newTurn (){};
|
||||
|
||||
|
||||
//TODO: implement functions below:
|
||||
virtual void equipArtefact(int HID, int AID, int slot, bool putOn){}; //putOn==0 means that artifact is taken off
|
||||
@ -34,7 +36,6 @@ public:
|
||||
//virtual void mouseClick (down,left,screen?, pos??){};
|
||||
virtual void heroLevelUp (int HID){}; //add possibility of changing available sec. skills
|
||||
|
||||
|
||||
};
|
||||
class CScript
|
||||
{
|
||||
@ -100,19 +101,16 @@ class CVisitableOPH : public CCPPObjectScript //once per hero
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
||||
|
||||
struct SComponent
|
||||
class CVisitableOPW : public CCPPObjectScript //once per week
|
||||
{
|
||||
enum Etype
|
||||
{
|
||||
primskill, secskill, resource, creature, artifact
|
||||
} type;
|
||||
int subtype;
|
||||
int val;
|
||||
CVisitableOPW(CScriptCallback * CB):CCPPObjectScript(CB){};
|
||||
std::map<CGObjectInstance*,bool> visited;
|
||||
void onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited);
|
||||
void newObject(CGObjectInstance *os);
|
||||
void onHeroVisit(CGObjectInstance *os, int heroID);
|
||||
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
||||
std::string hoverText(CGObjectInstance *os);
|
||||
void newTurn ();
|
||||
|
||||
std::string description; //r-click
|
||||
std::string subtitle;
|
||||
|
||||
SComponent(Etype Type, int Subtype, int Val);
|
||||
//SComponent(const & SComponent r);
|
||||
SDL_Surface * getImg();
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
8
CMT.cpp
8
CMT.cpp
@ -218,7 +218,9 @@ void initGameState(CGameInfo * cgi)
|
||||
/****************************C++ OBJECT SCRIPTS************************************************/
|
||||
std::map<int,CCPPObjectScript*> scripts;
|
||||
CScriptCallback * csc = new CScriptCallback();
|
||||
csc->gs = cgi->state;
|
||||
handleCPPObjS(&scripts,new CVisitableOPH(csc));
|
||||
handleCPPObjS(&scripts,new CVisitableOPW(csc));
|
||||
//created map
|
||||
|
||||
|
||||
@ -330,6 +332,8 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
cgi->screenh = new CScreenHandler;
|
||||
cgi->screenh->initScreen();
|
||||
|
||||
THC std::cout<<"Preparing first handlers: "<<tmh.getDif()<<std::endl;
|
||||
|
||||
//colors initialization
|
||||
SDL_Color p;
|
||||
p.unused = 0;
|
||||
@ -352,6 +356,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray
|
||||
cgi->neutralColor = p;//gray
|
||||
//colors initialized
|
||||
THC std::cout<<"Preparing players' colours: "<<tmh.getDif()<<std::endl;
|
||||
CMessage::init();
|
||||
cgi->townh = new CTownHandler;
|
||||
cgi->townh->loadNames();
|
||||
@ -364,6 +369,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
cgi->heroh = heroh;
|
||||
cgi->generaltexth = new CGeneralTextHandler;
|
||||
cgi->generaltexth->load();
|
||||
THC std::cout<<"Preparing more handlers: "<<tmh.getDif()<<std::endl;
|
||||
|
||||
//initializing hero flags
|
||||
|
||||
@ -641,7 +647,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
|
||||
//hero flags initialized
|
||||
|
||||
THC std::cout<<"Preparing first handlers: "<<tmh.getDif()<<std::endl;
|
||||
THC std::cout<<"Initializing colours and flags: "<<tmh.getDif()<<std::endl;
|
||||
CPreGame * cpg = new CPreGame(); //main menu and submenus
|
||||
THC std::cout<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
|
||||
cpg->mush = mush;
|
||||
|
87
CMessage.cpp
87
CMessage.cpp
@ -275,45 +275,76 @@ CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline
|
||||
{
|
||||
//TODO: support for more than one component
|
||||
CInfoWindow * ret = new CInfoWindow();
|
||||
|
||||
std::vector<std::string> * brtext = breakText(text,32,true,true);
|
||||
std::vector<std::string> * brdtext = breakText(comps[0]->subtitle,12,true,true);
|
||||
ret->components = comps;
|
||||
//for (int i=0;i<comps.size();i++)
|
||||
// comps[i]->
|
||||
std::vector<std::string> * brtext = breakText(text,charperline,true,true);
|
||||
std::vector<std::string> * brdtext;
|
||||
if (comps.size())
|
||||
brdtext = breakText(comps[0]->subtitle,12,true,true);
|
||||
else
|
||||
brdtext = NULL;
|
||||
std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
|
||||
std::pair<int,int> txts = getMaxSizes(txtg);
|
||||
txts.second = txts.second
|
||||
+ 30 //space to first component
|
||||
+ comps[0]->getImg()->h
|
||||
+ brdtext->size() * 10 //subtitle //!!!!!!!!!!!!!!!!!!!!
|
||||
+ 20 // space between subtitle and button
|
||||
+ ok->ourImages[0].bitmap->h //button
|
||||
+ 30; //after button
|
||||
+ 15 //after button
|
||||
+ 20; // space between subtitle and button
|
||||
if (comps.size())
|
||||
txts.second = txts.second
|
||||
+ 30 //space to first component
|
||||
+ comps[0]->getImg()->h
|
||||
+ 5 //img <-> subtitle
|
||||
+ brdtext->size() * 10; //subtitle //!!!!!!!!!!!!!!!!!!!!
|
||||
ret->bitmap = drawBox1(txts.first+70,txts.second+70,0);
|
||||
ret->pos.h=ret->bitmap->h;
|
||||
ret->pos.w=ret->bitmap->w;
|
||||
|
||||
int curh = 30; //gorny margines
|
||||
for (int i=0; i<txtg->size();i++)
|
||||
{
|
||||
int lw=0;
|
||||
for (int j=0;j<(*txtg)[i].size();j++)
|
||||
lw+=(*txtg)[i][j]->w;
|
||||
int pw = ret->bitmap->w/2;
|
||||
//int pw = Tmar, ph = Lmar;
|
||||
pw -= lw/2;
|
||||
|
||||
//for (int i=0; i<txtg->size();i++)
|
||||
//{
|
||||
// int lw=0;
|
||||
// for (int j=0;j<(*txtg)[i].size();j++)
|
||||
// lw+=(*txtg)[i][j]->w;
|
||||
// int pw = ret->bitmap->w/2, ph = ret->bitmap->h/2;
|
||||
// //int pw = Tmar, ph = Lmar;
|
||||
// pw -= lw/2;
|
||||
// ph -= (19*txtg->size())/2;
|
||||
int tw = pw;
|
||||
for (int j=0;j<(*txtg)[i].size();j++) //blit text
|
||||
{
|
||||
//std::stringstream n;
|
||||
//n <<"temp_"<<i<<"__"<<j<<".bmp";
|
||||
//SDL_SaveBMP(ret->bitmap,n.str().c_str());
|
||||
blitAt((*txtg)[i][j],tw,curh+i*19,ret->bitmap);
|
||||
tw+=(*txtg)[i][j]->w;
|
||||
SDL_FreeSurface((*txtg)[i][j]);
|
||||
}
|
||||
}
|
||||
curh += (19 * txtg->size()); //wys. tekstu
|
||||
|
||||
// int tw = pw;
|
||||
// for (int j=0;j<(*txtg)[i].size();j++)
|
||||
// {
|
||||
// //std::stringstream n;
|
||||
// //n <<"temp_"<<i<<"__"<<j<<".bmp";
|
||||
// blitAt((*txtg)[i][j],tw,ph+i*19,ret->bitmap);
|
||||
// //SDL_SaveBMP(ret->bitmap,n.str().c_str());
|
||||
// tw+=(*txtg)[i][j]->w;
|
||||
// SDL_FreeSurface((*txtg)[i][j]);
|
||||
// }
|
||||
//}
|
||||
if (comps.size())
|
||||
{
|
||||
curh += 30;
|
||||
comps[0]->pos.x = (ret->bitmap->w/2) - ((comps[0]->getImg()->w)/2);
|
||||
comps[0]->pos.y = curh;
|
||||
blitAt(comps[0]->getImg(),comps[0]->pos.x,comps[0]->pos.y,ret->bitmap);
|
||||
curh += comps[0]->getImg()->h + 5; //obrazek + przerwa
|
||||
for (int i=0; i<brdtext->size();i++) //descr.
|
||||
{
|
||||
SDL_Surface * tesu = TTF_RenderText_Blended(GEOR13,(*brdtext)[i].c_str(),zwykly);
|
||||
blitAt(tesu,((comps[0]->getImg()->w - tesu->w)/2)+comps[0]->pos.x,curh,ret->bitmap);
|
||||
curh+=tesu->h;
|
||||
SDL_FreeSurface(tesu);
|
||||
}
|
||||
}
|
||||
|
||||
curh += 20; //to buttton
|
||||
|
||||
ret->okb.posr.x = (ret->bitmap->w/2) - (ret->okb.imgs[0][0]->w/2);
|
||||
ret->okb.posr.y = curh;
|
||||
ret->okb.show();
|
||||
curh+=ret->okb.imgs[0][0]->h;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ class CDefHandler;
|
||||
struct SComponent;
|
||||
namespace NMessage
|
||||
{
|
||||
extern CDefHandler * ok, *cancel;
|
||||
extern std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
|
||||
extern SDL_Surface * background ;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <sstream>
|
||||
#include "hch/CHeroHandler.h"
|
||||
#include "SDL_framerate.h"
|
||||
#include "hch/CGeneralTextHandler.h"
|
||||
using namespace CSDL_Ext;
|
||||
|
||||
class OCM_HLP_CGIN
|
||||
@ -24,11 +25,142 @@ public:
|
||||
return (*a.first)<(*b.first);
|
||||
}
|
||||
} ocmptwo_cgin ;
|
||||
CInfoWindow::CInfoWindow()
|
||||
:okb(NMessage::ok,NULL,&CInfoWindow::okClicked)
|
||||
{
|
||||
okb.ourObj = this;
|
||||
okb.delg = this;
|
||||
}
|
||||
|
||||
void CInfoWindow::okClicked(tribool down)
|
||||
{
|
||||
if (!down)
|
||||
close();
|
||||
}
|
||||
|
||||
void CInfoWindow::close()
|
||||
{
|
||||
for (int i=0;i<components.size();i++)
|
||||
delete components[i];
|
||||
okb.deactivate();
|
||||
SDL_FreeSurface(bitmap);
|
||||
bitmap = NULL;
|
||||
LOCPLINT->removeObjToBlit(this);
|
||||
//delete this;
|
||||
LOCPLINT->adventureInt->show();
|
||||
}
|
||||
CInfoWindow::~CInfoWindow()
|
||||
{
|
||||
}
|
||||
SComponent::SComponent(Etype Type, int Subtype, int Val)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
switch (Type)
|
||||
{
|
||||
case primskill:
|
||||
description = CGI->generaltexth->arraytxt[2+Subtype];
|
||||
oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
|
||||
subtitle = oss.str();
|
||||
break;
|
||||
case resource:
|
||||
//description = CGI->generaltexth->arraytxt[2+Subtype];
|
||||
std::ostringstream oss;
|
||||
oss << Val;
|
||||
subtitle = oss.str();
|
||||
break;
|
||||
}
|
||||
type = Type;
|
||||
subtype = Subtype;
|
||||
val = Val;
|
||||
SDL_Surface * temp = getImg();
|
||||
pos.w = temp->w;
|
||||
pos.h = temp->h;
|
||||
}
|
||||
|
||||
SDL_Surface * SComponent::getImg()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case primskill:
|
||||
return CGI->heroh->pskillsb->ourImages[subtype].bitmap;
|
||||
break;
|
||||
case resource:
|
||||
return CGI->heroh->resources->ourImages[subtype].bitmap;
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SComponent::clickRight (tribool down)
|
||||
{
|
||||
LOCPLINT->adventureInt->handleRightClick(description,down,this);
|
||||
}
|
||||
void SComponent::activate()
|
||||
{
|
||||
ClickableR::activate();
|
||||
}
|
||||
void SComponent::deactivate()
|
||||
{
|
||||
ClickableR::deactivate();
|
||||
}
|
||||
CSimpleWindow::~CSimpleWindow()
|
||||
{
|
||||
if (bitmap)
|
||||
{
|
||||
SDL_FreeSurface(bitmap);
|
||||
bitmap=NULL;
|
||||
bitmap=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>CSCButton<T>::CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg)
|
||||
{
|
||||
ourObj = obj;
|
||||
delg = Delg;
|
||||
func = poin;
|
||||
imgs.resize(1);
|
||||
for (int i =0; i<img->ourImages.size();i++)
|
||||
{
|
||||
imgs[0].push_back(img->ourImages[i].bitmap);
|
||||
}
|
||||
pos.w = imgs[0][0]->w;
|
||||
pos.h = imgs[0][0]->h;
|
||||
state = 0;
|
||||
}
|
||||
template <typename T> void CSCButton<T>::clickLeft (tribool down)
|
||||
{
|
||||
if (down)
|
||||
{
|
||||
state=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
state=0;
|
||||
}
|
||||
show();
|
||||
if (delg)
|
||||
(delg->*func)(down);
|
||||
pressedL=state;
|
||||
}
|
||||
template <typename T> void CSCButton<typename T>::activate()
|
||||
{
|
||||
ClickableL::activate();
|
||||
}
|
||||
template <typename T> void CSCButton<typename T>::deactivate()
|
||||
{
|
||||
ClickableL::deactivate();
|
||||
}
|
||||
|
||||
template <typename T> void CSCButton<typename T>::show()
|
||||
{
|
||||
if (delg)
|
||||
{
|
||||
blitAt(imgs[curimg][state],posr.x,posr.y,delg->bitmap);
|
||||
updateRect(&genRect(pos.h,pos.w,posr.x,posr.y),delg->bitmap);
|
||||
}
|
||||
else
|
||||
{
|
||||
CButtonBase::show();
|
||||
}
|
||||
}
|
||||
CButtonBase::CButtonBase()
|
||||
{
|
||||
@ -1061,7 +1193,20 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int
|
||||
adventureInt->infoBar.draw();
|
||||
return;
|
||||
}
|
||||
void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> components)
|
||||
void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
|
||||
{
|
||||
;
|
||||
adventureInt->hide();
|
||||
CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
|
||||
LOCPLINT->objsToBlit.push_back(temp);
|
||||
temp->pos.x=300-(temp->pos.w/2);
|
||||
temp->pos.y=300-(temp->pos.h/2);
|
||||
temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
|
||||
temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
|
||||
temp->okb.activate();
|
||||
}
|
||||
void CPlayerInterface::removeObjToBlit(CSimpleWindow* obj)
|
||||
{
|
||||
objsToBlit.erase
|
||||
(std::find(objsToBlit.begin(),objsToBlit.end(),obj));
|
||||
//delete obj;
|
||||
}
|
@ -10,7 +10,7 @@ class CDefHandler;
|
||||
struct HeroMoveDetails;
|
||||
class CDefEssential;
|
||||
class CGHeroInstance;
|
||||
struct SComponent;
|
||||
class CAdvMapInt;
|
||||
class CIntObject //interface object
|
||||
{
|
||||
public:
|
||||
@ -25,19 +25,13 @@ public:
|
||||
CSimpleWindow():bitmap(NULL),owner(NULL){};
|
||||
virtual ~CSimpleWindow();
|
||||
};
|
||||
class CInfoWindow : public CSimpleWindow //text + comp. + ok button
|
||||
{
|
||||
public:
|
||||
std::vector<SComponent *> components;
|
||||
CInfoWindow(){};
|
||||
};
|
||||
class CButtonBase : public virtual CIntObject //basic buttton class
|
||||
{
|
||||
public:
|
||||
int type; //advmapbutton=2
|
||||
bool abs;
|
||||
bool active;
|
||||
CIntObject * ourObj;
|
||||
CIntObject * ourObj; // "owner"
|
||||
int state;
|
||||
std::vector< std::vector<SDL_Surface*> > imgs;
|
||||
int curimg;
|
||||
@ -45,6 +39,7 @@ public:
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
CButtonBase();
|
||||
virtual ~CButtonBase(){};
|
||||
};
|
||||
class ClickableL : public virtual CIntObject //for left-clicks
|
||||
{
|
||||
@ -87,6 +82,54 @@ public:
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
|
||||
template <typename T> class CSCButton: public CButtonBase, public ClickableL //prosty guzik, ktory tylko zmienia obrazek
|
||||
{
|
||||
public:
|
||||
int3 posr; //position in the bitmap
|
||||
int state;
|
||||
T* delg;
|
||||
void(T::*func)(tribool);
|
||||
CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg=NULL);
|
||||
void clickLeft (tribool down);
|
||||
void activate();
|
||||
void deactivate();
|
||||
void show();
|
||||
};
|
||||
|
||||
class CInfoWindow : public CSimpleWindow //text + comp. + ok button
|
||||
{
|
||||
public:
|
||||
CSCButton<CInfoWindow> okb;
|
||||
std::vector<SComponent*> components;
|
||||
void okClicked(tribool down);
|
||||
void close();
|
||||
CInfoWindow();
|
||||
~CInfoWindow();
|
||||
};
|
||||
|
||||
class SComponent : public ClickableR
|
||||
{
|
||||
public:
|
||||
enum Etype
|
||||
{
|
||||
primskill, secskill, resource, creature, artifact
|
||||
} type;
|
||||
int subtype;
|
||||
int val;
|
||||
|
||||
std::string description; //r-click
|
||||
std::string subtitle;
|
||||
|
||||
SComponent(Etype Type, int Subtype, int Val);
|
||||
//SComponent(const & SComponent r);
|
||||
SDL_Surface * getImg();
|
||||
|
||||
void clickRight (tribool down);
|
||||
void activate();
|
||||
void deactivate();
|
||||
};
|
||||
|
||||
class CPlayerInterface : public CGameInterface
|
||||
{
|
||||
public:
|
||||
@ -121,7 +164,8 @@ public:
|
||||
void handleEvent(SDL_Event * sEvent);
|
||||
void init(CCallback * CB);
|
||||
int3 repairScreenPos(int3 pos);
|
||||
void showInfoDialog(std::string text, std::vector<SComponent*> components);
|
||||
void showInfoDialog(std::string text, std::vector<SComponent*> & components);
|
||||
void removeObjToBlit(CSimpleWindow* obj);
|
||||
|
||||
CPlayerInterface(int Player, int serial);
|
||||
};
|
BIN
CPreGame.cpp
BIN
CPreGame.cpp
Binary file not shown.
@ -91,13 +91,13 @@ public:
|
||||
: Button(Pos,Fun,Imgs,Sel,gr),key(My){ourPoinGroup=gr;};
|
||||
void select(bool on=true) {(*this).Button::select(on);ourPoinGroup->setYour(this);CPG->printRating();}
|
||||
};
|
||||
template <class T=ttt> class CPoinGroup :public CGroup<T>
|
||||
template <class T> class CPoinGroup :public CGroup<T>
|
||||
{
|
||||
public:
|
||||
int * gdzie; //where (po polsku, bo by by³o s³owo kluczowe :/)
|
||||
void setYour(IntSelBut<T> * your){*gdzie=your->key;};
|
||||
};
|
||||
template <class T=ttt> class CGroup
|
||||
template <class T> class CGroup
|
||||
{
|
||||
public:
|
||||
Button<T> * selected;
|
||||
|
@ -40,6 +40,7 @@ void CHeroHandler::loadPortraits()
|
||||
}
|
||||
of.close();
|
||||
pskillsb = CGI->spriteh->giveDef("PSKILL.DEF");
|
||||
resources = CGI->spriteh->giveDef("RESOUR82.DEF");
|
||||
|
||||
std::string strs = CGI->bitmaph->getTextFile("PRISKILL.TXT");
|
||||
int itr=0;
|
||||
|
@ -69,7 +69,7 @@ public:
|
||||
unsigned int getTileCost(EterrainType & ttype, Eroad & rdtype, Eriver & rvtype);
|
||||
unsigned int getLowestCreatureSpeed();
|
||||
unsigned int getAdditiveMoveBonus();
|
||||
unsigned float getMultiplicativeMoveBonus();
|
||||
float getMultiplicativeMoveBonus();
|
||||
static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
|
||||
int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
|
||||
int getSightDistance() const; //returns sight distance of this hero
|
||||
@ -89,7 +89,7 @@ public:
|
||||
std::vector<CHero*> heroes; //by³o nodrze
|
||||
std::vector<CHeroClass *> heroClasses;
|
||||
std::vector<CDefHandler *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,
|
||||
CDefHandler * pskillsb; //82x93
|
||||
CDefHandler * pskillsb, *resources; //82x93
|
||||
std::vector<std::string> pskillsn;
|
||||
unsigned int level(unsigned int experience);
|
||||
void loadHeroes();
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
|
||||
|
||||
int readNormalNr (int pos, int bytCon, unsigned char * str)
|
||||
{
|
||||
int ret=0;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "CDefObjInfoHandler.h"
|
||||
#include "../CLua.h"
|
||||
#include "CHeroHandler.h"
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
void CObjectHandler::loadObjects()
|
||||
{
|
||||
int ID=0;
|
||||
@ -28,6 +29,8 @@ void CObjectHandler::loadObjects()
|
||||
while (it<buf.length()-1)
|
||||
{
|
||||
CGeneralTextHandler::loadToIt(temp,buf,it,3);
|
||||
temp = temp.substr(1,temp.length()-2);
|
||||
boost::algorithm::replace_all(temp,"\"\"","\"");
|
||||
advobtxt.push_back(temp);
|
||||
}
|
||||
|
||||
@ -122,9 +125,9 @@ bool CGObjectInstance::visitableAt(int x, int y) const //returns true if ibject
|
||||
}
|
||||
bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen printing priority comparing
|
||||
{
|
||||
if(defInfo->printPriority==1 && defInfo->printPriority==0)
|
||||
if(defInfo->printPriority==1 && cmp.defInfo->printPriority==0)
|
||||
return true;
|
||||
if(defInfo->printPriority==1 && defInfo->printPriority==0)
|
||||
if(cmp.defInfo->printPriority==1 && defInfo->printPriority==0)
|
||||
return false;
|
||||
if(this->pos.y<cmp.pos.y)
|
||||
return true;
|
||||
@ -277,6 +280,7 @@ CGObjectInstance::CGObjectInstance(const CGObjectInstance & right)
|
||||
defInfo = right.defInfo;
|
||||
info = right.info;
|
||||
defObjInfoNumber = right.defObjInfoNumber;
|
||||
blockVisit = false;
|
||||
//state = new CLuaObjectScript(right.state->);
|
||||
//*state = *right.state;
|
||||
//state = right.state;
|
||||
@ -291,6 +295,7 @@ CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
|
||||
defInfo = right.defInfo;
|
||||
info = right.info;
|
||||
defObjInfoNumber = right.defObjInfoNumber;
|
||||
blockVisit = right.blockVisit;
|
||||
//state = new CLuaObjectScript();
|
||||
//*state = *right.state;
|
||||
tempOwner = right.tempOwner;
|
||||
|
@ -367,6 +367,7 @@ public:
|
||||
int defObjInfoNumber;
|
||||
|
||||
int tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna
|
||||
bool blockVisit;
|
||||
|
||||
virtual bool isHero() const;
|
||||
int getOwner() const;
|
||||
@ -405,7 +406,7 @@ public:
|
||||
unsigned int getTileCost(EterrainType & ttype, Eroad & rdtype, Eriver & rvtype);
|
||||
unsigned int getLowestCreatureSpeed();
|
||||
unsigned int getAdditiveMoveBonus();
|
||||
unsigned float getMultiplicativeMoveBonus();
|
||||
float getMultiplicativeMoveBonus();
|
||||
static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
|
||||
int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
|
||||
int getSightDistance() const; //returns sight distance of this hero
|
||||
|
4
map.h
4
map.h
@ -1,6 +1,6 @@
|
||||
#ifndef MAPD_H
|
||||
#define MAPD_H
|
||||
|
||||
#pragma warning (disable : 4482)
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "global.h"
|
||||
@ -174,7 +174,7 @@ public:
|
||||
struct Mapa
|
||||
{
|
||||
Eformat version; // version of map Eformat
|
||||
bool twoLevel; // if map has underground level
|
||||
int twoLevel; // if map has underground level
|
||||
int difficulty; // 0 easy - 4 impossible
|
||||
int levelLimit;
|
||||
bool areAnyPLayers; // if there are any playable players on map
|
||||
|
@ -1524,6 +1524,7 @@ std::string CMapHandler::getDefName(int id, int subid)
|
||||
if(CGI->dobjinfo->objs[i].type==id && CGI->dobjinfo->objs[i].subtype==subid)
|
||||
return CGI->dobjinfo->objs[i].defName;
|
||||
}
|
||||
throw new std::exception("Def not found.");
|
||||
}
|
||||
|
||||
bool CMapHandler::printObject(CGObjectInstance *obj)
|
||||
|
Loading…
Reference in New Issue
Block a user