Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow string type config editing #7119

Open
wants to merge 1 commit into
base: mc1.20.1/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -66,6 +67,7 @@ protected void renderList(GuiGraphics graphics, int p_239229_, int p_239230_, fl
@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
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;
Expand Down Expand Up @@ -280,6 +283,8 @@ protected void init() {
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}