diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java index 1831c5d8a..4cb9ec622 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java @@ -11,6 +11,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.foundation.config.ui.entries.NumberEntry; +import com.simibubi.create.foundation.config.ui.entries.StringEntry; import com.simibubi.create.foundation.gui.RemovedGuiUtils; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.TickableGuiEventListener; @@ -66,6 +67,7 @@ public class ConfigScreenList extends ObjectSelectionList e instanceof NumberEntry).forEach(e -> e.mouseClicked(x, y, button)); + children().stream().filter(e -> e instanceof StringEntry).forEach(e -> e.mouseClicked(x, y, button)); return super.mouseClicked(x, y, button); } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java index d33db3ce2..d0e15ab53 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java @@ -14,6 +14,9 @@ import java.util.function.Consumer; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import com.simibubi.create.Create; +import com.simibubi.create.foundation.config.ui.entries.StringEntry; + import org.lwjgl.glfw.GLFW; import com.electronwill.nightconfig.core.AbstractConfig; @@ -280,6 +283,8 @@ public class SubMenuConfigScreen extends ConfigScreen { entry = new EnumEntry(humanKey, (ForgeConfigSpec.ConfigValue>) configValue, valueSpec); } else if (value instanceof Number) { entry = NumberEntry.create(value, humanKey, configValue, valueSpec); + } else if (value instanceof String) { + entry = new StringEntry(humanKey, (ForgeConfigSpec.ConfigValue) configValue, valueSpec); } if (entry == null) diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/StringEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/StringEntry.java new file mode 100644 index 000000000..ad3a13566 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/StringEntry.java @@ -0,0 +1,52 @@ +package com.simibubi.create.foundation.config.ui.entries; + +import com.simibubi.create.foundation.config.ui.ConfigTextField; + +import com.simibubi.create.foundation.gui.Theme; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.EditBox; +import net.minecraftforge.common.ForgeConfigSpec; + +public class StringEntry extends ValueEntry { + + protected EditBox textField; + + public StringEntry(String label, ForgeConfigSpec.ConfigValue value, ForgeConfigSpec.ValueSpec spec) { + super(label, value, spec); + textField = new ConfigTextField(Minecraft.getInstance().font, 0, 0, 200, 20); + textField.setValue(value.get()); + textField.setTextColor(Theme.i(Theme.Key.TEXT)); + + textField.setResponder(this::setValue); + + textField.moveCursorToStart(); + listeners.add(textField); + onReset(); + } + + @Override + public void render(GuiGraphics graphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) { + super.render(graphics, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks); + + textField.setX(x + width - 82 - resetWidth); + textField.setY(y + 8); + textField.setWidth(Math.min(width - getLabelWidth(width) - resetWidth, 60)); + textField.setHeight(20); + textField.render(graphics, mouseX, mouseY, partialTicks); + + } + + @Override + protected void setEditable(boolean b) { + super.setEditable(b); + textField.setEditable(b); + } + + @Override + public void tick() { + super.tick(); + textField.tick(); + } +}