Преглед изворни кода

Add EditLayerWindow for fastest mask view change (with children nodes)

MonkeyFirst пре 10 година
родитељ
комит
9c8ba2e2b0

+ 40 - 0
bin/Data/Scripts/Editor/EditorActions.as

@@ -14,6 +14,46 @@ class EditActionGroup
     Array<EditAction@> actions;
 }
 
+class CreateDrawableMaskAction : EditAction
+{
+    uint nodeID;
+    uint drawableID;
+    int oldViewMask;
+    int redoViewMask;
+
+    void Define(Drawable@ drawable)
+    {
+        drawableID = drawable.id;
+        nodeID = drawable.node.id;
+        oldViewMask = drawable.viewMask;
+        redoViewMask = oldViewMask;
+    }
+
+    void Undo()
+    {
+        Node@ node = editorScene.GetNode(nodeID);
+        Drawable@ drawable = editorScene.GetComponent(drawableID);
+        if (node !is null && drawable !is null)
+        {
+            redoViewMask = drawable.viewMask;
+            drawable.viewMask = oldViewMask;
+        }
+    }
+
+    void Redo()
+    {
+        Node@ node = editorScene.GetNode(nodeID);
+        Drawable@ drawable = editorScene.GetComponent(drawableID);
+        if (node !is null && drawable !is null)
+        {
+            oldViewMask = drawable.viewMask;
+            drawable.viewMask = redoViewMask;
+        }
+    }
+
+
+}
+
 class CreateNodeAction : EditAction
 {
     uint nodeID;

+ 194 - 0
bin/Data/Scripts/Editor/EditorLayers.as

@@ -0,0 +1,194 @@
+// Urho3D editor layer window
+
+Array<CheckBox@> bits;
+Window@ layerWindow;
+IntVector2 layerWindowPosition;
+
+void CreateLayerEditor()
+{
+    if (layerWindow !is null)
+        return;
+
+    layerWindow = LoadEditorUI("UI/EditorLayersWindow.xml");
+    ui.root.AddChild(layerWindow);
+    layerWindow.opacity = uiMaxOpacity;
+    
+    HideLayerEditor();
+    
+    bits.Resize(MAX_BITMASK_BITS);
+    
+    for (int i=0; i < MAX_BITMASK_BITS; i++) 
+    {
+            bits[i] = layerWindow.GetChild("Bit" + String(i), true);
+            bits[i].vars["index"] = i;
+            SubscribeToEvent(bits[i], "Toggled", "ToggleBits");
+    }
+}
+
+bool ShowLayerEditor()
+{
+    //if (ui.focusElement !is null) return false;
+    
+    if ( layerWindow.visible == true )
+    {
+        layerWindowPosition = ui.cursorPosition;
+        layerWindow.position = layerWindowPosition;
+        layerWindowPosition.x += layerWindow.width / 2;
+        layerWindow.BringToFront();
+        return true;
+    }
+    
+    EstablishSelectedNodeBitMaskToPanel();
+    
+    layerWindowPosition = ui.cursorPosition;
+    layerWindow.position = layerWindowPosition;
+    layerWindowPosition.x += layerWindow.width / 2;
+    layerWindow.visible = true;
+    layerWindow.BringToFront();
+    
+    // Subscribe while window are visible
+    SubscribeToEvent("MouseMove", "HandleHideLayerEditor");
+    SubscribeToEvent("MouseButtonDown", "HandleHideLayerEditor");
+    
+    return true;
+}
+
+void HideLayerEditor()
+{
+    layerWindow.visible = false;
+    // Unsubscribe then window are hides
+    UnsubscribeFromEvent(layerWindow, "MouseMove");
+    UnsubscribeFromEvent("MouseButtonDown");
+}
+
+void EstablishSelectedNodeBitMaskToPanel() 
+{
+    if (selectedNodes.length < 1) return;
+    
+    Node@ node;
+    
+    node = lastSelectedNode;
+    
+    if (node !is null) 
+    {
+        StaticModel@ model = node.GetComponent("StaticModel");
+        if (model !is null) 
+        {
+            SetupBitsPanel(model.viewMask);
+        }
+    }
+}
+
+void SetupBitsPanel( int mask) 
+{
+    for (int i = 0; i < 8; i++) 
+    {
+        if ((1 << i) & mask != 0) 
+        {
+            bits[i].checked = true;
+        }
+        else
+        {
+            bits[i].checked = false;
+        }
+    }
+}
+
+void ChangeNodeViewMask(Node@ node, EditActionGroup@ group, int mask) 
+{
+    Array<Component@> components = node.GetComponents();
+    if (components.length > 0) 
+    {
+        for (int componentIndex = 0; componentIndex < components.length; componentIndex++) 
+        {
+            Component@ component = components[componentIndex];
+            Drawable@ drawable = cast<Drawable>(component);
+            if (drawable !is null) 
+            {
+                    
+                    // Save before modification
+                    CreateDrawableMaskAction action;
+                    action.Define(drawable);
+                    group.actions.Push(action);
+    
+                    drawable.viewMask = mask;    
+            }       
+        }
+    }
+}
+
+void EstablishBitMaskToSelectedNodes() 
+{
+    if (selectedNodes.length < 1) return;
+    
+    // Group for storing undo actions
+    EditActionGroup group;
+    
+    for (int indexNode = 0; indexNode < selectedNodes.length; indexNode++) 
+    {
+        Node@ node = selectedNodes[indexNode];
+        if (node !is null) 
+        {
+            int mask = 0;
+            for (int i = 0; i < MAX_BITMASK_BITS; i++) 
+            {
+                mask = mask | (bits[i].checked ? 1 << i : 0);
+            }
+            
+            if (mask == MAX_BITMASK_VALUE)
+                mask = -1;
+            
+            
+            ChangeNodeViewMask(node, group, mask);
+            Array<Node@> children = node.GetChildren(true);
+            if (children.length > 0) 
+            {
+                for (int i =0; i < children.length; i++) 
+                {
+                    ChangeNodeViewMask(children[i], group, mask);
+                }
+            }   
+        }
+    }
+    
+    SaveEditActionGroup(group);
+    SetSceneModified();
+}
+
+void HandleHideLayerEditor(StringHash eventType, VariantMap& eventData)
+{
+    if ( eventType == StringHash("MouseMove") && ui.focusElement is null) 
+    {
+        IntVector2 mousePos;
+        mousePos.x = eventData["X"].GetInt();
+        mousePos.y = eventData["Y"].GetInt();
+        
+        Vector2 a = Vector2(layerWindowPosition.x, layerWindowPosition.y);
+        Vector2 b = Vector2(mousePos.x, mousePos.y);
+        Vector2 dir = a - b;
+        float distance = dir.length;
+        
+        if (distance > layerWindow.width)
+            HideLayerEditor();
+    } 
+    else if ( eventType == StringHash("MouseButtonDown") ) 
+    {
+        if (ui.focusElement is null) 
+        {
+            HideLayerEditor();
+        } 
+    }
+}
+
+void ToggleBits(StringHash eventType, VariantMap& eventData)
+{
+    CheckBox@ cb = cast<CheckBox>(eventData["Element"].GetPtr());
+    int bitIndex = cb.vars["index"].GetInt();
+  
+    if (bitIndex < MAX_BITMASK_BITS) 
+    {
+        EstablishBitMaskToSelectedNodes();
+    }
+    
+
+}

+ 5 - 0
bin/Data/Scripts/Editor/EditorScene.as

@@ -519,6 +519,11 @@ bool ToggleSceneUpdate()
     return true;
 }
 
