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

                {
                    int levels = RendererWorld.InitializationOptions.TextureSkipMipLevels;
                    //get value from Engine.config.
                    if (rendererBlock != null && rendererBlock.IsAttributeExist("textureSkipMipLevels"))
                    {
                        levels = int.Parse(rendererBlock.GetAttribute("textureSkipMipLevels"));
                    }

                    comboBox = (ComboBox)pageVideo.Controls["TextureSkipMipLevels"];
                    for (int n = 0; n <= 7; n++)
                    {
                        comboBox.Items.Add(n);
                        if (levels == n)
                        {
                            comboBox.SelectedIndex = comboBox.Items.Count - 1;
                        }
                    }
                    if (comboBox.SelectedIndex < 0)
                    {
                        comboBox.SelectedIndex = 0;
                    }

                    comboBox.SelectedIndexChange += comboBoxTextureSkipMipLevels_SelectedIndexChange;
                }

                //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"));

                    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 < 4; n++)
                    {
                        comboBox.Items.Add(n);
                        if (n == 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 < 4; n++)
                    {
                        comboBox.Items.Add(n);
                        if (n == 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();
        }
        public GameModeSelection()
        {
            var groupBox = new GroupBox()
            {
                Text = "Выберите режим игры",
                Font = new Font("Arial", 10)
            };

            var gameSettingsLabel = new Label
            {
                Text = "Настройки игры",
                Font = new Font("Arial", 14, FontStyle.Bold)
            };

            var typeBallsCountLabel = new Label
            {
                Text = "Количество шаров на поле: " + ballsCount,
                Font = new Font("Arial", 10)
            };

            var playerCountLabel = new Label
            {
                Text = "Выберите количество игроков:",
                Font = new Font("Arial", 10)
            };

            var selectGametimeLabel = new Label
            {
                Text = "Продолжительность игры в минутах:",
                Font = new Font("Arial", 10)
            };

            var selectFormSizeLabel = new Label
            {
                Text = "Выберите ширину и высоту игрового поля:",
                Font = new Font("Arial", 10)
            };

            var controlsHelpButton = new Button
            {
                Text = "?",
                Font = new Font("Arial", 10, FontStyle.Bold)
            };

            var startGameButton = new Button
            {
                Text = "Начать игру",
            };

            var gameMode1 = new RadioButton()
            {
                Text    = "Игра на очки",
                Checked = true
            };

            var gameMode2 = new RadioButton()
            {
                Text = "Захват флага"
            };

            var rb1 = new RadioButton()
            {
                Text    = "1",
                Checked = true
            };
            var rb2 = new RadioButton()
            {
                Text = "2"
            };
            var rb3 = new RadioButton()
            {
                Text = "3"
            };
            var rb4 = new RadioButton()
            {
                Text = "4"
            };

            var ballsCountTrackBar = new TrackBar
            {
                Maximum   = 200,
                Minimum   = 10,
                TickStyle = TickStyle.None
            };

            var sizesArray    = new object[14];
            var gametimeArray = new object[14];

            for (int i = 0; i < 14; i++)
            {
                sizesArray[i]    = i * 100;
                gametimeArray[i] = i;
            }

            var formWidthComboBox = new ComboBox
            {
                DropDownStyle    = ComboBoxStyle.DropDownList,
                MaxDropDownItems = 4,
            };

            formWidthComboBox.Items.AddRange(sizesArray.Skip(3).ToArray());
            formWidthComboBox.SelectedIndex = 4;

            var formHeightComboBox = new ComboBox
            {
                DropDownStyle    = ComboBoxStyle.DropDownList,
                MaxDropDownItems = 4,
            };

            formHeightComboBox.Items.AddRange(sizesArray.Skip(3).ToArray());
            formHeightComboBox.SelectedIndex = 3;

            var gametimeComboBox = new ComboBox
            {
                DropDownStyle    = ComboBoxStyle.DropDownList,
                MaxDropDownItems = 4,
            };

            gametimeComboBox.Items.AddRange(gametimeArray.Skip(1).ToArray());
            gametimeComboBox.SelectedIndex = 2;

            rb1.CheckedChanged += (sender, args) => playersCountSelection = 1;
            rb2.CheckedChanged += (sender, args) => playersCountSelection = 2;
            rb3.CheckedChanged += (sender, args) => playersCountSelection = 3;
            rb4.CheckedChanged += (sender, args) => playersCountSelection = 4;

            gameMode1.CheckedChanged += (sender, args) => gameMode = GameModes.MaxScore;
            gameMode2.CheckedChanged += (sender, args) => gameMode = GameModes.CaptureTheFlag;

            controlsHelpButton.Click += ControlsHelpButton_Click;

            startGameButton.Click += StartGameButton_Click;

            formWidthComboBox.SelectedIndexChanged  += (sender, args) => selectedFormWidth = (int)formWidthComboBox.SelectedItem;
            formHeightComboBox.SelectedIndexChanged += (sender, args) => selectedFormHeight = (int)formHeightComboBox.SelectedItem;
            gametimeComboBox.SelectedIndexChanged   += (sender, args) => selectedGametime = (int)gametimeComboBox.SelectedItem;

            ballsCountTrackBar.ValueChanged += (sender, args) =>
            {
                var userInput = sender as TrackBar;
                ballsCount = userInput.Value;
                typeBallsCountLabel.Text = "Количество шаров на поле: " + ballsCount;
            };

            Controls.Add(gameSettingsLabel);
            Controls.Add(gameMode1);
            Controls.Add(gameMode2);
            Controls.Add(typeBallsCountLabel);
            Controls.Add(playerCountLabel);
            Controls.Add(selectGametimeLabel);
            Controls.Add(startGameButton);
            Controls.Add(controlsHelpButton);
            Controls.Add(ballsCountTrackBar);
            Controls.Add(selectFormSizeLabel);
            Controls.Add(rb1);
            Controls.Add(rb2);
            Controls.Add(rb3);
            Controls.Add(rb4);
            Controls.Add(groupBox);
            groupBox.Controls.Add(gameMode1);
            groupBox.Controls.Add(gameMode2);
            Controls.Add(formWidthComboBox);
            Controls.Add(formHeightComboBox);
            Controls.Add(gametimeComboBox);

            SizeChanged += (sender, args) =>
            {
                var labelHight  = 20;
                var buttonHight = 40;
                var margin      = 5;

                gameSettingsLabel.Location = new Point(0, ClientSize.Height / 20);
                gameSettingsLabel.Size     = new Size(ClientSize.Width, labelHight);
                groupBox.Location          = new Point(0, gameSettingsLabel.Bottom + margin);
                groupBox.Size             = new Size(ClientSize.Width, 50);
                gameMode1.Location        = new Point(margin, labelHight);
                gameMode1.Size            = new Size(buttonHight * 4, labelHight);
                gameMode2.Location        = new Point(gameMode1.Right, labelHight);
                gameMode2.Size            = gameMode1.Size;
                playerCountLabel.Location = new Point(0, groupBox.Bottom + margin);
                playerCountLabel.Size     = new Size(ClientSize.Width, 20);
                rb1.Location = new Point(margin, playerCountLabel.Bottom);
                rb1.Size     = new Size(2 * labelHight, labelHight);
                rb2.Location = new Point(rb1.Right, playerCountLabel.Bottom);
                rb2.Size     = rb1.Size;
                rb3.Location = new Point(rb2.Right, playerCountLabel.Bottom);
                rb3.Size     = rb1.Size;
                rb4.Location = new Point(rb3.Right, playerCountLabel.Bottom);
                rb4.Size     = rb1.Size;
                controlsHelpButton.Location  = new Point(rb4.Right + margin, playerCountLabel.Bottom);
                controlsHelpButton.Size      = new Size(20, 20);
                typeBallsCountLabel.Location = new Point(0, rb1.Bottom + margin);
                typeBallsCountLabel.Size     = playerCountLabel.Size;
                ballsCountTrackBar.Location  = new Point(margin, typeBallsCountLabel.Bottom);
                ballsCountTrackBar.Size      = new Size(ClientSize.Width - margin * 3, labelHight);
                selectFormSizeLabel.Location = new Point(0, ballsCountTrackBar.Bottom);
                selectFormSizeLabel.Size     = playerCountLabel.Size;
                formWidthComboBox.Location   = new Point(margin, selectFormSizeLabel.Bottom);
                formHeightComboBox.Location  = new Point(formWidthComboBox.Right + 2 * margin, selectFormSizeLabel.Bottom);
                selectGametimeLabel.Location = new Point(0, formWidthComboBox.Bottom + 2 * margin);
                selectGametimeLabel.Size     = selectFormSizeLabel.Size;
                gametimeComboBox.Location    = new Point(selectGametimeLabel.Right - 3 * labelHight - margin, formWidthComboBox.Bottom + 2 * margin - 1);
                gametimeComboBox.Size        = new Size(buttonHight, 10);
                gametimeComboBox.BringToFront();
                startGameButton.Location = new Point(0, gametimeComboBox.Bottom + 2 * margin);
                startGameButton.Size     = new Size(ClientSize.Width, buttonHight);
            };

            Load           += (sender, args) => OnSizeChanged(EventArgs.Empty);
            StartPosition   = FormStartPosition.CenterScreen;
            ClientSize      = new Size(300, 400);
            FormClosed     += (sender, args) => Application.Exit();
            FormBorderStyle = FormBorderStyle.FixedSingle;
            MaximizeBox     = false;
        }
Esempio n. 3
0
        //

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

            instance = this;

            viewport = RendererWorld.Instance.DefaultViewport;

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

            for (int n = 0; n < scrollBarFloatParameters.Length; n++)
            {
                scrollBarFloatParameters[n] = (EScrollBar)window.Controls[
                    "FloatParameter" + n.ToString()];
                scrollBarFloatParameters[n].ValueChange += floatParameter_ValueChange;
            }
            for (int n = 0; n < checkBoxBoolParameters.Length; n++)
            {
                checkBoxBoolParameters[n] = (ECheckBox)window.Controls["BoolParameter" + n.ToString()];
                checkBoxBoolParameters[n].CheckedChange += boolParameter_CheckedChange;
            }

            listBox = (EListBox)window.Controls["List"];
            listBox.Items.Add("HDR");
            listBox.Items.Add("LDRBloom");
            listBox.Items.Add("Glass");
            listBox.Items.Add("OldTV");
            listBox.Items.Add("HeatVision");
            listBox.Items.Add("MotionBlur");
            listBox.Items.Add("RadialBlur");
            listBox.Items.Add("Blur");
            listBox.Items.Add("Grayscale");
            listBox.Items.Add("Invert");
            listBox.Items.Add("Tiling");

            listBox.SelectedIndexChange += listBox_SelectedIndexChange;

            checkBoxEnabled        = (ECheckBox)window.Controls["Enabled"];
            checkBoxEnabled.Click += checkBoxEnabled_Click;

            for (int n = 0; n < listBox.Items.Count; n++)
            {
                EButton   itemButton = listBox.ItemButtons[n];
                ECheckBox checkBox   = (ECheckBox)itemButton.Controls["CheckBox"];

                string name = GetListCompositorItemName((string)listBox.Items[n]);

                CompositorInstance compositorInstance = viewport.GetCompositorInstance(name);
                if (compositorInstance != null && compositorInstance.Enabled)
                {
                    checkBox.Checked = true;
                }

                if (itemButton.Text == "HDR")
                {
                    checkBox.Enable = false;
                }

                checkBox.Click += listBoxCheckBox_Click;
            }

            listBox.SelectedIndex = 0;

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

            //ApplyToTheScreenGUI
            {
                ECheckBox checkBox = (ECheckBox)window.Controls["ApplyToTheScreenGUI"];
                checkBox.Checked = EngineApp.Instance.ScreenGuiRenderer.ApplyPostEffectsToScreenRenderer;
                checkBox.Click  += delegate(ECheckBox sender)
                {
                    EngineApp.Instance.ScreenGuiRenderer.ApplyPostEffectsToScreenRenderer = sender.Checked;
                };
            }
        }
        protected override void OnAttach()
        {
            base.OnAttach();

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

            MechsPriceList = (PriceListC)Entities.Instance.Create("MechPriceList", Map.Instance);
            AunitPriceList = (PriceListC)Entities.Instance.Create("AunitPriceList", Map.Instance);
            GunitPriceList = (PriceListC)Entities.Instance.Create("GunitPriceList", Map.Instance);
            JunitPriceList = (PriceListC)Entities.Instance.Create("JunitPriceList", Map.Instance);

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

            btnBuy        = (Button)window.Controls["Buy"];
            btnBuy.Click += new Button.ClickDelegate(btnBuy_Click);
            btnBuy.Enable = false;

            btnMechs       = window.Controls["MechsB"] as Button;
            btnAirUnits    = window.Controls["Aunits"] as Button;
            btnGroundUnits = window.Controls["Gunits"] as Button;
            btnJets        = window.Controls["Junits"] as Button;

            btnNext        = (Button)window.Controls["NextB"];
            btnNext.Click += new Button.ClickDelegate(btnNext_Click);

            btnPrevious        = (Button)window.Controls["PreviousB"];
            btnPrevious.Click += new Button.ClickDelegate(btnPrevious_Click);

            txtPageInfo = (TextBox)window.Controls["Pageinfo"];

            variantList = (ComboBox)window.Controls["CustomUnit"];
            variantList.Items.Add("Stock");
            variantList.SelectedIndex        = 0;
            variantList.SelectedIndexChange += new ComboBox.SelectedIndexChangeDelegate(variantList_SelectedIndexChange);

            if (mechHangar != null)
            {
                btnMechs.Click += new Button.ClickDelegate(btnMechs_Click);
            }
            else
            {
                btnMechs.Enable = false;
            }

            if (groundUnitHangar != null)
            {
                btnGroundUnits.Click += new Button.ClickDelegate(btnGroundUnits_Click);
            }
            else
            {
                btnGroundUnits.Enable = false;
            }

            if (airUnitHangar != null)
            {
                btnAirUnits.Click += new Button.ClickDelegate(btnAirUnits_Click);
            }
            else
            {
                btnAirUnits.Enable = false;
            }

            if (jetHangar != null)
            {
                btnJets.Click += new Button.ClickDelegate(btnJets_Click);
            }
            else
            {
                btnJets.Enable = false;
            }

            GetListOfPlayerUnits();

            SetupFirstList();
        }