1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

More stuff for selection window.

This commit is contained in:
Michał W. Urbańczyk 2007-12-25 16:25:53 +00:00
parent 06a081c924
commit 01c996591a
8 changed files with 141 additions and 24 deletions

View File

@ -10,6 +10,7 @@ public:
void heroCreated(const CHeroInstance *); void heroCreated(const CHeroInstance *);
void heroMoved(const HeroMoveDetails &); void heroMoved(const HeroMoveDetails &);
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) {}; void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) {};
void showSelDialog(std::string text, std::vector<SComponent*> & components, int askID){};
void tileRevealed(int3 pos){}; void tileRevealed(int3 pos){};
void tileHidden(int3 pos){}; void tileHidden(int3 pos){};
}; };

View File

@ -204,6 +204,12 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
return true; return true;
} }
void CCallback::selectionMade(int selection, int asker)
{
//todo - jak bedzie multiplayer po sieci, to moze wymagac przerobek zaleznych od obranego modelu
IChosen * ask = (IChosen *)asker;
ask->chosen(selection);
}
int CCallback::howManyTowns() int CCallback::howManyTowns()
{ {
@ -378,15 +384,23 @@ int3 CScriptCallback::getPos(CGObjectInstance * ob)
void CScriptCallback::changePrimSkill(int ID, int which, int val) void CScriptCallback::changePrimSkill(int ID, int which, int val)
{ {
CGHeroInstance * hero = CGI->state->getHero(ID,0); CGHeroInstance * hero = CGI->state->getHero(ID,0);
hero->primSkills[which]+=val; if (which<PRIMARY_SKILLS)
for (int i=0; i<CGI->playerint.size(); i++)
{ {
if (CGI->playerint[i]->playerID == hero->getOwner()) hero->primSkills[which]+=val;
for (int i=0; i<CGI->playerint.size(); i++)
{ {
CGI->playerint[i]->heroPrimarySkillChanged(hero, which, val); if (CGI->playerint[i]->playerID == hero->getOwner())
break; {
CGI->playerint[i]->heroPrimarySkillChanged(hero, which, val);
break;
}
} }
} }
else if (which==4)
{
hero->exp+=val;
//TODO - powiadomic interfejsy, sprawdzic czy nie ma awansu itp
}
} }
int CScriptCallback::getHeroOwner(int heroID) int CScriptCallback::getHeroOwner(int heroID)
@ -413,6 +427,14 @@ void CScriptCallback::showInfoDialog(int player, std::string text, std::vector<S
} }
} }
} }
void CScriptCallback::showSelDialog(int player, std::string text, std::vector<SComponent*>*components, IChosen * asker)
{
CGameInterface * temp = CGI->playerint[CGI->state->players[player].serial];
if (temp->human)
((CPlayerInterface*)(temp))->showSelDialog(text,*components,(int)asker);
return;
}
int CScriptCallback::getSelectedHero() int CScriptCallback::getSelectedHero()
{ {
int ret; int ret;

View File

@ -9,6 +9,7 @@ class CTownInstance;
class CPath; class CPath;
class CGObjectInstance; class CGObjectInstance;
class SComponent; class SComponent;
class IChosen;
typedef struct lua_State lua_State; typedef struct lua_State lua_State;
class ICallback class ICallback
@ -59,6 +60,7 @@ public:
//commands //commands
bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
void selectionMade(int selection, int asker);
//get info //get info
bool verifyPath(CPath * path, bool blockSea); bool verifyPath(CPath * path, bool blockSea);
@ -93,6 +95,7 @@ public:
//do sth //do sth
static void changePrimSkill(int ID, int which, int val); static void changePrimSkill(int ID, int which, int val);
void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components); void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components);
void showSelDialog(int player, std::string text, std::vector<SComponent*>*components, IChosen * asker);
void giveResource(int player, int which, int val); void giveResource(int player, int which, int val);
void showCompInfo(int player, SComponent * comp); void showCompInfo(int player, SComponent * comp);

View File

@ -24,6 +24,7 @@ public:
virtual void tileRevealed(int3 pos)=0{}; virtual void tileRevealed(int3 pos)=0{};
virtual void tileHidden(int3 pos)=0{}; virtual void tileHidden(int3 pos)=0{};
virtual void receivedResource(int type, int val){}; virtual void receivedResource(int type, int val){};
virtual void showSelDialog(std::string text, std::vector<SComponent*> & components, int askID)=0{};
}; };
class CAIHandler class CAIHandler
{ {

View File

@ -202,7 +202,7 @@ void CVisitableOPH::onHeroVisit(CGObjectInstance *os, int heroID)
}; };
void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited) void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited)
{ {
int w=0, ot=0; int w=0, ot=0, vvv=1;
switch(os->ID) switch(os->ID)
{ {
case 51: case 51:
@ -221,6 +221,11 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
w=3; w=3;
ot=59; ot=59;
break; break;
case 100:
w=4;
ot=143;
vvv=1000;
break;
} }
if (!alreadyVisited) if (!alreadyVisited)
{ {
@ -231,10 +236,20 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
case 61: case 61:
case 32: case 32:
{ {
cb->changePrimSkill(heroID,w,1); cb->changePrimSkill(heroID,w,vvv);
std::vector<SComponent*> weko; std::vector<SComponent*> weko;
weko.push_back(new SComponent(SComponent::primskill,w,1)); weko.push_back(new SComponent(SComponent::primskill,w,vvv));
cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko); //TODO: maybe we have memory leak with these windows cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko);
//for (int ii=0; ii<weko.size();ii++)
// delete weko[ii];
break;
}
case 100:
{
cb->changePrimSkill(heroID,w,vvv);
std::vector<SComponent*> weko;
weko.push_back(new SComponent(SComponent::experience,0,vvv));
cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko);
//for (int ii=0; ii<weko.size();ii++) //for (int ii=0; ii<weko.size();ii++)
// delete weko[ii]; // delete weko[ii];
break; break;
@ -250,11 +265,12 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
std::vector<int> CVisitableOPH::yourObjects() std::vector<int> CVisitableOPH::yourObjects()
{ {
std::vector<int> ret(4); std::vector<int> ret(5);
ret.push_back(51); ret.push_back(51);
ret.push_back(23); ret.push_back(23);
ret.push_back(61); ret.push_back(61);
ret.push_back(32); ret.push_back(32);
ret.push_back(100);
return ret; return ret;
} }
@ -276,6 +292,9 @@ std::string CVisitableOPH::hoverText(CGObjectInstance *os)
case 32: case 32:
pom = 4; pom = 4;
break; break;
case 100:
pom = 5;
break;
default: default:
throw new std::exception("Unsupported ID in CVisitableOPH::hoverText"); throw new std::exception("Unsupported ID in CVisitableOPH::hoverText");
} }
@ -479,9 +498,59 @@ void CPickable::onHeroVisit(CGObjectInstance *os, int heroID)
cb->showCompInfo(cb->getHeroOwner(heroID),&ccc); cb->showCompInfo(cb->getHeroOwner(heroID),&ccc);
break; break;
} }
case 101:
{
if (os->subID)
break; //not OH3 treasure chest
int wyn = rand()%100;
if (wyn<32)
{
tempStore.push_back(new SComponent(SComponent::resource,6,1000));
tempStore.push_back(new SComponent(SComponent::experience,0,500));
}//1k/0.5k
else if(wyn<64)
{
tempStore.push_back(new SComponent(SComponent::resource,6,1500));
tempStore.push_back(new SComponent(SComponent::experience,0,1000));
}//1.5k/1k
else if(wyn<95)
{
tempStore.push_back(new SComponent(SComponent::resource,6,2000));
tempStore.push_back(new SComponent(SComponent::experience,0,1500));
}//2k/1.5k
else
{
if (1/*TODO: backpack is full*/)
{
tempStore.push_back(new SComponent(SComponent::resource,6,1000));
tempStore.push_back(new SComponent(SComponent::experience,0,500));
}
else
{
//TODO: give treasure artifact
break;
}
}//random treasure artifact, or (if backapack is full) 1k/0.5k
player = cb->getHeroOwner(heroID);
cb->showSelDialog(player,"Wybierz prosze co chcesz dostac :)",&tempStore,this);
break;
}
} }
CGI->mh->removeObject(os); CGI->mh->removeObject(os);
} }
void CPickable::chosen(int which)
{
switch(tempStore[which]->type)
{
case SComponent::resource:
cb->giveResource(player,tempStore[which]->subtype,tempStore[which]->val);
break;
default:
throw new std::exception("Unhandled choice");
}
}
std::string CPickable::hoverText(CGObjectInstance *os) std::string CPickable::hoverText(CGObjectInstance *os)
{ {
switch (os->ID) switch (os->ID)

14
CLua.h
View File

@ -8,6 +8,7 @@ class CGObjectInstance;
class CGameInfo; class CGameInfo;
class CGHeroInstance; class CGHeroInstance;
class CScriptCallback; class CScriptCallback;
class SComponent;
enum ESLan{UNDEF=-1,CPP,ERM,LUA}; enum ESLan{UNDEF=-1,CPP,ERM,LUA};
class CObjectScript class CObjectScript
{ {
@ -43,7 +44,11 @@ public:
CScript(); CScript();
virtual ~CScript(); virtual ~CScript();
}; };
class IChosen
{
public:
virtual void chosen(int which)=0;
};
class CLua :public CScript class CLua :public CScript
{ {
protected: protected:
@ -130,10 +135,13 @@ class CMines : public CCPPObjectScript //flaggable, and giving resource at each
friend void initGameState(CGameInfo * cgi); friend void initGameState(CGameInfo * cgi);
}; };
class CPickable : public CCPPObjectScript //pickable - resources, artifacts, etc class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc
{ {
CPickable(CScriptCallback * CB):CCPPObjectScript(CB){}; std::vector<SComponent*> tempStore;
int player;
CPickable(CScriptCallback * CB):CCPPObjectScript(CB){};
void chosen(int which);
void newObject(CGObjectInstance *os); void newObject(CGObjectInstance *os);
void onHeroVisit(CGObjectInstance *os, int heroID); void onHeroVisit(CGObjectInstance *os, int heroID);
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);

View File

@ -47,11 +47,11 @@ void CInfoWindow::close()
} }
components.clear(); components.clear();
okb.deactivate(); okb.deactivate();
//SDL_FreeSurface(bitmap); SDL_FreeSurface(bitmap);
//bitmap = NULL; bitmap = NULL;
LOCPLINT->removeObjToBlit(this); LOCPLINT->removeObjToBlit(this);
//delete this;
LOCPLINT->adventureInt->show(); LOCPLINT->adventureInt->show();
delete this;
} }
CInfoWindow::~CInfoWindow() CInfoWindow::~CInfoWindow()
{ {
@ -68,10 +68,14 @@ SComponent::SComponent(Etype Type, int Subtype, int Val)
break; break;
case resource: case resource:
description = CGI->generaltexth->allTexts[242]; description = CGI->generaltexth->allTexts[242];
std::ostringstream oss;
oss << Val; oss << Val;
subtitle = oss.str(); subtitle = oss.str();
break; break;
case experience:
description = CGI->generaltexth->allTexts[241];
oss << Val ;
subtitle = oss.str();
break;
} }
type = Type; type = Type;
subtype = Subtype; subtype = Subtype;
@ -91,6 +95,9 @@ SDL_Surface * SComponent::getImg()
case resource: case resource:
return CGI->heroh->resources->ourImages[subtype].bitmap; return CGI->heroh->resources->ourImages[subtype].bitmap;
break; break;
case experience:
return CGI->heroh->pskillsb->ourImages[4].bitmap;
break;
} }
return NULL; return NULL;
} }
@ -113,10 +120,10 @@ void CSelectableComponent::clickLeft(tribool down)
if (down) if (down)
{ {
select(true); select(true);
owner->selectionChange(this);
} }
} }
CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner=NULL, SDL_Surface * Border) CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner, SDL_Surface * Border)
:SComponent(Type,Sub,Val),owner(Owner) :SComponent(Type,Sub,Val),owner(Owner)
{ {
if (Border) //use custom border if (Border) //use custom border
@ -236,9 +243,9 @@ template <typename T> void CSCButton<T>::clickLeft (tribool down)
state=0; state=0;
} }
show(); show();
pressedL=state;
if (delg) if (delg)
(delg->*func)(down); (delg->*func)(down);
pressedL=state;
} }
template <typename T> void CSCButton<typename T>::activate() template <typename T> void CSCButton<typename T>::activate()
{ {
@ -1142,7 +1149,7 @@ SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL
itoa(curh->primSkills[i],buf,10); itoa(curh->primSkills[i],buf,10);
printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret); printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
} }
delete[] buf; delete buf;
return ret; return ret;
} }
SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh) SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
@ -1162,7 +1169,7 @@ SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
blitAt(curh->type->portraitLarge,11,12,ret); blitAt(curh->type->portraitLarge,11,12,ret);
itoa(curh->mana,buf,10); itoa(curh->mana,buf,10);
printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
delete[] buf; delete buf;
blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret); blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret); blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
//SDL_SaveBMP(ret,"inf1.bmp"); //SDL_SaveBMP(ret,"inf1.bmp");
@ -1448,6 +1455,10 @@ void CPlayerInterface::receivedResource(int type, int val)
adventureInt->resdatabar.draw(); adventureInt->resdatabar.draw();
} }
void CPlayerInterface::showSelDialog(std::string text, std::vector<SComponent*> & components, int askID)
{
}
void CPlayerInterface::showComp(SComponent comp) void CPlayerInterface::showComp(SComponent comp)
{ {
adventureInt->infoBar.showComp(&comp,4000); adventureInt->infoBar.showComp(&comp,4000);

View File

@ -131,6 +131,7 @@ public:
}; };
class CSelWindow : public CInfoWindow //component selection window class CSelWindow : public CInfoWindow //component selection window
{ {
public:
void selectionChange(SComponent * to); void selectionChange(SComponent * to);
void okClicked(tribool down); void okClicked(tribool down);
void close(); void close();
@ -140,7 +141,7 @@ class SComponent : public ClickableR
public: public:
enum Etype enum Etype
{ {
primskill, secskill, resource, creature, artifact primskill, secskill, resource, creature, artifact, experience
} type; } type;
int subtype; int subtype;
int val; int val;
@ -166,7 +167,7 @@ public:
void clickLeft(tribool down); void clickLeft(tribool down);
CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner, SDL_Surface * Border=NULL); CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner=NULL, SDL_Surface * Border=NULL);
void activate(); void activate();
void deactivate(); void deactivate();
void select(bool on); void select(bool on);
@ -208,6 +209,7 @@ public:
void heroCreated(const CGHeroInstance* hero); void heroCreated(const CGHeroInstance* hero);
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val); void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
void receivedResource(int type, int val); void receivedResource(int type, int val);
void showSelDialog(std::string text, std::vector<SComponent*> & components, int askID);
void showComp(SComponent comp); void showComp(SComponent comp);