예제 #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
        ///////////////////////////////////////////

        protected override void OnAttach()
        {
            base.OnAttach();

            ComboBox  comboBox;
            ScrollBar scrollBar;
            CheckBox  checkBox;

            window = ControlDeclarationManager.Instance.CreateControl("Gui\\OptionsWindow.gui");
            Controls.Add(window);

            tabControl = (TabControl)window.Controls["TabControl"];

            BackColor  = new ColorValue(0, 0, 0, .5f);
            MouseCover = true;

            //load Engine.config
            TextBlock engineConfigBlock = LoadEngineConfig();
            TextBlock rendererBlock     = null;

            if (engineConfigBlock != null)
            {
                rendererBlock = engineConfigBlock.FindChild("Renderer");
            }

            //page buttons
            pageButtons[0] = (Button)window.Controls["ButtonVideo"];
            pageButtons[1] = (Button)window.Controls["ButtonShadows"];
            pageButtons[2] = (Button)window.Controls["ButtonSound"];
            pageButtons[3] = (Button)window.Controls["ButtonControls"];
            pageButtons[4] = (Button)window.Controls["ButtonLanguage"];
            foreach (Button pageButton in pageButtons)
            {
                pageButton.Click += new Button.ClickDelegate(pageButton_Click);
            }

            //Close button
            ((Button)window.Controls["Close"]).Click += delegate(Button sender)
            {
                SetShouldDetach();
            };

            //pageVideo
            {
                Control pageVideo = tabControl.Controls["Video"];

                Vec2I currentMode = EngineApp.Instance.VideoMode;

                //screenResolutionComboBox
                comboBox           = (ComboBox)pageVideo.Controls["ScreenResolution"];
                comboBox.Enable    = !EngineApp.Instance.MultiMonitorMode;
                comboBoxResolution = comboBox;

                if (EngineApp.Instance.MultiMonitorMode)
                {
                    comboBox.Items.Add(string.Format("{0}x{1} (multi-monitor)", currentMode.X,
                                                     currentMode.Y));
                    comboBox.SelectedIndex = 0;
                }
                else
                {
                    foreach (Vec2I mode in DisplaySettings.VideoModes)
                    {
                        if (mode.X < 640)
                        {
                            continue;
                        }

                        comboBox.Items.Add(string.Format("{0}x{1}", mode.X, mode.Y));

                        if (mode == currentMode)
                        {
                            comboBox.SelectedIndex = comboBox.Items.Count - 1;
                        }
                    }

                    comboBox.SelectedIndexChange += delegate(ComboBox sender)
                    {
                        ChangeVideoMode();
                    };
                }

                //gamma
                scrollBar              = (ScrollBar)pageVideo.Controls["Gamma"];
                scrollBar.Value        = GameEngineApp._Gamma;
                scrollBar.Enable       = true;
                scrollBar.ValueChange += delegate(ScrollBar sender)
                {
                    float value = float.Parse(sender.Value.ToString("F1"));
                    GameEngineApp._Gamma = value;
                    pageVideo.Controls["GammaValue"].Text = value.ToString("F1");
                };
                pageVideo.Controls["GammaValue"].Text = GameEngineApp._Gamma.ToString("F1");

                //MaterialScheme
                {
                    comboBox = (ComboBox)pageVideo.Controls["MaterialScheme"];
                    foreach (MaterialSchemes materialScheme in
                             Enum.GetValues(typeof(MaterialSchemes)))
                    {
                        comboBox.Items.Add(materialScheme.ToString());

                        if (GameEngineApp.MaterialScheme == materialScheme)
                        {
                            comboBox.SelectedIndex = comboBox.Items.Count - 1;
                        }
                    }
                    comboBox.SelectedIndexChange += delegate(ComboBox sender)
                    {
                        if (sender.SelectedIndex != -1)
                        {
                            GameEngineApp.MaterialScheme = (MaterialSchemes)sender.SelectedIndex;
                        }
                    };
                }

                //fullScreen
                checkBox                = (CheckBox)pageVideo.Controls["FullScreen"];
                checkBox.Enable         = !EngineApp.Instance.MultiMonitorMode;
                checkBox.Checked        = EngineApp.Instance.FullScreen;
                checkBox.CheckedChange += delegate(CheckBox sender)
                {
                    EngineApp.Instance.FullScreen = sender.Checked;
                };

                //RenderTechnique
                {
                    comboBox = (ComboBox)pageVideo.Controls["RenderTechnique"];
                    comboBox.Items.Add(new ComboBoxItem("RecommendedSetting", Translate("Recommended setting")));
                    comboBox.Items.Add(new ComboBoxItem("Standard", Translate("Low Dynamic Range (Standard)")));
                    comboBox.Items.Add(new ComboBoxItem("HDR", Translate("High Dynamic Range (HDR)")));

                    string renderTechnique = "";
                    if (rendererBlock != null && rendererBlock.IsAttributeExist("renderTechnique"))
                    {
                        renderTechnique = rendererBlock.GetAttribute("renderTechnique");
                    }

                    for (int n = 0; n < comboBox.Items.Count; n++)
                    {
                        ComboBoxItem item = (ComboBoxItem)comboBox.Items[n];
                        if (item.Identifier == renderTechnique)
                        {
                            comboBox.SelectedIndex = n;
                        }
                    }
                    if (comboBox.SelectedIndex == -1)
                    {
                        comboBox.SelectedIndex = 0;
                    }

                    comboBox.SelectedIndexChange += comboBoxRenderTechnique_SelectedIndexChange;
                }

                //Filtering
                {
                    comboBox = (ComboBox)pageVideo.Controls["Filtering"];

                    Type enumType = typeof(RendererWorld.FilteringModes);
                    LocalizedEnumConverter enumConverter = new LocalizedEnumConverter(enumType);

                    RendererWorld.FilteringModes filtering = RendererWorld.FilteringModes.RecommendedSetting;
                    //get value from Engine.config.
                    if (rendererBlock != null && rendererBlock.IsAttributeExist("filtering"))
                    {
                        try
                        {
                            filtering = (RendererWorld.FilteringModes)Enum.Parse(enumType, rendererBlock.GetAttribute("filtering"));
                        }
                        catch { }
                    }

                    RendererWorld.FilteringModes[] values = (RendererWorld.FilteringModes[])Enum.GetValues(enumType);
                    for (int n = 0; n < values.Length; n++)
                    {
                        RendererWorld.FilteringModes value = values[n];
                        string valueStr = enumConverter.ConvertToString(value);
                        comboBox.Items.Add(new ComboBoxItem(value.ToString(), Translate(valueStr)));
                        if (filtering == value)
                        {
                            comboBox.SelectedIndex = comboBox.Items.Count - 1;
                        }
                    }
                    if (comboBox.SelectedIndex == -1)
                    {
                        comboBox.SelectedIndex = 0;
                    }

                    comboBox.SelectedIndexChange += comboBoxFiltering_SelectedIndexChange;
                }

                //DepthBufferAccess
                {
                    checkBox = (CheckBox)pageVideo.Controls["DepthBufferAccess"];
                    checkBoxDepthBufferAccess = checkBox;

                    bool depthBufferAccess = true;
                    //get value from Engine.config.
                    if (rendererBlock != null && rendererBlock.IsAttributeExist("depthBufferAccess"))
                    {
                        depthBufferAccess = bool.Parse(rendererBlock.GetAttribute("depthBufferAccess"));
                    }
                    checkBox.Checked = depthBufferAccess;

                    checkBox.CheckedChange += checkBoxDepthBufferAccess_CheckedChange;
                }

                //FSAA
                {
                    comboBox             = (ComboBox)pageVideo.Controls["FSAA"];
                    comboBoxAntialiasing = comboBox;

                    UpdateComboBoxAntialiasing();

                    string fullSceneAntialiasing = "";
                    if (rendererBlock != null && rendererBlock.IsAttributeExist("fullSceneAntialiasing"))
                    {
                        fullSceneAntialiasing = rendererBlock.GetAttribute("fullSceneAntialiasing");
                    }
                    for (int n = 0; n < comboBoxAntialiasing.Items.Count; n++)
                    {
                        ComboBoxItem item = (ComboBoxItem)comboBoxAntialiasing.Items[n];
                        if (item.Identifier == fullSceneAntialiasing)
                        {
                            comboBoxAntialiasing.SelectedIndex = n;
                        }
                    }

                    comboBoxAntialiasing.SelectedIndexChange += comboBoxAntialiasing_SelectedIndexChange;
                }

                //VerticalSync
                {
                    checkBox = (CheckBox)pageVideo.Controls["VerticalSync"];

                    bool verticalSync = RendererWorld.InitializationOptions.VerticalSync;
                    //get value from Engine.config.
                    if (rendererBlock != null && rendererBlock.IsAttributeExist("verticalSync"))
                    {
                        verticalSync = bool.Parse(rendererBlock.GetAttribute("verticalSync"));
                    }
                    checkBox.Checked = verticalSync;

                    checkBox.CheckedChange += checkBoxVerticalSync_CheckedChange;
                }

                //VideoRestart
                {
                    Button button = (Button)pageVideo.Controls["VideoRestart"];
                    button.Click += buttonVideoRestart_Click;
                }

                //waterReflectionLevel
                comboBox = (ComboBox)pageVideo.Controls["WaterReflectionLevel"];
                foreach (WaterPlane.ReflectionLevels level in Enum.GetValues(
                             typeof(WaterPlane.ReflectionLevels)))
                {
                    comboBox.Items.Add(level);
                    if (GameEngineApp.WaterReflectionLevel == level)
                    {
                        comboBox.SelectedIndex = comboBox.Items.Count - 1;
                    }
                }
                comboBox.SelectedIndexChange += delegate(ComboBox sender)
                {
                    GameEngineApp.WaterReflectionLevel = (WaterPlane.ReflectionLevels)sender.SelectedItem;
                };

                //showDecorativeObjects
                checkBox                = (CheckBox)pageVideo.Controls["ShowDecorativeObjects"];
                checkBox.Checked        = GameEngineApp.ShowDecorativeObjects;
                checkBox.CheckedChange += delegate(CheckBox sender)
                {
                    GameEngineApp.ShowDecorativeObjects = sender.Checked;
                };

                //showSystemCursorCheckBox
                checkBox                = (CheckBox)pageVideo.Controls["ShowSystemCursor"];
                checkBox.Checked        = GameEngineApp._ShowSystemCursor;
                checkBox.CheckedChange += delegate(CheckBox sender)
                {
                    GameEngineApp._ShowSystemCursor = sender.Checked;
                    sender.Checked = GameEngineApp._ShowSystemCursor;
                };

                //showFPSCheckBox
                checkBox                = (CheckBox)pageVideo.Controls["ShowFPS"];
                checkBox.Checked        = GameEngineApp._DrawFPS;
                checkBox.CheckedChange += delegate(CheckBox sender)
                {
                    GameEngineApp._DrawFPS = sender.Checked;
                    sender.Checked         = GameEngineApp._DrawFPS;
                };
            }

            //pageShadows
            {
                Control pageShadows = tabControl.Controls["Shadows"];

                //ShadowTechnique
                {
                    comboBox = (ComboBox)pageShadows.Controls["ShadowTechnique"];

                    comboBox.Items.Add(new ShadowTechniqueItem(ShadowTechniques.None, "None"));
                    comboBox.Items.Add(new ShadowTechniqueItem(ShadowTechniques.ShadowmapLow, "Shadowmap Low"));
                    comboBox.Items.Add(new ShadowTechniqueItem(ShadowTechniques.ShadowmapMedium, "Shadowmap Medium"));
                    comboBox.Items.Add(new ShadowTechniqueItem(ShadowTechniques.ShadowmapHigh, "Shadowmap High"));
                    comboBox.Items.Add(new ShadowTechniqueItem(ShadowTechniques.ShadowmapLowPSSM, "PSSMx3 Low"));
                    comboBox.Items.Add(new ShadowTechniqueItem(ShadowTechniques.ShadowmapMediumPSSM, "PSSMx3 Medium"));
                    comboBox.Items.Add(new ShadowTechniqueItem(ShadowTechniques.ShadowmapHighPSSM, "PSSMx3 High"));
                    comboBox.Items.Add(new ShadowTechniqueItem(ShadowTechniques.Stencil, "Stencil"));

                    for (int n = 0; n < comboBox.Items.Count; n++)
                    {
                        ShadowTechniqueItem item = (ShadowTechniqueItem)comboBox.Items[n];
                        if (item.Technique == GameEngineApp.ShadowTechnique)
                        {
                            comboBox.SelectedIndex = n;
                        }
                    }

                    comboBox.SelectedIndexChange += delegate(ComboBox sender)
                    {
                        if (sender.SelectedIndex != -1)
                        {
                            ShadowTechniqueItem item = (ShadowTechniqueItem)sender.SelectedItem;
                            GameEngineApp.ShadowTechnique = item.Technique;
                        }
                        UpdateShadowControlsEnable();
                    };
                    UpdateShadowControlsEnable();
                }

                //ShadowUseMapSettings
                {
                    checkBox                = (CheckBox)pageShadows.Controls["ShadowUseMapSettings"];
                    checkBox.Checked        = GameEngineApp.ShadowUseMapSettings;
                    checkBox.CheckedChange += delegate(CheckBox sender)
                    {
                        GameEngineApp.ShadowUseMapSettings = sender.Checked;
                        if (sender.Checked && Map.Instance != null)
                        {
                            GameEngineApp.ShadowPSSMSplitFactors = Map.Instance.InitialShadowPSSMSplitFactors;
                            GameEngineApp.ShadowFarDistance      = Map.Instance.InitialShadowFarDistance;
                            GameEngineApp.ShadowColor            = Map.Instance.InitialShadowColor;
                        }

                        UpdateShadowControlsEnable();

                        if (sender.Checked)
                        {
                            ((ScrollBar)pageShadows.Controls["ShadowFarDistance"]).Value =
                                GameEngineApp.ShadowFarDistance;

                            pageShadows.Controls["ShadowFarDistanceValue"].Text =
                                ((int)GameEngineApp.ShadowFarDistance).ToString();

                            ColorValue color = GameEngineApp.ShadowColor;
                            ((ScrollBar)pageShadows.Controls["ShadowColor"]).Value =
                                (color.Red + color.Green + color.Blue) / 3;
                        }
                    };
                }

                //ShadowPSSMSplitFactor1
                scrollBar              = (ScrollBar)pageShadows.Controls["ShadowPSSMSplitFactor1"];
                scrollBar.Value        = GameEngineApp.ShadowPSSMSplitFactors[0];
                scrollBar.ValueChange += delegate(ScrollBar sender)
                {
                    GameEngineApp.ShadowPSSMSplitFactors = new Vec2(
                        sender.Value, GameEngineApp.ShadowPSSMSplitFactors[1]);
                    pageShadows.Controls["ShadowPSSMSplitFactor1Value"].Text =
                        (GameEngineApp.ShadowPSSMSplitFactors[0].ToString("F2")).ToString();
                };
                pageShadows.Controls["ShadowPSSMSplitFactor1Value"].Text =
                    (GameEngineApp.ShadowPSSMSplitFactors[0].ToString("F2")).ToString();

                //ShadowPSSMSplitFactor2
                scrollBar              = (ScrollBar)pageShadows.Controls["ShadowPSSMSplitFactor2"];
                scrollBar.Value        = GameEngineApp.ShadowPSSMSplitFactors[1];
                scrollBar.ValueChange += delegate(ScrollBar sender)
                {
                    GameEngineApp.ShadowPSSMSplitFactors = new Vec2(
                        GameEngineApp.ShadowPSSMSplitFactors[0], sender.Value);
                    pageShadows.Controls["ShadowPSSMSplitFactor2Value"].Text =
                        (GameEngineApp.ShadowPSSMSplitFactors[1].ToString("F2")).ToString();
                };
                pageShadows.Controls["ShadowPSSMSplitFactor2Value"].Text =
                    (GameEngineApp.ShadowPSSMSplitFactors[1].ToString("F2")).ToString();

                //ShadowFarDistance
                scrollBar              = (ScrollBar)pageShadows.Controls["ShadowFarDistance"];
                scrollBar.Value        = GameEngineApp.ShadowFarDistance;
                scrollBar.ValueChange += delegate(ScrollBar sender)
                {
                    GameEngineApp.ShadowFarDistance = sender.Value;
                    pageShadows.Controls["ShadowFarDistanceValue"].Text =
                        ((int)GameEngineApp.ShadowFarDistance).ToString();
                };
                pageShadows.Controls["ShadowFarDistanceValue"].Text =
                    ((int)GameEngineApp.ShadowFarDistance).ToString();

                //ShadowColor
                scrollBar       = (ScrollBar)pageShadows.Controls["ShadowColor"];
                scrollBar.Value = (GameEngineApp.ShadowColor.Red + GameEngineApp.ShadowColor.Green +
                                   GameEngineApp.ShadowColor.Blue) / 3;
                scrollBar.ValueChange += delegate(ScrollBar sender)
                {
                    float color = sender.Value;
                    GameEngineApp.ShadowColor = new ColorValue(color, color, color, color);
                };

                //ShadowDirectionalLightTextureSize
                {
                    comboBox = (ComboBox)pageShadows.Controls["ShadowDirectionalLightTextureSize"];
                    for (int value = 256, index = 0; value <= 8192; value *= 2, index++)
                    {
                        comboBox.Items.Add(value);
                        if (GameEngineApp.ShadowDirectionalLightTextureSize == value)
                        {
                            comboBox.SelectedIndex = index;
                        }
                    }
                    comboBox.SelectedIndexChange += delegate(ComboBox sender)
                    {
                        GameEngineApp.ShadowDirectionalLightTextureSize = (int)sender.SelectedItem;
                    };
                }

                ////ShadowDirectionalLightMaxTextureCount
                //{
                //   comboBox = (EComboBox)pageVideo.Controls[ "ShadowDirectionalLightMaxTextureCount" ];
                //   for( int n = 0; n < 3; n++ )
                //   {
                //      int count = n + 1;
                //      comboBox.Items.Add( count );
                //      if( count == GameEngineApp.ShadowDirectionalLightMaxTextureCount )
                //         comboBox.SelectedIndex = n;
                //   }
                //   comboBox.SelectedIndexChange += delegate( EComboBox sender )
                //   {
                //      GameEngineApp.ShadowDirectionalLightMaxTextureCount = (int)sender.SelectedItem;
                //   };
                //}

                //ShadowSpotLightTextureSize
                {
                    comboBox = (ComboBox)pageShadows.Controls["ShadowSpotLightTextureSize"];
                    for (int value = 256, index = 0; value <= 8192; value *= 2, index++)
                    {
                        comboBox.Items.Add(value);
                        if (GameEngineApp.ShadowSpotLightTextureSize == value)
                        {
                            comboBox.SelectedIndex = index;
                        }
                    }
                    comboBox.SelectedIndexChange += delegate(ComboBox sender)
                    {
                        GameEngineApp.ShadowSpotLightTextureSize = (int)sender.SelectedItem;
                    };
                }

                //ShadowSpotLightMaxTextureCount
                {
                    comboBox = (ComboBox)pageShadows.Controls["ShadowSpotLightMaxTextureCount"];
                    for (int n = 0; n < 3; n++)
                    {
                        int count = n + 1;
                        comboBox.Items.Add(count);
                        if (count == GameEngineApp.ShadowSpotLightMaxTextureCount)
                        {
                            comboBox.SelectedIndex = n;
                        }
                    }
                    comboBox.SelectedIndexChange += delegate(ComboBox sender)
                    {
                        GameEngineApp.ShadowSpotLightMaxTextureCount = (int)sender.SelectedItem;
                    };
                }

                //ShadowPointLightTextureSize
                {
                    comboBox = (ComboBox)pageShadows.Controls["ShadowPointLightTextureSize"];
                    for (int value = 256, index = 0; value <= 8192; value *= 2, index++)
                    {
                        comboBox.Items.Add(value);
                        if (GameEngineApp.ShadowPointLightTextureSize == value)
                        {
                            comboBox.SelectedIndex = index;
                        }
                    }
                    comboBox.SelectedIndexChange += delegate(ComboBox sender)
                    {
                        GameEngineApp.ShadowPointLightTextureSize = (int)sender.SelectedItem;
                    };
                }

                //ShadowPointLightMaxTextureCount
                {
                    comboBox = (ComboBox)pageShadows.Controls["ShadowPointLightMaxTextureCount"];
                    for (int n = 0; n < 3; n++)
                    {
                        int count = n + 1;
                        comboBox.Items.Add(count);
                        if (count == GameEngineApp.ShadowPointLightMaxTextureCount)
                        {
                            comboBox.SelectedIndex = n;
                        }
                    }
                    comboBox.SelectedIndexChange += delegate(ComboBox sender)
                    {
                        GameEngineApp.ShadowPointLightMaxTextureCount = (int)sender.SelectedItem;
                    };
                }
            }

            //pageSound
            {
                bool enabled = SoundWorld.Instance.DriverName != "NULL";

                Control pageSound = tabControl.Controls["Sound"];

                //soundVolumeCheckBox
                scrollBar              = (ScrollBar)pageSound.Controls["SoundVolume"];
                scrollBar.Value        = enabled ? GameEngineApp.SoundVolume : 0;
                scrollBar.Enable       = enabled;
                scrollBar.ValueChange += delegate(ScrollBar sender)
                {
                    GameEngineApp.SoundVolume = sender.Value;
                };

                //musicVolumeCheckBox
                scrollBar              = (ScrollBar)pageSound.Controls["MusicVolume"];
                scrollBar.Value        = enabled ? GameEngineApp.MusicVolume : 0;
                scrollBar.Enable       = enabled;
                scrollBar.ValueChange += delegate(ScrollBar sender)
                {
                    GameEngineApp.MusicVolume = sender.Value;
                };
            }

            //pageControls
            {
                Control pageControls = tabControl.Controls["Controls"];

                //MouseHSensitivity
                scrollBar              = (ScrollBar)pageControls.Controls["MouseHSensitivity"];
                scrollBar.Value        = GameControlsManager.Instance.MouseSensitivity.X;
                scrollBar.ValueChange += delegate(ScrollBar sender)
                {
                    Vec2 value = GameControlsManager.Instance.MouseSensitivity;
                    value.X = sender.Value;
                    GameControlsManager.Instance.MouseSensitivity = value;
                };

                //MouseVSensitivity
                scrollBar              = (ScrollBar)pageControls.Controls["MouseVSensitivity"];
                scrollBar.Value        = Math.Abs(GameControlsManager.Instance.MouseSensitivity.Y);
                scrollBar.ValueChange += delegate(ScrollBar sender)
                {
                    Vec2 value  = GameControlsManager.Instance.MouseSensitivity;
                    bool invert = ((CheckBox)pageControls.Controls["MouseVInvert"]).Checked;
                    value.Y = sender.Value * (invert ? -1.0f : 1.0f);
                    GameControlsManager.Instance.MouseSensitivity = value;
                };

                //MouseVInvert
                checkBox                = (CheckBox)pageControls.Controls["MouseVInvert"];
                checkBox.Checked        = GameControlsManager.Instance.MouseSensitivity.Y < 0;
                checkBox.CheckedChange += delegate(CheckBox sender)
                {
                    Vec2 value = GameControlsManager.Instance.MouseSensitivity;
                    value.Y =
                        ((ScrollBar)pageControls.Controls["MouseVSensitivity"]).Value *
                        (sender.Checked ? -1.0f : 1.0f);
                    GameControlsManager.Instance.MouseSensitivity = value;
                };

                //AlwaysRun
                checkBox                = (CheckBox)pageControls.Controls["AlwaysRun"];
                checkBox.Checked        = GameControlsManager.Instance.AlwaysRun;
                checkBox.CheckedChange += delegate(CheckBox sender)
                {
                    GameControlsManager.Instance.AlwaysRun = sender.Checked;
                };

                //Devices
                comboBox             = (ComboBox)pageControls.Controls["InputDevices"];
                comboBoxInputDevices = comboBox;
                comboBox.Items.Add("Keyboard/Mouse");
                if (InputDeviceManager.Instance != null)
                {
                    foreach (InputDevice device in InputDeviceManager.Instance.Devices)
                    {
                        comboBox.Items.Add(device);
                    }
                }
                comboBox.SelectedIndex = 0;

                comboBox.SelectedIndexChange += delegate(ComboBox sender)
                {
                    UpdateBindedInputControlsTextBox();
                };

                //Controls
                UpdateBindedInputControlsTextBox();
            }

            //pageLanguage
            {
                Control pageLanguage = tabControl.Controls["Language"];

                //Language
                {
                    comboBox = (ComboBox)pageLanguage.Controls["Language"];

                    List <string> languages = new List <string>();
                    {
                        languages.Add("Autodetect");
                        string[] directories = VirtualDirectory.GetDirectories(LanguageManager.LanguagesDirectory, "*.*",
                                                                               SearchOption.TopDirectoryOnly);
                        foreach (string directory in directories)
                        {
                            languages.Add(Path.GetFileNameWithoutExtension(directory));
                        }
                    }

                    string language = "Autodetect";
                    if (engineConfigBlock != null)
                    {
                        TextBlock localizationBlock = engineConfigBlock.FindChild("Localization");
                        if (localizationBlock != null && localizationBlock.IsAttributeExist("language"))
                        {
                            language = localizationBlock.GetAttribute("language");
                        }
                    }

                    foreach (string lang in languages)
                    {
                        string displayName = lang;
                        if (lang == "Autodetect")
                        {
                            displayName = Translate(lang);
                        }

                        comboBox.Items.Add(new ComboBoxItem(lang, displayName));
                        if (string.Compare(language, lang, true) == 0)
                        {
                            comboBox.SelectedIndex = comboBox.Items.Count - 1;
                        }
                    }
                    if (comboBox.SelectedIndex == -1)
                    {
                        comboBox.SelectedIndex = 0;
                    }

                    comboBox.SelectedIndexChange += comboBoxLanguage_SelectedIndexChange;
                }

                //LanguageRestart
                {
                    Button button = (Button)pageLanguage.Controls["LanguageRestart"];
                    button.Click += buttonLanguageRestart_Click;
                }
            }

            tabControl.SelectedIndex        = lastPageIndex;
            tabControl.SelectedIndexChange += tabControl_SelectedIndexChange;
            UpdatePageButtonsState();
        }
