Browse Source

Fixed UI element layout sometimes getting sorted upside down.
Added editing of misc. material attributes (depth bias, cull mode.)
Refresh material editor if the current material is externally edited & reloaded.

Lasse Öörni 12 years ago
parent
commit
dafa08d4ba

+ 95 - 2
Bin/Data/Scripts/Editor/EditorMaterial.as

@@ -3,6 +3,7 @@
 Window@ materialWindow;
 Window@ materialWindow;
 Material@ editMaterial;
 Material@ editMaterial;
 XMLFile@ oldMaterialState;
 XMLFile@ oldMaterialState;
+bool inMaterialRefresh = true;
 
 
 void CreateMaterialEditor()
 void CreateMaterialEditor()
 {
 {
@@ -14,7 +15,7 @@ void CreateMaterialEditor()
     materialWindow.opacity = uiMaxOpacity;
     materialWindow.opacity = uiMaxOpacity;
 
 
     RefreshMaterialEditor();
     RefreshMaterialEditor();
-    
+
     int height = Min(ui.root.height - 60, 500);
     int height = Min(ui.root.height - 60, 500);
     materialWindow.SetSize(300, height);
     materialWindow.SetSize(300, height);
     CenterDialog(materialWindow);
     CenterDialog(materialWindow);
@@ -31,10 +32,17 @@ void CreateMaterialEditor()
     SubscribeToEvent(materialWindow.GetChild("NewTechniqueButton", true), "Released", "NewTechnique");
     SubscribeToEvent(materialWindow.GetChild("NewTechniqueButton", true), "Released", "NewTechnique");
     SubscribeToEvent(materialWindow.GetChild("DeleteTechniqueButton", true), "Released", "DeleteTechnique");
     SubscribeToEvent(materialWindow.GetChild("DeleteTechniqueButton", true), "Released", "DeleteTechnique");
     SubscribeToEvent(materialWindow.GetChild("SortTechniquesButton", true), "Released", "SortTechniques");
     SubscribeToEvent(materialWindow.GetChild("SortTechniquesButton", true), "Released", "SortTechniques");
+    SubscribeToEvent(materialWindow.GetChild("ConstantBiasEdit", true), "TextChanged", "EditConstantBias");
+    SubscribeToEvent(materialWindow.GetChild("ConstantBiasEdit", true), "TextFinished", "EditConstantBias");
+    SubscribeToEvent(materialWindow.GetChild("SlopeBiasEdit", true), "TextChanged", "EditSlopeBias");
+    SubscribeToEvent(materialWindow.GetChild("SlopeBiasEdit", true), "TextFinished", "EditSlopeBias");
+    SubscribeToEvent(materialWindow.GetChild("CullModeEdit", true), "ItemSelected", "EditCullMode");
+    SubscribeToEvent(materialWindow.GetChild("ShadowCullModeEdit", true), "ItemSelected", "EditShadowCullMode");
 }
 }
 
 
 bool ShowMaterialEditor()
 bool ShowMaterialEditor()
 {
 {
+    RefreshMaterialEditor();
     materialWindow.visible = true;
     materialWindow.visible = true;
     materialWindow.BringToFront();
     materialWindow.BringToFront();
     return true;
     return true;
@@ -47,8 +55,14 @@ void HideMaterialEditor()
 
 
 void EditMaterial(Material@ mat)
 void EditMaterial(Material@ mat)
 {
 {
+    if (editMaterial !is null)
+        UnsubscribeFromEvent(editMaterial, "ReloadFinished");
+
     editMaterial = mat;
     editMaterial = mat;
-    RefreshMaterialEditor();
+
+    if (editMaterial !is null)
+        SubscribeToEvent(editMaterial, "ReloadFinished", "RefreshMaterialEditor");
+
     ShowMaterialEditor();
     ShowMaterialEditor();
 }
 }
 
 
@@ -58,6 +72,7 @@ void RefreshMaterialEditor()
     RefreshMaterialTechniques();
     RefreshMaterialTechniques();
     RefreshMaterialTextures();
     RefreshMaterialTextures();
     RefreshMaterialShaderParameters();
     RefreshMaterialShaderParameters();
+    RefreshMaterialMiscParameters();
 }
 }
 
 
 void RefreshMaterialName()
 void RefreshMaterialName()
