//*************************************************************** 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; } } } }
// *************************************************************** void CToolSelectRotate::setEntityAngle(CEntityCL &/* entity */, CInstance &instance, float angle) { //H_AUTO(R2_CToolSelectRotate_setEntityAngle) CObjectNumber *angleObject = new CObjectNumber(angle); getEditor().requestSetLocalNode(instance.getId(), "Angle", angleObject); delete angleObject; }
// *************************************************************** void CToolSelectRotate::commitAction(CInstance &instance) { //H_AUTO(R2_CToolSelectRotate_commitAction) getDMC().newAction(CI18N::get("uiR2EDRotateAction") + instance.getDisplayName()); // nothing to do, entity already has good angle getEditor().requestCommitLocalNode(instance.getId(), "Angle"); setRotateInProgress(false, instance); }
// *************************************************************** void CToolSelectRotate::cancelAction(CInstance &instance) { //H_AUTO(R2_CToolSelectRotate_cancelAction) CEntityCL *entity = instance.getEntity(); nlassert(entity); getEditor().requestRollbackLocalNode(instance.getId(), "Angle"); setRotateInProgress(false, instance); }
virtual void visit(CInstance &inst) { CNotifySonDeletion notifySonDeletion(inst); getEditor().triggerInstanceObserver(inst.getId(), notifySonDeletion); }
//*************************************************************** void CAutoGroup::group(CObject *newEntityDesc, const NLMISC::CVectorD &createPosition) { //H_AUTO(R2_CAutoGroup_group) CInstance *destGroup = getGroupingCandidate(); if (!destGroup || !_AutoGroupEnabled) return; _AutoGroupEnabled = false; // force user to call 'update' again clear(); // remove any activity, dialog, or event in the copy CObject *behav = newEntityDesc->findAttr("Behavior"); if (behav) { behav->setObject("Actions", new CObjectTable()); behav->setObject("Activities", new CObjectTable()); behav->setObject("ChatSequences", new CObjectTable()); newEntityDesc->setObject("ActivitiesId", new CObjectTable()); } nlassert(newEntityDesc); nlassert(destGroup); std::string targetGroupId; if (destGroup->isKindOf("NpcGrpFeature")) { // make relative to newgroup and insert CVectorD relPos = createPosition; CDisplayerVisual *vd = destGroup->getDisplayerVisual(); if (vd) { relPos = relPos - vd->getWorldPos(); } newEntityDesc->setObject("Position", buildVector(relPos)); targetGroupId = destGroup->getId(); } else { // other is a standalone entity -> create a new group std::auto_ptr<CObject> newGroup(getEditor().getDMC().newComponent("NpcGrpFeature")); if (!newGroup.get()) { nlwarning("Syntax error in r2_features_npc_group.lua."); getEditor().getDMC().getActionHistoric().endAction(); getEditor().getDMC().flushActions(); return; } ucstring readableName; CLuaState &ls = getEditor().getLua(); R2::getEditor().getEnv()["PaletteIdToGroupTranslation"][newEntityDesc->getAttr("Base")->toString()].push(); if (ls.isString(-1)) readableName.fromUtf8(ls.toString(-1)); ucstring ucGroupName = ucstring(readableName + " " + CI18N::get("uiR2EDNameGroup").toUtf8()); newGroup->set("Name", getEditor().genInstanceName(ucGroupName).toUtf8()); getEditor().getDMC().requestInsertNode(destGroup->getParentAct()->getId(), "Features", -1, "", newGroup.get()); targetGroupId = getString(newGroup.get(), "InstanceId"); // move target instance in that group (becomes the leader) getEditor().getDMC().requestMoveNode(destGroup->getId(), "", -1, targetGroupId, "Components", -1); } // move newly created entity into target group getEditor().getDMC().requestInsertNode(targetGroupId, "Components", -1, "", newEntityDesc); getEditor().getDMC().getActionHistoric().endAction(); getEditor().getDMC().flushActions(); }