فهرست منبع

Select CSComponent class from assembly field UI

Josh Engebretson 10 سال پیش
والد
کامیت
b49539ce13

+ 86 - 0
Script/AtomicEditor/ui/frames/inspector/CSComponentClassSelector.ts

@@ -0,0 +1,86 @@
+//
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// LICENSE: Atomic Game Engine Editor and Tools EULA
+// Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
+// license information: https://github.com/AtomicGameEngine/AtomicGameEngine
+//
+
+import EditorUI = require("ui/EditorUI");
+
+class CSComponentClassSelector extends Atomic.UIWindow {
+
+    constructor(editField: Atomic.UIEditField, component: AtomicNET.CSComponent) {
+
+        super();
+
+        var assemblyFile = component.assemblyFile;
+
+        this.text = "Select Class: " + assemblyFile.name;
+
+        this.rect = [0, 0, 400, 512];
+
+        var mainLayout = new Atomic.UILayout();
+        mainLayout.gravity = Atomic.UI_GRAVITY_ALL;
+        mainLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_AVAILABLE;
+        mainLayout.axis = Atomic.UI_AXIS_Y;
+        this.contentRoot.addChild(mainLayout);
+
+        // really want a grid container
+        var scrollContainer = new Atomic.UIScrollContainer();
+        scrollContainer.gravity = Atomic.UI_GRAVITY_ALL;
+        scrollContainer.scrollMode = Atomic.UI_SCROLL_MODE_Y_AUTO;
+        scrollContainer.adaptContentSize = true;
+
+        var scrollLayout = new Atomic.UILayout();
+        scrollLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
+        scrollLayout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
+        scrollLayout.axis = Atomic.UI_AXIS_Y;
+
+        scrollContainer.contentRoot.addChild(scrollLayout);
+
+        var window = this;
+
+        for (var i in assemblyFile.classNames) {
+
+            var classname = assemblyFile.classNames[i];
+            var button = new Atomic.UIButton();
+            button.text = classname;
+
+            button.onClick = function() {
+                editField.text = this.text;
+                component.componentClassName = this.text;
+                window.close();
+            }.bind(button);
+
+            scrollLayout.addChild(button);
+        }
+
+        mainLayout.addChild(scrollContainer);
+
+        EditorUI.getMainFrame().addChild(this);
+
+        this.center();
+
+        this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
+
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            if (ev.target != this && !this.isAncestorOf(ev.target)) {
+
+                //this.close();
+
+            }
+
+        }
+
+        return false;
+
+    }
+
+}
+
+export = CSComponentClassSelector;

+ 52 - 22
Script/AtomicEditor/ui/frames/inspector/ComponentInspector.ts

@@ -9,6 +9,7 @@ import ScriptWidget = require("ui/ScriptWidget");
 import DataBinding = require("./DataBinding");
 import InspectorUtils = require("./InspectorUtils");
 import EditorUI = require("ui/EditorUI");
