aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt113
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt105
2 files changed, 108 insertions, 110 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
index 38da02e08..9f249ee7a 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
@@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.GuiPositionMovedEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isRancherSign
@@ -31,10 +32,15 @@ import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
-class GuiEditManager {
+@SkyHanniModule
+object GuiEditManager {
private var lastHotkeyPressed = SimpleTimeMark.farPast()
+ private var currentPositions = TimeLimitedCache<String, Position>(15.seconds)
+ private var currentBorderSize = mutableMapOf<String, Pair<Int, Int>>()
+ private var lastMovedGui: String? = null
+
@SubscribeEvent
fun onKeyClick(event: LorenzKeyPressEvent) {
if (event.keyCode != SkyHanniMod.feature.gui.keyBindOpen) return
@@ -71,77 +77,70 @@ class GuiEditManager {
}
}
- companion object {
-
- private var currentPositions = TimeLimitedCache<String, Position>(15.seconds)
- private var currentBorderSize = mutableMapOf<String, Pair<Int, Int>>()
- private var lastMovedGui: String? = null
-
- @JvmStatic
- fun add(position: Position, posLabel: String, x: Int, y: Int) {
- var name = position.internalName
- if (name == null) {
- name = if (posLabel == "none") "none " + UUID.randomUUID() else posLabel
- position.internalName = name
- }
- currentPositions[name] = position
- currentBorderSize[posLabel] = Pair(x, y)
+ @JvmStatic
+ fun add(position: Position, posLabel: String, x: Int, y: Int) {
+ var name = position.internalName
+ if (name == null) {
+ name = if (posLabel == "none") "none " + UUID.randomUUID() else posLabel
+ position.internalName = name
}
+ currentPositions[name] = position
+ currentBorderSize[posLabel] = Pair(x, y)
+ }
- private var lastHotkeyReminded = SimpleTimeMark.farPast()
-
- @JvmStatic
- fun openGuiPositionEditor(hotkeyReminder: Boolean) {
- SkyHanniMod.screenToOpen = GuiPositionEditor(
- currentPositions.values().toList(),
- 2,
- Minecraft.getMinecraft().currentScreen as? GuiContainer
+ private var lastHotkeyReminded = SimpleTimeMark.farPast()
+
+ @JvmStatic
+ fun openGuiPositionEditor(hotkeyReminder: Boolean) {
+ SkyHanniMod.screenToOpen = GuiPositionEditor(
+ currentPositions.values().toList(),
+ 2,
+ Minecraft.getMinecraft().currentScreen as? GuiContainer
+ )
+ if (hotkeyReminder && lastHotkeyReminded.passedSince() > 30.minutes) {
+ lastHotkeyReminded = SimpleTimeMark.now()
+ ChatUtils.chat(
+ "§eTo edit hidden GUI elements:\n" +
+ " §7- §e1. Set a key in /sh edit.\n" +
+ " §7- §e2. Click that key while the GUI element is visible."
)
- if (hotkeyReminder && lastHotkeyReminded.passedSince() > 30.minutes) {
- lastHotkeyReminded = SimpleTimeMark.now()
- ChatUtils.chat(
- "§eTo edit hidden GUI elements:\n" +
- " §7- §e1. Set a key in /sh edit.\n" +
- " §7- §e2. Click that key while the GUI element is visible."
- )
- }
}
+ }
- @JvmStatic
- fun renderLast() {
- if (!isInGui()) return
- if (!SkyHanniDebugsAndTests.globalRender) return
+ @JvmStatic
+ fun renderLast() {
+ if (!isInGui()) return
+ if (!SkyHanniDebugsAndTests.globalRender) return
- GlStateManager.translate(0f, 0f, 200f)
+ GlStateManager.translate(0f, 0f, 200f)
- GuiRenderEvent.GuiOverlayRenderEvent().postAndCatch()
+ GuiRenderEvent.GuiOverlayRenderEvent().postAndCatch()
- GlStateManager.pushMatrix()
- GlStateManager.enableDepth()
- GuiRenderEvent.ChestGuiOverlayRenderEvent().postAndCatch()
- GlStateManager.popMatrix()
+ GlStateManager.pushMatrix()
+ GlStateManager.enableDepth()
+ GuiRenderEvent.ChestGuiOverlayRenderEvent().postAndCatch()
+ GlStateManager.popMatrix()
- GlStateManager.translate(0f, 0f, -200f)
- }
+ GlStateManager.translate(0f, 0f, -200f)
+ }
- fun isInGui() = Minecraft.getMinecraft().currentScreen is GuiPositionEditor
+ fun isInGui() = Minecraft.getMinecraft().currentScreen is GuiPositionEditor
- fun Position.getDummySize(random: Boolean = false): Vector2i {
- if (random) return Vector2i(5, 5)
- val (x, y) = currentBorderSize[internalName] ?: return Vector2i(1, 1)
- return Vector2i((x * effectiveScale).toInt(), (y * effectiveScale).toInt())
- }
+ fun Position.getDummySize(random: Boolean = false): Vector2i {
+ if (random) return Vector2i(5, 5)
+ val (x, y) = currentBorderSize[internalName] ?: return Vector2i(1, 1)
+ return Vector2i((x * effectiveScale).toInt(), (y * effectiveScale).toInt())
+ }
- fun Position.getAbsX() = getAbsX0(getDummySize(true).x)
+ fun Position.getAbsX() = getAbsX0(getDummySize(true).x)
- fun Position.getAbsY() = getAbsY0(getDummySize(true).y)
+ fun Position.getAbsY() = getAbsY0(getDummySize(true).y)
- fun GuiProfileViewer.anyTextBoxFocused() =
- this.getPropertiesWithType<GuiElementTextField>().any { it.focus }
+ fun GuiProfileViewer.anyTextBoxFocused() =
+ this.getPropertiesWithType<GuiElementTextField>().any { it.focus }
- fun handleGuiPositionMoved(guiName: String) {
- lastMovedGui = guiName
- }
+ fun handleGuiPositionMoved(guiName: String) {
+ lastMovedGui = guiName
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
index a69210f6d..72abf6bab 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.ScoreboardChangeEvent
import at.hannibal2.skyhanni.events.ScoreboardRawChangeEvent
import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import net.minecraft.client.Minecraft
import net.minecraft.network.play.server.S3CPacketUpdateScore
@@ -14,63 +15,42 @@ import net.minecraft.scoreboard.ScorePlayerTeam
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-class ScoreboardData {
-
- companion object {
-
- private val minecraftColorCodesPattern = "(?i)[0-9a-fkmolnr]".toPattern()
-
- // TODO USE SH-REPO
- private val splitIcons = listOf(
- "\uD83C\uDF6B",
- "\uD83D\uDCA3",
- "\uD83D\uDC7D",
- "\uD83D\uDD2E",
- "\uD83D\uDC0D",
- "\uD83D\uDC7E",
- "\uD83C\uDF20",
- "\uD83C\uDF6D",
- "⚽",
- "\uD83C\uDFC0",
- "\uD83D\uDC79",
- "\uD83C\uDF81",
- "\uD83C\uDF89",
- "\uD83C\uDF82",
- "\uD83D\uDD2B",
- )
-
- fun formatLines(rawList: List<String>): List<String> {
- val list = mutableListOf<String>()
- for (line in rawList) {
- val separator = splitIcons.find { line.contains(it) } ?: continue
- val split = line.split(separator)
- val start = split[0]
- var end = split[1]
- // get last color code in start
- val lastColorIndex = start.lastIndexOf('§')
- val lastColor = if (lastColorIndex != -1
- && lastColorIndex + 1 < start.length
- && (minecraftColorCodesPattern.matches(start[lastColorIndex + 1].toString()))
- ) start.substring(lastColorIndex, lastColorIndex + 2)
- else ""
-
- // remove first color code from end, when it is the same as the last color code in start
- end = end.removePrefix(lastColor)
-
- list.add(start + end)
- }
+@SkyHanniModule
+object ScoreboardData {
- return list
- }
+ var sidebarLinesFormatted: List<String> = emptyList()
- var sidebarLinesFormatted: List<String> = emptyList()
+ private var sidebarLines: List<String> = emptyList() // TODO rename to raw
+ var sidebarLinesRaw: List<String> = emptyList() // TODO delete
+ var objectiveTitle = ""
- var sidebarLines: List<String> = emptyList() // TODO rename to raw
- var sidebarLinesRaw: List<String> = emptyList() // TODO delete
- var objectiveTitle = ""
- }
+ private var dirty = false
+
+ private val minecraftColorCodesPattern = "(?i)[0-9a-fkmolnr]".toPattern()
+
+ fun formatLines(rawList: List<String>): List<String> {
+ val list = mutableListOf<String>()
+ for (line in rawList) {
+ val separator = splitIcons.find { line.contains(it) } ?: continue
+ val split = line.split(separator)
+ val start = split[0]
+ var end = split[1]
+ // get last color code in start
+ val lastColorIndex = start.lastIndexOf('§')
+ val lastColor = if (lastColorIndex != -1
+ && lastColorIndex + 1 < start.length
+ && (minecraftColorCodesPattern.matches(start[lastColorIndex + 1].toString()))
+ ) start.substring(lastColorIndex, lastColorIndex + 2)
+ else ""
- var dirty = false
+ // remove first color code from end, when it is the same as the last color code in start
+ end = end.removePrefix(lastColor)
+
+ list.add(start + end)
+ }
+
+ return list
+ }
@HandleEvent(receiveCancelled = true)
fun onPacketReceive(event: PacketReceivedEvent) {
@@ -127,4 +107,23 @@ class ScoreboardData {
ScorePlayerTeam.formatPlayerName(scoreboard.getPlayersTeam(it.playerName), it.playerName)
}
}
+
+ // TODO USE SH-REPO
+ private val splitIcons = listOf(
+ "\uD83C\uDF6B",
+ "\uD83D\uDCA3",
+ "\uD83D\uDC7D",
+ "\uD83D\uDD2E",
+ "\uD83D\uDC0D",
+ "\uD83D\uDC7E",
+ "\uD83C\uDF20",
+ "\uD83C\uDF6D",
+ "⚽",
+ "\uD83C\uDFC0",
+ "\uD83D\uDC79",
+ "\uD83C\uDF81",
+ "\uD83C\uDF89",
+ "\uD83C\uDF82",
+ "\uD83D\uDD2B",
+ )
}