|
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("[\\\\/:*?\"<>|\n]"); |
16 | 19 |
|
17 | 20 | protected ScriptCreationScreen() { |
18 | | - super(105, 60); |
| 21 | + super(100, 33); |
| 22 | + |
| 23 | + widgets.add(new CText(4, 4, Text.of("Create Script"))); |
| 24 | + |
| 25 | + CTextField name = new CTextField("My Script", 4, 9, 92, 9, true){ |
| 26 | + @Override |
| 27 | + public void keyPressed(int keyCode, int scanCode, int modifiers) { |
| 28 | + if(keyCode == 257) return; |
| 29 | + super.keyPressed(keyCode, scanCode, modifiers); |
| 30 | + } |
| 31 | + }; |
19 | 32 |
|
20 | | - CTextField name = new CTextField("My Script", 2, 2, 96, 36, true); |
| 33 | + name.setChangedListener(() -> { |
| 34 | + String scriptName = name.getText(); |
| 35 | + |
| 36 | + Matcher m = ILLEGAL_CHARS.matcher(scriptName); |
21 | 37 |
|
22 | | - name.setChangedListener(() -> name.textColor = 0xFFFFFF); |
| 38 | + name.textColor = m.find() ? 0xFF3333 : 0xFFFFFF; |
| 39 | + }); |
23 | 40 |
|
24 | 41 | widgets.add(name); |
25 | 42 |
|
26 | | - widgets.add(new CButton(2, 42, 48, 15, "Create", () -> { |
| 43 | + widgets.add(new CButton(4, 20, 44, 9, "Create", () -> { |
27 | 44 | String scriptName = name.getText(); |
28 | 45 |
|
29 | 46 | Matcher m = ILLEGAL_CHARS.matcher(scriptName); |
30 | 47 |
|
31 | | - if (m.find()) { |
32 | | - name.textColor = 0xFF3333; |
33 | | - return; |
34 | | - } |
| 48 | + if (m.find()) return; |
35 | 49 |
|
36 | 50 | ScriptManager.getInstance().createScript(name.getText()); |
37 | 51 | DFScript.MC.setScreen(new ScriptListScreen(true)); |
38 | 52 | })); |
39 | 53 |
|
40 | | - widgets.add(new CButton(50, 42, 48, 15, "Cancel", () -> { |
| 54 | + widgets.add(new CButton(52, 20, 44, 9, "Cancel", () -> { |
41 | 55 | DFScript.MC.setScreen(new ScriptAddScreen()); |
42 | 56 | })); |
43 | 57 | } |
|
0 commit comments