+import CSComponentClassSelector = require("./CSComponentClassSelector");
 
 class ComponentInspector extends Atomic.UISection {
 
@@ -47,11 +48,11 @@ class ComponentInspector extends Atomic.UISection {
         // For JSComponents append the filename
         if (component.typeName == "JSComponent") {
 
-            var jsc = <Atomic.JSComponent> component;
+            var jsc = <Atomic.JSComponent>component;
 
             if (jsc.componentFile) {
-              var pathInfo = Atomic.splitPath( jsc.componentFile.name);
-              this.text = "JS - " + pathInfo.fileName;
+                var pathInfo = Atomic.splitPath(jsc.componentFile.name);
+                this.text = "JS - " + pathInfo.fileName;
             }
 
         }
@@ -82,7 +83,7 @@ class ComponentInspector extends Atomic.UISection {
 
         for (var i in attrs) {
 
-            var attr = <Atomic.AttributeInfo> attrs[i];
+            var attr = <Atomic.AttributeInfo>attrs[i];
 
             if (attr.mode & Atomic.AM_NOEDIT)
                 continue;
@@ -148,6 +149,7 @@ class ComponentInspector extends Atomic.UISection {
         if (component.typeName == "CSComponent") {
             // auto expand CSComponents
             this.value = 1;
+            this.addCSComponentUI(attrsVerticalLayout);
         }
 
 
@@ -202,7 +204,7 @@ class ComponentInspector extends Atomic.UISection {
 
         if (dragObject.object && dragObject.object.typeName == "Asset") {
 
-            var asset = <ToolCore.Asset> dragObject.object;
+            var asset = <ToolCore.Asset>dragObject.object;
 
             if (asset.importerTypeName == importerTypeName) {
                 return asset.importer;
@@ -226,7 +228,7 @@ class ComponentInspector extends Atomic.UISection {
 
             EditorUI.getModelOps().showResourceSelection("Select Material", "MaterialImporter", function(asset: ToolCore.Asset) {
 
-                staticModel.setMaterialIndex(index, <Atomic.Material> Atomic.cache.getResource("Material", asset.path));
+                staticModel.setMaterialIndex(index, <Atomic.Material>Atomic.cache.getResource("Material", asset.path));
 
                 if (staticModel.getMaterial())
                     materialField.text = staticModel.getMaterial().name;
@@ -254,10 +256,10 @@ class ComponentInspector extends Atomic.UISection {
 
                 if (importer) {
 
-                    var materialImporter = <ToolCore.MaterialImporter> importer;
+                    var materialImporter = <ToolCore.MaterialImporter>importer;
                     var asset = materialImporter.asset;
 
-                    var material = <Atomic.Material> Atomic.cache.getResource("Material", asset.path);
+                    var material = <Atomic.Material>Atomic.cache.getResource("Material", asset.path);
 
                     if (material) {
 
@@ -275,7 +277,7 @@ class ComponentInspector extends Atomic.UISection {
 
     addModelUI(layout: Atomic.UILayout, typeName: string) {
 
-        var staticModel = <Atomic.StaticModel> this.component;
+        var staticModel = <Atomic.StaticModel>this.component;
 
         var numGeometries = staticModel.numGeometries;
         if (typeName == "Skybox") {
@@ -294,7 +296,7 @@ class ComponentInspector extends Atomic.UISection {
 
     addSpriteUI(layout: Atomic.UILayout, typeName: string) {
 
-        var spriteComponent = <Atomic.StaticSprite2D> this.component;
+        var spriteComponent = <Atomic.StaticSprite2D>this.component;
 
         var o = InspectorUtils.createAttrEditFieldWithSelectButton("Sprite", layout);
         var field = o.editField;
@@ -308,7 +310,7 @@ class ComponentInspector extends Atomic.UISection {
             // this should allow selecting of sprite sheets as well
             EditorUI.getModelOps().showResourceSelection("Select Sprite", "TextureImporter", function(asset: ToolCore.Asset) {
 
-                spriteComponent.sprite = <Atomic.Sprite2D> Atomic.cache.getResource("Sprite2D", asset.path);
+                spriteComponent.sprite = <Atomic.Sprite2D>Atomic.cache.getResource("Sprite2D", asset.path);
                 if (spriteComponent.sprite)
                     field.text = spriteComponent.sprite.name;
 
@@ -325,9 +327,9 @@ class ComponentInspector extends Atomic.UISection {
 
                 if (importer) {
 
-                  spriteComponent.sprite = <Atomic.Sprite2D> Atomic.cache.getResource("Sprite2D", importer.asset.path);
-                  if (spriteComponent.sprite)
-                      field.text = spriteComponent.sprite.name;
+                    spriteComponent.sprite = <Atomic.Sprite2D>Atomic.cache.getResource("Sprite2D", importer.asset.path);
+                    if (spriteComponent.sprite)
+                        field.text = spriteComponent.sprite.name;
 
                 }
             }
@@ -339,7 +341,7 @@ class ComponentInspector extends Atomic.UISection {
 
     addTilemap2DUI(layout: Atomic.UILayout) {
 
-        var tilemap = <Atomic.TileMap2D> this.component;
+        var tilemap = <Atomic.TileMap2D>this.component;
 
         var o = InspectorUtils.createAttrEditFieldWithSelectButton("TMX File", layout);
         var field = o.editField;
@@ -353,7 +355,7 @@ class ComponentInspector extends Atomic.UISection {
             // this should allow selecting of sprite sheets as well
             EditorUI.getModelOps().showResourceSelection("Select TMX File", "TMXImporter", function(asset: ToolCore.Asset) {
 
-                tilemap.tmxFile = <Atomic.TmxFile2D> Atomic.cache.getResource("TmxFile2D", asset.path);
+                tilemap.tmxFile = <Atomic.TmxFile2D>Atomic.cache.getResource("TmxFile2D", asset.path);
                 if (tilemap.tmxFile)
                     field.text = tilemap.tmxFile.name;
             });
@@ -369,9 +371,9 @@ class ComponentInspector extends Atomic.UISection {
 
                 if (importer) {
 
-                  tilemap.tmxFile = <Atomic.TmxFile2D> Atomic.cache.getResource("TmxFile2D", importer.asset.path);
-                  if (tilemap.tmxFile)
-                      field.text = tilemap.tmxFile.name;
+                    tilemap.tmxFile = <Atomic.TmxFile2D>Atomic.cache.getResource("TmxFile2D", importer.asset.path);
+                    if (tilemap.tmxFile)
+                        field.text = tilemap.tmxFile.name;
 
                 }
             }
@@ -382,7 +384,7 @@ class ComponentInspector extends Atomic.UISection {
 
     addLightCascadeParametersUI(layout: Atomic.UILayout) {
 
-        var light = <Atomic.Light> this.component;
+        var light = <Atomic.Light>this.component;
 
         var cascadeInfo = light.getShadowCascade();
 
@@ -434,7 +436,7 @@ class ComponentInspector extends Atomic.UISection {
 
     addCollisionShapeUI(layout: Atomic.UILayout) {
 
-        var shape = <Atomic.CollisionShape> this.component;
+        var shape = <Atomic.CollisionShape>this.component;
 
         var button = new Atomic.UIButton();
         button.fontDescription = InspectorUtils.attrFontDesc;
@@ -443,7 +445,7 @@ class ComponentInspector extends Atomic.UISection {
 
         button.onClick = () => {
 
-            var model = <Atomic.Drawable> shape.node.getComponent("StaticModel");
+            var model = <Atomic.Drawable>shape.node.getComponent("StaticModel");
             if (model) {
                 var box = model.boundingBox;
                 shape.setBox([box[3] - box[0], box[4] - box[1], box[5] - box[2]]);
@@ -455,6 +457,34 @@ class ComponentInspector extends Atomic.UISection {
 
     }
 
+    addCSComponentUI(layout: Atomic.UILayout) {
+
+        for (var i in this.bindings) {
+
+            var binding = this.bindings[i];
+
+            // replace the Class widget with a editfield + select button
+            if (binding.attrInfo.name == "Class") {
+
+                var parent = binding.widget.parent;
+                var text = binding.widget.text;
+                binding.widget.parent.removeChild(binding.widget);
+                var o = InspectorUtils.createAttrEditFieldWithSelectButton("", parent);
+                o.editField.text = text;
+                binding.widget = o.editField;
+
+                o.selectButton.onClick = () => {
+
+                  var cscomponent = <AtomicNET.CSComponent> this.component;
+                  if (cscomponent.assemblyFile) {
+                    var selector = new CSComponentClassSelector(o.editField, cscomponent);
+                  }
+                }
+
+                break;
+            }
+        }
+    }
 
     component: Atomic.Component;
     bindings: Array<DataBinding> = new Array();