فهرست منبع

GuiEditor and Named Objects

This causes the GuiEditor to avoid actually naming objects since doing so causes bugs if the object already exists in the engine. Instead it stores the name in a temporary editor name. As far as I can tell there are no side effects and hopefully it will stay that way.
Peter Robinson 1 سال پیش
والد
کامیت
a487ddfeca

+ 2 - 0
editor/GuiEditor/GuiEditor.cs

@@ -232,10 +232,12 @@ function GuiEditor::open(%this, %content)
     //EditorCore.menuBar.setMenuActive("Edit", true); //These features still need development
     EditorCore.menuBar.setMenuActive("Layout", true);
     EditorCore.menuBar.setMenuActive("Select", true);
+    editorMode(true);
 }
 
 function GuiEditor::close(%this)
 {
+    editorMode(false);
     EditorCore.menuBar.setMenuActive("File", false);
     EditorCore.menuBar.setMenuActive("Edit", false);
     EditorCore.menuBar.setMenuActive("Layout", false);

+ 1 - 0
engine/source/console/consoleExprEvalState.cc

@@ -66,6 +66,7 @@ ExprEvalState::ExprEvalState()
    globalVars.setState(this);
    thisObject = NULL;
    traceOn = false;
+   editorModeOn = false;
 }
 
 ExprEvalState::~ExprEvalState()

+ 1 - 0
engine/source/console/consoleExprEvalState.h

@@ -39,6 +39,7 @@ public:
     SimObject *thisObject;
     Dictionary::Entry *currentVariable;
     bool traceOn;
+	bool editorModeOn;
 
     ExprEvalState();
     ~ExprEvalState();

+ 12 - 0
engine/source/console/metaScripting_ScriptBinding.cc

@@ -743,6 +743,18 @@ ConsoleFunctionWithDocs(trace, ConsoleVoid, 2, 2, ( enable ))
 
 //----------------------------------------------------------------
 
