aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-03-12 15:43:15 +0700
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-03-12 15:43:15 +0700
commiteece3cb994280498d2a9c259030cc79a4be3fce3 (patch)
treee23c8d6a1c2553d2511630012f275ffa15ebf532
parent380e0adb5ef1401dd8cbf70b2ef7bc121c371c42 (diff)
downloadChatting-eece3cb994280498d2a9c259030cc79a4be3fce3.tar.gz
Chatting-eece3cb994280498d2a9c259030cc79a4be3fce3.tar.bz2
Chatting-eece3cb994280498d2a9c259030cc79a4be3fce3.zip
color property
-rw-r--r--docs/chattabs.md28
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt3
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt54
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt8
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt45
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt27
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt18
7 files changed, 143 insertions, 40 deletions
diff --git a/docs/chattabs.md b/docs/chattabs.md
index 6caeaaf..2c8ca9a 100644
--- a/docs/chattabs.md
+++ b/docs/chattabs.md
@@ -12,6 +12,9 @@ something like this:
"enabled": true,
"name": "ALL",
"unformatted": false,
+ "color": 14737632,
+ "hovered_color": 16777120,
+ "selected_color": 10526880,
"prefix": ""
},
{
@@ -78,6 +81,9 @@ something like this:
"§cThis party is currently muted\\.§r",
"(§r)*(§9P §8>)+(.*)"
],
+ "color": 14737632,
+ "hovered_color": 16777120,
+ "selected_color": 10526880,
"prefix": "/pc "
},
{
@@ -88,6 +94,9 @@ something like this:
"Guild >",
"G >"
],
+ "color": 14737632,
+ "hovered_color": 16777120,
+ "selected_color": 10526880,
"prefix": "/gc "
},
{
@@ -98,15 +107,19 @@ something like this:
"To ",
"From "
],
+ "color": 14737632,
+ "hovered_color": 16777120,
+ "selected_color": 10526880,
"prefix": "/r "
}
],
- "version": 3
+ "version": 4
}
```
The `version` property stores the version number of the Chat Tabs JSON file. This should not be touched unless you have
-an older Chat Tab JSON and would like Chatting to automatically migrate to the newer version.
+an older Chat Tab JSON and would like Chatting to automatically migrate to the newer version. The current version is `4`
+.
The `tabs` property stores all the chat tabs, in the order they should be displayed in. By default, there are 4 chat
tabs - ALL, PARTY, GUILD, and PM. ALL simply shows all messages; nothing is filtered. PARTY shows only party messages,
@@ -144,6 +157,9 @@ that you may want to use.
...
"(§r)*(§9P §8>)+(.*)"
],
+ "color": 14737632,
+ "hovered_color": 16777120,
+ "selected_color": 10526880,
"prefix": "/pc "
}
```
@@ -197,5 +213,13 @@ The `regex` property allows you to only allow a message if it matches a regex in
You can append `ignore_` to `starts`, `ends`, `equals`, or `regex` to ignore messages that match rather than allow, and
of course use both at the same time.
+The `color` property allows you to change the color of the chat tab text. It is in RGBA format.
+
+The `hovered_color` property allows you to change the color of the chat tab text while being hovered. This takes
+priority over the `color` property. Like the `color` property, it is in RGBA format.
+
+The `selected_color` property allows you to change the color of the chat tab text while selected. This takes priority
+over all the other color properties. Like the other color properties, it is in RGBA format.
+
The `prefix` property appends the prefix to any message sent while in the specific chat tab **if it is not a command**.
This can be used to automatically send messages in a specific channel in servers, like in Hypixel. \ No newline at end of file
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