mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 06:34:36 +00:00
Editor integration for creation of entities and GameObjects.
This commit is contained in:
parent
f54fde9c6b
commit
6517b86491
6 changed files with 294 additions and 12 deletions
|
|
@ -29,7 +29,7 @@ function ItemRotationComponent::onAdd(%this)
|
|||
%this.addComponentField(horizontal, "Rotate horizontal or verticle, true for horizontal", "bool", "1", "");
|
||||
}
|
||||
|
||||
function ItemRotateBehavior::Update(%this)
|
||||
function ItemRotationComponent::Update(%this)
|
||||
{
|
||||
%tickRate = 0.032;
|
||||
|
||||
|
|
|
|||
|
|
@ -39,15 +39,12 @@ function execGameObjects()
|
|||
}
|
||||
}
|
||||
|
||||
function spawnGameObject(%name, %addToMissionGroup)
|
||||
function findGameObject(%name)
|
||||
{
|
||||
if(%addToMissionGroup $= "")
|
||||
%addToMissionGroup = true;
|
||||
|
||||
//find all GameObjectAssets
|
||||
%assetQuery = new AssetQuery();
|
||||
if(!AssetDatabase.findAssetType(%assetQuery, "GameObjectAsset"))
|
||||
return; //if we didn't find ANY, just exit
|
||||
return 0; //if we didn't find ANY, just exit
|
||||
|
||||
%count = %assetQuery.getCount();
|
||||
|
||||
|
|
@ -61,15 +58,64 @@ function spawnGameObject(%name, %addToMissionGroup)
|
|||
{
|
||||
if(isFile(%gameObjectAsset.TAMLFilePath))
|
||||
{
|
||||
%newSGOObject = TamlRead(%gameObjectAsset.TAMLFilePath);
|
||||
|
||||
if(%addToMissionGroup == true)
|
||||
MissionGroup.add(%newSGOObject);
|
||||
|
||||
return %newSGOObject;
|
||||
return %gameObjectAsset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function spawnGameObject(%name, %addToMissionGroup)
|
||||
{
|
||||
if(%addToMissionGroup $= "")
|
||||
%addToMissionGroup = true;
|
||||
|
||||
%gameObjectAsset = findGameObject(%name);
|
||||
|
||||
if(isObject(%gameObjectAsset))
|
||||
{
|
||||
%newSGOObject = TamlRead(%gameObjectAsset.TAMLFilePath);
|
||||
|
||||
if(%addToMissionGroup == true)
|
||||
MissionGroup.add(%newSGOObject);
|
||||
|
||||
return %newSGOObject;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function saveGameObject(%name, %tamlPath, %scriptPath)
|
||||
{
|
||||
%gameObjectAsset = findGameObject(%name);
|
||||
|
||||
//find if it already exists. If it does, we'll update it, if it does not, we'll make a new asset
|
||||
if(isObject(%gameObjectAsset))
|
||||
{
|
||||
%assetID = %gameObjectAsset.getAssetId();
|
||||
|
||||
%gameObjectAsset.TAMLFilePath = %tamlPath;
|
||||
%gameObjectAsset.scriptFilePath = %scriptPath;
|
||||
|
||||
TAMLWrite(%gameObjectAsset, AssetDatabase.getAssetFilePath(%assetID));
|
||||
AssetDatabase.refreshAsset(%assetID);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Doesn't exist, so make a new one
|
||||
%gameObjectAsset = new GameObjectAsset()
|
||||
{
|
||||
assetName = %name @ "Asset";
|
||||
gameObjectName = %name;
|
||||
TAMLFilePath = %tamlPath;
|
||||
scriptFilePath = %scriptPath;
|
||||
};
|
||||
|
||||
//Save it alongside the taml file
|
||||
%path = filePath(%tamlPath);
|
||||
|
||||
TAMLWrite(%gameObjectAsset, %path @ "/" @ %name @ ".asset.taml");
|
||||
AssetDatabase.refreshAllAssets(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -204,6 +204,77 @@
|
|||
editorSettingsWrite = "EditorGui.writeWorldEditorSettings();";
|
||||
};
|
||||
};
|
||||
new GuiControl() {
|
||||
position = "0 0";
|
||||
extent = "430 18";
|
||||
minExtent = "8 2";
|
||||
horizSizing = "right";
|
||||
vertSizing = "bottom";
|
||||
profile = "ToolsGuiDefaultProfile";
|
||||
visible = "1";
|
||||
active = "1";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
hovertime = "1000";
|
||||
isContainer = "1";
|
||||
canSave = "1";
|
||||
canSaveDynamicFields = "0";
|
||||
|
||||
new GuiTextCtrl() {
|
||||
text = "New Game Objects";
|
||||
maxLength = "1024";
|
||||
margin = "0 0 0 0";
|
||||
padding = "0 0 0 0";
|
||||
anchorTop = "1";
|
||||
anchorBottom = "0";
|
||||
anchorLeft = "1";
|
||||
anchorRight = "0";
|
||||
position = "5 1";
|
||||
extent = "70 16";
|
||||
minExtent = "8 2";
|
||||
horizSizing = "right";
|
||||
vertSizing = "bottom";
|
||||
profile = "ToolsGuiTextRightProfile";
|
||||
visible = "1";
|
||||
active = "1";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
hovertime = "1000";
|
||||
isContainer = "0";
|
||||
canSave = "1";
|
||||
canSaveDynamicFields = "0";
|
||||
};
|
||||
new GuiTextEditCtrl() {
|
||||
historySize = "0";
|
||||
tabComplete = "0";
|
||||
sinkAllKeyEvents = "0";
|
||||
password = "0";
|
||||
passwordMask = "*";
|
||||
text = "scripts/server/gameObjects";
|
||||
maxLength = "1024";
|
||||
margin = "0 0 0 0";
|
||||
padding = "0 0 0 0";
|
||||
anchorTop = "1";
|
||||
anchorBottom = "0";
|
||||
anchorLeft = "1";
|
||||
anchorRight = "0";
|
||||
position = "81 0";
|
||||
extent = "345 17";
|
||||
minExtent = "8 2";
|
||||
horizSizing = "width";
|
||||
vertSizing = "bottom";
|
||||
profile = "ToolsGuiTextEditProfile";
|
||||
visible = "1";
|
||||
active = "1";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
hovertime = "1000";
|
||||
isContainer = "0";
|
||||
canSave = "1";
|
||||
canSaveDynamicFields = "1";
|
||||
class = "ESettingsWindowTextEdit";
|
||||
editorSettingsRead = "EditorGui.readWorldEditorSettings();";
|
||||
editorSettingsValue = "WorldEditor/newGameObjectDir";
|
||||
editorSettingsWrite = "EditorGui.writeWorldEditorSettings();";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1643,6 +1643,20 @@ function EditorTree::onRightMouseUp( %this, %itemId, %mouse, %obj )
|
|||
|
||||
object = -1;
|
||||
};
|
||||
|
||||
if(%obj.isMemberOfClass("Entity"))
|
||||
{
|
||||
%popup = ETEntityContextPopup;
|
||||
if( !isObject( %popup ) )
|
||||
%popup = new PopupMenu( ETEntityContextPopup : ETSimGroupContextPopup )
|
||||
{
|
||||
superClass = "MenuBuilder";
|
||||
isPopup = "1";
|
||||
|
||||
item[ 12 ] = "-";
|
||||
item[ 13 ] = "Convert to Game Object" TAB "" TAB "EWorldEditor.createGameObject( %this.object );";
|
||||
};
|
||||
}
|
||||
|
||||
%popup.object = %obj;
|
||||
|
||||
|
|
@ -2204,6 +2218,155 @@ function EWorldEditor::deleteMissionObject( %this, %object )
|
|||
EditorTree.buildVisibleTree( true );
|
||||
}
|
||||
|
||||
function EWorldEditor::createGameObject( %this, %entity )
|
||||
{
|
||||
if(!isObject(GameObjectBuilder))
|
||||
{
|
||||
new GuiControl(GameObjectBuilder, EditorGuiGroup) {
|
||||
profile = "ToolsGuiDefaultProfile";
|
||||
horizSizing = "right";
|
||||
vertSizing = "bottom";
|
||||
position = "0 0";
|
||||
extent = "800 600";
|
||||
minExtent = "8 8";
|
||||
visible = "1";
|
||||
setFirstResponder = "0";
|
||||
modal = "1";
|
||||
helpTag = "0";
|
||||
|
||||
new GuiWindowCtrl(GameObjectBuilderTargetWindow) {
|
||||
profile = "ToolsGuiWindowProfile";
|
||||
horizSizing = "center";
|
||||
vertSizing = "center";
|
||||
position = "384 205";
|
||||
extent = "256 102";
|
||||
minExtent = "256 8";
|
||||
visible = "1";
|
||||
setFirstResponder = "0";
|
||||
modal = "1";
|
||||
helpTag = "0";
|
||||
resizeWidth = "1";
|
||||
resizeHeight = "1";
|
||||
canMove = "1";
|
||||
canClose = "0";
|
||||
canMinimize = "0";
|
||||
canMaximize = "0";
|
||||
minSize = "50 50";
|
||||
text = "Create Object";
|
||||
|
||||
new GuiTextCtrl() {
|
||||
profile = "GuiCenterTextProfile";
|
||||
horizSizing = "right";
|
||||
vertSizing = "bottom";
|
||||
position = "9 26";
|
||||
extent = "84 16";
|
||||
minExtent = "8 8";
|
||||
visible = "1";
|
||||
setFirstResponder = "0";
|
||||
modal = "1";
|
||||
helpTag = "0";
|
||||
text = "Object Name:";
|
||||
};
|
||||
new GuiTextEditCtrl(GameObjectBuilderObjectName) {
|
||||
class = ObjectBuilderGuiTextEditCtrl;
|
||||
profile = "ToolsGuiTextEditProfile";
|
||||
horizSizing = "width";
|
||||
vertSizing = "bottom";
|
||||
position = "78 26";
|
||||
extent = "172 18";
|
||||
minExtent = "8 8";
|
||||
visible = "1";
|
||||
setFirstResponder = "0";
|
||||
modal = "1";
|
||||
helpTag = "0";
|
||||
historySize = "0";
|
||||
};
|
||||
new GuiButtonCtrl(GameObjectBuilderOKButton) {
|
||||
profile = "ToolsGuiButtonProfile";
|
||||
horizSizing = "width";
|
||||
vertSizing = "bottom";
|
||||
position = "7 250";
|
||||
extent = "156 24";
|
||||
minExtent = "8 8";
|
||||
visible = "1";
|
||||
setFirstResponder = "0";
|
||||
modal = "1";
|
||||
command = "EWorldEditor.buildGameObject();";
|
||||
helpTag = "0";
|
||||
text = "Create New";
|
||||
Accelerator = "return";
|
||||
};
|
||||
new GuiButtonCtrl(GameObjectBuilderCancelButton) {
|
||||
profile = "ToolsGuiButtonProfile";
|
||||
horizSizing = "left";
|
||||
vertSizing = "bottom";
|
||||
position = "170 250";
|
||||
extent = "80 24";
|
||||
minExtent = "8 8";
|
||||
visible = "1";
|
||||
setFirstResponder = "0";
|
||||
modal = "1";
|
||||
command = "Canvas.popDialog(GameObjectBuilder);";
|
||||
helpTag = "0";
|
||||
text = "Cancel";
|
||||
Accelerator = "escape";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
GameObjectBuilderTargetWindow.extent = getWord(GameObjectBuilderTargetWindow.extent, 0) SPC 88;
|
||||
GameObjectBuilderOKButton.position = getWord(GameObjectBuilderOKButton.position, 0) SPC 57;
|
||||
GameObjectBuilderCancelButton.position = getWord(GameObjectBuilderCancelButton.position, 0) SPC 57;
|
||||
}
|
||||
|
||||
GameObjectBuilderObjectName.text = "";
|
||||
GameObjectBuilder.selectedEntity = %entity;
|
||||
|
||||
Canvas.pushDialog(GameObjectBuilder);
|
||||
}
|
||||
|
||||
function EWorldEditor::buildGameObject(%this)
|
||||
{
|
||||
if(GameObjectBuilderObjectName.getText() $= "")
|
||||
{
|
||||
error("Attempted to make a new Game Object with no name!");
|
||||
Canvas.popDialog(GameObjectBuilder);
|
||||
return;
|
||||
}
|
||||
|
||||
%path = EditorSettings.value( "WorldEditor/newGameObjectDir" );
|
||||
%className = GameObjectBuilderObjectName.getText();
|
||||
GameObjectBuilder.selectedEntity.class = %className;
|
||||
Inspector.inspect(GameObjectBuilder.selectedEntity);
|
||||
|
||||
%file = new FileObject();
|
||||
|
||||
if(%file.openForWrite(%path @ "\\" @ %className @ ".cs"))
|
||||
{
|
||||
%file.writeline("function " @ %className @ "::onAdd(%this)\n{\n\n}\n");
|
||||
%file.writeline("function " @ %className @ "::onRemove(%this)\n{\n\n}\n");
|
||||
|
||||
//todo, pre-write any event functions of interest
|
||||
|
||||
%file.close();
|
||||
}
|
||||
|
||||
//set up the paths
|
||||
%tamlPath = %path @ "/" @ %className @ ".taml";
|
||||
%scriptPath = %path @ "/" @ %className @ ".cs";
|
||||
saveGameObject(%className, %tamlPath, %scriptPath);
|
||||
|
||||
//reload it
|
||||
execGameObjects();
|
||||
|
||||
//now, add the script file and a ref to the taml into our SGO manifest so we can readily spawn it later.
|
||||
TamlWrite(GameObjectBuilder.selectedEntity, %tamlpath);
|
||||
|
||||
GameObjectBuilder.selectedEntity = "";
|
||||
|
||||
Canvas.popDialog(GameObjectBuilder);
|
||||
}
|
||||
|
||||
function EWorldEditor::selectAllObjectsInSet( %this, %set, %deselect )
|
||||
{
|
||||
if( !isObject( %set ) )
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ EditorSettings.setDefaultValue( "orthoFOV", "50" );
|
|||
EditorSettings.setDefaultValue( "orthoShowGrid", "1" );
|
||||
EditorSettings.setDefaultValue( "currentEditor", "WorldEditorInspectorPlugin" );
|
||||
EditorSettings.setDefaultValue( "newLevelFile", "tools/levels/BlankRoom.mis" );
|
||||
EditorSettings.setDefaultValue( "newGameObjectDir", "scripts/server/gameObjects" );
|
||||
|
||||
if( isFile( "C:/Program Files/Torsion/Torsion.exe" ) )
|
||||
EditorSettings.setDefaultValue( "torsionPath", "C:/Program Files/Torsion/Torsion.exe" );
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ function EWCreatorWindow::init( %this )
|
|||
%this.registerMissionObject( "SFXSpace", "Sound Space" );
|
||||
%this.registerMissionObject( "OcclusionVolume", "Occlusion Volume" );
|
||||
%this.registerMissionObject( "AccumulationVolume", "Accumulation Volume" );
|
||||
%this.registerMissionObject( "Entity", "Entity" );
|
||||
|
||||
%this.endGroup();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue