Example #1
0
//***************************************************************
CInstance *CToolSelectMove::createGhost(CInstance &instance)
{
	//H_AUTO(R2_CToolSelectMove_createGhost)
	CLuaState &ls = getEditor().getLua();
	// copy then do a local paste
	CLuaStackRestorer lsr(&ls, 0);
	//
	CLuaObject &luaProj = instance.getLuaProjection();
	CLuaObject &classDef = instance.getClass();
	if (luaProj.callMethodByNameNoThrow("copy", 0, 1))
	{
		// now we got a table that is an exact (canonical) copy of the original object, with the
		// same instance ids..
		// prepare for new insertion by renaming these instance id's (which 'newCopy' does)
		if (classDef["newCopy"].callNoThrow(1, 1))
		{
			// now, insert the new copy as a ghost in the new scene
			if (classDef["pasteGhost"].callNoThrow(1, 1))
			{

				CLuaObject ghost(ls); // pop the ghost from stack
				CInstance *newInst = getEditor().getInstanceFromId(ghost["InstanceId"].toString());
				if (newInst)
				{
					if (!newInst->getGhost())
					{
						nlwarning("When duplicating an object using the 'select/move' tool, temporary duplicate should be inserted \
								   as a ghost in the scene, removing object...");
						getEditor().getDMC().requestEraseNode(newInst->getId(), "", -1);
					}
					// set the flag so that the cost of this object isn't taken in account in the displayed quotas
					newInst->getLuaProjection()["User"].setValue("GhostDuplicate", true);
					getEditor().setSelectedInstance(newInst);
					newInst->getDisplayerVisual()->setDisplayFlag(CDisplayerVisual::FlagHideActivities, true);
					nlwarning("CToolSelectMove: beginning duplicate with instance with id %s", newInst->getId().c_str());
					// show in "frozen" state
					{
						/*CObjectNumber *numberValue = new CObjectNumber(2); // 2 = frozen state
						getEditor().getDMC().requestSetNode(newInst->getId(), "DisplayMode", numberValue);
						delete numberValue;
						*/
						newInst->getDisplayerVisual()->setDisplayMode(CDisplayerVisual::DisplayModeFrozen);
						getEditor().getEntitySorter()->clipEntitiesByDist();
						return newInst;
					}
				}
			}
		}