Quellcode durchsuchen

Applied further UI and editor patch from weitjong. Text is now shown at full opacity in the editor, and the min/max opacity is also configurable.

Lasse Öörni vor 12 Jahren
Ursprung
Commit
1eda3844f0

+ 10 - 0
Bin/Data/Scripts/Editor.as

@@ -4,6 +4,7 @@
 #include "Scripts/Editor/EditorScene.as"
 #include "Scripts/Editor/EditorGizmo.as"
 #include "Scripts/Editor/EditorSettings.as"
+#include "Scripts/Editor/EditorPreferences.as"
 #include "Scripts/Editor/EditorUI.as"
 #include "Scripts/Editor/EditorImport.as"
 
@@ -133,6 +134,9 @@ void SaveConfig()
     XMLElement cameraElem = configElem.CreateChild("camera");
     XMLElement objectElem = configElem.CreateChild("object");
     XMLElement renderingElem = configElem.CreateChild("rendering");
+    XMLElement uiElem = configElem.CreateChild("ui");
+    XMLElement attributeInspector = configElem.CreateChild("attribute-inspector");
+    XMLElement textLabelColorElem = attributeInspector.CreateChild("text-label-color");
 
     cameraElem.SetFloat("nearclip", camera.nearClip);
     cameraElem.SetFloat("farclip", camera.farClip);
@@ -158,6 +162,12 @@ void SaveConfig()
     renderingElem.SetBool("specularlighting", renderer.specularLighting);
     renderingElem.SetBool("dynamicinstancing", graphics.sm3Support ? renderer.dynamicInstancing : instancingSetting);
     renderingElem.SetBool("framelimiter", engine.maxFps > 0);
+    
+    uiElem.SetFloat("min-opacity", uiMinOpacity);
+    uiElem.SetFloat("max-opacity", uiMaxOpacity);
+    
+    textLabelColorElem.SetColor("original-attribute", normalTextColor);
+    textLabelColorElem.SetColor("modified-attribute", modifiedTextColor);
 
     config.Save(File(configFileName, FILE_WRITE));
 }

+ 3 - 2
Bin/Data/Scripts/Editor/EditorNodeWindow.as

@@ -10,8 +10,9 @@ const int ATTR_HEIGHT = 19;
 const ShortStringHash textType("Text");
 const ShortStringHash containerType("UIElement");
 const StringHash textChangedEventType("TextChanged");
