From b7a2c30337f86bd821f17a6e3bb79edf9b2169a1 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 24 Jan 2021 04:33:28 -0600 Subject: [PATCH 1/2] Integrates object creator logic into the AB Adds lookup logic to Datablock AB entries to try and find class icons for the preview Adds 2 new datablock class create methods --- .../game/tools/assetBrowser/main.tscript | 1 + .../assetBrowser/scripts/assetBrowser.tscript | 189 +++++++++++------- .../scripts/assetTypes/creatorObj.tscript | 44 ++++ .../assetTypes/datablockObjects.tscript | 14 +- .../scripts/assetTypes/script.tscript | 2 +- .../worldEditor/gui/objectBuilderGui.ed.gui | 20 ++ 6 files changed, 192 insertions(+), 78 deletions(-) create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/creatorObj.tscript diff --git a/Templates/BaseGame/game/tools/assetBrowser/main.tscript b/Templates/BaseGame/game/tools/assetBrowser/main.tscript index 723545d22..7ac0ced40 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/main.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/main.tscript @@ -108,6 +108,7 @@ function initializeAssetBrowser() exec("./scripts/assetTypes/datablockObjects." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/looseFiles." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/prefab." @ $TorqueScriptFileExtension); + exec("./scripts/assetTypes/creatorObj." @ $TorqueScriptFileExtension); new ScriptObject( AssetBrowserPlugin ) { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript index 82625e981..4bcc58435 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript @@ -421,6 +421,12 @@ function AssetBrowser::buildAssetPreview( %this, %asset, %moduleName ) %assetDesc.description = %moduleName @ "/" @ %assetName; %assetDesc.assetType = %assetType; } + else if(%assetType $= "Creator") + { + %assetDesc = %assetName; + %assetDesc.assetType = %assetType; + %moduleName = %assetDesc; + } } /*%fullPath = %moduleName !$= "" ? %moduleName @ "/" @ %assetName : %assetName; %fullPath = strreplace(%fullPath, "/", "_"); @@ -810,69 +816,69 @@ function AssetBrowser::loadCreatorClasses(%this) %this.beginCreatorGroup( "Environment" ); - /*// Removed Prefab as there doesn't really seem to be a point in creating a blank one - //%this.registerMissionObject( "Prefab", "Prefab" ); - %this.registerMissionObject( "SkyBox", "Sky Box" ); - %this.registerMissionObject( "CloudLayer", "Cloud Layer" ); - %this.registerMissionObject( "BasicClouds", "Basic Clouds" ); - %this.registerMissionObject( "ScatterSky", "Scatter Sky" ); - %this.registerMissionObject( "Sun", "Basic Sun" ); - %this.registerMissionObject( "Lightning" ); - %this.registerMissionObject( "WaterBlock", "Water Block" ); - %this.registerMissionObject( "SFXEmitter", "Sound Emitter" ); - %this.registerMissionObject( "Precipitation" ); - %this.registerMissionObject( "ParticleEmitterNode", "Particle Emitter" ); + // Removed Prefab as there doesn't really seem to be a point in creating a blank one + //%this.addCreatorClass( "Prefab", "Prefab" ); + %this.addCreatorClass( "SkyBox", "Sky Box" ); + %this.addCreatorClass( "CloudLayer", "Cloud Layer" ); + %this.addCreatorClass( "BasicClouds", "Basic Clouds" ); + %this.addCreatorClass( "ScatterSky", "Scatter Sky" ); + %this.addCreatorClass( "Sun", "Basic Sun" ); + %this.addCreatorClass( "Lightning" ); + %this.addCreatorClass( "WaterBlock", "Water Block" ); + %this.addCreatorClass( "SFXEmitter", "Sound Emitter" ); + %this.addCreatorClass( "Precipitation" ); + %this.addCreatorClass( "ParticleEmitterNode", "Particle Emitter" ); // Legacy features. Users should use Ground Cover and the Forest Editor. - //%this.registerMissionObject( "fxShapeReplicator", "Shape Replicator" ); - //%this.registerMissionObject( "fxFoliageReplicator", "Foliage Replicator" ); + //%this.addCreatorClass( "fxShapeReplicator", "Shape Replicator" ); + //%this.addCreatorClass( "fxFoliageReplicator", "Foliage Replicator" ); - %this.registerMissionObject( "PointLight", "Point Light" ); - %this.registerMissionObject( "SpotLight", "Spot Light" ); - %this.registerMissionObject( "GroundCover", "Ground Cover" ); - %this.registerMissionObject( "TerrainBlock", "Terrain Block" ); - %this.registerMissionObject( "GroundPlane", "Ground Plane" ); - %this.registerMissionObject( "WaterPlane", "Water Plane" ); - %this.registerMissionObject( "PxCloth", "Cloth" ); - %this.registerMissionObject( "ForestWindEmitter", "Wind Emitter" ); + %this.addCreatorClass( "PointLight", "Point Light" ); + %this.addCreatorClass( "SpotLight", "Spot Light" ); + %this.addCreatorClass( "GroundCover", "Ground Cover" ); + %this.addCreatorClass( "TerrainBlock", "Terrain Block" ); + %this.addCreatorClass( "GroundPlane", "Ground Plane" ); + %this.addCreatorClass( "WaterPlane", "Water Plane" ); + %this.addCreatorClass( "PxCloth", "Cloth" ); + %this.addCreatorClass( "ForestWindEmitter", "Wind Emitter" ); - %this.registerMissionObject( "DustEmitter", "Dust Emitter" ); - %this.registerMissionObject( "DustSimulation", "Dust Simulation" ); - %this.registerMissionObject( "DustEffecter", "Dust Effecter" );*/ + %this.addCreatorClass( "DustEmitter", "Dust Emitter" ); + %this.addCreatorClass( "DustSimulation", "Dust Simulation" ); + %this.addCreatorClass( "DustEffecter", "Dust Effecter" ); %this.endCreatorGroup(); %this.beginCreatorGroup( "Level" ); - /*%this.registerMissionObject( "MissionArea", "Mission Area" ); - %this.registerMissionObject( "Path" ); - %this.registerMissionObject( "Marker", "Path Node" ); - %this.registerMissionObject( "Trigger" ); - %this.registerMissionObject( "PhysicalZone", "Physical Zone" ); - %this.registerMissionObject( "Camera" ); - %this.registerMissionObject( "LevelInfo", "Level Info" ); - %this.registerMissionObject( "TimeOfDay", "Time of Day" ); - %this.registerMissionObject( "Zone", "Zone" ); - %this.registerMissionObject( "Portal", "Zone Portal" ); - %this.registerMissionObject( "SpawnSphere", "Player Spawn Sphere", "PlayerDropPoint" ); - %this.registerMissionObject( "SpawnSphere", "Observer Spawn Sphere", "ObserverDropPoint" ); - %this.registerMissionObject( "SFXSpace", "Sound Space" ); - %this.registerMissionObject( "OcclusionVolume", "Occlusion Volume" );*/ + %this.addCreatorClass("MissionArea", "Mission Area" ); + %this.addCreatorClass("Path" ); + %this.addCreatorClass("Marker", "Path Node" ); + %this.addCreatorClass("Trigger" ); + %this.addCreatorClass("PhysicalZone", "Physical Zone" ); + %this.addCreatorClass("Camera" ); + %this.addCreatorClass( "LevelInfo", "Level Info" ); + %this.addCreatorClass( "TimeOfDay", "Time of Day" ); + %this.addCreatorClass( "Zone", "Zone" ); + %this.addCreatorClass( "Portal", "Zone Portal" ); + %this.addCreatorClass( "SpawnSphere", "Player Spawn Sphere"/*, "PlayerDropPoint"*/ ); + %this.addCreatorClass( "SpawnSphere", "Observer Spawn Sphere"/*, "ObserverDropPoint"*/ ); + %this.addCreatorClass( "SFXSpace", "Sound Space" ); + %this.addCreatorClass( "OcclusionVolume", "Occlusion Volume" ); %this.endCreatorGroup(); %this.beginCreatorGroup( "System" ); - //%this.registerMissionObject( "SimGroup" ); - //%this.registerMissionObject( "AIPathGroup" ); + %this.addCreatorClass( "SimGroup" ); + %this.addCreatorClass( "AIPathGroup" ); %this.endCreatorGroup(); %this.beginCreatorGroup( "ExampleObjects" ); - //%this.registerMissionObject( "RenderObjectExample" ); - //%this.registerMissionObject( "RenderMeshExample" ); - //%this.registerMissionObject( "RenderShapeExample" ); + %this.addCreatorClass( "RenderObjectExample" ); + %this.addCreatorClass( "RenderMeshExample" ); + %this.addCreatorClass( "RenderShapeExample" ); %this.endCreatorGroup(); @@ -881,9 +887,8 @@ function AssetBrowser::loadCreatorClasses(%this) function AssetBrowser::beginCreatorGroup(%this, %group) { - %this.currentCreatorGroup = %group; - AssetBrowser-->filterTree.insertItem(AssetBrowser-->filterTree.creatorIdx, %group); + %this.currentCreatorGroup = %group; } function AssetBrowser::endCreatorGroup(%this, %group) @@ -907,6 +912,20 @@ function AssetBrowser::addCreatorClass(%this, %class, %name, %buildfunc) warn( "AssetBrowser::addCreatorClass, invalid parameters!" ); return; } + + if(%buildfunc $= "") + { + %method = "build" @ %buildfunc; + if( !ObjectBuilderGui.isMethod( %method ) ) + %method = "build" @ %class; + + if( !ObjectBuilderGui.isMethod( %method ) ) + %cmd = "return new " @ %class @ "();"; + else + %cmd = "ObjectBuilderGui." @ %method @ "();"; + + %buildfunc = "ObjectBuilderGui.newObjectCallback = \"AssetBrowser.onFinishCreateObject\"; EWCreatorWindow.createObject( \"" @ %cmd @ "\" );"; + } %args = new ScriptObject(); %args.val[0] = %class; @@ -1330,23 +1349,10 @@ function AssetBrowserFilterTree::onSelect(%this, %itemId) } else if(%parentItem == %this.creatorIdx) { - //One of the creator folders was selected - %creatorGroup = %this.getItemText(%itemId); - for ( %i = 0; %i < %this.creatorClassArray.count(); %i++ ) - { - %group = %array.getKey( %i ); - - if ( %group $= %creatorGroup ) - { - %args = %array.getValue( %i ); - %class = %args.val[0]; - %name = %args.val[1]; - %func = %args.val[2]; - - //%this.addMissionObjectIcon( %class, %name, %func ); - echo("Populating Creator Group! " @ %group @ " for class: " @ %class); - } - } + %name = %this.getItemText(%itemId); + AssetBrowser.dirHandler.currentAddress = "Creator/" @ %name; + AssetBrowser.rebuildAssetArray(); + AssetBrowser.refresh(); } else { @@ -1368,6 +1374,23 @@ function AssetBrowserFilterTree::onSelect(%this, %itemId) } } +function AssetBrowserFilterTree::hasAsParent(%this, %itemId, %text) +{ + %parentId = %this.getParentItem(%itemId); + + while(%parentId != 0) + { + %parentText = %this.getItemText(%parentId); + if(%parentText $= %text) + return true; + + %parentId = %this.getParentItem(%parentId); + } + + + return false; +} + function AssetBrowser::rebuildAssetArray(%this) { if(!%this.previewArrayDirty) @@ -1539,7 +1562,7 @@ function AssetBrowser::doRebuildAssetArray(%this) } //Add Non-Asset Scripted Objects. Datablock, etc based - if(AssetBrowser.assetTypeFilter $= "") + if(AssetBrowser.assetTypeFilter $= "" && %breadcrumbPath !$= "") { %category = getWord( %breadcrumbPath, 1 ); %dataGroup = "DataBlockGroup"; @@ -1699,6 +1722,28 @@ function AssetBrowser::doRebuildAssetArray(%this) } } + //If we've selected into the Creator section, we have special handling for that + if(startsWith(%breadcrumbPath, "Creator")) + { + //One of the creator folders was selected + %creatorGroup = AssetBrowserFilterTree.getItemText(AssetBrowserFilterTree.getSelectedItem(0)); + + for ( %i = 0; %i < AssetBrowser.creatorClassArray.count(); %i++ ) + { + %group = AssetBrowser.creatorClassArray.getKey( %i ); + + if ( %group $= %creatorGroup ) + { + %creatorObj = AssetBrowser.creatorClassArray.getValue( %i ); + %class = %creatorObj.val[0]; + %name = %creatorObj.val[1]; + %func = %creatorObj.val[2]; + + %assetArray.add( %name, "Creator" TAB %creatorObj ); + } + } + } + for(%i=0; %i < %assetArray.count(); %i++) AssetBrowser.buildAssetPreview( %assetArray.getValue(%i), %assetArray.getKey(%i) ); @@ -2188,18 +2233,6 @@ function AssetBrowserPreviewButton::onMouseDragged(%this) %payload.position = "0 0"; //%payload.class = "AssetPreviewControl"; - /*%payload = new GuiBitmapButtonCtrl(); - //%payload.assignFieldsFrom( %this ); - %payload.assetName = %this.assetName; - %payload.assetType = %this.assetType ; - %payload.moduleName = %this.moduleName; - %payload.class = "AssetPreviewControl"; - %payload.position = "0 0"; - %payload.dragSourceControl = %this; - %payload.bitmap = %this.icon; - %payload.extent.x /= 2; - %payload.extent.y /= 2;*/ - %xOffset = getWord( %payload.extent, 0 ) / 2; %yOffset = getWord( %payload.extent, 1 ) / 2; @@ -2344,6 +2377,10 @@ function EWorldEditor::onControlDropped( %this, %payload, %position ) { %buildCommand = AssetBrowser @ ".on" @ %assetType @ "EditorDropped(\"" @ %module @ "/" @ %asset @ "\",\"" @ %position @ "\");"; } + else if(%assetType $= "Creator") + { + %buildCommand = AssetBrowser @ ".on" @ %assetType @ "EditorDropped(" @ %module @ ",\"" @ %position @ "\");"; + } else { %assetDef = AssetDatabase.acquireAsset(%module @ ":" @ %asset); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/creatorObj.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/creatorObj.tscript new file mode 100644 index 000000000..0cdeb5d0d --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/creatorObj.tscript @@ -0,0 +1,44 @@ +function AssetBrowser::buildCreatorPreview(%this, %assetDef, %previewData) +{ + %class = %assetDef.val[0]; + %name = %assetDef.val[1]; + %func = %assetDef.val[2]; + + %previewData.assetName = %name; + %previewData.assetPath = ""; + + %previewData.previewImage = "tools/classIcons/" @ %class; + + //%previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef; + %previewData.tooltip = "This creates a new object of the class " @ %class; + %previewData.doubleClickCommand = %func; +} + +function AssetBrowser::onFinishCreateObject(%this, %objId) +{ + %objId.position = %this.createdObjectPos; +} + +function AssetBrowser::onCreatorEditorDropped(%this, %assetDef, %position) +{ + %targetPosition = EWorldEditor.unproject(%position SPC 1000); + %camPos = LocalClientConnection.camera.getPosition(); + %rayResult = containerRayCast(%camPos, %targetPosition, -1); + + %pos = EWCreatorWindow.getCreateObjectPosition(); + + if(%rayResult != 0) + { + %pos = getWords(%rayResult, 1, 3); + } + else + { + %pos = "0 0 0"; + } + + %func = %assetDef.val[2]; + + %this.createdObjectPos = %pos; + %newObj = eval(%func); +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/datablockObjects.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/datablockObjects.tscript index 91e4f9968..2c46ca1e6 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/datablockObjects.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/datablockObjects.tscript @@ -47,9 +47,21 @@ function AssetBrowser::buildDatablockPreview(%this, %assetDef, %previewData) %previewData.previewImage = "tools/assetBrowser/art/datablockIcon"; + //Lets see if we have a icon for specifically for this datablock type + %dataClass = %assetDef.getClassName(); + %dataClass = strreplace(%dataClass, "Data", ""); + + %previewImage = "tools/classIcons/" @ %dataClass @ ".png"; + if(isFile(%previewImage)) + { + %previewData.previewImage = %previewImage; + } + //%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetDesc = %assetDef; - %previewData.tooltip = %assetDef; + %previewData.tooltip = "Datablock Name: " @ %assetDef @ "\n" @ + "Datablock Type: " @ %assetDef.getClassName(); + %previewData.doubleClickCommand = "AssetBrowser.schedule(10, \"spawnDatablockObject\",\""@ %assetDef @"\");";//browseTo %assetDef.dirPath / %assetDef.assetName } diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/script.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/script.tscript index adc921013..c7a226d49 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/script.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/script.tscript @@ -90,7 +90,7 @@ function AssetBrowser::moveScriptAsset(%this, %assetDef, %destination) AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath); } -function AssetBrowser::buildScriptAssetPreview(%this, %assetDef, %previewData) +function AssetBrowser::buildTScriptPreview(%this, %assetDef, %previewData) { %previewData.assetName = %assetDef.assetName; %previewData.assetPath = %assetDef.scriptFile; diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui index 28117af2e..b6277d8e7 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui @@ -1254,3 +1254,23 @@ function RibbonData::create( %datablock ) return %obj; } + +function ParticleEmitterData::create( %datablock ) +{ + %obj = new ParticleEmitter() + { + dataBlock = %datablock; + parentGroup = EWCreatorWindow.objectGroup; + }; + return %obj; +} + +function PrecipitationData::create(%datablock) +{ + %obj = new Precipitation() + { + dataBlock = %datablock; + parentGroup = EWCreatorWindow.objectGroup; + }; + return %obj; +} \ No newline at end of file From 3cb1699ed159bb7fcc0c0e0fc942d6be4e416988 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 24 Jan 2021 04:40:19 -0600 Subject: [PATCH 2/2] Fixed guiProfile references --- .../game/tools/assetBrowser/scripts/assetBrowser.tscript | 2 +- .../game/tools/worldEditor/gui/ManageBookmarksWindow.ed.gui | 2 +- .../BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript index 4bcc58435..33f67ddf7 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript @@ -1562,7 +1562,7 @@ function AssetBrowser::doRebuildAssetArray(%this) } //Add Non-Asset Scripted Objects. Datablock, etc based - if(AssetBrowser.assetTypeFilter $= "" && %breadcrumbPath !$= "") + if(AssetBrowser.assetTypeFilter $= "" && %breadcrumbPath !$= "" && !startsWith(%breadcrumbPath, "Creator/")) { %category = getWord( %breadcrumbPath, 1 ); %dataGroup = "DataBlockGroup"; diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/ManageBookmarksWindow.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/ManageBookmarksWindow.ed.gui index 49ec1d65b..c5f4ff469 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/ManageBookmarksWindow.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/ManageBookmarksWindow.ed.gui @@ -45,7 +45,7 @@ //Docking = "Top"; new GuiTextCtrl() { - profile = "GuiCenterTextProfile"; + profile = "ToolsGuiTextProfile"; horizSizing = "right"; vertSizing = "bottom"; position = "1 2"; diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui index b6277d8e7..b486ca467 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui @@ -32,7 +32,7 @@ text = "Create Object"; new GuiTextCtrl() { - profile = "GuiCenterTextProfile"; + profile = "ToolsGuiTextProfile"; horizSizing = "right"; vertSizing = "bottom"; position = "9 26";