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:
parent
06a081c924
commit
01c996591a
@ -10,6 +10,7 @@ public:
|
||||
void heroCreated(const CHeroInstance *);
|
||||
void heroMoved(const HeroMoveDetails &);
|
||||
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 tileHidden(int3 pos){};
|
||||
};
|
||||
|
@ -204,6 +204,12 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
|
||||
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()
|
||||
{
|
||||
@ -378,6 +384,8 @@ int3 CScriptCallback::getPos(CGObjectInstance * ob)
|
||||
void CScriptCallback::changePrimSkill(int ID, int which, int val)
|
||||
{
|
||||
CGHeroInstance * hero = CGI->state->getHero(ID,0);
|
||||
if (which<PRIMARY_SKILLS)
|
||||
{
|
||||
hero->primSkills[which]+=val;
|
||||
for (int i=0; i<CGI->playerint.size(); i++)
|
||||
{
|
||||
@ -387,6 +395,12 @@ void CScriptCallback::changePrimSkill(int ID, int which, int val)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (which==4)
|
||||
{
|
||||
hero->exp+=val;
|
||||
//TODO - powiadomic interfejsy, sprawdzic czy nie ma awansu itp
|
||||
}
|
||||
}
|
||||
|
||||
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 ret;
|
||||
|
@ -9,6 +9,7 @@ class CTownInstance;
|
||||
class CPath;
|
||||
class CGObjectInstance;
|
||||
class SComponent;
|
||||
class IChosen;
|
||||
typedef struct lua_State lua_State;
|
||||
|
||||
class ICallback
|
||||
@ -59,6 +60,7 @@ public:
|
||||
//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
|
||||
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
|
||||
void selectionMade(int selection, int asker);
|
||||
|
||||
//get info
|
||||
bool verifyPath(CPath * path, bool blockSea);
|
||||
@ -93,6 +95,7 @@ public:
|
||||
//do sth
|
||||
static void changePrimSkill(int ID, int which, int val);
|
||||
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 showCompInfo(int player, SComponent * comp);
|
||||
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
virtual void tileRevealed(int3 pos)=0{};
|
||||
virtual void tileHidden(int3 pos)=0{};
|
||||
virtual void receivedResource(int type, int val){};
|
||||
virtual void showSelDialog(std::string text, std::vector<SComponent*> & components, int askID)=0{};
|
||||
};
|
||||
class CAIHandler
|
||||
{
|
||||
|
79
CLua.cpp
79
CLua.cpp
@ -202,7 +202,7 @@ void CVisitableOPH::onHeroVisit(CGObjectInstance *os, int heroID)
|
||||
};
|
||||
void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited)
|
||||
{
|
||||
int w=0, ot=0;
|
||||
int w=0, ot=0, vvv=1;
|
||||
switch(os->ID)
|
||||
{
|
||||
case 51:
|
||||
@ -221,6 +221,11 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
|
||||
w=3;
|
||||
ot=59;
|
||||
break;
|
||||
case 100:
|
||||
w=4;
|
||||
ot=143;
|
||||
vvv=1000;
|
||||
break;
|
||||
}
|
||||
if (!alreadyVisited)
|
||||
{
|
||||
@ -231,10 +236,20 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
|
||||
case 61:
|
||||
case 32:
|
||||
{
|
||||
cb->changePrimSkill(heroID,w,1);
|
||||
cb->changePrimSkill(heroID,w,vvv);
|
||||
std::vector<SComponent*> weko;
|
||||
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
|
||||
weko.push_back(new SComponent(SComponent::primskill,w,vvv));
|
||||
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++)
|
||||
// delete weko[ii];
|
||||
break;
|
||||
@ -250,11 +265,12 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
|
||||
|
||||
std::vector<int> CVisitableOPH::yourObjects()
|
||||
{
|
||||
std::vector<int> ret(4);
|
||||
std::vector<int> ret(5);
|
||||
ret.push_back(51);
|
||||
ret.push_back(23);
|
||||
ret.push_back(61);
|
||||
ret.push_back(32);
|
||||
ret.push_back(100);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -276,6 +292,9 @@ std::string CVisitableOPH::hoverText(CGObjectInstance *os)
|
||||
case 32:
|
||||
pom = 4;
|
||||
break;
|
||||
case 100:
|
||||
pom = 5;
|
||||
break;
|
||||
default:
|
||||
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);
|
||||
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);
|
||||
}
|
||||
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)
|
||||
{
|
||||
switch (os->ID)
|
||||
|
14
CLua.h
14
CLua.h
@ -8,6 +8,7 @@ class CGObjectInstance;
|
||||
class CGameInfo;
|
||||
class CGHeroInstance;
|
||||
class CScriptCallback;
|
||||
class SComponent;
|
||||
enum ESLan{UNDEF=-1,CPP,ERM,LUA};
|
||||
class CObjectScript
|
||||
{
|
||||
@ -43,7 +44,11 @@ public:
|
||||
CScript();
|
||||
virtual ~CScript();
|
||||
};
|
||||
|
||||
class IChosen
|
||||
{
|
||||
public:
|
||||
virtual void chosen(int which)=0;
|
||||
};
|
||||
class CLua :public CScript
|
||||
{
|
||||
protected:
|
||||
@ -130,10 +135,13 @@ class CMines : public CCPPObjectScript //flaggable, and giving resource at each
|
||||
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 onHeroVisit(CGObjectInstance *os, int heroID);
|
||||
std::string hoverText(CGObjectInstance *os);
|
||||
|
@ -47,11 +47,11 @@ void CInfoWindow::close()
|
||||
}
|
||||
components.clear();
|
||||
okb.deactivate();
|
||||
//SDL_FreeSurface(bitmap);
|
||||
//bitmap = NULL;
|
||||
SDL_FreeSurface(bitmap);
|
||||
bitmap = NULL;
|
||||
LOCPLINT->removeObjToBlit(this);
|
||||
//delete this;
|
||||
LOCPLINT->adventureInt->show();
|
||||
delete this;
|
||||
}
|
||||
CInfoWindow::~CInfoWindow()
|
||||
{
|
||||
@ -68,10 +68,14 @@ SComponent::SComponent(Etype Type, int Subtype, int Val)
|
||||
break;
|
||||
case resource:
|
||||
description = CGI->generaltexth->allTexts[242];
|
||||
std::ostringstream oss;
|
||||
oss << Val;
|
||||
subtitle = oss.str();
|
||||
break;
|
||||
case experience:
|
||||
description = CGI->generaltexth->allTexts[241];
|
||||
oss << Val ;
|
||||
subtitle = oss.str();
|
||||
break;
|
||||
}
|
||||
type = Type;
|
||||
subtype = Subtype;
|
||||
@ -91,6 +95,9 @@ SDL_Surface * SComponent::getImg()
|
||||
case resource:
|
||||
return CGI->heroh->resources->ourImages[subtype].bitmap;
|
||||
break;
|
||||
case experience:
|
||||
return CGI->heroh->pskillsb->ourImages[4].bitmap;
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -113,10 +120,10 @@ void CSelectableComponent::clickLeft(tribool down)
|
||||
if (down)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (Border) //use custom border
|
||||
@ -236,9 +243,9 @@ template <typename T> void CSCButton<T>::clickLeft (tribool down)
|
||||
state=0;
|
||||
}
|
||||
show();
|
||||
pressedL=state;
|
||||
if (delg)
|
||||
(delg->*func)(down);
|
||||
pressedL=state;
|
||||
}
|
||||
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);
|
||||
printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
|
||||
}
|
||||
delete[] buf;
|
||||
delete buf;
|
||||
return ret;
|
||||
}
|
||||
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);
|
||||
itoa(curh->mana,buf,10);
|
||||
printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
|
||||
delete[] buf;
|
||||
delete buf;
|
||||
blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
|
||||
blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
|
||||
//SDL_SaveBMP(ret,"inf1.bmp");
|
||||
@ -1448,6 +1455,10 @@ void CPlayerInterface::receivedResource(int type, int val)
|
||||
adventureInt->resdatabar.draw();
|
||||
}
|
||||
|
||||
void CPlayerInterface::showSelDialog(std::string text, std::vector<SComponent*> & components, int askID)
|
||||
{
|
||||
}
|
||||
|
||||
void CPlayerInterface::showComp(SComponent comp)
|
||||
{
|
||||
adventureInt->infoBar.showComp(&comp,4000);
|
||||
|
@ -131,6 +131,7 @@ public:
|
||||
};
|
||||
class CSelWindow : public CInfoWindow //component selection window
|
||||
{
|
||||
public:
|
||||
void selectionChange(SComponent * to);
|
||||
void okClicked(tribool down);
|
||||
void close();
|
||||
@ -140,7 +141,7 @@ class SComponent : public ClickableR
|
||||
public:
|
||||
enum Etype
|
||||
{
|
||||
primskill, secskill, resource, creature, artifact
|
||||
primskill, secskill, resource, creature, artifact, experience
|
||||
} type;
|
||||
int subtype;
|
||||
int val;
|
||||
@ -166,7 +167,7 @@ public:
|
||||
|
||||
|
||||
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 deactivate();
|
||||
void select(bool on);
|
||||
@ -208,6 +209,7 @@ public:
|
||||
void heroCreated(const CGHeroInstance* hero);
|
||||
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
|
||||
void receivedResource(int type, int val);
|
||||
void showSelDialog(std::string text, std::vector<SComponent*> & components, int askID);
|
||||
|
||||
void showComp(SComponent comp);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user