Skip to content

Commit

Permalink
Merge pull request #49 from XTerPL/UIImprovement
Browse files Browse the repository at this point in the history
CItem Rendering Fix
  • Loading branch information
TechStreetDev authored Jan 4, 2024
2 parents f31f465 + 2b3aeea commit 789c02f
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 459 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public class MOptionsScreen extends Screen {
@Unique
private final Identifier identifier_main_highlight = new Identifier(DFScript.MOD_ID + ":scripts_highlight");

@Unique
private final Identifier identifier_test = new Identifier(DFScript.MOD_ID + ":scripts");
@Unique
private final Identifier identifier_test_highlight = new Identifier(DFScript.MOD_ID + ":scripts_highlight");

public MOptionsScreen(Text literalText) {
super(literalText);
}
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/io/github/techstreet/dfscript/screen/CScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

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

// float scaleFactor = (float) mc.getWindow().getScaleFactor();
float scaleFactor = 2;
stack.scale(scaleFactor,scaleFactor,0);
stack.scale(scaleFactor,scaleFactor,1F);

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

Expand Down Expand Up @@ -143,4 +144,34 @@ public boolean shouldCloseOnEsc() {

return super.shouldCloseOnEsc();
}

@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
mouseX = translateMouseX(mouseX);
mouseY = translateMouseY(mouseY);

for (int i = widgets.size() - 1; i >= 0; i--) {
if (widgets.get(i).mouseReleased(mouseX, mouseY, button)) {
break;
}
}

return super.mouseReleased(mouseX, mouseY, button);
}

@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
mouseX = translateMouseX(mouseX);
mouseY = translateMouseY(mouseY);
deltaX = translateMouseX(deltaX);
deltaY = translateMouseY(deltaY);

for (int i = widgets.size() - 1; i >= 0; i--) {
if (widgets.get(i).mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) {
break;
}
}

return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,221 +35,6 @@ public ScriptEditScreen(Script script) {
this.script = script;

reload();
/*panel = new CScrollPanel(0, 3, 120, 94);
//CTextField description = new CTextField(script.getDescription(), 3, 3, 115, 20, true);
//description.setChangedListener(() -> script.setDescription(description.getText()));
//panel.add(description);
widgets.add(panel);
int y = 0;
int index = 0;
int indent = 0;
CText name = new CText(5,y+2,Text.literal(script.getName()),0,1,false,false);
panel.add(name);
CButton settings = new CTexturedButton(120-8, y, 8, 8, DFScript.MOD_ID + ":settings.png", () -> {
DFScript.MC.setScreen(new ScriptSettingsScreen(this.script, true));
}, 0, 0, 1, 0.5f, 0, 0.5f);
panel.add(settings);
y += 10;
for (ScriptPart part : script.getParts()) {
if (part instanceof ScriptEvent se) {
panel.add(new CItem(5, y, se.getType().getIcon()));
panel.add(new CText(15, y + 2, Text.literal(se.getType().getName())));
indent = 5;
int currentIndex = index;
panel.add(new CButton(5, y-1, 115, 10, "",() -> {}) {
@Override
public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
Rectangle b = getBounds();
if (b.contains(mouseX, mouseY)) {
int color = 0x33000000;
DrawableHelper.fill(stack, b.x, b.y, b.x + b.width, b.y + b.height, color);
}
}
@Override
public boolean mouseClicked(double x, double y, int button) {
if (getBounds().contains(x, y)) {
DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK, 1f,1f));
if (button != 0) {
CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex));
});
CButton insertAfter = new CButton((int) x, (int) y+8, 40, 8, "Insert After", () -> {
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex + 1));
});
CButton delete = new CButton((int) x, (int) y+16, 40, 8, "Delete", () -> {
script.getParts().remove(currentIndex);
scroll = panel.getScroll();
DFScript.MC.setScreen(new ScriptEditScreen(script));
});
DFScript.MC.send(() -> {
panel.add(insertBefore);
panel.add(insertAfter);
panel.add(delete);
contextMenu.add(insertBefore);
contextMenu.add(insertAfter);
contextMenu.add(delete);
});
}
return true;
}
return false;
}
});
} else if (part instanceof ScriptAction sa) {
if (sa.getType() == ScriptActionType.CLOSE_BRACKET) {
indent -= 5;
}
panel.add(new CItem(5 + indent, y, sa.getType().getIcon()));
panel.add(new CText(15 + indent, y + 2, Text.literal(sa.getType().getName())));
createIndent(indent, y);
int currentIndex = index;
panel.add(new CButton(5, y - 1, 115, 10, "", () -> {
}) {
@Override
public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
Rectangle b = getBounds();
if (b.contains(mouseX, mouseY)) {
int color = 0x33000000;
if (sa.getType().isDeprecated()) {
color = 0x80FF0000;
}
DrawableHelper.fill(stack, b.x, b.y, b.x + b.width, b.y + b.height, color);
} else {
if (sa.getType().isDeprecated()) {
DrawableHelper.fill(stack, b.x, b.y, b.x + b.width, b.y + b.height, 0x33FF0000);
}
}
}
@Override
public boolean mouseClicked(double x, double y, int button) {
if (getBounds().contains(x, y)) {
DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK, 1f, 1f));
if (button == 0) {
if (sa.getType() != ScriptActionType.CLOSE_BRACKET) {
scroll = panel.getScroll();
DFScript.MC.setScreen(new ScriptEditActionScreen(sa, script));
}
} else {
CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex));
});
CButton insertAfter = new CButton((int) x, (int) y + 8, 40, 8, "Insert After", () -> {
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex + 1));
});
CButton delete = new CButton((int) x, (int) y + 16, 40, 8, "Delete", () -> {
script.getParts().remove(currentIndex);
scroll = panel.getScroll();
DFScript.MC.setScreen(new ScriptEditScreen(script));
});
DFScript.MC.send(() -> {
panel.add(insertBefore);
panel.add(insertAfter);
panel.add(delete);
contextMenu.add(insertBefore);
contextMenu.add(insertAfter);
contextMenu.add(delete);
});
}
return true;
}
return false;
}
});
if (sa.getType().hasChildren()) {
indent += 5;
}
} else if (part instanceof ScriptComment sc) {
panel.add(new CItem(5 + indent, y, new ItemStack(Items.MAP).setCustomName(Text.literal("Comment").setStyle(Style.EMPTY.withItalic(false)))));
CTextField cTextField = new CTextField(sc.getComment(),15+indent, y-1, width-(15+indent)-5, 10, true);
cTextField.setChangedListener(() -> sc.setComment(cTextField.getText()));
panel.add(cTextField);
int currentIndex = index;
panel.add(new CButton(5, y-1, 115, 10, "",() -> {}) {
@Override
public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
Rectangle b = getBounds();
if (b.contains(mouseX, mouseY)) {
int color = 0x33000000;
DrawableHelper.fill(stack, b.x, b.y, b.x + b.width, b.y + b.height, color);
}
}
@Override
public boolean mouseClicked(double x, double y, int button) {
if (getBounds().contains(x, y)) {
DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK, 1f,1f));
if (button != 0) {
CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex));
});
CButton insertAfter = new CButton((int) x, (int) y+8, 40, 8, "Insert After", () -> {
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, currentIndex + 1));
});
CButton delete = new CButton((int) x, (int) y+16, 40, 8, "Delete", () -> {
script.getParts().remove(currentIndex);
scroll = panel.getScroll();
DFScript.MC.setScreen(new ScriptEditScreen(script));
});
DFScript.MC.send(() -> {
panel.add(insertBefore);
panel.add(insertAfter);
panel.add(delete);
contextMenu.add(insertBefore);
contextMenu.add(insertAfter);
contextMenu.add(delete);
});
return true;
}
}
return false;
}
});
createIndent(indent, y);
} else {
throw new IllegalArgumentException("Unknown script part type");
}
y += 10;
index++;
}
CButton add = new CButton(37, y, 46, 8, "Add", () -> {
DFScript.MC.setScreen(new ScriptActionCategoryScreen(script, script.getParts().size()));
});
panel.add(add);
panel.setScroll(scroll);*/
}

public void reload()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package io.github.techstreet.dfscript.screen.widget;

import io.github.techstreet.dfscript.util.chat.ChatUtil;

public class CDragPanel extends CPanel {
private double offsetX = 0;
private double offsetY = 0;

boolean moveOffset = false;
double lastMouseX = 0;
double lastMouseY = 0;

public CDragPanel(int x, int y, int w, int h) {
super(x,y,w,h);
}

@Override
public double getOffsetCenterX() {
return offsetX;
}

@Override
public double getOffsetCenterY() {
return offsetY;
}

public void setOffset(double x, double y) {
offsetX = x;
offsetY = y;
}

@Override
public boolean mouseClicked(double x, double y, int button) {
if(getBounds().contains(x, y)) {
if(super.mouseClicked(x, y, button)) {
return true;
}

moveOffset = true;
lastMouseX = x;
lastMouseY = y;
return true;
}

return false;
}

@Override
public boolean mouseReleased(double x, double y, int button) {
if(getBounds().contains(x, y)) {
if(super.mouseReleased(x, y, button)) {
return true;
}
}

if(moveOffset) {
moveOffset = false;
return true;
}

return false;
}

@Override
public boolean mouseDragged(double x, double y, int button, double dx, double dy) {
if(getBounds().contains(x, y)) {
if(super.mouseDragged(x, y, button, dx, dy)) {
return true;
}
}

if(moveOffset) {
offsetX += x - lastMouseX;
offsetY += y - lastMouseY;
lastMouseX = x;
lastMouseY = y;
return true;
}

return false;
}
}
Loading

0 comments on commit 789c02f

Please sign in to comment.