feat: remove checkbox widgets

- As voted on in a recent MidnightDust Discord Poll
This commit is contained in:
Martin Prokoph
2025-05-12 22:57:15 +02:00
parent 74d8800fa5
commit f1fe868192

View File

@@ -164,9 +164,6 @@ public abstract class MidnightConfig {
else if (info.dataType == boolean.class) {
Function<Object, Text> func = value -> Text.translatable((Boolean) value ? "gui.yes" : "gui.no").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED);
info.function = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
if (info.actionButton instanceof CheckboxWidget checkbox && checkbox.isChecked() == (Boolean) info.value) {
checkbox.onPress(); return;
}
info.setValue(!(Boolean) info.value); button.setMessage(func.apply(info.value));
}, func);
} else if (info.dataType.isEnum()) {
@@ -377,7 +374,6 @@ public abstract class MidnightConfig {
values.setValue(value -> getEnumTranslatableText(value, modid, info));
}
widget = ButtonWidget.builder(values.getValue().apply(info.value), values.getKey()).dimensions(width - 185, 0, 150, 20).tooltip(info.getTooltip(true)).build();
if (info.dataType == boolean.class) info.actionButton = CheckboxWidget.builder(Text.empty(), textRenderer).callback((checkbox, checked) -> values.getKey().onPress((ButtonWidget) widget)).checked((Boolean) info.value).pos(widget.getX(), 1).build();
} else if (e.isSlider())
widget = new MidnightSliderWidget(width - 185, 0, 150, 20, Text.of(info.tempValue), (Double.parseDouble(info.tempValue) - e.min()) / (e.max() - e.min()), info);
else widget = new TextFieldWidget(textRenderer, width - 185, 0, 150, 20, Text.empty());
@@ -490,7 +486,7 @@ public abstract class MidnightConfig {
}
}
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
buttons.forEach(b -> { b.setY(y + (b instanceof CheckboxWidget ? 1 : 0)); b.render(context, mouseX, mouseY, tickDelta);});
buttons.forEach(b -> { b.setY(y); b.render(context, mouseX, mouseY, tickDelta);});
if (title != null) {
title.setY(y+5);
title.renderWidget(context, mouseX, mouseY, tickDelta);