Browse Source

Safeguard against the editor's user resource directory containing outdated Urho editor UI layouts, which can lead to exceptions in the editor. Note: some UI resources like fonts and textures may still be overridden by the user resource directory.

Lasse Öörni 11 years ago
parent
commit
65bec05611

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

@@ -56,7 +56,7 @@ void CreateHierarchyWindow()
     if (hierarchyWindow !is null)
         return;
 
-    hierarchyWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorHierarchyWindow.xml"));
+    hierarchyWindow = LoadEditorUI("UI/EditorHierarchyWindow.xml");
     hierarchyList = hierarchyWindow.GetChild("HierarchyList");
     ui.root.AddChild(hierarchyWindow);
     int height = Min(ui.root.height - 60, 460);

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

@@ -118,7 +118,7 @@ void CreateAttributeInspectorWindow()
     InitVectorStructs();
     InitXMLResources();
 
-    attributeInspectorWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorInspectorWindow.xml"));
+    attributeInspectorWindow = LoadEditorUI("UI/EditorInspectorWindow.xml");
     parentContainer = attributeInspectorWindow.GetChild("ParentContainer");
     ui.root.AddChild(attributeInspectorWindow);
     int height = Min(ui.root.height - 60, 500);

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

@@ -17,7 +17,7 @@ void CreateMaterialEditor()
     if (materialWindow !is null)
         return;
 
-    materialWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorMaterialWindow.xml"));
+    materialWindow = LoadEditorUI("UI/EditorMaterialWindow.xml");
     ui.root.AddChild(materialWindow);
     materialWindow.opacity = uiMaxOpacity;
 

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

@@ -18,7 +18,7 @@ void CreateParticleEffectEditor()
     if (particleEffectWindow !is null)
         return;
 
-    particleEffectWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorParticleEffectWindow.xml"));
+    particleEffectWindow = LoadEditorUI("UI/EditorParticleEffectWindow.xml");
     ui.root.AddChild(particleEffectWindow);
     particleEffectWindow.opacity = uiMaxOpacity;
 

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

@@ -39,7 +39,7 @@ void CreateEditorPreferencesDialog()
     if (preferencesDialog !is null)
         return;
 
-    preferencesDialog = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorPreferencesDialog.xml"));
+    preferencesDialog = LoadEditorUI("UI/EditorPreferencesDialog.xml");
     ui.root.AddChild(preferencesDialog);
     preferencesDialog.opacity = uiMaxOpacity;
     preferencesDialog.height = 440;

+ 2 - 2
Bin/Data/Scripts/Editor/EditorResourceBrowser.as

@@ -192,7 +192,7 @@ void DoResourceBrowserWork()
 
 void CreateResourceBrowserUI()
 {
-    browserWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorResourceBrowser.xml"));
+    browserWindow = LoadEditorUI("UI/EditorResourceBrowser.xml");
     browserDirList = browserWindow.GetChild("DirectoryList", true);
     browserFileList = browserWindow.GetChild("FileList", true);
     browserSearch = browserWindow.GetChild("Search", true);
@@ -201,7 +201,7 @@ void CreateResourceBrowserUI()
     // browserWindow.visible = false;
     browserWindow.opacity = uiMaxOpacity;
 
-    browserFilterWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorResourceFilterWindow.xml"));
+    browserFilterWindow = LoadEditorUI("UI/EditorResourceFilterWindow.xml");
     CreateResourceFilterUI();
     HideResourceFilterWindow();
 

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

@@ -8,7 +8,7 @@ void CreateEditorSettingsDialog()
     if (settingsDialog !is null)
         return;
     
-    settingsDialog = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorSettingsDialog.xml"));
+    settingsDialog = LoadEditorUI("UI/EditorSettingsDialog.xml");
     ui.root.AddChild(settingsDialog);
     settingsDialog.opacity = uiMaxOpacity;
     settingsDialog.height = 440;

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

@@ -26,7 +26,7 @@ void CreateSpawnEditor()
     if (spawnWindow !is null)
         return;
 
-    spawnWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorSpawnWindow.xml"));
+    spawnWindow = LoadEditorUI("UI/EditorSpawnWindow.xml");
     ui.root.AddChild(spawnWindow);
     spawnWindow.opacity = uiMaxOpacity;
 

+ 30 - 4
Bin/Data/Scripts/Editor/EditorUI.as

@@ -60,9 +60,9 @@ void CreateUI()
     /// \todo The console will not be properly recreated as it has already been created once
     ui.root.RemoveAllChildren();
 
-    uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
+    uiStyle = GetEditorUIXMLFile("UI/DefaultStyle.xml");
     ui.root.defaultStyle = uiStyle;
-    iconStyle = cache.GetResource("XMLFile", "UI/EditorIcons.xml");
+    iconStyle = GetEditorUIXMLFile("UI/EditorIcons.xml");
 
     CreateCursor();
     CreateMenuBar();
@@ -240,7 +240,7 @@ void CreateQuickMenu()
     if (quickMenu !is null)
         return;
 
-    quickMenu = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorQuickMenu.xml"));
+    quickMenu = LoadEditorUI("UI/EditorQuickMenu.xml");
     quickMenu.enabled = false;
     quickMenu.visible = false;
     quickMenu.opacity = uiMaxOpacity;
@@ -929,7 +929,7 @@ void CenterDialog(UIElement@ element)
 
 void CreateContextMenu()
 {
-    contextMenu = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorContextMenu.xml"));
+    contextMenu = LoadEditorUI("UI/EditorContextMenu.xml");
     ui.root.AddChild(contextMenu);
 }
 
@@ -1443,3 +1443,29 @@ void ContextMenuEventWrapper(StringHash eventType, VariantMap& eventData)
     }
     CloseContextMenu();
 }
+
+/// Load a UI XML file used by the editor
+XMLFile@ GetEditorUIXMLFile(const String&in fileName)
+{
+    // Prefer the executable path to avoid using the user's resource path, which may point
+    // to an outdated Urho installation
+    String fullFileName = fileSystem.programDir + "Data/" + fileName;
+    if (fileSystem.FileExists(fullFileName))
+    {
+        File@ file = File(fullFileName, FILE_READ);
+        XMLFile@ xml = XMLFile();
+        xml.name = fileName;
+        if (xml.Load(file))
+            return xml;
+    }
+
+    // Fallback to resource system
+    return cache.GetResource("XMLFile", fileName);
+}
+
+
+/// Load an UI layout used by the editor
+UIElement@ LoadEditorUI(const String&in fileName)
+{
+    return ui.LoadLayout(GetEditorUIXMLFile(fileName));
+}

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

@@ -153,7 +153,7 @@ class ViewportContext
         cameraPosText.textEffect = TE_SHADOW;
         cameraPosText.priority = -100;
 
-        settingsWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorViewport.xml"));
+        settingsWindow = LoadEditorUI("UI/EditorViewport.xml");
         settingsWindow.opacity = uiMaxOpacity;
         settingsWindow.visible = false;
         viewportContextUI.AddChild(settingsWindow);