1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Several bugfixes and half-done things.

This commit is contained in:
Michał W. Urbańczyk 2007-12-01 12:50:33 +00:00
parent 7c0f9afc9f
commit e1b2ae0df1
8 changed files with 106 additions and 65 deletions

View File

@ -4,8 +4,8 @@ void CEmptyAI::init(CCallback * CB)
{
cb = CB;
human=false;
playerID=-1;
serialID=-1;
playerID=cb->getMyColor();
serialID=cb->getMySerial();
std::cout << "EmptyAI initialized." << std::endl;
}
void CEmptyAI::yourTurn()

View File

@ -1299,6 +1299,7 @@ void CAdvMapInt::show()
townList.activate();
townList.draw();
terrain.activate();
update();
resdatabar.draw();
@ -1376,7 +1377,11 @@ void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * c
{
for (int i=0;i<LOCPLINT->objsToBlit.size();i++)
{
if (LOCPLINT->objsToBlit[i]->owner==client)
//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));
}

View File

@ -125,6 +125,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
if (!blockvis)
{
curd.successful = true;
hero->pos = curd.dst;
int heroSight = hero->getSightDistance();
int xbeg = stpos.x - heroSight - 2;
@ -154,7 +155,6 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
}
}
hero->pos = curd.dst;
int nn=0; //number of interfece of currently browsed player
for(std::map<int, PlayerState>::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing
{
@ -174,7 +174,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID);
}
}
else
else //interaction with blocking object (like resources)
{
curd.successful = false;
CGI->playerint[gs->players[hero->getOwner()].serial]->heroMoved(curd);
@ -194,7 +194,6 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
}
else
return true; //move ended - no more movement points
//hero->pos = curd.dst;
}
return true;
}
@ -245,7 +244,7 @@ const CGHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) //
int CCallback::getResourceAmount(int type)
{
return gs->players[gs->currentPlayer].resources[type];
return gs->players[player].resources[type];
}
int CCallback::getDate(int mode)
@ -347,6 +346,14 @@ bool CCallback::isVisible(int3 pos)
return isVisible(pos,player);
}
int CCallback::getMyColor()
{
return player;
}
int CCallback::getMySerial()
{
return gs->players[player].serial;
}
int3 CScriptCallback::getPos(CGObjectInstance * ob)

View File

@ -48,6 +48,8 @@ public:
std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest
std::vector < const CGHeroInstance *> * getHeroesInfo(bool onlyOur=true);
bool isVisible(int3 pos);
int getMyColor();
int getMySerial();
//friends
friend int _tmain(int argc, _TCHAR* argv[]);

View File

@ -200,7 +200,47 @@ std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> >
}
return ret;
}
SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret)
{
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; //lw - laczna szerokosc linii
int pw = ret->w/2;
pw -= lw/2; //poczatek tekstu (x)
int tw = pw;
for (int j=0;j<(*txtg)[i].size();j++) //blit text
{
blitAt((*txtg)[i][j],tw,curh+i*19,ret);
tw+=(*txtg)[i][j]->w;
SDL_FreeSurface((*txtg)[i][j]);
}
}
return ret;
}
SDL_Surface * CMessage::blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret)
{
std::vector<std::string> * brdtext;
if (comps.size())
brdtext = breakText(comps[0]->subtitle,12,true,true);
else
brdtext = NULL;
curh += 30;
comps[0]->pos.x = (ret->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);
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);
curh+=tesu->h;
SDL_FreeSurface(tesu);
}
return ret;
}
std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext)
{
std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
@ -276,14 +316,7 @@ CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline
//TODO: support for more than one component
CInfoWindow * ret = new CInfoWindow();
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
@ -295,50 +328,19 @@ CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline
+ 30 //space to first component
+ comps[0]->getImg()->h
+ 5 //img <-> subtitle
+ brdtext->size() * 10; //subtitle //!!!!!!!!!!!!!!!!!!!!
+ 20; //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;
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]);
}
}
blitTextOnSur(txtg,curh,ret->bitmap);
curh += (19 * txtg->size()); //wys. tekstu
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);
}
blitCompsOnSur(comps,200,0,curh,ret->bitmap);
}
curh += 20; //to buttton
ret->okb.posr.x = (ret->bitmap->w/2) - (ret->okb.imgs[0][0]->w/2);

View File

@ -24,6 +24,8 @@ public:
static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg);
static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext);
static SDL_Surface * blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret);
static SDL_Surface * blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret);
static CInfoWindow * genIWindow(std::string text, int player, int charperline, std::vector<SComponent*> & comps);
static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins
static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,

View File

