Exemple #1
0
        public void LoadSettings(bool silent)
        {
            // Load the settings from the XML file
            if (_tempEnvironment != "")
            {
                Settings.Environment = _tempEnvironment;
            }
            Settings.LoadEnvironment();
            Settings.Load(silent);

            if (_tempEnvironment == "")
            {
                Environment.SelectedItem = Settings.Environment;
            }
            EnvironmentLoading.SelectedItem = Settings.EnvironmentLoading;

            _isLoading = true;

            // Populate the controls on the UI with the values from the settings
            // Through the wonders of Reflection this is an automated process
            Type type = typeof(Settings);

            PropertyInfo[] props = type.GetProperties();
            foreach (var p in props)
            {
                if (p.Name == "DirtyData")
                {
                    continue;
                }
                if (p.Name == "Environment")
                {
                    continue;
                }
                if (p.Name == "EnvironmentLoading")
                {
                    continue;
                }

                PropertyInfo pInfo     = type.GetProperty(p.Name);
                object       propValue = pInfo.GetValue(p.Name, null);

                foreach (TabPage tab in tabControl1.Controls)
                {
                    foreach (GroupBox gb in tab.Controls)
                    {
                        foreach (object obj in gb.Controls)
                        {
                            // Populate all combo boxes, this will be the most common
                            if (obj is ComboBox)
                            {
                                ComboBox cbox = (ComboBox)obj;
                                if (cbox.Name == p.Name)
                                {
                                    cbox.SelectedItem = propValue.ToString();
                                    break;
                                }
                            }

                            // Populate all progress bars, mostly for health or mana
                            else if (obj is ProgressBar)
                            {
                                ProgressBar pbar = (ProgressBar)obj;
                                if (pbar.Name == p.Name)
                                {
                                    pbar.Value = (int)propValue;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            _isLoading = false;
        }