From 20dd3f99a7b139b5848128246c622fd9cfefa478 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sat, 21 May 2022 21:18:14 +0900 Subject: - Project separation --- .../roomedit/valueedit/ValueEdit.java | 27 ++ .../roomedit/valueedit/ValueEditAColor.java | 339 +++++++++++++++++++++ .../roomedit/valueedit/ValueEditBoolean.java | 101 ++++++ .../roomedit/valueedit/ValueEditColor.java | 290 ++++++++++++++++++ .../roomedit/valueedit/ValueEditCreator.java | 29 ++ .../roomedit/valueedit/ValueEditFloat.java | 99 ++++++ .../roomedit/valueedit/ValueEditInteger.java | 99 ++++++ .../roomedit/valueedit/ValueEditNull.java | 38 +++ .../roomedit/valueedit/ValueEditOffsetPoint.java | 167 ++++++++++ .../valueedit/ValueEditOffsetPointSet.java | 250 +++++++++++++++ .../roomedit/valueedit/ValueEditRegistry.java | 71 +++++ .../roomedit/valueedit/ValueEditString.java | 99 ++++++ 12 files changed, 1609 insertions(+) create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEdit.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditAColor.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditBoolean.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditColor.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditCreator.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditFloat.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditInteger.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditNull.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditOffsetPoint.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditOffsetPointSet.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditRegistry.java create mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditString.java (limited to 'mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit') diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEdit.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEdit.java new file mode 100755 index 00000000..980ae947 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEdit.java @@ -0,0 +1,27 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.roomedit.Parameter; + +public interface ValueEdit { + void setParameter(Parameter parameter); + + void renderWorld(float partialTicks); +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditAColor.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditAColor.java new file mode 100755 index 00000000..ef310b3d --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditAColor.java @@ -0,0 +1,339 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.config.types.AColor; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.gui.elements.MColor; +import kr.syeyoung.dungeonsguide.gui.elements.MFloatSelectionButton; +import kr.syeyoung.dungeonsguide.gui.elements.MLabelAndElement; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.MathHelper; +import org.lwjgl.opengl.GL11; + +import java.awt.*; + +public class ValueEditAColor extends MPanel implements ValueEdit { + private Parameter parameter; + private final MFloatSelectionButton h; + private final MFloatSelectionButton s; + private final MFloatSelectionButton v; + private final MFloatSelectionButton a; + + + @Override + public void renderWorld(float partialTicks) { + + } + public ValueEditAColor(final Parameter parameter2) { + this.parameter = parameter2; + { + MColor color = new MColor() { + @Override + public Color getColor() { + return (Color) parameter2.getPreviousData(); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("Prev",color); + mLabelAndElement.setBounds(new Rectangle(0,0,getBounds().width,20)); + add(mLabelAndElement); + } + { + MColor color = new MColor() { + @Override + public Color getColor() { + return (Color) parameter2.getNewData(); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("New",color); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + + Color color = (Color) parameter2.getNewData(); + Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsv); + alpha = color.getAlpha() / 255.0f; + + { + h = new MFloatSelectionButton(hsv[0] * 360); + h.setOnUpdate(new Runnable() { + @Override + public void run() { + hsv[0] = h.getData() / 360; + update(); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("H", h); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + { + s = new MFloatSelectionButton(hsv[1] * 100); + s.setOnUpdate(new Runnable() { + @Override + public void run() { + hsv[1] = s.getData() / 100; + update(); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("S", s); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + { + v = new MFloatSelectionButton(hsv[2] * 100); + v.setOnUpdate(new Runnable() { + @Override + public void run() { + hsv[2] = v.getData() / 100; + update(); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("V", v); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + { + a = new MFloatSelectionButton(alpha * 100); + a.setOnUpdate(new Runnable() { + @Override + public void run() { + alpha = a.getData() / 100; + update(); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("A", a); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + } + + private final float[] hsv = new float[3]; + private float alpha = 0; + + public void update() { + if (hsv[2] > 1) hsv[2] = 1; + if (hsv[2] < 0) hsv[2] = 0; + if (hsv[1] > 1) hsv[1] = 1; + if (hsv[1] < 0) hsv[1] = 0; + parameter.setNewData(new AColor(Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0xffffff | (MathHelper.clamp_int((int)(alpha * 255), 0, 255) << 24), true )); + h.setData((float) Math.floor(hsv[0] * 360)); + s.setData((float) Math.floor(hsv[1] * 100)); + v.setData((float) Math.floor(hsv[2] * 100)); + a.setData((float) Math.floor(alpha * 100)); + h.updateSelected(); + s.updateSelected(); + v.updateSelected(); + a.updateSelected(); + } + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + // draw CoolRect + int width = getBounds().width - 60; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + int shademodel = GL11.glGetInteger(GL11.GL_SHADE_MODEL); + GlStateManager.shadeModel(GL11.GL_SMOOTH); + GlStateManager.enableBlend(); + GlStateManager.disableDepth(); + GlStateManager.disableTexture2D(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + +// worldrenderer.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR); + + int rgb = Color.HSBtoRGB(hsv[0], hsv[1], 1); + float r = (rgb >> 16 & 255) / 255.0f; + float g = (rgb >> 8 & 255) / 255.0f; + float b = (rgb & 255) / 255.0f; + GL11.glBegin(GL11.GL_TRIANGLES); + GlStateManager.color(0,0,0,alpha);GL11.glVertex3i(25+width ,45, 0); + GlStateManager.color(0,0,0,alpha);GL11.glVertex3i(10+width , 45, 0); + GlStateManager.color(r,g,b,alpha);GL11.glVertex3i(25+width , 45+width, 0); + + GlStateManager.color(0,0,0,alpha); GL11.glVertex3i(10+width , 45, 0); + GlStateManager.color(r,g,b,alpha);GL11.glVertex3i(10+width , 45 + width, 0); + GlStateManager.color(r,g,b,alpha);GL11.glVertex3i(25+width , 45+width, 0); + GL11.glEnd(); + rgb = Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]); + r = (rgb >> 16 & 255) / 255.0f; + g = (rgb >> 8 & 255) / 255.0f; + b = (rgb & 255) / 255.0f; + GL11.glBegin(GL11.GL_TRIANGLES); + GlStateManager.color(r,g,b,0);GL11.glVertex3i(50+width ,45, 0); + GlStateManager.color(r,g,b,0);GL11.glVertex3i(35+width , 45, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(50+width , 45+width, 0); + +// GlStateManager.color(r,g,b,0); GL11.glVertex3i(35+width , 45, 0); +// GlStateManager.color(r,g,b,1);GL11.glVertex3i(35+width , 45 + width, 0); +// GlStateManager.color(r,g,b,1);GL11.glVertex3i(50+width , 45+width, 0); + GL11.glEnd(); + + + float radius = width/2f; + float cx = 5 + radius; + float cy = 45 + radius; + + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + GlStateManager.color(1,1,1,alpha); + GL11.glVertex3f(cx,cy,0); + for (int i = 0; i <= 360; i++) { + float rad = 3.141592653f * i / 180; + int rgb2 = Color.HSBtoRGB(i / 360f, 1, hsv[2]); + float r2 = (rgb2 >> 16 & 255) / 255.0f; + float g2 = (rgb2 >> 8 & 255) / 255.0f; + float b2 = (rgb2 & 255) / 255.0f; + GlStateManager.color(r2,g2,b2, alpha); + GL11.glVertex3f(MathHelper.sin(rad) * radius + cx, MathHelper.cos(rad) * radius + cy, 0); + } + GL11.glEnd(); + GlStateManager.shadeModel(shademodel); + + GlStateManager.color(1,1,1,1); + worldrenderer.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION); + float rad2 = 2 * 3.141592653f * hsv[0] ; + float x = 5 + radius + (MathHelper.sin(rad2)) * hsv[1] * radius; + float y = 45 + radius + (MathHelper.cos(rad2))* hsv[1] * radius; + for (int i = 0; i < 100; i++) { + float rad = 2 * 3.141592653f * (i / 100f); + worldrenderer.pos(MathHelper.sin(rad) * 2 + x, MathHelper.cos(rad) * 2 + y, 0).endVertex(); + } + tessellator.draw(); + + worldrenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + worldrenderer.pos(8+width, 45 + (hsv[2]) * width, 0.5).endVertex(); + worldrenderer.pos(27+width, 45 + (hsv[2]) * width, 0.5).endVertex(); + tessellator.draw(); + + worldrenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + worldrenderer.pos(33+width, 45 + (alpha) * width, 0.5).endVertex(); + worldrenderer.pos(52+width, 45 + (alpha) * width, 0.5).endVertex(); + tessellator.draw(); + + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.color(1,1,1,1); + GlStateManager.color(1,1,1,1); + } + private int selected = 0; + + @Override + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + int width = getBounds().width - 60; + float radius = width / 2f; + float circleX = 5 + radius; + float circleY = 45 + radius; + selected = 0; + { + // check circle + float dx = relMouseX - circleX; + float dy = circleY - relMouseY; + if (dx * dx + dy * dy <= radius * radius) { + double theta = (MathHelper.atan2(dy, dx) / Math.PI * 180 + 90) % 360; + hsv[0] = (float) theta / 360f; + hsv[1] = MathHelper.sqrt_float(dx * dx + dy * dy) / radius; + selected = 1; + } + } + { + if (10+width <= relMouseX && relMouseX <= 25 + width && + 45 <= relMouseY && relMouseY <= 45 + width) { + hsv[2] = (relMouseY - 45) / (float)width; + selected = 2; + } + } + { + if (35+width <= relMouseX && relMouseX <= 50 + width && + 45 <= relMouseY && relMouseY <= 45 + width) { + alpha = (relMouseY - 45) / (float)width; + selected = 3; + } + } + update(); + } + + @Override + public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { + int width = getBounds().width - 60; + float radius = width / 2f; + float circleX = 5 + radius; + float circleY = 45 + radius; + { + // check circle + float dx = relMouseX - circleX; + float dy = circleY - relMouseY; + if (selected == 1) { + double theta = (MathHelper.atan2(dy, dx) / Math.PI * 180 + 90) % 360; + hsv[0] = (float) theta / 360f; + hsv[1] = MathHelper.clamp_float(MathHelper.sqrt_float(dx * dx + dy * dy) / radius, 0, 1); + } + } + { + if (selected == 2) { + hsv[2] = MathHelper.clamp_float((relMouseY - 45) / (float)width, 0, 1); + } + if (selected == 3) { + alpha = MathHelper.clamp_float((relMouseY - 45) / (float)width, 0, 1); + } + } + update(); + } + + @Override + public void onBoundsUpdate() { + int cnt = 0; + for (MPanel panel :getChildComponents()){ + panel.setSize(new Dimension(getBounds().width, 20)); cnt++; + if (cnt > 2) { + panel.setPosition(new Point(0, getBounds().width + (cnt - 3) * 20)); + } + } + } + + @Override + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + } + + public static class Generator implements ValueEditCreator { + + @Override + public ValueEditAColor createValueEdit(Parameter parameter) { + return new ValueEditAColor(parameter); + } + + @Override + public Object createDefaultValue(Parameter parameter) { + return new AColor(255,0,0,255); + } + + @Override + public Object cloneObj(Object object) { + return object; + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditBoolean.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditBoolean.java new file mode 100755 index 00000000..ab6a9ada --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditBoolean.java @@ -0,0 +1,101 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.gui.elements.MStringSelectionButton; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.gui.elements.MLabel; +import kr.syeyoung.dungeonsguide.gui.elements.MLabelAndElement; + +import java.awt.*; +import java.util.Arrays; + +public class ValueEditBoolean extends MPanel implements ValueEdit { + private Parameter parameter; + + + public ValueEditBoolean(Parameter parameter2) { + this.parameter = parameter2; + { + MLabel label = new MLabel() { + @Override + public String getText() { + return parameter.getPreviousData().toString(); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("Prev",label); + mLabelAndElement.setBounds(new Rectangle(0,0,getBounds().width,20)); + add(mLabelAndElement); + } + { + boolean newData = (Boolean) parameter.getNewData(); + final MStringSelectionButton textField = new MStringSelectionButton(Arrays.asList("true", "false"), Boolean.toString(newData)); + textField.setOnUpdate(new Runnable() { + @Override + public void run() { + parameter.setNewData(Boolean.valueOf(textField.getSelected())); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("New",textField); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + } + + @Override + public void onBoundsUpdate() { + for (MPanel panel :getChildComponents()){ + panel.setSize(new Dimension(getBounds().width, 20)); + } + } + + @Override + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + @Override + public void renderWorld(float partialTicks) { + + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + } + + public static class Generator implements ValueEditCreator { + + @Override + public ValueEditBoolean createValueEdit(Parameter parameter) { + return new ValueEditBoolean(parameter); + } + + @Override + public Object createDefaultValue(Parameter parameter) { + return true; + } + + @Override + public Object cloneObj(Object object) { + return object; + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditColor.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditColor.java new file mode 100755 index 00000000..8acec6f4 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditColor.java @@ -0,0 +1,290 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.gui.elements.MColor; +import kr.syeyoung.dungeonsguide.gui.elements.MFloatSelectionButton; +import kr.syeyoung.dungeonsguide.gui.elements.MLabelAndElement; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.gui.elements.*; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.MathHelper; +import org.lwjgl.opengl.GL11; + +import java.awt.*; + +public class ValueEditColor extends MPanel implements ValueEdit { + private Parameter parameter; + private final MFloatSelectionButton h; + private final MFloatSelectionButton s; + private final MFloatSelectionButton v; + + + @Override + public void renderWorld(float partialTicks) { + + } + public ValueEditColor(final Parameter parameter2) { + this.parameter = parameter2; + { + MColor color = new MColor() { + @Override + public Color getColor() { + return (Color) parameter2.getPreviousData(); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("Prev",color); + mLabelAndElement.setBounds(new Rectangle(0,0,getBounds().width,20)); + add(mLabelAndElement); + } + { + MColor color = new MColor() { + @Override + public Color getColor() { + return (Color) parameter2.getNewData(); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("New",color); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + + Color color = (Color) parameter2.getNewData(); + Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsv); + + { + h = new MFloatSelectionButton(hsv[0] * 360); + h.setOnUpdate(new Runnable() { + @Override + public void run() { + hsv[0] = h.getData() / 360; + update(); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("H", h); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + { + s = new MFloatSelectionButton(hsv[1] * 100); + s.setOnUpdate(new Runnable() { + @Override + public void run() { + hsv[1] = s.getData() / 100; + update(); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("S", s); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + { + v = new MFloatSelectionButton(hsv[2] * 100); + v.setOnUpdate(new Runnable() { + @Override + public void run() { + hsv[2] = v.getData() / 100; + update(); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("V", v); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + } + + private final float[] hsv = new float[3]; + + public void update() { + if (hsv[2] > 1) hsv[2] = 1; + if (hsv[2] < 0) hsv[2] = 0; + if (hsv[1] > 1) hsv[1] = 1; + if (hsv[1] < 0) hsv[1] = 0; + parameter.setNewData(new Color(Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]))); + h.setData((float) Math.floor(hsv[0] * 360)); + s.setData((float) Math.floor(hsv[1] * 100)); + v.setData((float) Math.floor(hsv[2] * 100)); + h.updateSelected(); + s.updateSelected(); + v.updateSelected(); + } + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + // draw CoolRect + int width = getBounds().width - 30; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + int shademodel = GL11.glGetInteger(GL11.GL_SHADE_MODEL); + GlStateManager.shadeModel(GL11.GL_SMOOTH); + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); +// worldrenderer.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR); + + int rgb = Color.HSBtoRGB(hsv[0], hsv[1], 1); + float r = (rgb >> 16 & 255) / 255.0f; + float g = (rgb >> 8 & 255) / 255.0f; + float b = (rgb & 255) / 255.0f; + GL11.glBegin(GL11.GL_TRIANGLES); + GlStateManager.color(0,0,0,1);GL11.glVertex3i(25+width ,45, 0); + GlStateManager.color(0,0,0,1);GL11.glVertex3i(10+width , 45, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(25+width , 45+width, 0); + + GlStateManager.color(0,0,0,1); GL11.glVertex3i(10+width , 45, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(10+width , 45 + width, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(25+width , 45+width, 0); + GL11.glEnd(); + + float radius = width/2f; + float cx = 5 + radius; + float cy = 45 + radius; + + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + GlStateManager.color(1,1,1,1); + GL11.glVertex3f(cx,cy,0); + for (int i = 0; i <= 360; i++) { + float rad = 3.141592653f * i / 180; + int rgb2 = Color.HSBtoRGB(i / 360f, 1, hsv[2]); + float r2 = (rgb2 >> 16 & 255) / 255.0f; + float g2 = (rgb2 >> 8 & 255) / 255.0f; + float b2 = (rgb2 & 255) / 255.0f; + GlStateManager.color(r2,g2,b2, 1); + GL11.glVertex3f(MathHelper.sin(rad) * radius + cx, MathHelper.cos(rad) * radius + cy, 0); + } + GL11.glEnd(); + GlStateManager.shadeModel(shademodel); + + GlStateManager.color(1,1,1,1); + worldrenderer.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION); + float rad2 = 2 * 3.141592653f * hsv[0] ; + float x = 5 + radius + (MathHelper.sin(rad2)) * hsv[1] * radius; + float y = 45 + radius + (MathHelper.cos(rad2))* hsv[1] * radius; + for (int i = 0; i < 100; i++) { + float rad = 2 * 3.141592653f * (i / 100f); + worldrenderer.pos(MathHelper.sin(rad) * 2 + x, MathHelper.cos(rad) * 2 + y, 0).endVertex(); + } + tessellator.draw(); + + worldrenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + worldrenderer.pos(8+width, 45 + (hsv[2]) * width, 0.5).endVertex(); + worldrenderer.pos(27+width, 45 + (hsv[2]) * width, 0.5).endVertex(); + tessellator.draw(); + + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.color(1,1,1,1); + GlStateManager.color(1,1,1,1); + } + private int selected = 0; + + @Override + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + int width = getBounds().width - 30; + float radius = width / 2f; + float circleX = 5 + radius; + float circleY = 45 + radius; + selected = 0; + { + // check circle + float dx = relMouseX - circleX; + float dy = circleY - relMouseY; + if (dx * dx + dy * dy <= radius * radius) { + double theta = (MathHelper.atan2(dy, dx) / Math.PI * 180 + 90) % 360; + hsv[0] = (float) theta / 360f; + hsv[1] = MathHelper.sqrt_float(dx * dx + dy * dy) / radius; + selected = 1; + } + } + { + if (10+width <= relMouseX && relMouseX <= 25 + width && + 45 <= relMouseY && relMouseY <= 45 + width) { + hsv[2] = (relMouseY - 45) / (float)width; + selected = 2; + } + } + update(); + } + + @Override + public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { + int width = getBounds().width - 30; + float radius = width / 2f; + float circleX = 5 + radius; + float circleY = 45 + radius; + { + // check circle + float dx = relMouseX - circleX; + float dy = circleY - relMouseY; + if (selected == 1) { + double theta = (MathHelper.atan2(dy, dx) / Math.PI * 180 + 90) % 360; + hsv[0] = (float) theta / 360f; + hsv[1] = MathHelper.clamp_float(MathHelper.sqrt_float(dx * dx + dy * dy) / radius, 0, 1); + } + } + { + if (selected == 2) { + hsv[2] = MathHelper.clamp_float((relMouseY - 45) / (float)width, 0, 1); + } + } + update(); + } + + @Override + public void onBoundsUpdate() { + int cnt = 0; + for (MPanel panel :getChildComponents()){ + panel.setSize(new Dimension(getBounds().width, 20)); cnt++; + if (cnt > 2) { + panel.setPosition(new Point(0, getBounds().width + (cnt - 2) * 20)); + } + } + } + + @Override + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + } + + public static class Generator implements ValueEditCreator { + + @Override + public ValueEditColor createValueEdit(Parameter parameter) { + return new ValueEditColor(parameter); + } + + @Override + public Object createDefaultValue(Parameter parameter) { + return Color.red; + } + + @Override + public Object cloneObj(Object object) { + return object; + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditCreator.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditCreator.java new file mode 100755 index 00000000..41579f0c --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditCreator.java @@ -0,0 +1,29 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.roomedit.Parameter; + +public interface ValueEditCreator { + T createValueEdit(Parameter parameter); + + Object createDefaultValue(Parameter parameter); + + Object cloneObj(Object object); +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditFloat.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditFloat.java new file mode 100755 index 00000000..66fa4c54 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditFloat.java @@ -0,0 +1,99 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.gui.elements.MFloatSelectionButton; +import kr.syeyoung.dungeonsguide.gui.elements.MLabel; +import kr.syeyoung.dungeonsguide.gui.elements.MLabelAndElement; + +import java.awt.*; + +public class ValueEditFloat extends MPanel implements ValueEdit { + private Parameter parameter; + + + @Override + public void renderWorld(float partialTicks) { + + } + public ValueEditFloat(final Parameter parameter2) { + this.parameter = parameter2; + { + MLabel label = new MLabel() { + @Override + public String getText() { + return parameter.getPreviousData().toString(); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("Prev",label); + mLabelAndElement.setBounds(new Rectangle(0,0,getBounds().width,20)); + add(mLabelAndElement); + } + { + float newData = (Float) parameter.getNewData(); + final MFloatSelectionButton textField = new MFloatSelectionButton(newData); + textField.setOnUpdate(new Runnable() { + @Override + public void run() { + parameter.setNewData(textField.getData()); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("New",textField); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + } + + @Override + public void onBoundsUpdate() { + for (MPanel panel :getChildComponents()){ + panel.setSize(new Dimension(getBounds().width, 20)); + } + } + + @Override + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + } + + public static class Generator implements ValueEditCreator { + + @Override + public ValueEditFloat createValueEdit(Parameter parameter) { + return new ValueEditFloat(parameter); + } + + @Override + public Object createDefaultValue(Parameter parameter) { + return 0.0f; + } + + @Override + public Object cloneObj(Object object) { + return object; + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditInteger.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditInteger.java new file mode 100755 index 00000000..37430077 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditInteger.java @@ -0,0 +1,99 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.gui.elements.MIntegerSelectionButton; +import kr.syeyoung.dungeonsguide.gui.elements.MLabel; +import kr.syeyoung.dungeonsguide.gui.elements.MLabelAndElement; + +import java.awt.*; + +public class ValueEditInteger extends MPanel implements ValueEdit { + private Parameter parameter; + + + @Override + public void renderWorld(float partialTicks) { + + } + public ValueEditInteger(final Parameter parameter2) { + this.parameter = parameter2; + { + MLabel label = new MLabel() { + @Override + public String getText() { + return parameter.getPreviousData().toString(); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("Prev",label); + mLabelAndElement.setBounds(new Rectangle(0,0,getBounds().width,20)); + add(mLabelAndElement); + } + { + int newData = (Integer) parameter.getNewData(); + final MIntegerSelectionButton textField = new MIntegerSelectionButton(newData); + textField.setOnUpdate(new Runnable() { + @Override + public void run() { + parameter.setNewData(textField.getData()); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("New",textField); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + } + + @Override + public void onBoundsUpdate() { + for (MPanel panel :getChildComponents()){ + panel.setSize(new Dimension(getBounds().width, 20)); + } + } + + @Override + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + } + + public static class Generator implements ValueEditCreator { + + @Override + public ValueEditInteger createValueEdit(Parameter parameter) { + return new ValueEditInteger(parameter); + } + + @Override + public Object createDefaultValue(Parameter parameter) { + return 0; + } + + @Override + public Object cloneObj(Object object) { + return object; + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditNull.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditNull.java new file mode 100755 index 00000000..475a942a --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditNull.java @@ -0,0 +1,38 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.roomedit.Parameter; + +public class ValueEditNull implements ValueEditCreator { + @Override + public ValueEdit createValueEdit(Parameter parameter) { + return null; + } + + @Override + public Cloneable createDefaultValue(Parameter parameter) { + return null; + } + + @Override + public Object cloneObj(Object object) { + return null; + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditOffsetPoint.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditOffsetPoint.java new file mode 100755 index 00000000..978ead50 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditOffsetPoint.java @@ -0,0 +1,167 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPoint; +import kr.syeyoung.dungeonsguide.gui.elements.MButton; +import kr.syeyoung.dungeonsguide.gui.elements.MIntegerSelectionButton; +import kr.syeyoung.dungeonsguide.gui.elements.MLabel; +import kr.syeyoung.dungeonsguide.gui.elements.MLabelAndElement; +import kr.syeyoung.dungeonsguide.roomedit.EditingContext; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.gui.elements.*; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.BlockPos; +import java.awt.*; + +public class ValueEditOffsetPoint extends MPanel implements ValueEdit { + private Parameter parameter; + + @Override + public void renderWorld(float partialTicks) { + RenderUtils.highlightBlock(((OffsetPoint)parameter.getPreviousData()).getBlockPos(EditingContext.getEditingContext().getRoom()), new Color(255,0,0,150), partialTicks); + RenderUtils.highlightBlock(((OffsetPoint)parameter.getNewData()).getBlockPos(EditingContext.getEditingContext().getRoom()), new Color(0,255,0,150), partialTicks); + } + + public ValueEditOffsetPoint(final Parameter parameter2) { + this.parameter = parameter2; + { + MLabel label = new MLabel() { + @Override + public String getText() { + return parameter.getPreviousData().toString(); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("Prev",label); + mLabelAndElement.setBounds(new Rectangle(0,0,getBounds().width,20)); + add(mLabelAndElement); + } + OffsetPoint newData = (OffsetPoint) parameter.getNewData(); + { + final MIntegerSelectionButton textField = new MIntegerSelectionButton(newData.getX()); + textField.setOnUpdate(new Runnable() { + @Override + public void run() { + ((OffsetPoint) parameter.getNewData()).setX(textField.getData()); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("x",textField); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + { + final MIntegerSelectionButton textField = new MIntegerSelectionButton(newData.getY()); + textField.setOnUpdate(new Runnable() { + @Override + public void run() { + ((OffsetPoint) parameter.getNewData()).setY(textField.getData()); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("y",textField); + mLabelAndElement.setBounds(new Rectangle(0,40,getBounds().width,20)); + add(mLabelAndElement); + } + { + final MIntegerSelectionButton textField = new MIntegerSelectionButton(newData.getZ()); + textField.setOnUpdate(new Runnable() { + @Override + public void run() { + ((OffsetPoint) parameter.getNewData()).setZ(textField.getData()); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("z",textField); + mLabelAndElement.setBounds(new Rectangle(0,60,getBounds().width,20)); + add(mLabelAndElement); + } + { + final MLabel setToHEre = new MLabel() { + @Override + public String getText() { + OffsetPoint offsetPoint = (OffsetPoint) parameter.getNewData(); + return Block.getIdFromBlock(offsetPoint.getBlock(EditingContext.getEditingContext().getRoom())) + + ":" + offsetPoint.getData(EditingContext.getEditingContext().getRoom()); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("newPt",setToHEre); + mLabelAndElement.setBounds(new Rectangle(0,80,getBounds().width,20)); + add(mLabelAndElement); + } + { + final MButton setToHEre2 = new MButton(); + setToHEre2.setText("Set to here"); + setToHEre2.setBackgroundColor(Color.green); + setToHEre2.setOnActionPerformed(new Runnable() { + @Override + public void run() { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ); + ((OffsetPoint)parameter2.getNewData()).setPosInWorld(EditingContext.getEditingContext().getRoom(),pos ); + } + }); + MLabelAndElement mLabelAndElement = new MLabelAndElement("set",setToHEre2); + mLabelAndElement.setBounds(new Rectangle(0,100,getBounds().width,20)); + add(mLabelAndElement); + } + } + + @Override + public void onBoundsUpdate() { + for (MPanel panel :getChildComponents()){ + panel.setSize(new Dimension(getBounds().width, 20)); + } + } + + @Override + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + } + + public static class Generator implements ValueEditCreator { + + @Override + public ValueEditOffsetPoint createValueEdit(Parameter parameter) { + return new ValueEditOffsetPoint(parameter); + } + + @Override + public Object createDefaultValue(Parameter parameter) { + return new OffsetPoint(EditingContext.getEditingContext().getRoom(), Minecraft.getMinecraft().thePlayer.getPosition()); + } + + @Override + public Object cloneObj(Object object) { + try { + return ((OffsetPoint)object).clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assert false; + return null; + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditOffsetPointSet.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditOffsetPointSet.java new file mode 100755 index 00000000..cdc32448 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditOffsetPointSet.java @@ -0,0 +1,250 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPoint; +import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPointSet; +import kr.syeyoung.dungeonsguide.roomedit.EditingContext; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.gui.elements.MButton; +import kr.syeyoung.dungeonsguide.gui.elements.MValue; +import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonAddSet; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; +import lombok.Getter; +import net.minecraft.client.Minecraft; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class ValueEditOffsetPointSet extends MPanel implements ValueEdit { + private Parameter parameter; + + // scroll pane + // just create + // add set + + private final MPanel scroll; + @Getter + private final List MParameters = new ArrayList(); + + private final MButton add; + private final MButton addSet; + + public void delete(OffsetPoint offsetPoint) { + ((OffsetPointSet)parameter.getNewData()).getOffsetPointList().remove(offsetPoint); + Iterator iterator = MParameters.iterator(); + while (iterator.hasNext()) { + MValue panel = (MValue) iterator.next(); + if (panel.getData() == offsetPoint) { + iterator.remove(); + break; + } + } + + } + + public ValueEditOffsetPointSet(final Parameter parameter2) { + this.parameter = parameter2; + { + scroll = new MPanel() { + private int offsetY = 0; + + @Override + public List getChildComponents() { + return MParameters; + } + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + int heights = 0; + for (MPanel panel:getChildComponents()) { + panel.setPosition(new Point(0, -offsetY + heights)); + heights += panel.getBounds().height; + } + } + + @Override + public boolean mouseClicked0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int mouseButton) { + if (!getBounds().contains(relMouseX0, relMouseY0)) { + return false; + } + + int relMousex = relMouseX0 - getBounds().x; + int relMousey = relMouseY0 - getBounds().y; + + boolean noClip = true; + boolean focusedOverall = false; + for (MPanel childComponent : getChildComponents()) { + if (childComponent.mouseClicked0(absMouseX, absMouseY, relMousex, relMousey, mouseButton)) { + noClip = false; + focusedOverall = true; + } + } + + if (getBounds().contains(relMouseX0, relMouseY0) && noClip) { + isFocused = true; + focusedOverall = true; + } else { + isFocused = false; + } + + mouseClicked(absMouseX, absMouseY, relMousex, relMousey, mouseButton); + return focusedOverall; + } + + @Override + public void onBoundsUpdate() { + for (MPanel panel :getChildComponents()){ + panel.setSize(new Dimension(getBounds().width, 20)); + } + } + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(5,5,parentWidth-10,parentHeight-10)); + } + + @Override + public void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) { + if (new Rectangle(new Point(0,0), getSize()).contains(relMouseX0, relMouseY0)) { + if (scrollAmount >0) offsetY += 20; + else if (scrollAmount < 0) offsetY -= 20; + if (offsetY <0) offsetY = 0; + } + } + }; + scroll.setBounds(new Rectangle(0,0,getBounds().width, getBounds().height-20)); + add(scroll); + } + + { + add = new MButton() { + @Override + public void resize(int parentWidth, int parentHeight) { + setBounds(new Rectangle(0,parentHeight - 20, parentWidth / 2, 20)); + } + }; + add.setText("Add"); + add.setBackgroundColor(Color.green); + add.setOnActionPerformed(new Runnable() { + @Override + public void run() { + OffsetPoint offsetPoint = new OffsetPoint(EditingContext.getEditingContext().getRoom(), Minecraft.getMinecraft().thePlayer.getPosition()); + MValue mValue; + MParameters.add(mValue = new MValue(offsetPoint, buildAddonsFor(offsetPoint))); + ((OffsetPointSet)parameter.getNewData()).getOffsetPointList().add(offsetPoint); + mValue.setSize(new Dimension(getBounds().width, 20)); + } + }); + + addSet = new MButton(){ + @Override + public void resize(int parentWidth, int parentHeight) { + setBounds(new Rectangle(parentWidth / 2,parentHeight - 20, parentWidth / 2, 20)); + } + }; + addSet.setText("Add Set"); + addSet.setBackgroundColor(Color.cyan); + addSet.setOnActionPerformed(new Runnable() { + @Override + public void run() { + EditingContext.getEditingContext().openGui(new GuiDungeonAddSet(ValueEditOffsetPointSet.this)); + } + }); + add(add); + add(addSet); + } + for (OffsetPoint offsetPoint : ((OffsetPointSet)parameter.getNewData()).getOffsetPointList()) { + MParameters.add(new MValue(offsetPoint, buildAddonsFor(offsetPoint))); + } + } + + public List buildAddonsFor(final OffsetPoint offsetPoint) { + ArrayList panels = new ArrayList(); + MButton mButton = new MButton(); + mButton.setText("Delete"); + mButton.setForeground(Color.white); + mButton.setBackgroundColor(Color.red); + mButton.setOnActionPerformed(new Runnable() { + @Override + public void run() { + delete(offsetPoint); + } + }); + panels.add(mButton); + return panels; + } + + @Override + public void onBoundsUpdate() { + scroll.setBounds(new Rectangle(0,0,getBounds().width, getBounds().height-20)); + add.setBounds(new Rectangle(0,getBounds().height-20,getBounds().width / 2, 20)); + addSet.setBounds(new Rectangle(getBounds().width / 2,getBounds().height-20,getBounds().width / 2, 20)); + } + + @Override + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + @Override + public void renderWorld(float partialTicks) { + for (OffsetPoint offsetPoint :((OffsetPointSet)parameter.getNewData()).getOffsetPointList()) { + RenderUtils.highlightBlock(offsetPoint.getBlockPos(EditingContext.getEditingContext().getRoom()), new Color(0,255,255,50), partialTicks); + } + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + } + + public void addAll(List blockPoses) { + ((OffsetPointSet)parameter.getNewData()).getOffsetPointList().addAll(blockPoses); + for (OffsetPoint blockPose : blockPoses) { + MParameters.add(new MValue(blockPose, buildAddonsFor(blockPose))); + } + } + + public static class Generator implements ValueEditCreator { + + @Override + public ValueEditOffsetPointSet createValueEdit(Parameter parameter) { + return new ValueEditOffsetPointSet(parameter); + } + + @Override + public Object createDefaultValue(Parameter parameter) { + return new OffsetPointSet(); + } + + @Override + public Object cloneObj(Object object) { + try { + return ((OffsetPointSet)object).clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assert false; + return null; + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditRegistry.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditRegistry.java new file mode 100755 index 00000000..611dc533 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditRegistry.java @@ -0,0 +1,71 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPoint; +import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPointSet; +import kr.syeyoung.dungeonsguide.dungeon.mechanics.*; +import kr.syeyoung.dungeonsguide.config.types.AColor; +import kr.syeyoung.dungeonsguide.roomedit.mechanicedit.*; +import kr.syeyoung.dungeonsguide.roomedit.mechanicedit.*; + +import java.awt.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ValueEditRegistry { + private static final Map valueEditMap = new HashMap(); + + public static ValueEditCreator getValueEditMap(String className) { + return valueEditMap.get(className); + } + + public static List getClassesSupported() { + return new ArrayList(valueEditMap.keySet()); + } + + static { + valueEditMap.put("null", new ValueEditNull()); + valueEditMap.put(String.class.getName(), new ValueEditString.Generator()); + valueEditMap.put(Boolean.class.getName(), new ValueEditBoolean.Generator()); + valueEditMap.put(Integer.class.getName(), new ValueEditInteger.Generator()); + valueEditMap.put(Float.class.getName(), new ValueEditFloat.Generator()); + valueEditMap.put(OffsetPoint.class.getName(), new ValueEditOffsetPoint.Generator()); + valueEditMap.put(OffsetPointSet.class.getName(), new ValueEditOffsetPointSet.Generator()); + valueEditMap.put(Color.class.getName(), new ValueEditColor.Generator()); + valueEditMap.put(AColor.class.getName(), new ValueEditAColor.Generator()); + + + valueEditMap.put(DungeonSecret.class.getName(), new ValueEditSecret.Generator()); + valueEditMap.put(DungeonFairySoul.class.getName(), new ValueEditFairySoul.Generator()); + valueEditMap.put(DungeonNPC.class.getName(), new ValueEditNPC.Generator()); + valueEditMap.put(DungeonTomb.class.getName(), new ValueEditTomb.Generator()); + valueEditMap.put(DungeonBreakableWall.class.getName(), new ValueEditBreakableWall.Generator()); + valueEditMap.put(DungeonJournal.class.getName(), new ValueEditJournal.Generator()); + valueEditMap.put(DungeonDummy.class.getName(), new ValueEditDummy.Generator()); + + valueEditMap.put(DungeonPressurePlate.class.getName(), new ValueEditPressurePlate.Generator()); + valueEditMap.put(DungeonOnewayLever.class.getName(), new ValueEditOnewayLever.Generator()); + valueEditMap.put(DungeonLever.class.getName(), new ValueEditLever.Generator()); + valueEditMap.put(DungeonDoor.class.getName(), new ValueEditDoor.Generator()); + valueEditMap.put(DungeonOnewayDoor.class.getName(), new ValueEditOnewayDoor.Generator()); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditString.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditString.java new file mode 100755 index 00000000..2eeca0fb --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/roomedit/valueedit/ValueEditString.java @@ -0,0 +1,99 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.roomedit.valueedit; + +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.gui.elements.MLabel; +import kr.syeyoung.dungeonsguide.gui.elements.MLabelAndElement; +import kr.syeyoung.dungeonsguide.gui.elements.MTextField; + +import java.awt.*; + +public class ValueEditString extends MPanel implements ValueEdit { + private Parameter parameter; + + @Override + public void renderWorld(float partialTicks) { + + } + + public ValueEditString(Parameter parameter2) { + this.parameter = parameter2; + { + MLabel label = new MLabel() { + @Override + public String getText() { + return parameter.getPreviousData().toString(); + } + }; + MLabelAndElement mLabelAndElement = new MLabelAndElement("Prev",label); + mLabelAndElement.setBounds(new Rectangle(0,0,getBounds().width,20)); + add(mLabelAndElement); + } + { + String newData = (String) parameter.getNewData(); + MTextField textField = new MTextField() { + @Override + public void edit(String str) { + parameter.setNewData(str); + } + }; + textField.setText(newData); + MLabelAndElement mLabelAndElement = new MLabelAndElement("New",textField); + mLabelAndElement.setBounds(new Rectangle(0,20,getBounds().width,20)); + add(mLabelAndElement); + } + } + + @Override + public void onBoundsUpdate() { + for (MPanel panel :getChildComponents()){ + panel.setSize(new Dimension(getBounds().width, 20)); + } + } + + @Override + public void setParameter(Parameter parameter) { + this.parameter = parameter; + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + } + + public static class Generator implements ValueEditCreator { + + @Override + public ValueEditString createValueEdit(Parameter parameter) { + return new ValueEditString(parameter); + } + + @Override + public Object createDefaultValue(Parameter parameter) { + return "default"; + } + + @Override + public Object cloneObj(Object object) { + return object; + } + } +} -- cgit