Game Development Community

dev|Pro Game Development Curriculum

Adding

by Jeff Parker · 05/05/2003 (1:15 pm) · 5 comments

The Torque mission editor as it stands is a fine thing, but one of the seriously lacking features to my mind is the ability to control where a created or pasted object appears within the MissionGroup 'tree'.

Using the following script package, a mapper can select a simGroup in the Mission Tree, which will become the parent of all objects created, or pasted into the 'world'.

// ----
package NMissionEditorHacks
{
// ----

function EditorTree::onSelect( %this, %obj )
{
   %this.selectedObject = %obj;
   parent::onSelect(%this, %obj);
}

function EWorldEditor::copySelection( %this )
{
    %this.copySize = %this.getSelectionSize();
    parent::copySelection(%this);
}

function EWorldEditor::pasteSelection( %this )
{
    parent::pasteSelection(%this);
    // -- add the pasted object to the currently selected group
    if( %pasteTo = EditorTree.getSelectedSimgroup() )
        for(%i = 0; %i < %this.copySize; %i++)
            %pasteTo.add(missionGroup.getObject(missionGroup.getCount() - 1));
}

function Creator::create( %this, %sel )
{
    parent::create(%this, %sel);
    %paste = EWorldEditor.getSelectedObject(0);
    if( %pasteTo = EditorTree.getSelectedSimgroup() )
        %pasteTo.add(%paste);
}

function ObjectBuilderGui::processNewObject( %this, %obj )
{
    parent::processNewObject(%this, %obj);
    if( %pasteTo = EditorTree.getSelectedSimgroup() )
        %pasteTo.add(%obj);
}

function EditorTree::getSelectedSimgroup( %this )
{
    %startGroup = %simGroup = %this.selectedObject;

    // -- make sure the beggar exists
    if( !isObject(%simGroup) )
        return false;

    // -- make sure we're sending back a simGroup
    if( %simGroup.getClassName() !$= "SimGroup" )
        return false;

    // -- make sure the simGroup we have labelled as selected is part of the
    //    mission group.
    while( (%simGroup = %simGroup.getGroup()) != -1 )
        if( %simGroup == MissionGroup.getID() )
            return %startGroup;

    return false;
}

// ----
};
activatePackage(NMissionEditorHacks);
// -----------------------------------------------------------------------------

I'd advise adding this to the "common/editor/EditorGui.cs" script, at the very end, and that's it... all done, the first step to a tidy Mission Tree.

**: updated to include objects created without the use of the ObjectBuilderGUI
**: added 'child of missionGroup' error check
**: grouped the various %pasteTo checks and calls into the EditorTree::getSelectedSimgroup function

About the author

Recent Blogs

• Plan for Jeff Parker

#1
05/05/2003 (1:45 pm)
You can also select (left mouse-click) a mission group while holding down the ALT key, which will put your object into the selected group...
#2
05/05/2003 (7:19 pm)
Was about to say that :)
#3
05/06/2003 (5:56 am)
I must have missed that nice little feature... ah well, think of this as an addon :o
#4
06/10/2003 (2:23 pm)
Now if we had the same thing for the Gui Editor...
#5
07/02/2003 (3:09 am)
Mark, all you have to do is right click on a GUI object to "select" it, then add something, it'll add it under that :)