Game Development Community

How the T3D loads a Gui?

by qiansheng · in Torque 3D Beginner · 12/13/2012 (4:59 am) · 2 replies

I have found the function that loads a Gui.
But I don't understand how the function works.

//location:guiEditorCanvas.ed.cs

function GuiEditCanvas::load( %this, %filename )
{
%newRedefineBehavior = "replaceExisting";
if( isDefined( "$GuiEditor::loadRedefineBehavior" ) )
{
// This trick allows to choose different redefineBehaviors when loading
// GUIs. This is useful, for example, when loading GUIs that would lead to
// problems when loading with their correct names because script behavior
// would immediately attach.
//
// This allows to also edit the GUI editor's own GUI inside itself.

%newRedefineBehavior = $GuiEditor::loadRedefineBehavior;
}

// Allow stomping objects while exec'ing the GUI file as we want to
// pull the file's objects even if we have another version of the GUI
// already loaded.

%oldRedefineBehavior = $Con::redefineBehavior;
$Con::redefineBehavior = %newRedefineBehavior;

// Load up the gui.
exec( %fileName );

$Con::redefineBehavior = %oldRedefineBehavior;

// The GUI file should have contained a GUIControl which should now be in the instant
// group. And, it should be the only thing in the group.
if( !isObject( %guiContent ) )
{
MessageBox( getEngineName(),
"You have loaded a Gui file that was created before this version. It has been loaded but you must open it manually from the content list dropdown",
"Ok", "Information" );
return 0;
}

GuiEditor.openForEditing( %guiContent );

GuiEditorStatusBar.print( "Loaded '" @ %filename @ "'" );
}

What is the meaning of "newRedefineBehavior","replaceExisting" and "loadRedefineBehavior"? And how the
function works as a whole?
At last,will the T3D make backup copy file for the Gui file?

#1
12/13/2012 (5:42 am)
Sort of. It saves a direct save object (DSO) and reads that. It never uses the actual .CS file just in case there is an error.
#2
12/13/2012 (9:09 am)
Gui objects are saved to .gui files. Compiled gui objects are saved to .gui.dso files.

Script files containing scripts for gui object callbacks and other related functions are usually saved in a .cs file that is named the same as the parent gui object. IE MyFileDialog is usually saved in myFileDialog.gui and associated scripts are usually saved in myFileDialog.cs. You need to load both of these files if you expect them to function properly.

For an example, look at art/gui/playGui.gui and it's script file scripts/gui/playGui.cs. These are loaded in scripts/client/init.cs and they dictate how the in-game HUD looks and acts.

To get to your last question - the answer is in the script you posted:
// This trick allows to choose different redefineBehaviors when loading
// GUIs. This is useful, for example, when loading GUIs that would lead to
// problems when loading with their correct names because script behavior
// would immediately attach.
//
// This allows to also edit the GUI editor's own GUI inside itself.

My question to you is this; what are you trying to accomplish? If you're just trying to load a gui, just use exec() to load it:
// Load up the gui.
exec( %fileName );