diff options
author | HiZe_ <superhize@hotmail.com> | 2023-11-03 19:07:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-03 19:07:00 +0100 |
commit | 915229c4bd5621ba3e2118f723797fa16846c827 (patch) | |
tree | 0918c2e74bebb73e2cbc3635377bcf58c9175994 /src/main/java/at/hannibal2 | |
parent | 6d3b19227177702b6c809dc305b496f68878d474 (diff) | |
download | skyhanni-915229c4bd5621ba3e2118f723797fa16846c827.tar.gz skyhanni-915229c4bd5621ba3e2118f723797fa16846c827.tar.bz2 skyhanni-915229c4bd5621ba3e2118f723797fa16846c827.zip |
Import VisualWords from SBE (#609)
Added support to import SBE Visual Words into SkyHanni. #609
Diffstat (limited to 'src/main/java/at/hannibal2')
3 files changed, 64 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index a63477a07..951e80ebf 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -44,6 +44,9 @@ public class Storage { public List<VisualWord> modifiedWords = new ArrayList<>(); @Expose + public boolean visualWordsImported = false; + + @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 82318656a..da75c9cc6 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -368,6 +368,7 @@ object Commands { if (!LorenzUtils.onHypixel) { LorenzUtils.chat("§cYou need to join Hypixel to use this feature!") } else { + if (VisualWordGui.sbeConfigPath.exists()) VisualWordGui.drawImport = true SkyHanniMod.screenToOpen = VisualWordGui() } } @@ -388,7 +389,7 @@ object Commands { name: String, description: String, function: (Array<String>) -> Unit, - autoComplete: ((Array<String>) -> List<String>) = { listOf() } + autoComplete: ((Array<String>) -> List<String>) = { listOf() }, ) { val command = SimpleCommand( name, 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 index 6e9ef14cc..4e845a313 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt @@ -1,8 +1,12 @@ package at.hannibal2.skyhanni.features.misc.visualwords import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.LorenzUtils.chat import at.hannibal2.skyhanni.utils.StringUtils.convertToFormatted +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import com.google.gson.JsonObject import kotlinx.coroutines.launch import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiScreen @@ -12,6 +16,8 @@ import net.minecraft.item.ItemStack import net.minecraft.util.MathHelper import org.lwjgl.input.Keyboard import org.lwjgl.input.Mouse +import java.io.File +import java.io.FileReader import java.io.IOException open class VisualWordGui : GuiScreen() { @@ -44,8 +50,12 @@ open class VisualWordGui : GuiScreen() { private var modifiedWords = mutableListOf<VisualWord>() + private val shouldDrawImport get() = drawImport && !SkyHanniMod.feature.storage.visualWordsImported + companion object { fun isInGui() = Minecraft.getMinecraft().currentScreen is VisualWordGui + var sbeConfigPath = File("." + File.separator + "config" + File.separator + "SkyblockExtras.cfg") + var drawImport = false } override fun drawScreen(unusedX: Int, unusedY: Int, partialTicks: Float) { @@ -75,6 +85,15 @@ open class VisualWordGui : GuiScreen() { 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 (shouldDrawImport){ + val importX = guiLeft + sizeX - 45 + val importY = guiTop + sizeY - 10 + GuiRenderUtils.drawStringCentered("§aImport from SBE", importX, importY) + val importColor = + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, importX - 45, importY - 10, 90, 20)) 0x50828282 else 0x50303030 + drawRect(importX - 45, importY - 10, importX + 45, importY + 10, importColor) + } + GlStateManager.scale(scale, scale, 1f) drawUnmodifiedStringCentered( @@ -346,6 +365,14 @@ open class VisualWordGui : GuiScreen() { } currentlyEditing = !currentlyEditing } + if (shouldDrawImport){ + val importX = guiLeft + sizeX - 45 + val importY = guiTop + sizeY - 10 + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, importX - 45, importY - 10, 90, 20)) { + SoundUtils.playClickSound() + tryImport() + } + } } @Throws(IOException::class) @@ -452,6 +479,37 @@ open class VisualWordGui : GuiScreen() { SkyHanniMod.feature.storage.modifiedWords = modifiedWords } + private fun tryImport() { + if (drawImport) { + val json = ConfigManager.gson.fromJson( + FileReader(sbeConfigPath), + JsonObject::class.java + ) + var importedWords = 0 + var skippedWords = 0 + val lists = json["custom"].asJsonObject["visualWords"].asJsonArray + loop@ for (line in lists) { + "(?<from>.*)@-(?<to>.*)@:-(?<state>false|true)".toPattern().matchMatcher(line.asString) { + val from = group("from") + val to = group("to") + val state = group("state").toBoolean() + + if (modifiedWords.any { it.phrase == from }) { + skippedWords++ + continue@loop + } + + modifiedWords.add(VisualWord(from.replace("&", "&&"), to.replace("&", "&&"), state, false)) + importedWords++ + } + } + if (importedWords > 0 || skippedWords > 0) { + chat("§e[SkyHanni] §aSuccessfully imported §e$importedWords §aand skipped §e$skippedWords §aVisualWords from SkyBlockExtras !") + SkyHanniMod.feature.storage.visualWordsImported = true + drawImport = false + } + } + } private fun drawUnmodifiedString(str: String, x: Float, y: Float) { GuiRenderUtils.drawString("§§$str", x, y) } @@ -479,4 +537,4 @@ private enum class SelectedTextBox { PHRASE, REPLACEMENT, NONE -}
\ No newline at end of file +} |