private void AddAllowedStashTabNode(StashTabNode node) { var deleteTabButton = new ButtonNode(); var deleteTabButtonDrawer = new ButtonSettingDrawer(deleteTabButton, "Delete", GetUniqDrawerId()); AllowedStashTabsRoot.Children.Insert(AllowedStashTabsRoot.Children.Count - 1, deleteTabButtonDrawer); var buttonSameLineDrawer = new SameLineSettingDrawer("", GetUniqDrawerId());//Delete button and stash node should be on same line AllowedStashTabsRoot.Children.Insert(AllowedStashTabsRoot.Children.Count - 1, buttonSameLineDrawer); var stashNodeDrawer = new StashTabNodeSettingDrawer(node, "", GetUniqDrawerId()); AllowedStashTabsRoot.Children.Insert(AllowedStashTabsRoot.Children.Count - 1, stashNodeDrawer);//AllowedStashTabsRoot.Children.Count - 1, deleteTabButton.OnPressed += delegate { //Delete stash node related drawers AllowedStashTabsRoot.Children.Remove(deleteTabButtonDrawer); AllowedStashTabsRoot.Children.Remove(buttonSameLineDrawer); AllowedStashTabsRoot.Children.Remove(stashNodeDrawer); Settings.AllowedStashTabs.Remove(stashNodeDrawer.StashNode); StashTabController.UnregisterStashNode(stashNodeDrawer.StashNode);//No sence to update data in deleted stash node }; StashTabController.RegisterStashNode(node); }
private List <StashTabNode> StashTabNodes = new List <StashTabNode>(); //This is for hot reload, we will unload it private void GenerateStashieSettingsMenu() //Separate func cuz we can call it in anu moment to reload all menu { if (FiltersMenuRootMenu != null) { SettingsDrawers.Remove(FiltersMenuRootMenu); } if (RefillMenuRootMenu != null) { SettingsDrawers.Remove(RefillMenuRootMenu); } FiltersMenuRootMenu = new BaseSettingsDrawer("Filters", GetUniqDrawerId()); SettingsDrawers.Add(FiltersMenuRootMenu); var submenu = new Dictionary <string, BaseSettingsDrawer>(); foreach (var customFilter in _customFilters) { if (!Settings.FilterOptions.TryGetValue(customFilter.Name, out var tabNode)) { tabNode = new StashTabNode(); Settings.FilterOptions.Add(customFilter.Name, tabNode); } StashTabNodes.Add(tabNode); StashTabController.RegisterStashNode(tabNode); var filterParent = FiltersMenuRootMenu; if (!string.IsNullOrEmpty(customFilter.SubmenuName)) { if (!submenu.TryGetValue(customFilter.SubmenuName, out filterParent)) { filterParent = new BaseSettingsDrawer(customFilter.SubmenuName, GetUniqDrawerId()); FiltersMenuRootMenu.Children.Add(filterParent); submenu.Add(customFilter.SubmenuName, filterParent); } } filterParent.Children.Add(new StashTabNodeSettingDrawer(tabNode, customFilter.Name, GetUniqDrawerId())); customFilter.StashIndexNode = tabNode; } RefillMenuRootMenu = new CheckboxSettingDrawer(Settings.RefillCurrency, "Refill Currency", GetUniqDrawerId()); SettingsDrawers.Add(RefillMenuRootMenu); RefillMenuRootMenu.Children.Add(new StashTabNodeSettingDrawer(Settings.CurrencyStashTab, "Currency Tab", GetUniqDrawerId())); StashTabController.RegisterStashNode(Settings.CurrencyStashTab); RefillMenuRootMenu.Children.Add(new CheckboxSettingDrawer(Settings.AllowHaveMore, "Allow Have More", GetUniqDrawerId())); var refillRoot = new BaseSettingsDrawer("Refills:", GetUniqDrawerId()); RefillMenuRootMenu.Children.Add(refillRoot); var addTabButton = new ButtonNode(); var addTabButtonDrawer = new ButtonSettingDrawer(addTabButton, "Add Refill", GetUniqDrawerId()); RefillMenuRootMenu.Children.Add(addTabButtonDrawer); addTabButton.OnPressed += delegate { var newRefill = new RefillProcessor(); AddRefill(newRefill); Settings.Refills.Add(newRefill); }; foreach (var refill in Settings.Refills) { AddRefill(refill); } }
internal void InitializeSettingsMenu(bool ignoreAttribute = false)//ignoreAttribute - for Core plugins { SettingPropertyDrawers.Clear(); StashTabNodesToUnload.ForEach(x => StashTabController.UnregisterStashNode(x)); StashTabNodesToUnload.Clear(); var settingsProps = Settings.GetType().GetProperties(); foreach (var property in settingsProps) { if (property.Name == "Enable") { continue; } if (property.GetCustomAttribute <IgnoreMenuAttribute>() != null) { continue; } var menuAttrib = property.GetCustomAttribute <MenuAttribute>(); if (ignoreAttribute && menuAttrib == null) { menuAttrib = new MenuAttribute(System.Text.RegularExpressions.Regex.Replace(property.Name, "(\\B[A-Z])", " $1"));//fix camel case } if (menuAttrib != null) { BaseSettingsDrawer drawer = null; int drawerId = menuAttrib.index == -1 ? GetUniqDrawerId() : menuAttrib.index; if (DrawersIds.Contains(drawerId)) { BasePlugin.LogError($"{PluginName}: Already contain settings child with id {menuAttrib.parentIndex}. Fixed by giving a new uniq ID. Property " + property.Name, 5); // drawer.SettingId = GetUniqDrawerId(); } var propType = property.PropertyType; if (propType == typeof(ButtonNode) || propType.IsSubclassOf(typeof(ButtonNode))) { drawer = new ButtonSettingDrawer(property.GetValue(Settings) as ButtonNode, menuAttrib.MenuName, drawerId); } else if (propType == typeof(TextNode) || propType.IsSubclassOf(typeof(TextNode))) { drawer = new TextSettingsDrawer(property.GetValue(Settings) as TextNode, menuAttrib.MenuName, drawerId); } else if (propType == typeof(EmptyNode) || propType.IsSubclassOf(typeof(EmptyNode))) { drawer = new LabelSettingDrawer(menuAttrib.MenuName, drawerId); } else if (propType == typeof(HotkeyNode) || propType.IsSubclassOf(typeof(HotkeyNode))) { drawer = new HotkeySettingDrawer(property.GetValue(Settings) as HotkeyNode, menuAttrib.MenuName, drawerId); } else if (propType == typeof(ToggleNode) || propType.IsSubclassOf(typeof(ToggleNode))) { drawer = new CheckboxSettingDrawer(property.GetValue(Settings) as ToggleNode, menuAttrib.MenuName, drawerId); } else if (propType == typeof(ColorNode) || propType.IsSubclassOf(typeof(ColorNode))) { drawer = new ColorSettingDrawer(property.GetValue(Settings) as ColorNode, menuAttrib.MenuName, drawerId); } else if (propType == typeof(ListNode) || propType.IsSubclassOf(typeof(ListNode))) { drawer = new ComboBoxSettingDrawer(property.GetValue(Settings) as ListNode, menuAttrib.MenuName, drawerId); } else if (propType == typeof(FileNode) || propType.IsSubclassOf(typeof(FileNode))) { drawer = new FilePickerDrawer(property.GetValue(Settings) as FileNode, menuAttrib.MenuName, drawerId); } else if (propType == typeof(StashTabNode) || propType.IsSubclassOf(typeof(StashTabNode))) { var stashNode = property.GetValue(Settings) as StashTabNode; StashTabNodesToUnload.Add(stashNode); StashTabController.RegisterStashNode(stashNode); drawer = new StashTabNodeSettingDrawer(stashNode, menuAttrib.MenuName, drawerId); } else if (propType.IsGenericType) { var genericType = propType.GetGenericTypeDefinition(); if (genericType == typeof(RangeNode <>)) { var genericParameter = propType.GenericTypeArguments; if (genericParameter.Length > 0) { var argType = genericParameter[0]; var valueDrawer = new CustomSettingsDrawer(menuAttrib.MenuName, drawerId); if (argType == typeof(int)) { var rangeInt = property.GetValue(Settings) as RangeNode <int>; valueDrawer.DrawDelegate = delegate { rangeInt.Value = ImGuiExtension.IntSlider(valueDrawer.ImguiUniqLabel, rangeInt.Value, rangeInt.Min, rangeInt.Max); }; } else if (argType == typeof(float)) { var rangeInt = property.GetValue(Settings) as RangeNode <float>; valueDrawer.DrawDelegate = delegate { rangeInt.Value = ImGuiExtension.FloatSlider(valueDrawer.ImguiUniqLabel, rangeInt.Value, rangeInt.Min, rangeInt.Max); }; } else if (argType == typeof(double)) { var rangeInt = property.GetValue(Settings) as RangeNode <double>; valueDrawer.DrawDelegate = delegate { rangeInt.Value = ImGuiExtension.FloatSlider(valueDrawer.ImguiUniqLabel, (float)rangeInt.Value, (float)rangeInt.Min, (float)rangeInt.Max); }; } else if (argType == typeof(byte)) { var rangeInt = property.GetValue(Settings) as RangeNode <byte>; valueDrawer.DrawDelegate = delegate { rangeInt.Value = (byte)ImGuiExtension.IntSlider(valueDrawer.ImguiUniqLabel, rangeInt.Value, rangeInt.Min, rangeInt.Max); }; } else if (argType == typeof(long)) { var rangeInt = property.GetValue(Settings) as RangeNode <long>; valueDrawer.DrawDelegate = delegate { rangeInt.Value = ImGuiExtension.IntSlider(valueDrawer.ImguiUniqLabel, (int)rangeInt.Value, (int)rangeInt.Min, (int)rangeInt.Max); }; } else if (argType == typeof(short)) { var rangeInt = property.GetValue(Settings) as RangeNode <short>; valueDrawer.DrawDelegate = delegate { rangeInt.Value = (short)ImGuiExtension.IntSlider(valueDrawer.ImguiUniqLabel, rangeInt.Value, rangeInt.Min, rangeInt.Max); }; } else if (argType == typeof(ushort)) { var rangeInt = property.GetValue(Settings) as RangeNode <ushort>; valueDrawer.DrawDelegate = delegate { rangeInt.Value = (ushort)ImGuiExtension.IntSlider(valueDrawer.ImguiUniqLabel, rangeInt.Value, rangeInt.Min, rangeInt.Max); }; } else if (argType == typeof(Vector2)) { var vect = property.GetValue(Settings) as RangeNode <Vector2>; valueDrawer.DrawDelegate = delegate { var val = vect.Value; ImGui.SliderVector2(valueDrawer.ImguiUniqLabel, ref val, vect.Min.X, vect.Max.X, "%.0f", 1); vect.Value = val; }; } else { BasePlugin.LogError($"{PluginName}: Generic node argument for range node '{argType.Name}' is not defined in code. Range node type: " + propType.Name, 5); } drawer = valueDrawer; } else { BasePlugin.LogError($"{PluginName}: Can't get GenericTypeArguments from option type: " + propType.Name, 5); } } else { BasePlugin.LogError($"{PluginName}: Generic option node is not defined in code: " + genericType.Name, 5); } } else { BasePlugin.LogError($"{PluginName}: Type of option node is not defined: " + propType.Name, 5); } if (drawer != null) { drawer.SettingTooltip = menuAttrib.Tooltip; if (menuAttrib.parentIndex != -1) { var parent = GetAllDrawers().Find(x => x.SettingId == menuAttrib.parentIndex); if (parent != null) { parent.Children.Add(drawer); continue; } BasePlugin.LogError($"{PluginName}: Can't find child with id {menuAttrib.parentIndex} to parent node. Property " + property.Name, 5); } SettingPropertyDrawers.Add(drawer); } else { BasePlugin.LogError($"{PluginName}: Type of option node is not defined: " + propType.Name, 5); } } } }