diff options
author | syeyoung <cyoung06@naver.com> | 2023-01-26 03:05:00 +0900 |
---|---|---|
committer | syeyoung <cyoung06@naver.com> | 2023-01-26 03:05:00 +0900 |
commit | 500611d7684d7cf136f96f0049fee65529be3080 (patch) | |
tree | fbe642554cad4d1f927ac5bcad3a05901dcc2861 /mod/src/main/java/kr | |
parent | 8f2366c1fd9850c0689306419343265099cfca7a (diff) | |
download | Skyblock-Dungeons-Guide-500611d7684d7cf136f96f0049fee65529be3080.tar.gz Skyblock-Dungeons-Guide-500611d7684d7cf136f96f0049fee65529be3080.tar.bz2 Skyblock-Dungeons-Guide-500611d7684d7cf136f96f0049fee65529be3080.zip |
Rounded Rectangles!
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main/java/kr')
4 files changed, 96 insertions, 1 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java index a12bb9af..3bc517b7 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java @@ -43,6 +43,7 @@ import kr.syeyoung.dungeonsguide.mod.parallelUniverse.tab.TabList; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.tab.TabListEntry; import kr.syeyoung.dungeonsguide.mod.party.PartyContext; import kr.syeyoung.dungeonsguide.mod.party.PartyManager; +import kr.syeyoung.dungeonsguide.mod.shader.ShaderManager; import kr.syeyoung.dungeonsguide.mod.utils.AhUtils; import kr.syeyoung.dungeonsguide.mod.utils.MapUtils; import kr.syeyoung.dungeonsguide.mod.wsresource.StaticResourceCache; @@ -212,6 +213,9 @@ public class CommandDgDebug extends CommandBase { t.printStackTrace(); } break; + case "reloadshader": + ShaderManager.onResourceReload(); + break; default: ChatTransmitter.addToQueue(new ChatComponentText("ain't gonna find much anything here")); ChatTransmitter.addToQueue(new ChatComponentText("§eDungeons Guide §7:: §e/dg loadrooms §7-§f Reloads dungeon roomdata.")); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/RoundRect.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/RoundRect.java new file mode 100644 index 00000000..66b4ebc7 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/RoundRect.java @@ -0,0 +1,81 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * 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 <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.guiv2.elements; + +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.DomElement; +import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; +import kr.syeyoung.dungeonsguide.mod.guiv2.layouter.Layouter; +import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.ConstraintBox; +import kr.syeyoung.dungeonsguide.mod.guiv2.primitive.Size; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.Renderer; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.RenderingContext; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.SingleChildRenderer; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedExportOnlyWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.ExportedWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Export; +import kr.syeyoung.dungeonsguide.mod.shader.ShaderManager; +import kr.syeyoung.dungeonsguide.mod.shader.ShaderProgram; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL20; + +import java.util.Collections; +import java.util.List; + +public class RoundRect extends AnnotatedExportOnlyWidget { + @Export(attributeName = "radius") + public final BindableAttribute<Double> radius = new BindableAttribute<>(Double.class, 0.0); + + @Export(attributeName = "backgroundColor") + public final BindableAttribute<Integer> color = new BindableAttribute<>(Integer.class, 0xFFFFFFFF); + + @Export(attributeName = "_") + public final BindableAttribute<Widget> child = new BindableAttribute<>(Widget.class); + + @Override + protected Renderer createRenderer() { + return new BRender(); + } + + @Override + public List<Widget> build(DomElement buildContext) { + return child.getValue() == null ? Collections.EMPTY_LIST : Collections.singletonList(child.getValue()); + } + + public class BRender extends SingleChildRenderer { + @Override + public void doRender(int absMouseX, int absMouseY, double relMouseX, double relMouseY, float partialTicks, RenderingContext renderingContext, DomElement buildContext) { + ShaderProgram shaderProgram = ShaderManager.getShader("shaders/roundrect"); + shaderProgram.useShader(); + shaderProgram.uploadUniform("radius", radius.getValue().floatValue()); + shaderProgram.uploadUniform("halfSize", (float) buildContext.getAbsBounds().getWidth()/2, (float) buildContext.getAbsBounds().getHeight()/2); + shaderProgram.uploadUniform("centerPos", + (float) (buildContext.getAbsBounds().getX()+buildContext.getAbsBounds().getWidth()/2), + Minecraft.getMinecraft().displayHeight - (float) (buildContext.getAbsBounds().getY() + buildContext.getAbsBounds().getHeight()/2)); + shaderProgram.uploadUniform("smoothness", 0.0f); + + GlStateManager.color(0.0f, 1.0f, 1.0f, 1.0f); + renderingContext.drawRect(0,0,buildContext.getSize().getWidth(), buildContext.getSize().getHeight(), color.getValue()); + GL20.glUseProgram(0); + super.doRender(absMouseX, absMouseY, relMouseX, relMouseY, partialTicks, renderingContext, buildContext); + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java index 5cc22476..b34ea8cb 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java @@ -76,6 +76,7 @@ public class DomElementRegistry { register("IntrinsicWidth", new ExportedWidgetConverter(IntrinsicWidth::new)); register("IntrinsicHeight", new ExportedWidgetConverter(IntrinsicHeight::new)); register("TestView", new ExportedWidgetConverter(TestView::new)); + register("RoundRect", new ExportedWidgetConverter(RoundRect::new)); register("ColorButton", new DelegatingWidgetConverter(new ResourceLocation("dungeonsguide:gui/elements/simpleButton.gui"))); register("SimpleHorizontalScrollBar", new DelegatingWidgetConverter(new ResourceLocation("dungeonsguide:gui/elements/simpleHorizontalScrollBar.gui"))); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/shader/ShaderManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/shader/ShaderManager.java index dbb3178c..e1fcae13 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/shader/ShaderManager.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/shader/ShaderManager.java @@ -65,22 +65,30 @@ public class ShaderManager { } if (sourceVert != null) { vertex = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); + System.out.println(sourceVert); GL20.glShaderSource(vertex, sourceVert); GL20.glCompileShader(vertex); if (GL20.glGetShaderi(vertex, 35713) == 0) { System.err.println(GL20.glGetShaderInfoLog(vertex, 100)); + GL20.glDeleteShader(vertex); + return null; } } int fragment = -1; if (sourceFrag != null) { fragment = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); + System.out.println(sourceFrag); GL20.glShaderSource(fragment, sourceFrag); GL20.glCompileShader(fragment); if (GL20.glGetShaderi(fragment, 35713) == 0) { System.err.println(GL20.glGetShaderInfoLog(fragment, 100)); + if (vertex != -1) + GL20.glDeleteShader(vertex); + GL20.glDeleteShader(fragment); + return null; } } @@ -96,10 +104,12 @@ public class ShaderManager { if (GL20.glGetProgrami(program, 35714) == 0) { System.err.println(GL20.glGetProgramInfoLog(program, 100)); + return null; } GL20.glValidateProgram(program); if (GL20.glGetProgrami(program, 35715) == 0) { System.err.println(GL20.glGetProgramInfoLog(program, 100)); + return null; } ShaderProgram shaderProgram = new ShaderProgram(name, program); shaders.put(name, shaderProgram); @@ -113,7 +123,6 @@ public class ShaderManager { try (InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream()) { return IOUtils.toString(is); } catch (Exception e) { - e.printStackTrace(); } return null; } |