Boolean Option
Introduction
The BooleanOption
class inherits from the Option<Boolean>
class and allows users to switch between two states, typically represented as "on" and "off".
Details
Constructor
The Boolean Option class has two constructors that takes the following parameters:
One of the constructors uses the
BooleanPool
class to store and manage the Boolean values. This is when you don't want the hassle to create a new Boolean for every BooleanOption you create.Supplier Requirement: The
Supplier<Boolean>
parameter is necessary to obtain the current state of the Boolean value.Consumer Provision: The
Consumer<Boolean>
parameter updates the Boolean value when the option is interacted with.Name Parameter: The
name
parameter labels the option within the HUD, enhancing user experience and clarity.
BooleanPool
The BooleanPool
class is a thread-safe cache that stores and retrieves Boolean values. It provides a fast and efficient way to access and update the Boolean values. This is what the BooleanPool
class looks like
Interactivity
Click Response: Clicking the option toggles its state and triggers the associated setter action.
Render Behavior: The option is visually represented with a label, changing color to indicate its state (green for "on", red for "off").
Mouse Interaction: The class includes methods to handle mouse clicks, ensuring the option responds to user input.
Example Usage
Ensure that the getter is synchronized with the setter; otherwise, the option will enter a soft lock, and the value will not update. (Meaning the getter and setter should be updating the same variables or referencing the same variable)
Last updated
Was this helpful?