diff --git a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt new file mode 100644 index 0000000..6f03a47 --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt @@ -0,0 +1,10 @@ +package fr.username404.snowygui + +import fr.username404.snowygui.gui.Element +import fr.username404.snowygui.gui.SnowyScreen + +class ClickGui: SnowyScreen() { + override val components: MutableSet = mutableSetOf( + // TODO Add components to the ClickGui + ) +} \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/SnowyScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/SnowyScreen.kt deleted file mode 100644 index 79d37fc..0000000 --- a/common/src/main/kotlin/fr/username404/snowygui/SnowyScreen.kt +++ /dev/null @@ -1,8 +0,0 @@ -package fr.username404.snowygui - -import net.minecraft.client.gui.screens.Screen -import net.minecraft.network.chat.TranslatableComponent - -internal class SnowyScreen: Screen(TranslatableComponent("screen.snowy.gui")) { - -} \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt b/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt index 490f97d..002df80 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt @@ -1,7 +1,7 @@ package fr.username404.snowygui.config import com.mojang.blaze3d.platform.InputConstants -import fr.username404.snowygui.SnowyScreen +import fr.username404.snowygui.ClickGui import net.minecraft.client.KeyMapping import net.minecraft.client.Minecraft import org.lwjgl.glfw.GLFW.GLFW_KEY_U @@ -17,7 +17,7 @@ object AddKeyMaps { ) to lambda } val list: MutableMap Unit)?> = mutableMapOf( - mkMap("opengui", GLFW_KEY_Y) { Minecraft.getInstance().setScreen(SnowyScreen()) }, + mkMap("opengui", GLFW_KEY_Y) { Minecraft.getInstance().setScreen(ClickGui()) }, mkMap("configkey", GLFW_KEY_U) { Minecraft.getInstance().setScreen(SnowyConfigScreen()) } ) } \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt index 9ff5025..b9882e0 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -1,8 +1,10 @@ package fr.username404.snowygui.config -import net.minecraft.client.gui.screens.Screen -import net.minecraft.network.chat.TranslatableComponent - -open class SnowyConfigScreen: Screen(TranslatableComponent("screen.snowygui.config")) { // TODO Actual config screen +import fr.username404.snowygui.gui.Element +import fr.username404.snowygui.gui.SnowyScreen +open class SnowyConfigScreen: SnowyScreen("screen.snowygui.config") { // TODO Actual config screen + override val components: MutableSet? = mutableSetOf( + // TODO Add components to the config gui + ) } \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Box.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Box.kt new file mode 100644 index 0000000..34e3b2e --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Box.kt @@ -0,0 +1,9 @@ +package fr.username404.snowygui.gui + +import fr.username404.snowygui.rendering.Util + +class Box(x: Int, y: Int, scale: Int): Element(x, y, 20 * scale, 10 * scale) { + override fun render() { + Util.UIRect(x, y, this.width, this.height, opacity = 1F) + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt new file mode 100644 index 0000000..bbf3dd4 --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -0,0 +1,10 @@ +package fr.username404.snowygui.gui + +fun interface Renderable { fun render() } +abstract class Element( + var x: Int, var y: Int, + val width: Int, val height: Int +): Renderable { + fun display() { if (!hidden) render() } + var hidden: Boolean = false +} \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt new file mode 100644 index 0000000..639c743 --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt @@ -0,0 +1,17 @@ +package fr.username404.snowygui.gui + +import com.mojang.blaze3d.vertex.PoseStack +import net.minecraft.client.gui.screens.Screen +import net.minecraft.network.chat.TranslatableComponent + +abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) { + open val components: MutableSet? = null + override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) { + if (poseStack != null) { + components?.forEach { + it.display() + } + } + } + override fun isPauseScreen(): Boolean = willPauseScreen +} \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/rendering/Util.kt b/common/src/main/kotlin/fr/username404/snowygui/rendering/Util.kt new file mode 100644 index 0000000..0764825 --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/rendering/Util.kt @@ -0,0 +1,41 @@ +package fr.username404.snowygui.rendering + +import com.mojang.blaze3d.platform.GlStateManager +import com.mojang.blaze3d.systems.RenderSystem +import com.mojang.blaze3d.vertex.BufferBuilder +import com.mojang.blaze3d.vertex.DefaultVertexFormat +import com.mojang.blaze3d.vertex.PoseStack +import com.mojang.blaze3d.vertex.Tesselator +import net.minecraft.client.Minecraft +import org.lwjgl.opengl.GL11 + +internal object Util { + private val tessellator: Tesselator = Tesselator.getInstance() + private val buffer: BufferBuilder = tessellator.builder + fun UIRect(x: Int, y: Int, width: Int, height: Int, color: Int = -0x1, opacity: Float) { + val r = (color shr 16 and 255) / 255.0f + val g = (color shr 8 and 255) / 255.0f + val b = (color and 255) / 255.0f + RenderSystem.enableBlend() + RenderSystem.disableTexture() + RenderSystem.blendFuncSeparate( + GlStateManager.SourceFactor.SRC_ALPHA, + GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, + GlStateManager.SourceFactor.ONE, + GlStateManager.DestFactor.ZERO + ) + with(buffer) { + begin(GL11.GL_QUADS, DefaultVertexFormat.POSITION_COLOR) + vertex(x.toDouble(), y.toDouble() + height, 0.0).color(r, g, b, opacity).endVertex() + vertex(x.toDouble() + width, y.toDouble() + height, 0.0).color(r, g, b, opacity).endVertex() + vertex(x.toDouble() + width, y.toDouble(), 0.0).color(r, g, b, opacity).endVertex() + vertex(x.toDouble(), y.toDouble(), 0.0).color(r, g, b, opacity).endVertex() + tessellator.end() + RenderSystem.enableTexture() + RenderSystem.disableBlend() + } + } + fun UIString(poseStack: PoseStack, string: String, i: Float, j: Float) { + Minecraft.getInstance().font.draw(poseStack, string, i, j, 10) + } +} \ No newline at end of file