+/*! Use the trace function to enable (or disable) function call tracing. If enabled, tracing will print a message every time a function is entered, showing what arguments it received, and it will print a message every time a function is exited, showing the return value (or last value of last statement) for that function.
+	@param enable A boolean value. If set to true, tracing is enabled, otherwise it is disabled.
+	@return No return value
+*/
+ConsoleFunctionWithDocs(editorMode, ConsoleVoid, 2, 2, (enable))
+{
+	TORQUE_UNUSED(argc);
+	gEvalState.editorModeOn = dAtob(argv[1]);
+}
+
+//----------------------------------------------------------------
+
 #if defined(TORQUE_DEBUG) || defined(INTERNAL_RELEASE)
 /*! Use the debug function to cause the engine to issue a debug break and to break into an active debugger.
     For this to work, the engine must have been compiled with either TORQUE_DEBUG, or INTERNAL_RELEASE defined

+ 2 - 0
engine/source/gui/containers/guiWindowCtrl.cc

@@ -87,6 +87,7 @@ void GuiWindowCtrl::initPersistFields()
 {
    Parent::initPersistFields();
 
+   addGroup("GuiWindowCtrl");
    addField("resizeWidth",       TypeBool,         Offset(mResizeWidth, GuiWindowCtrl));
    addField("resizeHeight",      TypeBool,         Offset(mResizeHeight, GuiWindowCtrl));
    addField("canMove",           TypeBool,         Offset(mCanMove, GuiWindowCtrl));
@@ -103,6 +104,7 @@ void GuiWindowCtrl::initPersistFields()
    addField("leftRightCursor", TypeGuiCursor, Offset(mLeftRightCursor, GuiWindowCtrl));
    addField("upDownCursor", TypeGuiCursor, Offset(mUpDownCursor, GuiWindowCtrl));
    addField("nWSECursor", TypeGuiCursor, Offset(mNWSECursor, GuiWindowCtrl));
+   endGroup("GuiWindowCtrl");
 }
 
 bool GuiWindowCtrl::isMinimized(S32 &index)

+ 37 - 11
engine/source/sim/simObject.cc

@@ -53,6 +53,7 @@ SimObject::SimObject()
 {
     mFlags.set( ModStaticFields | ModDynamicFields );
     objectName               = NULL;
+	objectNameEditor         = NULL;
     mInternalName            = NULL;
     nextNameObject           = (SimObject*)-1;
     nextManagerNameObject    = (SimObject*)-1;
@@ -208,6 +209,17 @@ void SimObject::assignName(const char *name)
         Con::errorf( "SimObject::assignName - Assigning name '%s' to instance of object with type '%s'."
         " This can cause namespace linking issues.", getClassName(), name  );
 
+    StringTableEntry newName = NULL;
+
+    if (name[0])
+        newName = StringTable->insert(name);
+
+	if (gEvalState.editorModeOn)
+	{
+		objectNameEditor = newName;
+		return;
+	}
+
     // Is this name already registered?
     if ( Sim::gNameDictionary->find(name) != NULL )
     {
@@ -216,11 +228,6 @@ void SimObject::assignName(const char *name)
         return;
     }
 
-    StringTableEntry newName = NULL;
-
-    if (name[0])
-        newName = StringTable->insert(name);
-
     if (mGroup)
         mGroup->nameDictionary.remove(this);
 
@@ -1074,7 +1081,7 @@ void SimObject::initPersistFields()
 
    
    addGroup("SimBase");
-   addProtectedField("name", TypeName, Offset(objectName, SimObject), &setProtectedName, &defaultProtectedGetFn, "Name for the object.");
+   addProtectedField("name", TypeName, Offset(objectName, SimObject), &setProtectedName, &getProtectedName, "Name for the object.");
    addField("canSaveDynamicFields",    TypeBool,         Offset(mCanSaveFieldDictionary, SimObject), &writeCanSaveDynamicFields, "");
    addField("internalName",            TypeString,       Offset(mInternalName, SimObject), &writeInternalName, "");   
    addProtectedField("parentGroup",    TypeSimObjectPtr, Offset(mGroup, SimObject), &setParentGroup, &defaultProtectedGetFn, &writeParentGroup, "Group hierarchy parent of the object." );
@@ -1098,17 +1105,36 @@ void SimObject::initPersistFields()
 
 bool SimObject::setProtectedName(void *obj, const char *data)
 {
-   if (disableNameChanging)
-      return false;
-   SimObject *object = static_cast<SimObject*>(obj);
+	if (disableNameChanging && !gEvalState.editorModeOn)
+			return false;
 
-   if (object->isProperlyAdded())
-      object->assignName(data);
+	SimObject *object = static_cast<SimObject*>(obj);
+	if (object->isProperlyAdded())
+		object->assignName(data);
 
    // always return false because we assign the name here
    return false;
 }
 
+const char* SimObject::getProtectedName(void* obj, const char* data)
+{
+	if (gEvalState.editorModeOn)
+	{
+		SimObject* object = static_cast<SimObject*>(obj);
+		return object->objectNameEditor;
+	}
+	return data;
+}
+
+const StringTableEntry SimObject::getName(void) const
+{ 
+	if (gEvalState.editorModeOn && objectNameEditor && objectNameEditor[0])
+	{
+		return objectNameEditor;
+	}
+	return objectName; 
+};
+
 
 //-----------------------------------------------------------------------------
 

+ 3 - 1
engine/source/sim/simObject.h

@@ -305,6 +305,7 @@ public:
 private:
     // dictionary information stored on the object
     StringTableEntry objectName;
+	StringTableEntry objectNameEditor;
     SimObject*       nextNameObject;
     SimObject*       nextManagerNameObject;
     SimObject*       nextIdObject;
@@ -374,6 +375,7 @@ protected:
     static bool writeSuperclass( void* obj, StringTableEntry pFieldName )            { SimObject* simObject = static_cast<SimObject*>(obj); return simObject->mSuperClassName != NULL && simObject->mSuperClassName != StringTable->EmptyString; }
     static bool writeClass( void* obj, StringTableEntry pFieldName )                 { SimObject* simObject = static_cast<SimObject*>(obj); return simObject->mClassName != NULL && simObject->mClassName != StringTable->EmptyString; }
     static bool setProtectedName(void * obj, const char * data);
+	static const char* getProtectedName(void* obj, const char* data);
     // Accessors
     public:
     StringTableEntry getClassNamespace() const { return mClassName; };
@@ -621,7 +623,7 @@ public:
     inline SimObjectId getId( void ) const { return mId; }
     inline StringTableEntry getIdString( void ) const { return mIdString; }
     U32 getType() const  { return mTypeMask; }
-    const StringTableEntry getName( void ) const { return objectName; };
+    const StringTableEntry getName( void ) const;
 
     void setId(SimObjectId id);
     void assignName(const char* name);