aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorNopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>2024-08-26 20:11:32 +1000
committerGitHub <noreply@github.com>2024-08-26 12:11:32 +0200
commit78e5046355d1047e1988b19eaadf155caae159f1 (patch)
tree61476fed76135a763cd21ce87d46d276f753ce07 /src/main/java/at
parentf9f271831ba80631e73d5f5c2e44c297552af9cc (diff)
downloadskyhanni-78e5046355d1047e1988b19eaadf155caae159f1.tar.gz
skyhanni-78e5046355d1047e1988b19eaadf155caae159f1.tar.bz2
skyhanni-78e5046355d1047e1988b19eaadf155caae159f1.zip
Feature: Made dye hex code show actual colour (#2321)
Co-authored-by: ItsEmpa <itsempa@users.noreply.github.com> Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/ColorHexInLore.kt63
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemCategory.kt2
4 files changed, 73 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
index e7609135e..f66f784c2 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java
@@ -264,4 +264,10 @@ public class InventoryConfig {
@ConfigEditorBoolean
@FeatureToggle
public boolean stonkOfStonkPrice = true;
+
+ @Expose
+ @ConfigOption(name = "Show hex as actual color", desc = "Changes the color of hex codes to the actual color.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean hexAsColorInLore = true;
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ColorHexInLore.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ColorHexInLore.kt
new file mode 100644
index 000000000..8767b3d2d
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ColorHexInLore.kt
@@ -0,0 +1,63 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.api.event.HandleEvent
+import at.hannibal2.skyhanni.events.item.ItemHoverEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.utils.ColorUtils
+import at.hannibal2.skyhanni.utils.ExtendedChatColor
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemCategory
+import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+
+@SkyHanniModule
+object ColorHexInLore {
+
+ private val patternGroup = RepoPattern.group("color.item.hex.lore")
+
+ /**
+ * REGEX-TEST: §5§o§7to §4#960018§7!
+ * REGEX-TEST: §8Hex #F56FA1
+ * REGEX-TEST: Color: #1793C4
+ */
+ private val hexPattern by patternGroup.pattern(
+ "code",
+ ".*(?:Color:|Hex|to) (?:§.)?(?<hex>#[0-9a-fA-F]{1,6}).*",
+ )
+
+ /**
+ * REGEX-TEST: §5§o§7between §9#034150§7 and §9#009295§7!
+ */
+ private val doubleHexPattern by patternGroup.pattern(
+ "code.animated",
+ ".*(?<hexfirst>#[0-9a-fA-F]{6})§. and §.(?<hexsecond>#[0-9a-fA-F]{6})§.!",
+ )
+
+ @HandleEvent(onlyOnSkyblock = true)
+ fun onTooltip(event: ItemHoverEvent) {
+ if (!isEnabled()) return
+ val itemCategory = event.itemStack.getItemCategoryOrNull()
+ if (itemCategory != ItemCategory.DYE &&
+ itemCategory !in ItemCategory.armor &&
+ !InventoryUtils.openInventoryName().startsWith("Dye")
+ ) return
+
+ event.toolTip = event.toolTip.map {
+ doubleHexPattern.matchMatcher(it) {
+ it.replaceColor(group("hexfirst")).replaceColor(group("hexsecond"))
+ } ?: hexPattern.matchMatcher(it) {
+ it.replaceColor(group("hex"))
+ } ?: it
+
+ }.toMutableList()
+ }
+
+ private fun String.replaceColor(hexCode: String) = replace(hexCode, addColor(hexCode))
+
+ private fun addColor(hexFirst: String): String = ExtendedChatColor(ColorUtils.getColorFromHex(hexFirst), false).toString() + hexFirst
+
+ fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.inventory.hexAsColorInLore
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt
index b2057d339..7b941aebe 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt
@@ -37,4 +37,6 @@ object ColorUtils {
fun Color.withAlpha(alpha: Int): Int = (alpha.coerceIn(0, 255) shl 24) or (this.rgb and 0x00ffffff)
fun Color.addAlpha(alpha: Int): Color = Color(red, green, blue, alpha)
+
+ fun getColorFromHex(hex: String): Int = runCatching { Color(Integer.decode(hex)) }.getOrNull()?.rgb ?: 0
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemCategory.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemCategory.kt
index 4549e2be2..8fa41978e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemCategory.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemCategory.kt
@@ -63,5 +63,7 @@ enum class ItemCategory {
stack?.getItemCategoryOrNull()?.let { this.contains(it) } ?: false
val miningTools = listOf(PICKAXE, DRILL, GAUNTLET)
+
+ val armor = setOf(HELMET, CHESTPLATE, LEGGINGS, BOOTS)
}
}