Class GuiContextMenu

All Implemented Interfaces:
ElementEvents, GuiParent<GuiContextMenu>, TooltipHandler<GuiContextMenu>

public class GuiContextMenu extends GuiElement<GuiContextMenu>
Context menus get added to the root element when they are created so as long as no new elements are added after the menu is opened, the menu will always be on top. It will also automatically close when an option is selected, or when the user clicks outside the context menu.

Created by brandon3055 on 21/11/2023

  • Constructor Details

    • GuiContextMenu

      public GuiContextMenu(ModularGui gui)
  • Method Details

    • tooltipStyleMenu

      public static GuiContextMenu tooltipStyleMenu(GuiParent<?> parent)
    • setCloseOnItemClicked

      public GuiContextMenu setCloseOnItemClicked(boolean closeOnItemClicked)
    • setCloseOnOutsideClick

      public GuiContextMenu setCloseOnOutsideClick(boolean closeOnOutsideClick)
    • actionOnClick

      public GuiContextMenu actionOnClick()
      By default, the option action fires on mouse button release (like pretty much any UI button in existence) Calling this will change that to action on mouse button press, (What minecraft uses for its buttons)
    • setButtonBuilder

      public GuiContextMenu setButtonBuilder(BiFunction<GuiContextMenu,Supplier<net.minecraft.network.chat.Component>,GuiButton> buttonBuilder)
      Only height should be constrained, with will be set automatically to accommodate the provided label.
    • addOption

      public GuiContextMenu addOption(Supplier<net.minecraft.network.chat.Component> label, Runnable action)
    • addOption

      public GuiContextMenu addOption(Supplier<net.minecraft.network.chat.Component> label, Supplier<List<net.minecraft.network.chat.Component>> tooltip, Runnable action)
    • addOption

      public GuiContextMenu addOption(Supplier<net.minecraft.network.chat.Component> label, List<net.minecraft.network.chat.Component> tooltip, Runnable action)
    • addOption

      public GuiContextMenu addOption(Supplier<net.minecraft.network.chat.Component> label, Runnable action, net.minecraft.network.chat.Component... tooltip)
    • mouseClicked

      public boolean mouseClicked(double mouseX, double mouseY, int button, boolean consumed)
      Description copied from interface: ElementEvents
      Root handler for mouseClick event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of mouseClick handling should be implemented via ElementEvents.mouseClicked(double, double, int)

      Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.

      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      button - Mouse Button
      consumed - Will be true if this action has already been consumed.
      Returns:
      true if this event has been consumed.
    • mouseReleased

      public boolean mouseReleased(double mouseX, double mouseY, int button, boolean consumed)
      Description copied from interface: ElementEvents
      Root handler for mouseReleased event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of mouseReleased handling should be implemented via ElementEvents.mouseReleased(double, double, int)

      Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.

      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      button - Mouse Button
      consumed - Will be true if this action has already been consumed.
      Returns:
      true if this event has been consumed.
    • close

      public void close()
    • setNormalizedPos

      public GuiContextMenu setNormalizedPos(double x, double y)