+bool ShowLayerMover()
+{
+  return ShowLayerEditor();
+}
+
 void SetSceneModified()
 {
     if (!sceneModified)

+ 5 - 2
bin/Data/Scripts/Editor/EditorUI.as

@@ -87,6 +87,7 @@ void CreateUI()
     CreateDebugHud();
     CreateResourceBrowser();
     CreateCamera();
+    CreateLayerEditor();
 
     SubscribeToEvent("ScreenMode", "ResizeUI");
     SubscribeToEvent("MenuSelected", "HandleMenuSelected");
@@ -327,7 +328,7 @@ void CreateMenuBar()
         if ( hotKeyMode == HOTKEYS_MODE_STANDARD )
             popup.AddChild(CreateMenuItem("Duplicate", @Duplicate, 'D', QUAL_CTRL));
         else if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
-          popup.AddChild(CreateMenuItem("Duplicate", @Duplicate, 'D', QUAL_SHIFT ));
+            popup.AddChild(CreateMenuItem("Duplicate", @Duplicate, 'D', QUAL_SHIFT ));
         
         popup.AddChild(CreateMenuItem("Copy", @Copy, 'C', QUAL_CTRL));
         popup.AddChild(CreateMenuItem("Paste", @Paste, 'V', QUAL_CTRL));
@@ -385,6 +386,8 @@ void CreateMenuBar()
         //else if ( hotKeyMode == HOT_KEYS_MODE_BLENDER )
         //    popup.AddChild(CreateMenuItem("Toggle update", @ToggleSceneUpdate, 'P', QUAL_CTRL));
         
+        if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
+             popup.AddChild(CreateMenuItem("Move to layer", @ShowLayerMover, 'M'));
         
         popup.AddChild(CreateMenuItem("Stop test animation", @StopTestAnimation));
         CreateChildDivider(popup);
@@ -1256,7 +1259,7 @@ void HandleHotKeysBlender( VariantMap& eventData )
     }
     else if (key == KEY_SPACE)
     {
-        if (ui.cursor.visible)
+        if (ui.cursor.visible && ui.focusElement is null)
             ToggleQuickMenu();
     }
     else 

