mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-27 13:28:00 +01:00
Allow string type config editing
This commit is contained in:
parent
d48a504486
commit
af8bd3d263
3 changed files with 59 additions and 0 deletions
|
@ -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<ConfigScreenList.Entry
|
|||
@Override
|
||||
public boolean mouseClicked(double x, double y, int button) {
|
||||
children().stream().filter(e -> 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);
|
||||
}
|
||||
|
|
|
@ -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<Enum<?>>) 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<String>) configValue, valueSpec);
|
||||
}
|
||||
|
||||
if (entry == null)
|
||||
|
|
|
@ -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<String> {
|
||||
|
||||
protected EditBox textField;
|
||||
|
||||
public StringEntry(String label, ForgeConfigSpec.ConfigValue<String> 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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue