diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md
new file mode 100644
index 0000000..b986ecb
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug-report.md
@@ -0,0 +1,28 @@
+---
+name: Bug Report
+about: Create a report to help us improve the mod.
+title: ''
+labels: bug
+assignees: ''
+
+---
+
+**Describe the bug**
+[A clear and simple description of what the bug is **Remove this line!**]
+
+**To Reproduce**
+Steps to reproduce the behaviour:
+1. [replace with]
+2. [all the steps]
+3. [required to explain]
+4. [how to reproduce]
+5. [remove/add steps as you see fit]
+
+**Mod Version and OS**
+[What mod version are you using and operating system. **Remove this line!**]
+
+**Screenshot/Video**
+[Screenshots/video evidence of the issue occuring is applicable. **Remove this line!**]
+
+**Effected Scripts**
+[Add any website links to effected scripts. **Remove this line!**]
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..f70a98a
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,5 @@
+blank_issues_enabled: false
+contact_links:
+ - name: Discord Contact
+ url: https://discord.gg/gtfFwWEapx
+ about: Contact us via our discord
\ No newline at end of file
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 82aec44..82b20ac 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -8,6 +8,20 @@ on:
jobs:
build:
runs-on: ubuntu-latest
+ permissions:
+ actions: write
+ checks: write
+ contents: write
+ deployments: write
+ id-token: write
+ issues: write
+ discussions: write
+ packages: write
+ pages: write
+ pull-requests: write
+ repository-projects: write
+ security-events: write
+ statuses: write
steps:
- uses: actions/checkout@v1
- name: Set up JDK 17
diff --git a/README.md b/README.md
index 6b3dbb9..4eccbc9 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
-[![Build](https://github.com/DFOnline/DFScript/actions/workflows/build.yml/badge.svg)
-](https://github.com/DFOnline/DFScript/actions/workflows/build.yml)
+[![Build](https://github.com/DFScripting/DFScript/actions/workflows/build.yml/badge.svg)
+](https://github.com/DFScripting/DFScript/actions/workflows/build.yml)
# DFScript
DFScript is a mod created for DiamondFire to allow scripting on the client. This mod is a seperation and improvement from the shutdown mod [CodeUtilities](https://github.com/CodeUtilities/CodeUtilities).
-- You can download DFScript from its [Github page](https://github.com/DFOnline/DFScript/releases/latest), or its [Modrinth page](https://modrinth.com/mod/dfscript).
-- You can report issues on [the issues tab](https://github.com/DFOnline/DFScript/issues)
+- You can download DFScript from its [Github page](https://github.com/DFScripting/DFScript/releases/latest), or its [Modrinth page](https://modrinth.com/mod/dfscript).
+- You can report issues on [the issues tab](https://github.com/DFScripting/DFScript/issues)
- You can join our [discord here](https://discord.gg/gtfFwWEapx)
@@ -107,8 +107,8 @@ You can easily back up scripts here by copy and pasting the json file into anoth
___
-
-
-
-
+
+
+
+
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000..987e495
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,9 @@
+# Security Policy
+
+## Definition of a Vulnerability
+We define a security vulnerability to be a weakness in a product, service, or software that could allow an attacker to comprimise the integrity, availability, or data of that product, service, or software.
+
+## Reporting a Vulnerability
+**Please do not report security vulnerabilities publically (e.g. through discord, creating a GitHub issue).**
+
+If you believe that the security issue you have found is considered to be a vulnerability under our definition then please report it to us via github, or email us at **vulnerability@techstreet.tech**.
diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java b/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java
index 1c7ef3c..568fa36 100644
--- a/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java
@@ -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);
}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java
index 7499eaa..bb5c533 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java
@@ -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;
@@ -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);
@@ -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);
+ }
}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java
index 08fcad6..2b315e8 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java
@@ -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()
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CDragPanel.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CDragPanel.java
new file mode 100644
index 0000000..4413c03
--- /dev/null
+++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CDragPanel.java
@@ -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;
+ }
+}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CPanel.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CPanel.java
new file mode 100644
index 0000000..ae4f415
--- /dev/null
+++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CPanel.java
@@ -0,0 +1,219 @@
+package io.github.techstreet.dfscript.screen.widget;
+
+import io.github.techstreet.dfscript.DFScript;
+import io.github.techstreet.dfscript.util.RenderUtil;
+import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.util.math.MatrixStack;
+import org.joml.Vector4f;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class CPanel implements CWidget {
+ private final List children = new ArrayList<>();
+ private final int x, y, width, height;
+
+ public CPanel(int x, int y, int w, int h) {
+ this.x = x;
+ this.y = y;
+ this.width = w;
+ this.height = h;
+ }
+
+ public abstract double getOffsetCenterX();
+ public abstract double getOffsetCenterY();
+
+ @Override
+ public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
+ MatrixStack stack = context.getMatrices();
+ stack.push();
+
+ stack.translate(x, y, 0);
+ mouseX -= x;
+ mouseY -= y;
+
+ float xPos = stack.peek().getPositionMatrix().m30();
+ float yPos = stack.peek().getPositionMatrix().m31();
+
+ Vector4f begin = new Vector4f(xPos, yPos, 1, 1);
+ Vector4f end = new Vector4f(xPos + (width * 2), yPos + (height * 2), 1, 1);
+
+ int guiScale = (int) DFScript.MC.getWindow().getScaleFactor();
+ RenderUtil.pushScissor(
+ (int) begin.x()*guiScale,
+ (int) begin.y()*guiScale,
+ (int) (end.x() - begin.x())*guiScale,
+ (int) (end.y() - begin.y())*guiScale
+ );
+
+ double scroll = getOffsetCenterY();
+ double hScroll = getOffsetCenterX();
+ stack.translate(hScroll, scroll, 0);
+ mouseY -= scroll;
+ mouseX -= hScroll;
+
+ for (CWidget child : children) {
+ child.render(context, mouseX, mouseY, tickDelta);
+ }
+
+ RenderUtil.popScissor();
+ stack.pop();
+ }
+
+ @Override
+ public boolean mouseClicked(double x, double y, int button) {
+ if(!getBounds().contains(x, y)) {
+ return false;
+ }
+
+ x -= getOffsetCenterX();
+ y -= getOffsetCenterY();
+ x -= this.x;
+ y -= this.y;
+
+ for (int i = children.size() - 1; i >= 0; i--) {
+ if (children.get(i).mouseClicked(x, y, button)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean mouseReleased(double x, double y, int button) {
+ if(!getBounds().contains(x, y)) {
+ return false;
+ }
+
+ x -= getOffsetCenterX();
+ y -= getOffsetCenterY();
+ x -= this.x;
+ y -= this.y;
+
+ for (int i = children.size() - 1; i >= 0; i--) {
+ if (children.get(i).mouseReleased(x, y, button)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean mouseDragged(double x, double y, int button, double dx, double dy) {
+ if(!getBounds().contains(x, y)) {
+ return false;
+ }
+
+ x -= getOffsetCenterX();
+ y -= getOffsetCenterY();
+ x -= this.x;
+ y -= this.y;
+
+ for (int i = children.size() - 1; i >= 0; i--) {
+ if (children.get(i).mouseDragged(x, y, button, dx, dy)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void charTyped(char ch, int keyCode) {
+ for (CWidget child : children) {
+ child.charTyped(ch, keyCode);
+ }
+ }
+
+ @Override
+ public void keyPressed(int keyCode, int scanCode, int modifiers) {
+ for (CWidget child : children) {
+ child.keyPressed(keyCode, scanCode, modifiers);
+ }
+ }
+
+ @Override
+ public void keyReleased(int keyCode, int scanCode, int modifiers) {
+ for (CWidget child : children) {
+ child.keyReleased(keyCode, scanCode, modifiers);
+ }
+ }
+
+ @Override
+ public boolean mouseScrolled(double mouseX, double mouseY, double vertical, double horizontal) {
+ if(!getBounds().contains(mouseX, mouseY)) {
+ return false;
+ }
+
+ mouseX -= getOffsetCenterX();
+ mouseY -= getOffsetCenterY();
+ mouseX -= this.x;
+ mouseY -= this.y;
+
+ for (CWidget child : children) {
+ if(child.mouseScrolled(mouseX, mouseY, vertical, horizontal)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void add(CWidget child) {
+ children.add(child);
+ }
+
+ public void clear() { children.clear(); }
+
+ @Override
+ public void renderOverlay(DrawContext context, int mouseX, int mouseY, float tickDelta) {
+ MatrixStack stack = context.getMatrices();
+ stack.push();
+ stack.translate(x, y, 0);
+ mouseX -= x;
+ mouseY -= y;
+ double scroll = getOffsetCenterY();
+ double hScroll = getOffsetCenterX();
+ if(mouseX < 0 || mouseX > width) {
+ mouseX = -99999;
+ }
+ else {
+ mouseX -= hScroll;
+ }
+ if(mouseY < 0 || mouseY > height) {
+ mouseY = -99999;
+ }
+ else {
+ mouseY -= scroll;
+ }
+ stack.translate(hScroll, scroll, 0);
+ for (CWidget child : children) {
+ child.renderOverlay(context, mouseX, mouseY, tickDelta);
+ }
+ stack.pop();
+ }
+
+ @Override
+ public Rectangle getBounds() {
+ return new Rectangle(x, y, width, height);
+ }
+
+ public CWidget[] getChildren() {
+ return children.toArray(new CWidget[0]);
+ }
+
+ @Override
+ public boolean enableClosingOnEsc() {
+ for(CWidget widget : children) {
+ if(!widget.enableClosingOnEsc())
+ {
+ return false;
+ }
+ }
+
+ return CWidget.super.enableClosingOnEsc();
+ }
+
+ public void remove(CWidget w) {
+ children.remove(w);
+ }
+}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CPlainPanel.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CPlainPanel.java
index bdbd089..9184cb6 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CPlainPanel.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CPlainPanel.java
@@ -10,120 +10,19 @@
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Vector4f;
-public class CPlainPanel implements CWidget {
-
- private final List children = new ArrayList<>();
- private final int x, y, width, height;
+public class CPlainPanel extends CPanel {
public CPlainPanel(int x, int y, int w, int h) {
- this.x = x;
- this.y = y;
- this.width = w;
- this.height = h;
- }
-
- @Override
- public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
- MatrixStack stack = context.getMatrices();
- stack.push();
- stack.translate(x, y, 0);
-
- float xPos = stack.peek().getPositionMatrix().m30() + x;
- float yPos = stack.peek().getPositionMatrix().m31() - y;
-
- Vector4f begin = new Vector4f(xPos, yPos, 1, 1);
- Vector4f end = new Vector4f(xPos + (width * 2), yPos + (height * 2), 1, 1);
-
- int guiScale = (int) DFScript.MC.getWindow().getScaleFactor();
- RenderUtil.pushScissor(
- (int) begin.x()*guiScale,
- (int) begin.y()*guiScale,
- (int) (end.x() - begin.x())*guiScale,
- (int) (end.y() - begin.y())*guiScale
- );
-
- for (CWidget child : children) {
- child.render(context, mouseX, mouseY, tickDelta);
- }
-
- RenderUtil.popScissor();
- stack.pop();
- }
-
- @Override
- public boolean mouseClicked(double x, double y, int button) {
- for (int i = children.size() - 1; i >= 0; i--) {
- if (children.get(i).mouseClicked(x, y, button)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public void charTyped(char ch, int keyCode) {
- for (CWidget child : children) {
- child.charTyped(ch, keyCode);
- }
- }
-
- @Override
- public void keyPressed(int keyCode, int scanCode, int modifiers) {
- for (CWidget child : children) {
- child.keyPressed(keyCode, scanCode, modifiers);
- }
- }
-
- @Override
- public void mouseScrolled(double mouseX, double mouseY, double vertical, double horizontal) {
- for (CWidget child : children) {
- child.mouseScrolled(mouseX, mouseY, vertical, horizontal);
- }
- }
-
- private int getMaxScroll() {
- int max = 0;
- for (CWidget child : children) {
- max = Math.max(max, child.getBounds().y + child.getBounds().height);
- }
- return max - height;
- }
-
- public void add(CWidget child) {
- children.add(child);
- }
-
- public void clear() { children.clear(); }
-
- @Override
- public void renderOverlay(DrawContext context, int mouseX, int mouseY, float tickDelta) {
- MatrixStack stack = context.getMatrices();
- stack.push();
- stack.translate(x, y, 0);
- for (CWidget child : children) {
- child.renderOverlay(context, mouseX, mouseY, tickDelta);
- }
- stack.pop();
+ super(x, y, w, h);
}
@Override
- public Rectangle getBounds() {
- return new Rectangle(x, y, width, height);
- }
-
- public CWidget[] getChildren() {
- return children.toArray(new CWidget[0]);
+ public double getOffsetCenterX() {
+ return 0;
}
@Override
- public boolean enableClosingOnEsc() {
- for(CWidget widget : children) {
- if(!widget.enableClosingOnEsc())
- {
- return false;
- }
- }
-
- return CWidget.super.enableClosingOnEsc();
+ public double getOffsetCenterY() {
+ return 0;
}
}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CScrollPanel.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CScrollPanel.java
index 5e3e904..7f6f405 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CScrollPanel.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CScrollPanel.java
@@ -10,96 +10,37 @@
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Vector4f;
-public class CScrollPanel implements CWidget {
-
- private final List children = new ArrayList<>();
+public class CScrollPanel extends CPanel {
private int scroll = 0;
- private final int x, y, width, height;
public CScrollPanel(int x, int y, int w, int h) {
- this.x = x;
- this.y = y;
- this.width = w;
- this.height = h;
+ super(x,y,w,h);
}
@Override
- public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
- MatrixStack stack = context.getMatrices();
- stack.push();
- stack.translate(x, y, 0);
-
- mouseX -= x;
- mouseY -= y;
-
- float xpos = stack.peek().getPositionMatrix().m30() + x;
- float ypos = stack.peek().getPositionMatrix().m31() - y;
-
- Vector4f begin = new Vector4f(xpos, ypos, 1, 1);
- Vector4f end = new Vector4f(xpos + (width * 2), ypos + (height * 2), 1, 1);
-
- int guiScale = (int) DFScript.MC.getWindow().getScaleFactor();
- RenderUtil.pushScissor(
- (int) begin.x()*guiScale,
- (int) begin.y()*guiScale,
- (int) (end.x() - begin.x())*guiScale,
- (int) (end.y() - begin.y())*guiScale
- );
-
- stack.translate(0, scroll, 0);
- mouseY -= scroll;
-
- for (CWidget child : children) {
- child.render(context, mouseX, mouseY, tickDelta);
- }
-
- RenderUtil.popScissor();
- stack.pop();
+ public double getOffsetCenterX() {
+ return 0;
}
@Override
- public boolean mouseClicked(double x, double y, int button) {
- if(!getBounds().contains(x, y)) {
- return false;
- }
-
- y -= scroll;
- x -= this.x;
- y -= this.y;
- for (int i = children.size() - 1; i >= 0; i--) {
- if (children.get(i).mouseClicked(x, y, button)) {
- return true;
- }
- }
- return false;
+ public double getOffsetCenterY() {
+ return scroll;
}
- @Override
- public void charTyped(char ch, int keyCode) {
- for (CWidget child : children) {
- child.charTyped(ch, keyCode);
+ private int getMaxScroll() {
+ int max = 0;
+ for (CWidget child : getChildren()) {
+ max = Math.max(max, child.getBounds().y + child.getBounds().height);
}
+ return max - getBounds().height;
}
- @Override
- public void keyPressed(int keyCode, int scanCode, int modifiers) {
- for (CWidget child : children) {
- child.keyPressed(keyCode, scanCode, modifiers);
- }
+ public int getScroll() {
+ return scroll;
}
- @Override
- public void mouseScrolled(double mouseX, double mouseY, double vertical, double horizontal) {
- if(!getBounds().contains(mouseX, mouseY)) {
- return;
- }
-
- mouseX -= x;
- mouseY -= y;
- for (CWidget child : children) {
- child.mouseScrolled(mouseX, mouseY, vertical, horizontal);
- }
- scroll += vertical * 5;
+ public void setScroll(int s) {
+ scroll = s;
if (scroll < -getMaxScroll()) {
scroll = -getMaxScroll();
@@ -108,55 +49,19 @@ public void mouseScrolled(double mouseX, double mouseY, double vertical, double
if (scroll > 0) {
scroll = 0;
}
-
}
- private int getMaxScroll() {
- int max = 0;
- for (CWidget child : children) {
- max = Math.max(max, child.getBounds().y + child.getBounds().height);
- }
- return max - height;
- }
-
- public void add(CWidget child) {
- children.add(child);
- }
-
- public void clear() { children.clear(); }
-
@Override
- public void renderOverlay(DrawContext context, int mouseX, int mouseY, float tickDelta) {
- MatrixStack stack = context.getMatrices();
- mouseY -= scroll;
-
- mouseX -= x;
- mouseY -= y;
-
- stack.push();
- stack.translate(x, y, 0);
- stack.translate(0, scroll, 0);
- for (CWidget child : children) {
- child.renderOverlay(context, mouseX, mouseY, tickDelta);
+ public boolean mouseScrolled(double mouseX, double mouseY, double vertical, double horizontal) {
+ if(!getBounds().contains(mouseX, mouseY)) {
+ return false;
}
- stack.pop();
- }
-
- @Override
- public Rectangle getBounds() {
- return new Rectangle(x, y, width, height);
- }
- public CWidget[] getChildren() {
- return children.toArray(new CWidget[0]);
- }
-
- public int getScroll() {
- return scroll;
- }
+ if(super.mouseScrolled(mouseX, mouseY, vertical, horizontal)) {
+ return true;
+ }
- public void setScroll(int s) {
- scroll = s;
+ scroll += vertical * 5;
if (scroll < -getMaxScroll()) {
scroll = -getMaxScroll();
@@ -165,21 +70,7 @@ public void setScroll(int s) {
if (scroll > 0) {
scroll = 0;
}
- }
-
- public void remove(CWidget w) {
- children.remove(w);
- }
-
- @Override
- public boolean enableClosingOnEsc() {
- for(CWidget widget : children) {
- if(!widget.enableClosingOnEsc())
- {
- return false;
- }
- }
- return CWidget.super.enableClosingOnEsc();
+ return true;
}
}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CTextField.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CTextField.java
index 0330533..805e6cd 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CTextField.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CTextField.java
@@ -318,9 +318,9 @@ public boolean mouseClicked(double x, double y, int button) {
}
@Override
- public void mouseScrolled(double mouseX, double mouseY, double vertical, double horizontal) {
+ public boolean mouseScrolled(double mouseX, double mouseY, double vertical, double horizontal) {
if (!editable || !selected) {
- return;
+ return false;
}
TextRenderer f = DFScript.MC.textRenderer;
@@ -349,6 +349,8 @@ public void mouseScrolled(double mouseX, double mouseY, double vertical, double
scroll = Math.min(0, Math.max(scroll, -(getLines().length + 1) * f.fontHeight / 2 + height - 2));
xScroll += horizontal * 5;
xScroll = Math.min(0, Math.max(xScroll, -maxScroll));
+
+ return true;
}
public int getCursorLineIndex() {
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CWidget.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CWidget.java
index 4555fbc..b757ff9 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CWidget.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CWidget.java
@@ -21,7 +21,8 @@ default void keyPressed(int keyCode, int scanCode, int modifiers) {
default void keyReleased(int keyCode, int scanCode, int modifiers) {
}
- default void mouseScrolled(double mouseX, double mouseY, double vertical, double horizontal) {
+ default boolean mouseScrolled(double mouseX, double mouseY, double vertical, double horizontal) {
+ return false;
}
default void renderOverlay(DrawContext context, int mouseX, int mouseY, float tickDelta) {
@@ -33,4 +34,12 @@ default void renderOverlay(DrawContext context, int mouseX, int mouseY, float ti
default boolean enableClosingOnEsc(){
return true;
}
+
+ default boolean mouseReleased(double x, double y, int button) {
+ return false;
+ }
+
+ default boolean mouseDragged(double x, double y, int button, double deltaX, double deltaY) {
+ return false;
+ }
}
diff --git a/src/main/java/io/github/techstreet/dfscript/util/RenderUtil.java b/src/main/java/io/github/techstreet/dfscript/util/RenderUtil.java
index 46b99b3..3e797ff 100644
--- a/src/main/java/io/github/techstreet/dfscript/util/RenderUtil.java
+++ b/src/main/java/io/github/techstreet/dfscript/util/RenderUtil.java
@@ -12,6 +12,7 @@
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
+import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.lwjgl.opengl.GL11;
@@ -40,6 +41,8 @@ public static void renderImage(DrawContext context, int x, int y, int width, int
bb.vertex(stack.peek().getPositionMatrix(), x + width, y + height, 0).texture(ux+uw, uy+uh).next();
bb.vertex(stack.peek().getPositionMatrix(), x, y + height, 0).texture(ux, uy+uh).next();
tessellator.draw();
+
+ RenderSystem.enableCull();
}
public static void renderButton(DrawContext context, int x, int y, int width, int height, boolean hovered, boolean disabled) {
@@ -165,7 +168,6 @@ public static void popScissor() {
public static void renderGuiItem(DrawContext context, ItemStack item) {
MatrixStack stack = context.getMatrices();
stack.push();
- stack.translate(0.0F, 0.0F, 100.0F);
stack.scale(0.5F,0.5F,1F);
context.drawItem(item, 0, 0);
stack.pop();