mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
-rewrote GarrisonInt with use of object capturing
- BitmapHandler can now load images from any format supported by SDL_Image note: file can have any possible format but extension should be .bmp or .pcx - fixed some warnings
This commit is contained in:
parent
527a0ef4d6
commit
4d171bd53c
@ -140,6 +140,14 @@ SDL_Surface * CPCXConv::getSurface() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isPCX(const unsigned char *header)//check whether file can be PCX according to 1st 12 bytes
|
||||||
|
{
|
||||||
|
int fSize = readNormalNr(header, 0);
|
||||||
|
int width = readNormalNr(header, 4);
|
||||||
|
int height = readNormalNr(header, 8);
|
||||||
|
return fSize == width*height || fSize == width*height*3;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Surface * BitmapHandler::loadBitmap(std::string fname, bool setKey)
|
SDL_Surface * BitmapHandler::loadBitmap(std::string fname, bool setKey)
|
||||||
{
|
{
|
||||||
if(!fname.size())
|
if(!fname.size())
|
||||||
@ -153,47 +161,44 @@ SDL_Surface * BitmapHandler::loadBitmap(std::string fname, bool setKey)
|
|||||||
Entry *e = bitmaph->entries.znajdz(fname);
|
Entry *e = bitmaph->entries.znajdz(fname);
|
||||||
if(!e)
|
if(!e)
|
||||||
{
|
{
|
||||||
tlog2<<"File "<<fname<<" not found"<<std::endl;
|
tlog2<<"Entry for file "<<fname<<" was not found"<<std::endl;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(e->offset<0)
|
if(e->offset<0)//not in LOD
|
||||||
{
|
{
|
||||||
fname = e->realName;
|
fname = e->realName;
|
||||||
fname = DATA_DIR "/Data/" + fname;
|
fname = DATA_DIR "/Data/" + fname;
|
||||||
FILE * f = fopen(fname.c_str(),"r");
|
FILE * f = fopen(fname.c_str(),"r");
|
||||||
char sign[3];
|
unsigned char sign[12];
|
||||||
f = fopen(fname.c_str(),"r");
|
|
||||||
if(!f)
|
if(!f)
|
||||||
{
|
{
|
||||||
tlog1 << "Cannot open " << fname << " - not present as bmp nor as pcx.\n";
|
tlog1 << "Cannot open " << fname << " - file not found!\n";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fread(sign,1,3,f);
|
fread(sign,1,12,f);
|
||||||
if(sign[0]=='B' && sign[1]=='M') //BMP named as PCX - people (eg. Kulex) sometimes use such files
|
SDL_Surface * ret=NULL;
|
||||||
|
if (isPCX(sign))//H3-style PCX
|
||||||
|
{
|
||||||
|
CPCXConv cp;
|
||||||
|
pcx = new unsigned char[e->realSize];
|
||||||
|
memcpy(pcx,sign,3);
|
||||||
|
int res = fread((char*)pcx+3, 1, e->realSize-3, f); //TODO use me
|
||||||
|
fclose(f);
|
||||||
|
cp.openPCX((char*)pcx,e->realSize);
|
||||||
|
ret = cp.getSurface();
|
||||||
|
if (!ret)
|
||||||
|
tlog1<<"Failed to open "<<fname<<" as H3 PCX!\n";
|
||||||
|
}
|
||||||
|
else //try loading via SDL_Image
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return SDL_LoadBMP(fname.c_str());
|
ret = IMG_Load(fname.c_str());
|
||||||
}
|
if (!ret)
|
||||||
else //PCX - but we don't know which
|
tlog1<<"Failed to open "<<fname<<" via SDL_Image\n";
|
||||||
{
|
|
||||||
if((sign[0]==10) && (sign[1]<6) && (sign[2]==1)) //ZSoft PCX
|
|
||||||
{
|
|
||||||
fclose(f);
|
|
||||||
return IMG_Load(fname.c_str());
|
|
||||||
}
|
|
||||||
else //H3-style PCX
|
|
||||||
{
|
|
||||||
CPCXConv cp;
|
|
||||||
pcx = new unsigned char[e->realSize];
|
|
||||||
memcpy(pcx,sign,3);
|
|
||||||
int res = fread((char*)pcx+3, 1, e->realSize-3, f); //TODO use me
|
|
||||||
fclose(f);
|
|
||||||
cp.openPCX((char*)pcx,e->realSize);
|
|
||||||
return cp.getSurface();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
//loading from LOD
|
||||||
pcx = bitmaph->giveFile(e->nameStr, NULL);
|
pcx = bitmaph->giveFile(e->nameStr, NULL);
|
||||||
|
|
||||||
CPCXConv cp;
|
CPCXConv cp;
|
||||||
|
@ -435,7 +435,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, int listPos)
|
|||||||
exit->assignedKeys.insert(SDLK_ESCAPE);
|
exit->assignedKeys.insert(SDLK_ESCAPE);
|
||||||
split = new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+744,pos.y+382,"TSBTNS.DEF");
|
split = new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+744,pos.y+382,"TSBTNS.DEF");
|
||||||
split->callback += boost::bind(&CCastleInterface::splitClicked,this);
|
split->callback += boost::bind(&CCastleInterface::splitClicked,this);
|
||||||
garr->splitButtons.push_back(split);
|
garr->addSplitBtn(split);
|
||||||
statusbar = new CStatusBar(pos.x+7,pos.y+555,"TSTATBAR.bmp",732);
|
statusbar = new CStatusBar(pos.x+7,pos.y+555,"TSTATBAR.bmp",732);
|
||||||
resdatabar = new CResDataBar("ZRESBAR.bmp",pos.x+3,pos.y+575,32,2,85,85);
|
resdatabar = new CResDataBar("ZRESBAR.bmp",pos.x+3,pos.y+575,32,2,85,85);
|
||||||
|
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
#include "CConfigHandler.h"
|
#include "CConfigHandler.h"
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
#if BOOST_VERSION >= 103800
|
||||||
|
#include <boost/spirit/include/classic.hpp>
|
||||||
|
#else
|
||||||
#include <boost/spirit.hpp>
|
#include <boost/spirit.hpp>
|
||||||
|
#endif
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
using namespace config;
|
using namespace config;
|
||||||
using namespace boost::spirit;
|
using namespace boost::spirit;
|
||||||
|
@ -239,11 +239,10 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
|
|||||||
|
|
||||||
delete garr;
|
delete garr;
|
||||||
garr = new CGarrisonInt(pos.x+80, pos.y+493, 8, Point(), curBack, Point(16,486), curHero);
|
garr = new CGarrisonInt(pos.x+80, pos.y+493, 8, Point(), curBack, Point(16,486), curHero);
|
||||||
garr->update = false;
|
|
||||||
|
|
||||||
AdventureMapButton * split = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::bind(&CGarrisonInt::splitClick,garr), pos.x+604, pos.y+527, "hsbtns9.def", false, NULL, false); //deleted by garrison destructor
|
AdventureMapButton * split = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::bind(&CGarrisonInt::splitClick,garr), pos.x+604, pos.y+527, "hsbtns9.def", false, NULL, false); //deleted by garrison destructor
|
||||||
boost::algorithm::replace_first(split->hoverTexts[0],"%s",CGI->generaltexth->allTexts[43]);
|
boost::algorithm::replace_first(split->hoverTexts[0],"%s",CGI->generaltexth->allTexts[43]);
|
||||||
garr->splitButtons.push_back(split);
|
garr->addSplitBtn(split);
|
||||||
|
|
||||||
//primary skills support
|
//primary skills support
|
||||||
for(size_t g=0; g<primSkillAreas.size(); ++g)
|
for(size_t g=0; g<primSkillAreas.size(); ++g)
|
||||||
|
@ -517,7 +517,6 @@ void CKingdomInterface::CTownItem::setTown(const CGTownInstance * newTown)
|
|||||||
garr = NULL;
|
garr = NULL;
|
||||||
}
|
}
|
||||||
garr = new CGarrisonInt(pos.x+313,pos.y+3,4,Point(232,0),parent->slots->ourImages[parent->PicCount+2].bitmap,Point(313,2),town,town->visitingHero,true,true, true);
|
garr = new CGarrisonInt(pos.x+313,pos.y+3,4,Point(232,0),parent->slots->ourImages[parent->PicCount+2].bitmap,Point(313,2),town,town->visitingHero,true,true, true);
|
||||||
garr->update = true;
|
|
||||||
|
|
||||||
garrHero->hero = town->garrisonHero;
|
garrHero->hero = town->garrisonHero;
|
||||||
visitHero->hero = town->visitingHero;
|
visitHero->hero = town->visitingHero;
|
||||||
|
@ -530,6 +530,7 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
|
|||||||
break;
|
break;
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
case SDLK_DOWN:
|
case SDLK_DOWN:
|
||||||
|
{
|
||||||
bool down = key.keysym.sym == SDLK_DOWN;
|
bool down = key.keysym.sym == SDLK_DOWN;
|
||||||
static const int schoolsOrder[] = {0, 3, 1, 2, 4};
|
static const int schoolsOrder[] = {0, 3, 1, 2, 4};
|
||||||
int index = -1;
|
int index = -1;
|
||||||
@ -540,6 +541,9 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
|
|||||||
selectSchool(schoolsOrder[index]);
|
selectSchool(schoolsOrder[index]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default://to get rid of warnings
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
//alt + 1234567890-= casts spell from 1 - 12 slot
|
//alt + 1234567890-= casts spell from 1 - 12 slot
|
||||||
if(LOCPLINT->altPressed())
|
if(LOCPLINT->altPressed())
|
||||||
@ -602,8 +606,8 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//battle spell on adv map or adventure map spell during combat => display infowindow, not cast
|
//battle spell on adv map or adventure map spell during combat => display infowindow, not cast
|
||||||
if(sp->combatSpell && !owner->myInt->battleInt
|
if((sp->combatSpell && !owner->myInt->battleInt)
|
||||||
|| !sp->combatSpell && owner->myInt->battleInt)
|
|| (!sp->combatSpell && owner->myInt->battleInt))
|
||||||
{
|
{
|
||||||
std::vector<SComponent*> hlp(1, new SComponent(SComponent::spell, mySpell, 0));
|
std::vector<SComponent*> hlp(1, new SComponent(SComponent::spell, mySpell, 0));
|
||||||
LOCPLINT->showInfoDialog(sp->descriptions[schoolLevel], hlp);
|
LOCPLINT->showInfoDialog(sp->descriptions[schoolLevel], hlp);
|
||||||
|
@ -472,7 +472,7 @@ public:
|
|||||||
|
|
||||||
CPicture(const Rect &r, const SDL_Color &color, bool screenFormat = false); //rect filled with given color
|
CPicture(const Rect &r, const SDL_Color &color, bool screenFormat = false); //rect filled with given color
|
||||||
CPicture(const Rect &r, ui32 color, bool screenFormat = false); //rect filled with given color
|
CPicture(const Rect &r, ui32 color, bool screenFormat = false); //rect filled with given color
|
||||||
CPicture(SDL_Surface *BG, int x, int y, bool Free = true); //wrap existing SDL_Surface
|
CPicture(SDL_Surface *BG, int x=0, int y=0, bool Free = true); //wrap existing SDL_Surface
|
||||||
CPicture(const std::string &bmpname, int x=0, int y=0);
|
CPicture(const std::string &bmpname, int x=0, int y=0);
|
||||||
CPicture(SDL_Surface *BG, const Rect &SrcRext, int x = 0, int y = 0, bool free = false); //wrap subrect of given surface
|
CPicture(SDL_Surface *BG, const Rect &SrcRext, int x = 0, int y = 0, bool free = false); //wrap subrect of given surface
|
||||||
void init();
|
void init();
|
||||||
|
@ -167,11 +167,6 @@ void CGarrisonSlot::clickRight(tribool down, bool previousState)
|
|||||||
}
|
}
|
||||||
void CGarrisonSlot::clickLeft(tribool down, bool previousState)
|
void CGarrisonSlot::clickLeft(tribool down, bool previousState)
|
||||||
{
|
{
|
||||||
if(owner->ignoreEvent)
|
|
||||||
{
|
|
||||||
owner->ignoreEvent = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(down)
|
if(down)
|
||||||
{
|
{
|
||||||
bool refr = false;
|
bool refr = false;
|
||||||
@ -308,8 +303,8 @@ CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg
|
|||||||
myStack = Creature;
|
myStack = Creature;
|
||||||
creature = Creature ? Creature->type : NULL;
|
creature = Creature ? Creature->type : NULL;
|
||||||
count = Creature ? Creature->count : 0;
|
count = Creature ? Creature->count : 0;
|
||||||
pos.x = x;
|
pos.x += x;
|
||||||
pos.y = y;
|
pos.y += y;
|
||||||
if(Owner->smallIcons)
|
if(Owner->smallIcons)
|
||||||
{
|
{
|
||||||
pos.w = 32;
|
pos.w = 32;
|
||||||
@ -355,102 +350,42 @@ void CGarrisonSlot::show(SDL_Surface * to)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
CGarrisonInt::~CGarrisonInt()
|
CGarrisonInt::~CGarrisonInt()
|
||||||
{
|
{/*
|
||||||
if(sup)
|
|
||||||
{
|
|
||||||
for(size_t i=0;i<sup->size();i++)
|
|
||||||
{
|
|
||||||
delete (*sup)[i];
|
|
||||||
}
|
|
||||||
delete sup;
|
|
||||||
}
|
|
||||||
if(sdown)
|
|
||||||
{
|
|
||||||
for(size_t i=0;i<sdown->size();i++)
|
|
||||||
{
|
|
||||||
delete (*sdown)[i]; //XXX what about smartpointers? boost or auto_ptr from std
|
|
||||||
}
|
|
||||||
delete sdown;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(size_t i = 0; i<splitButtons.size(); i++)
|
for(size_t i = 0; i<splitButtons.size(); i++)
|
||||||
delete splitButtons[i];
|
delete splitButtons[i];*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGarrisonInt::show(SDL_Surface * to)
|
void CGarrisonInt::addSplitBtn(AdventureMapButton * button)
|
||||||
{
|
{
|
||||||
if(sup)
|
addChild(button);
|
||||||
|
button->recActions = defActions;
|
||||||
|
splitButtons.push_back(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGarrisonInt::createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int posY, int distance, int Upg )
|
||||||
|
{
|
||||||
|
ret.resize(7);
|
||||||
|
|
||||||
|
for(TSlots::const_iterator i=set->Slots().begin(); i!=set->Slots().end(); i++)
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i<sup->size(); i++)
|
ret[i->first] = new CGarrisonSlot(this, posX + (i->first*distance), posY, i->first, Upg, &i->second);
|
||||||
{
|
|
||||||
if((*sup)[i])
|
|
||||||
{
|
|
||||||
(*sup)[i]->show(to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(sdown)
|
|
||||||
{
|
|
||||||
for(size_t i = 0; i<sdown->size(); i++)
|
|
||||||
{
|
|
||||||
if((*sdown)[i])
|
|
||||||
{
|
|
||||||
(*sdown)[i]->show(to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(size_t i = 0; i<splitButtons.size(); i++)
|
for(int i=0; i<ret.size(); i++)
|
||||||
splitButtons[i]->show(to);
|
if(!ret[i])
|
||||||
}
|
ret[i] = new CGarrisonSlot(this, posX + (i*distance), posY,i,Upg,NULL);
|
||||||
void CGarrisonInt::deactiveteSlots()
|
|
||||||
{
|
if (twoRows)
|
||||||
if(sup)
|
for (int i=4; i<ret.size(); i++)
|
||||||
{
|
{
|
||||||
for(int i = 0; i<sup->size(); i++)
|
ret[i]->pos.x -= 126;
|
||||||
{
|
ret[i]->pos.y += 37;
|
||||||
if((*sup)[i])
|
};
|
||||||
{
|
|
||||||
(*sup)[i]->deactivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(sdown)
|
|
||||||
{
|
|
||||||
for(int i = 0; i<sdown->size(); i++)
|
|
||||||
{
|
|
||||||
if((*sdown)[i])
|
|
||||||
{
|
|
||||||
(*sdown)[i]->deactivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void CGarrisonInt::activeteSlots()
|
|
||||||
{
|
|
||||||
if(sup)
|
|
||||||
{
|
|
||||||
for(int i = 0; i<sup->size(); i++)
|
|
||||||
{
|
|
||||||
if((*sup)[i])
|
|
||||||
{
|
|
||||||
(*sup)[i]->activate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(sdown)
|
|
||||||
{
|
|
||||||
for(int i = 0; i<sdown->size(); i++)
|
|
||||||
{
|
|
||||||
if((*sdown)[i])
|
|
||||||
{
|
|
||||||
(*sdown)[i]->activate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGarrisonInt::createSlots()
|
void CGarrisonInt::createSlots()
|
||||||
{
|
{
|
||||||
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||||
int h, w; //height and width of slot
|
int h, w; //height and width of slot
|
||||||
if(smallIcons)
|
if(smallIcons)
|
||||||
{
|
{
|
||||||
@ -463,90 +398,46 @@ void CGarrisonInt::createSlots()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(set1)
|
if(set1)
|
||||||
{
|
createSet(slotsUp, set1, 0, 0, w+interx, 0);
|
||||||
sup = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
|
|
||||||
for(TSlots::const_iterator i=set1->Slots().begin(); i!=set1->Slots().end(); i++)
|
|
||||||
(*sup)[i->first] = new CGarrisonSlot(this, pos.x + (i->first*(w+interx)), pos.y, i->first, 0, &i->second);
|
|
||||||
|
|
||||||
for(int i=0; i<sup->size(); i++)
|
|
||||||
if((*sup)[i] == NULL)
|
|
||||||
(*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(w+interx)), pos.y,i,0,NULL);
|
|
||||||
|
|
||||||
if (twoRows)
|
|
||||||
for (int i=4; i<sup->size(); i++)
|
|
||||||
{
|
|
||||||
(*sup)[i]->pos.x -= 126;
|
|
||||||
(*sup)[i]->pos.y += 37;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if(set2)
|
if(set2)
|
||||||
{
|
createSet (slotsDown, set2, garOffset.x, garOffset.y, w+interx, 1);
|
||||||
sdown = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
|
|
||||||
for(TSlots::const_iterator i=set2->Slots().begin(); i!=set2->Slots().end(); i++)
|
|
||||||
{
|
|
||||||
(*sdown)[i->first] =
|
|
||||||
new CGarrisonSlot(this, pos.x + (i->first*(w+interx)) + garOffset.x, pos.y + garOffset.y,i->first,1, &i->second);
|
|
||||||
}
|
|
||||||
for(int i=0; i<sdown->size(); i++)
|
|
||||||
if((*sdown)[i] == NULL)
|
|
||||||
(*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(w+interx)) + garOffset.x, pos.y + garOffset.y,i,1, NULL);
|
|
||||||
|
|
||||||
if (twoRows)
|
|
||||||
for (int i=4; i<sup->size(); i++)
|
|
||||||
{
|
|
||||||
(*sup)[i]->pos.x -= 126;
|
|
||||||
(*sup)[i]->pos.y += 37;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGarrisonInt::deleteSlots()
|
void CGarrisonInt::deleteSlots()
|
||||||
{
|
{
|
||||||
if(sup)
|
for (int i=0; i<slotsUp.size(); i++)
|
||||||
{
|
delChildNUll(slotsUp[i]);
|
||||||
for(int i = 0; i<sup->size(); i++)
|
|
||||||
{
|
for (int i=0; i<slotsDown.size(); i++)
|
||||||
if((*sup)[i])
|
delChildNUll(slotsDown[i]);
|
||||||
{
|
|
||||||
delete (*sup)[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete sup;
|
|
||||||
sup = NULL;
|
|
||||||
}
|
|
||||||
if(sdown)
|
|
||||||
{
|
|
||||||
for(int i = 0; i<sdown->size(); i++)
|
|
||||||
{
|
|
||||||
if((*sdown)[i])
|
|
||||||
{
|
|
||||||
delete (*sdown)[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete sdown;
|
|
||||||
sdown = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGarrisonInt::recreateSlots()
|
void CGarrisonInt::recreateSlots()
|
||||||
{
|
{
|
||||||
|
|
||||||
splitting = false;
|
splitting = false;
|
||||||
highlighted = NULL;
|
highlighted = NULL;
|
||||||
|
|
||||||
for(size_t i = 0; i<splitButtons.size(); i++)
|
for(size_t i = 0; i<splitButtons.size(); i++)
|
||||||
splitButtons[i]->block(true);
|
splitButtons[i]->block(true);
|
||||||
|
|
||||||
|
bool wasActive = active;
|
||||||
if(active)
|
if(active)
|
||||||
{
|
{
|
||||||
deactiveteSlots();
|
deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteSlots();
|
deleteSlots();
|
||||||
createSlots();
|
createSlots();
|
||||||
if(active)
|
|
||||||
|
if(wasActive)
|
||||||
{
|
{
|
||||||
//ignoreEvent = true;
|
activate();
|
||||||
activeteSlots();
|
showAll(screen2);
|
||||||
//show(screen2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGarrisonInt::splitClick()
|
void CGarrisonInt::splitClick()
|
||||||
{
|
{
|
||||||
if(!highlighted)
|
if(!highlighted)
|
||||||
@ -564,23 +455,20 @@ void CGarrisonInt::splitStacks(int am2)
|
|||||||
am2);
|
am2);
|
||||||
|
|
||||||
}
|
}
|
||||||
CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *&pomsur, const Point& SurOffset,
|
CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset,
|
||||||
const CArmedInstance *s1, const CArmedInstance *s2, bool _removableUnits, bool smallImgs, bool _twoRows )
|
SDL_Surface *&pomsur, const Point& SurOffset,
|
||||||
:interx(inx),garOffset(garsOffset),highlighted(NULL),sur(pomsur),surOffset(SurOffset),sup(NULL),
|
const CArmedInstance *s1, const CArmedInstance *s2,
|
||||||
sdown(NULL),oup(s1),odown(s2), smallIcons(smallImgs), twoRows(_twoRows)
|
bool _removableUnits, bool smallImgs, bool _twoRows )
|
||||||
|
|
||||||
|
:interx(inx), garOffset(garsOffset), surOffset(SurOffset), highlighted(NULL), sur(pomsur), splitting(false),
|
||||||
|
smallIcons(smallImgs), removableUnits (_removableUnits), twoRows(_twoRows), oup(s1), odown(s2)
|
||||||
{
|
{
|
||||||
ourUp = s1?s1->tempOwner == LOCPLINT->playerID:false;
|
ourUp = s1?s1->tempOwner == LOCPLINT->playerID:false;
|
||||||
ourDown = s2?s2->tempOwner == LOCPLINT->playerID:false;
|
ourDown = s2?s2->tempOwner == LOCPLINT->playerID:false;
|
||||||
active = false;
|
|
||||||
splitting = false;
|
|
||||||
set1 = LOCPLINT->cb->getGarrison(s1);
|
set1 = LOCPLINT->cb->getGarrison(s1);
|
||||||
set2 = LOCPLINT->cb->getGarrison(s2);
|
set2 = LOCPLINT->cb->getGarrison(s2);
|
||||||
ignoreEvent = false;
|
pos.x += x;
|
||||||
update = true;
|
pos.y += y;
|
||||||
pos.x=(x);
|
|
||||||
pos.y=(y);
|
|
||||||
pos.w=(58);
|
|
||||||
pos.h=(64);
|
|
||||||
createSlots();
|
createSlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,29 +478,7 @@ void CGarrisonInt::activate()
|
|||||||
if(splitButtons[i]->blocked != !highlighted)
|
if(splitButtons[i]->blocked != !highlighted)
|
||||||
splitButtons[i]->block(!highlighted);
|
splitButtons[i]->block(!highlighted);
|
||||||
|
|
||||||
active = true;
|
CIntObject::activate();
|
||||||
if(sup)
|
|
||||||
{
|
|
||||||
for(int i = 0; i<sup->size(); i++)
|
|
||||||
if((*sup)[i])
|
|
||||||
(*sup)[i]->activate();
|
|
||||||
}
|
|
||||||
if(sdown)
|
|
||||||
{
|
|
||||||
for(int i = 0; i<sdown->size(); i++)
|
|
||||||
if((*sdown)[i])
|
|
||||||
(*sdown)[i]->activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
for(size_t i = 0; i<splitButtons.size(); i++)
|
|
||||||
splitButtons[i]->activate();
|
|
||||||
}
|
|
||||||
void CGarrisonInt::deactivate()
|
|
||||||
{
|
|
||||||
active = false;
|
|
||||||
deactiveteSlots();
|
|
||||||
for(size_t i = 0; i<splitButtons.size(); i++)
|
|
||||||
splitButtons[i]->deactivate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@ -864,6 +730,12 @@ void SComponent::init(Etype Type, int Subtype, int Val)
|
|||||||
subtitle += CGI->generaltexth->levels[Val-1] + " " + CGI->generaltexth->skillName[Subtype];
|
subtitle += CGI->generaltexth->levels[Val-1] + " " + CGI->generaltexth->skillName[Subtype];
|
||||||
description = CGI->generaltexth->skillInfoTexts[Subtype][Val-1];
|
description = CGI->generaltexth->skillInfoTexts[Subtype][Val-1];
|
||||||
break;
|
break;
|
||||||
|
case morale:
|
||||||
|
description = CGI->generaltexth->heroscrn[ 4 - (val>0) + (val<0)];
|
||||||
|
break;
|
||||||
|
case luck:
|
||||||
|
description = CGI->generaltexth->heroscrn[ 7 - (val>0) + (val<0)];
|
||||||
|
break;
|
||||||
case resource:
|
case resource:
|
||||||
description = CGI->generaltexth->allTexts[242];
|
description = CGI->generaltexth->allTexts[242];
|
||||||
oss << Val;
|
oss << Val;
|
||||||
@ -1948,7 +1820,7 @@ void CRecruitmentWindow::show(SDL_Surface * to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(int,int)> &Recruit, int y_offset)
|
CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(int,int)> &Recruit, int y_offset)
|
||||||
:recruit(Recruit), dwelling(Dwelling), dst(Dst), level(Level)
|
:recruit(Recruit), dwelling(Dwelling), level(Level), dst(Dst)
|
||||||
{
|
{
|
||||||
which = 0;
|
which = 0;
|
||||||
SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp");
|
SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp");
|
||||||
@ -2203,7 +2075,6 @@ void CSplitWindow::clickLeft(tribool down, bool previousState)
|
|||||||
|
|
||||||
void CCreInfoWindow::show(SDL_Surface * to)
|
void CCreInfoWindow::show(SDL_Surface * to)
|
||||||
{
|
{
|
||||||
char pom[15];
|
|
||||||
blitAt(*bitmap,pos.x,pos.y,to);
|
blitAt(*bitmap,pos.x,pos.y,to);
|
||||||
anim->blitPic(to,pos.x+21,pos.y+48,(type) && !(anf%4));
|
anim->blitPic(to,pos.x+21,pos.y+48,(type) && !(anf%4));
|
||||||
if(++anf==4)
|
if(++anf==4)
|
||||||
@ -2569,7 +2440,8 @@ CMinorResDataBar::~CMinorResDataBar()
|
|||||||
}
|
}
|
||||||
|
|
||||||
CObjectListWindow::CObjectListWindow(const std::vector<int> &_items, CPicture * titlePic, std::string _title, std::string _descr,
|
CObjectListWindow::CObjectListWindow(const std::vector<int> &_items, CPicture * titlePic, std::string _title, std::string _descr,
|
||||||
boost::function<void(int)> Callback, int initState):items(_items), title(_title), descr(_descr),selected(initState)
|
boost::function<void(int)> Callback, int initState)
|
||||||
|
:title(_title), descr(_descr),items(_items),selected(initState)
|
||||||
{
|
{
|
||||||
init = false;
|
init = false;
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||||
@ -2896,7 +2768,7 @@ std::string CTradeWindow::CTradeableItem::getName(int number /*= -1*/) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
CTradeWindow::CTradeWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode)
|
CTradeWindow::CTradeWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode)
|
||||||
: market(Market), hero(Hero), hLeft(NULL), hRight(NULL), readyToTrade(false), arts(NULL)
|
: market(Market), hero(Hero), arts(NULL), hLeft(NULL), hRight(NULL), readyToTrade(false)
|
||||||
{
|
{
|
||||||
type = BLOCK_ADV_HOTKEYS;
|
type = BLOCK_ADV_HOTKEYS;
|
||||||
mode = Mode;
|
mode = Mode;
|
||||||
@ -4553,7 +4425,7 @@ CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance
|
|||||||
pos.h = screen->h;
|
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(pos.x+92, pos.y+127, 4, Point(0,96), bg, Point(93,127), up, down, removableUnits);
|
||||||
garr->splitButtons.push_back(new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+88,pos.y+314,"IDV6432.DEF"));
|
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);
|
quit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CGarrisonWindow::close,this),pos.x+399,pos.y+314,"IOK6432.DEF",SDLK_RETURN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5186,7 +5058,7 @@ void CArtifactsOfHero::eraseSlotData (CArtPlace* artPlace, int slotID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CArtifactsOfHero::CArtifactsOfHero(const Point &position) :
|
CArtifactsOfHero::CArtifactsOfHero(const Point &position) :
|
||||||
backpackPos(0), updateState(false), commonInfo(NULL), curHero(NULL), allowedAssembling(true)
|
curHero(NULL), backpackPos(0), commonInfo(NULL), updateState(false), allowedAssembling(true)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||||
pos += position;
|
pos += position;
|
||||||
@ -5570,8 +5442,8 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) : bg(NULL)
|
|||||||
//garrison interface
|
//garrison interface
|
||||||
garr = new CGarrisonInt(pos.x + 69, pos.y + 131, 4, Point(418,0), bg, Point(69,131), heroInst[0],heroInst[1], true, true);
|
garr = new CGarrisonInt(pos.x + 69, pos.y + 131, 4, Point(418,0), bg, Point(69,131), heroInst[0],heroInst[1], true, true);
|
||||||
|
|
||||||
garr->splitButtons.push_back(new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+10,pos.y+132,"TSBTNS.DEF"));
|
garr->addSplitBtn(new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+10,pos.y+132,"TSBTNS.DEF"));
|
||||||
garr->splitButtons.push_back(new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+740,pos.y+132,"TSBTNS.DEF"));
|
garr->addSplitBtn(new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+740,pos.y+132,"TSBTNS.DEF"));
|
||||||
}
|
}
|
||||||
|
|
||||||
CExchangeWindow::~CExchangeWindow() //d-tor
|
CExchangeWindow::~CExchangeWindow() //d-tor
|
||||||
@ -5844,7 +5716,7 @@ void CTransformerWindow::CItem::clickLeft(tribool down, bool previousState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CTransformerWindow::CItem::CItem(CTransformerWindow * _parent, int _size, int _id):
|
CTransformerWindow::CItem::CItem(CTransformerWindow * _parent, int _size, int _id):
|
||||||
parent(_parent), id(_id), size(_size)
|
id(_id), size(_size), parent(_parent)
|
||||||
{
|
{
|
||||||
used = LCLICK;
|
used = LCLICK;
|
||||||
left = true;
|
left = true;
|
||||||
@ -5981,8 +5853,8 @@ void CUniversityWindow::CItem::showAll(SDL_Surface * to)
|
|||||||
CPicture::showAll(to);
|
CPicture::showAll(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
CUniversityWindow::CItem::CItem(CUniversityWindow * _parent, int _ID, int X, int Y):ID(_ID), parent(_parent),
|
CUniversityWindow::CItem::CItem(CUniversityWindow * _parent, int _ID, int X, int Y):
|
||||||
CPicture (graphics->abils44->ourImages[_ID*3+3].bitmap,X,Y,false)
|
CPicture (graphics->abils44->ourImages[_ID*3+3].bitmap,X,Y,false),ID(_ID), parent(_parent)
|
||||||
{
|
{
|
||||||
used = LCLICK | RCLICK | HOVER;
|
used = LCLICK | RCLICK | HOVER;
|
||||||
}
|
}
|
||||||
@ -6080,9 +5952,8 @@ void CUnivConfirmWindow::makeDeal(int skill)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object):
|
CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object):
|
||||||
hero(visitor), fort(object)
|
fort(object),hero(visitor)
|
||||||
{
|
{
|
||||||
{
|
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||||
|
|
||||||
slotsCount=7;
|
slotsCount=7;
|
||||||
@ -6108,9 +5979,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn
|
|||||||
upgradeAll = new AdventureMapButton(CGI->generaltexth->allTexts[432],"",boost::bind(&CHillFortWindow::makeDeal, this, slotsCount), 30, 231, getDefForSlot(slotsCount));
|
upgradeAll = new AdventureMapButton(CGI->generaltexth->allTexts[432],"",boost::bind(&CHillFortWindow::makeDeal, this, slotsCount), 30, 231, getDefForSlot(slotsCount));
|
||||||
quit = new AdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 294, 275, "IOKAY.DEF", SDLK_RETURN);
|
quit = new AdventureMapButton("","",boost::bind(&CGuiHandler::popIntTotally, &GH, this), 294, 275, "IOKAY.DEF", SDLK_RETURN);
|
||||||
bar = new CGStatusBar(327, 332);
|
bar = new CGStatusBar(327, 332);
|
||||||
|
|
||||||
}
|
|
||||||
BLOCK_CAPTURING;
|
|
||||||
garr = new CGarrisonInt(pos.x+108, pos.y+60, 18, Point(),bg->bg,Point(108,60),hero,NULL);
|
garr = new CGarrisonInt(pos.x+108, pos.y+60, 18, Point(),bg->bg,Point(108,60),hero,NULL);
|
||||||
updateGarrisons();
|
updateGarrisons();
|
||||||
}
|
}
|
||||||
@ -6552,7 +6421,7 @@ void CLabel::showAll(SDL_Surface * to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CLabel::CLabel(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= zwykly*/, const std::string &Text /*= ""*/)
|
CLabel::CLabel(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= zwykly*/, const std::string &Text /*= ""*/)
|
||||||
:font(Font), color(Color), text(Text), alignment(Align)
|
:alignment(Align), font(Font), color(Color), text(Text)
|
||||||
{
|
{
|
||||||
autoRedraw = true;
|
autoRedraw = true;
|
||||||
pos.x += x;
|
pos.x += x;
|
||||||
@ -6574,7 +6443,7 @@ void CLabel::setTxt(const std::string &Txt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= zwykly*/)
|
CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= zwykly*/)
|
||||||
:CLabel(rect.x, rect.y, Font, Align, Color, Text), slider(NULL), sliderStyle(SliderStyle)
|
:CLabel(rect.x, rect.y, Font, Align, Color, Text), sliderStyle(SliderStyle), slider(NULL)
|
||||||
{
|
{
|
||||||
redrawParentOnScrolling = false;
|
redrawParentOnScrolling = false;
|
||||||
autoRedraw = false;
|
autoRedraw = false;
|
||||||
|
@ -222,14 +222,14 @@ class CGarrisonInt :public CIntObject
|
|||||||
public:
|
public:
|
||||||
int interx; //space between slots
|
int interx; //space between slots
|
||||||
Point garOffset, //offset between garrisons (not used if only one hero)
|
Point garOffset, //offset between garrisons (not used if only one hero)
|
||||||
surOffset; //offset between garrison position on the bg surface and position on the screen
|
surOffset; //offset between garrison position on the bg surface and position on the screen
|
||||||
CGarrisonSlot *highlighted; //chosen slot
|
CGarrisonSlot *highlighted; //chosen slot
|
||||||
std::vector<AdventureMapButton *> splitButtons; //may be empty if no buttons
|
std::vector<AdventureMapButton *> splitButtons; //may be empty if no buttons
|
||||||
|
|
||||||
SDL_Surface *&sur; //bg surface
|
SDL_Surface *&sur; //bg surface
|
||||||
int p2, //TODO: comment me
|
int p2, //TODO: comment me
|
||||||
shiftPos;//1st slot of the second row, set shiftPoint for effect
|
shiftPos;//1st slot of the second row, set shiftPoint for effect
|
||||||
bool ignoreEvent, update, active, splitting, pb,
|
bool splitting, pb,
|
||||||
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
|
||||||
@ -238,16 +238,15 @@ public:
|
|||||||
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*> *sup, *sdown; //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 *oup, *odown; //upper and lower garrisons (heroes or towns)
|
||||||
|
|
||||||
|
void addSplitBtn(AdventureMapButton * button);
|
||||||
|
void createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int distance, int posY, int Upg );
|
||||||
|
|
||||||
void activate();
|
void activate();
|
||||||
void deactivate();
|
|
||||||
void show(SDL_Surface * to);
|
|
||||||
void activeteSlots();
|
|
||||||
void deactiveteSlots();
|
|
||||||
void deleteSlots();
|
|
||||||
void createSlots();
|
void createSlots();
|
||||||
|
void deleteSlots();
|
||||||
void recreateSlots();
|
void recreateSlots();
|
||||||
|
|
||||||
void splitClick(); //handles click on split button
|
void splitClick(); //handles click on split button
|
||||||
|
Loading…
x
Reference in New Issue
Block a user