Skip to content

Commit dbac749

Browse files
committed
Improve ScriptCreationScreen
1 parent f576c25 commit dbac749

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/main/java/io/github/techstreet/dfscript/screen/script/ScriptCreationScreen.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,43 @@
33
import io.github.techstreet.dfscript.DFScript;
44
import io.github.techstreet.dfscript.screen.CScreen;
55
import io.github.techstreet.dfscript.screen.widget.CButton;
6+
import io.github.techstreet.dfscript.screen.widget.CText;
67
import io.github.techstreet.dfscript.screen.widget.CTextField;
78
import io.github.techstreet.dfscript.script.ScriptManager;
9+
import net.minecraft.text.Text;
10+
811
import java.util.regex.Matcher;
912
import java.util.regex.Pattern;
1013

1114
public class ScriptCreationScreen extends CScreen {
1215

1316
// invalid file name chars
1417
// there's definitely a better place to put this but this felt the simplest rn
15-
Pattern ILLEGAL_CHARS = Pattern.compile("[\\\\/:*?\"<>|]");
18+
Pattern ILLEGAL_CHARS = Pattern.compile("[\\x00-\\x1f<>:\"\\\\/|?*]");
1619

1720
protected ScriptCreationScreen() {
18-
super(105, 60);
19-
20-
CTextField name = new CTextField("My Script", 2, 2, 96, 36, true);
21-
22-
name.setChangedListener(() -> name.textColor = 0xFFFFFF);
23-
24-
widgets.add(name);
25-
26-
widgets.add(new CButton(2, 42, 48, 15, "Create", () -> {
27-
String scriptName = name.getText();
28-
29-
Matcher m = ILLEGAL_CHARS.matcher(scriptName);
30-
31-
if (m.find()) {
32-
name.textColor = 0xFF3333;
33-
return;
34-
}
21+
super(103,35);
3522

23+
widgets.add(new CText(4, 3, Text.literal("Name your script:")));
24+
CTextField name = new CTextField("My Script", 3, 8, 95, 8, true);
25+
CButton addButton = new CButton(3, 19, 46, 10, "Create", () -> {
26+
Matcher m = ILLEGAL_CHARS.matcher(name.getText());
27+
if(m.find()) return;
3628
ScriptManager.getInstance().createScript(name.getText());
3729
DFScript.MC.setScreen(new ScriptListScreen(true));
38-
}));
39-
40-
widgets.add(new CButton(50, 42, 48, 15, "Cancel", () -> {
30+
});
31+
name.setChangedListener(() -> {
32+
name.textColor = 0xFFFFFF;
33+
addButton.setDisabled(false);
34+
Matcher m = ILLEGAL_CHARS.matcher(name.getText());
35+
if(m.find()) {
36+
name.textColor = 0xFF3333;
37+
addButton.setDisabled(true);
38+
}
39+
});
40+
widgets.add(name);
41+
widgets.add(addButton);
42+
widgets.add(new CButton(52, 19, 46, 10, "Cancel", () -> {
4143
DFScript.MC.setScreen(new ScriptAddScreen());
4244
}));
4345
}

0 commit comments

Comments
 (0)