mirror of
https://github.com/Shiewk/Widgets.git
synced 2026-04-28 11:34:17 +02:00
Add option to set show condition on widget options
This commit is contained in:
@@ -6,6 +6,7 @@ import net.minecraft.client.gui.widget.ClickableWidget;
|
|||||||
import net.minecraft.client.gui.widget.Widget;
|
import net.minecraft.client.gui.widget.Widget;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public abstract class WidgetSettingOption implements Drawable, Widget {
|
public abstract class WidgetSettingOption implements Drawable, Widget {
|
||||||
@@ -14,6 +15,7 @@ public abstract class WidgetSettingOption implements Drawable, Widget {
|
|||||||
private int x = 0;
|
private int x = 0;
|
||||||
private int y = 0;
|
private int y = 0;
|
||||||
private boolean focused = false;
|
private boolean focused = false;
|
||||||
|
private BooleanSupplier shouldShow = WidgetUtils.TRUE_SUPPLIER;
|
||||||
|
|
||||||
protected WidgetSettingOption(String id, Text name) {
|
protected WidgetSettingOption(String id, Text name) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -83,4 +85,13 @@ public abstract class WidgetSettingOption implements Drawable, Widget {
|
|||||||
public void setFocused(boolean focused) {
|
public void setFocused(boolean focused) {
|
||||||
this.focused = focused;
|
this.focused = focused;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean shouldShow(){
|
||||||
|
return shouldShow.getAsBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WidgetSettingOption setShowCondition(BooleanSupplier shouldShow){
|
||||||
|
this.shouldShow = shouldShow;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package de.shiewk.widgets;
|
package de.shiewk.widgets;
|
||||||
|
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
|
|
||||||
public class WidgetUtils {
|
public class WidgetUtils {
|
||||||
|
|
||||||
|
public static final BooleanSupplier TRUE_SUPPLIER = () -> true;
|
||||||
|
|
||||||
public static double translateToWidgetSettingsValue(double value, int max){
|
public static double translateToWidgetSettingsValue(double value, int max){
|
||||||
return (value / max) * 100;
|
return (value / max) * 100;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
|||||||
context.getMatrices().pop();
|
context.getMatrices().pop();
|
||||||
int y = textRenderer.fontHeight * 2 + this.height / 50 + 5;
|
int y = textRenderer.fontHeight * 2 + this.height / 50 + 5;
|
||||||
for (WidgetSettingOption setting : widget.getSettings().getCustomSettings()) {
|
for (WidgetSettingOption setting : widget.getSettings().getCustomSettings()) {
|
||||||
|
if (!setting.shouldShow()) continue;
|
||||||
if (this.width - setting.getWidth() > textRenderer.getWidth(setting.getName()) + 20){
|
if (this.width - setting.getWidth() > textRenderer.getWidth(setting.getName()) + 20){
|
||||||
setting.setX(this.getX() + this.width - setting.getWidth() - 5);
|
setting.setX(this.getX() + this.width - setting.getWidth() - 5);
|
||||||
setting.setY(y);
|
setting.setY(y);
|
||||||
|
|||||||
Reference in New Issue
Block a user