Exemplo n.º 1
0
        /// <summary>
        /// Loads the appropriate paths stored in the <see cref="ProjectConfig"/> instance into each of the editors.
        /// </summary>
        public static void ApplyInstance(MainForm.MainForm mainForm, ProjectConfig config)
        {
            mainForm.ClearConfig();

            ExecuteIfFilePresent($"Config Editor error: file not found: {config.StageConfigPath}", "Error", config.StageConfigPath, path => mainForm.ConfigEditor.OpenFile(path, mainForm));

            if (config.IsShadow)
            {
                if (Directory.Exists(config.LevelEditorPath))
                {
                    mainForm.LevelEditor.OpenONEShadowFolder(config.LevelEditorPath, true);
                }
                else if (!string.IsNullOrEmpty(config.LevelEditorPath))
                {
                    MessageBox.Show($"Level Editor error: file not found: {config.LevelEditorPath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                ExecuteIfFilePresent($"Level Editor error: file not found: {config.LevelEditorPath}", "Error", config.LevelEditorPath, path => mainForm.LevelEditor.OpenONEHeroesFile(path, mainForm.renderer));
                ExecuteIfFilePresent($"Visibility Editor error: file not found: {config.VisibilityPath}", "Error", config.VisibilityPath, path => mainForm.LevelEditor.initVisibilityEditor(false, path));
            }

            if (config.CollisionEditorPaths != null)
            {
                foreach (var v in config.CollisionEditorPaths)
                {
                    ExecuteIfFilePresent($"Collision Editor error: file not found: {v}", "Error", v, path => mainForm.AddCollisionEditor(path));
                }
            }
            if (config.LayoutEditorPaths != null)
            {
                foreach (var v in config.LayoutEditorPaths)
                {
                    ExecuteIfFilePresent($"Layout Editor error: file not found: {v}", "Error", v, path => mainForm.AddLayoutEditor(path));
                }
            }

            ExecuteIfFilePresent($"Camera Editor error: file not found: {config.CameraEditorPath}", "Error", config.CameraEditorPath, path => mainForm.CameraEditor.OpenFile(path));
            ExecuteIfFilePresent($"Particle Editor error: file not found: {config.ParticleEditorPath}", "Error", config.ParticleEditorPath, path => mainForm.ParticleEditor.OpenFile(path));
            ExecuteIfFilePresent($"Texture Pattern Editor error: file not found: {config.TexturePatternEditorPath}", "Error", config.TexturePatternEditorPath, path => mainForm.TexturePatternEditor.OpenFile(path));
            ExecuteIfFilePresent($"Light Editor error: file not found: {config.LightEditorPath}", "Error", config.LightEditorPath, path => mainForm.LightEditor.OpenFile(path, config.LightEditorIsShadow));
            ExecuteIfFilePresent($"SET ID Table Editor error: file not found: {config.SetIdTableEditorPath}", "Error", config.SetIdTableEditorPath, path => mainForm.SetIdTableEditor.OpenExternal(path, config.SetIdTableEditorIsShadow));

            if (config.CameraSettings != null)
            {
                mainForm.renderer.Camera.ApplyConfig(config.CameraSettings);
            }

            TextureManager.ClearTextures(mainForm.renderer, mainForm.LevelEditor.bspRenderer);
            if (config.TXDPaths != null)
            {
                foreach (string s in config.TXDPaths)
                {
                    ExecuteIfFilePresent($"Error: TXD file not found: {s}", "Error", s, path => TextureManager.LoadTexturesFromTXD(s, mainForm.renderer, mainForm.LevelEditor.bspRenderer));
                }
            }

            if (config.TextureFolderPaths != null)
            {
                foreach (string s in config.TextureFolderPaths)
                {
                    ExecuteIfFilePresent($"Error: Folder not found: {s}", "Error", s, path => TextureManager.LoadTexturesFromFolder(s, mainForm.renderer, mainForm.LevelEditor.bspRenderer));
                }
            }

            mainForm.renderer.dffRenderer.ClearObjectONEFiles();
            if (config.DFFONEPaths != null)
            {
                mainForm.renderer.dffRenderer.AddDFFFiles(config.DFFONEPaths);
            }

            if (config.RenderingOptions != null)
            {
                mainForm.ApplyConfig(config.RenderingOptions);
                mainForm.ViewConfig.NumericQuadHeight.Value = (decimal)config.RenderingOptions.QuadtreeHeight;
            }
        }