diff options
Diffstat (limited to 'src')
6 files changed, 117 insertions, 38 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt index 1e20b01..2cd4418 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt @@ -20,6 +20,9 @@ data class ChatTab( @SerializedName("ignore_ends") val ignoreEndsWith: List<String>?, @SerializedName("ignore_equals") val ignoreEquals: List<String>?, @SerializedName("ignore_regex") val uncompiledIgnoreRegex: List<String>?, + val color: Int?, + @SerializedName("hovered_color") val hoveredColor: Int?, + @SerializedName("selected_color") val selectedColor: Int?, val prefix: String, ) { lateinit var button: TabButton diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt index ec9dfc8..99a8999 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt @@ -1,6 +1,7 @@ package cc.woverflow.chatting.chat import cc.woverflow.chatting.Chatting +import cc.woverflow.chatting.gui.components.TabButton import com.google.gson.GsonBuilder import com.google.gson.JsonArray import com.google.gson.JsonObject @@ -43,16 +44,26 @@ object ChatTabs { chatTabJson.tabs.forEach { applyVersion2Changes(it.asJsonObject) applyVersion3Changes(it.asJsonObject) + applyVersion4Changes(it.asJsonObject) } - chatTabJson.version = 3 + chatTabJson.version = ChatTabsJson.VERSION tabFile.writeText(chatTabJson.toString()) } 2 -> { - // ver 2 adds `enabled` + // ver 3 adds ignore_ chatTabJson.tabs.forEach { applyVersion3Changes(it.asJsonObject) + applyVersion4Changes(it.asJsonObject) + } + chatTabJson.version = ChatTabsJson.VERSION + tabFile.writeText(chatTabJson.toString()) + } + 3 -> { + // ver 4 adds color options + chatTabJson.tabs.forEach { + applyVersion4Changes(it.asJsonObject) } - chatTabJson.version = 3 + chatTabJson.version = ChatTabsJson.VERSION tabFile.writeText(chatTabJson.toString()) } } @@ -86,6 +97,12 @@ object ChatTabs { json.add("ignore_regex", JsonArray()) } + private fun applyVersion4Changes(json: JsonObject) { + json.addProperty("color", TabButton.color) + json.addProperty("hovered_color", TabButton.hoveredColor) + json.addProperty("selected_color", TabButton.selectedColor) + } + fun shouldRender(message: IChatComponent): Boolean { return currentTab?.shouldRender(message) ?: true } @@ -95,12 +112,30 @@ object ChatTabs { val jsonObject = JsonObject() val defaultTabs = generateDefaultTabs() jsonObject.add("tabs", defaultTabs) - jsonObject.addProperty("version", 3) + jsonObject.addProperty("version", ChatTabsJson.VERSION) tabFile.writeText(jsonObject.toString()) } private fun generateDefaultTabs(): JsonArray { - val all = ChatTab(true, "ALL", false, null, null, null, null, null, null, null, null, null, null, "") + val all = ChatTab( + true, + "ALL", + false, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + TabButton.color, + TabButton.hoveredColor, + TabButton.selectedColor, + "" + ) val party = ChatTab( true, "PARTY", @@ -164,6 +199,9 @@ object ChatTabs { null, null, null, + TabButton.color, + TabButton.hoveredColor, + TabButton.selectedColor, "/pc " ) val guild = ChatTab( @@ -180,6 +218,9 @@ object ChatTabs { null, null, null, + TabButton.color, + TabButton.hoveredColor, + TabButton.selectedColor, "/gc " ) val pm = ChatTab( @@ -196,6 +237,9 @@ object ChatTabs { null, null, null, + TabButton.color, + TabButton.hoveredColor, + TabButton.selectedColor, "/r " ) tabs.add(all) diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt index e37ef7f..6954b8e 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt @@ -3,9 +3,13 @@ package cc.woverflow.chatting.chat import com.google.gson.JsonArray import com.google.gson.annotations.SerializedName -data class ChatTabsJson(@SerializedName("tabs") val tabs: JsonArray, @SerializedName("version") var version: Int) { +data class ChatTabsJson(@SerializedName("tabs") val tabs: JsonArray, var version: Int) { override fun toString(): String { - return "{\"tabs\": $tabs, \"version\": \"$version\"}" + return "{\"tabs\": $tabs, \"version\": $version}" + } + + companion object { + const val VERSION = 4 } }
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt index 6c09731..223de76 100644 --- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt @@ -5,6 +5,8 @@ import cc.woverflow.chatting.chat.ChatShortcuts import cc.woverflow.chatting.chat.ChatTab import cc.woverflow.chatting.chat.ChatTabs import cc.woverflow.chatting.gui.ChatShortcutViewGui +import cc.woverflow.chatting.gui.components.TabButton +import cc.woverflow.onecore.utils.openScreen import gg.essential.api.EssentialAPI import gg.essential.vigilance.Vigilant import gg.essential.vigilance.data.Category @@ -14,7 +16,8 @@ import gg.essential.vigilance.data.SortingBehavior import java.awt.Color import java.io.File -object ChattingConfig : Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), Chatting.NAME, sortingBehavior = ConfigSorting) { +object ChattingConfig : + Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), Chatting.NAME, sortingBehavior = ConfigSorting) { @Property( type = PropertyType.SELECTOR, @@ -106,11 +109,7 @@ object ChattingConfig : Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), C name = "Screenshot Mode", description = "The mode in which screenshotting will work.", category = "Screenshotting", - options = [ - "Save To System", - "Add To Clipboard", - "Both" - ] + options = ["Save To System", "Add To Clipboard", "Both"] ) var copyMode = 0 @@ -123,10 +122,7 @@ object ChattingConfig : Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), C var chatSearch = true @Property( - type = PropertyType.SWITCH, - name = "Chat Tabs", - description = "Add chat tabs.", - category = "Tabs" + type = PropertyType.SWITCH, name = "Chat Tabs", description = "Add chat tabs.", category = "Tabs" ) var chatTabs = true get() { @@ -147,10 +143,7 @@ object ChattingConfig : Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), C var hypixelOnlyChatTabs = true @Property( - type = PropertyType.SWITCH, - name = "Chat Shortcuts", - description = "Add chat shortcuts.", - category = "Shortcuts" + type = PropertyType.SWITCH, name = "Chat Shortcuts", description = "Add chat shortcuts.", category = "Shortcuts" ) var chatShortcuts = false get() { @@ -176,9 +169,7 @@ object ChattingConfig : Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), C description = "Edit chat shortcuts.", category = "Shortcuts" ) - fun openChatShortcutsGUI() { - EssentialAPI.getGuiUtil().openScreen(ChatShortcutViewGui()) - } + fun openChatShortcutsGUI() = ChatShortcutViewGui().openScreen() init { initialize() @@ -186,7 +177,25 @@ object ChattingConfig : Vigilant(File(Chatting.modDir, "${Chatting.ID}.toml"), C chatTabs = funny ChatTabs.initialize() if (!funny) { - val dummy = ChatTab(true, "ALL", false, null, null, null, null, null, null, null, null, null, null, "") + val dummy = ChatTab( + true, + "ALL", + false, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + TabButton.color, + TabButton.hoveredColor, + TabButton.selectedColor, + "" + ) dummy.initialize() ChatTabs.currentTab = dummy } else { diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt index 9863936..1d8d8ce 100644 --- a/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt +++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt @@ -14,7 +14,17 @@ import java.awt.Color * https://github.com/P0keDev/ChatShortcuts/blob/master/LICENSE * @author P0keDev */ -open class CleanButton(buttonId: Int, private val x: () -> Int, private val y: () -> Int, widthIn: Int, heightIn: Int, name: String, private val renderType: () -> RenderType) : +open class CleanButton(buttonId: Int, private val x: () -> Int, private val y: () -> Int, widthIn: Int, heightIn: Int, name: String, private val renderType: () -> RenderType, private val textColor: (packedFGColour: Int, enabled: Boolean, hovered: Boolean) -> Int = { packedFGColour: Int, enabled: Boolean, hovered: Boolean -> + var j = 14737632 + if (packedFGColour != 0) { + j = packedFGColour + } else if (!enabled) { + j = 10526880 + } else if (hovered) { + j = 16777120 + } + j +}) : GuiButton(buttonId, x.invoke(), 0, widthIn, heightIn, name) { open fun isEnabled(): Boolean { @@ -36,8 +46,8 @@ open class CleanButton(buttonId: Int, private val x: () -> Int, private val y: ( override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { enabled = isEnabled() - xPosition = x.invoke() - yPosition = y.invoke() + xPosition = x() + yPosition = y() if (visible) { val fontrenderer = mc.fontRendererObj GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f) @@ -53,15 +63,8 @@ open class CleanButton(buttonId: Int, private val x: () -> Int, private val y: ( ) } mouseDragged(mc, mouseX, mouseY) - var j = 14737632 - if (packedFGColour != 0) { - j = packedFGColour - } else if (!enabled) { - j = 10526880 - } else if (hovered) { - j = 16777120 - } - when (renderType.invoke()) { + val j = textColor(packedFGColour, enabled, hovered) + when (renderType()) { RenderType.NONE, RenderType.SHADOW -> { drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, j) } diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt index 25190e1..da20eed 100644 --- a/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt +++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt @@ -8,7 +8,17 @@ import gg.essential.universal.UResolution class TabButton(buttonId: Int, x: Int, widthIn: Int, heightIn: Int, private val chatTab: ChatTab) : CleanButton(buttonId, { x }, { UResolution.scaledHeight - 26 - }, widthIn, heightIn, chatTab.name, { RenderType.values()[ChattingConfig.textRenderType] }) { + }, widthIn, heightIn, chatTab.name, { RenderType.values()[ChattingConfig.textRenderType] }, { packedFGColour: Int, enabled: Boolean, hovered: Boolean -> + var j = chatTab.color ?: color + if (packedFGColour != 0) { + j = packedFGColour + } else if (!enabled) { + j = chatTab.selectedColor ?: selectedColor + } else if (hovered) { + j = chatTab.hoveredColor ?: hoveredColor + } + j + }) { override fun onMousePress() { ChatTabs.currentTab = chatTab @@ -17,4 +27,10 @@ class TabButton(buttonId: Int, x: Int, widthIn: Int, heightIn: Int, private val override fun isEnabled(): Boolean { return chatTab != ChatTabs.currentTab } + + companion object { + const val color: Int = 14737632 + const val hoveredColor: Int = 16777120 + const val selectedColor: Int = 10526880 + } }
\ No newline at end of file |