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

Various fixes, mainly around garrisons.

This commit is contained in:
Michał W. Urbańczyk 2011-02-05 13:39:10 +00:00
parent c6db92c0be
commit a3ba75b0b7
4 changed files with 70 additions and 85 deletions

View File

@ -487,10 +487,13 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
{ {
c->garr->highlighted = NULL; c->garr->highlighted = NULL;
c->hslotup.hero = town->garrisonHero; c->hslotup.hero = town->garrisonHero;
c->garr->odown = c->hslotdown.hero = town->visitingHero; c->hslotdown.hero = town->visitingHero;
c->garr->set2 = town->visitingHero; const CArmedInstance *upperArmy = town;
c->garr->ourUp = LOCPLINT->playerID==(town->garrisonHero ? town->garrisonHero->tempOwner : town->tempOwner); if(town->garrisonHero)
c->garr->ourDown = (town->visitingHero ? LOCPLINT->playerID==town->visitingHero->tempOwner : false); upperArmy = town->garrisonHero;
c->garr->setArmy(upperArmy, 0);
c->garr->setArmy(town->visitingHero, 1);
c->garr->recreateSlots(); c->garr->recreateSlots();
} }
GH.totalRedraw(); GH.totalRedraw();

View File

@ -112,7 +112,7 @@ void CGarrisonSlot::hover (bool on)
{ {
temp = CGI->generaltexth->tcommands[32]; //Select %s (visiting) temp = CGI->generaltexth->tcommands[32]; //Select %s (visiting)
} }
else if(owner->oup && owner->oup->ID == TOWNI_TYPE) else if(owner->armedObjs[0] && owner->armedObjs[0]->ID == TOWNI_TYPE)
{ {
temp = CGI->generaltexth->tcommands[12]; //Select %s (in garrison) temp = CGI->generaltexth->tcommands[12]; //Select %s (in garrison)
} }
@ -156,12 +156,12 @@ void CGarrisonSlot::hover (bool on)
const CArmedInstance * CGarrisonSlot::getObj() const CArmedInstance * CGarrisonSlot::getObj()
{ {
return (!upg)?(owner->oup):(owner->odown); return (!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]);
} }
bool CGarrisonSlot::our() bool CGarrisonSlot::our()
{ {
return upg?(owner->ourDown):(owner->ourUp); return upg?(owner->owned[1]):(owner->owned[0]);
} }
void CGarrisonSlot::clickRight(tribool down, bool previousState) void CGarrisonSlot::clickRight(tribool down, bool previousState)
@ -246,15 +246,15 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState)
else if(creature != owner->highlighted->creature) //swap else if(creature != owner->highlighted->creature) //swap
{ {
LOCPLINT->cb->swapCreatures( LOCPLINT->cb->swapCreatures(
(!upg)?(owner->oup):(owner->odown), (!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]),
(!owner->highlighted->upg)?(owner->oup):(owner->odown), (!owner->highlighted->upg)?(owner->armedObjs[0]):(owner->armedObjs[1]),
ID,owner->highlighted->ID); ID,owner->highlighted->ID);
} }
else //merge else //merge
{ {
LOCPLINT->cb->mergeStacks( LOCPLINT->cb->mergeStacks(
(!owner->highlighted->upg)?(owner->oup):(owner->odown), (!owner->highlighted->upg)?(owner->armedObjs[0]):(owner->armedObjs[1]),
(!upg)?(owner->oup):(owner->odown), (!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]),
owner->highlighted->ID,ID); owner->highlighted->ID,ID);
} }
} }
@ -353,6 +353,7 @@ void CGarrisonSlot::showAll(SDL_Surface * to)
blitAt(imgs[-1],pos,to); blitAt(imgs[-1],pos,to);
} }
} }
CGarrisonInt::~CGarrisonInt() CGarrisonInt::~CGarrisonInt()
{/* {/*
for(size_t i = 0; i<splitButtons.size(); i++) for(size_t i = 0; i<splitButtons.size(); i++)
@ -401,11 +402,11 @@ void CGarrisonInt::createSlots()
w = 58; w = 58;
} }
if(set1) if(armedObjs[0])
createSet(slotsUp, set1, 0, 0, w+interx, 0); createSet(slotsUp, armedObjs[0], 0, 0, w+interx, 0);
if(set2) if(armedObjs[1])
createSet (slotsDown, set2, garOffset.x, garOffset.y, w+interx, 1); createSet (slotsDown, armedObjs[1], garOffset.x, garOffset.y, w+interx, 1);
} }
void CGarrisonInt::deleteSlots() void CGarrisonInt::deleteSlots()
@ -451,26 +452,18 @@ void CGarrisonInt::splitClick()
} }
void CGarrisonInt::splitStacks(int am2) void CGarrisonInt::splitStacks(int am2)
{ {
LOCPLINT->cb->splitStack( LOCPLINT->cb->splitStack(armedObjs[highlighted->upg], armedObjs[pb], highlighted->ID, p2, am2);
(highlighted->upg)?(odown):(oup),
(pb)?(odown):(oup),
highlighted->ID,
p2,
am2);
} }
CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset, CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset,
SDL_Surface *&pomsur, const Point& SurOffset, SDL_Surface *&pomsur, const Point& SurOffset,
const CArmedInstance *s1, const CArmedInstance *s2, const CArmedInstance *s1, const CArmedInstance *s2,
bool _removableUnits, bool smallImgs, bool _twoRows ) bool _removableUnits, bool smallImgs, bool _twoRows )
: interx(inx), garOffset(garsOffset), surOffset(SurOffset), highlighted(NULL), sur(pomsur), splitting(false),
:interx(inx), garOffset(garsOffset), surOffset(SurOffset), highlighted(NULL), sur(pomsur), splitting(false), smallIcons(smallImgs), removableUnits (_removableUnits), twoRows(_twoRows)
smallIcons(smallImgs), removableUnits (_removableUnits), twoRows(_twoRows), oup(s1), odown(s2)
{ {
ourUp = s1?(s1->tempOwner == LOCPLINT->playerID || s1->tempOwner == 254):false; //254 - neutral objects (pandora, banks) setArmy(s1, false);
ourDown = s2?(s2->tempOwner == LOCPLINT->playerID || s2->tempOwner == 254):false; setArmy(s2, true);
set1 = LOCPLINT->cb->getGarrison(s1);
set2 = LOCPLINT->cb->getGarrison(s2);
pos.x += x; pos.x += x;
pos.y += y; pos.y += y;
createSlots(); createSlots();
@ -485,6 +478,12 @@ void CGarrisonInt::activate()
CIntObject::activate(); CIntObject::activate();
} }
void CGarrisonInt::setArmy(const CArmedInstance *army, bool bottomGarrison)
{
owned[bottomGarrison] = army ? (army->tempOwner == LOCPLINT->playerID || army->tempOwner == 254) : false; //254 - neutral objects (pandora, banks)
armedObjs[bottomGarrison] = army;
}
CInfoWindow::CInfoWindow(std::string Text, int player, const std::vector<SComponent*> &comps, std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, bool delComps) CInfoWindow::CInfoWindow(std::string Text, int player, const std::vector<SComponent*> &comps, std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, bool delComps)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
@ -3629,7 +3628,7 @@ void CAltarWindow::makeDeal()
} }
arts->commonInfo->reset(); arts->commonInfo->reset();
arts->scrollBackpack(0); //arts->scrollBackpack(0);
deal->block(true); deal->block(true);
} }
@ -4451,58 +4450,42 @@ void CGarrisonWindow::close()
GH.popIntTotally(this); GH.popIntTotally(this);
} }
void CGarrisonWindow::activate()
{
quit->activate();
garr->activate();
}
void CGarrisonWindow::deactivate()
{
quit->deactivate();
garr->deactivate();
}
void CGarrisonWindow::show(SDL_Surface * to)
{
blitAt(bg,pos,to);
quit->show(to);
garr->show(to);
std::string title;
if (garr->odown->tempOwner == garr->oup->tempOwner)
title = CGI->generaltexth->allTexts[709];
else
{
title = CGI->generaltexth->allTexts[35];
boost::algorithm::replace_first(title, "%s", garr->oup->Slots().begin()->second->type->namePl);
}
blitAt(graphics->flags->ourImages[garr->odown->getOwner()].bitmap,pos.x+28,pos.y+124,to);
blitAt(graphics->portraitLarge[static_cast<const CGHeroInstance*>(garr->odown)->portrait],pos.x+29,pos.y+222,to);
printAtMiddle(title,pos.x+275,pos.y+30,FONT_BIG,tytulowy,to);
}
CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits ) CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits )
{ {
bg = BitmapHandler::loadBitmap("GARRISON.bmp"); OBJ_CONSTRUCTION_CAPTURING_ALL;
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); bg = new CPicture("GARRISON.bmp");
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); bg->colorizeAndConvert(LOCPLINT->playerID);
pos.x = screen->w/2 - bg->w/2; pos = bg->center();
pos.y = screen->h/2 - bg->h/2;
pos.w = screen->w;
pos.h = screen->h;
garr = new CGarrisonInt(pos.x+92, pos.y+127, 4, Point(0,96), bg, Point(93,127), up, down, removableUnits); garr = new CGarrisonInt(92, 127, 4, Point(0,96), bg->bg, Point(93,127), up, down, removableUnits);
garr->addSplitBtn(new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+88,pos.y+314,"IDV6432.DEF")); {
quit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CGarrisonWindow::close,this),pos.x+399,pos.y+314,"IOK6432.DEF",SDLK_RETURN); AdventureMapButton *split = new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),88,314,"IDV6432.DEF");
removeChild(split);
garr->addSplitBtn(split);
}
quit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CGarrisonWindow::close,this),399,314,"IOK6432.DEF",SDLK_RETURN);
} }
CGarrisonWindow::~CGarrisonWindow() CGarrisonWindow::~CGarrisonWindow()
{ {
SDL_FreeSurface(bg); }
delete quit;
delete garr; void CGarrisonWindow::showAll(SDL_Surface * to)
{
CIntObject::showAll(to);
std::string title;
if (garr->armedObjs[1]->tempOwner == garr->armedObjs[0]->tempOwner)
title = CGI->generaltexth->allTexts[709];
else
{
title = CGI->generaltexth->allTexts[35];
boost::algorithm::replace_first(title, "%s", garr->armedObjs[0]->Slots().begin()->second->type->namePl);
}
blitAtLoc(graphics->flags->ourImages[garr->armedObjs[1]->getOwner()].bitmap,28,124,to);
blitAtLoc(graphics->portraitLarge[static_cast<const CGHeroInstance*>(garr->armedObjs[1])->portrait],29,222,to);
printAtMiddleLoc(title,275,30,FONT_BIG,tytulowy,to);
} }
IShowActivable::IShowActivable() IShowActivable::IShowActivable()

View File

@ -237,14 +237,16 @@ public:
smallIcons, //true - 32x32 imgs, false - 58x64 smallIcons, //true - 32x32 imgs, false - 58x64
removableUnits,//player can remove units from up removableUnits,//player can remove units from up
twoRows,//slots will be placed in 2 rows twoRows,//slots will be placed in 2 rows
ourUp,ourDown;//player owns up or down army owned[2];//player owns up or down army [0] upper, [1] lower
const CCreatureSet *set1; //top set of creatures // const CCreatureSet *set1; //top set of creatures
const CCreatureSet *set2; //bottom set of creatures // const CCreatureSet *set2; //bottom set of creatures
std::vector<CGarrisonSlot*> slotsUp, slotsDown; //slots of upper and lower garrison std::vector<CGarrisonSlot*> slotsUp, slotsDown; //slots of upper and lower garrison
const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns) const CArmedInstance *armedObjs[2]; //[0] is upper, [1] is down
//const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
void setArmy(const CArmedInstance *army, bool bottomGarrison);
void addSplitBtn(AdventureMapButton * button); void addSplitBtn(AdventureMapButton * button);
void createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int distance, int posY, int Upg ); void createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int distance, int posY, int Upg );
@ -1006,14 +1008,11 @@ public:
class CGarrisonWindow : public CWindowWithGarrison class CGarrisonWindow : public CWindowWithGarrison
{ {
public: public:
SDL_Surface *bg; //background surface CPicture *bg; //background surface
AdventureMapButton *quit; AdventureMapButton *quit;
void close(); void close();
void activate(); void showAll(SDL_Surface * to);
void deactivate();
void show(SDL_Surface * to);
void showAll(SDL_Surface * to){show(to);};
CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
~CGarrisonWindow(); //d-tor ~CGarrisonWindow(); //d-tor
}; };

View File

@ -328,7 +328,7 @@ CStackInstance * CCreatureSet::detachStack(TSlot slot)
assert(hasStackAtSlot(slot)); assert(hasStackAtSlot(slot));
CStackInstance *ret = stacks[slot]; CStackInstance *ret = stacks[slot];
if(CArmedInstance *armedObj = castToArmyObj()) //if(CArmedInstance *armedObj = castToArmyObj())
{ {
ret->setArmyObj(NULL); //detaches from current armyobj ret->setArmyObj(NULL); //detaches from current armyobj
} }