@@ -229,6 +244,28 @@ void RefreshMaterialShaderParameters()
     }
     }
 }
 }
 
 
+void RefreshMaterialMiscParameters()
+{
+    if (editMaterial is null)
+        return;
+        
+    BiasParameters bias = editMaterial.depthBias;
+
+    inMaterialRefresh = true;
+
+    LineEdit@ attrEdit = materialWindow.GetChild("ConstantBiasEdit", true);
+    attrEdit.text = String(bias.constantBias);
+    attrEdit = materialWindow.GetChild("SlopeBiasEdit", true);
+    attrEdit.text = String(bias.slopeScaledBias);
+    
+    DropDownList@ attrList = materialWindow.GetChild("CullModeEdit", true);
+    attrList.selection = editMaterial.cullMode;
+    attrList = materialWindow.GetChild("ShadowCullModeEdit", true);
+    attrList.selection = editMaterial.shadowCullMode;
+    
+    inMaterialRefresh = false;
+}
+
 void EditMaterialName(StringHash eventType, VariantMap& eventData)
 void EditMaterialName(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ nameEdit = eventData["Element"].GetUIElement();
     LineEdit@ nameEdit = eventData["Element"].GetUIElement();
@@ -630,6 +667,62 @@ void SortTechniques()
     RefreshMaterialTechniques();
     RefreshMaterialTechniques();
 }
 }
 
 