@ -107,6 +107,12 @@ void SComponent::deactivate()
{
ClickableR::deactivate();
}
void CSimpleWindow::show(SDL_Surface * to)
{
if(!to)
to=ekran;
blitAt(bitmap,pos.x,pos.y,to);
}
CSimpleWindow::~CSimpleWindow()
{
if (bitmap)
@ -154,16 +160,16 @@ template <typename T> void CSCButton<typename T>::deactivate()
ClickableL::deactivate();
}
template <typename T> void CSCButton<typename T>::show()
template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
{
if (delg)
if (delg) //we blit on our owner's bitmap
{
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::show(to);
}
}
CButtonBase::CButtonBase()
@ -175,17 +181,19 @@ CButtonBase::CButtonBase()
ourObj=NULL;
state=0;
}
void CButtonBase::show()
void CButtonBase::show(SDL_Surface * to)
{
if(!to)
to=ekran;
if (abs)
{
blitAt(imgs[curimg][state],pos.x,pos.y);
updateRect(&pos);
blitAt(imgs[curimg][state],pos.x,pos.y,to);
updateRect(&pos,to);
}
else
{
blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y);
updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y));
blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
}
}
@ -362,7 +370,7 @@ void CPlayerInterface::yourTurn()
adventureInt->updateMinimap=false;
}
for(int i=0;i<objsToBlit.size();i++)
blitAt(objsToBlit[i]->bitmap,objsToBlit[i]->pos.x,objsToBlit[i]->pos.y);
objsToBlit[i]->show();
SDL_Delay(5); //give time for other apps
SDL_framerateDelay(mainFPSmng);
}
@ -427,7 +435,6 @@ int getDir(int3 src, int3 dst)
}
void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
{
adventureInt->minimap.draw();
//initializing objects and performing first step of move
CGHeroInstance * ho = details.ho; //object representing this hero
int3 hp = details.src;
@ -994,6 +1001,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
ho->isStanding = true;
//move finished
CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
adventureInt->minimap.draw();
adventureInt->heroList.draw();
}
void CPlayerInterface::heroKilled(const CGHeroInstance*)
@ -1268,7 +1276,7 @@ void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*>
temp->components[i]->pos.y += temp->pos.y;
}
}
void CPlayerInterface::removeObjToBlit(CSimpleWindow* obj)
void CPlayerInterface::removeObjToBlit(IShowable* obj)
{
objsToBlit.erase
(std::find(objsToBlit.begin(),objsToBlit.end(),obj));

View File

@ -11,21 +11,36 @@ struct HeroMoveDetails;
class CDefEssential;
class CGHeroInstance;
class CAdvMapInt;
class IShowable
{
public:
virtual void show(SDL_Surface * to = NULL)=0;
};
class IActivable
{
public:
virtual void activate()=0;
virtual void deactivate()=0;
};
class CIntObject //interface object
{
public:
SDL_Rect pos;
int ID;
};
class CSimpleWindow : public virtual CIntObject
class CSimpleWindow : public virtual CIntObject, public IShowable
{
public:
SDL_Surface * bitmap;
CIntObject * owner;
virtual void show(SDL_Surface * to = NULL);
CSimpleWindow():bitmap(NULL),owner(NULL){};
virtual ~CSimpleWindow();
};
class CButtonBase : public virtual CIntObject //basic buttton class
class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
{
public:
int type; //advmapbutton=2
@ -35,7 +50,7 @@ public:
int state;
std::vector< std::vector<SDL_Surface*> > imgs;
int curimg;
virtual void show() ;
virtual void show(SDL_Surface * to = NULL);
virtual void activate()=0;
virtual void deactivate()=0;
CButtonBase();
@ -94,7 +109,7 @@ public:
void clickLeft (tribool down);
void activate();
void deactivate();
void show();
void show(SDL_Surface * to = NULL);
};
class CInfoWindow : public CSimpleWindow //text + comp. + ok button
@ -146,7 +161,7 @@ public:
std::vector<Hoverable*> hoverable;
std::vector<KeyInterested*> keyinterested;
std::vector<MotionInterested*> motioninterested;
std::vector<CSimpleWindow*> objsToBlit;
std::vector<IShowable*> objsToBlit;
SDL_Surface * hInfo;
std::vector<std::pair<int, int> > slotsPos;
@ -166,7 +181,7 @@ public:
void init(CCallback * CB);
int3 repairScreenPos(int3 pos);
void showInfoDialog(std::string text, std::vector<SComponent*> & components);
void removeObjToBlit(CSimpleWindow* obj);
void removeObjToBlit(IShowable* obj);
CPlayerInterface(int Player, int serial);
};