Enum Option

Introduction

EnumOption is an option that allows cycling through an enumeration of values. It extends Option<E> for enum types, providing a user interface for selecting from a predefined set of options.

Details

  • Supplier Requirement: Retrieves the current enum value.

  • Consumer Provision: Updates the enum value upon user interaction.

  • Name Parameter: Labels the option in the HUD.

  • Values Array: Holds the enumeration of possible values.

Interactivity

  • Click Response: Left-click cycles forward, right-click cycles backward through the enum values.

  • Render Behavior: Displays the option's name followed by the current enum value, with visual feedback for the active selection.

Example Usage

// Enum representing difficulty levels
enum Difficulty {
    EASY, MEDIUM, HARD
}

// Create an EnumOption for selecting difficulty
EnumOption<Difficulty> difficultyOption = new EnumOption<>(
    "Difficulty",
    () -> this.getDifficulty(), // Getter
    value -> this.setDifficulty(value), // Setter
    Difficulty.values() // Enum values
);

Last updated

Was this helpful?