public new void Remove(Button button) { // Remove button links if (button != null) { button.OnActiveStateChanged -= OnActiveStateChanged; if (LinkedContainers.ContainsKey(button)) { if (button.CurrentButtonType == Button.ButtonType.Addon) { // Remove all sub menu buttons foreach (var subButton in GetSubMenus(button)) { Remove(subButton); } } // Base remove button base.Remove(button); MainMenu.Instance.Remove(LinkedContainers[button].Item1); MainMenu.Instance.Remove(LinkedContainers[button].Item2); LinkedContainers.Remove(button); } } }
internal ValueContainer AddSubMenu(Button parent, Button subButton, string addonId, string uniqueMenuId, string longTitle = null) { if (parent == null) { throw new ArgumentNullException("parent"); } if (subButton == null) { throw new ArgumentNullException("subButton"); } if (!LinkedContainers.ContainsKey(parent)) { throw new ArgumentException("parent was not added to the menu yet!", "parent"); } if (parent.CurrentButtonType != Button.ButtonType.Addon) { throw new ArgumentException(string.Format("parent is of type {0}, which is invalid", parent.CurrentButtonType), "parent"); } if (subButton.CurrentButtonType != Button.ButtonType.AddonSub) { throw new ArgumentException(string.Format("subButton is of type {0}, which is invalid", subButton.CurrentButtonType), "subButton"); } var index = Children.FindIndex(o => o == parent) + 1; while (Children.Count > index && Children[index].CurrentButtonType == Button.ButtonType.AddonSub) { index++; } return(AddMenu(subButton, addonId, uniqueMenuId, string.Format("{0} :: {1}", LinkedContainers[parent].Item1.TextObjects[0].TextValue, longTitle ?? subButton.TextValue), index)); }
internal ValueContainer AddMenu(Button button, string addonId, string uniqueMenuId, string longTitle = null, int index = -1) { if (button == null) { throw new ArgumentNullException("button"); } if (uniqueMenuId == null) { throw new ArgumentNullException("uniqueMenuId"); } // Add button to Children if (!Children.Contains(button)) { button.SetParent(this); Children.Insert(index >= 0 ? index : Children.Count, button); RecalculateAlignOffsets(); } // TODO: Improve button.TextHandle.Size = button.Size - new Vector2(button.TextHandle.Padding.X * 2f, 0); // Listen to state changes button.OnActiveStateChanged += OnActiveStateChanged; // Create a new control container for the button var container = new ValueContainer(addonId, uniqueMenuId) { IsVisible = false }; MainMenu.Instance.Add(container); // Create a new emtpry control for the text handle var textHolder = new EmptyControl(ThemeManager.SpriteType.FormContentHeader) { IsVisible = false }; textHolder.TextObjects.Add(new Text(longTitle ?? button.TextValue, new FontDescription { FaceName = "Gill Sans MT Pro Medium", Height = 20, Quality = FontQuality.Antialiased, Weight = FontWeight.ExtraBold }) { TextAlign = Text.Align.Left, TextOrientation = Text.Orientation.Center, Color = System.Drawing.Color.FromArgb(255, 143, 122, 72) }); MainMenu.Instance.Add(textHolder); // Associate button with container and long title text handle LinkedContainers.Add(button, new Tuple <Control, ControlContainer <ValueBase> >(textHolder, container)); // Return container return(container); }
internal void SetContentView(Button button, bool state) { if (LinkedContainers.ContainsKey(button)) { LinkedContainers[button].Item1.IsVisible = state; LinkedContainers[button].Item2.IsVisible = state; } }