mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
add add dropdown to gui editor
also added general guieditcanvas createobject, onfinishcreateobjec,t and onobjectcreated methods for callback injection points
This commit is contained in:
parent
4c58a3601f
commit
54a4510bc6
|
|
@ -211,6 +211,8 @@ function GuiEditCanvas::onCreateMenu(%this)
|
|||
};
|
||||
};
|
||||
|
||||
%this.buildAddMenu();
|
||||
|
||||
// Workaround (for some reason it doesn't size to the width of the canvas)
|
||||
// TODO: After a canvas resize it still messes up the width
|
||||
%position = %this.menubar.position.x SPC %this.menubar.position.y;
|
||||
|
|
@ -220,6 +222,94 @@ function GuiEditCanvas::onCreateMenu(%this)
|
|||
%this.menuBar.attachToCanvas( Canvas, 0 );
|
||||
}
|
||||
|
||||
function GuiEditCanvas::buildAddMenu(%this)
|
||||
{
|
||||
%addMenu = MenuBuilder::newMenu("Add");
|
||||
|
||||
%enumeratedClasses = enumerateConsoleClasses("GuiControl");
|
||||
for(%c=0; %c < getFieldCount(%enumeratedClasses); %c++)
|
||||
{
|
||||
%class = getField(%enumeratedClasses, %c);
|
||||
|
||||
if( GuiEditor.isFilteredClass( %class )
|
||||
|| !isMemberOfClass( %class, "GuiControl" ) )
|
||||
continue;
|
||||
|
||||
%category = getCategoryOfClass(%class);
|
||||
|
||||
if(%category $= "")
|
||||
{
|
||||
error("Attempted to fetch category of class " @ %class @ " but none were found.");
|
||||
continue;
|
||||
}
|
||||
|
||||
%parentMenu = %addMenu; //start at the top
|
||||
for(%cat=0; %cat < getFieldCount(%category); %cat++)
|
||||
{
|
||||
%subCat = getField(%category, %cat);
|
||||
%targetSubmenu = %parentMenu.findMenu(%subCat);
|
||||
if(!isObject(%targetSubmenu))
|
||||
{
|
||||
%targetSubmenu = %parentMenu.newSubmenu(%subCat);
|
||||
}
|
||||
|
||||
%parentMenu = %targetSubmenu;
|
||||
}
|
||||
|
||||
%buildfunc = "";
|
||||
%class = %class;
|
||||
%method = "build" @ %buildfunc;
|
||||
if( !GuiEditCanvas.isMethod( %method ) )
|
||||
%method = "build" @ %class;
|
||||
|
||||
if( !GuiEditCanvas.isMethod( %method ) )
|
||||
%cmd = "return new " @ %class @ "();";
|
||||
else
|
||||
%cmd = "GuiEditCanvas." @ %method @ "();";
|
||||
|
||||
%createCmd = "GuiEditCanvas.newObjectCallback = \"GuiEditCanvas.onFinishCreateObject\"; GuiEditCanvas.createObject( \"" @ %cmd @ "\" );";
|
||||
|
||||
%targetSubmenu.newItem(%class, %createCmd, "");
|
||||
}
|
||||
|
||||
MenuBuilder::addMenuToMenubar(%this.menubar, %addMenu, 4);
|
||||
}
|
||||
|
||||
function GuiEditCanvas::createObject( %this, %cmd )
|
||||
{
|
||||
if(startsWith(%cmd, "return "))
|
||||
%objId = eval(%cmd);
|
||||
else
|
||||
%objId = eval("return " @ %cmd);
|
||||
|
||||
if( isObject( %objId ) )
|
||||
%this.onFinishCreateObject( %objId );
|
||||
|
||||
return %objId;
|
||||
}
|
||||
|
||||
function GuiEditCanvas::onFinishCreateObject( %this, %objId )
|
||||
{
|
||||
GuiEditor.getCurrentAddSet().add( %objId );
|
||||
|
||||
if( %objId.isMemberOfClass( "GuiControl" ) )
|
||||
{
|
||||
%objId.position = "0 0";
|
||||
}
|
||||
|
||||
%this.onObjectCreated( %objId );
|
||||
}
|
||||
|
||||
function GuiEditCanvas::onObjectCreated( %this, %objId )
|
||||
{
|
||||
// Can we submit an undo action?
|
||||
if ( isObject( %objId ) )
|
||||
GuiEditor.onAddNewCtrl( %objId );
|
||||
|
||||
GuiEditorTreeView.clearSelection();
|
||||
GuiEditor.select(%objId);
|
||||
}
|
||||
|
||||
$GUI_EDITOR_MENU_EDGESNAP_INDEX = 0;
|
||||
$GUI_EDITOR_MENU_CENTERSNAP_INDEX = 1;
|
||||
$GUI_EDITOR_MENU_GUIDESNAP_INDEX = 3;
|
||||
|
|
|
|||
|
|
@ -128,6 +128,8 @@ function UndoActionAddDelete::trashObjects(%this)
|
|||
|
||||
if( isObject( %this.tree ) )
|
||||
%this.tree.update();
|
||||
|
||||
GuiEditor.clearSelection();
|
||||
}
|
||||
|
||||
function UndoActionAddDelete::restoreObjects(%this)
|
||||
|
|
|
|||
Loading…
Reference in a new issue