Class DropDown<T>

java.lang.Object
com.pixelmonmod.pixelmon.client.gui.widgets.DropDown<T>

public class DropDown<T> extends Object
A drop-down menu used to select a certain option in a list.
  • Field Details

    • OPTION_HEIGHT

      public static final int OPTION_HEIGHT
      The height of one option in the menu.
      See Also:
  • Constructor Details

    • DropDown

      public DropDown(List<T> options, int selected, int left, int top, int width, int height)
      Initializes the menu.
      Parameters:
      options - The options that can be selected in the list.
      selected - The index of the currently selected option.
      left - The x coordinate of the left side of the slot.
      top - The y coordinate of the top of the slot.
      width - The width of the slot.
      height - The height of the slot.
    • DropDown

      public DropDown(List<T> options, int selected, int left, int top, int width, int height, int dropDownWidth)
      Initializes the menu.
      Parameters:
      options - The options that can be selected in the list.
      selected - The index of the currently selected option.
      left - The x coordinate of the left side of the slot.
      top - The y coordinate of the top of the slot.
      width - The width of the slot.
      height - The height of the slot.
      dropDownWidth - The width of the dropdown box
    • DropDown

      public DropDown(List<T> options, T selected, int left, int top, int width, int height)
      Initializes the menu.
      Parameters:
      options - The options that can be selected in the list.
      selected - The currently selected option.
      left - The x coordinate of the left side of the slot.
      top - The y coordinate of the top of the slot.
      width - The width of the slot.
      height - The height of the slot.
    • DropDown

      public DropDown(List<T> options, T selected, int left, int top, int width, int height, int dropDownWidth)
      Initializes the menu with extended dropdown width
      Parameters:
      options - The options that can be selected in the list.
      selected - The currently selected option.
      left - The x coordinate of the left side of the slot.
      top - The y coordinate of the top of the slot.
      width - The width of the slot.
      height - The height of the slot.
  • Method Details

    • setOptions

      public void setOptions(List<T> options, T selected)
      Sets the options in the list.
      Parameters:
      options - The options that can be selected in the list.
      selected - The index of the currently selected option.
    • setSelected

      public void setSelected(T selected)
      Sets the currently selected option.
      Parameters:
      selected - The currently selected option.
    • setSelected

      public void setSelected(int selected)
      Sets the currently selected option.
      Parameters:
      selected - The index of the currently selected option.
    • setInactiveTop

      public DropDown<T> setInactiveTop(int top)
      Sets the top of the menu when inactive.
      Parameters:
      top - The y coordinate of the top of the menu when inactive.
      Returns:
      The menu instance.
    • setInactiveHeight

      public DropDown<T> setInactiveHeight(int height)
      Sets the height of the menu when inactive.
      Parameters:
      height - The y coordinate of the top of the menu when inactive.
      Returns:
      The menu instance.
    • setTextAlign

      public DropDown<T> setTextAlign(TextAlignment align)
      Sets the alignment of text in the menu.
      Parameters:
      align - The alignment of text in the menu.
      Returns:
      The menu instance.
    • setGetOptionString

      public DropDown<T> setGetOptionString(Function<T,String> getOptionString)
      Sets the function used to convert an option to a string.
      Parameters:
      getOptionString - The function used to convert an option to a string.
      Returns:
      The menu instance.
    • setOptionRenderer

      public DropDown<T> setOptionRenderer(DropDown.OptionRenderer<T> optionRenderer)
    • setOnSelected

      public DropDown<T> setOnSelected(Consumer<T> onSelected)
      Sets a method to call when an option is selected.
      Parameters:
      onSelected - The method to call when an option is selected.
      Returns:
      The menu instance.
    • setOnSelectedIndex

      public DropDown<T> setOnSelectedIndex(Consumer<Integer> onSelectedIndex)
      Sets a method to call when an option is selected.
      Parameters:
      onSelectedIndex - The method to call when an option is selected.
      Returns:
      The menu instance.
    • setOrdered

      public DropDown<T> setOrdered()
      Sorts the options in the menu by name.
      Returns:
      The menu instance.
    • getSelected

      public T getSelected()
      Gets the currently selected option.
      Returns:
      The currently selected option.
    • render

      public void render(net.minecraft.client.gui.GuiGraphics graphics, int mouseX, int mouseY, float partialTicks, DropDown active)
      Draws the list to the screen.
      Parameters:
      mouseX - The x coordinate of the mouse.
      mouseY - The y coordinate of the mouse.
      partialTicks - The current number of partial ticks.
    • isMouseOver

      public boolean isMouseOver(int mouseX, int mouseY)
      Gets the index of the element that the cursor is currently over.
      Parameters:
      mouseX - The x coordinate of the cursor.
      mouseY - The y coordinate of the cursor.
      Returns:
      The index of the element that the cursor is currently over, or -1 if the cursor is not over the list.
    • getLastSelected

      public boolean getLastSelected()
      Checks if an option was selected in the current mouse press.
      Returns:
      Whether an option was selected in the current mouse press.
    • getTop

      public int getTop()
      Gets the y coordinate of the top of the menu when inactive.
      Returns:
      The y coordinate of the top of the menu when inactive.
    • getSelectedIndex

      public int getSelectedIndex()
      Gets the index of the currently selected option.
      Returns:
      The index of the currently selected option.
    • getVisible

      public boolean getVisible()
      returns true if this textbox is visible
    • setVisible

      public void setVisible(boolean isVisible)
      Sets whether or not this textbox is visible