Skip to content

Commit 789c02f

Browse files
Merge pull request #49 from XTerPL/UIImprovement
CItem Rendering Fix
2 parents f31f465 + 2b3aeea commit 789c02f

File tree

10 files changed

+384
-459
lines changed

10 files changed

+384
-459
lines changed

src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public class MOptionsScreen extends Screen {
2121
@Unique
2222
private final Identifier identifier_main_highlight = new Identifier(DFScript.MOD_ID + ":scripts_highlight");
2323

24+
@Unique
25+
private final Identifier identifier_test = new Identifier(DFScript.MOD_ID + ":scripts");
26+
@Unique
27+
private final Identifier identifier_test_highlight = new Identifier(DFScript.MOD_ID + ":scripts_highlight");
28+
2429
public MOptionsScreen(Text literalText) {
2530
super(literalText);
2631
}

src/main/java/io/github/techstreet/dfscript/screen/CScreen.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraft.client.gui.DrawContext;
1010
import net.minecraft.client.gui.screen.Screen;
1111
import net.minecraft.client.util.math.MatrixStack;
12+
import net.minecraft.item.Items;
1213
import net.minecraft.text.Text;
1314
import org.jetbrains.annotations.NotNull;
1415

@@ -38,7 +39,7 @@ public void render(@NotNull DrawContext context, int mouseX, int mouseY, float t
3839

3940
// float scaleFactor = (float) mc.getWindow().getScaleFactor();
4041
float scaleFactor = 2;
41-
stack.scale(scaleFactor,scaleFactor,0);
42+
stack.scale(scaleFactor,scaleFactor,1F);
4243

4344
stack.translate(-width/2f, -height/2f, 0);
4445

@@ -143,4 +144,34 @@ public boolean shouldCloseOnEsc() {
143144

144145
return super.shouldCloseOnEsc();
145146
}
147+
148+
@Override
149+
public boolean mouseReleased(double mouseX, double mouseY, int button) {
150+
mouseX = translateMouseX(mouseX);
151+
mouseY = translateMouseY(mouseY);
152+
153+
for (int i = widgets.size() - 1; i >= 0; i--) {
154+
if (widgets.get(i).mouseReleased(mouseX, mouseY, button)) {
155+
break;
156+
}
157+
}
158+
159+
return super.mouseReleased(mouseX, mouseY, button);
160+
}
161+
162+
@Override
163+
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
164+
mouseX = translateMouseX(mouseX);
165+
mouseY = translateMouseY(mouseY);
166+
deltaX = translateMouseX(deltaX);
167+
deltaY = translateMouseY(deltaY);
168+
169+
for (int i = widgets.size() - 1; i >= 0; i--) {
170+
if (widgets.get(i).mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) {
171+
break;
172+
}
173+
}
174+
175+
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
176+
}
146177
}

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