+void EditConstantBias(StringHash eventType, VariantMap& eventData)
+{
+    if (editMaterial is null || inMaterialRefresh)
+        return;
+        
+    BeginMaterialEdit();
+ 
+    LineEdit@ attrEdit = eventData["Element"].GetUIElement();
+    BiasParameters bias = editMaterial.depthBias;
+    bias.constantBias = attrEdit.text.ToFloat();
+    editMaterial.depthBias = bias;
+
+    EndMaterialEdit();
+}
+
+void EditSlopeBias(StringHash eventType, VariantMap& eventData)
+{
+    if (editMaterial is null || inMaterialRefresh)
+        return;
+        
+    BeginMaterialEdit();
+ 
+    LineEdit@ attrEdit = eventData["Element"].GetUIElement();
+    BiasParameters bias = editMaterial.depthBias;
+    bias.slopeScaledBias = attrEdit.text.ToFloat();
+    editMaterial.depthBias = bias;
+
+    EndMaterialEdit();
+}
+
+void EditCullMode(StringHash eventType, VariantMap& eventData)
+{
+    if (editMaterial is null || inMaterialRefresh)
+        return;
+        
+    BeginMaterialEdit();
+    
+    DropDownList@ attrEdit = eventData["Element"].GetUIElement();
+    editMaterial.cullMode = CullMode(attrEdit.selection);
+
+    EndMaterialEdit();
+}
+
+void EditShadowCullMode(StringHash eventType, VariantMap& eventData)
+{
+    if (editMaterial is null || inMaterialRefresh)
+        return;
+        
+    BeginMaterialEdit();
+    
+    DropDownList@ attrEdit = eventData["Element"].GetUIElement();
+    editMaterial.shadowCullMode = CullMode(attrEdit.selection);
+
+    EndMaterialEdit();
+}
+
 void BeginMaterialEdit()
 void BeginMaterialEdit()
 {
 {
     if (editMaterial is null)
     if (editMaterial is null)

+ 75 - 0
Bin/Data/UI/EditorMaterialWindow.xml

@@ -132,6 +132,81 @@
         </element>
         </element>
     </element>
     </element>
     <element type="BorderImage" style="EditorDivider" />
     <element type="BorderImage" style="EditorDivider" />
+    <element>
+        <attribute name="Min Size" value="0 16" />
+        <attribute name="Max Size" value="2147483647 16" />
+        <attribute name="Layout Mode" value="Horizontal" />
+        <attribute name="Layout Spacing" value="10" />
+        <element type="Text" style="EditorAttributeText">
+            <attribute name="Text" value="Constant bias" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="ConstantBiasEdit" />
+        </element>
+        <element type="Text" style="EditorAttributeText">
+            <attribute name="Text" value="Slope bias" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="SlopeBiasEdit" />
+        </element>
+    </element>
+    <element>
+        <attribute name="Min Size" value="0 16" />
+        <attribute name="Max Size" value="2147483647 16" />
+        <attribute name="Layout Mode" value="Horizontal" />
+        <attribute name="Layout Spacing" value="8" />
+        <element type="Text" style="EditorAttributeText">
+            <attribute name="Text" value="Cull mode" />
+        </element>
+        <element type="DropDownList">
+            <attribute name="Name" value="CullModeEdit" />
+            <attribute name="Resize Popup" value="true" />
+            <!-- Skip style processing as the purpose of below tags is to populate the content element -->
+            <element type="Window" internal="true" popup="true" style="none">
+                <element type="ListView" internal="true" style="none">
+                    <element type="BorderImage" internal="true" style="none">
+                        <element internal="true" style="none">
+                            <element type="Text" style="FileSelectorFilterText">
+                                <attribute name="Text" value="None" />
+                            </element>
+                            <element type="Text" style="FileSelectorFilterText">
+                                <attribute name="Text" value="CCW" />
+                            </element>
+                            <element type="Text" style="FileSelectorFilterText">
+                                <attribute name="Text" value="CW" />
+                            </element>
+                        </element>
+                    </element>
+                </element>
+            </element>
+        </element>
+        <element type="Text" style="EditorAttributeText">
+            <attribute name="Text" value="Shadow cull" />
+        </element>
+        <element type="DropDownList">
+            <attribute name="Name" value="ShadowCullModeEdit" />
+            <attribute name="Resize Popup" value="true" />
+            <!-- Skip style processing as the purpose of below tags is to populate the content element -->
+            <element type="Window" internal="true" popup="true" style="none">
+                <element type="ListView" internal="true" style="none">
+                    <element type="BorderImage" internal="true" style="none">
+                        <element internal="true" style="none">
+                            <element type="Text" style="FileSelectorFilterText">
+                                <attribute name="Text" value="None" />
+                            </element>
+                            <element type="Text" style="FileSelectorFilterText">
+                                <attribute name="Text" value="CCW" />
+                            </element>
+                            <element type="Text" style="FileSelectorFilterText">
+                                <attribute name="Text" value="CW" />
+                            </element>
+                        </element>
+                    </element>
+                </element>
+            </element>
+        </element>
+    </element>
+    <element type="BorderImage" style="EditorDivider" />
     <element>
     <element>
         <attribute name="Name" value="ButtonContainer" />
         <attribute name="Name" value="ButtonContainer" />
         <attribute name="Min Size" value="0 16" />
         <attribute name="Min Size" value="0 16" />

+ 3 - 1
Engine/UI/UIElement.cpp

@@ -1514,7 +1514,9 @@ void UIElement::SortChildren()
 {
 {
     if (sortChildren_ && sortOrderDirty_)
     if (sortChildren_ && sortOrderDirty_)
     {
     {
-        Sort(children_.Begin(), children_.End(), CompareUIElements);
+        // Only sort when there is no layout
+        if (layoutMode_ == LM_FREE)
+            Sort(children_.Begin(), children_.End(), CompareUIElements);
         sortOrderDirty_ = false;
         sortOrderDirty_ = false;
     }
     }
 }
 }