From 9429cb4340ed4c1181419c7f1214b58a0f2bcdcb Mon Sep 17 00:00:00 2001 From: nordsoft Date: Wed, 7 Sep 2022 02:21:00 +0400 Subject: [PATCH] Add more objects into inspector --- lib/mapObjects/MiscObjects.h | 2 +- mapeditor/inspector.cpp | 124 ++++++++++++++++++++++++++++++----- mapeditor/inspector.h | 8 +++ mapeditor/mapcontroller.cpp | 1 + mapeditor/maphandler.cpp | 4 +- 5 files changed, 119 insertions(+), 20 deletions(-) diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index e970d9c44..8949debeb 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -445,7 +445,7 @@ public: } }; -class CGShipyard : public CGObjectInstance, public IShipyard +class DLL_LINKAGE CGShipyard : public CGObjectInstance, public IShipyard { public: void getOutOffsets(std::vector &offsets) const override; //offsets to obj pos when we boat can be placed diff --git a/mapeditor/inspector.cpp b/mapeditor/inspector.cpp index e3af1142b..19387d68c 100644 --- a/mapeditor/inspector.cpp +++ b/mapeditor/inspector.cpp @@ -13,11 +13,41 @@ Initializer::Initializer(CMap * m, CGObjectInstance * o) : map(m) INIT_OBJ_TYPE(CGResource); INIT_OBJ_TYPE(CGArtifact); INIT_OBJ_TYPE(CArmedInstance); + INIT_OBJ_TYPE(CGShipyard); + INIT_OBJ_TYPE(CGGarrison); INIT_OBJ_TYPE(CGMine); + INIT_OBJ_TYPE(CGDwelling); INIT_OBJ_TYPE(CGTownInstance); + INIT_OBJ_TYPE(CGHeroInstance); } void Initializer::initialize(CArmedInstance * o) +{ + if(!o) return; +} + +void Initializer::initialize(CGDwelling * o) +{ + if(!o) return; + + o->tempOwner = PlayerColor::NEUTRAL; +} + +void Initializer::initialize(CGGarrison * o) +{ + if(!o) return; + + o->tempOwner = PlayerColor::NEUTRAL; +} + +void Initializer::initialize(CGShipyard * o) +{ + if(!o) return; + + o->tempOwner = PlayerColor::NEUTRAL; +} + +void Initializer::initialize(CGHeroInstance * o) { if(!o) return; @@ -80,11 +110,38 @@ void Inspector::updateProperties(CArmedInstance * o) addProperty("Owner", o->tempOwner); } -void Inspector::updateProperties(CGTownInstance * o) +void Inspector::updateProperties(CGDwelling * o) { if(!o) return; addProperty("Owner", o->tempOwner, false); +} + +void Inspector::updateProperties(CGGarrison * o) +{ + if(!o) return; + + addProperty("Owner", o->tempOwner, false); +} + +void Inspector::updateProperties(CGShipyard * o) +{ + if(!o) return; + + addProperty("Owner", o->tempOwner, false); +} + +void Inspector::updateProperties(CGHeroInstance * o) +{ + if(!o) return; + + addProperty("Owner", o->tempOwner, o->ID == Obj::PRISON); //field is not editable for prison +} + +void Inspector::updateProperties(CGTownInstance * o) +{ + if(!o) return; + addProperty("Town name", o->name, false); } @@ -109,6 +166,8 @@ void Inspector::updateProperties(CGResource * o) addProperty("Amount", o->amount, false); } + + void Inspector::updateProperties() { if(!obj) @@ -125,10 +184,14 @@ void Inspector::updateProperties() addProperty("IsStatic", factory->isStaticObject()); UPDATE_OBJ_PROPERTIES(CArmedInstance); - UPDATE_OBJ_PROPERTIES(CGTownInstance); + UPDATE_OBJ_PROPERTIES(CGResource); UPDATE_OBJ_PROPERTIES(CGArtifact); UPDATE_OBJ_PROPERTIES(CGMine); - UPDATE_OBJ_PROPERTIES(CGResource); + UPDATE_OBJ_PROPERTIES(CGGarrison); + UPDATE_OBJ_PROPERTIES(CGShipyard); + UPDATE_OBJ_PROPERTIES(CGDwelling); + UPDATE_OBJ_PROPERTIES(CGTownInstance); + UPDATE_OBJ_PROPERTIES(CGHeroInstance); table->show(); } @@ -139,18 +202,6 @@ void Inspector::setProperty(const QString & key, const QVariant & value) if(!obj) return; - SET_PROPERTIES(CArmedInstance); - SET_PROPERTIES(CGTownInstance); - SET_PROPERTIES(CGArtifact); - SET_PROPERTIES(CGMine); - SET_PROPERTIES(CGResource); -} - -void Inspector::setProperty(CArmedInstance * object, const QString & key, const QVariant & value) -{ - if(!object) - return; - if(key == "Owner") { PlayerColor owner(value.toString().toInt()); @@ -158,9 +209,24 @@ void Inspector::setProperty(CArmedInstance * object, const QString & key, const owner = PlayerColor::NEUTRAL; if(value == "UNFLAGGABLE") owner = PlayerColor::UNFLAGGABLE; - object->tempOwner = owner; - return; + obj->tempOwner = owner; } + + SET_PROPERTIES(CArmedInstance); + SET_PROPERTIES(CGTownInstance); + SET_PROPERTIES(CGArtifact); + SET_PROPERTIES(CGMine); + SET_PROPERTIES(CGResource); + SET_PROPERTIES(CGDwelling); + SET_PROPERTIES(CGGarrison); + SET_PROPERTIES(CGHeroInstance); + SET_PROPERTIES(CGShipyard); +} + +void Inspector::setProperty(CArmedInstance * object, const QString & key, const QVariant & value) +{ + if(!object) + return; } void Inspector::setProperty(CGTownInstance * object, const QString & key, const QVariant & value) @@ -187,6 +253,30 @@ void Inspector::setProperty(CGArtifact * object, const QString & key, const QVar return; } +void Inspector::setProperty(CGDwelling * object, const QString & key, const QVariant & value) +{ + if(!object) + return; +} + +void Inspector::setProperty(CGGarrison * object, const QString & key, const QVariant & value) +{ + if(!object) + return; +} + +void Inspector::setProperty(CGHeroInstance * object, const QString & key, const QVariant & value) +{ + if(!object) + return; +} + +void Inspector::setProperty(CGShipyard * object, const QString & key, const QVariant & value) +{ + if(!object) + return; +} + void Inspector::setProperty(CGResource * object, const QString & key, const QVariant & value) { if(!object) diff --git a/mapeditor/inspector.h b/mapeditor/inspector.h index 5c5a2d3a3..a7412d0bb 100644 --- a/mapeditor/inspector.h +++ b/mapeditor/inspector.h @@ -24,10 +24,14 @@ class Initializer public: //===============DECLARE MAP OBJECTS====================================== DECLARE_OBJ_TYPE(CArmedInstance); + DECLARE_OBJ_TYPE(CGShipyard); DECLARE_OBJ_TYPE(CGTownInstance); DECLARE_OBJ_TYPE(CGArtifact); DECLARE_OBJ_TYPE(CGMine); DECLARE_OBJ_TYPE(CGResource); + DECLARE_OBJ_TYPE(CGDwelling); + DECLARE_OBJ_TYPE(CGGarrison); + DECLARE_OBJ_TYPE(CGHeroInstance); Initializer(CMap *, CGObjectInstance *); @@ -42,9 +46,13 @@ protected: //===============DECLARE PROPERTIES SETUP================================= DECLARE_OBJ_PROPERTY_METHODS(CArmedInstance); DECLARE_OBJ_PROPERTY_METHODS(CGTownInstance); + DECLARE_OBJ_PROPERTY_METHODS(CGShipyard); DECLARE_OBJ_PROPERTY_METHODS(CGArtifact); DECLARE_OBJ_PROPERTY_METHODS(CGMine); DECLARE_OBJ_PROPERTY_METHODS(CGResource); + DECLARE_OBJ_PROPERTY_METHODS(CGDwelling); + DECLARE_OBJ_PROPERTY_METHODS(CGGarrison); + DECLARE_OBJ_PROPERTY_METHODS(CGHeroInstance); //===============DECLARE PROPERTY VALUE TYPE============================== QTableWidgetItem * addProperty(unsigned int value); diff --git a/mapeditor/mapcontroller.cpp b/mapeditor/mapcontroller.cpp index 285a174a1..4d785f0c9 100644 --- a/mapeditor/mapcontroller.cpp +++ b/mapeditor/mapcontroller.cpp @@ -75,6 +75,7 @@ void MapController::setMap(std::unique_ptr cmap) dynamic_cast(obj.get()) || dynamic_cast(obj.get()) || dynamic_cast(obj.get()) || + dynamic_cast(obj.get()) || dynamic_cast(obj.get())) obj->tempOwner = PlayerColor::NEUTRAL; diff --git a/mapeditor/maphandler.cpp b/mapeditor/maphandler.cpp index 9837bc009..587826ba6 100644 --- a/mapeditor/maphandler.cpp +++ b/mapeditor/maphandler.cpp @@ -143,8 +143,8 @@ void setPlayerColor(QImage * sur, PlayerColor player) if(sur->format() == QImage::Format_Indexed8) { QRgb color = graphics->neutralColor; - if(player != PlayerColor::NEUTRAL) - color = graphics->playerColors[player.getNum()]; + if(player != PlayerColor::NEUTRAL && player < PlayerColor::PLAYER_LIMIT) + color = graphics->playerColors.at(player.getNum()); sur->setColor(5, color); }