diff options
author | Appability <appable@icloud.com> | 2022-10-21 23:33:52 -0700 |
---|---|---|
committer | Appability <appable@icloud.com> | 2022-10-21 23:33:52 -0700 |
commit | 4f25e7948c7e85151a80c17f7d2b25b72675cecf (patch) | |
tree | 7e152610a0f80f40f5524a231a157ea81ffab0e3 /src | |
parent | 1c3359e42f38012dae182e75200cc1f364dcda8f (diff) | |
download | AmbientAddons-4f25e7948c7e85151a80c17f7d2b25b72675cecf.tar.gz AmbientAddons-4f25e7948c7e85151a80c17f7d2b25b72675cecf.tar.bz2 AmbientAddons-4f25e7948c7e85151a80c17f7d2b25b72675cecf.zip |
moving gui stuff (attempt 1)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/kotlin/com/ambientaddons/AmbientAddons.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/config/Config.kt | 16 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/config/PersistentData.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/features/display/CatOverlay.kt | 29 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/gui/GuiElement.kt | 44 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/gui/GuiPosition.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/gui/MoveGui.kt | 77 | ||||
-rw-r--r-- | src/main/kotlin/com/ambientaddons/utils/render/OverlayUtils.kt | 35 | ||||
-rwxr-xr-x | src/main/resources/assets/ambientaddons/kittycatmodule.png | bin | 0 -> 1153448 bytes |
9 files changed, 222 insertions, 3 deletions
diff --git a/src/main/kotlin/com/ambientaddons/AmbientAddons.kt b/src/main/kotlin/com/ambientaddons/AmbientAddons.kt index 8f0bcef..7b481ce 100644 --- a/src/main/kotlin/com/ambientaddons/AmbientAddons.kt +++ b/src/main/kotlin/com/ambientaddons/AmbientAddons.kt @@ -1,12 +1,14 @@ import com.ambientaddons.commands.AmbientCommand import com.ambientaddons.config.Config import com.ambientaddons.config.PersistentData +import com.ambientaddons.features.display.CatOverlay import com.ambientaddons.features.display.WitherShieldOverlay import com.ambientaddons.features.dungeon.* import com.ambientaddons.features.dungeon.terminals.MelodyHelper import com.ambientaddons.features.keybinds.PerspectiveKeybind import com.ambientaddons.features.keybinds.SendLastMessageKeybind import com.ambientaddons.features.misc.* +import com.ambientaddons.gui.GuiElement import com.ambientaddons.utils.SBLocation import com.ambientaddons.utils.dungeon.DungeonPlayers import net.minecraft.client.Minecraft @@ -63,9 +65,13 @@ class AmbientAddons { KuudraReady, DungeonHighlights, Trapper, - CrimsonFishing + CrimsonFishing, + CatOverlay ).forEach(MinecraftForge.EVENT_BUS::register) keyBinds.values.forEach(ClientRegistry::registerKeyBinding) + guiElements = listOf( + CatOverlay.element + ) } @SubscribeEvent @@ -90,6 +96,8 @@ class AmbientAddons { var currentGui: GuiScreen? = null + lateinit var guiElements: List<GuiElement> + lateinit var configDirectory: File lateinit var config: Config lateinit var persistentData: PersistentData diff --git a/src/main/kotlin/com/ambientaddons/config/Config.kt b/src/main/kotlin/com/ambientaddons/config/Config.kt index e81d89a..4e4c39f 100644 --- a/src/main/kotlin/com/ambientaddons/config/Config.kt +++ b/src/main/kotlin/com/ambientaddons/config/Config.kt @@ -1,5 +1,7 @@ package com.ambientaddons.config +import AmbientAddons.Companion.currentGui +import com.ambientaddons.gui.MoveGui import gg.essential.vigilance.Vigilant import java.awt.Color import java.io.File @@ -9,6 +11,7 @@ object Config : Vigilant( File(AmbientAddons.configDirectory, "config.toml"), AmbientAddons.metadata.name ) { + var kuudraReady = false var autoTrapper = false var trapperEsp = false @@ -31,7 +34,7 @@ object Config : Vigilant( var autoReady = 0 var maskWarning = false - + var cat = true var witherShieldDisplay = 0 var terminatorCps = 0 @@ -171,6 +174,17 @@ object Config : Vigilant( } category("Displays") { + button( + name = "Move GUI elements", + description = "Opens a GUI to edit locations of all GUI elements.", + ) { + currentGui = MoveGui() + } + switch( + ::cat, + name = "Cat", + description = "Show catplague's awesome cat upgrade! Disabling is a crime.", + ) selector( ::witherShieldDisplay, name = "Wither shield display", diff --git a/src/main/kotlin/com/ambientaddons/config/PersistentData.kt b/src/main/kotlin/com/ambientaddons/config/PersistentData.kt index 87bb287..9588e21 100644 --- a/src/main/kotlin/com/ambientaddons/config/PersistentData.kt +++ b/src/main/kotlin/com/ambientaddons/config/PersistentData.kt @@ -1,5 +1,6 @@ package com.ambientaddons.config +import com.ambientaddons.gui.GuiPosition import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import java.io.File @@ -23,7 +24,8 @@ data class PersistentData( "THUNDERLORD_7" to null, "WITHER_CHESTPLATE" to null, "ULTIMATE_ONE_FOR_ALL_1" to null - ) + ), + var positions: MutableMap<String, GuiPosition> = mutableMapOf() ) { fun save() { diff --git a/src/main/kotlin/com/ambientaddons/features/display/CatOverlay.kt b/src/main/kotlin/com/ambientaddons/features/display/CatOverlay.kt new file mode 100644 index 0000000..ac35729 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/features/display/CatOverlay.kt @@ -0,0 +1,29 @@ +package com.ambientaddons.features.display + +import AmbientAddons.Companion.config +import AmbientAddons.Companion.mc +import com.ambientaddons.gui.GuiElement +import com.ambientaddons.utils.render.OverlayUtils +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.util.ResourceLocation +import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.math.roundToInt + +object CatOverlay { + private val cat = ResourceLocation("ambientaddons", "kittycatmodule.png") + val element = GuiElement("cat", 100, 100) + + @SubscribeEvent + fun onRenderOverlay(event: RenderGameOverlayEvent) { + if (!config.cat || event.type != RenderGameOverlayEvent.ElementType.TEXT) return + GlStateManager.pushMatrix() + GlStateManager.enableAlpha() + GlStateManager.color(255f, 255f, 255f, 255f) + GlStateManager.translate(element.position.x, element.position.y, 500.0) + mc.textureManager.bindTexture(cat) + val renderSize = (100 * element.position.scale).roundToInt() + OverlayUtils.drawTexturedModalRect(0, 0, renderSize, renderSize) + GlStateManager.popMatrix() + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/gui/GuiElement.kt b/src/main/kotlin/com/ambientaddons/gui/GuiElement.kt new file mode 100644 index 0000000..c398464 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/gui/GuiElement.kt @@ -0,0 +1,44 @@ +package com.ambientaddons.gui + +import AmbientAddons.Companion.persistentData +import com.ambientaddons.utils.render.OverlayUtils +import gg.essential.universal.UResolution +import net.minecraft.client.renderer.GlStateManager +import java.awt.Color + + +class GuiElement(val name: String, private val width: Int, private val height: Int) { + var position = persistentData.positions[name] ?: run { + persistentData.positions[name] = GuiPosition(0.0, 0.0, 1.0) + persistentData.positions[name]!! + } + + fun isInsideElement(mouseX: Double, mouseY: Double): Boolean { + val renderWidth = width * position.scale + val renderHeight = height * position.scale + val xInside = mouseX in (position.x - padding * renderWidth)..(position.x + renderWidth * (1 + padding)) + val yInside = mouseY in (position.y - padding * renderHeight)..(position.y + renderHeight * (1 + padding)) + return xInside && yInside + } + + fun coerceIntoScreen() { + val xRange = 0.0..(UResolution.scaledWidth - width * position.scale) + val yRange = 0.0..(UResolution.scaledHeight - height * position.scale) + position.x = if (xRange.isEmpty()) 0.0 else position.x.coerceIn(xRange) + position.y = if (yRange.isEmpty()) 0.0 else position.y.coerceIn(yRange) + } + + fun draw(mouseX: Double, mouseY: Double) { + GlStateManager.pushMatrix() + val renderWidth = width * position.scale + val renderHeight = height * position.scale + GlStateManager.translate(position.x - padding * renderWidth, position.y - padding * renderWidth, 400.0) + val color = if (isInsideElement(mouseX, mouseY)) Color(255, 255, 255, 128) else Color(128, 128, 128, 128) + OverlayUtils.renderRect(0.0, 0.0, renderWidth * (1 + padding * 2), renderHeight * (1 + padding * 2), color) + GlStateManager.popMatrix() + } + + companion object { + private const val padding = 0.05 + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/gui/GuiPosition.kt b/src/main/kotlin/com/ambientaddons/gui/GuiPosition.kt new file mode 100644 index 0000000..50b3f07 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/gui/GuiPosition.kt @@ -0,0 +1,10 @@ +package com.ambientaddons.gui + +import kotlinx.serialization.Serializable + +@Serializable +data class GuiPosition ( + var x: Double, + var y: Double, + var scale: Double +)
\ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/gui/MoveGui.kt b/src/main/kotlin/com/ambientaddons/gui/MoveGui.kt new file mode 100644 index 0000000..33c96e7 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/gui/MoveGui.kt @@ -0,0 +1,77 @@ +package com.ambientaddons.gui + +import AmbientAddons.Companion.guiElements +import AmbientAddons.Companion.persistentData +import com.ambientaddons.utils.Alignment +import com.ambientaddons.utils.dungeon.TextStyle +import com.ambientaddons.utils.render.OverlayUtils +import gg.essential.universal.UResolution +import net.minecraft.client.gui.GuiScreen +import net.minecraft.client.renderer.GlStateManager +import org.lwjgl.input.Mouse +import org.lwjgl.opengl.Display +import java.awt.Color + +class MoveGui : GuiScreen() { + private var currentElement: GuiElement? = null + private var clickOffsetX = 0.0 + private var clickOffsetY = 0.0 + + override fun drawScreen(x: Int, y: Int, partialTicks: Float) { + super.drawScreen(x, y, partialTicks) + val (mouseX, mouseY) = getMouseCoordinates() + OverlayUtils.renderRect( + 0.0, 0.0, UResolution.scaledWidth.toDouble(), UResolution.scaledHeight.toDouble(), Color(0, 0, 0, 64) + ) + GlStateManager.pushMatrix() + GlStateManager.translate(UResolution.scaledWidth / 2.0, UResolution.scaledHeight / 2.0, 300.0) + OverlayUtils.drawString(0, 10, "Drag to move GUI elements.", TextStyle.Outline, Alignment.Center) + OverlayUtils.drawString(0, 20, "Scroll inside elements to scale.", TextStyle.Outline, Alignment.Center) + GlStateManager.popMatrix() + guiElements.forEach { it.draw(mouseX, mouseY) } + } + + override fun mouseClicked(x: Int, y: Int, mouseButton: Int) { + val (mouseX, mouseY) = getMouseCoordinates() + currentElement = guiElements.find { it.isInsideElement(mouseX, mouseY) }?.apply { + clickOffsetX = mouseX - position.x + clickOffsetY = mouseY - position.y + } + super.mouseClicked(x, y, mouseButton) + } + + override fun mouseClickMove(x: Int, y: Int, clickedMouseButton: Int, timeSinceLastClick: Long) { + currentElement?.apply { + val (mouseX, mouseY) = getMouseCoordinates() + position.x = mouseX - clickOffsetX + position.y = mouseY - clickOffsetY + coerceIntoScreen() + } + super.mouseClickMove(x, y, clickedMouseButton, timeSinceLastClick) + } + + override fun handleMouseInput() { + super.handleMouseInput() + val (mouseX, mouseY) = getMouseCoordinates() + currentElement = guiElements.find { it.isInsideElement(mouseX, mouseY) }?.apply { + clickOffsetX = mouseX - position.x + clickOffsetY = mouseY - position.y + val scrollAmount = Mouse.getEventDWheel() + val oldScale = position.scale + val newScale = (position.scale + scrollAmount / 7200.0).coerceAtLeast(0.1) + position.x = mouseX + (newScale / oldScale) * (position.x - mouseX) + position.y = mouseY + (newScale / oldScale) * (position.y - mouseY) + position.scale = newScale + coerceIntoScreen() + } + } + + private fun getMouseCoordinates(): Pair<Double, Double> { + val mouseX = Mouse.getX() / UResolution.scaleFactor + val mouseY = (Display.getHeight() - Mouse.getY()) / UResolution.scaleFactor + return Pair(mouseX, mouseY) + } + + override fun onGuiClosed() = persistentData.save() + +}
\ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/utils/render/OverlayUtils.kt b/src/main/kotlin/com/ambientaddons/utils/render/OverlayUtils.kt index 69f3c99..084bf1d 100644 --- a/src/main/kotlin/com/ambientaddons/utils/render/OverlayUtils.kt +++ b/src/main/kotlin/com/ambientaddons/utils/render/OverlayUtils.kt @@ -7,6 +7,8 @@ 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 org.lwjgl.opengl.GL11.GL_QUADS +import java.awt.Color import kotlin.math.roundToInt object OverlayUtils { @@ -71,4 +73,37 @@ object OverlayUtils { } } + + fun renderRect(x: Double, y: Double, w: Double, h: Double, color: Color) { + if (color.alpha == 0) return + GlStateManager.enableBlend() + GlStateManager.disableTexture2D() + GlStateManager.enableAlpha() + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) + GlStateManager.color(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f) + + worldRenderer.begin(GL_QUADS, DefaultVertexFormats.POSITION) + worldRenderer.pos(x, y + h, 0.0).endVertex() + worldRenderer.pos(x + w, y + h, 0.0).endVertex() + worldRenderer.pos(x + w, y, 0.0).endVertex() + worldRenderer.pos(x, y, 0.0).endVertex() + tessellator.draw() + + GlStateManager.disableAlpha() + GlStateManager.enableTexture2D() + GlStateManager.disableBlend() + } + + private val tessellator: Tessellator = Tessellator.getInstance() + private val worldRenderer: WorldRenderer = tessellator.worldRenderer + + fun drawTexturedModalRect(x: Int, y: Int, width: Int, height: Int) { + worldRenderer.begin(GL_QUADS, DefaultVertexFormats.POSITION_TEX) + worldRenderer.pos(x.toDouble(), (y + height).toDouble(), 0.0).tex(0.0, 1.0).endVertex() + worldRenderer.pos((x + width).toDouble(), (y + height).toDouble(), 0.0).tex(1.0, 1.0).endVertex() + worldRenderer.pos((x + width).toDouble(), y.toDouble(), 0.0).tex(1.0, 0.0).endVertex() + worldRenderer.pos(x.toDouble(), y.toDouble(), 0.0).tex(0.0, 0.0).endVertex() + tessellator.draw() + } + }
\ No newline at end of file diff --git a/src/main/resources/assets/ambientaddons/kittycatmodule.png b/src/main/resources/assets/ambientaddons/kittycatmodule.png Binary files differnew file mode 100755 index 0000000..284c21f --- /dev/null +++ b/src/main/resources/assets/ambientaddons/kittycatmodule.png |