From c5b74a2dce3a6017be5cc04aeefb58e43b441b25 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 13 Jan 2014 17:44:21 +0000 Subject: [PATCH] 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 --- client/CPreGame.cpp | 7 +++++-- client/battle/CBattleInterface.cpp | 6 +++--- client/gui/CIntObjectClasses.cpp | 20 ++++++++++++++++++-- client/gui/CIntObjectClasses.h | 2 ++ lib/CDefObjInfoHandler.cpp | 1 + server/CGameHandler.cpp | 2 ++ 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index d1355fd9d..d33438a1c 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -3139,8 +3139,6 @@ void CBonusSelection::init() 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); 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 if (ourCampaign->camp->header.name.length()) @@ -3299,12 +3297,17 @@ void CBonusSelection::selectMap(int mapNr, bool initialSelect) // draw start button restartB->disable(); startB->enable(); + if (!ourCampaign->mapsConquered.empty()) + backB->block(true); + else + backB->block(false); } else { // draw restart button startB->disable(); restartB->enable(); + backB->block(false); } startInfo.difficulty = ourCampaign->camp->scenarios[mapNr].difficulty; diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index 1060b1987..391b8497e 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -1911,9 +1911,9 @@ void CBattleInterface::blockUI(bool on) bFlee->block(on || !curInt->cb->battleCanFlee()); bSurrender->block(on || curInt->cb->battleGetSurrenderCost() < 0); - // never block autofight button - //FIXME: is that correct? - bAutofight->block(false); //curInt->isAutoFightOn + // block only if during enemy turn and auto-fight is off + // othervice - crash on accessing non-exisiting active stack + bAutofight->block(curInt->isAutoFightOn || activeStack); if(tacticsMode && btactEnd && btactNext) { diff --git a/client/gui/CIntObjectClasses.cpp b/client/gui/CIntObjectClasses.cpp index 90fb22f19..c3059e9cc 100644 --- a/client/gui/CIntObjectClasses.cpp +++ b/client/gui/CIntObjectClasses.cpp @@ -309,6 +309,22 @@ CAdventureMapButton::CAdventureMapButton( const std::pairtraceStream() << "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) { if(isBlocked()) @@ -327,11 +343,11 @@ void CAdventureMapButton::clickLeft(tribool down, bool previousState) if (actOnDown && down) { - callback(); + onButtonClicked(); } else if (!actOnDown && previousState && (down==false)) { - callback(); + onButtonClicked(); } } diff --git a/client/gui/CIntObjectClasses.h b/client/gui/CIntObjectClasses.h index 811b869ab..af33588a5 100644 --- a/client/gui/CIntObjectClasses.h +++ b/client/gui/CIntObjectClasses.h @@ -124,6 +124,8 @@ class CAdventureMapButton : public CButtonBase { std::vector imageNames;//store list of images that can be used by this button size_t currentImage; + + void onButtonClicked(); // calls callback public: std::map hoverTexts; //text for statusbar std::string helpBox; //for right-click help diff --git a/lib/CDefObjInfoHandler.cpp b/lib/CDefObjInfoHandler.cpp index cc54ae368..f47509a70 100644 --- a/lib/CDefObjInfoHandler.cpp +++ b/lib/CDefObjInfoHandler.cpp @@ -35,6 +35,7 @@ static bool isVisitableFromTop(int identifier, int type) Obj::BOAT, Obj::WHIRLPOOL, Obj::GARRISON, + Obj::GARRISON2, Obj::SCHOLAR, Obj::CAMPFIRE, Obj::BORDERGUARD, diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 6b68064c4..541182cc6 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2390,6 +2390,8 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID, COMPLAIN_RETF("No such town (ID=%s)!", tid); 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); + 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);