Skip to content

Commit 4714d44

Browse files
committed
The options now show their name.
Also you can now remove and insert options by right clicking the option name
1 parent 7944bd5 commit 4714d44

File tree

3 files changed

+93
-9
lines changed

3 files changed

+93
-9
lines changed

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

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22

33
import io.github.techstreet.dfscript.DFScript;
44
import io.github.techstreet.dfscript.screen.CScreen;
5-
import io.github.techstreet.dfscript.screen.widget.CButton;
6-
import io.github.techstreet.dfscript.screen.widget.CScrollPanel;
7-
import io.github.techstreet.dfscript.screen.widget.CTextField;
8-
import io.github.techstreet.dfscript.screen.widget.CWidget;
5+
import io.github.techstreet.dfscript.screen.widget.*;
96
import io.github.techstreet.dfscript.script.Script;
107
import io.github.techstreet.dfscript.script.ScriptManager;
8+
import io.github.techstreet.dfscript.script.action.ScriptActionType;
119
import io.github.techstreet.dfscript.script.options.ScriptOption;
12-
10+
import io.github.techstreet.dfscript.util.chat.ChatUtil;
11+
import net.minecraft.client.gui.DrawableHelper;
12+
import net.minecraft.client.sound.PositionedSoundInstance;
13+
import net.minecraft.client.util.math.MatrixStack;
14+
import net.minecraft.sound.SoundEvents;
15+
import net.minecraft.text.Text;
16+
17+
import java.awt.*;
1318
import java.util.ArrayList;
1419
import java.util.List;
1520

@@ -29,15 +34,76 @@ public ScriptSettingsScreen(Script script) {
2934

3035
widgets.add(panel);
3136

32-
CTextField description = new CTextField(script.getDescription(), 3, 3, 115, 20, true);
37+
int y = 3;
38+
int index = 0;
39+
40+
CText descriptionText = new CText(5, y, Text.of("Description:"));
41+
panel.add(descriptionText);
42+
43+
y += 5;
44+
45+
CTextField description = new CTextField(script.getDescription(), 5, y, 110, 20, true);
3346
description.setChangedListener(() -> script.setDescription(description.getText()));
3447
panel.add(description);
3548

36-
int y = 25;
37-
int index = 0;
49+
y += 22;
3850

3951
for(ScriptOption option : script.getOptions())
4052
{
53+
String name = option.getName() + ":";
54+
55+
Text text = Text.of(name);
56+
57+
CWrappedText ctext = new CWrappedText(5, y, 110*2, text);
58+
59+
panel.add(ctext);
60+
61+
int height = DFScript.MC.textRenderer.getWrappedLinesHeight(name, 110*2) / 2;
62+
int finalIndex = index;
63+
panel.add(new CButton(5, y, 115, height, "",() -> {}) {
64+
@Override
65+
public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
66+
Rectangle b = getBounds();
67+
if (b.contains(mouseX, mouseY)) {
68+
DrawableHelper.fill(stack, b.x, b.y, b.x + b.width, b.y + b.height, 0x33000000);
69+
}
70+
}
71+
72+
@Override
73+
public boolean mouseClicked(double x, double y, int button) {
74+
if (getBounds().contains(x, y)) {
75+
DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK, 1f,1f));
76+
77+
if (button != 0) {
78+
CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
79+
DFScript.MC.setScreen(new ScriptAddSettingScreen(script, finalIndex));
80+
});
81+
CButton insertAfter = new CButton((int) x, (int) y+8, 40, 8, "Insert After", () -> {
82+
DFScript.MC.setScreen(new ScriptAddSettingScreen(script, finalIndex + 1));
83+
});
84+
CButton delete = new CButton((int) x, (int) y+16, 40, 8, "Delete", () -> {
85+
script.getOptions().remove(finalIndex);
86+
scroll = panel.getScroll();
87+
DFScript.MC.setScreen(new ScriptSettingsScreen(script));
88+
});
89+
DFScript.MC.send(() -> {
90+
panel.add(insertBefore);
91+
panel.add(insertAfter);
92+
panel.add(delete);
93+
contextMenu.add(insertBefore);
94+
contextMenu.add(insertAfter);
95+
contextMenu.add(delete);
96+
});
97+
}
98+
return true;
99+
}
100+
return false;
101+
}
102+
});
103+
104+
y += height;
105+
y++;
106+
41107
y = option.create(panel, 5, y, 105);
42108

43109
index++;
@@ -56,4 +122,16 @@ public ScriptSettingsScreen(Script script) {
56122
public void close() {
57123
DFScript.MC.setScreen(new ScriptEditScreen(script));
58124
}
59-
}
125+
126+
public boolean mouseClicked(double mouseX, double mouseY, int button) {
127+
boolean b = super.mouseClicked(mouseX, mouseY, button);
128+
clearContextMenu();
129+
return b;
130+
}
131+
private void clearContextMenu() {
132+
for (CWidget w : contextMenu) {
133+
panel.remove(w);
134+
}
135+
contextMenu.clear();
136+
}
137+
}

src/main/java/io/github/techstreet/dfscript/script/options/ScriptOption.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import io.github.techstreet.dfscript.screen.widget.CScrollPanel;
44
import io.github.techstreet.dfscript.script.values.ScriptValue;
5+
import net.minecraft.text.Text;
56

67
public interface ScriptOption {
78
String name = "Default Config Option Name";
89

910
ScriptValue getValue();
1011

12+
String getName();
13+
1114
int create(CScrollPanel panel, int x, int y, int width); // the return value = new y
1215
}

src/main/java/io/github/techstreet/dfscript/script/options/ScriptTextOption.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public ScriptValue getValue() {
1414
return new ScriptTextValue(value);
1515
}
1616

17+
@Override
18+
public String getName() { return name; }
19+
1720
@Override
1821
public int create(CScrollPanel panel, int x, int y, int width) {
1922
CTextField field = new CTextField(value, x, y, width, 10, true);

0 commit comments

Comments
 (0)