mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
- fixes #1276
- minor fix to json arrays merging - fixed update of growth icons on town screen
This commit is contained in:
parent
3943c10f1a
commit
4724ccbb45
@ -37,6 +37,14 @@ using namespace boost::assign;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const CBuilding * CBuildingRect::getBuilding()
|
||||||
|
{
|
||||||
|
if (str->hiddenUpgrade) // hidden upgrades, e.g. hordes - return base (dwelling for hordes)
|
||||||
|
return town->town->buildings[str->building->getBase()];
|
||||||
|
|
||||||
|
return str->building;
|
||||||
|
}
|
||||||
|
|
||||||
CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str)
|
CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str)
|
||||||
:CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE | CShowableAnim::USE_RLE),
|
:CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE | CShowableAnim::USE_RLE),
|
||||||
parent(Par),
|
parent(Par),
|
||||||
@ -94,18 +102,18 @@ void CBuildingRect::hover(bool on)
|
|||||||
|
|
||||||
void CBuildingRect::clickLeft(tribool down, bool previousState)
|
void CBuildingRect::clickLeft(tribool down, bool previousState)
|
||||||
{
|
{
|
||||||
if( previousState && !down && area && (parent->selectedBuilding==this) && str->building )
|
if( previousState && !down && area && (parent->selectedBuilding==this) && getBuilding() )
|
||||||
if (!CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image
|
if (!CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image
|
||||||
parent->buildingClicked(str->building->bid);
|
parent->buildingClicked(getBuilding()->bid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBuildingRect::clickRight(tribool down, bool previousState)
|
void CBuildingRect::clickRight(tribool down, bool previousState)
|
||||||
{
|
{
|
||||||
if((!area) || (!((bool)down)) || (this!=parent->selectedBuilding) || str->building == nullptr)
|
if((!area) || (!((bool)down)) || (this!=parent->selectedBuilding) || getBuilding() == nullptr)
|
||||||
return;
|
return;
|
||||||
if( !CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image
|
if( !CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image
|
||||||
{
|
{
|
||||||
BuildingID bid = str->building->bid;
|
BuildingID bid = getBuilding()->bid;
|
||||||
const CBuilding *bld = town->town->buildings[bid];
|
const CBuilding *bld = town->town->buildings[bid];
|
||||||
if (bid < BuildingID::DWELL_FIRST)
|
if (bid < BuildingID::DWELL_FIRST)
|
||||||
{
|
{
|
||||||
@ -193,19 +201,18 @@ void CBuildingRect::showAll(SDL_Surface * to)
|
|||||||
blitAtLoc(border,0,0,to);
|
blitAtLoc(border,0,0,to);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getBuildingSubtitle(const CStructure * structure)//hover text for building
|
std::string CBuildingRect::getSubtitle()//hover text for building
|
||||||
{
|
{
|
||||||
const CGTownInstance * t = LOCPLINT->castleInt->town;
|
if (!getBuilding())
|
||||||
if (!structure->building)
|
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
int bid = structure->building->bid;
|
int bid = getBuilding()->bid;
|
||||||
|
|
||||||
if (bid<30)//non-dwellings - only buiding name
|
if (bid<30)//non-dwellings - only buiding name
|
||||||
return t->town->buildings[structure->building->bid]->Name();
|
return town->town->buildings[getBuilding()->bid]->Name();
|
||||||
else//dwellings - recruit %creature%
|
else//dwellings - recruit %creature%
|
||||||
{
|
{
|
||||||
auto & availableCreatures = t->creatures[(bid-30)%GameConstants::CREATURES_PER_TOWN].second;
|
auto & availableCreatures = town->creatures[(bid-30)%GameConstants::CREATURES_PER_TOWN].second;
|
||||||
if(availableCreatures.size())
|
if(availableCreatures.size())
|
||||||
{
|
{
|
||||||
int creaID = availableCreatures.back();//taking last of available creatures
|
int creaID = availableCreatures.back();//taking last of available creatures
|
||||||
@ -237,7 +244,7 @@ void CBuildingRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
|
|||||||
|| (*parent->selectedBuilding)<(*this)) //or we are on top
|
|| (*parent->selectedBuilding)<(*this)) //or we are on top
|
||||||
{
|
{
|
||||||
parent->selectedBuilding = this;
|
parent->selectedBuilding = this;
|
||||||
GH.statusbar->print(getBuildingSubtitle(str));
|
GH.statusbar->print(getSubtitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,11 @@ class CCreature;
|
|||||||
/// Building "button"
|
/// Building "button"
|
||||||
class CBuildingRect : public CShowableAnim
|
class CBuildingRect : public CShowableAnim
|
||||||
{
|
{
|
||||||
|
std::string getSubtitle();
|
||||||
public:
|
public:
|
||||||
|
/// returns building associated with this structure
|
||||||
|
const CBuilding * getBuilding();
|
||||||
|
|
||||||
CCastleBuildings * parent;
|
CCastleBuildings * parent;
|
||||||
const CGTownInstance * town;
|
const CGTownInstance * town;
|
||||||
const CStructure* str;
|
const CStructure* str;
|
||||||
|
@ -1570,12 +1570,12 @@ void JsonUtils::merge(JsonNode & dest, JsonNode & source)
|
|||||||
for (size_t i=0; i< total; i++)
|
for (size_t i=0; i< total; i++)
|
||||||
merge(dest.Vector()[i], source.Vector()[i]);
|
merge(dest.Vector()[i], source.Vector()[i]);
|
||||||
|
|
||||||
if (source.Vector().size() < dest.Vector().size())
|
if (dest.Vector().size() < source.Vector().size())
|
||||||
{
|
{
|
||||||
//reserve place and *move* data from source to dest
|
//reserve place and *move* remaining data from source to dest
|
||||||
source.Vector().reserve(source.Vector().size() + dest.Vector().size());
|
source.Vector().reserve(source.Vector().size() + dest.Vector().size());
|
||||||
|
|
||||||
std::move(source.Vector().begin(), source.Vector().end(),
|
std::move(source.Vector().begin() + total, source.Vector().end(),
|
||||||
std::back_inserter(dest.Vector()));
|
std::back_inserter(dest.Vector()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2482,9 +2482,6 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//We know what has been built, appluy changes
|
|
||||||
sendAndApply(&ns);
|
|
||||||
|
|
||||||
//reveal ground for lookout tower
|
//reveal ground for lookout tower
|
||||||
FoWChange fw;
|
FoWChange fw;
|
||||||
fw.player = t->tempOwner;
|
fw.player = t->tempOwner;
|
||||||
@ -2505,6 +2502,8 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
|
|||||||
sendAndApply(&sr);
|
sendAndApply(&sr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//We know what has been built, appluy changes. Do this as final step to properly update town window
|
||||||
|
sendAndApply(&ns);
|
||||||
|
|
||||||
if(t->visitingHero)
|
if(t->visitingHero)
|
||||||
vistiCastleObjects (t, t->visitingHero);
|
vistiCastleObjects (t, t->visitingHero);
|
||||||
|
Loading…
Reference in New Issue
Block a user