2021-10-06 19:01:48 +02:00
|
|
|
package io.gitlab.jfronny.libjf.config.impl.gui;
|
2021-05-15 15:34:19 +02:00
|
|
|
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
|
|
import net.fabricmc.api.Environment;
|
|
|
|
import net.minecraft.client.MinecraftClient;
|
|
|
|
import net.minecraft.client.font.TextRenderer;
|
|
|
|
import net.minecraft.client.gui.DrawableHelper;
|
|
|
|
import net.minecraft.client.gui.Element;
|
2021-05-29 10:37:13 +02:00
|
|
|
import net.minecraft.client.gui.Selectable;
|
|
|
|
import net.minecraft.client.gui.widget.ClickableWidget;
|
2021-05-15 15:34:19 +02:00
|
|
|
import net.minecraft.client.gui.widget.ElementListWidget;
|
|
|
|
import net.minecraft.client.util.math.MatrixStack;
|
|
|
|
import net.minecraft.text.Text;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
@Environment(EnvType.CLIENT)
|
2022-01-08 20:02:15 +01:00
|
|
|
public class ConfigScreenEntry extends ElementListWidget.Entry<ConfigScreenEntry> {
|
2021-05-15 15:34:19 +02:00
|
|
|
private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
2021-05-29 10:37:13 +02:00
|
|
|
public final List<ClickableWidget> buttons = new ArrayList<>();
|
|
|
|
private final List<ClickableWidget> resetButtons = new ArrayList<>();
|
2021-05-15 15:34:19 +02:00
|
|
|
private final List<Text> texts = new ArrayList<>();
|
2021-05-29 10:37:13 +02:00
|
|
|
private final List<ClickableWidget> buttonsWithResetButtons = new ArrayList<>();
|
|
|
|
public static final Map<ClickableWidget, Text> buttonsWithText = new HashMap<>();
|
2021-05-15 15:34:19 +02:00
|
|
|
|
2022-01-08 20:02:15 +01:00
|
|
|
private ConfigScreenEntry(ClickableWidget button, Text text, ClickableWidget resetButton) {
|
2021-05-15 15:34:19 +02:00
|
|
|
buttonsWithText.put(button,text);
|
|
|
|
this.buttons.add(button);
|
|
|
|
this.resetButtons.add(resetButton);
|
|
|
|
this.texts.add(text);
|
|
|
|
this.buttonsWithResetButtons.add(button);
|
|
|
|
this.buttonsWithResetButtons.add(resetButton);
|
|
|
|
}
|
2022-01-08 20:02:15 +01:00
|
|
|
public static ConfigScreenEntry create(ClickableWidget button, Text text, ClickableWidget resetButton) {
|
|
|
|
return new ConfigScreenEntry(button, text, resetButton);
|
2021-05-15 15:34:19 +02:00
|
|
|
}
|
|
|
|
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
|
|
|
this.buttons.forEach((button) -> {
|
|
|
|
button.y = y;
|
|
|
|
button.render(matrices, mouseX, mouseY, tickDelta);
|
|
|
|
});
|
|
|
|
this.texts.forEach((text) -> DrawableHelper.drawTextWithShadow(matrices,textRenderer, text,12,y+5,0xFFFFFF));
|
|
|
|
this.resetButtons.forEach((button) -> {
|
|
|
|
button.y = y;
|
|
|
|
button.render(matrices, mouseX, mouseY, tickDelta);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
public List<? extends Element> children() {
|
|
|
|
return buttonsWithResetButtons;
|
|
|
|
}
|
2021-05-29 10:37:13 +02:00
|
|
|
|
|
|
|
@Override
|
2021-07-13 15:07:56 +02:00
|
|
|
public List<? extends Selectable> selectableChildren() {
|
2021-05-29 10:37:13 +02:00
|
|
|
return buttons;
|
|
|
|
}
|
2021-05-15 15:34:19 +02:00
|
|
|
}
|