void AddDynamicOption(IConfigToggle toggle) { if (toggle.IsOn) { var targetIndex = Package.Tabs[0].Options.IndexOf("toggle8") + 1; var dynamicOption = new ConfigToggle("toggle9", "Added dynamically!", false); Package.Tabs[0].Options.Insert(targetIndex, dynamicOption); dynamicOption.StateDidChange += AddDynamicTab; } else { Package.Tabs[0].Options.Remove("toggle9"); } }
private void GenerateOptions(TabbedOptionsPackage options, ModConfig config) { var firstTab = new OptionsTab("main", "Main"); options.Tabs.Add(firstTab); var enableDrop = new ConfigToggle("enableDrop", "Enable Dropdown", config.enableDropdown); firstTab.Options.Add(enableDrop); var choices = new List <ISelectionChoice> { new SelectionChoice("none", "None"), new SelectionChoice("5", "Checkbox 5", "Hover text for Checkbox 5"), new SelectionChoice("6", "Checkbox 6", "Hover text for Checkbox 6"), new SelectionChoice("7", "Checkbox 7", "Hover text for Checkbox 7") }; var dropdown = new ConfigSelection("drop", "Disable Another Option", choices, config.dropdownChoice, config.enableDropdown); dropdown.SelectionDidChange += Dropdown_SelectionDidChange;; firstTab.Options.Add(dropdown); enableDrop.StateDidChange += (toggle) => { dropdown.Enabled = toggle.IsOn; }; var checkbox2 = new ConfigToggle("toggle2", "Add checkbox 9", config.checkbox2); firstTab.Options.Add(checkbox2); checkbox2.StateDidChange += AddDynamicOption; firstTab.Options.Add(new ConfigToggle("toggle3", "Checkbox 3", false)); var slider = new ConfigRange("range", "Slider", 10, 25, 1, config.rangeValue, true); var stepper = new ConfigStepper("stepper", "Plus/Minus Controls", (decimal)5.0, (decimal)105.0, (decimal)1.5, config.stepperValue, RangeDisplayType.PERCENT); firstTab.Options.Add(slider); firstTab.Options.Add(stepper); firstTab.Options.Add(new ConfigToggle("stepperCheck", "Show Stepper Value", false)); firstTab.Options.Add(new ConfigToggle("toggle5", "Checkbox 5")); firstTab.Options.Add(new ConfigToggle("toggle6", "Checkbox 6")); firstTab.Options.Add(new ConfigToggle("toggle7", "Checkbox 7")); firstTab.Options.Add(new ConfigToggle("toggle8", "Checkbox 8")); var saveButton = new ConfigAction("okButton", "OK Button", ButtonType.OK); firstTab.Options.Add(saveButton); saveButton.ActionWasTriggered += SaveButton_ActionWasTriggered; GraphicsEvents.OnPostRenderEvent += (sender, e) => { if (firstTab.GetOption <IConfigToggle>("toggle3").IsOn) { Game1.spriteBatch.DrawString(Game1.dialogueFont, "Cool!", new Vector2(Game1.getMouseX(), Game1.getMouseY()), Color.Black); } if (firstTab.GetOption <IConfigToggle>("stepperCheck").IsOn) { Game1.spriteBatch.DrawString(Game1.dialogueFont, stepper.Value.ToString(), new Vector2(Game1.getMouseX(), Game1.getMouseY() + 12 * Game1.pixelZoom), Color.Black); } }; var secondTab = new OptionsTab("second", "Second"); secondTab.Options.Add(new ConfigHeader("secondTabHeader", "Second Tab!")); options.Tabs.Add(secondTab); }
void LoadMenu(object sender, EventArgs e) { Settings = Helper.ModRegistry.GetApi <IConfigMenu>("Juice805.StardewConfigMenu"); Package = new SimpleOptionsPackage(this); var config = Helper.ReadConfig <TestConfig>(); Settings.AddOptionsPackage(Package); var testbox = new ConfigToggle("checkbox", "Checkbox", config.checkbox); Package.AddOption(testbox); var emptyDropdown = new ConfigSelection("emptyDropdown", "Empty Dropdowns are disabled"); Package.AddOption(emptyDropdown); testbox.StateDidChange += (toggle) => { emptyDropdown.Enabled = toggle.IsOn; // should not do anything }; var list = new List <ISelectionChoice>(); list.Add(new SelectionChoice("first", "First", "This is the first option!")); list.Add(new SelectionChoice("second", "Second", "This is the Second option!")); list.Add(new SelectionChoice("third", "Third")); list.Add(new SelectionChoice("fourth", "Fourth")); var filledDropdown = new ConfigSelection("filledDropdown", "Filled Dropdown", list, config.filledDropown, true); Package.AddOption(filledDropdown); var stepper = new ConfigStepper("stepper", "Plus/Minus Controls", (decimal)5.0, (decimal)105.0, (decimal)1.5, config.stepperValue, RangeDisplayType.PERCENT); Package.AddOption(stepper); var label = new ConfigHeader("catlabel", "Category Label"); Package.AddOption(label); var button = new ConfigAction("setButton", "Click Me!", ButtonType.SET); button.ActionWasTriggered += (identifier) => { filledDropdown.Enabled = !filledDropdown.Enabled; }; Package.AddOption(button); var tranformingButton = new ConfigAction("clearButton", "Clear Button", ButtonType.CLEAR); tranformingButton.ButtonType = ButtonType.CLEAR; tranformingButton.ActionWasTriggered += (identifier) => { switch (tranformingButton.ButtonType) { case ButtonType.CLEAR: tranformingButton.Label = "Are you sure?"; tranformingButton.ButtonType = ButtonType.OK; break; case ButtonType.OK: tranformingButton.Label = "Cleared"; tranformingButton.ButtonType = ButtonType.DONE; break; case ButtonType.DONE: tranformingButton.Label = "Clear Button"; tranformingButton.ButtonType = ButtonType.CLEAR; break; default: tranformingButton.Label = "Clear Button"; tranformingButton.ButtonType = ButtonType.CLEAR; break; } }; Package.AddOption(tranformingButton); Package.AddOption(new ConfigAction("doneButton", "Done Button", ButtonType.DONE)); Package.AddOption(new ConfigAction("giftButton", "Gift Button", ButtonType.GIFT)); var saveButton = new ConfigAction("okButton", "OK Button", ButtonType.OK); Package.AddOption(saveButton); saveButton.ActionWasTriggered += (_) => { SaveConfig(); }; }