Lines changed: 0 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -35,221 +35,6 @@ public ScriptEditScreen(Script script) {
3535
this.script = script;
3636

3737
reload();
38-
/*panel = new CScrollPanel(0, 3, 120, 94);
39-
40-
//CTextField description = new CTextField(script.getDescription(), 3, 3, 115, 20, true);
41-
//description.setChangedListener(() -> script.setDescription(description.getText()));
42-
//panel.add(description);
43-
44-
widgets.add(panel);
45-
46-
int y = 0;
47-
int index = 0;
48-
int indent = 0;
49-
50-
CText name = new CText(5,y+2,Text.literal(script.getName()),0,1,false,false);
51-
panel.add(name);
52-
53-
CButton settings = new CTexturedButton(120-8, y, 8, 8, DFScript.MOD_ID + ":settings.png", () -> {
54-
DFScript.MC.setScreen(new ScriptSettingsScreen(this.script, true));
55-
}, 0, 0, 1, 0.5f, 0, 0.5f);
56-
57-
panel.add(settings);
58-
59-
y += 10;
60-
61-
for (ScriptPart part : script.getParts()) {
62-
if (part instanceof ScriptEvent se) {
63-
panel.add(new CItem(5, y, se.getType().getIcon()));
64-
panel.add(new CText(15, y + 2, Text.literal(se.getType().getName())));
65-
indent = 5;
66-
67-
int currentIndex = index;
68-
panel.add(new CButton(5, y-1, 115, 10, "",() -> {}) {
69-
@Override
70-
public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
71-
Rectangle b = getBounds();
72-
73-
if (b.contains(mouseX, mouseY)) {
74-
int color = 0x33000000;
75-
76-
DrawableHelper.fill(stack, b.x, b.y, b.x + b.width, b.y + b.height, color);
77-
}
78-
}
79-
80-
@Override
81-
public boolean mouseClicked(double x, double y, int button) {
82-
if (getBounds().contains(x, y)) {
83-
DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK, 1f,1f));
84-
85-
if (button != 0) {
86-
CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
87-
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex));
88-
});
89-
CButton insertAfter = new CButton((int) x, (int) y+8, 40, 8, "Insert After", () -> {
90-
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex + 1));
91-
});
92-
CButton delete = new CButton((int) x, (int) y+16, 40, 8, "Delete", () -> {
93-
script.getParts().remove(currentIndex);
94-
scroll = panel.getScroll();
95-
DFScript.MC.setScreen(new ScriptEditScreen(script));
96-
});
97-
DFScript.MC.send(() -> {
98-
panel.add(insertBefore);
99-
panel.add(insertAfter);
100-
panel.add(delete);
101-
contextMenu.add(insertBefore);
102-
contextMenu.add(insertAfter);
103-
contextMenu.add(delete);
104-
});
105-
}
106-
return true;
107-
}
108-
return false;
109-
}
110-
});
111-
} else if (part instanceof ScriptAction sa) {
112-
if (sa.getType() == ScriptActionType.CLOSE_BRACKET) {
113-
indent -= 5;
114-
}
115-
116-
panel.add(new CItem(5 + indent, y, sa.getType().getIcon()));
117-
panel.add(new CText(15 + indent, y + 2, Text.literal(sa.getType().getName())));
118-
119-
createIndent(indent, y);
120-
121-
int currentIndex = index;
122-
panel.add(new CButton(5, y - 1, 115, 10, "", () -> {
123-
}) {
124-
@Override
125-
public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
126-
Rectangle b = getBounds();
127-
if (b.contains(mouseX, mouseY)) {
128-
int color = 0x33000000;
129-
130-
if (sa.getType().isDeprecated()) {
131-
color = 0x80FF0000;
132-
}
133-
134-
DrawableHelper.fill(stack, b.x, b.y, b.x + b.width, b.y + b.height, color);
135-
} else {
136-
if (sa.getType().isDeprecated()) {
137-
DrawableHelper.fill(stack, b.x, b.y, b.x + b.width, b.y + b.height, 0x33FF0000);
138-
}
139-
}
140-
}
141-
142-
@Override
143-
public boolean mouseClicked(double x, double y, int button) {
144-
if (getBounds().contains(x, y)) {
145-
DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK, 1f, 1f));
146-
147-
if (button == 0) {
148-
if (sa.getType() != ScriptActionType.CLOSE_BRACKET) {
149-
scroll = panel.getScroll();
150-
DFScript.MC.setScreen(new ScriptEditActionScreen(sa, script));
151-
}
152-
} else {
153-
CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
154-
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex));
155-
});
156-
CButton insertAfter = new CButton((int) x, (int) y + 8, 40, 8, "Insert After", () -> {
157-
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex + 1));
158-
});
159-
CButton delete = new CButton((int) x, (int) y + 16, 40, 8, "Delete", () -> {
160-
script.getParts().remove(currentIndex);
161-
scroll = panel.getScroll();
162-
DFScript.MC.setScreen(new ScriptEditScreen(script));
163-
});
164-
DFScript.MC.send(() -> {
165-
panel.add(insertBefore);
166-
panel.add(insertAfter);
167-
panel.add(delete);
168-
contextMenu.add(insertBefore);
169-
contextMenu.add(insertAfter);
170-
contextMenu.add(delete);
171-
});
172-
}
173-
return true;
174-
}
175-
return false;
176-
}
177-
});
178-
179-
if (sa.getType().hasChildren()) {
180-
indent += 5;
181-
}
182-
} else if (part instanceof ScriptComment sc) {
183-
panel.add(new CItem(5 + indent, y, new ItemStack(Items.MAP).setCustomName(Text.literal("Comment").setStyle(Style.EMPTY.withItalic(false)))));
184-
185-
CTextField cTextField = new CTextField(sc.getComment(),15+indent, y-1, width-(15+indent)-5, 10, true);
186-
187-
cTextField.setChangedListener(() -> sc.setComment(cTextField.getText()));
188-
189-
panel.add(cTextField);
190-
191-
int currentIndex = index;
192-
193-
panel.add(new CButton(5, y-1, 115, 10, "",() -> {}) {
194-
@Override
195-
public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
196-
Rectangle b = getBounds();
197-
198-
if (b.contains(mouseX, mouseY)) {
199-
int color = 0x33000000;
200-
201-
DrawableHelper.fill(stack, b.x, b.y, b.x + b.width, b.y + b.height, color);
202-
}
203-
}
204-
205-
@Override
206-
public boolean mouseClicked(double x, double y, int button) {
207-
if (getBounds().contains(x, y)) {
208-
DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK, 1f,1f));
209-
210-
if (button != 0) {
211-
CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
212-
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex));
213-
});
214-
CButton insertAfter = new CButton((int) x, (int) y+8, 40, 8, "Insert After", () -> {
215-
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex + 1));
216-
});
217-
CButton delete = new CButton((int) x, (int) y+16, 40, 8, "Delete", () -> {
218-
script.getParts().remove(currentIndex);
219-
scroll = panel.getScroll();
220-
DFScript.MC.setScreen(new ScriptEditScreen(script));
221-
});
222-
DFScript.MC.send(() -> {
223-
panel.add(insertBefore);
224-
panel.add(insertAfter);
225-
panel.add(delete);
226-
contextMenu.add(insertBefore);
227-
contextMenu.add(insertAfter);
228-
contextMenu.add(delete);
229-
});
230-
231-
return true;
232-
}
233-
}
234-
return false;
235-
}
236-
});
237-
238-
createIndent(indent, y);
239-
} else {
240-
throw new IllegalArgumentException("Unknown script part type");
241-
}
242-
243-
y += 10;
244-
index++;
245-
}
246-
247-
CButton add = new CButton(37, y, 46, 8, "Add", () -> {
248-
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, script.getParts().size()));
249-
});
250-
251-
panel.add(add);
252-
panel.setScroll(scroll);*/
25338
}
25439

