Browse Source

Start of copy/paste for nodes, editable CSM shadow splits, cleanups

Josh Engebretson 10 years ago
parent
commit
4f5cf02fc5

+ 7 - 0
Script/AtomicEditor/ui/HierarchyFrame.ts

@@ -96,6 +96,13 @@ class HierarchyFrame extends Atomic.UIWidget {
 
 
           });
           });
 
 
+          this.subscribeToEvent("NodeAdded", (data) => {
+
+              this.refresh();
+
+          });
+
+
         }
         }
 
 
         this.refresh();
         this.refresh();

+ 2 - 4
Script/AtomicEditor/ui/ResourceFrame.ts

@@ -1,8 +1,6 @@
 import ScriptWidget = require("./ScriptWidget");
 import ScriptWidget = require("./ScriptWidget");
 import UIEvents = require("./UIEvents");
 import UIEvents = require("./UIEvents");
 
 
-var UI = Atomic.UI;
-
 // the root content of editor widgets (rootContentWidget property) are extended with an editor field
 // the root content of editor widgets (rootContentWidget property) are extended with an editor field
 // so we can access the editor they belong to from the widget itself
 // so we can access the editor they belong to from the widget itself
 interface EditorRootContentWidget extends Atomic.UIWidget {
 interface EditorRootContentWidget extends Atomic.UIWidget {
@@ -145,7 +143,7 @@ class ResourceFrame extends ScriptWidget {
 
 
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
 
 
-        if (ev.type == Atomic.UI.EVENT_TYPE_TAB_CHANGED && ev.target == this.tabcontainer) {
+        if (ev.type == Atomic.UI_EVENT_TYPE_TAB_CHANGED && ev.target == this.tabcontainer) {
             var w = <EditorRootContentWidget> this.tabcontainer.currentPageWidget;
             var w = <EditorRootContentWidget> this.tabcontainer.currentPageWidget;
 
 
             if (w && w.editor) {
             if (w && w.editor) {
@@ -171,7 +169,7 @@ class ResourceFrame extends ScriptWidget {
 
 
         this.load("AtomicEditor/editor/ui/resourceframe.tb.txt");
         this.load("AtomicEditor/editor/ui/resourceframe.tb.txt");
 
 
-        this.gravity = UI.GRAVITY_ALL;
+        this.gravity = Atomic.UI_GRAVITY_ALL;
 
 
         this.resourceViewContainer = <Atomic.UILayout> parent.getWidget("resourceviewcontainer");
         this.resourceViewContainer = <Atomic.UILayout> parent.getWidget("resourceviewcontainer");
         this.tabcontainer = <Atomic.UITabContainer> this.getWidget("tabcontainer");
         this.tabcontainer = <Atomic.UITabContainer> this.getWidget("tabcontainer");

+ 86 - 29
Script/AtomicEditor/ui/inspector/ComponentInspector.ts

@@ -1,6 +1,7 @@
 
 
 import ScriptWidget = require("../ScriptWidget");
 import ScriptWidget = require("../ScriptWidget");
 import DataBinding = require("./DataBinding");
 import DataBinding = require("./DataBinding");
+import InspectorUtils = require("./InspectorUtils");
 
 
 class ComponentInspector extends Atomic.UISection {
 class ComponentInspector extends Atomic.UISection {
 
 
@@ -31,34 +32,6 @@ class ComponentInspector extends Atomic.UISection {
 
 
     }
     }
 
 
-    addPrefabUI(layout:Atomic.UILayout) {
-
-      // expand prefab
-      this.value = 1;
-
-      var fd = new Atomic.UIFontDescription();
-      fd.id = "Vera";
-      fd.size = 11;
-
-      var selectButton = new Atomic.UIButton();
-      selectButton.text = "Select Prefab";
-      selectButton.fontDescription = fd;
-
-      selectButton.onClick = () => {
-
-          var node = (<Atomic.PrefabComponent> this.component).getPrefabNode();
-
-          this.sendEvent("EditorActiveNodeChange", { node: node });
-
-          return true;
-
-      }
-
-      layout.addChild(selectButton);
-
-
-    }
-
     inspect(component: Atomic.Component) {
     inspect(component: Atomic.Component) {
 
 
         this.component = component;
         this.component = component;
@@ -110,7 +83,6 @@ class ComponentInspector extends Atomic.UISection {
                 attrLayout.skinBg = "InspectorVectorAttrLayout";
                 attrLayout.skinBg = "InspectorVectorAttrLayout";
             }
             }
 
 
-
             var bname = attr.name;
             var bname = attr.name;
 
 
             if (bname == "Is Enabled")
             if (bname == "Is Enabled")
@@ -135,6 +107,10 @@ class ComponentInspector extends Atomic.UISection {
 
 
         }
         }
 
 
+        if (component.getTypeName() == "Light") {
+          this.addLightCascadeParametersUI(attrsVerticalLayout);
+        }
+
         var deleteButton = new Atomic.UIButton();
         var deleteButton = new Atomic.UIButton();
         deleteButton.text = "Delete Component";
         deleteButton.text = "Delete Component";
         deleteButton.fontDescription = fd;
         deleteButton.fontDescription = fd;
@@ -160,6 +136,87 @@ class ComponentInspector extends Atomic.UISection {
 
 
     }
     }
 
 
+    addPrefabUI(layout:Atomic.UILayout) {
+
+      // expand prefab
+      this.value = 1;
+
+      var fd = new Atomic.UIFontDescription();
+      fd.id = "Vera";
+      fd.size = 11;
+
+      var selectButton = new Atomic.UIButton();
+      selectButton.text = "Select Prefab";
+      selectButton.fontDescription = fd;
+
+      selectButton.onClick = () => {
+
+          var node = (<Atomic.PrefabComponent> this.component).getPrefabNode();
+
+          this.sendEvent("EditorActiveNodeChange", { node: node });
+
+          return true;
+
+      }
+
+      layout.addChild(selectButton);
+
+
+    }
+
+
+    addLightCascadeParametersUI(layout:Atomic.UILayout) {
+
+      var light = <Atomic.Light> this.component;
+
+      var cascadeInfo = light.getShadowCascade();
+
+      var container = InspectorUtils.createContainer();
+      container.gravity = Atomic.UI_GRAVITY_ALL;
+      layout.addChild(container);
+
+      var panel = new Atomic.UILayout();
+      panel.axis = Atomic.UI_AXIS_Y;
+      panel.layoutSize = Atomic.UI_LAYOUT_SIZE_PREFERRED;
+      panel.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
+      container.addChild(panel);
+
+      var label = InspectorUtils.createAttrName("CSM Splits:");
+      panel.addChild(label);
+
+      function createHandler(index, light, field) {
+
+        return function(data:Atomic.UIWidgetEvent) {
+
+          if (data.type == Atomic.UI_EVENT_TYPE_CHANGED) {
+
+            this.light.setShadowCascadeParameter(this.index, Number(this.field.text));
+
+          }
+
+        }.bind({index:index, light:light, field:field});
+
+      }
+
+      var field = InspectorUtils.createAttrEditField("Split 0", panel);
+      field.text = cascadeInfo[0].toString();
+      field.subscribeToEvent(field, "WidgetEvent", createHandler(0, light, field));
+
+      field = InspectorUtils.createAttrEditField("Split 1", panel);
+      field.text = cascadeInfo[1].toString();
+      field.subscribeToEvent(field, "WidgetEvent", createHandler(1, light, field));
+
+      field = InspectorUtils.createAttrEditField("Split 2", panel);
+      field.text = cascadeInfo[2].toString();
+      field.subscribeToEvent(field, "WidgetEvent", createHandler(2, light, field));
+
+      field = InspectorUtils.createAttrEditField("Split 3", panel);
+      field.text = cascadeInfo[3].toString();
+      field.subscribeToEvent(field, "WidgetEvent", createHandler(3, light, field));
+
+    }
+
+
     component: Atomic.Component;
     component: Atomic.Component;
     bindings: Array<DataBinding> = new Array();
     bindings: Array<DataBinding> = new Array();
 
 

+ 12 - 3
Script/AtomicEditor/ui/inspector/InspectorUtils.ts

@@ -1,7 +1,7 @@
 
 
 class InspectorUtils {
 class InspectorUtils {
 
 
-  static init() {
+  private static Ctor = (() => {
 
 
     var fd = InspectorUtils.attrFontDesc = new Atomic.UIFontDescription();
     var fd = InspectorUtils.attrFontDesc = new Atomic.UIFontDescription();
     fd.id = "Vera";
     fd.id = "Vera";
@@ -10,7 +10,7 @@ class InspectorUtils {
     // must not be void dor static initializer
     // must not be void dor static initializer
     return null;
     return null;
 
 
-  }
+  })();
 
 
   static createSeparator(parent:Atomic.UIWidget):Atomic.UISeparator {
   static createSeparator(parent:Atomic.UIWidget):Atomic.UISeparator {
 
 
@@ -24,6 +24,16 @@ class InspectorUtils {
 
 
   }
   }
 
 
+  static createContainer():Atomic.UIContainer {
+
+    var container = new Atomic.UIContainer();
+
+    container.skinBg = "AEContainer";
+
+    return container;
+
+  }
+
   static createAttrName(name:string):Atomic.UITextField {
   static createAttrName(name:string):Atomic.UITextField {
 
 
     var nameField = new Atomic.UITextField();
     var nameField = new Atomic.UITextField();
@@ -67,7 +77,6 @@ class InspectorUtils {
   }
   }
 
 
   // "static constructor"
   // "static constructor"
-  private static _init = InspectorUtils.init();
   private static attrFontDesc:Atomic.UIFontDescription;
   private static attrFontDesc:Atomic.UIFontDescription;
 
 
 }
 }

+ 3 - 0
Script/TypeScript/Atomic.d.ts

@@ -2495,6 +2495,9 @@ declare module Atomic {
       isNegative(): boolean;
       isNegative(): boolean;
       // Return a divisor value based on intensity for calculating the sort value.
       // Return a divisor value based on intensity for calculating the sort value.
       getIntensityDivisor(attenuation?: number): number;
       getIntensityDivisor(attenuation?: number): number;
+      getShadowCascade():Number[];
+      setShadowCascade(Number[] args);
+      setShadowCascadeParameter(index:number, value:number);
 
 
    }
    }
 
 

+ 1 - 1
Source/Atomic/UI/UISceneView.cpp

@@ -69,7 +69,7 @@ UISceneView::~UISceneView()
 
 
 bool UISceneView::OnEvent(const TBWidgetEvent &ev)
 bool UISceneView::OnEvent(const TBWidgetEvent &ev)
 {
 {
-    return false;
+    return UIWidget::OnEvent(ev);
 }
 }
 
 
 void UISceneView::HandleEndFrame(StringHash eventType, VariantMap& eventData)
 void UISceneView::HandleEndFrame(StringHash eventType, VariantMap& eventData)

+ 20 - 0
Source/AtomicEditorWork/Editors/SceneEditor3D/SceneEditor3D.cpp

@@ -119,8 +119,28 @@ bool SceneEditor3D::OnEvent(const TBWidgetEvent &ev)
             }
             }
 
 
             return true;
             return true;
+        }
+        else if (ev.ref_id == TBIDC("copy"))
+        {
+            if (selectedNode_.NotNull())
+            {
+                clipboardNode_ = selectedNode_->Clone();
+            }
+        }
+        else if (ev.ref_id == TBIDC("paste"))
+        {
+            if (clipboardNode_.NotNull() && selectedNode_.NotNull())
+            {
+                SharedPtr<Node> pasteNode(clipboardNode_->Clone());
+                selectedNode_->GetParent()->AddChild(pasteNode);
+
+                VariantMap eventData;
+                eventData[EditorActiveNodeChange::P_NODE] = pasteNode;
+                SendEvent(E_EDITORACTIVENODECHANGE, eventData);
 
 
+            }
         }
         }
+
     }
     }
 
 
     if (ev.type == EVENT_TYPE_CLICK)
     if (ev.type == EVENT_TYPE_CLICK)

+ 1 - 0
Source/AtomicEditorWork/Editors/SceneEditor3D/SceneEditor3D.h

@@ -66,6 +66,7 @@ private:
     SharedPtr<Gizmo3D> gizmo3D_;
     SharedPtr<Gizmo3D> gizmo3D_;
 
 
     WeakPtr<Node> selectedNode_;
     WeakPtr<Node> selectedNode_;
+    SharedPtr<Node> clipboardNode_;
 
 
 };
 };
 
 

+ 67 - 0
Source/AtomicJS/Javascript/JSGraphics.cpp

@@ -39,6 +39,69 @@ static int Light_SetShadowCascade(duk_context* ctx)
     return 0;
     return 0;
 }
 }
 
 
