aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/cc/woverflow/chatting/gui/components
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-01-03 11:12:54 +0700
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-01-03 11:12:54 +0700
commit487709996c22fb0dbcac792076be799a09865600 (patch)
tree5ab6f27a54d673fb057fd3eafd9a5e27816f898c /src/main/kotlin/cc/woverflow/chatting/gui/components
parentdf895d122a8a2ea249e686578e026c1d0a8b8c47 (diff)
downloadChatting-487709996c22fb0dbcac792076be799a09865600.tar.gz
Chatting-487709996c22fb0dbcac792076be799a09865600.tar.bz2
Chatting-487709996c22fb0dbcac792076be799a09865600.zip
Chattils -> Chatting (1.1.0)
Update images (ty Mo2men) update screenshot line tooltip (ty Mo2men)
Diffstat (limited to 'src/main/kotlin/cc/woverflow/chatting/gui/components')
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt70
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt35
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/SearchButton.kt69
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt19
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/TextBlock.kt41
5 files changed, 234 insertions, 0 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt
new file mode 100644
index 0000000..b67510a
--- /dev/null
+++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/CleanButton.kt
@@ -0,0 +1,70 @@
+package cc.woverflow.chatting.gui.components
+
+import cc.woverflow.chatting.Chatting
+import club.sk1er.patcher.config.PatcherConfig
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.GuiButton
+import net.minecraft.client.renderer.GlStateManager
+import java.awt.Color
+
+/**
+ * Taken from ChatShortcuts under MIT License
+ * 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) :
+ GuiButton(buttonId, x.invoke(), 0, widthIn, heightIn, name) {
+
+ open fun isEnabled(): Boolean {
+ return false
+ }
+
+ open fun onMousePress() {
+
+ }
+
+ override fun mousePressed(mc: Minecraft, mouseX: Int, mouseY: Int): Boolean {
+ val isPressed =
+ visible && mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height
+ if (isPressed) {
+ onMousePress()
+ }
+ return isPressed
+ }
+
+ override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) {
+ enabled = isEnabled()
+ xPosition = x.invoke()
+ yPosition = y.invoke()
+ if (visible) {
+ val fontrenderer = mc.fontRendererObj
+ GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
+ hovered =
+ mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height
+ if (!Chatting.isPatcher || !PatcherConfig.transparentChatInputField) {
+ drawRect(
+ xPosition,
+ yPosition,
+ xPosition + width,
+ yPosition + height,
+ if (hovered) hoveredColor else color
+ )
+ }
+ mouseDragged(mc, mouseX, mouseY)
+ var j = 14737632
+ if (packedFGColour != 0) {
+ j = packedFGColour
+ } else if (!enabled) {
+ j = 10526880
+ } else if (hovered) {
+ j = 16777120
+ }
+ drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, j)
+ }
+ }
+
+ companion object {
+ val hoveredColor = Color(255, 255, 255, 128).rgb
+ val color = Color(0, 0, 0, 128).rgb
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt
new file mode 100644
index 0000000..379444c
--- /dev/null
+++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt
@@ -0,0 +1,35 @@
+package cc.woverflow.chatting.gui.components
+
+import cc.woverflow.chatting.Chatting
+import cc.woverflow.chatting.mixin.GuiNewChatAccessor
+import gg.essential.api.utils.GuiUtil
+import gg.essential.universal.UResolution
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.Gui
+import net.minecraft.client.gui.GuiChat
+import net.minecraft.client.renderer.GlStateManager
+import net.minecraft.util.ResourceLocation
+
+class ScreenshotButton :
+ CleanButton(448318, { UResolution.scaledWidth - 28 }, { UResolution.scaledHeight - 27 }, 12, 12, "") {
+
+ override fun onMousePress() {
+ val chat = Minecraft.getMinecraft().ingameGUI.chatGUI
+ if (GuiUtil.getOpenedScreen() is GuiChat) {
+ Chatting.screenshotChat((chat as GuiNewChatAccessor).scrollPos)
+ }
+ }
+
+ override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) {
+ super.drawButton(mc, mouseX, mouseY)
+ if (visible) {
+ if (hovered) {
+ GlStateManager.color(1f, 1f, 160f / 255f)
+ } else {
+ GlStateManager.color(1f, 1f, 1f)
+ }
+ mc.textureManager.bindTexture(ResourceLocation(Chatting.ID, "screenshot.png"))
+ Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f)
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/SearchButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/SearchButton.kt
new file mode 100644
index 0000000..a0f875e
--- /dev/null
+++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/SearchButton.kt
@@ -0,0 +1,69 @@
+package cc.woverflow.chatting.gui.components
+
+import cc.woverflow.chatting.Chatting
+import cc.woverflow.chatting.hook.GuiNewChatHook
+import gg.essential.universal.UResolution
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.Gui
+import net.minecraft.client.gui.GuiTextField
+import net.minecraft.client.renderer.GlStateManager
+import net.minecraft.util.ResourceLocation
+
+class SearchButton :
+ CleanButton(3993935, { UResolution.scaledWidth - 14 }, { UResolution.scaledHeight - 27 }, 12, 12, "") {
+ val inputField = SearchTextField()
+ private var chatBox = false
+
+ override fun isEnabled(): Boolean {
+ return chatBox
+ }
+
+ override fun onMousePress() {
+ chatBox = !chatBox
+ inputField.setEnabled(chatBox)
+ inputField.isFocused = chatBox
+ (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).prevText = ""
+ inputField.text = ""
+ }
+
+ override fun drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) {
+ inputField.drawTextBox()
+ super.drawButton(mc, mouseX, mouseY)
+ if (visible) {
+ mc.textureManager.bindTexture(ResourceLocation(Chatting.ID, "search.png"))
+ if (isEnabled()) {
+ GlStateManager.color(224f / 255f, 224f / 255f, 224f / 255f)
+ } else if (mouseX >= xPosition && mouseX <= xPosition + 10 && mouseY >= yPosition && mouseY <= yPosition + 10) {
+ GlStateManager.color(1f, 1f, 160f / 255f)
+ } else {
+ GlStateManager.color(1f, 1f, 1f)
+ }
+ Gui.drawModalRectWithCustomSizedTexture(xPosition + 1, yPosition + 1, 0f, 0f, 10, 10, 10f, 10f)
+ }
+ }
+
+ inner class SearchTextField : GuiTextField(
+ 69420,
+ Minecraft.getMinecraft().fontRendererObj,
+ UResolution.scaledWidth * 4 / 5 - 60,
+ UResolution.scaledHeight - 27,
+ UResolution.scaledWidth / 5,
+ 12
+ ) {
+
+ init {
+ maxStringLength = 100
+ enableBackgroundDrawing = true
+ isFocused = false
+ text = ""
+ setCanLoseFocus(true)
+ }
+
+ override fun drawTextBox() {
+ if (isEnabled()) {
+ if (!isFocused) isFocused = true
+ super.drawTextBox()
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt
new file mode 100644
index 0000000..5342629
--- /dev/null
+++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/TabButton.kt
@@ -0,0 +1,19 @@
+package cc.woverflow.chatting.gui.components
+
+import cc.woverflow.chatting.chat.ChatTab
+import cc.woverflow.chatting.chat.ChatTabs
+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) {
+
+ override fun onMousePress() {
+ ChatTabs.currentTab = chatTab
+ }
+
+ override fun isEnabled(): Boolean {
+ return chatTab != ChatTabs.currentTab
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/TextBlock.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/TextBlock.kt
new file mode 100644
index 0000000..8a4f32a
--- /dev/null
+++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/TextBlock.kt
@@ -0,0 +1,41 @@
+package cc.woverflow.chatting.gui.components
+
+import gg.essential.elementa.components.UIBlock
+import gg.essential.elementa.components.UIText
+import gg.essential.elementa.constraints.ChildBasedSizeConstraint
+import gg.essential.elementa.dsl.*
+import gg.essential.elementa.effects.OutlineEffect
+import gg.essential.elementa.state.BasicState
+import gg.essential.vigilance.gui.VigilancePalette
+import gg.essential.vigilance.gui.settings.SettingComponent
+
+/**
+ * Heavily modified from Vigilance under LGPLv3 (modified to be just a text block)
+ * https://github.com/Sk1erLLC/Vigilance/blob/master/LICENSE
+ */
+class TextBlock(
+ text: String
+) : SettingComponent() {
+ private val textHolder = UIBlock() constrain {
+ width = ChildBasedSizeConstraint() + 6.pixels()
+ height = ChildBasedSizeConstraint() + 6.pixels()
+ color = VigilancePalette.getDarkHighlight().toConstraint()
+ } childOf this effect OutlineEffect(
+ VigilancePalette.getDivider(),
+ 1f
+ ).bindColor(BasicState(VigilancePalette.getDivider()))
+
+ private val text: UIText = UIText(text) constrain {
+ x = 3.pixels()
+ y = 3.pixels()
+ }
+
+ init {
+ this.text childOf textHolder
+
+ constrain {
+ width = ChildBasedSizeConstraint()
+ height = ChildBasedSizeConstraint()
+ }
+ }
+} \ No newline at end of file