+ 120 - 0
bin/Data/UI/EditorLayersWindow.xml

@@ -0,0 +1,120 @@
+<?xml version="1.0"?>
+<element type="Window">
+	<attribute name="Name" value="EditorLayers" />
+	<attribute name="Position" value="952 533" />
+	<attribute name="Size" value="220 45" />
+	<element type="CheckBox">
+		<attribute name="Name" value="Bit0" />
+		<attribute name="Position" value="55 24" />
+		<attribute name="Size" value="16 16" />
+		<attribute name="Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Is Selected" value="true" />
+		<attribute name="Layout Mode" value="Horizontal" />
+	</element>
+	<element type="CheckBox">
+		<attribute name="Name" value="Bit1" />
+		<attribute name="Position" value="75 24" />
+		<attribute name="Size" value="16 16" />
+		<attribute name="Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Is Selected" value="true" />
+		<attribute name="Layout Mode" value="Horizontal" />
+	</element>
+	<element type="CheckBox">
+		<attribute name="Name" value="Bit2" />
+		<attribute name="Position" value="95 24" />
+		<attribute name="Size" value="16 16" />
+		<attribute name="Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Is Selected" value="true" />
+		<attribute name="Layout Mode" value="Horizontal" />
+	</element>
+	<element type="CheckBox">
+		<attribute name="Name" value="Bit3" />
+		<attribute name="Position" value="115 24" />
+		<attribute name="Size" value="16 16" />
+		<attribute name="Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Is Selected" value="true" />
+		<attribute name="Layout Mode" value="Horizontal" />
+	</element>
+	<element type="CheckBox">
+		<attribute name="Name" value="Bit4" />
+		<attribute name="Position" value="135 24" />
+		<attribute name="Size" value="16 16" />
+		<attribute name="Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Is Selected" value="true" />
+		<attribute name="Layout Mode" value="Horizontal" />
+	</element>
+	<element type="CheckBox">
+		<attribute name="Name" value="Bit5" />
+		<attribute name="Position" value="155 24" />
+		<attribute name="Size" value="16 16" />
+		<attribute name="Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Is Selected" value="true" />
+		<attribute name="Layout Mode" value="Horizontal" />
+	</element>
+	<element type="CheckBox">
+		<attribute name="Name" value="Bit6" />
+		<attribute name="Position" value="175 24" />
+		<attribute name="Size" value="16 16" />
+		<attribute name="Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Is Selected" value="true" />
+		<attribute name="Layout Mode" value="Horizontal" />
+	</element>
+	<element type="CheckBox">
+		<attribute name="Name" value="Bit7" />
+		<attribute name="Position" value="195 24" />
+		<attribute name="Size" value="16 16" />
+		<attribute name="Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Top Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Left Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Bottom Right Color" value="0.5 0.5 0.5 1" />
+		<attribute name="Is Selected" value="true" />
+		<attribute name="Layout Mode" value="Horizontal" />
+	</element>
+	<element type="Text">
+		<attribute name="Position" value="6 24" />
+		<attribute name="Top Left Color" value="0.85 0.85 0.85 1" />
+		<attribute name="Top Right Color" value="0.85 0.85 0.85 1" />
+		<attribute name="Bottom Left Color" value="0.85 0.85 0.85 1" />
+		<attribute name="Bottom Right Color" value="0.85 0.85 0.85 1" />
+		<attribute name="Text" value="Layer" />
+		<attribute name="Text Alignment" value="Center" />
+	</element>
+	<element type="Text">
+		<attribute name="Position" value="6 4" />
+		<attribute name="Top Left Color" value="0.85 0.85 0.85 1" />
+		<attribute name="Top Right Color" value="0.85 0.85 0.85 1" />
+		<attribute name="Bottom Left Color" value="0.85 0.85 0.85 1" />
+		<attribute name="Bottom Right Color" value="0.85 0.85 0.85 1" />
+		<attribute name="Text" value="Move to" />
+		<attribute name="Text Alignment" value="Center" />
+	</element>
+</element>