Sfoglia il codice sorgente

clean out unnecessary position set
add a new route for the asset browser to create things in the form of ".on" @ %assetType @ "GUIEditorDropped(" @ %assetDef @ ",\"" @ %pos @ "\");";
demonstrate it with a soundasset creating a GuiAudioCtrl when drug onto the canvas

AzaezelX 1 anno fa
parent
commit
733c9d4b6d

+ 17 - 5
Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript

@@ -2582,12 +2582,24 @@ function GuiEditor::onControlDropped(%this, %payload, %position)
       //dealing with an actual asset, so build the assetName
       %assetId = %payload.moduleName @ ":" @ %payload.assetName;
       %assetType = AssetDatabase.getAssetType(%assetId);
-      
-      if(%assetType $= "ImageAsset")
+ 
+      if(AssetBrowser.isMethod("on" @ %assetType @ "GUIEditorDropped"))
+      {
+        %module = %payload.moduleName;
+        %asset = %payload.assetName;
+        %assetDef = AssetDatabase.acquireAsset(%module @ ":" @ %asset);
+        %buildCommand = AssetBrowser @ ".on" @ %assetType @ "GUIEditorDropped(" @ %assetDef @ ",\"" @ %pos @ "\");";  
+        eval(%buildCommand);    
+      }
+      else
       {
-         %cmd = "return new guiBitmapCtrl();";
-         %ctrl = eval( %cmd ); 
-         %ctrl.bitmap = %assetId;
+        //fallback example
+        if(%assetType $= "ImageAsset")
+        {
+            %cmd = "return new guiBitmapCtrl();";
+            %ctrl = eval( %cmd ); 
+            %ctrl.bitmap = %assetId;
+        }
       }
    }
    else

+ 11 - 0
Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/sound.tscript

@@ -91,6 +91,17 @@ function AssetBrowser::onSoundAssetEditorDropped(%this, %assetDef, %position)
    
 }
 
+function AssetBrowser::onSoundAssetGUIEditorDropped(%this, %assetDef, %position)
+{    
+   %assetId = %assetDef.getAssetId();
+   %cmd = "new GuiAudioCtrl(){";
+   %cmd = %cmd @ "SoundAsset =\""@ %assetId @"\";";
+   %cmd = %cmd @ "position =\""@ %position @"\";";
+   %cmd = %cmd @ "};";
+   %ctrl = GuiEditCanvas.createObject(%cmd);
+   echo(%ctrl SPC "created");
+}
+
 function GuiInspectorTypeSoundAssetPtr::onControlDropped( %this, %payload, %position )
 {
    Canvas.popDialog(EditorDragAndDropLayer);

+ 1 - 7
Templates/BaseGame/game/tools/guiEditor/scripts/guiEditorCanvas.ed.tscript

@@ -290,13 +290,7 @@ function GuiEditCanvas::createObject( %this, %cmd )
 
 function GuiEditCanvas::onFinishCreateObject( %this, %objId )
 {
-   GuiEditor.getCurrentAddSet().add( %objId );
-
-   if( %objId.isMemberOfClass( "GuiControl" ) )
-   {
-      %objId.position = "0 0";
-   }
-   
+   GuiEditor.getCurrentAddSet().add( %objId );   
    %this.onObjectCreated( %objId );
 }