示例#1
0
        public void SetScriptTags(IEnumerable <string> tags)
        {
            changesBox.Text = ModStore.GetModOptionSummary(mod, tags, true);
            if (changesBox.Text.Length == 0)
            {
                changesBox.Text = "All options are set to their default value.";
            }
            try
            {
                foreach (var setOption in Mod.GetModOptionPairs(tags))
                {
                    var control = optionControls[setOption.Key];
                    var option  = options[setOption.Key];
                    switch (option.Type)
                    {
                    case OptionType.Bool:
                        var box = (CheckBox)control;
                        box.Checked = setOption.Value != "0";
                        break;

                    case OptionType.List:
                    {
                        var optionIndex = option.ListOptions.IndexOf(option.ListOptions.Single(o => o.Key == setOption.Value));
                        var comboBox    = (ComboBox)control;
                        comboBox.SelectedIndex = optionIndex;
                    }
                    break;

                    case OptionType.Number:
                    {
                        var numeric = (NumericUpDown)control;
                        numeric.Value = decimal.Parse(setOption.Value, CultureInfo.InvariantCulture).Constrain(numeric.Minimum, numeric.Maximum);
                        break;
                    }

                    case OptionType.String:
                        control.Text = setOption.Value;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Trace.TraceError("Error in setting mod options: " + e);
            }
        }
        public void SetModOptions(Dictionary <string, string> modOptions = null)
        {
            if (offlineMode)
            {
                if (offlineOptions.Count == 0)
                {
                    changesBox.Text = "All options are set to their default value.";
                }
                else
                {
                    var optionBuilder = new System.Text.StringBuilder();
                    optionBuilder.AppendLine();
                    foreach (var setOption in offlineOptions)
                    {
                        optionBuilder.AppendLine("\t" + setOption.Key + " = " + setOption.Value);
                    }
                    changesBox.Text = optionBuilder.ToString();
                }
            }
            else
            {
                changesBox.Text = ModStore.GetModOptionSummary(mod, modOptions, true);
                if (changesBox.Text.Length == 0)
                {
                    changesBox.Text = "All options are set to their default value.";
                }
            }
            try
            {
                Dictionary <string, string> optionPairs;
                if (offlineMode)
                {
                    optionPairs = offlineOptions;
                }
                else
                {
                    optionPairs = modOptions;
                }

                foreach (var setOption in optionPairs)
                {
                    var control = optionControls[setOption.Key];
                    var option  = options[setOption.Key];
                    switch (option.Type)
                    {
                    case OptionType.Bool:
                        var box = (CheckBox)control;
                        box.Checked = setOption.Value != "0";
                        break;

                    case OptionType.List:
                    {
                        var optionIndex = option.ListOptions.IndexOf(option.ListOptions.Single(o => o.Key == setOption.Value));
                        var comboBox    = (ComboBox)control;
                        comboBox.SelectedIndex = optionIndex;
                    }
                    break;

                    case OptionType.Number:
                    {
                        var numeric = (NumericUpDown)control;
                        numeric.Value = decimal.Parse(setOption.Value, CultureInfo.InvariantCulture).Constrain(numeric.Minimum, numeric.Maximum);
                        break;
                    }

                    case OptionType.String:
                        control.Text = setOption.Value;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Trace.TraceError("Error in setting mod options: " + e);
            }
        }