Skip to content

Commit

Permalink
GuiEditor and Named Objects
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greenfire27 committed Dec 21, 2023
1 parent 54c2ae1 commit a487ddf
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
2 changes: 2 additions & 0 deletions editor/GuiEditor/GuiEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,12 @@ class = "SimulatedCanvas";
//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);
Expand Down
1 change: 1 addition & 0 deletions engine/source/console/consoleExprEvalState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ ExprEvalState::ExprEvalState()
globalVars.setState(this);
thisObject = NULL;
traceOn = false;
editorModeOn = false;
}

ExprEvalState::~ExprEvalState()
Expand Down
1 change: 1 addition & 0 deletions engine/source/console/consoleExprEvalState.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ExprEvalState
SimObject *thisObject;
Dictionary::Entry *currentVariable;
bool traceOn;
bool editorModeOn;

ExprEvalState();
~ExprEvalState();
Expand Down
12 changes: 12 additions & 0 deletions engine/source/console/metaScripting_ScriptBinding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions engine/source/gui/containers/guiWindowCtrl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)
Expand Down
48 changes: 37 additions & 11 deletions engine/source/sim/simObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ SimObject::SimObject()
{
mFlags.set( ModStaticFields | ModDynamicFields );
objectName = NULL;
objectNameEditor = NULL;
mInternalName = NULL;
nextNameObject = (SimObject*)-1;
nextManagerNameObject = (SimObject*)-1;
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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);

Expand Down Expand Up @@ -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." );
Expand All @@ -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;
};


//-----------------------------------------------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion engine/source/sim/simObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ class SimObject: public ConsoleObject, public TamlCallbacks
private:
// dictionary information stored on the object
StringTableEntry objectName;
StringTableEntry objectNameEditor;
SimObject* nextNameObject;
SimObject* nextManagerNameObject;
SimObject* nextIdObject;
Expand Down Expand Up @@ -374,6 +375,7 @@ class SimObject: public ConsoleObject, public TamlCallbacks
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; };
Expand Down Expand Up @@ -621,7 +623,7 @@ class SimObject: public ConsoleObject, public TamlCallbacks
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);
Expand Down

0 comments on commit a487ddf

Please sign in to comment.