2
0
Эх сурвалжийг харах

Save/load editor settings.
Support for stop() function in the Urho3D Shell. This will be run at application exit.

Lasse Öörni 14 жил өмнө
parent
commit
480e0a07c1

+ 73 - 2
Bin/CoreData/Scripts/Editor.as

@@ -5,6 +5,8 @@
 #include "Scripts/EditorUI.as"
 #include "Scripts/EditorImport.as"
 
+string configFileName;
+
 void start()
 {
     if (engine.isHeadless())
@@ -13,7 +15,9 @@ void start()
         engine.exit();
         return;
     }
-    
+
+    configFileName = getUserDocumentsDirectory() + "Urho3D/Editor/Config.xml";
+
     // Free the mouse cursor
     input.setClipCursor(false);
 
@@ -24,9 +28,15 @@ void start()
 
     createScene();
     createUI();
+    loadConfig();
     parseArguments();
 }
 
+void stop()
+{
+    saveConfig();
+}
+
 void parseArguments()
 {
     array<string> arguments = getArguments();
@@ -48,7 +58,68 @@ void handleUpdate(StringHash eventType, VariantMap& eventData)
 
     moveCamera(timeStep);
     updateStats(timeStep);
-    
+
     if (runPhysics)
         editorScene.getPhysicsWorld().update(timeStep);
 }
+
+void loadConfig()
+{
+    if (!fileExists(configFileName))
+        return;
+
+    XMLFile config;
+    config.load(File(configFileName, FILE_READ));
+
+    XMLElement configElem = config.getRootElement("configuration");
+    if (configElem.isNull())
+        return;
+
+    XMLElement cameraElem = configElem.getChildElement("camera");
+    XMLElement objectElem = configElem.getChildElement("object");
+    if ((cameraElem.isNull()) || (objectElem.isNull()))
+        return;
+
+    camera.setNearClip(cameraElem.getFloat("nearclip"));
+    camera.setFarClip(cameraElem.getFloat("farclip"));
+    camera.setFov(cameraElem.getFloat("fov"));
+    cameraBaseSpeed = cameraElem.getFloat("speed");
+
+    newNodeDistance = objectElem.getFloat("newnodedistance");
+    moveStep = objectElem.getFloat("movestep");
+    rotateStep = objectElem.getFloat("rotatestep");
+    scaleStep = objectElem.getFloat("scalestep");
+    moveSnap = objectElem.getBool("movesnap");
+    rotateSnap = objectElem.getBool("rotatesnap");
+    scaleSnap = objectElem.getBool("scalesnap");
+    useLocalIDs = objectElem.getBool("uselocalids");
+}
+
+void saveConfig()
+{
+    if (configFileName.empty())
+        return;
+
+    createDirectory(getUserDocumentsDirectory() + "Urho3D/Editor");
+
+    XMLFile config;
+    XMLElement configElem = config.createRootElement("configuration");
+    XMLElement cameraElem = configElem.createChildElement("camera");
+    XMLElement objectElem = configElem.createChildElement("object");
+
+    cameraElem.setFloat("nearclip", camera.getNearClip());
+    cameraElem.setFloat("farclip", camera.getFarClip());
+    cameraElem.setFloat("fov", camera.getFov());
+    cameraElem.setFloat("speed", cameraBaseSpeed);
+
+    objectElem.setFloat("newnodedistance", newNodeDistance);
+    objectElem.setFloat("movestep", moveStep);
+    objectElem.setFloat("rotatestep", rotateStep);
+    objectElem.setFloat("scalestep", scaleStep);
+    objectElem.setBool("movesnap", moveSnap);
+    objectElem.setBool("rotatesnap", rotateSnap);
+    objectElem.setBool("scalesnap", scaleSnap);
+    objectElem.setBool("uselocalids", useLocalIDs);
+
+    config.save(File(configFileName, FILE_WRITE));
+}

+ 5 - 1
Bin/CoreData/Scripts/EditorCamera.as

@@ -15,7 +15,6 @@ float cameraBaseRotationSpeed = 0.2;
 float cameraShiftSpeedMultiplier = 5;
 float cameraYaw = 0;
 float cameraPitch = 0;
-
 float newNodeDistance = 20;
 float moveStep = 0.5;
 float rotateStep = 5;
@@ -513,3 +512,8 @@ void steppedObjectManipulation(int key)
 
     updateComponentAttributes();
 }
+
+Vector3 getNewNodePosition()
+{
+    return camera.getWorldPosition() + camera.getWorldRotation() * Vector3(0, 0, newNodeDistance);
+}

+ 1 - 1
Bin/CoreData/Scripts/EditorImport.as

@@ -19,7 +19,7 @@ void importModel(const string& in fileName)
     {
         Entity@ newEntity = editorScene.createEntity(getFileName(fileName));
         StaticModel@ newModel = newEntity.createComponent("StaticModel");
-        newModel.setPosition(camera.getWorldPosition() + camera.getWorldRotation() * Vector3(0, 0, newNodeDistance));
+        newModel.setPosition(getNewNodePosition());
         newModel.setModel(cache.getResource("Model", modelName));
 
         if (fileExists(materialListName))

+ 6 - 1
Bin/CoreData/Scripts/EditorSceneWindow.as

@@ -580,7 +580,12 @@ void handleCreateComponent(StringHash eventType, VariantMap& eventData)
     if (text is null)
         return;
 
-    selectedEntity.createComponent(text.getText(), "");
+    Component@ newComponent = selectedEntity.createComponent(text.getText(), "");
+    // If component is a scene node, set it to a certain distance from camera
+    Node@ newNode = cast<Node>(newComponent);
+    if (newNode !is null)
+        newNode.setPosition(getNewNodePosition());
+
     updateSceneWindowEntity(selectedEntity);
 }
 

+ 7 - 3
Editor.txt

@@ -40,17 +40,21 @@ window without changing the object selection.
 Workflow
 --------
 
-When you start with an empty scene, set the resource path first (File -> Set 
-resource path). This is the base directory, under which the subdirectories 
+When you start with an empty scene, set the resource path first (File -> Set
+resource path). This is the base directory, under which the subdirectories
 Models, Materials & Textures will be created as you import assets.
 
 Scenes should be saved either into this base directory, or into its immediate
 subdirectory, named for example Scenes or Levels. When loading a scene, the
 resource path will be set automatically.
 
-Check the Global scene settings & Camera settings so that they match the
+Check the Global scene settings & Editor settings so that they match the
 size of the objects you are using.
 
+The editor settings will be saved on exit to a file Urho3D/Editor/Config.xml 
+in the My Documents directory. Delete this file if you want to revert the 
+settings to defaults.
+
 
 Editing
 -------

+ 8 - 0
Examples/Urho3D/Application.cpp

@@ -111,4 +111,12 @@ void Application::run()
     // Run until exited
     while (!mEngine->isExiting())
         mEngine->runFrame();
+    
+    // Run the "stop" function from script if it has any
+    if (mScriptFile)
+    {
+        asIScriptFunction* stop = mScriptFile->getFunction("void stop()");
+        if (stop)
+            mScriptFile->execute(stop);
+    }
 }