25540
public void reload()
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package io.github.techstreet.dfscript.screen.widget;
2+
3+
import io.github.techstreet.dfscript.util.chat.ChatUtil;
4+
5+
public class CDragPanel extends CPanel {
6+
private double offsetX = 0;
7+
private double offsetY = 0;
8+
9+
boolean moveOffset = false;
10+
double lastMouseX = 0;
11+
double lastMouseY = 0;
12+
13+
public CDragPanel(int x, int y, int w, int h) {
14+
super(x,y,w,h);
15+
}
16+
17+
@Override
18+
public double getOffsetCenterX() {
19+
return offsetX;
20+
}
21+
22+
@Override
23+
public double getOffsetCenterY() {
24+
return offsetY;
25+
}
26+
27+
public void setOffset(double x, double y) {
28+
offsetX = x;
29+
offsetY = y;
30+
}
31+
32+
@Override
33+
public boolean mouseClicked(double x, double y, int button) {
34+
if(getBounds().contains(x, y)) {
35+
if(super.mouseClicked(x, y, button)) {
36+
return true;
37+
}
38+
39+
moveOffset = true;
40+
lastMouseX = x;
41+
lastMouseY = y;
42+
return true;
43+
}
44+
45+
return false;
46+
}
47+
48+
@Override
49+
public boolean mouseReleased(double x, double y, int button) {
50+
if(getBounds().contains(x, y)) {
51+
if(super.mouseReleased(x, y, button)) {
52+
return true;
53+
}
54+
}
55+
56+
if(moveOffset) {
57+
moveOffset = false;
58+
return true;
59+
}
60+
61+
return false;
62+
}
63+
64+
@Override
65+
public boolean mouseDragged(double x, double y, int button, double dx, double dy) {
66+
if(getBounds().contains(x, y)) {
67+
if(super.mouseDragged(x, y, button, dx, dy)) {
68+
return true;
69+
}
70+
}
71+
72+
if(moveOffset) {
73+
offsetX += x - lastMouseX;
74+
offsetY += y - lastMouseY;
75+
lastMouseX = x;
76+
lastMouseY = y;
77+
return true;
78+
}
79+
80+
return false;
81+
}
82+
}

0 commit comments

Comments
 (0)