コード例 #1
0
        bool SaveEngineConfig()
        {
            TextBlock block = new TextBlock();

            //Renderer
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.RenderingSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxRenderSystems.SelectedIndex != -1)
                {
                    component = components[comboBoxRenderSystems.SelectedIndex];
                }

                TextBlock rendererBlock = block.AddChild("Renderer");
                if (component != null)
                {
                    rendererBlock.SetAttribute("implementationComponent", component.Name);
                }

                //rendering device
                if (component != null && component.Name.Contains("Direct3D"))
                {
                    rendererBlock.SetAttribute("renderingDeviceName", (string)comboBoxRenderingDevices.SelectedItem);
                    rendererBlock.SetAttribute("renderingDeviceIndex", (comboBoxRenderingDevices.SelectedIndex - 1).ToString());
                }

                if (!checkBoxAllowShaders.Checked)
                {
                    rendererBlock.SetAttribute("allowShaders", checkBoxAllowShaders.Checked.ToString());
                }

                //depthBufferAccess
                if (comboBoxDepthBufferAccess.SelectedIndex != -1)
                {
                    rendererBlock.SetAttribute("depthBufferAccess",
                                               (comboBoxDepthBufferAccess.SelectedIndex == 1).ToString());
                }

                //fullSceneAntialiasing
                if (comboBoxAntialiasing.SelectedIndex != -1)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxAntialiasing.SelectedItem;
                    rendererBlock.SetAttribute("fullSceneAntialiasing", item.Identifier);
                }

                //filtering
                if (comboBoxFiltering.SelectedIndex != -1)
                {
                    RendererWorld.FilteringModes filtering = (RendererWorld.FilteringModes)
                                                             comboBoxFiltering.SelectedIndex;
                    rendererBlock.SetAttribute("filtering", filtering.ToString());
                }

                //renderTechnique
                if (comboBoxRenderTechnique.SelectedIndex != -1)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxRenderTechnique.SelectedItem;
                    rendererBlock.SetAttribute("renderTechnique", item.Identifier);
                }

                //multiMonitorMode
                if (comboBoxVideoMode.SelectedIndex == 1)
                {
                    rendererBlock.SetAttribute("multiMonitorMode", true.ToString());
                }

                //videoMode
                if (comboBoxVideoMode.SelectedIndex >= 2)
                {
                    string[] strings = ((string)comboBoxVideoMode.SelectedItem).
                                       Split(new char[] { 'x' });
                    Vec2I videoMode = new Vec2I(int.Parse(strings[0]),
                                                int.Parse(strings[1]));
                    rendererBlock.SetAttribute("videoMode", videoMode.ToString());
                }

                //fullScreen
                rendererBlock.SetAttribute("fullScreen", checkBoxFullScreen.Checked.ToString());

                //vertical sync
                rendererBlock.SetAttribute("verticalSync",
                                           checkBoxVerticalSync.Checked.ToString());
            }

            //Physics system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.PhysicsSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxPhysicsSystems.SelectedIndex != -1)
                {
                    component = components[comboBoxPhysicsSystems.SelectedIndex];
                }

                if (component != null)
                {
                    TextBlock physicsSystemBlock = block.AddChild("PhysicsSystem");
                    physicsSystemBlock.SetAttribute("implementationComponent", component.Name);
                    //physicsSystemBlock.SetAttribute( "allowHardwareAcceleration",
                    //   checkBoxPhysicsAllowHardwareAcceleration.Checked.ToString() );
                }
            }

            //Sound system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.SoundSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxSoundSystems.SelectedIndex != -1)
                {
                    component = components[comboBoxSoundSystems.SelectedIndex];
                }

                if (component != null)
                {
                    TextBlock soundSystemBlock = block.AddChild("SoundSystem");
                    soundSystemBlock.SetAttribute("implementationComponent", component.Name);
                }
            }

            //Localization
            {
                string language = "Autodetect";
                if (comboBoxLanguages.SelectedIndex > 0)
                {
                    language = (string)comboBoxLanguages.SelectedItem;
                }

                TextBlock localizationBlock = block.AddChild("Localization");
                localizationBlock.SetAttribute("language", language);
                if (!checkBoxLocalizeEngine.Checked)
                {
                    localizationBlock.SetAttribute("localizeEngine", checkBoxLocalizeEngine.Checked.ToString());
                }
                if (!checkBoxLocalizeToolset.Checked)
                {
                    localizationBlock.SetAttribute("localizeToolset", checkBoxLocalizeToolset.Checked.ToString());
                }
            }

            //save file
            {
                string fileName = VirtualFileSystem.GetRealPathByVirtual(
                    "user:Configs/Engine.config");

                try
                {
                    string directoryName = Path.GetDirectoryName(fileName);
                    if (directoryName != "" && !Directory.Exists(directoryName))
                    {
                        Directory.CreateDirectory(directoryName);
                    }
                    using (StreamWriter writer = new StreamWriter(fileName))
                    {
                        writer.Write(block.DumpToString());
                    }
                }
                catch
                {
                    string text = string.Format("Saving file failed \"{0}\".", fileName);
                    MessageBox.Show(text, "Configurator", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        private bool SaveEngineConfig()
        {
            TextBlock block = new TextBlock();

            //Renderer
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.RenderingSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxRenderSystems.SelectedIndex != -1)
                    component = components[comboBoxRenderSystems.SelectedIndex];

                TextBlock rendererBlock = block.AddChild("Renderer");
                if (component != null)
                    rendererBlock.SetAttribute("implementationComponent", component.Name);

                //rendering device
                if (component != null && component.Name.Contains("Direct3D"))
                {
                    rendererBlock.SetAttribute("renderingDeviceName", (string)comboBoxRenderingDevices.SelectedItem);
                    rendererBlock.SetAttribute("renderingDeviceIndex", (comboBoxRenderingDevices.SelectedIndex - 1).ToString());
                }

                if (!checkBoxAllowShaders.Checked)
                    rendererBlock.SetAttribute("allowShaders", checkBoxAllowShaders.Checked.ToString());

                //depthBufferAccess
                if (comboBoxDepthBufferAccess.SelectedIndex != -1)
                {
                    rendererBlock.SetAttribute("depthBufferAccess",
                        (comboBoxDepthBufferAccess.SelectedIndex == 1).ToString());
                }

                //fullSceneAntialiasing
                if (comboBoxAntialiasing.SelectedIndex != -1)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxAntialiasing.SelectedItem;
                    rendererBlock.SetAttribute("fullSceneAntialiasing", item.Identifier);
                }

                //filtering
                if (comboBoxFiltering.SelectedIndex != -1)
                {
                    RendererWorld.FilteringModes filtering = (RendererWorld.FilteringModes)
                        comboBoxFiltering.SelectedIndex;
                    rendererBlock.SetAttribute("filtering", filtering.ToString());
                }

                //renderTechnique
                if (comboBoxRenderTechnique.SelectedIndex != -1)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxRenderTechnique.SelectedItem;
                    rendererBlock.SetAttribute("renderTechnique", item.Identifier);
                }

                //multiMonitorMode
                if (comboBoxVideoMode.SelectedIndex == 1)
                    rendererBlock.SetAttribute("multiMonitorMode", true.ToString());

                //videoMode
                if (comboBoxVideoMode.SelectedIndex >= 2)
                {
                    string[] strings = ((string)comboBoxVideoMode.SelectedItem).
                        Split(new char[] { 'x' });
                    Vec2I videoMode = new Vec2I(int.Parse(strings[0]),
                        int.Parse(strings[1]));
                    rendererBlock.SetAttribute("videoMode", videoMode.ToString());
                }

                //fullScreen
                rendererBlock.SetAttribute("fullScreen", checkBoxFullScreen.Checked.ToString());

                //vertical sync
                rendererBlock.SetAttribute("verticalSync",
                    checkBoxVerticalSync.Checked.ToString());
            }

            //Physics system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.PhysicsSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxPhysicsSystems.SelectedIndex != -1)
                    component = components[comboBoxPhysicsSystems.SelectedIndex];

                if (component != null)
                {
                    TextBlock physicsSystemBlock = block.AddChild("PhysicsSystem");
                    physicsSystemBlock.SetAttribute("implementationComponent", component.Name);
                    //physicsSystemBlock.SetAttribute( "allowHardwareAcceleration",
                    //   checkBoxPhysicsAllowHardwareAcceleration.Checked.ToString() );
                }
            }

            //Sound system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.SoundSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxSoundSystems.SelectedIndex != -1)
                    component = components[comboBoxSoundSystems.SelectedIndex];

                if (component != null)
                {
                    TextBlock soundSystemBlock = block.AddChild("SoundSystem");
                    soundSystemBlock.SetAttribute("implementationComponent", component.Name);
                }
            }

            //Localization
            {
                string language = "Autodetect";
                if (comboBoxLanguages.SelectedIndex > 0)
                    language = (string)comboBoxLanguages.SelectedItem;

                TextBlock localizationBlock = block.AddChild("Localization");
                localizationBlock.SetAttribute("language", language);
                if (!checkBoxLocalizeEngine.Checked)
                    localizationBlock.SetAttribute("localizeEngine", checkBoxLocalizeEngine.Checked.ToString());
                if (!checkBoxLocalizeToolset.Checked)
                    localizationBlock.SetAttribute("localizeToolset", checkBoxLocalizeToolset.Checked.ToString());
            }

            //save file
            {
                string fileName = VirtualFileSystem.GetRealPathByVirtual(
                    "user:Configs/Engine.config");

                try
                {
                    string directoryName = Path.GetDirectoryName(fileName);
                    if (directoryName != "" && !Directory.Exists(directoryName))
                        Directory.CreateDirectory(directoryName);
                    using (StreamWriter writer = new StreamWriter(fileName))
                    {
                        writer.Write(block.DumpToString());
                    }
                }
                catch
                {
                    string text = string.Format("Saving file failed \"{0}\".", fileName);
                    MessageBox.Show(text, "Configurator", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    return false;
                }
            }

            return true;
        }