Bläddra i källkod

Fix hero type for random hero

nordsoft 2 år sedan
förälder
incheckning
5136305455

+ 10 - 7
mapeditor/inspector/inspector.cpp

@@ -135,12 +135,14 @@ void Initializer::initialize(CGHeroInstance * o)
 		}
 	}
 	
-	if(!o->type)
-		o->type = VLC->heroh->objects.at(o->subID);
-	
-	o->gender = o->type->gender;
-	o->portrait = o->type->imageIndex;
-	o->randomizeArmy(o->type->heroClass->faction);
+	if(o->type)
+	{
+		//	o->type = VLC->heroh->objects.at(o->subID);
+		
+		o->gender = o->type->gender;
+		o->portrait = o->type->imageIndex;
+		o->randomizeArmy(o->type->heroClass->faction);
+	}
 }
 
 void Initializer::initialize(CGTownInstance * o)
@@ -250,7 +252,7 @@ void Inspector::updateProperties(CGHeroInstance * o)
 	
 	addProperty("Owner", o->tempOwner, o->ID == Obj::PRISON); //field is not editable for prison
 	addProperty<int>("Experience", o->exp, false);
-	addProperty("Hero class", o->type->heroClass->getNameTranslated(), true);
+	addProperty("Hero class", o->type ? o->type->heroClass->getNameTranslated() : "", true);
 	
 	{ //Sex
 		auto * delegate = new InspectorDelegate;
@@ -261,6 +263,7 @@ void Inspector::updateProperties(CGHeroInstance * o)
 	addProperty("Biography", o->biographyCustom, new MessageDelegate, false);
 	addProperty("Portrait", o->portrait, false);
 	
+	if(o->type)
 	{ //Hero type
 		auto * delegate = new InspectorDelegate;
 		for(int i = 0; i < VLC->heroh->objects.size(); ++i)

+ 2 - 1
mapeditor/inspector/inspector.h

@@ -126,7 +126,8 @@ protected:
 			table->setRowCount(row + 1);
 			table->setItem(row, 0, itemKey);
 			table->setItem(row, 1, itemValue);
-			table->setItemDelegateForRow(row, delegate);
+			if(delegate)
+				table->setItemDelegateForRow(row, delegate);
 			++row;
 		}
 	}

+ 2 - 1
mapeditor/mapcontroller.cpp

@@ -145,7 +145,8 @@ void MapController::repairMap()
 				nih->subID = 0;
 			}
 			
-			nih->type = type;
+			if(obj->ID != Obj::RANDOM_HERO)
+				nih->type = type;
 			
 			if(nih->ID == Obj::HERO) //not prison
 				nih->appearance = VLC->objtypeh->getHandlerFor(Obj::HERO, type->heroClass->getIndex())->getTemplates().front();

+ 3 - 1
mapeditor/mapview.cpp

@@ -397,6 +397,7 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
 		bool tab = false;
 		if(sc->selectionObjectsView.selectionMode == SelectionObjectsLayer::MOVEMENT)
 		{
+			tab = sc->selectionObjectsView.shift.isNull();
 			controller->commitObjectShift(sc->level);
 		}
 		else
@@ -405,7 +406,6 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
 			sc->selectionObjectsView.shift = QPoint(0, 0);
 			sc->selectionObjectsView.draw();
 			tab = true;
-			//check if we have only one object
 		}
 		auto selection = sc->selectionObjectsView.getSelection();
 		if(selection.size() == 1)
@@ -463,7 +463,9 @@ void MapView::dropEvent(QDropEvent * event)
 		QString errorMsg;
 		if(controller->canPlaceObject(sc->level, sc->selectionObjectsView.newObject, errorMsg))
 		{
+			auto * obj = sc->selectionObjectsView.newObject;
 			controller->commitObjectCreate(sc->level);
+			emit openObjectProperties(obj, false);
 		}
 		else
 		{

+ 1 - 1
mapeditor/validator.cpp

@@ -131,7 +131,7 @@ std::list<Validator::Issue> Validator::validate(const CMap * map)
 					if(!allHeroesOnMap.insert(ins->type).second)
 						issues.emplace_back(QString(tr("Hero %1 has duplicate on map")).arg(ins->type->getNameTranslated().c_str()), false);
 				}
-				else
+				else if(ins->ID != Obj::RANDOM_HERO)
 					issues.emplace_back(QString(tr("Hero %1 has an empty type and must be removed")).arg(ins->instanceName.c_str()), true);
 			}