diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2023-10-14 21:45:26 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-14 12:45:26 +0200 |
commit | 7a634386ec4dd842e946bd3ba331c0d565faf173 (patch) | |
tree | 558cc86b80b6e1af0d2a8ba857324b1d72ed774b /src/main/java/at/hannibal2/skyhanni/features | |
parent | 16ef943b3c2ce8db2331332261143a12bdba61cf (diff) | |
download | skyhanni-7a634386ec4dd842e946bd3ba331c0d565faf173.tar.gz skyhanni-7a634386ec4dd842e946bd3ba331c0d565faf173.tar.bz2 skyhanni-7a634386ec4dd842e946bd3ba331c0d565faf173.zip |
Feature: Modify Visual Words (#492)
Added /shwords. #492
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
7 files changed, 498 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt index 65c6c54b2..b7e103be1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt @@ -97,96 +97,120 @@ open class FFGuideGUI : GuiScreen() { GuiRenderUtils.drawStringCentered("§7SkyHanni", guiLeft + 325, guiTop + 170) if (currentCrop == null) { GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.HELMET.getItem(), guiLeft + 142, guiTop + 5, mouseX, mouseY, if (currentArmor == 1) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.CHESTPLATE.getItem(), guiLeft + 162, guiTop + 5, mouseX, mouseY, if (currentArmor == 2) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.LEGGINGS.getItem(), guiLeft + 182, guiTop + 5, mouseX, mouseY, if (currentArmor == 3) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.BOOTS.getItem(), guiLeft + 202, guiTop + 5, mouseX, mouseY, if (currentArmor == 4) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.NECKLACE.getItem(), guiLeft + 262, guiTop + 5, mouseX, mouseY, if (currentEquipment == 1) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.CLOAK.getItem(), guiLeft + 282, guiTop + 5, mouseX, mouseY, if (currentEquipment == 2) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.BELT.getItem(), guiLeft + 302, guiTop + 5, mouseX, mouseY, if (currentEquipment == 3) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.BRACELET.getItem(), guiLeft + 322, guiTop + 5, mouseX, mouseY, if (currentEquipment == 4) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.ELEPHANT.getItem(), guiLeft + 142, guiTop + 130, mouseX, mouseY, if (currentPet == FarmingItems.ELEPHANT) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.MOOSHROOM_COW.getItem(), guiLeft + 162, guiTop + 130, mouseX, mouseY, if (currentPet == FarmingItems.MOOSHROOM_COW) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.RABBIT.getItem(), guiLeft + 182, guiTop + 130, mouseX, mouseY, if (currentPet == FarmingItems.RABBIT) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.BEE.getItem(), guiLeft + 202, guiTop + 130, mouseX, mouseY, if (currentPet == FarmingItems.BEE) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) } else { GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.ELEPHANT.getItem(), guiLeft + 142, guiTop + 160, mouseX, mouseY, if (currentPet == FarmingItems.ELEPHANT) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.MOOSHROOM_COW.getItem(), guiLeft + 162, guiTop + 160, mouseX, mouseY, if (currentPet == FarmingItems.MOOSHROOM_COW) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.RABBIT.getItem(), guiLeft + 182, guiTop + 160, mouseX, mouseY, if (currentPet == FarmingItems.RABBIT) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.BEE.getItem(), guiLeft + 202, guiTop + 160, mouseX, mouseY, if (currentPet == FarmingItems.BEE) 0xFFB3FFB3.toInt() else 0xFF43464B.toInt() ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.HELMET.getItem(), guiLeft + 162, guiTop + 80, mouseX, mouseY ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.CHESTPLATE.getItem(), guiLeft + 162, guiTop + 100, mouseX, mouseY ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.LEGGINGS.getItem(), guiLeft + 162, guiTop + 120, mouseX, mouseY ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.BOOTS.getItem(), guiLeft + 162, guiTop + 140, mouseX, mouseY ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.NECKLACE.getItem(), guiLeft + 182, guiTop + 80, mouseX, mouseY ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.CLOAK.getItem(), guiLeft + 182, guiTop + 100, mouseX, mouseY ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.BELT.getItem(), guiLeft + 182, guiTop + 120, mouseX, mouseY ) GuiRenderUtils.renderItemAndTip( + tooltipToDisplay, FarmingItems.BRACELET.getItem(), guiLeft + 182, guiTop + 140, mouseX, mouseY ) } @@ -443,4 +467,4 @@ open class FFGuideGUI : GuiScreen() { abstract class FFGuidePage { abstract fun drawPage(mouseX: Int, mouseY: Int, partialTicks: Float) } -} +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/pages/CropPage.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/pages/CropPage.kt index 7a5435393..cb20cc86a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/pages/CropPage.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/pages/CropPage.kt @@ -12,7 +12,7 @@ class CropPage: FFGuideGUI.FFGuidePage() { override fun drawPage(mouseX: Int, mouseY: Int, partialTicks: Float) { for (item in FarmingItems.entries) { if (item.name == FFGuideGUI.currentCrop?.name) { - GuiRenderUtils.renderItemAndTip(item.getItem(), FFGuideGUI.guiLeft + 172, FFGuideGUI.guiTop + 60, mouseX, mouseY) + GuiRenderUtils.renderItemAndTip(FFGuideGUI.tooltipToDisplay, item.getItem(), FFGuideGUI.guiLeft + 172, FFGuideGUI.guiTop + 60, mouseX, mouseY) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/pages/UpgradePage.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/pages/UpgradePage.kt index 27dfc6a33..bef201bc7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/pages/UpgradePage.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/pages/UpgradePage.kt @@ -23,10 +23,10 @@ class UpgradePage: FFGuideGUI.FFGuidePage() { GlStateManager.scale(0.75f, 0.75f, 1f) GuiRenderUtils.drawString("Upgrade", (FFGuideGUI.guiLeft + 45) * inverseScale, (FFGuideGUI.guiTop + 5) * inverseScale) + GuiRenderUtils.drawString("Item", (FFGuideGUI.guiLeft + 190) * inverseScale, (FFGuideGUI.guiTop + 5) * inverseScale) GuiRenderUtils.drawString("FF increase", (FFGuideGUI.guiLeft + 240) * inverseScale, (FFGuideGUI.guiTop + 5) * inverseScale) GuiRenderUtils.drawString("Cost/FF", (FFGuideGUI.guiLeft + 290) * inverseScale, (FFGuideGUI.guiTop + 5) * inverseScale) GuiRenderUtils.drawString("Total", (FFGuideGUI.guiLeft + 330) * inverseScale, (FFGuideGUI.guiTop + 5) * inverseScale) - GuiRenderUtils.drawString("Item", (FFGuideGUI.guiLeft + 190) * inverseScale, (FFGuideGUI.guiTop + 5) * inverseScale) val upgradeList = if (FFGuideGUI.currentCrop == null) FortuneUpgrades.genericUpgrades else FortuneUpgrades.cropSpecificUpgrades listLength = upgradeList.size @@ -43,12 +43,12 @@ class UpgradePage: FFGuideGUI.FFGuidePage() { formattedUpgrade = "$formattedUpgrade §fx${upgrade.itemQuantity}" } GuiRenderUtils.drawTwoLineString(upgrade.description, (FFGuideGUI.guiLeft + 15) * inverseScale, (adjustedY + 25 * index) * inverseScale) + GuiRenderUtils.renderItemAndTip(FFGuideGUI.tooltipToDisplay, upgradeItem, (FFGuideGUI.guiLeft + 155) * inverseScale, (adjustedY + 25 * index - 5) * inverseScale, + mouseX * inverseScale, mouseY * inverseScale, 0x00FFFFFF) + GuiRenderUtils.drawString(formattedUpgrade, (FFGuideGUI.guiLeft + 180) * inverseScale, (adjustedY + 25 * index) * inverseScale) GuiRenderUtils.drawString("§a${DecimalFormat("0.##").format(upgrade.fortuneIncrease)}", (FFGuideGUI.guiLeft + 270) * inverseScale, (adjustedY + 25 * index) * inverseScale) GuiRenderUtils.drawString("§6" + upgrade.costPerFF?.let { NumberUtil.format(it) }, (FFGuideGUI.guiLeft + 300) * inverseScale, (adjustedY + 25 * index) * inverseScale) GuiRenderUtils.drawString(("§6" + upgrade.cost?.let { NumberUtil.format(it) }), (FFGuideGUI.guiLeft + 335) * inverseScale, (adjustedY + 25 * index) * inverseScale) - GuiRenderUtils.drawString(formattedUpgrade, (FFGuideGUI.guiLeft + 180) * inverseScale, (adjustedY + 25 * index) * inverseScale) - GuiRenderUtils.renderItemAndTip(upgradeItem, (FFGuideGUI.guiLeft + 155) * inverseScale, (adjustedY + 25 * index - 5) * inverseScale, - mouseX * inverseScale, mouseY * inverseScale, 0x00FFFFFF) } GlStateManager.scale(inverseScale, inverseScale, 1f) scrollScreen() diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ChatPeek.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ChatPeek.kt index eb9b49a78..b92375f10 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ChatPeek.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ChatPeek.kt @@ -1,7 +1,10 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.GuiEditManager import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld +import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI +import at.hannibal2.skyhanni.features.misc.visualwords.VisualWordGui import at.hannibal2.skyhanni.utils.NEUItems import io.github.moulberry.moulconfig.gui.GuiScreenElementWrapper import net.minecraft.client.Minecraft @@ -20,6 +23,7 @@ object ChatPeek { if (Minecraft.getMinecraft().currentScreen is GuiScreenElementWrapper) return false if (NEUItems.neuHasFocus()) return false + if (GuiEditManager.isInGui() || FFGuideGUI.isInGui() || VisualWordGui.isInGui()) return false return key.isKeyHeld() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt new file mode 100644 index 000000000..6b39b3885 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt @@ -0,0 +1,47 @@ +package at.hannibal2.skyhanni.features.misc.visualwords + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.convertToFormatted +import com.google.common.cache.Cache +import com.google.common.cache.CacheBuilder +import java.util.concurrent.TimeUnit + +object ModifyVisualWords { + private val config get() = SkyHanniMod.feature.gui.modifyWords + var textCache: Cache<String, String> = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build() + + var modifiedWords = mutableListOf<VisualWord>() + + fun modifyText(originalText: String?): String? { + var modifiedText = originalText ?: return null + if (!LorenzUtils.onHypixel) return originalText + if (!config.enabled) return originalText + if (!LorenzUtils.inSkyBlock && !config.workOutside) return originalText + if (VisualWordGui.isInGui()) return originalText + + if (modifiedWords.isEmpty()) { + modifiedWords = SkyHanniMod.feature.storage.modifiedWords + } + + val cachedResult = textCache.getIfPresent(originalText) + if (cachedResult != null) { + return cachedResult + } + + var replacements = 0 + + for (modifiedWord in modifiedWords) { + if (!modifiedWord.enabled) continue + val phrase = modifiedWord.phrase.convertToFormatted() + + if (phrase.isEmpty()) continue + + replacements += 1 + modifiedText = modifiedText.replace(phrase, modifiedWord.replacement.convertToFormatted()) + } + // if not many are done it is better to not cache it + if (replacements > 2) textCache.put(originalText, modifiedText) + return modifiedText + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWord.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWord.kt new file mode 100644 index 000000000..fa8e0fa97 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWord.kt @@ -0,0 +1,9 @@ +package at.hannibal2.skyhanni.features.misc.visualwords + +import com.google.gson.annotations.Expose + +data class VisualWord( + @Expose var phrase: String, + @Expose var replacement: String, + @Expose var enabled: Boolean + )
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt new file mode 100644 index 000000000..b3492663d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt @@ -0,0 +1,408 @@ +package at.hannibal2.skyhanni.features.misc.visualwords + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.StringUtils.convertToFormatted +import kotlinx.coroutines.launch +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiScreen +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.init.Blocks +import net.minecraft.item.ItemStack +import net.minecraft.util.MathHelper +import org.lwjgl.input.Keyboard +import org.lwjgl.input.Mouse +import java.io.IOException + +open class VisualWordGui : GuiScreen() { + private var guiLeft = 0 + private var guiTop = 0 + private var screenHeight = 0 + private val sizeX = 360 + private val sizeY = 180 + private val maxTextLength = 75 + + private var mouseX = 0 + private var mouseY = 0 + private var lastMouseScroll = 0 + private var noMouseScrollFrames = 0 + + private var pageScroll = 0 + private var scrollVelocity = 0.0 + private val maxNoInputFrames = 100 + + private var lastClickedHeight = 0 + private var lastClickedWidth = 0 + private var changedIndex = -1 + private var changedAction = "" + + private var currentlyEditing = false + private var currentIndex = -1 + + private var currentTextBox = "" + private var currentText = "" + + private var modifiedWords = mutableListOf<VisualWord>() + + companion object { + fun isInGui() = Minecraft.getMinecraft().currentScreen is VisualWordGui + } + + override fun drawScreen(unusedX: Int, unusedY: Int, partialTicks: Float) { + super.drawScreen(unusedX, unusedY, partialTicks) + drawDefaultBackground() + screenHeight = height + guiLeft = (width - sizeX) / 2 + guiTop = (height - sizeY) / 2 + + mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth + mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1 + + GlStateManager.pushMatrix() + drawRect(guiLeft, guiTop, guiLeft + sizeX, guiTop + sizeY, 0x50000000) + val scale = 0.75f + val inverseScale = 1 / scale + + if (!currentlyEditing) { + val adjustedY = guiTop + 30 + pageScroll + var toRemove = -1 + + val x = guiLeft + 180 + val y = guiTop + 170 + + GuiRenderUtils.drawStringCentered("§aAdd New", x, y) + val colour = + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x - 30, y - 10, 60, 20)) 0x50828282 else 0x50303030 + drawRect(x - 30, y - 10, x + 30, y + 10, colour) + + GlStateManager.scale(scale, scale, 1f) + + GuiRenderUtils.drawStringCentered( + "§7Modify Words. Replaces the top with the bottom", + (guiLeft + 180) * inverseScale, + (guiTop + 9) * inverseScale + ) + GuiRenderUtils.drawString("§bPhrase", (guiLeft + 30) * inverseScale, (guiTop + 5) * inverseScale) + GuiRenderUtils.drawString("§1Status", (guiLeft + 310) * inverseScale, (guiTop + 5) * inverseScale) + + for ((index, phrase) in modifiedWords.withIndex()) { + if (adjustedY + 30 * index < guiTop + 20) continue + if (adjustedY + 30 * index > guiTop + 125) continue + + if (phrase.phrase == "" && phrase.replacement == "") { + toRemove = index + } + + var inBox = false + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, guiLeft, adjustedY + 30 * index, sizeX, 30)) inBox = true + + GuiRenderUtils.drawString("${index + 1}.", (guiLeft + 5) * inverseScale, (adjustedY + 10 + 30 * index) * inverseScale) + + if (GuiRenderUtils.isPointInRect(lastClickedWidth, lastClickedHeight, guiLeft + 335, adjustedY + 30 * index + 7, 16, 16)) { + lastClickedWidth = 0 + lastClickedHeight = 0 + phrase.enabled = !phrase.enabled + saveChanges() + SoundUtils.playClickSound() + } else if (GuiRenderUtils.isPointInRect(lastClickedWidth, lastClickedHeight, guiLeft + 295, + adjustedY + 30 * index + 7, 16, 16) && index != 0) { + lastClickedWidth = 0 + lastClickedHeight = 0 + SoundUtils.playClickSound() + changedIndex = index + changedAction = "up" + } else if (GuiRenderUtils.isPointInRect(lastClickedWidth, lastClickedHeight, guiLeft + 315, + adjustedY + 30 * index + 7, 16, 16) && index != modifiedWords.size - 1) { + lastClickedWidth = 0 + lastClickedHeight = 0 + SoundUtils.playClickSound() + changedIndex = index + changedAction = "down" + } else if (GuiRenderUtils.isPointInRect(lastClickedWidth, lastClickedHeight, guiLeft, adjustedY + 30 * index, sizeX, 30)) { + lastClickedWidth = 0 + lastClickedHeight = 0 + SoundUtils.playClickSound() + currentlyEditing = true + currentIndex = index + } + + if (inBox) { + GuiRenderUtils.drawScaledRec(guiLeft, adjustedY + 30 * index, guiLeft + sizeX, adjustedY + 30 * index + 30, 0x50303030, inverseScale) + } + + val statusBlock = if (phrase.enabled) { + ItemStack(Blocks.stained_hardened_clay, 1, 13) + } else { + ItemStack(Blocks.stained_hardened_clay, 1, 14) + } + + GlStateManager.scale(inverseScale, inverseScale, 1f) + + if (index != 0) { + val skullItem = ItemUtils.createSkull("Up", "7f68dd73-1ff6-4193-b246-820975d6fab1", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzczMzRjZGRmYWI0NWQ3NWFkMjhlMWE0N2JmOGNmNTAxN2QyZjA5ODJmNjczN2RhMjJkNDk3Mjk1MjUxMDY2MSJ9fX0=") + GuiRenderUtils.renderItemAndBackground(skullItem, guiLeft + 295, adjustedY + 30 * index + 7, 0x50828282) + } + if (index != modifiedWords.size - 1) { + val skullItem = ItemUtils.createSkull("Down", "e4ace6de-0629-4719-aea3-3e113314dd3f", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTc3NDIwMzRmNTlkYjg5MGM4MDA0MTU2YjcyN2M3N2NhNjk1YzQzOTlkOGUwZGE1Y2U5MjI3Y2Y4MzZiYjhlMiJ9fX0=") + GuiRenderUtils.renderItemAndBackground(skullItem, guiLeft + 315, adjustedY + 30 * index + 7, 0x50828282) + } + + GuiRenderUtils.renderItemAndBackground(statusBlock, guiLeft + 335, adjustedY + 30 * index + 7, 0x50828282) + + GlStateManager.scale(scale, scale, 1f) + + if (inBox) { + GuiRenderUtils.drawString(phrase.phrase, (guiLeft + 15) * inverseScale, (adjustedY + 5 + 30 * index) * inverseScale) + GuiRenderUtils.drawString(phrase.replacement, (guiLeft + 15) * inverseScale, (adjustedY + 15 + 30 * index) * inverseScale) + } else { + GuiRenderUtils.drawString(phrase.phrase.convertToFormatted(), (guiLeft + 15) * inverseScale, (adjustedY + 5 + 30 * index) * inverseScale) + GuiRenderUtils.drawString(phrase.replacement.convertToFormatted(), (guiLeft + 15) * inverseScale, (adjustedY + 15 + 30 * index) * inverseScale) + } + } + + if (modifiedWords.size < 1) { + modifiedWords = SkyHanniMod.feature.storage.modifiedWords + } + + if (toRemove != -1) { + modifiedWords.removeAt(toRemove) + saveChanges() + } + + GlStateManager.scale(inverseScale, inverseScale, 1f) + + scrollScreen() + } + else { + val x = guiLeft + 180 + var y = guiTop + 140 + GuiRenderUtils.drawStringCentered("§cDelete", x, y) + var colour = if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x - 30, y - 10, 60, 20)) 0x50828282 else 0x50303030 + drawRect(x - 30, y - 10, x + 30, y + 10, colour) + y += 30 + GuiRenderUtils.drawStringCentered("§eBack", x, y) + colour = if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x - 30, y - 10, 60, 20)) 0x50828282 else 0x50303030 + drawRect(x - 30, y - 10, x + 30, y + 10, colour) + + if (currentIndex < modifiedWords.size && currentIndex != -1) { + y -= 150 + val currentPhrase = modifiedWords[currentIndex] + val status = if (currentPhrase.enabled) "§2Enabled" else "§4Disabled" + GuiRenderUtils.drawStringCentered(status, x, y) + colour = if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x - 30, y - 10, 60, 20)) 0x50828282 else 0x50303030 + drawRect(x - 30, y - 10, x + 30, y + 10, colour) + + GuiRenderUtils.drawString("§bIs replaced by:", guiLeft + 30, guiTop + 75) + + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, guiLeft, guiTop + 35, sizeX, 30)) { + drawRect(guiLeft, guiTop + 35, guiLeft + sizeX, guiTop + 35 + 30, 0x50303030) + } + if (currentTextBox == "phrase") { + drawRect(guiLeft, guiTop + 35, guiLeft + sizeX, guiTop + 35 + 30, 0x50828282) + } + + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, guiLeft, guiTop + 90, sizeX, 30)) { + drawRect(guiLeft, guiTop + 90, guiLeft + sizeX, guiTop + 90 + 30, 0x50303030) + } + if (currentTextBox == "replacement") { + drawRect(guiLeft, guiTop + 90, guiLeft + sizeX, guiTop + 90 + 30, 0x50828282) + } + + GlStateManager.scale(0.75f, 0.75f, 1f) + + GuiRenderUtils.drawTwoLineString("§bThe top line of each section is the preview of the bottom text", + (guiLeft + 10) * inverseScale, (guiTop + 17) * inverseScale) + GuiRenderUtils.drawTwoLineString("§bTo get the minecraft formatting sign use \"&&\"", + (guiLeft + 220) * inverseScale, (guiTop + 17) * inverseScale) + + GuiRenderUtils.drawString(currentPhrase.phrase.convertToFormatted(), (guiLeft + 30) * inverseScale, (guiTop + 40) * inverseScale) + GuiRenderUtils.drawString(currentPhrase.phrase, (guiLeft + 30) * inverseScale, (guiTop + 55) * inverseScale) + + GuiRenderUtils.drawString(currentPhrase.replacement.convertToFormatted(), (guiLeft + 30) * inverseScale, (guiTop + 95) * inverseScale) + GuiRenderUtils.drawString(currentPhrase.replacement, (guiLeft + 30) * inverseScale, (guiTop + 110) * inverseScale) + + GlStateManager.scale(inverseScale, inverseScale, 1f) + } + } + + if (changedIndex != -1) { + if (changedAction == "up") { + if (changedIndex > 0) { + val temp = modifiedWords[changedIndex] + modifiedWords[changedIndex] = modifiedWords[changedIndex - 1] + modifiedWords[changedIndex - 1] = temp + } + } + else if (changedAction == "down") { + if (changedIndex < modifiedWords.size - 1) { + val temp = modifiedWords[changedIndex] + modifiedWords[changedIndex] = modifiedWords[changedIndex + 1] + modifiedWords[changedIndex + 1] = temp + } + } + + changedIndex = -1 + changedAction = "" + saveChanges() + } + + GlStateManager.popMatrix() + } + + override fun handleMouseInput() { + super.handleMouseInput() + + if (Mouse.getEventButtonState()) { + mouseClickEvent() + } + if (!Mouse.getEventButtonState()) { + if (Mouse.getEventDWheel() != 0) { + lastMouseScroll = Mouse.getEventDWheel() + noMouseScrollFrames = 0 + } + } + } + + @Throws(IOException::class) + fun mouseClickEvent() { + if (!currentlyEditing) { + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, guiLeft, guiTop, sizeX, sizeY - 25)) { + lastClickedWidth = mouseX + lastClickedHeight = mouseY + } + } + val x = guiLeft + 180 + var y = guiTop + 140 + if (currentlyEditing) { + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x - 30, y - 10, 60, 20)) { + SoundUtils.playClickSound() + currentlyEditing = false + modifiedWords.removeAt(currentIndex) + currentIndex = -1 + saveChanges() + currentTextBox = "" + } + if (currentIndex < modifiedWords.size && currentIndex != -1) { + y = guiTop + 20 + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x - 30, y - 10, 60, 20)) { + SoundUtils.playClickSound() + modifiedWords[currentIndex].enabled = !modifiedWords[currentIndex].enabled + saveChanges() + } else if (GuiRenderUtils.isPointInRect(mouseX, mouseY, guiLeft, guiTop + 35, sizeX, 30)) { + SoundUtils.playClickSound() + currentTextBox = "phrase" + currentText = modifiedWords[currentIndex].phrase + } else if (GuiRenderUtils.isPointInRect(mouseX, mouseY, guiLeft, guiTop + 90, sizeX, 30)) { + SoundUtils.playClickSound() + currentTextBox = "replacement" + currentText = modifiedWords[currentIndex].replacement + } else { + if (currentTextBox != "") { + SoundUtils.playClickSound() + currentTextBox = "" + } + } + } + } + y = guiTop + 170 + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x - 30, y - 10, 60, 20)) { + SoundUtils.playClickSound() + if (currentlyEditing) { + currentIndex = -1 + currentTextBox = "" + } else { + modifiedWords.add(VisualWord("", "", true)) + currentTextBox = "phrase" + currentIndex = modifiedWords.size - 1 + saveChanges() + } + currentlyEditing = !currentlyEditing + } + } + + @Throws(IOException::class) + override fun keyTyped(typedChar: Char, keyCode: Int) { + super.keyTyped(typedChar, keyCode) + if (!currentlyEditing) return + if (currentTextBox == "") return + if (currentIndex >= modifiedWords.size || currentIndex == -1) return + + if (keyCode == Keyboard.KEY_ESCAPE) { + saveTextChanges() + currentTextBox = "" + return + } + + if (keyCode == Keyboard.KEY_BACK) { + if (currentText.isNotEmpty()) { + currentText = if (KeyboardManager.isControlKeyDown()) { + "" + } else if (KeyboardManager.isShiftKeyDown()) { + val lastSpaceIndex = currentText.lastIndexOf(' ') + if (lastSpaceIndex >= 0) { + currentText.substring(0, lastSpaceIndex) + } else { + "" + } + } else { + currentText.substring(0, currentText.length - 1) + } + saveTextChanges() + } + + return + } + + if (currentText.length < maxTextLength && !Character.isISOControl(typedChar)) { + currentText += typedChar + saveTextChanges() + return + } + + if (KeyboardManager.isPastingKeysDown()) { + SkyHanniMod.coroutineScope.launch { + val clipboard = OSUtils.readFromClipboard() ?: "" + for (char in clipboard) { + if (currentText.length < maxTextLength && !Character.isISOControl(char)) { + currentText += char + } + } + saveTextChanges() + } + } + } + + private fun saveTextChanges() { + if (currentTextBox == "phrase") { + modifiedWords[currentIndex].phrase = currentText + } else if (currentTextBox == "replacement") { + modifiedWords[currentIndex].replacement = currentText + } + saveChanges() + } + + private fun scrollScreen() { + scrollVelocity += lastMouseScroll / 48.0 + scrollVelocity *= 0.95 + pageScroll += scrollVelocity.toInt() + lastMouseScroll / 24 + + noMouseScrollFrames++ + + if (noMouseScrollFrames >= maxNoInputFrames) { + scrollVelocity *= 0.75 + } + + if (pageScroll > 0) { + pageScroll = 0 + } + + pageScroll = MathHelper.clamp_int(pageScroll, -(SkyHanniMod.feature.storage.modifiedWords.size * 30 - 100), 0) + lastMouseScroll = 0 + } + + private fun saveChanges() { + ModifyVisualWords.modifiedWords = modifiedWords + ModifyVisualWords.textCache.invalidateAll() + SkyHanniMod.feature.storage.modifiedWords = modifiedWords + } +}
\ No newline at end of file |