From b4f2a4256ce88fe6c2021acf7eadd8754bbf515b Mon Sep 17 00:00:00 2001 From: TechStreet Date: Tue, 2 Jan 2024 20:35:02 +0000 Subject: [PATCH 1/7] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 ___

- - - - + + + +

From fc403b1c05dc43d975f7f5cb0b0c99f0e9df0dab Mon Sep 17 00:00:00 2001 From: XTerPL Date: Thu, 4 Jan 2024 05:12:10 +0100 Subject: [PATCH 2/7] added CDragPanel, fixed the z-layering issue on most items and tried to fix the item lighting --- .../dfscript/mixin/render/MOptionsScreen.java | 9 + .../techstreet/dfscript/screen/CScreen.java | 30 +++ .../screen/script/ScriptEditScreen.java | 215 ----------------- .../dfscript/screen/script/TestScreen.java | 40 ++++ .../dfscript/screen/widget/CDragPanel.java | 82 +++++++ .../dfscript/screen/widget/CItem.java | 3 +- .../dfscript/screen/widget/CPanel.java | 219 ++++++++++++++++++ .../dfscript/screen/widget/CPlainPanel.java | 113 +-------- .../dfscript/screen/widget/CScrollPanel.java | 155 ++----------- .../dfscript/screen/widget/CTextField.java | 6 +- .../dfscript/screen/widget/CWidget.java | 11 +- .../techstreet/dfscript/util/RenderUtil.java | 4 +- 12 files changed, 428 insertions(+), 459 deletions(-) create mode 100644 src/main/java/io/github/techstreet/dfscript/screen/script/TestScreen.java create mode 100644 src/main/java/io/github/techstreet/dfscript/screen/widget/CDragPanel.java create mode 100644 src/main/java/io/github/techstreet/dfscript/screen/widget/CPanel.java 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..4826870 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 @@ -2,6 +2,7 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.screen.script.ScriptListScreen; +import io.github.techstreet.dfscript.screen.script.TestScreen; import io.github.techstreet.dfscript.util.render.BlendableTexturedButtonWidget; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.option.OptionsScreen; @@ -21,6 +22,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); } @@ -31,5 +37,8 @@ protected void init(CallbackInfo callbackInfo) { ScriptListScreen screen = new ScriptListScreen(DFScript.MC.player != null); DFScript.MC.setScreen(screen); })); + this.addDrawableChild(new BlendableTexturedButtonWidget(5, 30, 20, 20, identifier_test, identifier_test_highlight, (button) -> { + DFScript.MC.setScreen(new TestScreen()); + })); } } \ No newline at end of file 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..4d387f2 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java @@ -143,4 +143,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/script/TestScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/TestScreen.java new file mode 100644 index 0000000..a2e0ba9 --- /dev/null +++ b/src/main/java/io/github/techstreet/dfscript/screen/script/TestScreen.java @@ -0,0 +1,40 @@ +package io.github.techstreet.dfscript.screen.script; + +import com.google.gson.JsonObject; +import io.github.techstreet.dfscript.DFScript; +import io.github.techstreet.dfscript.features.AuthHandler; +import io.github.techstreet.dfscript.screen.CScreen; +import io.github.techstreet.dfscript.screen.widget.*; +import io.github.techstreet.dfscript.script.Script; +import io.github.techstreet.dfscript.script.ScriptManager; +import io.github.techstreet.dfscript.script.VirtualScript; +import io.github.techstreet.dfscript.script.util.UploadResponse; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import org.apache.commons.codec.binary.Base64; + +import java.awt.*; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.zip.GZIPOutputStream; + +public class TestScreen extends CScreen { + public TestScreen() { + super(160, 160); + + CDragPanel panel = new CDragPanel(0,0,160,160); + widgets.add(panel); + + CTextField field = new CTextField("", 50, 50, 100, 20, false); + + panel.add(field); + } +} 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/CItem.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java index db69ce0..06f0e47 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java @@ -43,7 +43,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) MatrixStack stack = context.getMatrices(); stack.push(); stack.translate(x, y, 0); - RenderUtil.renderGuiItem(context, item); + stack.scale(0.5F,0.5F,1F); + context.drawItem(item, 0, 0); if(countText != null) { stack.translate(4, 4, 0); 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(); From 2b3aeeaad87e8c505e2bd883428067ad91a38cb6 Mon Sep 17 00:00:00 2001 From: XTerPL Date: Thu, 4 Jan 2024 08:02:07 +0100 Subject: [PATCH 3/7] fixed the bad rendering on CItems the fix was to change a 0 to a 1 lmao --- .../dfscript/mixin/render/MOptionsScreen.java | 4 -- .../techstreet/dfscript/screen/CScreen.java | 3 +- .../dfscript/screen/script/TestScreen.java | 40 ------------------- .../dfscript/screen/widget/CItem.java | 3 +- 4 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 src/main/java/io/github/techstreet/dfscript/screen/script/TestScreen.java 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 4826870..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 @@ -2,7 +2,6 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.screen.script.ScriptListScreen; -import io.github.techstreet.dfscript.screen.script.TestScreen; import io.github.techstreet.dfscript.util.render.BlendableTexturedButtonWidget; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.option.OptionsScreen; @@ -37,8 +36,5 @@ protected void init(CallbackInfo callbackInfo) { ScriptListScreen screen = new ScriptListScreen(DFScript.MC.player != null); DFScript.MC.setScreen(screen); })); - this.addDrawableChild(new BlendableTexturedButtonWidget(5, 30, 20, 20, identifier_test, identifier_test_highlight, (button) -> { - DFScript.MC.setScreen(new TestScreen()); - })); } } \ No newline at end of file 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 4d387f2..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); diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/TestScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/TestScreen.java deleted file mode 100644 index a2e0ba9..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/TestScreen.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import com.google.gson.JsonObject; -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.features.AuthHandler; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.*; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptManager; -import io.github.techstreet.dfscript.script.VirtualScript; -import io.github.techstreet.dfscript.script.util.UploadResponse; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import org.apache.commons.codec.binary.Base64; - -import java.awt.*; -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.zip.GZIPOutputStream; - -public class TestScreen extends CScreen { - public TestScreen() { - super(160, 160); - - CDragPanel panel = new CDragPanel(0,0,160,160); - widgets.add(panel); - - CTextField field = new CTextField("", 50, 50, 100, 20, false); - - panel.add(field); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java index 06f0e47..db69ce0 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java @@ -43,8 +43,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) MatrixStack stack = context.getMatrices(); stack.push(); stack.translate(x, y, 0); - stack.scale(0.5F,0.5F,1F); - context.drawItem(item, 0, 0); + RenderUtil.renderGuiItem(context, item); if(countText != null) { stack.translate(4, 4, 0); From 42e1d00062a300957e3001fc0b1b94072c28000b Mon Sep 17 00:00:00 2001 From: TechStreet Date: Thu, 4 Jan 2024 09:32:42 +0000 Subject: [PATCH 4/7] add: issue template --- .github/ISSUE_TEMPLATE/bug-report.md | 25 +++++++++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 5 +++++ 2 files changed, 30 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000..9b05e97 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,25 @@ +--- +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] + +**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!**] \ No newline at end of file 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 From 277c32f15c259dcfefcddef5951ea879ac7882a6 Mon Sep 17 00:00:00 2001 From: TechStreet Date: Thu, 4 Jan 2024 09:52:24 +0000 Subject: [PATCH 5/7] fix: workflow permissions --- .github/workflows/build.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 From 80a9a1dc1ac89e7cf8c7de49e8e17828b10bad9d Mon Sep 17 00:00:00 2001 From: TechStreet Date: Thu, 4 Jan 2024 13:26:37 +0000 Subject: [PATCH 6/7] Update bug-report.md --- .github/ISSUE_TEMPLATE/bug-report.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 9b05e97..b986ecb 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -18,8 +18,11 @@ Steps to reproduce the behaviour: 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!**] \ No newline at end of file +[Add any website links to effected scripts. **Remove this line!**] From f31f4656d37026023556e73ba7696baac6bc3c68 Mon Sep 17 00:00:00 2001 From: TechStreet Date: Thu, 4 Jan 2024 13:29:31 +0000 Subject: [PATCH 7/7] Create SECURITY.md --- SECURITY.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 SECURITY.md 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**.