+static int Light_SetShadowCascadeParameter(duk_context* ctx)
+{
+    int index = (int) duk_require_number(ctx, 0);
+    float value = (float) duk_require_number(ctx, 1);
+
+    duk_push_this(ctx);
+    Light* light = js_to_class_instance<Light>(ctx, -1, 0);
+
+    CascadeParameters parms = light->GetShadowCascade();
+
+    switch (index)
+    {
+    case 0:
+        parms.splits_[0] = value;
+        break;
+    case 1:
+        parms.splits_[1] = value;
+        break;
+    case 2:
+        parms.splits_[2] = value;
+        break;
+    case 3:
+        parms.splits_[3] = value;
+        break;
+    case 4:
+        parms.fadeStart_ = value;
+        break;
+    case 5:
+        parms.biasAutoAdjust_ = value;
+        break;
+    }
+
+    light->SetShadowCascade(parms);
+
+    return 0;
+}
+
+
+static int Light_GetShadowCascade(duk_context* ctx)
+{
+    duk_push_this(ctx);
+    Light* light = js_to_class_instance<Light>(ctx, -1, 0);
+
+    const CascadeParameters& parms = light->GetShadowCascade();
+
+    duk_push_array(ctx);
+    duk_push_number(ctx, parms.splits_[0]);
+    duk_put_prop_index(ctx, -2, 0);
+    duk_push_number(ctx, parms.splits_[1]);
+    duk_put_prop_index(ctx, -2, 1);
+    duk_push_number(ctx, parms.splits_[2]);
+    duk_put_prop_index(ctx, -2, 2);
+    duk_push_number(ctx, parms.splits_[3]);
+    duk_put_prop_index(ctx, -2, 3);
+    duk_push_number(ctx, parms.fadeStart_);
+    duk_put_prop_index(ctx, -2, 4);
+    duk_push_number(ctx, parms.biasAutoAdjust_);
+    duk_put_prop_index(ctx, -2, 5);
+
+    return 1;
+}
+
+
 static int Light_SetShadowBias(duk_context* ctx)
 static int Light_SetShadowBias(duk_context* ctx)
 {
 {
     float constantBias = (float) duk_to_number(ctx, 0);
     float constantBias = (float) duk_to_number(ctx, 0);
@@ -125,6 +188,10 @@ void jsapi_init_graphics(JSVM* vm)
     js_class_get_prototype(ctx, "Atomic", "Light");
     js_class_get_prototype(ctx, "Atomic", "Light");
     duk_push_c_function(ctx, Light_SetShadowCascade, DUK_VARARGS);
     duk_push_c_function(ctx, Light_SetShadowCascade, DUK_VARARGS);
     duk_put_prop_string(ctx, -2, "setShadowCascade");
     duk_put_prop_string(ctx, -2, "setShadowCascade");
+    duk_push_c_function(ctx, Light_SetShadowCascadeParameter, 2);
+    duk_put_prop_string(ctx, -2, "setShadowCascadeParameter");
+    duk_push_c_function(ctx, Light_GetShadowCascade, 0);
+    duk_put_prop_string(ctx, -2, "getShadowCascade");
     duk_push_c_function(ctx, Light_SetShadowBias, 2);
     duk_push_c_function(ctx, Light_SetShadowBias, 2);
     duk_put_prop_string(ctx, -2, "setShadowBias");
     duk_put_prop_string(ctx, -2, "setShadowBias");
     duk_pop(ctx);
     duk_pop(ctx);

+ 6 - 0
Source/AtomicJS/Packages/Atomic/Graphics.json

@@ -22,7 +22,13 @@
 
 
 		"Material" : [
 		"Material" : [
 			"static getTextureUnitName(unit:TextureUnit):string;"
 			"static getTextureUnitName(unit:TextureUnit):string;"
+		],
+		"Light" : [
+			"getShadowCascade():Number[];",
+			"setShadowCascade(Number[] args);",
+			"setShadowCascadeParameter(index:number, value:number);"
 		]
 		]
+
 	}
 	}
 
 
 }
 }