DynamicHUD Dev Guide
DownloadNeed Support?
  • Dynamic HUD
  • Import using Gradle
  • Integrating DynamicHUD
    • Integrating DynamicHUD
    • Adding Widgets
    • Adding your own WidgetRenderer
    • Passing AbstractMoveableScreen instance
    • Changing default key bind
    • Changing save and load file
    • Registering Custom Widgets
  • Widget
    • Widget class
    • How to create a custom widget
    • Widget Renderer
    • WidgetData
    • DynamicValueRegistry
    • Scaling
  • Screens
    • AbstractMoveableScreen
  • ContextMenu
    • ContextMenu class
    • Using context menu
    • Option<T> class
      • Color Option
      • Boolean Option
      • Double Option
      • Runnable Option
      • Enum Option
      • List Option
      • SubMenu Option
Powered by GitBook
On this page
  • Overview
  • Constructor
  • Core Methods
  • Usage

Was this helpful?

  1. ContextMenu

Option<T> class

Overview

The Option<T> class is an abstract representation of an option within a context menu. It is designed to be extended for various types of options that can be interacted with in the Minecraft client GUI.

Constructor

Option(Supplier<T> getter, Consumer<T> setter)

Creates an Option instance with specified getter and setter for managing the option’s value.

Option(Supplier<T> getter, Consumer<T> setter, Supplier<Boolean> shouldRender)

Initializes an Option with specified getter, setter, and a condition for rendering.

Core Methods

get()

Retrieves the current value of the option.

set(T value)

Sets the current value of the option and applies it using the provided setter.

render(DrawContext drawContext, int x, int y)

Defines how the option is rendered on the screen at the given coordinates.

isMouseOver(double mouseX, double mouseY)

Determines if the mouse cursor is over the option’s area.

setShouldRender(Supplier<Boolean> shouldRender)

Sets the condition that determines if the option should be rendered.

Usage

To use the Option<T> class, extend it and implement the abstract render method to define the option’s appearance and behavior. Use the setShouldRender method to specify conditions under which the option should be displayed.

This is an example usage of all options from TextWidget:

TextWidget.java
public void createMenu() {
    AtomicReference<Enum> enums = new AtomicReference<>(Enum.Enum1);
    AtomicReference<String> option = new AtomicReference<>("Enum1");
    List<String> options = Arrays.asList("List1", "List2", "List3");
    AtomicBoolean running = new AtomicBoolean(false);
    AtomicBoolean subMenu = new AtomicBoolean(false);
    menu = new ContextMenu(getX(), getY());
    menu.addOption(new BooleanOption("Shadow", () -> this.shadow, value -> this.shadow = value));
    menu.addOption(new BooleanOption("Rainbow", () -> this.rainbow, value -> this.rainbow = value));
    menu.addOption(new ColorOption("TextColor", menu, () -> this.textColor, value -> this.textColor = value));
    menu.addOption(new DoubleOption("RainbowSpeed", 1, 4, 1.0f, () -> (double) this.rainbowSpeed, value -> this.rainbowSpeed = value.intValue(),menu));
    menu.addOption(new EnumOption<>("Enum", enums::get, enums::set, Enum.values()));
    menu.addOption(new ListOption<>("List", option::get, option::set, options));
    menu.addOption(new RunnableOption("Runnable Test",running::get,running::set, this::printStuff));
    SubMenuOption subMenuOption = new SubMenuOption("SubMenu",menu,subMenu::get,subMenu::set);
    subMenuOption.getSubMenu().addOption(new BooleanOption("Shadows2", () -> this.shadow, value -> this.shadow = value));
    menu.addOption(subMenuOption);
}
public void printStuff(){
    System.out.println("Runnable works");
}
PreviousUsing context menuNextColor Option

Last updated 1 year ago

Was this helpful?