|
3 | 3 | import io.github.techstreet.dfscript.DFScript; |
4 | 4 | import io.github.techstreet.dfscript.screen.CScreen; |
5 | 5 | import io.github.techstreet.dfscript.screen.widget.CButton; |
| 6 | +import io.github.techstreet.dfscript.screen.widget.CText; |
6 | 7 | import io.github.techstreet.dfscript.screen.widget.CTextField; |
7 | 8 | import io.github.techstreet.dfscript.script.ScriptManager; |
| 9 | +import net.minecraft.text.Text; |
| 10 | + |
8 | 11 | import java.util.regex.Matcher; |
9 | 12 | import java.util.regex.Pattern; |
10 | 13 |
|
11 | 14 | public class ScriptCreationScreen extends CScreen { |
12 | 15 |
|
13 | 16 | // invalid file name chars |
14 | 17 | // 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<>:\"\\\\/|?*]"); |
16 | 19 |
|
17 | 20 | 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); |
35 | 22 |
|
| 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; |
36 | 28 | ScriptManager.getInstance().createScript(name.getText()); |
37 | 29 | 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", () -> { |
41 | 43 | DFScript.MC.setScreen(new ScriptAddScreen()); |
42 | 44 | })); |
43 | 45 | } |
|
0 commit comments