diff options
Diffstat (limited to 'src/main/kotlin/cc/woverflow/chattils/gui')
7 files changed, 381 insertions, 0 deletions
diff --git a/src/main/kotlin/cc/woverflow/chattils/gui/ChatShortcutEditGui.kt b/src/main/kotlin/cc/woverflow/chattils/gui/ChatShortcutEditGui.kt new file mode 100644 index 0000000..aa4b933 --- /dev/null +++ b/src/main/kotlin/cc/woverflow/chattils/gui/ChatShortcutEditGui.kt @@ -0,0 +1,90 @@ +package cc.woverflow.chattils.gui + +import cc.woverflow.chattils.chat.ChatShortcuts +import gg.essential.api.EssentialAPI +import gg.essential.api.gui.buildConfirmationModal +import gg.essential.elementa.ElementaVersion +import gg.essential.elementa.WindowScreen +import gg.essential.elementa.components.UIBlock +import gg.essential.elementa.constraints.CenterConstraint +import gg.essential.elementa.constraints.SiblingConstraint +import gg.essential.elementa.dsl.childOf +import gg.essential.elementa.dsl.constrain +import gg.essential.elementa.dsl.percent +import gg.essential.elementa.dsl.pixels +import gg.essential.vigilance.gui.VigilancePalette +import gg.essential.vigilance.gui.settings.ButtonComponent +import gg.essential.vigilance.gui.settings.TextComponent + +class ChatShortcutEditGui(private var alias: String, private var command: String, private val editing: Boolean) : + WindowScreen(restoreCurrentGuiOnClose = true, version = ElementaVersion.V1) { + + private val initialAlias = alias + private val initialCommand = command + + override fun initScreen(width: Int, height: Int) { + super.initScreen(width, height) + val block = UIBlock(VigilancePalette.getBackground()).constrain { + this.x = CenterConstraint() + this.y = CenterConstraint() + this.width = 100.pixels() + this.height = 100.pixels() + } childOf window + TextComponent(initialAlias, "Alias", wrap = false, protected = false).constrain { + x = CenterConstraint() + y = 10.percent() + }.childOf(block).onValueChange { + if (it is String) alias = it + } + TextComponent(initialCommand, "Command", wrap = false, protected = false).constrain { + x = CenterConstraint() + y = SiblingConstraint() + }.childOf(block).onValueChange { + if (it is String) command = it + } + if (editing) { + ButtonComponent("Reset") { + EssentialAPI.getGuiUtil().openScreen(ChatShortcutEditGui(initialAlias, initialCommand, editing)) + } constrain { + x = CenterConstraint() + y = 70.percent() + } childOf window + } + ButtonComponent("Save") { + alias = alias.substringAfter("/") + command = command.substringAfter("/") + if (editing) { + ChatShortcuts.removeShortcut(initialAlias) + } + if (alias.isBlank() || command.isBlank()) { + return@ButtonComponent + } + if (ChatShortcuts.shortcuts.any { it.first == alias }) { + EssentialAPI.getGuiUtil().openScreen(ChatShortcutConfirmGui(alias, command)) + return@ButtonComponent + } + ChatShortcuts.writeShortcut(alias, command) + restorePreviousScreen() + } constrain { + x = CenterConstraint() + y = 80.percent() + } childOf window + } + + inner class ChatShortcutConfirmGui(private var alias: String, private var command: String) : + WindowScreen(restoreCurrentGuiOnClose = true, version = ElementaVersion.V1) { + override fun initScreen(width: Int, height: Int) { + super.initScreen(width, height) + EssentialAPI.getEssentialComponentFactory().buildConfirmationModal { + text = "An alias with this name already exists, are you sure you want to overwrite it?" + onConfirm = { + ChatShortcuts.writeShortcut(alias, command) + EssentialAPI.getGuiUtil().openScreen(null) + } + onDeny = { + restorePreviousScreen() + } + } childOf this@ChatShortcutConfirmGui.window + } + } +} diff --git a/src/main/kotlin/cc/woverflow/chattils/gui/ChatShortcutViewGui.kt b/src/main/kotlin/cc/woverflow/chattils/gui/ChatShortcutViewGui.kt new file mode 100644 index 0000000..f4ad049 --- /dev/null +++ b/src/main/kotlin/cc/woverflow/chattils/gui/ChatShortcutViewGui.kt @@ -0,0 +1,57 @@ +package cc.woverflow.chattils.gui + +import cc.woverflow.chattils.chat.ChatShortcuts +import cc.woverflow.chattils.gui.components.TextBlock +import gg.essential.api.EssentialAPI +import gg.essential.elementa.ElementaVersion +import gg.essential.elementa.WindowScreen +import gg.essential.elementa.components.UIBlock +import gg.essential.elementa.constraints.CenterConstraint +import gg.essential.elementa.constraints.RelativeWindowConstraint +import gg.essential.elementa.constraints.SiblingConstraint +import gg.essential.elementa.dsl.* +import gg.essential.vigilance.gui.VigilancePalette +import gg.essential.vigilance.gui.settings.ButtonComponent + +class ChatShortcutViewGui : WindowScreen(version = ElementaVersion.V1) { + override fun initScreen(width: Int, height: Int) { + super.initScreen(width, height) + for ((index, shortcut) in ChatShortcuts.shortcuts.withIndex()) { + val block = UIBlock(VigilancePalette.getBackground()).constrain { + x = 3.percent() + y = (index * 12).percent() + this.width = 94.percent() + this.height = 25.pixels() + } childOf this.window + TextBlock(shortcut.first).constrain { + x = RelativeWindowConstraint(0.05F) + y = CenterConstraint() + } childOf block + TextBlock(shortcut.second).constrain { + x = SiblingConstraint(10F) + y = CenterConstraint() + } childOf block + ButtonComponent("Edit") { + println("${shortcut.first} ${shortcut.second}") + EssentialAPI.getGuiUtil().openScreen(ChatShortcutEditGui(shortcut.first, shortcut.second, true)) + } constrain { + x = SiblingConstraint(20F) + y = CenterConstraint() + } childOf block + ButtonComponent("Delete") { + println("${shortcut.first} ${shortcut.second}") + ChatShortcuts.removeShortcut(shortcut.first) + EssentialAPI.getGuiUtil().openScreen(ChatShortcutViewGui()) + } constrain { + x = SiblingConstraint(5F) + y = CenterConstraint() + } childOf block + } + ButtonComponent("New") { + EssentialAPI.getGuiUtil().openScreen(ChatShortcutEditGui("", "", false)) + } constrain { + x = CenterConstraint() + y = 80.percent() + } childOf window + } +}
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chattils/gui/components/CleanButton.kt b/src/main/kotlin/cc/woverflow/chattils/gui/components/CleanButton.kt new file mode 100644 index 0000000..7011518 --- /dev/null +++ b/src/main/kotlin/cc/woverflow/chattils/gui/components/CleanButton.kt @@ -0,0 +1,70 @@ +package cc.woverflow.chattils.gui.components + +import cc.woverflow.chattils.Chattils +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 (!Chattils.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 { + private val hoveredColor = Color(255, 255, 255, 128).rgb + private val color = Color(0, 0, 0, 128).rgb + } +}
\ No newline at end of file diff --git a/src/main/kotlin/cc/woverflow/chattils/gui/components/ScreenshotButton.kt b/src/main/kotlin/cc/woverflow/chattils/gui/components/ScreenshotButton.kt new file mode 100644 index 0000000..0e6f088 --- /dev/null +++ b/src/main/kotlin/cc/woverflow/chattils/gui/components/ScreenshotButton.kt @@ -0,0 +1,35 @@ +package cc.woverflow.chattils.gui.components + +import cc.woverflow.chattils.Chattils +import cc.woverflow.chattils.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) { + Chattils.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(Chattils.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/chattils/gui/components/SearchButton.kt b/src/main/kotlin/cc/woverflow/chattils/gui/components/SearchButton.kt new file mode 100644 index 0000000..04a2743 --- /dev/null +++ b/src/main/kotlin/cc/woverflow/chattils/gui/components/SearchButton.kt @@ -0,0 +1,69 @@ +package cc.woverflow.chattils.gui.components + +import cc.woverflow.chattils.Chattils +import cc.woverflow.chattils.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(Chattils.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/chattils/gui/components/TabButton.kt b/src/main/kotlin/cc/woverflow/chattils/gui/components/TabButton.kt new file mode 100644 index 0000000..4770900 --- /dev/null +++ b/src/main/kotlin/cc/woverflow/chattils/gui/components/TabButton.kt @@ -0,0 +1,19 @@ +package cc.woverflow.chattils.gui.components + +import cc.woverflow.chattils.chat.ChatTab +import cc.woverflow.chattils.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/chattils/gui/components/TextBlock.kt b/src/main/kotlin/cc/woverflow/chattils/gui/components/TextBlock.kt new file mode 100644 index 0000000..c83d22d --- /dev/null +++ b/src/main/kotlin/cc/woverflow/chattils/gui/components/TextBlock.kt @@ -0,0 +1,41 @@ +package cc.woverflow.chattils.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 |
