diff options
17 files changed, 631 insertions, 16 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 4e4cbc68d..c2cf5a25d 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -220,6 +220,7 @@ import at.hannibal2.skyhanni.features.misc.trevor.TrevorFeatures import at.hannibal2.skyhanni.features.misc.trevor.TrevorSolver import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker import at.hannibal2.skyhanni.features.misc.update.UpdateManager +import at.hannibal2.skyhanni.features.misc.visualwords.ModifyVisualWords import at.hannibal2.skyhanni.features.mobs.AreaMiniBossFeatures import at.hannibal2.skyhanni.features.mobs.AshfangMinisNametagHider import at.hannibal2.skyhanni.features.mobs.MobHighlight @@ -585,6 +586,7 @@ class SkyHanniMod { loadModule(CosmeticFollowingLine()) loadModule(SuperpairsClicksAlert()) loadModule(PowderTracker()) + loadModule(ModifyVisualWords) loadModule(TabListReader) loadModule(TabListRenderer) loadModule(GlowingDroppedItems()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index a80211e3a..9f1455605 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.features.misc.FrozenTreasure; import at.hannibal2.skyhanni.features.misc.ghostcounter.GhostData; import at.hannibal2.skyhanni.features.misc.powdertracker.PowderChestReward; import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker; +import at.hannibal2.skyhanni.features.misc.visualwords.VisualWord; import at.hannibal2.skyhanni.features.rift.area.westvillage.KloonTerminal; import at.hannibal2.skyhanni.utils.LorenzVec; import at.hannibal2.skyhanni.utils.NEUInternalName; @@ -37,6 +38,9 @@ public class Storage { public Map<Long, List<CropType>> gardenJacobFarmingContestTimes = new HashMap<>(); @Expose + public List<VisualWord> modifiedWords = new ArrayList<>(); + + @Expose public Boolean contestSendingAsked = false; @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 7d21fa92e..57f95b56b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -28,6 +28,7 @@ import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager import at.hannibal2.skyhanni.features.misc.ghostcounter.GhostUtil import at.hannibal2.skyhanni.features.misc.massconfiguration.DefaultConfigFeatures +import at.hannibal2.skyhanni.features.misc.visualwords.VisualWordGui import at.hannibal2.skyhanni.features.slayer.SlayerItemProfitTracker import at.hannibal2.skyhanni.test.PacketTest import at.hannibal2.skyhanni.test.SkyHanniConfigSearchResetCommand @@ -277,6 +278,7 @@ object Commands { // "shsendtranslation", // "Respond with a translation of the message that the user clicks" // ) { Translator.toEnglish(it) } + registerCommand("shwords", "Opens the config list for modifying visual words") { openVisualWords() } } private fun commandHelp(args: Array<String>) { @@ -325,6 +327,15 @@ object Commands { } } + @JvmStatic + fun openVisualWords() { + if (!LorenzUtils.onHypixel) { + LorenzUtils.chat("§cYou need to join Hypixel to use this feature!") + } else { + SkyHanniMod.screenToOpen = VisualWordGui() + } + } + private fun clearFarmingItems() { val config = GardenAPI.config?.fortune ?: return LorenzUtils.chat("§e[SkyHanni] clearing farming items") diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/GUIConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/GUIConfig.java index ed365809c..47b62e9e5 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/GUIConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/GUIConfig.java @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.config.features; import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.commands.Commands; import at.hannibal2.skyhanni.config.core.config.Position; import at.hannibal2.skyhanni.data.GuiEditManager; import com.google.gson.annotations.Expose; @@ -30,6 +31,32 @@ public class GUIConfig { @ConfigEditorSlider(minValue = 0.1F, maxValue = 10, minStep = 0.05F) public float globalScale = 1F; + + @Expose + @ConfigOption(name = "Modify Visual Words", desc = "") + @Accordion + public ModifyWords modifyWords = new ModifyWords(); + + public static class ModifyWords { + + @Expose + @ConfigOption(name = "Enabled", desc = "Enables replacing all instances of a word or phrase with another word or phrase.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Work Outside SkyBlock", desc = "Allows modifying visual words anywhere on Hypixel.") + @ConfigEditorBoolean + @FeatureToggle + public boolean workOutside = false; + + @ConfigOption(name = "Open Config", desc = "Opens the menu to setup the visual words.\n§eCommand: /shwords") + @ConfigEditorButton(buttonText = "Open") + public Runnable open = Commands::openVisualWords; + + } + @Expose @ConfigOption(name = "Custom Text Box", desc = "") @Accordion diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java index 2bb959f44..a74895a7f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java @@ -1270,7 +1270,7 @@ public class GardenConfig { @ConfigOption(name = "Farming Fortune Guide", desc = "Opens a guide that breaks down your Farming Fortune.\n§eCommand: /ff") @ConfigEditorButton(buttonText = "Open") - public Runnable positions = Commands::openFortuneGuide; + public Runnable open = Commands::openFortuneGuide; @Expose public Position farmingFortunePos = new Position(5, -180, false, true); diff --git a/src/main/java/at/hannibal2/skyhanni/data/RenderData.kt b/src/main/java/at/hannibal2/skyhanni/data/RenderData.kt index 9688add2c..0137c4491 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/RenderData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/RenderData.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests +import at.hannibal2.skyhanni.features.misc.visualwords.VisualWordGui import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.gui.inventory.GuiInventory @@ -19,7 +20,7 @@ class RenderData { fun onRenderOverlay(event: RenderGameOverlayEvent.Pre) { if (event.type != RenderGameOverlayEvent.ElementType.HOTBAR) return if (!SkyHanniDebugsAndTests.globalRender) return - if (GuiEditManager.isInGui() || FFGuideGUI.isInGui()) return + if (GuiEditManager.isInGui() || FFGuideGUI.isInGui() || VisualWordGui.isInGui()) return GuiRenderEvent.GuiOverlayRenderEvent().postAndCatch() } @@ -27,7 +28,7 @@ class RenderData { @SubscribeEvent fun onBackgroundDraw(event: GuiScreenEvent.BackgroundDrawnEvent) { if (!SkyHanniDebugsAndTests.globalRender) return - if (GuiEditManager.isInGui() || FFGuideGUI.isInGui()) return + if (GuiEditManager.isInGui() || FFGuideGUI.isInGui() || VisualWordGui.isInGui()) return val currentScreen = Minecraft.getMinecraft().currentScreen ?: return if (currentScreen !is GuiInventory && currentScreen !is GuiChest) return 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) + } + |
