aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authoringlettronald <71849533+inglettronald@users.noreply.github.com>2023-01-11 02:36:35 -0600
committeringlettronald <inglettronald@gmail.com>2023-01-11 02:36:35 -0600
commitd7062b05c3d309e7a1e14d6d50c586b1dfe2138c (patch)
tree8a599b431dbf976e501770ec02779d97229005cb /src/main/kotlin
parentdfcc2c5818daa50b558a8a4cb81d0e92e03219d2 (diff)
downloadDulkirMod-d7062b05c3d309e7a1e14d6d50c586b1dfe2138c.tar.gz
DulkirMod-d7062b05c3d309e7a1e14d6d50c586b1dfe2138c.tar.bz2
DulkirMod-d7062b05c3d309e7a1e14d6d50c586b1dfe2138c.zip
- 1.14 commit:
oldanimations "fix" and scalable tooltips
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/dulkirmod/DulkirMod.kt27
-rw-r--r--src/main/kotlin/dulkirmod/config/Config.kt20
-rw-r--r--src/main/kotlin/dulkirmod/features/ScalableTooltips.kt146
3 files changed, 181 insertions, 12 deletions
diff --git a/src/main/kotlin/dulkirmod/DulkirMod.kt b/src/main/kotlin/dulkirmod/DulkirMod.kt
index 69ac692..7022105 100644
--- a/src/main/kotlin/dulkirmod/DulkirMod.kt
+++ b/src/main/kotlin/dulkirmod/DulkirMod.kt
@@ -61,17 +61,20 @@ class DulkirMod {
fun onInit(event: FMLInitializationEvent) {
config.init()
// REGISTER Classes and such HERE
- MinecraftForge.EVENT_BUS.register(this)
- MinecraftForge.EVENT_BUS.register(ChatEvent())
- MinecraftForge.EVENT_BUS.register(NametagCleaner)
- MinecraftForge.EVENT_BUS.register(titleUtils)
- MinecraftForge.EVENT_BUS.register(ArachneTimer())
- MinecraftForge.EVENT_BUS.register(MatchoAlert())
- MinecraftForge.EVENT_BUS.register(Croesus())
- MinecraftForge.EVENT_BUS.register(ContainerNameUtil())
- MinecraftForge.EVENT_BUS.register(DungeonLeap())
- MinecraftForge.EVENT_BUS.register(AbiphoneDND())
- MinecraftForge.EVENT_BUS.register(KeeperWaypoints())
+ val mcBus = MinecraftForge.EVENT_BUS
+ mcBus.register(this)
+ mcBus.register(ChatEvent())
+ mcBus.register(NametagCleaner)
+ mcBus.register(titleUtils)
+ mcBus.register(ArachneTimer())
+ mcBus.register(MatchoAlert())
+ mcBus.register(Croesus())
+ mcBus.register(ContainerNameUtil())
+ mcBus.register(DungeonLeap())
+ mcBus.register(AbiphoneDND())
+ mcBus.register(KeeperWaypoints())
+ mcBus.register(ScalableTooltips)
+
keyBinds.forEach(ClientRegistry::registerKeyBinding)
}
@@ -118,7 +121,7 @@ class DulkirMod {
companion object {
const val MOD_ID = "dulkirmod"
const val MOD_NAME = "Dulkir Mod"
- const val MOD_VERSION = "1.1.3"
+ const val MOD_VERSION = "1.1.4"
const val CHAT_PREFIX = "§f<§3DulkirMod§f>"
val mc: Minecraft = Minecraft.getMinecraft()
diff --git a/src/main/kotlin/dulkirmod/config/Config.kt b/src/main/kotlin/dulkirmod/config/Config.kt
index 83ffe07..32f917e 100644
--- a/src/main/kotlin/dulkirmod/config/Config.kt
+++ b/src/main/kotlin/dulkirmod/config/Config.kt
@@ -56,6 +56,25 @@ object Config : Vigilant(File("./config/dulkirmod/config.toml"), "DulkirMod", so
@Property(
type = PropertyType.SWITCH,
+ name = "Scalable Tooltips",
+ description = "more or less TOOLTIP",
+ category = "General"
+ )
+ var scaledTooltips = false
+
+ @Property(
+ type = PropertyType.DECIMAL_SLIDER,
+ name = "Tooltip Scale",
+ description = "1 is default",
+ category = "General",
+ minF = 0f,
+ maxF = 2f,
+ decimalPlaces = 1
+ )
+ var tooltipSize = 1f
+
+ @Property(
+ type = PropertyType.SWITCH,
name = "Hide Healer fairy",
description = "Probably disable when not in dungeons for now. Will fix later.",
category = "Dungeons"
@@ -525,6 +544,7 @@ object Config : Vigilant(File("./config/dulkirmod/config.toml"), "DulkirMod", so
addDependency("highlightLeapName", "highlightLeap")
addDependency("abiCallerID", "abiDND")
addDependency("hurtCamIntensity", "hurtCamSlider")
+ addDependency("tooltipSize", "scaledTooltips")
setCategoryDescription(
"Custom Animations",
diff --git a/src/main/kotlin/dulkirmod/features/ScalableTooltips.kt b/src/main/kotlin/dulkirmod/features/ScalableTooltips.kt
new file mode 100644
index 0000000..ae53a3b
--- /dev/null
+++ b/src/main/kotlin/dulkirmod/features/ScalableTooltips.kt
@@ -0,0 +1,146 @@
+package dulkirmod.features
+
+import dulkirmod.config.Config
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.FontRenderer
+import net.minecraft.client.renderer.GlStateManager
+import net.minecraft.client.renderer.RenderHelper
+import net.minecraftforge.fml.client.config.GuiUtils
+import org.lwjgl.input.Keyboard
+import org.lwjgl.input.Mouse
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo
+
+object ScalableTooltips {
+ var scrollY: Int = 0
+ var scrollX: Int = 0
+ // Checks to see if large tooltips should be snapped (for larger than can fit on screen code)
+ var snapFlag: Boolean = true
+
+ fun drawScaledHoveringText(
+ textLines: List<String>,
+ mouseX: Int,
+ mouseY: Int,
+ screenWidth: Int,
+ screenHeight: Int,
+ maxTextWidth: Int,
+ font: FontRenderer,
+ ci: CallbackInfo
+ ): Boolean {
+ if(!Config.scaledTooltips) return false
+ val scale = Config.tooltipSize
+
+ // Calculate the width and height of the tooltip box
+ var width = 0
+ for (textLine in textLines) {
+ val textWidth = font.getStringWidth(textLine)
+ if (textWidth > width) {
+ width = textWidth
+ }
+ }
+ val height = (textLines.size) * font.FONT_HEIGHT
+
+ // Save the matrix state and scale it
+ GlStateManager.pushMatrix()
+ GlStateManager.scale(scale, scale, 1f)
+ GlStateManager.disableRescaleNormal()
+ RenderHelper.disableStandardItemLighting()
+ GlStateManager.disableLighting()
+ GlStateManager.disableDepth()
+
+ // Calculate the amount of translation that should be applied based on how much the user has scrolled
+ val eventDWheel = Mouse.getDWheel()
+ if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
+ if (eventDWheel < 0) {
+ scrollX += Minecraft.getMinecraft().displayWidth/192
+ } else if (eventDWheel > 0) {
+ //Scrolling to access higher stuff
+ scrollX -= Minecraft.getMinecraft().displayWidth/192
+ }
+ } else {
+ if (eventDWheel < 0) {
+ scrollY -= Minecraft.getMinecraft().displayHeight/108
+ } else if (eventDWheel > 0) {
+ //Scrolling to access higher stuff
+ scrollY += Minecraft.getMinecraft().displayHeight/108
+ }
+ }
+
+ // calculates where it wants to put the tooltip based on user input
+ var x = ((mouseX + 12 + scrollX) / scale).toInt()
+ var y = ((mouseY - 12 + scrollY) / scale).toInt()
+
+ /**
+ * Extra code to account for larger tooltips:
+ * Tooltips should not initially render off the screen if they can fit, if too wide/too long for screen
+ * it will just default to normal.
+ */
+ if ((x + width + 4 > screenWidth / scale) && (width + 4 <= screenWidth / scale)) {
+ scrollX = (screenWidth - mouseX - 12 - (width + 4)* scale).toInt()
+ }
+
+ if ((y + height + 4 > screenHeight / scale) && (height + 4 <= screenHeight / scale)) {
+ scrollY = (screenHeight - mouseY + 12 - (height + 4)* scale).toInt()
+ }
+
+ /**
+ * HAVE: default x and y
+ * NEED: modify scrollx and scroll why such that updates x and y to 0 later
+ */
+ if (x < 0 && (width + 4 <= screenWidth / scale))
+ scrollX = -mouseX - 12 + 4
+ if (y < 0 && (height + 4 <= screenHeight / scale))
+ scrollY = -mouseY + 12 + 4
+
+
+ // if too large, then snap to top (if first time rendering tooltip)
+ if (snapFlag) {
+ if (width + 4 > screenWidth / scale) {
+ scrollX = -mouseX - 12 + 4
+ }
+ if (height + 4 > screenHeight / scale) {
+ scrollY = -mouseY + 12 + 4
+ }
+ snapFlag = false
+ }
+
+ //updates the position of x and y if it has been modified.
+ x = ((mouseX + 12 + scrollX) / scale).toInt()
+ y = ((mouseY - 12 + scrollY) / scale).toInt()
+
+ // Draw the background rectangle
+ val backgroundColor = -0xfeffff0
+ val zLevel = 300
+
+ GuiUtils.drawGradientRect(zLevel, x - 3, y - 4, x + width + 3, y - 3, backgroundColor, backgroundColor)
+ GuiUtils.drawGradientRect(zLevel, x - 3, y + height + 3, x + width + 3, y + height + 4, backgroundColor, backgroundColor)
+ GuiUtils.drawGradientRect(zLevel, x - 3, y - 3, x + width + 3, y + height + 3, backgroundColor, backgroundColor)
+ GuiUtils.drawGradientRect(zLevel, x - 4, y - 3, x - 3, y + height + 3, backgroundColor, backgroundColor)
+ GuiUtils.drawGradientRect(zLevel, x + width + 3, y - 3, x + width + 4, y + height + 3, backgroundColor, backgroundColor)
+ val borderColorStart = 0x505000FF
+ val borderColorEnd = borderColorStart and 0xFEFEFE shr 1 or (borderColorStart and -0x1000000)
+ GuiUtils.drawGradientRect(zLevel, x - 3, y - 3 + 1, x - 3 + 1, y + height + 3 - 1, borderColorStart, borderColorEnd)
+ GuiUtils.drawGradientRect(zLevel, x + width + 2, y - 3 + 1, x + width + 3, y + height + 3 - 1, borderColorStart, borderColorEnd)
+ GuiUtils.drawGradientRect(zLevel, x - 3, y - 3, x + width + 3, y - 3 + 1, borderColorStart, borderColorStart)
+ GuiUtils.drawGradientRect(zLevel, x - 3, y + height + 2, x + width + 3, y + height + 3, borderColorEnd, borderColorEnd)
+
+ // Render the tooltip text
+ var yStart = y
+ for (textLine in textLines) {
+ font.drawStringWithShadow(textLine, x.toFloat(), yStart.toFloat(), -1)
+ yStart += font.FONT_HEIGHT
+ }
+ // Reset matrix state
+ GlStateManager.enableLighting()
+ GlStateManager.enableDepth()
+ RenderHelper.enableStandardItemLighting()
+ GlStateManager.enableRescaleNormal()
+ GlStateManager.popMatrix()
+ return true
+ }
+
+ fun resetPos() {
+ scrollX = 0
+ scrollY = 0
+ snapFlag = true
+ }
+} \ No newline at end of file