Browse Source

Editor viewport camera settings

Chris Friesen 11 years ago
parent
commit
b39eeb7cf7

+ 135 - 2
Bin/Data/Scripts/Editor/EditorView.as

@@ -81,6 +81,17 @@ class ViewportContext
     UIElement@ statusBar;
     Text@ cameraPosText;
 
+    Window@ settingsWindow;
+    LineEdit@ cameraPosX;
+    LineEdit@ cameraPosY;
+    LineEdit@ cameraPosZ;
+    LineEdit@ cameraRotX;
+    LineEdit@ cameraRotY;
+    LineEdit@ cameraRotZ;
+    LineEdit@ cameraZoom;
+    LineEdit@ cameraOrthoSize;
+    CheckBox@ cameraOrthographic;
+
     ViewportContext(IntRect viewRect, uint index_, uint viewportId_)
     {
         cameraNode = Node();
@@ -99,6 +110,7 @@ class ViewportContext
         // Look at the origin so user can see the scene.
         cameraNode.rotation = Quaternion(Vector3(0, 0, 1), -cameraNode.position);
         ReacquireCameraYawPitch();
+        UpdateSettingsUI();
     }
 
     void ReacquireCameraYawPitch()
@@ -126,6 +138,9 @@ class ViewportContext
         statusBar.layoutSpacing = 4;
         statusBar.opacity = uiMaxOpacity;
 
+        Button@ settingsButton = CreateSmallToolBarButton("Settings");
+        statusBar.AddChild(settingsButton);
+
         cameraPosText = Text();
         statusBar.AddChild(cameraPosText);
         
@@ -134,6 +149,35 @@ class ViewportContext
         cameraPosText.textEffect = TE_SHADOW;
         cameraPosText.priority = -100;
 
+        settingsWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorViewport.xml"));
+        settingsWindow.opacity = uiMaxOpacity;
+        settingsWindow.visible = false;
+        viewportContextUI.AddChild(settingsWindow);
+
+        cameraPosX = settingsWindow.GetChild("PositionX", true);
+        cameraPosY = settingsWindow.GetChild("PositionY", true);
+        cameraPosZ = settingsWindow.GetChild("PositionZ", true);
+        cameraRotX = settingsWindow.GetChild("RotationX", true);
+        cameraRotY = settingsWindow.GetChild("RotationY", true);
+        cameraRotZ = settingsWindow.GetChild("RotationZ", true);
+        cameraOrthographic = settingsWindow.GetChild("Orthographic", true);
+        cameraZoom = settingsWindow.GetChild("Zoom", true);
+        cameraOrthoSize = settingsWindow.GetChild("OrthoSize", true);
+
+        SubscribeToEvent(cameraPosX, "TextChanged", "HandleSettingsLineEditTextChange");
+        SubscribeToEvent(cameraPosY, "TextChanged", "HandleSettingsLineEditTextChange");
+        SubscribeToEvent(cameraPosZ, "TextChanged", "HandleSettingsLineEditTextChange");
+        SubscribeToEvent(cameraRotX, "TextChanged", "HandleSettingsLineEditTextChange");
+        SubscribeToEvent(cameraRotY, "TextChanged", "HandleSettingsLineEditTextChange");
+        SubscribeToEvent(cameraRotZ, "TextChanged", "HandleSettingsLineEditTextChange");
+        SubscribeToEvent(cameraZoom, "TextChanged", "HandleSettingsLineEditTextChange");
+        SubscribeToEvent(cameraOrthoSize, "TextChanged", "HandleSettingsLineEditTextChange");
+        SubscribeToEvent(cameraOrthographic, "Toggled", "HandleOrthographicToggled");
+
+        SubscribeToEvent(settingsButton, "Released", "ToggleViewportSettingsWindow");
+        SubscribeToEvent(settingsWindow.GetChild("ResetCamera", true), "Released", "ResetCamera");
+        SubscribeToEvent(settingsWindow.GetChild("CloseButton", true), "Released", "CloseViewportSettingsWindow");
+        SubscribeToEvent(settingsWindow.GetChild("Refresh", true), "Released", "UpdateSettingsUI");
         HandleResize();
     }
 
