1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Miscellaneous fixes:

- proper block of "back" button in campaign menu.
- proper block of AI switch in battles
- vertical garrisons can now be attacked from top
- better UI logging, vcmi will print to log file all pressed buttons
- server will not try to build already existing building
This commit is contained in:
Ivan Savenko
2014-01-13 17:44:21 +00:00
parent fb5c9fc972
commit c5b74a2dce
6 changed files with 31 additions and 7 deletions

View File

@ -3139,8 +3139,6 @@ void CBonusSelection::init()
startB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::startMap, this), 475, 536, "CBBEGIB.DEF", SDLK_RETURN); startB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::startMap, this), 475, 536, "CBBEGIB.DEF", SDLK_RETURN);
restartB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::restartMap, this), 475, 536, "CBRESTB.DEF", SDLK_RETURN); restartB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::restartMap, this), 475, 536, "CBRESTB.DEF", SDLK_RETURN);
backB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::goBack, this), 624, 536, "CBCANCB.DEF", SDLK_ESCAPE); backB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::goBack, this), 624, 536, "CBCANCB.DEF", SDLK_ESCAPE);
// block back button for in-progress campaigns. May not be H3 behaviour but avoids the crash
backB->block(!ourCampaign->mapsConquered.empty());
//campaign name //campaign name
if (ourCampaign->camp->header.name.length()) if (ourCampaign->camp->header.name.length())
@ -3299,12 +3297,17 @@ void CBonusSelection::selectMap(int mapNr, bool initialSelect)
// draw start button // draw start button
restartB->disable(); restartB->disable();
startB->enable(); startB->enable();
if (!ourCampaign->mapsConquered.empty())
backB->block(true);
else
backB->block(false);
} }
else else
{ {
// draw restart button // draw restart button
startB->disable(); startB->disable();
restartB->enable(); restartB->enable();
backB->block(false);
} }
startInfo.difficulty = ourCampaign->camp->scenarios[mapNr].difficulty; startInfo.difficulty = ourCampaign->camp->scenarios[mapNr].difficulty;

View File

@ -1911,9 +1911,9 @@ void CBattleInterface::blockUI(bool on)
bFlee->block(on || !curInt->cb->battleCanFlee()); bFlee->block(on || !curInt->cb->battleCanFlee());
bSurrender->block(on || curInt->cb->battleGetSurrenderCost() < 0); bSurrender->block(on || curInt->cb->battleGetSurrenderCost() < 0);
// never block autofight button // block only if during enemy turn and auto-fight is off
//FIXME: is that correct? // othervice - crash on accessing non-exisiting active stack
bAutofight->block(false); //curInt->isAutoFightOn bAutofight->block(curInt->isAutoFightOn || activeStack);
if(tacticsMode && btactEnd && btactNext) if(tacticsMode && btactEnd && btactNext)
{ {

View File

@ -309,6 +309,22 @@ CAdventureMapButton::CAdventureMapButton( const std::pair<std::string, std::stri
pom[0] = help.first; pom[0] = help.first;
init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key); init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key);
} }
void CAdventureMapButton::onButtonClicked()
{
// debug logging to figure out pressed button (and as result - player actions) in case of crash
logAnim->traceStream() << "Button clicked at " << pos.x << "x" << pos.y;
CIntObject * parent = this->parent;
std::string prefix = "Parent is";
while (parent)
{
logAnim->traceStream() << prefix << typeid(*parent).name() << " at " << parent->pos.x << "x" << parent->pos.y;
parent = parent->parent;
prefix = '\t' + prefix;
}
callback();
}
void CAdventureMapButton::clickLeft(tribool down, bool previousState) void CAdventureMapButton::clickLeft(tribool down, bool previousState)
{ {
if(isBlocked()) if(isBlocked())
@ -327,11 +343,11 @@ void CAdventureMapButton::clickLeft(tribool down, bool previousState)
if (actOnDown && down) if (actOnDown && down)
{ {
callback(); onButtonClicked();
} }
else if (!actOnDown && previousState && (down==false)) else if (!actOnDown && previousState && (down==false))
{ {
callback(); onButtonClicked();
} }
} }

View File

@ -124,6 +124,8 @@ class CAdventureMapButton : public CButtonBase
{ {
std::vector<std::string> imageNames;//store list of images that can be used by this button std::vector<std::string> imageNames;//store list of images that can be used by this button
size_t currentImage; size_t currentImage;
void onButtonClicked(); // calls callback
public: public:
std::map<int, std::string> hoverTexts; //text for statusbar std::map<int, std::string> hoverTexts; //text for statusbar
std::string helpBox; //for right-click help std::string helpBox; //for right-click help

View File

@ -35,6 +35,7 @@ static bool isVisitableFromTop(int identifier, int type)
Obj::BOAT, Obj::BOAT,
Obj::WHIRLPOOL, Obj::WHIRLPOOL,
Obj::GARRISON, Obj::GARRISON,
Obj::GARRISON2,
Obj::SCHOLAR, Obj::SCHOLAR,
Obj::CAMPFIRE, Obj::CAMPFIRE,
Obj::BORDERGUARD, Obj::BORDERGUARD,

View File

@ -2390,6 +2390,8 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
COMPLAIN_RETF("No such town (ID=%s)!", tid); COMPLAIN_RETF("No such town (ID=%s)!", tid);
if(!t->town->buildings.count(requestedID)) if(!t->town->buildings.count(requestedID))
COMPLAIN_RETF("Town of faction %s does not have info about building ID=%s!", t->town->faction->name % tid); COMPLAIN_RETF("Town of faction %s does not have info about building ID=%s!", t->town->faction->name % tid);
if (t->hasBuilt(requestedID))
COMPLAIN_RETF("Building %s is already built in %s", t->town->buildings.at(requestedID)->Name() % t->name);
const CBuilding * requestedBuilding = t->town->buildings.at(requestedID); const CBuilding * requestedBuilding = t->town->buildings.at(requestedID);