package chylex.bettercontrols.gui.elements; import net.minecraft.client.gui.components.Button; import java.util.List; import java.util.function.Consumer; public class CycleButtonWidget extends Button { private final List> options; private final Consumer onChanged; private T selectedValue; public CycleButtonWidget(final int x, final int y, final int width, final int height, final List> options, final T selectedValue, final Consumer onChanged) { super(x, y, width, height, Option.find(options, selectedValue).getText(), btn -> {}); this.options = options; this.selectedValue = selectedValue; this.onChanged = onChanged; } public CycleButtonWidget(final int x, final int y, final int width, final List> options, final T selectedValue, final Consumer onChanged) { this(x, y, width, 20, options, selectedValue, onChanged); } @Override public void onPress() { int nextIndex = options.indexOf(Option.find(options, selectedValue)) + 1; if (nextIndex >= options.size()) { nextIndex = 0; } final Option newSelectedOption = options.get(nextIndex); selectedValue = newSelectedOption.getValue(); onChanged.accept(selectedValue); setMessage(newSelectedOption.getText()); } }