-const Color normalTextColor(1.0f, 1.0f, 1.0f);
-const Color modifiedTextColor(1.0f, 0.8f, 0.5f);
+
+Color normalTextColor(1.0f, 1.0f, 1.0f);
+Color modifiedTextColor(1.0f, 0.8f, 0.5f);
 
 class ResourcePicker
 {

+ 141 - 0
Bin/Data/Scripts/Editor/EditorPreferences.as

@@ -0,0 +1,141 @@
+// Urho3D editor preferences dialog
+
+bool subscribedToEditorPreferences = false;
+Window@ preferencesDialog;
+
+LineEdit@ originalAttributeTextColorEditR;
+LineEdit@ originalAttributeTextColorEditG;
+LineEdit@ originalAttributeTextColorEditB;
+LineEdit@ modifiedAttributeTextColorEditR;
+LineEdit@ modifiedAttributeTextColorEditG;
+LineEdit@ modifiedAttributeTextColorEditB;
+
+void CreateEditorPreferencesDialog()
+{
+    if (preferencesDialog !is null)
+        return;
+    
+    preferencesDialog = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorPreferencesDialog.xml"), uiStyle);
+    ui.root.AddChild(preferencesDialog);
+    CenterDialog(preferencesDialog);
+
+    originalAttributeTextColorEditR = preferencesDialog.GetChild("OriginalAttributeTextColor.r", true);
+    originalAttributeTextColorEditG = preferencesDialog.GetChild("OriginalAttributeTextColor.g", true);
+    originalAttributeTextColorEditB = preferencesDialog.GetChild("OriginalAttributeTextColor.b", true);
+    modifiedAttributeTextColorEditR = preferencesDialog.GetChild("ModifiedAttributeTextColor.r", true);
+    modifiedAttributeTextColorEditG = preferencesDialog.GetChild("ModifiedAttributeTextColor.g", true);
+    modifiedAttributeTextColorEditB = preferencesDialog.GetChild("ModifiedAttributeTextColor.b", true);
+
+    UpdateEditorPreferencesDialog();
+    HideEditorPreferencesDialog();
+}
+
+void UpdateEditorPreferencesDialog()
+{
+    if (preferencesDialog is null)
+        return;
+
+    LineEdit@ uiMinOpacityEdit = preferencesDialog.GetChild("UIMinOpacity", true);
+    uiMinOpacityEdit.text = String(uiMinOpacity);
+    
+    LineEdit@ uiMaxOpacityEdit = preferencesDialog.GetChild("UIMaxOpacity", true);
+    uiMaxOpacityEdit.text = String(uiMaxOpacity);
+    
+    originalAttributeTextColorEditR.text = String(normalTextColor.r);
+    originalAttributeTextColorEditG.text = String(normalTextColor.g);
+    originalAttributeTextColorEditB.text = String(normalTextColor.b);
+    
+    modifiedAttributeTextColorEditR.text = String(modifiedTextColor.r);
+    modifiedAttributeTextColorEditG.text = String(modifiedTextColor.g);
+    modifiedAttributeTextColorEditB.text = String(modifiedTextColor.b);
+    
+    if (!subscribedToEditorPreferences)
+    {
+        SubscribeToEvent(uiMinOpacityEdit, "TextChanged", "EditUIMinOpacity");
+        SubscribeToEvent(uiMinOpacityEdit, "TextFinished", "EditUIMinOpacity");
+        SubscribeToEvent(uiMaxOpacityEdit, "TextChanged", "EditUIMaxOpacity");
+        SubscribeToEvent(uiMaxOpacityEdit, "TextFinished", "EditUIMaxOpacity");
+        SubscribeToEvent(originalAttributeTextColorEditR, "TextChanged", "EditOriginalAttributeTextColor");
+        SubscribeToEvent(originalAttributeTextColorEditR, "TextFinished", "EditOriginalAttributeTextColor");
+        SubscribeToEvent(originalAttributeTextColorEditG, "TextChanged", "EditOriginalAttributeTextColor");
+        SubscribeToEvent(originalAttributeTextColorEditG, "TextFinished", "EditOriginalAttributeTextColor");
+        SubscribeToEvent(originalAttributeTextColorEditB, "TextChanged", "EditOriginalAttributeTextColor");
+        SubscribeToEvent(originalAttributeTextColorEditB, "TextFinished", "EditOriginalAttributeTextColor");
+        SubscribeToEvent(modifiedAttributeTextColorEditR, "TextChanged", "EditModifiedAttributeTextColor");
+        SubscribeToEvent(modifiedAttributeTextColorEditR, "TextFinished", "EditModifiedAttributeTextColor");
+        SubscribeToEvent(modifiedAttributeTextColorEditG, "TextChanged", "EditModifiedAttributeTextColor");
+        SubscribeToEvent(modifiedAttributeTextColorEditG, "TextFinished", "EditModifiedAttributeTextColor");
+        SubscribeToEvent(modifiedAttributeTextColorEditB, "TextChanged", "EditModifiedAttributeTextColor");
+        SubscribeToEvent(modifiedAttributeTextColorEditB, "TextFinished", "EditModifiedAttributeTextColor");
+        SubscribeToEvent(preferencesDialog.GetChild("CloseButton", true), "Released", "HideEditorPreferencesDialog");
+        subscribedToEditorPreferences = true;
+    }
+}
+
+void ShowEditorPreferencesDialog()
+{
+    UpdateEditorPreferencesDialog();
+    preferencesDialog.visible = true;
+    preferencesDialog.BringToFront();
+}
+
+void HideEditorPreferencesDialog()
+{
+    preferencesDialog.visible = false;
+}
+
+void EditUIMinOpacity(StringHash eventType, VariantMap& eventData)
+{
+    LineEdit@ edit = eventData["Element"].GetUIElement();
+    uiMinOpacity = edit.text.ToFloat();
+    if (eventType == StringHash("TextFinished"))
+    {
+        edit.text = String(uiMinOpacity);
+        HideUI();
+        UnhideUI();
+    }
+}
+
+void EditUIMaxOpacity(StringHash eventType, VariantMap& eventData)
+{
+    LineEdit@ edit = eventData["Element"].GetUIElement();
+    uiMaxOpacity = edit.text.ToFloat();
+    if (eventType == StringHash("TextFinished"))
+    {
+        edit.text = String(uiMaxOpacity);
+        HideUI();
+        UnhideUI();
+    }
+}
+
+void EditOriginalAttributeTextColor(StringHash eventType, VariantMap& eventData)
+{
+    LineEdit@ edit = eventData["Element"].GetUIElement();
+    normalTextColor = Color(originalAttributeTextColorEditR.text.ToFloat(), originalAttributeTextColorEditG.text.ToFloat(), originalAttributeTextColorEditB.text.ToFloat());
+    if (eventType == StringHash("TextFinished"))
+    {
+        if (edit.name == "OriginalAttributeTextColor.r")
+            edit.text = String(normalTextColor.r);
+        else if (edit.name == "OriginalAttributeTextColor.g")
+            edit.text = String(normalTextColor.g);
+        else if (edit.name == "OriginalAttributeTextColor.b")
+            edit.text = String(normalTextColor.b);
+        UpdateAttributes(false);
+    }
+}
+
+void EditModifiedAttributeTextColor(StringHash eventType, VariantMap& eventData)
+{
+    LineEdit@ edit = eventData["Element"].GetUIElement();
+    modifiedTextColor = Color(modifiedAttributeTextColorEditR.text.ToFloat(), modifiedAttributeTextColorEditG.text.ToFloat(), modifiedAttributeTextColorEditB.text.ToFloat());
+    if (eventType == StringHash("TextFinished"))
+    {
+        if (edit.name == "ModifiedAttributeTextColor.r")
+            edit.text = String(modifiedTextColor.r);
+        else if (edit.name == "ModifiedAttributeTextColor.g")
+            edit.text = String(modifiedTextColor.g);
+        else if (edit.name == "ModifiedAttributeTextColor.b")
+            edit.text = String(modifiedTextColor.b);
+        UpdateAttributes(false);
+    }
+}

+ 1 - 1
Bin/Data/Scripts/Editor/EditorSettings.as

@@ -1,6 +1,7 @@
 // Urho3D editor settings dialog
 
 bool subscribedToEditorSettings = false;
+Window@ settingsDialog;
 
 void CreateEditorSettingsDialog()
 {
@@ -9,7 +10,6 @@ void CreateEditorSettingsDialog()
     
     settingsDialog = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorSettingsDialog.xml"), uiStyle);
     ui.root.AddChild(settingsDialog);
-    settingsDialog.opacity = uiMaxOpacity;
     CenterDialog(settingsDialog);
     UpdateEditorSettingsDialog();
     HideEditorSettingsDialog();

+ 5 - 1
Bin/Data/Scripts/Editor/EditorUI.as

@@ -20,7 +20,7 @@ String uiScriptPath = fileSystem.programDir + "Data/Scripts";
 
 bool uiHidden = false;
 float uiMinOpacity = 0.3;
-float uiMaxOpacity = 1.0;
+float uiMaxOpacity = 0.7;
 
 void CreateUI()
 {
@@ -31,6 +31,7 @@ void CreateUI()
     CreateSceneWindow();
     CreateNodeWindow();
     CreateEditorSettingsDialog();
+    CreateEditorPreferencesDialog();
     CreateStatsBar();
     CreateConsole();
     CreateDebugHud();
@@ -166,6 +167,7 @@ void CreateMenuBar()
         filePopup.AddChild(CreateMenuItem("Scene hierarchy", 'H', QUAL_CTRL));
         filePopup.AddChild(CreateMenuItem("Node / component edit", 'N', QUAL_CTRL));
         filePopup.AddChild(CreateMenuItem("Editor settings", 0, 0));
+        filePopup.AddChild(CreateMenuItem("Editor preferences", 0, 0));
         uiMenuBar.AddChild(fileMenu);
     }
 
@@ -383,6 +385,8 @@ void HandleMenuSelected(StringHash eventType, VariantMap& eventData)
         ShowNodeWindow();
     else if (action == "Editor settings")
         ShowEditorSettingsDialog();
+    else if (action == "Editor preferences")
+        ShowEditorPreferencesDialog();
     else if (action == "Cut")
         SceneCut();
     else if (action == "Copy")

+ 0 - 1
Bin/Data/Scripts/Editor/EditorView.as

@@ -2,7 +2,6 @@
 
 Node@ cameraNode;
 Camera@ camera;
-Window@ settingsDialog;
 
 enum EditMode
 {

+ 121 - 0
Bin/Data/UI/EditorPreferencesDialog.xml

@@ -0,0 +1,121 @@
+<element type="Window">
+    <attribute name="Name" value="EditorPrefsDialog" />
+    <attribute name="Min Size" value="400 0" />
+    <attribute name="Max Size" value="400 2147483647" />
+    <attribute name="Is Movable" value="true" />
+    <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="0 16" />
+        <attribute name="Max Size" value="2147483647 16" />
+        <attribute name="Layout Mode" value="Horizontal" />
+        <element type="Text">
+            <attribute name="Text" value="Editor Preferences" />
+        </element>
+        <element type="Button" style="CloseButton">
+            <attribute name="Name" value="CloseButton" />
+        </element>
+    </element>
+    <element type="BorderImage" style="EditorDivider" />
+    <element>
+        <attribute name="Min Size" value="0 17" />
+        <attribute name="Max Size" value="2147483647 17" />
+        <element type="Text">
+            <attribute name="Text" value="User Interface" />
+        </element>
+    </element>
+    <element>
+        <attribute name="Min Size" value="0 17" />
+        <attribute name="Max Size" value="2147483647 17" />
+        <attribute name="Layout Mode" value="Horizontal" />
+        <attribute name="Layout Border" value="20 0 0 0" />
+        <element type="Text">
+            <attribute name="Text" value="Minimum opacity" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="UIMinOpacity" />
+            <attribute name="Min Size" value="50 0" />
+            <attribute name="Max Size" value="50 2147483647" />
+        </element>
+    </element>
+    <element>
+        <attribute name="Min Size" value="0 17" />
+        <attribute name="Max Size" value="2147483647 17" />
+        <attribute name="Layout Mode" value="Horizontal" />
+        <attribute name="Layout Border" value="20 0 0 0" />
+        <element type="Text">
+            <attribute name="Text" value="Maximum opacity" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="UIMaxOpacity" />
+            <attribute name="Min Size" value="50 0" />
+            <attribute name="Max Size" value="50 2147483647" />
+        </element>
+    </element>
+    <element type="BorderImage" style="EditorDivider" />
+    <element>
+        <attribute name="Min Size" value="0 17" />
+        <attribute name="Max Size" value="2147483647 17" />
+        <element type="Text">
+            <attribute name="Text" value="Attribute Inspector" />
+        </element>
+    </element>
+    <element>
+        <attribute name="Min Size" value="0 17" />
+        <attribute name="Max Size" value="2147483647 17" />
+        <attribute name="Layout Mode" value="Horizontal" />
+        <attribute name="Layout Border" value="20 0 0 0" />
+        <element type="Text">
+            <attribute name="Text" value="Text label color" />
+        </element>
+    </element>
+    <element>
+        <attribute name="Min Size" value="0 17" />
+        <attribute name="Max Size" value="2147483647 17" />
+        <attribute name="Layout Mode" value="Horizontal" />
+        <attribute name="Layout Border" value="40 0 0 0" />
+        <element type="Text">
+            <attribute name="Text" value="Original attribute" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="OriginalAttributeTextColor.r" />
+            <attribute name="Min Size" value="50 0" />
+            <attribute name="Max Size" value="50 2147483647" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="OriginalAttributeTextColor.g" />
+            <attribute name="Min Size" value="50 0" />
+            <attribute name="Max Size" value="50 2147483647" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="OriginalAttributeTextColor.b" />
+            <attribute name="Min Size" value="50 0" />
+            <attribute name="Max Size" value="50 2147483647" />
+        </element>
+    </element>
+    <element>
+        <attribute name="Min Size" value="0 17" />
+        <attribute name="Max Size" value="2147483647 17" />
+        <attribute name="Layout Mode" value="Horizontal" />
+        <attribute name="Layout Border" value="40 0 0 0" />
+        <element type="Text">
+            <attribute name="Text" value="Modified attribute" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="ModifiedAttributeTextColor.r" />
+            <attribute name="Min Size" value="50 0" />
+            <attribute name="Max Size" value="50 2147483647" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="ModifiedAttributeTextColor.g" />
+            <attribute name="Min Size" value="50 0" />
+            <attribute name="Max Size" value="50 2147483647" />
+        </element>
+        <element type="LineEdit">
+            <attribute name="Name" value="ModifiedAttributeTextColor.b" />
+            <attribute name="Min Size" value="50 0" />
+            <attribute name="Max Size" value="50 2147483647" />
+        </element>
+    </element>
+</element>

+ 0 - 1
Engine/Core/ProcessUtils.cpp

@@ -26,7 +26,6 @@
 #include "MathDefs.h"
 
 #include <cstdio>
-#include <cstdlib>
 #include <fcntl.h>
 
 #ifdef __APPLE__

+ 3 - 1
Engine/Core/ProcessUtils.h

@@ -24,6 +24,8 @@
 
 #include "Str.h"
 
+#include <cstdlib>
+
 namespace Urho3D
 {
 
@@ -34,7 +36,7 @@ void InitFPU();
 /// Display an error dialog with the specified title and message.
 void ErrorDialog(const String& title, const String& message);
 /// Exit the application with an error message to the console.
-void ErrorExit(const String& message, int exitCode = 1);
+void ErrorExit(const String& message, int exitCode = EXIT_FAILURE);
 /// Open a console window.
 void OpenConsoleWindow();
 /// Print Unicode text to the console. Will not be printed to the MSVC output window.

+ 4 - 4
Engine/IO/Log.h

@@ -69,7 +69,7 @@ public:
     void SetLevel(int level);
     /// Set whether to timestamp log messages.
     void SetTimeStamp(bool enable);
-    /// Set quiet mode ie. only log errors to standard output stream.
+    /// Set quiet mode ie. only print error entries to standard error stream (which is normally redirected to console also). Output to log file is not affected by this mode.
     void SetQuiet(bool quiet);
     
     /// Return logging level.
@@ -78,7 +78,7 @@ public:
     bool GetTimeStamp() const { return timeStamp_; }
     /// Return last log message.
     const String& GetLastMessage() const { return lastMessage_; }
-    /// Return whether log is in quiet mode (only errors printed to standard output.)
+    /// Return whether log is in quiet mode (only errors printed to standard error stream).
     bool IsQuiet() const { return quiet_; }
     
 private:
@@ -96,9 +96,9 @@ private:
     bool quiet_;
 };
 
-/// Write to the log (static.)
+/// Write to the log (static).
 void WriteToLog(Context* context, int level, const String& message);
-/// Write raw output to the log (static.)
+/// Write raw output to the log (static).
 void WriteToLogRaw(Context* context, const String& message);
 
 #ifdef ENABLE_LOGGING

+ 6 - 0
Engine/UI/Text.cpp

@@ -187,6 +187,12 @@ void Text::OnResize()
         UpdateText();
 }
 
+float Text::GetDerivedOpacity() const
+{
+    // Text should always use its own opacity.
+    return GetOpacity();
+}
+
 bool Text::SetFont(const String& fontName, int size)
 {
     ResourceCache* cache = GetSubsystem<ResourceCache>();

+ 3 - 0
Engine/UI/Text.h

@@ -51,6 +51,9 @@ public:
     /// React to resize.
     virtual void OnResize();
     
+    /// Return derived opacity (affected by parent elements.)
+    virtual float GetDerivedOpacity() const;
+
     /// Set font and font size.
     bool SetFont(const String& fontName, int size = DEFAULT_FONT_SIZE);
     /// Set font and font size.

+ 1 - 1
Engine/UI/UIElement.h

@@ -309,7 +309,7 @@ public:
     /// Return opacity.
     float GetOpacity() const { return opacity_; }
     /// Return derived opacity (affected by parent elements.)
-    float GetDerivedOpacity() const;
+    virtual float GetDerivedOpacity() const;
     /// Return whether should be brought to front when focused.
     bool GetBringToFront() const { return bringToFront_; }
     /// Return whether should be put to background when another element is focused.

+ 0 - 1
Tools/PackageTool/PackageTool.cpp

@@ -31,7 +31,6 @@
 #endif
 
 #include <cstdio>
-#include <cstdlib>
 #include <cstring>
 
 #include "DebugNew.h"

+ 4 - 2
Tools/ScriptAPIDumper/ScriptAPIDumper.cpp

@@ -23,10 +23,12 @@
 #include "Context.h"
 #include "Engine.h"
 #include "Log.h"
-#include "Main.h"
 #include "ProcessUtils.h"
 #include "Script.h"
-#include "ScriptAPI.h"
+
+#ifdef WIN32
+#include <windows.h>
+#endif
 
 #include "DebugNew.h"