public GuiElement(Rectangle rectangle, GuiElement parent = null, GuiContainer.Layer layer = GuiContainer.Layer.hud) { Rectangle = rectangle.WithParent(parent?.Rectangle); ParentElement = parent; Layer = layer; Parent = GuiContainer.layers[(int)layer]; }
public void Tickbox(BasePlayer player, Plugin plugin, Rectangle parentRectangle, GuiContainer.Layer layer, string name, string parentContainer, Action <BasePlayer, string[]> onTick, Action <BasePlayer, string[]> onUntick, bool initialState = false, bool disabled = false, float fadeIn = 0, float fadeOut = 0) { GuiContainer c = new GuiContainer(plugin, name + "_APITickbox", parentContainer); GuiColor lightGrey = new GuiColor(0.5f, 0.5f, 0.5f, 1); GuiColor darkGrey = new GuiColor(0.8f, 0.8f, 0.8f, 1); if (initialState) { Rectangle fgPos = new Rectangle(0.15f, 0.15f, 0.72f, 0.72f, 1f, 1f, true).WithParent(parentRectangle); c.addPlainButton("bg", parentRectangle, layer, disabled ? lightGrey : GuiColor.White, fadeIn, fadeOut, callback: disabled ? null : onUntick); c.addPlainButton("fg", fgPos, layer, disabled ? darkGrey : GuiColor.Black, fadeIn, fadeOut, callback: disabled ? null : onUntick); } else { c.addPlainButton("bg", parentRectangle, layer, disabled ? lightGrey : GuiColor.White, fadeIn, fadeOut, callback: disabled ? null : onTick); } c.display(player); }
public void dropdown(Plugin plugin, BasePlayer player, List <string> options, Rectangle rectangle, GuiContainer.Layer layer, string parent, GuiColor panelColor, GuiColor textColor, Action <string> callback, bool allowNew = false, int page = 0, Predicate <string> predicate = null) { if (allowNew) { options.Add("(add new)"); } int maxItems = 5; rectangle.H *= ((float)options.Count / (float)maxItems); List <List <string> > ListOfLists = SplitIntoChunks <string>(options, maxItems); GuiContainer container = new GuiContainer(plugin, "dropdown_API", parent); double cfX = rectangle.W / 300; double cfY = rectangle.H / 570; Action <BasePlayer, string[]> up = (bPlayer, input) => { dropdown(plugin, player, options, rectangle, layer, parent, panelColor, textColor, callback, allowNew, page - 1, predicate); }; Action <BasePlayer, string[]> down = (bPlayer, input) => { dropdown(plugin, player, options, rectangle, layer, parent, panelColor, textColor, callback, allowNew, page + 1, predicate); }; if (page > 0) { container.addPlainButton("dropdown_up", new Rectangle(0, 1, 298, 36, 300, 570, true), new GuiColor(1, 1, 1, 0.4f), 0, 0, new GuiText("<b>∧</b>", (int)Math.Floor(22 * cfY), new GuiColor("black")), up, parent: "dropdown_background"); } if (page < ListOfLists.Count - 1) { container.addPlainButton("dropdown_up", new Rectangle(0, 533, 298, 37, 300, 570, true), new GuiColor(1, 1, 1, 0.4f), 0, 0, new GuiText("<b>∨</b>", (int)Math.Floor(22 * cfY), new GuiColor("black")), down, parent: "dropdown_background"); } int count = 0; foreach (string option in ListOfLists[page]) { int hEach = (int)(rectangle.H / ListOfLists[page].Count); Rectangle pos = new Rectangle(0, 0 + (count * hEach), rectangle.W, hEach, rectangle.W, rectangle.H, true).WithParent(rectangle); Action <BasePlayer, string[]> btnCallback = null; if (option == "(add new)") { btnCallback = (bPlayer, input) => dropdownAddNew(plugin, player, pos, callback, predicate); } else { string selected = option; btnCallback = (bPlayer, input) => { callback(selected); }; } container.addPlainButton($"dropdown_option_{option}", pos, layer, panelColor, 0, 0, new GuiText(option, color: textColor), btnCallback, blur: GuiContainer.Blur.strong); count++; } container.display(player); }