@@ -142,9 +186,19 @@ class ViewportContext
         viewportContextUI.SetPosition(viewport.rect.left, viewport.rect.top);
         viewportContextUI.SetFixedSize(viewport.rect.width, viewport.rect.height);
         if (viewport.rect.left < 34)
+        {
             statusBar.layoutBorder = IntRect(34 - viewport.rect.left, 4, 4, 8);
+            IntVector2 pos = settingsWindow.position;
+            pos.x = 32 - viewport.rect.left;
+            settingsWindow.position = pos;
+        }
         else
+        {
             statusBar.layoutBorder = IntRect(8, 4, 4, 8);
+            IntVector2 pos = settingsWindow.position;
+            pos.x = 5;
+            settingsWindow.position = pos;
+        }
 
         statusBar.SetFixedSize(viewport.rect.width, 22);
     }
@@ -156,10 +210,12 @@ class ViewportContext
     
     void SetOrthographic(bool orthographic)
     {
-        if (orthographic)
-            camera.orthoSize = (cameraNode.position - GetScreenCollision(IntVector2(viewport.rect.width, viewport.rect.height))).length;
+        // This doesn't work that great
+        /* if (orthographic) */
+        /*     camera.orthoSize = (cameraNode.position - GetScreenCollision(IntVector2(viewport.rect.width, viewport.rect.height))).length; */
 
         camera.orthographic = orthographic;
+        UpdateSettingsUI();
     }
 
     void Update(float timeStep)
@@ -178,6 +234,83 @@ class ViewportContext
 
         cameraPosText.size = cameraPosText.minSize;
     }
+
+    void ToggleViewportSettingsWindow()
+    {
+        if (settingsWindow.visible)
+            CloseViewportSettingsWindow();
+        else
+            OpenViewportSettingsWindow();
+    }
+
+    void OpenViewportSettingsWindow()
+    {
+        UpdateSettingsUI();
+        /* settingsWindow.position = */ 
+        settingsWindow.visible = true;
+    }
+
+    void CloseViewportSettingsWindow()
+    {
+        settingsWindow.visible = false;
+    }
+
+    void UpdateSettingsUI()
+    {
+        cameraPosX.text = Floor(cameraNode.position.x * 1000) / 1000;
+        cameraPosY.text = Floor(cameraNode.position.y * 1000) / 1000;
+        cameraPosZ.text = Floor(cameraNode.position.z * 1000) / 1000;
+        cameraRotX.text = Floor(cameraNode.rotation.pitch * 1000) / 1000;
+        cameraRotY.text = Floor(cameraNode.rotation.yaw * 1000) / 1000;
+        cameraRotZ.text = Floor(cameraNode.rotation.roll * 1000) / 1000;
+        cameraZoom.text = Floor(camera.zoom * 1000) / 1000;
+        cameraOrthoSize.text = Floor(camera.orthoSize * 1000) / 1000;
+        cameraOrthographic.checked = camera.orthographic;
+    }
+
+    void HandleOrthographicToggled(StringHash eventType, VariantMap& eventData)
+    {
+        SetOrthographic(cameraOrthographic.checked);
+    }
+
+    void HandleSettingsLineEditTextChange(StringHash eventType, VariantMap& eventData)
+    {
+        LineEdit@ element = eventData["Element"].GetPtr();
+        if (element.text == "")
+            return;
+
+        if (element is cameraRotX ||  element is cameraRotY || element is cameraRotZ)
+        {
+            Vector3 euler = cameraNode.rotation.eulerAngles;
+            if (element is cameraRotX)
+                euler.x = element.text.ToFloat();
+            else if (element is cameraRotY)
+                euler.y = element.text.ToFloat();
+            else if (element is cameraRotZ)
+                euler.z = element.text.ToFloat();
+
+            cameraNode.rotation = Quaternion(euler);
+        }
+        else if (element is cameraPosX ||  element is cameraPosY || element is cameraPosZ)
+        {
+            Vector3 pos = cameraNode.position;
+            if (element is cameraPosX)
+                pos.x = element.text.ToFloat();
+            else if (element is cameraPosY)
+                pos.y = element.text.ToFloat();
+            else if (element is cameraPosZ)
+                pos.z = element.text.ToFloat();
+
+            cameraNode.position = pos;
+        }
+        else if (element is cameraZoom)
+            camera.zoom = element.text.ToFloat();
+        else if (element is cameraOrthoSize)
+        {
+            Print(element.text);
+            camera.orthoSize = element.text.ToFloat();
+        }
+    }
 }
 
 Array<ViewportContext@> viewports;

