diff options
Diffstat (limited to 'mod/src/main')
7 files changed, 115 insertions, 4 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; } diff --git a/mod/src/main/resources/assets/dungeonsguide/gui/testpopup.gui b/mod/src/main/resources/assets/dungeonsguide/gui/testpopup.gui index 867c913f..51fdb7fa 100644 --- a/mod/src/main/resources/assets/dungeonsguide/gui/testpopup.gui +++ b/mod/src/main/resources/assets/dungeonsguide/gui/testpopup.gui @@ -18,7 +18,7 @@ <bgcolor backgroundColor="#33000000"> <align> <size width="200" height="200"> - <bgcolor backgroundColor="#FFFFFFFF"> + <RoundRect radius="10" backgroundColor="#FFFFFFFF"> <align> <size width="50" height="30"> <ColorButton on:click="close" disabled="false" @@ -30,7 +30,7 @@ /> </size> </align> - </bgcolor> + </RoundRect> </size> </align> </bgcolor>
\ No newline at end of file diff --git a/mod/src/main/resources/assets/dungeonsguide/gui/testview.gui b/mod/src/main/resources/assets/dungeonsguide/gui/testview.gui index e361909d..82f79c29 100644 --- a/mod/src/main/resources/assets/dungeonsguide/gui/testview.gui +++ b/mod/src/main/resources/assets/dungeonsguide/gui/testview.gui @@ -25,7 +25,7 @@ <flexible fit="TIGHT"> <col mainAlign="CENTER"> <flexible fit="TIGHT"> - <bgcolor backgroundColor="#FF0000FF"/> + <RoundRect radius="20"/> </flexible> <flexible fit="TIGHT"> <padding left="20.0" right="20.0" top="10.0" bottom="10.0"> diff --git a/mod/src/main/resources/assets/dungeonsguide/shaders/roundrect.frag b/mod/src/main/resources/assets/dungeonsguide/shaders/roundrect.frag new file mode 100644 index 00000000..9a41104a --- /dev/null +++ b/mod/src/main/resources/assets/dungeonsguide/shaders/roundrect.frag @@ -0,0 +1,16 @@ +#version 110 +uniform float radius; +uniform vec2 halfSize; +uniform vec2 centerPos; +uniform float smoothness; + +float roundedBoxSDF(vec2 CenterPosition, vec2 Size, float Radius) { + return length(max(abs(CenterPosition)-Size+Radius,0.0))-Radius; +} + +void main() { + float distance = roundedBoxSDF(gl_FragCoord.xy - centerPos, halfSize, radius); + float smoothedAlpha = smoothstep(-smoothness,0.0, -distance); +// gl_FragColor = mix(vec4(1.0, 1.0, 1.0, 1.0), vec4(0.0, 0.2, 1.0, smoothedAlpha), smoothedAlpha); + gl_FragColor = gl_Color * vec4(1.0, 1.0, 1.0, smoothedAlpha); +}
\ No newline at end of file |