Esempio n. 1
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();
        }
Esempio n. 2
0
        ///////////////////////////////////////////

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

            ComboBox  comboBox;
            ScrollBar scrollBar;
            CheckBox  checkBox;

            window = ControlDeclarationManager.Instance.CreateControl(Dialogs.Options);
            Controls.Add(window);

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

            ((Button)window.Controls["Options"].Controls["Quit"]).Click += delegate(Button sender)
            {
                SetShouldDetach();
            };

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

                Vec2I currentMode = EngineApp.Instance.VideoMode;

                //screenResolutionComboBox
                comboBox           = (ComboBox)pageVideo.Controls["ScreenResolution"];
                comboBox.Enable    = !EngineApp.Instance.WebPlayerMode && !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       = !EngineApp.Instance.WebPlayerMode;
                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;
                        }
                    };
                }

                //ShadowTechnique
                {
                    comboBox = (ComboBox)pageVideo.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)pageVideo.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)pageVideo.Controls["ShadowFarDistance"]).Value =
                                GameEngineApp.ShadowFarDistance;

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

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

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

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

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

                //ShadowColor
                scrollBar       = (ScrollBar)pageVideo.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)pageVideo.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)pageVideo.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)pageVideo.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)pageVideo.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)pageVideo.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;
                    };
                }

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

                //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;
                };
            }

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

                Control pageSound = window.Controls["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 = window.Controls["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();
            }
        }