mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
* fix for problems after r-clicking hero in tavern
* refactored Options::show * minor improvements
This commit is contained in:
@@ -386,23 +386,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
|
|||||||
void CHeroWindow::quit()
|
void CHeroWindow::quit()
|
||||||
{
|
{
|
||||||
LOCPLINT->popInt(this);
|
LOCPLINT->popInt(this);
|
||||||
|
dispose();
|
||||||
SDL_FreeSurface(curBack);
|
|
||||||
curBack = NULL;
|
|
||||||
curHero = NULL;
|
|
||||||
|
|
||||||
for(size_t g=0; g<artWorn.size(); ++g)
|
|
||||||
{
|
|
||||||
delete artWorn[g];
|
|
||||||
artWorn[g] = NULL;
|
|
||||||
}
|
|
||||||
for(size_t g=0; g<backpack.size(); ++g)
|
|
||||||
{
|
|
||||||
delete backpack[g];
|
|
||||||
backpack[g] = NULL;
|
|
||||||
}
|
|
||||||
backpack.clear();
|
|
||||||
activeArtPlace = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHeroWindow::activate()
|
void CHeroWindow::activate()
|
||||||
@@ -687,6 +671,26 @@ void CHeroWindow::redrawCurBack()
|
|||||||
CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack);
|
CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CHeroWindow::dispose()
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(curBack);
|
||||||
|
curBack = NULL;
|
||||||
|
curHero = NULL;
|
||||||
|
|
||||||
|
for(size_t g=0; g<artWorn.size(); ++g)
|
||||||
|
{
|
||||||
|
delete artWorn[g];
|
||||||
|
artWorn[g] = NULL;
|
||||||
|
}
|
||||||
|
for(size_t g=0; g<backpack.size(); ++g)
|
||||||
|
{
|
||||||
|
delete backpack[g];
|
||||||
|
backpack[g] = NULL;
|
||||||
|
}
|
||||||
|
backpack.clear();
|
||||||
|
activeArtPlace = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
CArtPlace::CArtPlace(const CArtifact* Art): active(false), clicked(false), ourArt(Art)/*,
|
CArtPlace::CArtPlace(const CArtifact* Art): active(false), clicked(false), ourArt(Art)/*,
|
||||||
spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false),
|
spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false),
|
||||||
warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false),
|
warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false),
|
||||||
|
@@ -130,7 +130,8 @@ public:
|
|||||||
void deactivate(); //activates hero window;
|
void deactivate(); //activates hero window;
|
||||||
virtual void show(SDL_Surface * to); //shows hero window
|
virtual void show(SDL_Surface * to); //shows hero window
|
||||||
void redrawCurBack(); //redraws curBAck from scratch
|
void redrawCurBack(); //redraws curBAck from scratch
|
||||||
void quit(); //stops displaying hero window
|
void dispose(); //free resources not needed after closing windows and reset state
|
||||||
|
void quit(); //stops displaying hero window and disposes
|
||||||
void dismissCurrent(); //dissmissed currently displayed hero (curHero)
|
void dismissCurrent(); //dissmissed currently displayed hero (curHero)
|
||||||
void questlog(); //show quest log in hero window
|
void questlog(); //show quest log in hero window
|
||||||
void scrollBackpack(int dir); //dir==-1 => to left; dir==-2 => to right
|
void scrollBackpack(int dir); //dir==-1 => to left; dir==-2 => to right
|
||||||
|
@@ -775,7 +775,9 @@ void Options::init()
|
|||||||
}
|
}
|
||||||
void Options::show()
|
void Options::show()
|
||||||
{
|
{
|
||||||
if (showed)return;
|
if (showed)
|
||||||
|
return;
|
||||||
|
|
||||||
PreGameTab::show();
|
PreGameTab::show();
|
||||||
MapSel & ms = CPG->ourScenSel->mapsel;
|
MapSel & ms = CPG->ourScenSel->mapsel;
|
||||||
blitAt(bg,3,6);
|
blitAt(bg,3,6);
|
||||||
@@ -791,71 +793,80 @@ void Options::show()
|
|||||||
CPG->interested.clear();
|
CPG->interested.clear();
|
||||||
CSDL_Ext::printAtMiddle("Advanced Options",225,35,GEORXX);
|
CSDL_Ext::printAtMiddle("Advanced Options",225,35,GEORXX);
|
||||||
CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[521],224,544,GEOR13); // Player Turn Duration
|
CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[521],224,544,GEOR13); // Player Turn Duration
|
||||||
int playersSoFar=0;
|
|
||||||
|
int playersSoFar = 0;
|
||||||
|
|
||||||
for (size_t i=0; i < PLAYER_LIMIT; ++i)
|
for (size_t i=0; i < PLAYER_LIMIT; ++i)
|
||||||
{
|
{
|
||||||
if (!(ms.selMaps[ms.selected]->players[i].canComputerPlay || ms.selMaps[ms.selected]->players[i].canComputerPlay))
|
PlayerInfo &curInfo = ms.selMaps[ms.selected]->players[i]; //map information for current player
|
||||||
|
|
||||||
|
if(!(curInfo.canComputerPlay || curInfo.canComputerPlay)) //no one can play - player not present on the map (empty entry)
|
||||||
continue;
|
continue;
|
||||||
for (size_t hi=0; hi<ms.selMaps[ms.selected]->players[i].heroesNames.size(); hi++) {
|
|
||||||
usedHeroes.insert(ms.selMaps[ms.selected]->players[i].heroesNames[hi].heroID);
|
for(size_t hi=0; hi<curInfo.heroesNames.size(); hi++)
|
||||||
}
|
usedHeroes.insert(curInfo.heroesNames[hi].heroID);
|
||||||
|
|
||||||
blitAt(bgs[i],57,128+playersSoFar*50);
|
blitAt(bgs[i],57,128+playersSoFar*50);
|
||||||
poptions.push_back(new PlayerOptions(playersSoFar,i));
|
|
||||||
poptions[poptions.size()-1]->nr=playersSoFar;
|
|
||||||
poptions[poptions.size()-1]->color=(Ecolor)i;
|
|
||||||
|
|
||||||
if(CPG->ret.playerInfos[playersSoFar].hero == -1)
|
PlayerOptions *options = new PlayerOptions(playersSoFar,i); //new options entry for current player
|
||||||
|
options->nr = playersSoFar;
|
||||||
|
options->color = (Ecolor)i;
|
||||||
|
poptions.push_back(options);
|
||||||
|
|
||||||
|
assert(CPG->ret.playerInfos.size() > playersSoFar);
|
||||||
|
PlayerSettings &curSettings = CPG->ret.playerInfos[playersSoFar]; //settings entry for current players
|
||||||
|
|
||||||
|
if(curSettings.hero == -1)
|
||||||
{
|
{
|
||||||
poptions[poptions.size()-1]->Hleft.show();
|
options->Hleft.show();
|
||||||
poptions[poptions.size()-1]->Hright.show();
|
options->Hright.show();
|
||||||
CPG->btns.push_back(&poptions[poptions.size()-1]->Hleft);
|
CPG->btns.push_back(&options->Hleft);
|
||||||
CPG->btns.push_back(&poptions[poptions.size()-1]->Hright);
|
CPG->btns.push_back(&options->Hright);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getNextCastle(CPG->ret.playerInfos[playersSoFar].castle,&ms.selMaps[ms.selected]->players[i]) != CPG->ret.playerInfos[playersSoFar].castle)
|
if(getNextCastle(curSettings.castle,&curInfo) != curSettings.castle)
|
||||||
{
|
{
|
||||||
poptions[poptions.size()-1]->Cleft.show();
|
options->Cleft.show();
|
||||||
poptions[poptions.size()-1]->Cright.show();
|
options->Cright.show();
|
||||||
CPG->btns.push_back(&poptions[poptions.size()-1]->Cleft);
|
CPG->btns.push_back(&options->Cleft);
|
||||||
CPG->btns.push_back(&poptions[poptions.size()-1]->Cright);
|
CPG->btns.push_back(&options->Cright);
|
||||||
}
|
}
|
||||||
|
|
||||||
poptions[poptions.size()-1]->Bleft.show();
|
options->Bleft.show();
|
||||||
poptions[poptions.size()-1]->Bright.show();
|
options->Bright.show();
|
||||||
CPG->btns.push_back(&poptions[poptions.size()-1]->Bleft);
|
CPG->btns.push_back(&options->Bleft);
|
||||||
CPG->btns.push_back(&poptions[poptions.size()-1]->Bright);
|
CPG->btns.push_back(&options->Bright);
|
||||||
|
|
||||||
|
CSDL_Ext::printAtMiddle(curSettings.name,111,137+playersSoFar*50,GEOR13,zwykly);
|
||||||
CSDL_Ext::printAtMiddle(CPG->ret.playerInfos[playersSoFar].name,111,137+playersSoFar*50,GEOR13,zwykly);
|
if (curInfo.canHumanPlay)
|
||||||
if (ms.selMaps[ms.selected]->players[i].canHumanPlay)
|
|
||||||
{
|
{
|
||||||
poptions[poptions.size()-1]->flag.show();
|
options->flag.show();
|
||||||
CPG->btns.push_back(&poptions[poptions.size()-1]->flag);
|
CPG->btns.push_back(&options->flag);
|
||||||
if (ms.selMaps[ms.selected]->players[i].canComputerPlay) {
|
if(curInfo.canComputerPlay)
|
||||||
CSDL_Ext::printAtMiddleWB("Human or CPU",86,163+playersSoFar*50,GEORM,7,zwykly);
|
CSDL_Ext::printAtMiddleWB("Human or CPU",86,163+playersSoFar*50,GEORM,7,zwykly);
|
||||||
}
|
else
|
||||||
else {
|
|
||||||
CSDL_Ext::printAtMiddleWB("Human",86,163+playersSoFar*50,GEORM,6,zwykly);
|
CSDL_Ext::printAtMiddleWB("Human",86,163+playersSoFar*50,GEORM,6,zwykly);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
CSDL_Ext::printAtMiddleWB("CPU",86,163+playersSoFar*50,GEORM,6,zwykly);
|
CSDL_Ext::printAtMiddleWB("CPU",86,163+playersSoFar*50,GEORM,6,zwykly);
|
||||||
}
|
}
|
||||||
playersSoFar++;
|
playersSoFar++;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->allTexts[516],221,63,GEOR13,55,zwykly);
|
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->allTexts[516],221,63,GEOR13,55,zwykly);
|
||||||
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[256].second),109,109,GEOR13,14);
|
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[256].second),109,109,GEOR13,14);
|
||||||
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[259].second),201,109,GEOR13,10);
|
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[259].second),201,109,GEOR13,10);
|
||||||
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[260].second),275,109,GEOR13,10);
|
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[260].second),275,109,GEOR13,10);
|
||||||
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[261].second),354,109,GEOR13,10);
|
CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[261].second),354,109,GEOR13,10);
|
||||||
turnLength->activate();
|
turnLength->activate();
|
||||||
for (size_t i=0; i < poptions.size(); ++i) {
|
|
||||||
|
for (size_t i=0; i < poptions.size(); ++i)
|
||||||
showIcon(-2,i,false);
|
showIcon(-2,i,false);
|
||||||
}
|
|
||||||
for(int i=0;i<12;i++)
|
for(int i=0;i<12;i++)
|
||||||
turnLength->moveDown();
|
turnLength->moveDown();
|
||||||
//SDL_Flip(screen);
|
|
||||||
CSDL_Ext::update(screen);
|
CSDL_Ext::update(screen);
|
||||||
}
|
}
|
||||||
void Options::hide()
|
void Options::hide()
|
||||||
|
@@ -2874,8 +2874,9 @@ void CTavernWindow::show(SDL_Surface * to)
|
|||||||
{
|
{
|
||||||
HeroPortrait *sel = selected ? &h2 : &h1;
|
HeroPortrait *sel = selected ? &h2 : &h1;
|
||||||
|
|
||||||
if (selected != oldSelected) {
|
if (selected != oldSelected && !recruit->blocked)
|
||||||
// Selected hero just changed. Update RECRUIT button hover text.
|
{
|
||||||
|
// Selected hero just changed. Update RECRUIT button hover text if recruitment is allowed.
|
||||||
oldSelected = selected;
|
oldSelected = selected;
|
||||||
|
|
||||||
recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[3]; //Recruit %s the %s
|
recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[3]; //Recruit %s the %s
|
||||||
@@ -3225,6 +3226,11 @@ CRClickPopupInt::CRClickPopupInt( IShowActivable *our, bool deleteInt )
|
|||||||
|
|
||||||
CRClickPopupInt::~CRClickPopupInt()
|
CRClickPopupInt::~CRClickPopupInt()
|
||||||
{
|
{
|
||||||
|
//workaround for hero window issue - if it's our interface, call dispose to properly reset it's state
|
||||||
|
//TODO? it might be better to rewrite hero window so it will bee newed/deleted on opening / closing (not effort-worthy now, but on some day...?)
|
||||||
|
if(inner == LOCPLINT->adventureInt->heroWindow)
|
||||||
|
LOCPLINT->adventureInt->heroWindow->dispose();
|
||||||
|
|
||||||
if(delInner)
|
if(delInner)
|
||||||
delete inner;
|
delete inner;
|
||||||
}
|
}
|
||||||
|
@@ -27,8 +27,11 @@ CSndHandler::~CSndHandler()
|
|||||||
// them. */
|
// them. */
|
||||||
CSndHandler::CSndHandler(std::string fname)
|
CSndHandler::CSndHandler(std::string fname)
|
||||||
{
|
{
|
||||||
mfile = new boost::iostreams::mapped_file_source(fname);
|
try //c-tor of mapped_file_source throws exception on failure
|
||||||
if (!mfile->is_open())
|
{
|
||||||
|
mfile = new boost::iostreams::mapped_file_source(fname);
|
||||||
|
} HANDLE_EXCEPTION
|
||||||
|
if (!mfile->is_open()) //just in case
|
||||||
{
|
{
|
||||||
tlog1 << "Cannot open " << fname << std::endl;
|
tlog1 << "Cannot open " << fname << std::endl;
|
||||||
throw std::string("Cannot open ")+fname;
|
throw std::string("Cannot open ")+fname;
|
||||||
|
Reference in New Issue
Block a user