예제 #3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //Engine.config parameters
            string renderingSystemComponentName = "";
            bool   allowShaders          = true;
            bool   depthBufferAccess     = true;
            string fullSceneAntialiasing = "";

            RendererWorld.FilteringModes filtering = RendererWorld.FilteringModes.RecommendedSetting;
            string renderTechnique             = "";
            bool   fullScreen                  = true;
            string videoMode                   = "";
            bool   multiMonitorMode            = false;
            bool   verticalSync                = true;
            bool   allowChangeDisplayFrequency = true;
            string physicsSystemComponentName  = "";
            //bool physicsAllowHardwareAcceleration = false;
            string soundSystemComponentName = "";
            string language             = "Autodetect";
            bool   localizeEngine       = true;
            bool   localizeToolset      = true;
            string renderingDeviceName  = "";
            int    renderingDeviceIndex = 0;

            //load from Deployment.config
            if (VirtualFileSystem.Deployed)
            {
                if (!string.IsNullOrEmpty(VirtualFileSystem.DeploymentParameters.DefaultLanguage))
                {
                    language = VirtualFileSystem.DeploymentParameters.DefaultLanguage;
                }
            }

            //load from Engine.config
            {
                string    error;
                TextBlock block = TextBlockUtils.LoadFromRealFile(
                    VirtualFileSystem.GetRealPathByVirtual("user:Configs/Engine.config"),
                    out error);
                if (block != null)
                {
                    //Renderer
                    TextBlock rendererBlock = block.FindChild("Renderer");
                    if (rendererBlock != null)
                    {
                        renderingSystemComponentName = rendererBlock.GetAttribute("implementationComponent");

                        if (rendererBlock.IsAttributeExist("renderingDeviceName"))
                        {
                            renderingDeviceName = rendererBlock.GetAttribute("renderingDeviceName");
                        }
                        if (rendererBlock.IsAttributeExist("renderingDeviceIndex"))
                        {
                            renderingDeviceIndex = int.Parse(rendererBlock.GetAttribute("renderingDeviceIndex"));
                        }
                        if (rendererBlock.IsAttributeExist("allowShaders"))
                        {
                            allowShaders = bool.Parse(rendererBlock.GetAttribute("allowShaders"));
                        }
                        if (rendererBlock.IsAttributeExist("depthBufferAccess"))
                        {
                            depthBufferAccess = bool.Parse(rendererBlock.GetAttribute("depthBufferAccess"));
                        }
                        if (rendererBlock.IsAttributeExist("fullSceneAntialiasing"))
                        {
                            fullSceneAntialiasing = rendererBlock.GetAttribute("fullSceneAntialiasing");
                        }

                        if (rendererBlock.IsAttributeExist("filtering"))
                        {
                            try
                            {
                                filtering = (RendererWorld.FilteringModes)
                                            Enum.Parse(typeof(RendererWorld.FilteringModes),
                                                       rendererBlock.GetAttribute("filtering"));
                            }
                            catch { }
                        }

                        if (rendererBlock.IsAttributeExist("renderTechnique"))
                        {
                            renderTechnique = rendererBlock.GetAttribute("renderTechnique");
                        }

                        if (rendererBlock.IsAttributeExist("fullScreen"))
                        {
                            fullScreen = bool.Parse(rendererBlock.GetAttribute("fullScreen"));
                        }

                        if (rendererBlock.IsAttributeExist("videoMode"))
                        {
                            videoMode = rendererBlock.GetAttribute("videoMode");
                        }

                        if (rendererBlock.IsAttributeExist("multiMonitorMode"))
                        {
                            multiMonitorMode = bool.Parse(rendererBlock.GetAttribute("multiMonitorMode"));
                        }

                        if (rendererBlock.IsAttributeExist("verticalSync"))
                        {
                            verticalSync = bool.Parse(rendererBlock.GetAttribute("verticalSync"));
                        }

                        if (rendererBlock.IsAttributeExist("allowChangeDisplayFrequency"))
                        {
                            allowChangeDisplayFrequency = bool.Parse(
                                rendererBlock.GetAttribute("allowChangeDisplayFrequency"));
                        }
                    }

                    //Physics system
                    TextBlock physicsSystemBlock = block.FindChild("PhysicsSystem");
                    if (physicsSystemBlock != null)
                    {
                        physicsSystemComponentName = physicsSystemBlock.GetAttribute("implementationComponent");
                        //if( physicsSystemBlock.IsAttributeExist( "allowHardwareAcceleration" ) )
                        //{
                        //   physicsAllowHardwareAcceleration =
                        //      bool.Parse( physicsSystemBlock.GetAttribute( "allowHardwareAcceleration" ) );
                        //}
                    }

                    //Sound system
                    TextBlock soundSystemBlock = block.FindChild("SoundSystem");
                    if (soundSystemBlock != null)
                    {
                        soundSystemComponentName = soundSystemBlock.GetAttribute("implementationComponent");
                    }

                    //Localization
                    TextBlock localizationBlock = block.FindChild("Localization");
                    if (localizationBlock != null)
                    {
                        if (localizationBlock.IsAttributeExist("language"))
                        {
                            language = localizationBlock.GetAttribute("language");
                        }
                        if (localizationBlock.IsAttributeExist("localizeEngine"))
                        {
                            localizeEngine = bool.Parse(localizationBlock.GetAttribute("localizeEngine"));
                        }
                        if (localizationBlock.IsAttributeExist("localizeToolset"))
                        {
                            localizeToolset = bool.Parse(localizationBlock.GetAttribute("localizeToolset"));
                        }
                    }
                }
            }

            //init toolset language
            if (localizeToolset)
            {
                if (!string.IsNullOrEmpty(language))
                {
                    string language2 = language;
                    if (string.Compare(language2, "autodetect", true) == 0)
                    {
                        language2 = DetectLanguage();
                    }
                    string languageDirectory = Path.Combine(LanguageManager.LanguagesDirectory, language2);
                    string fileName          = Path.Combine(languageDirectory, "Configurator.language");
                    ToolsLocalization.Init(fileName);
                }
            }

            //fill render system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.RenderingSystem);

                if (string.IsNullOrEmpty(renderingSystemComponentName))
                {
                    //find component by default
                    foreach (EngineComponentManager.ComponentInfo component2 in components)
                    {
                        if (component2.IsEnabledByDefaultForThisPlatform())
                        {
                            renderingSystemComponentName = component2.Name;
                            break;
                        }
                    }
                }

                //rendering systems combo box
                foreach (EngineComponentManager.ComponentInfo component in components)
                {
                    string text = component.FullName;
                    if (component.IsEnabledByDefaultForThisPlatform())
                    {
                        text = string.Format(Translate("{0} (default)"), text);
                    }
                    int itemId = comboBoxRenderSystems.Items.Add(text);
                    if (renderingSystemComponentName == component.Name)
                    {
                        comboBoxRenderSystems.SelectedIndex = itemId;
                    }
                }
                if (comboBoxRenderSystems.Items.Count != 0 && comboBoxRenderSystems.SelectedIndex == -1)
                {
                    comboBoxRenderSystems.SelectedIndex = 0;
                }

                //rendering device
                {
                    if (comboBoxRenderingDevices.Items.Count > 1 && !string.IsNullOrEmpty(renderingDeviceName))
                    {
                        int deviceCountWithSelectedName = 0;

                        for (int n = 1; n < comboBoxRenderingDevices.Items.Count; n++)
                        {
                            string name = (string)comboBoxRenderingDevices.Items[n];
                            if (name == renderingDeviceName)
                            {
                                comboBoxRenderingDevices.SelectedIndex = n;
                                deviceCountWithSelectedName++;
                            }
                        }

                        if (deviceCountWithSelectedName > 1)
                        {
                            int comboBoxIndex = renderingDeviceIndex + 1;
                            if (comboBoxIndex < comboBoxRenderingDevices.Items.Count)
                            {
                                string name = (string)comboBoxRenderingDevices.Items[comboBoxIndex];
                                if (name == renderingDeviceName)
                                {
                                    comboBoxRenderingDevices.SelectedIndex = comboBoxIndex;
                                }
                            }
                        }
                    }

                    if (comboBoxRenderingDevices.SelectedIndex == -1 && comboBoxRenderingDevices.Items.Count != 0)
                    {
                        comboBoxRenderingDevices.SelectedIndex = 0;
                    }
                }

                //allowShaders
                checkBoxAllowShaders.Checked = allowShaders;

                //depthBufferAccess
                comboBoxDepthBufferAccess.Items.Add(Translate("No"));
                comboBoxDepthBufferAccess.Items.Add(Translate("Yes"));
                comboBoxDepthBufferAccess.SelectedIndex = depthBufferAccess ? 1 : 0;

                //fullSceneAntialiasing
                for (int n = 0; n < comboBoxAntialiasing.Items.Count; n++)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxAntialiasing.Items[n];
                    if (item.Identifier == fullSceneAntialiasing)
                    {
                        comboBoxAntialiasing.SelectedIndex = n;
                    }
                }
                if (comboBoxAntialiasing.SelectedIndex == -1)
                {
                    comboBoxAntialiasing.SelectedIndex = 0;
                }

                //filtering
                {
                    Type enumType = typeof(RendererWorld.FilteringModes);
                    LocalizedEnumConverter enumConverter = new LocalizedEnumConverter(enumType);

                    RendererWorld.FilteringModes[] values =
                        (RendererWorld.FilteringModes[])Enum.GetValues(enumType);
                    for (int n = 0; n < values.Length; n++)
                    {
                        RendererWorld.FilteringModes value = values[n];
                        int index = comboBoxFiltering.Items.Add(enumConverter.ConvertToString(value));
                        if (filtering == value)
                        {
                            comboBoxFiltering.SelectedIndex = index;
                        }
                    }
                }

                //renderTechnique
                {
                    comboBoxRenderTechnique.Items.Add(new ComboBoxItem("RecommendedSetting", "Recommended setting"));
                    comboBoxRenderTechnique.Items.Add(new ComboBoxItem("Standard", "Low Dynamic Range (Standard)"));
                    comboBoxRenderTechnique.Items.Add(new ComboBoxItem("HDR", "64-bit High Dynamic Range (HDR)"));

                    for (int n = 0; n < comboBoxRenderTechnique.Items.Count; n++)
                    {
                        ComboBoxItem item = (ComboBoxItem)comboBoxRenderTechnique.Items[n];
                        if (item.Identifier == renderTechnique)
                        {
                            comboBoxRenderTechnique.SelectedIndex = n;
                        }
                    }
                    if (comboBoxRenderTechnique.SelectedIndex == -1)
                    {
                        comboBoxRenderTechnique.SelectedIndex = 0;
                    }
                }

                //video mode
                {
                    comboBoxVideoMode.Items.Add(Translate("Current screen resolution"));
                    comboBoxVideoMode.SelectedIndex = 0;

                    comboBoxVideoMode.Items.Add(Translate("Use all displays (multi-monitor mode)"));
                    if (multiMonitorMode)
                    {
                        comboBoxVideoMode.SelectedIndex = 1;
                    }

                    foreach (Vec2I mode in DisplaySettings.VideoModes)
                    {
                        if (mode.X < 640)
                        {
                            continue;
                        }
                        comboBoxVideoMode.Items.Add(string.Format("{0}x{1}", mode.X, mode.Y));
                        if (mode.ToString() == videoMode)
                        {
                            comboBoxVideoMode.SelectedIndex = comboBoxVideoMode.Items.Count - 1;
                        }
                    }

                    if (!string.IsNullOrEmpty(videoMode) && comboBoxVideoMode.SelectedIndex == 0)
                    {
                        try
                        {
                            Vec2I mode = Vec2I.Parse(videoMode);
                            comboBoxVideoMode.Items.Add(string.Format("{0}x{1}", mode.X, mode.Y));
                            comboBoxVideoMode.SelectedIndex = comboBoxVideoMode.Items.Count - 1;
                        }
                        catch { }
                    }
                }

                //full screen
                checkBoxFullScreen.Checked = fullScreen;

                //vertical sync
                checkBoxVerticalSync.Checked = verticalSync;
            }

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

                if (string.IsNullOrEmpty(physicsSystemComponentName))
                {
                    //find component by default
                    foreach (EngineComponentManager.ComponentInfo component2 in components)
                    {
                        if (component2.IsEnabledByDefaultForThisPlatform())
                        {
                            physicsSystemComponentName = component2.Name;
                            break;
                        }
                    }
                }

                //update combo box
                foreach (EngineComponentManager.ComponentInfo component in components)
                {
                    string text = component.FullName;
                    if (component.IsEnabledByDefaultForThisPlatform())
                    {
                        text = string.Format(Translate("{0} (default)"), text);
                    }

                    int itemId = comboBoxPhysicsSystems.Items.Add(text);
                    if (physicsSystemComponentName == component.Name)
                    {
                        comboBoxPhysicsSystems.SelectedIndex = itemId;
                    }
                }
                if (comboBoxPhysicsSystems.SelectedIndex == -1)
                {
                    comboBoxPhysicsSystems.SelectedIndex = 0;
                }

                //if( checkBoxPhysicsAllowHardwareAcceleration.Enabled )
                //   checkBoxPhysicsAllowHardwareAcceleration.Checked = physicsAllowHardwareAcceleration;
            }

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

                if (string.IsNullOrEmpty(soundSystemComponentName))
                {
                    //find component by default
                    foreach (EngineComponentManager.ComponentInfo component2 in components)
                    {
                        if (component2.IsEnabledByDefaultForThisPlatform())
                        {
                            soundSystemComponentName = component2.Name;
                            break;
                        }
                    }
                }

                //update combo box
                foreach (EngineComponentManager.ComponentInfo component in components)
                {
                    string text = component.FullName;
                    if (component.IsEnabledByDefaultForThisPlatform())
                    {
                        text = string.Format(Translate("{0} (default)"), text);
                    }

                    int itemId = comboBoxSoundSystems.Items.Add(text);
                    if (soundSystemComponentName == component.Name)
                    {
                        comboBoxSoundSystems.SelectedIndex = itemId;
                    }
                }
                if (comboBoxSoundSystems.SelectedIndex == -1)
                {
                    comboBoxSoundSystems.SelectedIndex = 0;
                }
            }

            //fill localization page
            {
                List <string> languages = new List <string>();
                {
                    languages.Add(Translate("Autodetect"));
                    string[] directories = VirtualDirectory.GetDirectories(LanguageManager.LanguagesDirectory,
                                                                           "*.*", SearchOption.TopDirectoryOnly);
                    foreach (string directory in directories)
                    {
                        languages.Add(Path.GetFileNameWithoutExtension(directory));
                    }
                }

                foreach (string lang in languages)
                {
                    int itemId = comboBoxLanguages.Items.Add(lang);
                    if (string.Compare(language, lang, true) == 0)
                    {
                        comboBoxLanguages.SelectedIndex = itemId;
                    }
                }

                if (comboBoxLanguages.SelectedIndex == -1)
                {
                    comboBoxLanguages.SelectedIndex = 0;
                }

                checkBoxLocalizeEngine.Checked  = localizeEngine;
                checkBoxLocalizeToolset.Checked = localizeToolset;
            }

            Translate();

            formLoaded = true;
        }