BIN
Bin/Data/Textures/EditorIcons.png


+ 4 - 0
Bin/Data/UI/EditorIcons.xml

@@ -295,4 +295,8 @@
         <attribute name="Texture" value="Texture2D;Textures/EditorIcons.png" />
         <attribute name="Image Rect" value="128 160 158 190" />
     </element>
+    <element type="Settings">
+        <attribute name="Texture" value="Texture2D;Textures/EditorIcons.png" />
+        <attribute name="Image Rect" value="112 16 126 30" />
+    </element>
 </elements>

+ 273 - 0
Bin/Data/UI/EditorViewport.xml

@@ -0,0 +1,273 @@
+<?xml version="1.0"?>
+<element type="Window">
+	<attribute name="Position" value="30 -25" />
+	<attribute name="Size" value="300 152" />
+	<attribute name="Vert Alignment" value="Bottom" />
+	<attribute name="Layout Mode" value="Vertical" />
+	<attribute name="Layout Spacing" value="4" />
+	<attribute name="Layout Border" value="6 6 6 6" />
+	<element>
+		<attribute name="Min Size" value="168 16" />
+		<attribute name="Max Size" value="2147483647 16" />
+		<attribute name="Layout Mode" value="Horizontal" />
+		<element type="Text">
+			<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="Viewport Properties" />
+		</element>
+		<element type="Button">
+			<attribute name="Name" value="Refresh" />
+			<attribute name="Min Size" value="16 16" />
+			<attribute name="Max Size" value="16 16" />
+			<attribute name="Layout Mode" value="Horizontal" />
+			<element type="BorderImage">
+				<attribute name="Texture" value="Texture2D;Textures/UI.png" />
+				<attribute name="Image Rect" value="128 32 144 48" />
+			</element>
+		</element>
+		<element type="Button" style="CloseButton">
+			<attribute name="Name" value="CloseButton" />
+		</element>
+	</element>
+	<element type="BorderImage" style="EditorDivider" />
+	<element>
+		<attribute name="Name" value="CameraPosition" />
+		<attribute name="Layout Mode" value="Horizontal" />
+		<element type="Text" style="EditorAttributeText">
+			<attribute name="Name" value="Label" />
+			<attribute name="Min Size" value="80 14" />
+			<attribute name="Max Size" value="80 14" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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="Position" />
+		</element>
+		<element type="LineEdit" style="EditorAttributeEdit">
+			<attribute name="Name" value="PositionX" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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" />
+			<element type="Text" internal="true" style="none">
+				<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+			</element>
+			<element type="BorderImage" internal="true" style="none">
+				<attribute name="Size" value="4 15" />
+			</element>
+		</element>
+		<element type="LineEdit" style="EditorAttributeEdit">
+			<attribute name="Name" value="PositionY" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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" />
+			<element type="Text" internal="true" style="none">
+				<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+			</element>
+			<element type="BorderImage" internal="true" style="none">
+				<attribute name="Size" value="4 15" />
+			</element>
+		</element>
+		<element type="LineEdit" style="EditorAttributeEdit">
+			<attribute name="Name" value="PositionZ" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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" />
+			<element type="Text" internal="true" style="none">
+				<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+			</element>
+			<element type="BorderImage" internal="true" style="none">
+				<attribute name="Size" value="4 15" />
+			</element>
+		</element>
+	</element>
+	<element>
+		<attribute name="Name" value="CameraRotation" />
+		<attribute name="Layout Mode" value="Horizontal" />
+		<element type="Text" style="EditorAttributeText">
+			<attribute name="Name" value="Label" />
+			<attribute name="Min Size" value="80 14" />
+			<attribute name="Max Size" value="80 14" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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="Rotation" />
+		</element>
+		<element type="LineEdit" style="EditorAttributeEdit">
+			<attribute name="Name" value="RotationX" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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" />
+			<element type="Text" internal="true" style="none">
+				<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+			</element>
+			<element type="BorderImage" internal="true" style="none">
+				<attribute name="Size" value="4 15" />
+			</element>
+		</element>
+		<element type="LineEdit" style="EditorAttributeEdit">
+			<attribute name="Name" value="RotationY" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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" />
+			<element type="Text" internal="true" style="none">
+				<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+			</element>
+			<element type="BorderImage" internal="true" style="none">
+				<attribute name="Size" value="4 15" />
+			</element>
+		</element>
+		<element type="LineEdit" style="EditorAttributeEdit">
+			<attribute name="Name" value="RotationZ" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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" />
+			<element type="Text" internal="true" style="none">
+				<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+			</element>
+			<element type="BorderImage" internal="true" style="none">
+				<attribute name="Size" value="4 15" />
+			</element>
+		</element>
+	</element>
+	<element>
+		<attribute name="Name" value="CameraZoom" />
+		<attribute name="Layout Mode" value="Horizontal" />
+		<element type="Text" style="EditorAttributeText">
+			<attribute name="Name" value="Label" />
+			<attribute name="Min Size" value="80 14" />
+			<attribute name="Max Size" value="80 14" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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="Zoom" />
+		</element>
+		<element type="LineEdit" style="EditorAttributeEdit">
+			<attribute name="Name" value="Zoom" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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" />
+			<element type="Text" internal="true" style="none">
+				<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+			</element>
+			<element type="BorderImage" internal="true" style="none">
+				<attribute name="Size" value="4 15" />
+			</element>
+		</element>
+	</element>
+	<element>
+		<attribute name="Name" value="CameraOrthographic" />
+		<attribute name="Layout Mode" value="Horizontal" />
+		<element type="Text" style="EditorAttributeText">
+			<attribute name="Name" value="Label" />
+			<attribute name="Min Size" value="80 14" />
+			<attribute name="Max Size" value="80 14" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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="Orthographic" />
+		</element>
+		<element type="CheckBox">
+			<attribute name="Name" value="Orthographic" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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" />
+		</element>
+	</element>
+	<element>
+		<attribute name="Name" value="CameraOrthoSize" />
+		<attribute name="Layout Mode" value="Horizontal" />
+		<element type="Text" style="EditorAttributeText">
+			<attribute name="Name" value="Label" />
+			<attribute name="Min Size" value="80 14" />
+			<attribute name="Max Size" value="80 14" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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="Ortho Size" />
+		</element>
+		<element type="LineEdit" style="EditorAttributeEdit">
+			<attribute name="Name" value="OrthoSize" />
+			<attribute name="Color" value="0.85 0.85 0.85 1" />
+			<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" />
+			<element type="Text" internal="true" style="none">
+				<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+				<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+			</element>
+			<element type="BorderImage" internal="true" style="none">
+				<attribute name="Size" value="4 15" />
+			</element>
+		</element>
+	</element>
+	<element type="BorderImage" style="EditorDivider" />
+	<element>
+		<attribute name="Layout Mode" value="Horizontal" />
+		<element type="Button">
+			<attribute name="Name" value="ResetCamera" />
+			<attribute name="Min Size" value="110 16" />
+			<attribute name="Max Size" value="0 16" />
+			<element type="Text">
+				<attribute name="Horiz Alignment" value="Center" />
+				<attribute name="Vert Alignment" value="Center" />
+				<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="Reset Camera" />
+				<attribute name="Text Alignment" value="Center" />
+			</element>
+		</element>
+	</element>
+</element>