From 19c59eb6d38e7b188a5881aff89c512484988851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=91=89=20Scarlet?= <93977077+mukjepscarlet@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:36:04 +0800 Subject: [PATCH 1/4] GuiPortScanner input validators --- .../ui/client/tools/GuiPortScanner.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt index 163c0a8d5d3..fe41a280842 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt @@ -55,16 +55,28 @@ class GuiPortScanner(private val prevGui: GuiScreen) : GuiScreen() { minPortField = GuiTextField(1, Fonts.minecraftFont, width / 2 - 100, 90, 90, 20).apply { maxStringLength = 5 text = "1" + setValidator { + val intValue = it?.toIntOrNull() ?: return@setValidator false + intValue >= 0 && intValue < maxPortField.text.toInt() + } } maxPortField = GuiTextField(2, Fonts.minecraftFont, width / 2 + 10, 90, 90, 20).apply { maxStringLength = 5 text = "65535" + setValidator { + val intValue = it?.toIntOrNull() ?: return@setValidator false + intValue > minPortField.text.toInt() && intValue < 65536 + } } parallelismField = GuiTextField(3, Fonts.minecraftFont, width / 2 - 100, 120, 200, 20).apply { maxStringLength = Int.MAX_VALUE - text = "500" + text = "64" + setValidator { + val intValue = it?.toIntOrNull() ?: return@setValidator false + intValue > 0 + } } buttonList.add(GuiButton(1, width / 2 - 100, height / 4 + 95, if (running) "Stop" else "Start").also { buttonToggle = it }) @@ -179,6 +191,7 @@ class GuiPortScanner(private val prevGui: GuiScreen) : GuiScreen() { fileWriter.write("Ports ($minPort - $maxPort):\r\n") ports.forEach { port -> fileWriter.write("$port\r\n") } } + JOptionPane.showMessageDialog(null, "Exported successfully!", "Port Scanner", JOptionPane.INFORMATION_MESSAGE) } catch (e: Exception) { e.printStackTrace() From a2544f6b178f9ab8e53a65317b0cfe94a3c6a45d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=91=89=20Scarlet?= <93977077+mukjepscarlet@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:36:20 +0800 Subject: [PATCH 2/4] GuiPasswordField string optimization --- .../ui/elements/GuiPasswordField.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/elements/GuiPasswordField.kt b/src/main/java/net/ccbluex/liquidbounce/ui/elements/GuiPasswordField.kt index 2cbfc80cc35..4ea933fea13 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/elements/GuiPasswordField.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/elements/GuiPasswordField.kt @@ -9,7 +9,14 @@ package net.ccbluex.liquidbounce.ui.elements import net.minecraft.client.gui.FontRenderer import net.minecraft.client.gui.GuiTextField -class GuiPasswordField(componentId: Int, fontrendererObj: FontRenderer, x: Int, y: Int, par5Width: Int, par6Height: Int) : GuiTextField(componentId, fontrendererObj, x, y, par5Width, par6Height) { +class GuiPasswordField( + componentId: Int, + fontrendererObj: FontRenderer, + x: Int, + y: Int, + width: Int, + height: Int +) : GuiTextField(componentId, fontrendererObj, x, y, width, height) { /** * Draw text box @@ -17,11 +24,14 @@ class GuiPasswordField(componentId: Int, fontrendererObj: FontRenderer, x: Int, override fun drawTextBox() { val realText = text - val stringBuilder = StringBuilder() - for (i in text.indices) stringBuilder.append('*') - text = stringBuilder.toString() + text = buildString(realText.length) { + repeat(realText.length) { + append('*') + } + } super.drawTextBox() + text = realText } From d029885faf63c1086352567917286f84f1255a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=91=89=20Scarlet?= <93977077+mukjepscarlet@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:00:48 +0800 Subject: [PATCH 3/4] refactor(legacy): GuiScreen button list --- .../ui/client/GuiClientConfiguration.kt | 136 +++++++++--------- .../liquidbounce/ui/client/GuiClientFixes.kt | 58 +++++--- .../liquidbounce/ui/client/GuiContributors.kt | 21 ++- .../liquidbounce/ui/client/GuiMainMenu.kt | 52 ++++--- .../liquidbounce/ui/client/GuiModsMenu.kt | 32 +++-- .../liquidbounce/ui/client/GuiScripts.kt | 48 ++++--- .../liquidbounce/ui/client/GuiServerStatus.kt | 18 ++- .../liquidbounce/ui/client/GuiUpdate.kt | 24 ++-- .../liquidbounce/ui/client/GuiWelcome.kt | 78 ++++++++-- .../ui/client/altmanager/GuiAltManager.kt | 41 +++--- .../client/altmanager/menus/GuiDonatorCape.kt | 29 ++-- .../altmanager/menus/GuiLoginIntoAccount.kt | 35 +++-- .../altmanager/menus/GuiLoginProgress.kt | 9 +- .../menus/GuiMicrosoftLoginProgress.kt | 11 +- .../altmanager/menus/GuiSessionLogin.kt | 12 +- .../menus/altgenerator/GuiTheAltening.kt | 53 ++++--- .../ui/client/tools/GuiPortScanner.kt | 9 +- .../liquidbounce/ui/client/tools/GuiTools.kt | 9 +- .../liquidbounce/utils/ui/GuiExtensions.kt | 13 ++ 19 files changed, 434 insertions(+), 254 deletions(-) create mode 100644 src/main/java/net/ccbluex/liquidbounce/utils/ui/GuiExtensions.kt diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiClientConfiguration.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiClientConfiguration.kt index fe511d1a45f..e5bd31765af 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiClientConfiguration.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiClientConfiguration.kt @@ -14,10 +14,11 @@ import net.ccbluex.liquidbounce.file.FileManager.valuesConfig import net.ccbluex.liquidbounce.lang.LanguageManager import net.ccbluex.liquidbounce.lang.translationMenu import net.ccbluex.liquidbounce.ui.font.Fonts -import net.ccbluex.liquidbounce.utils.render.shader.Background import net.ccbluex.liquidbounce.utils.client.MinecraftInstance.Companion.mc import net.ccbluex.liquidbounce.utils.io.MiscUtils import net.ccbluex.liquidbounce.utils.render.IconUtils +import net.ccbluex.liquidbounce.utils.render.shader.Background +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import net.minecraftforge.fml.client.config.GuiSlider @@ -25,7 +26,7 @@ import org.lwjgl.input.Keyboard import org.lwjgl.opengl.Display import java.nio.file.Files -class GuiClientConfiguration(val prevGui: GuiScreen) : GuiScreen() { +class GuiClientConfiguration(val prevGui: GuiScreen) : AbstractScreen() { companion object { var enabledClientTitle = true @@ -64,72 +65,73 @@ class GuiClientConfiguration(val prevGui: GuiScreen) : GuiScreen() { private lateinit var titleButton: GuiButton override fun initGui() { - buttonList.run { - clear() - - // Title button - // Location > 1st row - add(GuiButton( - 4, width / 2 - 100, height / 4 + 25, "Client title (${if (enabledClientTitle) "On" else "Off"})" - ).also { titleButton = it }) - add(GuiButton( - 7, - width / 2 - 100, - height / 4 + 50, - "Language (${LanguageManager.overrideLanguage.ifBlank { "Game" }})" - ).also { languageButton = it }) - - // Background configuration buttons - // Button location > 2nd row - add(GuiButton( - 0, - width / 2 - 100, - height / 4 + 25 + 75, - "Enabled (${if (enabledCustomBackground) "On" else "Off"})" - ).also { backgroundButton = it }) - add(GuiButton( - 1, width / 2 - 100, height / 4 + 25 + 75 + 25, "Particles (${if (particles) "On" else "Off"})" - ).also { particlesButton = it }) - add(GuiButton(2, width / 2 - 100, height / 4 + 25 + 75 + 25 * 2, 98, 20, "Change wallpaper")) - add(GuiButton(3, width / 2 + 2, height / 4 + 25 + 75 + 25 * 2, 98, 20, "Reset wallpaper")) - - // AltManager configuration buttons - // Location > 3rd row - add(GuiButton( - 6, - width / 2 - 100, - height / 4 + 25 + 185, - "Random alts mode (${if (stylisedAlts) "Stylised" else "Legacy"})" - ).also { altsModeButton = it }) - add(GuiSlider( - -1, - width / 2 - 100, - height / 4 + 210 + 25, - 200, - 20, - "${if (stylisedAlts && unformattedAlts) "Random alt max" else "Random alt"} length (", - ")", - 6.0, - 16.0, - altsLength.toDouble(), - false, - true - ) { - altsLength = it.valueInt - }.also { altsSlider = it }) - add(GuiButton( - 5, - width / 2 - 100, - height / 4 + 235 + 25, - "Unformatted alt names (${if (unformattedAlts) "On" else "Off"})" - ).also { - it.enabled = stylisedAlts - unformattedAltsButton = it - }) - - // Back button - add(GuiButton(8, width / 2 - 100, height / 4 + 25 + 25 * 11, "Back")) + // Title button + // Location > 1st row + titleButton = +GuiButton( + 4, width / 2 - 100, height / 4 + 25, "Client title (${if (enabledClientTitle) "On" else "Off"})" + ) + + languageButton = +GuiButton( + 7, + width / 2 - 100, + height / 4 + 50, + "Language (${LanguageManager.overrideLanguage.ifBlank { "Game" }})" + ) + + // Background configuration buttons + // Button location > 2nd row + backgroundButton = +GuiButton( + 0, + width / 2 - 100, + height / 4 + 25 + 75, + "Enabled (${if (enabledCustomBackground) "On" else "Off"})" + ) + + particlesButton = +GuiButton( + 1, width / 2 - 100, height / 4 + 25 + 75 + 25, "Particles (${if (particles) "On" else "Off"})" + ) + + +GuiButton(2, width / 2 - 100, height / 4 + 25 + 75 + 25 * 2, 98, 20, "Change wallpaper") + + +GuiButton(3, width / 2 + 2, height / 4 + 25 + 75 + 25 * 2, 98, 20, "Reset wallpaper") + + // AltManager configuration buttons + // Location > 3rd row + altsModeButton = +GuiButton( + 6, + width / 2 - 100, + height / 4 + 25 + 185, + "Random alts mode (${if (stylisedAlts) "Stylised" else "Legacy"})" + ) + + altsSlider = +GuiSlider( + -1, + width / 2 - 100, + height / 4 + 210 + 25, + 200, + 20, + "${if (stylisedAlts && unformattedAlts) "Random alt max" else "Random alt"} length (", + ")", + 6.0, + 16.0, + altsLength.toDouble(), + false, + true + ) { + altsLength = it.valueInt + } + + unformattedAltsButton = +GuiButton( + 5, + width / 2 - 100, + height / 4 + 235 + 25, + "Unformatted alt names (${if (unformattedAlts) "On" else "Off"})" + ).also { + it.enabled = stylisedAlts } + + // Back button + +GuiButton(8, width / 2 - 100, height / 4 + 25 + 25 * 11, "Back") } override fun actionPerformed(button: GuiButton) { diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiClientFixes.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiClientFixes.kt index 46fbc495f6e..1448a181d45 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiClientFixes.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiClientFixes.kt @@ -15,14 +15,14 @@ import net.ccbluex.liquidbounce.features.special.ClientFixes.fmlFixesEnabled import net.ccbluex.liquidbounce.file.FileManager.saveConfig import net.ccbluex.liquidbounce.file.FileManager.valuesConfig import net.ccbluex.liquidbounce.ui.font.Fonts +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import org.lwjgl.input.Keyboard import java.io.IOException import java.util.* -import java.util.concurrent.CopyOnWriteArrayList -class GuiClientFixes(private val prevGui: GuiScreen) : GuiScreen() { +class GuiClientFixes(private val prevGui: GuiScreen) : AbstractScreen() { private lateinit var enabledButton: GuiButton private lateinit var fmlButton: GuiButton @@ -30,20 +30,37 @@ class GuiClientFixes(private val prevGui: GuiScreen) : GuiScreen() { private lateinit var payloadButton: GuiButton private lateinit var customBrandButton: GuiButton private lateinit var resourcePackButton: GuiButton + override fun initGui() { - enabledButton = GuiButton(1, width / 2 - 100, height / 4 + 35, "AntiForge (" + (if (fmlFixesEnabled) "On" else "Off") + ")") - fmlButton = GuiButton(2, width / 2 - 100, height / 4 + 35 + 25, "Block FML (" + (if (blockFML) "On" else "Off") + ")") - proxyButton = GuiButton(3, width / 2 - 100, height / 4 + 35 + 25 * 2, "Block FML Proxy Packet (" + (if (blockProxyPacket) "On" else "Off") + ")") - payloadButton = GuiButton(4, width / 2 - 100, height / 4 + 35 + 25 * 3, "Block Non-MC Payloads (" + (if (blockPayloadPackets) "On" else "Off") + ")") - customBrandButton = GuiButton(5, width / 2 - 100, height / 4 + 35 + 25 * 4, "Brand ($clientBrand)") - resourcePackButton = GuiButton(6, width / 2 - 100, height / 4 + 50 + 25 * 5, "Block Resource Pack Exploit (" + (if (blockResourcePackExploit) "On" else "Off") + ")") - - buttonList = CopyOnWriteArrayList( - listOf( - enabledButton, fmlButton, proxyButton, payloadButton, customBrandButton, resourcePackButton, - GuiButton(0, width / 2 - 100, height / 4 + 55 + 25 * 6 + 5, "Back") - ) + enabledButton = +GuiButton( + 1, + width / 2 - 100, + height / 4 + 35, + "AntiForge (" + (if (fmlFixesEnabled) "On" else "Off") + ")" + ) + fmlButton = + +GuiButton(2, width / 2 - 100, height / 4 + 35 + 25, "Block FML (" + (if (blockFML) "On" else "Off") + ")") + proxyButton = +GuiButton( + 3, + width / 2 - 100, + height / 4 + 35 + 25 * 2, + "Block FML Proxy Packet (" + (if (blockProxyPacket) "On" else "Off") + ")" + ) + payloadButton = +GuiButton( + 4, + width / 2 - 100, + height / 4 + 35 + 25 * 3, + "Block Non-MC Payloads (" + (if (blockPayloadPackets) "On" else "Off") + ")" + ) + customBrandButton = +GuiButton(5, width / 2 - 100, height / 4 + 35 + 25 * 4, "Brand ($clientBrand)") + resourcePackButton = +GuiButton( + 6, + width / 2 - 100, + height / 4 + 50 + 25 * 5, + "Block Resource Pack Exploit (" + (if (blockResourcePackExploit) "On" else "Off") + ")" ) + + +GuiButton(0, width / 2 - 100, height / 4 + 55 + 25 * 6 + 5, "Back") } public override fun actionPerformed(button: GuiButton) { @@ -52,18 +69,22 @@ class GuiClientFixes(private val prevGui: GuiScreen) : GuiScreen() { fmlFixesEnabled = !fmlFixesEnabled enabledButton.displayString = "AntiForge (${if (fmlFixesEnabled) "On" else "Off"})" } + 2 -> { blockFML = !blockFML fmlButton.displayString = "Block FML (${if (blockFML) "On" else "Off"})" } + 3 -> { blockProxyPacket = !blockProxyPacket proxyButton.displayString = "Block FML Proxy Packet (${if (blockProxyPacket) "On" else "Off"})" } + 4 -> { blockPayloadPackets = !blockPayloadPackets payloadButton.displayString = "Block FML Payload Packets (${if (blockPayloadPackets) "On" else "Off"})" } + 5 -> { val brands = listOf(*ClientFixes.possibleBrands) @@ -72,10 +93,13 @@ class GuiClientFixes(private val prevGui: GuiScreen) : GuiScreen() { customBrandButton.displayString = "Brand ($clientBrand)" } + 6 -> { blockResourcePackExploit = !blockResourcePackExploit - resourcePackButton.displayString = "Block Resource Pack Exploit (${if (blockResourcePackExploit) "On" else "Off"})" + resourcePackButton.displayString = + "Block Resource Pack Exploit (${if (blockResourcePackExploit) "On" else "Off"})" } + 0 -> mc.displayGuiScreen(prevGui) } } @@ -83,7 +107,7 @@ class GuiClientFixes(private val prevGui: GuiScreen) : GuiScreen() { override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { drawBackground(0) Fonts.fontBold180.drawCenteredString("Fixes", width / 2f, height / 8f + 5f, 4673984, true) - + super.drawScreen(mouseX, mouseY, partialTicks) } @@ -93,7 +117,7 @@ class GuiClientFixes(private val prevGui: GuiScreen) : GuiScreen() { mc.displayGuiScreen(prevGui) return } - + super.keyTyped(typedChar, keyCode) } diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiContributors.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiContributors.kt index f45f60e5562..a1362cc7d8e 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiContributors.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiContributors.kt @@ -14,12 +14,13 @@ import net.ccbluex.liquidbounce.lang.translationMenu import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER -import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes import net.ccbluex.liquidbounce.utils.io.HttpUtils.get import net.ccbluex.liquidbounce.utils.io.HttpUtils.requestStream +import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes import net.ccbluex.liquidbounce.utils.render.CustomTexture import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawLoadingCircle import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRect +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiSlot @@ -33,7 +34,7 @@ import java.util.* import javax.imageio.ImageIO import kotlin.math.sin -class GuiContributors(private val prevGui: GuiScreen) : GuiScreen() { +class GuiContributors(private val prevGui: GuiScreen) : AbstractScreen() { private val DECIMAL_FORMAT = NumberFormat.getInstance(Locale.US) as DecimalFormat private lateinit var list: GuiList @@ -44,7 +45,7 @@ class GuiContributors(private val prevGui: GuiScreen) : GuiScreen() { list = GuiList(this) list.registerScrollButtons(7, 8) - buttonList.add(GuiButton(1, width / 2 - 100, height - 30, "Back")) + +GuiButton(1, width / 2 - 100, height - 30, "Back") failed = false @@ -175,7 +176,8 @@ class GuiContributors(private val prevGui: GuiScreen) : GuiScreen() { try { val jsonParser = JsonParser() - val gitHubContributors = PRETTY_GSON.fromJson(get("https://api.github.com/repos/CCBlueX/LiquidBounce/stats/contributors").first, + val gitHubContributors = PRETTY_GSON.fromJson( + get("https://api.github.com/repos/CCBlueX/LiquidBounce/stats/contributors").first, Array::class.java ) @@ -184,7 +186,8 @@ class GuiContributors(private val prevGui: GuiScreen) : GuiScreen() { return } - val additionalInformation = jsonParser.parse(get("https://raw.githubusercontent.com/CCBlueX/LiquidCloud/master/LiquidBounce/contributors.json").first).asJsonObject + val additionalInformation = + jsonParser.parse(get("https://raw.githubusercontent.com/CCBlueX/LiquidCloud/master/LiquidBounce/contributors.json").first).asJsonObject val credits = mutableListOf() @@ -207,7 +210,8 @@ class GuiContributors(private val prevGui: GuiScreen) : GuiScreen() { commits += week.commits } - credits += Credit(author.name, author.avatarUrl, null, + credits += Credit( + author.name, author.avatarUrl, null, additions, deletions, commits, contributorInformation?.teamMember ?: false, contributorInformation?.contributions ?: emptyList() @@ -230,7 +234,10 @@ class GuiContributors(private val prevGui: GuiScreen) : GuiScreen() { for (credit in credits) { try { - requestStream("${credit.avatarUrl}?s=${fontRendererObj.FONT_HEIGHT * 4}", "GET").let { (stream) -> + requestStream( + "${credit.avatarUrl}?s=${fontRendererObj.FONT_HEIGHT * 4}", + "GET" + ).let { (stream, _) -> stream.use { credit.avatar = CustomTexture(ImageIO.read(it)) } diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiMainMenu.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiMainMenu.kt index b3418514cec..aa0cf0fbe42 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiMainMenu.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiMainMenu.kt @@ -14,36 +14,39 @@ import net.ccbluex.liquidbounce.ui.client.altmanager.GuiAltManager import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.io.MiscUtils import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRoundedBorderRect -import net.minecraft.client.gui.* +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen +import net.minecraft.client.gui.GuiButton +import net.minecraft.client.gui.GuiMultiplayer +import net.minecraft.client.gui.GuiOptions +import net.minecraft.client.gui.GuiSelectWorld import net.minecraft.client.resources.I18n -class GuiMainMenu : GuiScreen() { +class GuiMainMenu : AbstractScreen() { override fun initGui() { val defaultHeight = height / 4 + 48 - buttonList.run { - add(GuiButton(100, width / 2 - 100, defaultHeight + 24, 98, 20, translationMenu("altManager"))) - add(GuiButton(103, width / 2 + 2, defaultHeight + 24, 98, 20, translationMenu("mods"))) - add(GuiButton(101, width / 2 - 100, defaultHeight + 24 * 2, 98, 20, translationMenu("serverStatus"))) - add(GuiButton(102, width / 2 + 2, defaultHeight + 24 * 2, 98, 20, translationMenu("configuration"))) + +GuiButton(100, width / 2 - 100, defaultHeight + 24, 98, 20, translationMenu("altManager")) + +GuiButton(103, width / 2 + 2, defaultHeight + 24, 98, 20, translationMenu("mods")) + +GuiButton(101, width / 2 - 100, defaultHeight + 24 * 2, 98, 20, translationMenu("serverStatus")) + +GuiButton(102, width / 2 + 2, defaultHeight + 24 * 2, 98, 20, translationMenu("configuration")) - add(GuiButton(1, width / 2 - 100, defaultHeight, 98, 20, I18n.format("menu.singleplayer"))) - add(GuiButton(2, width / 2 + 2, defaultHeight, 98, 20, I18n.format("menu.multiplayer"))) + +GuiButton(1, width / 2 - 100, defaultHeight, 98, 20, I18n.format("menu.singleplayer")) + +GuiButton(2, width / 2 + 2, defaultHeight, 98, 20, I18n.format("menu.multiplayer")) - // Minecraft Realms - // this.buttonList.add(new GuiButton(14, this.width / 2 - 100, j + 24 * 2, I18n.format("menu.online", new Object[0]))); + // Minecraft Realms + // this.buttonList.add(new GuiButton(14, this.width / 2 - 100, j + 24 * 2, I18n.format("menu.online", new Object[0]))); - add(GuiButton(108, width / 2 - 100, defaultHeight + 24 * 3, translationMenu("contributors"))) - add(GuiButton(0, width / 2 - 100, defaultHeight + 24 * 4, 98, 20, I18n.format("menu.options"))) - add(GuiButton(4, width / 2 + 2, defaultHeight + 24 * 4, 98, 20, I18n.format("menu.quit"))) - } + +GuiButton(108, width / 2 - 100, defaultHeight + 24 * 3, translationMenu("contributors")) + +GuiButton(0, width / 2 - 100, defaultHeight + 24 * 4, 98, 20, I18n.format("menu.options")) + +GuiButton(4, width / 2 + 2, defaultHeight + 24 * 4, 98, 20, I18n.format("menu.quit")) } override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { drawBackground(0) - drawRoundedBorderRect(width / 2f - 115, height / 4f + 35, width / 2f + 115, height / 4f + 175, + drawRoundedBorderRect( + width / 2f - 115, height / 4f + 35, width / 2f + 115, height / 4f + 175, 2f, Integer.MIN_VALUE, Integer.MIN_VALUE, @@ -51,13 +54,20 @@ class GuiMainMenu : GuiScreen() { ) Fonts.fontBold180.drawCenteredString(CLIENT_NAME, width / 2F, height / 8F, 4673984, true) - Fonts.font35.drawCenteredString(clientVersionText, width / 2F + 148, height / 8F + Fonts.font35.fontHeight, 0xffffff, true) + Fonts.font35.drawCenteredString( + clientVersionText, + width / 2F + 148, + height / 8F + Fonts.font35.fontHeight, + 0xffffff, + true + ) val messageOfTheDay = messageOfTheDay?.message if (messageOfTheDay?.isNotBlank() == true) { val lines = messageOfTheDay.lines() - drawRoundedBorderRect(width / 2f - 115, + drawRoundedBorderRect( + width / 2f - 115, height / 4f + 190, width / 2f + 115, height / 4f + 200 + (Fonts.font35.fontHeight * lines.size), @@ -69,8 +79,10 @@ class GuiMainMenu : GuiScreen() { // Draw rect below main rect and within draw MOTD text for ((index, line) in lines.withIndex()) { - Fonts.font35.drawCenteredString(line, width / 2F, height / 4f + 197.5f - + (Fonts.font35.fontHeight * index), 0xffffff, true) + Fonts.font35.drawCenteredString( + line, width / 2F, height / 4f + 197.5f + + (Fonts.font35.fontHeight * index), 0xffffff, true + ) } } diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiModsMenu.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiModsMenu.kt index 0bb53ca61bf..fa4ebe78301 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiModsMenu.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiModsMenu.kt @@ -13,25 +13,39 @@ import net.ccbluex.liquidbounce.lang.translationMenu import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiTextField import net.minecraftforge.fml.client.GuiModList import org.lwjgl.input.Keyboard -class GuiModsMenu(private val prevGui: GuiScreen) : GuiScreen() { +class GuiModsMenu(private val prevGui: GuiScreen) : AbstractScreen() { private lateinit var customTextField: GuiTextField override fun initGui() { - buttonList.run { - add(GuiButton(0, width / 2 - 100, height / 4 + 48, "Forge Mods")) - add(GuiButton(1, width / 2 - 100, height / 4 + 48 + 25, "Scripts")) - add(GuiButton(2, width / 2 - 100, height / 4 + 48 + 85, "Toggle: ${if (clientRichPresence.showRPCValue) "§aON" else "§cOFF"}")) - add(GuiButton(3, width / 2 - 100, height / 4 + 48 + 110, "Show IP: ${if (clientRichPresence.showRPCServerIP) "§aON" else "§cOFF"}")) - add(GuiButton(4, width / 2 - 100, height / 4 + 48 + 135, "Show Modules Count: ${if (clientRichPresence.showRPCModulesCount) "§aON" else "§cOFF"}")) - add(GuiButton(5, width / 2 - 100, height / 4 + 48 + 255, "Back")) - } + +GuiButton(0, width / 2 - 100, height / 4 + 48, "Forge Mods") + +GuiButton(1, width / 2 - 100, height / 4 + 48 + 25, "Scripts") + +GuiButton( + 2, + width / 2 - 100, + height / 4 + 48 + 85, + "Toggle: ${if (clientRichPresence.showRPCValue) "§aON" else "§cOFF"}" + ) + +GuiButton( + 3, + width / 2 - 100, + height / 4 + 48 + 110, + "Show IP: ${if (clientRichPresence.showRPCServerIP) "§aON" else "§cOFF"}" + ) + +GuiButton( + 4, + width / 2 - 100, + height / 4 + 48 + 135, + "Show Modules Count: ${if (clientRichPresence.showRPCModulesCount) "§aON" else "§cOFF"}" + ) + +GuiButton(5, width / 2 - 100, height / 4 + 48 + 255, "Back") customTextField = GuiTextField(2, Fonts.font35, width / 2 - 100, height / 4 + 48 + 190, 200, 20) customTextField.maxStringLength = Int.MAX_VALUE diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiScripts.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiScripts.kt index 3bec68a9f7d..d7190e611c9 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiScripts.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiScripts.kt @@ -17,6 +17,7 @@ import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolat import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER import net.ccbluex.liquidbounce.utils.io.MiscUtils +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiSlot @@ -28,7 +29,7 @@ import java.io.File import java.net.URL import java.util.zip.ZipFile -class GuiScripts(private val prevGui: GuiScreen) : GuiScreen() { +class GuiScripts(private val prevGui: GuiScreen) : AbstractScreen() { private lateinit var list: GuiList @@ -38,15 +39,13 @@ class GuiScripts(private val prevGui: GuiScreen) : GuiScreen() { list.elementClicked(-1, false, 0, 0) val j = 22 - buttonList.run { - add(GuiButton(0, width - 80, height - 65, 70, 20, "Back")) - add(GuiButton(1, width - 80, j + 24, 70, 20, "Import")) - add(GuiButton(2, width - 80, j + 24 * 2, 70, 20, "Delete")) - add(GuiButton(3, width - 80, j + 24 * 3, 70, 20, "Reload")) - add(GuiButton(4, width - 80, j + 24 * 4, 70, 20, "Folder")) - add(GuiButton(5, width - 80, j + 24 * 5, 70, 20, "Docs")) - add(GuiButton(6, width - 80, j + 24 * 6, 70, 20, "Find Scripts")) - } + +GuiButton(0, width - 80, height - 65, 70, 20, "Back") + +GuiButton(1, width - 80, j + 24, 70, 20, "Import") + +GuiButton(2, width - 80, j + 24 * 2, 70, 20, "Delete") + +GuiButton(3, width - 80, j + 24 * 3, 70, 20, "Reload") + +GuiButton(4, width - 80, j + 24 * 4, 70, 20, "Folder") + +GuiButton(5, width - 80, j + 24 * 5, 70, 20, "Docs") + +GuiButton(6, width - 80, j + 24 * 6, 70, 20, "Find Scripts") } override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { @@ -123,23 +122,30 @@ class GuiScripts(private val prevGui: GuiScreen) : GuiScreen() { LOGGER.error("Something went wrong while deleting a script.", t) MiscUtils.showErrorPopup(t.javaClass.name, t.message!!) } + 3 -> try { reloadScripts() } catch (t: Throwable) { LOGGER.error("Something went wrong while reloading all scripts.", t) MiscUtils.showErrorPopup(t.javaClass.name, t.message!!) } + 4 -> try { Desktop.getDesktop().open(scriptsFolder) } catch (t: Throwable) { LOGGER.error("Something went wrong while trying to open your scripts folder.", t) MiscUtils.showErrorPopup(t.javaClass.name, t.message!!) } + 5 -> try { - Desktop.getDesktop().browse(URL("https://github.com/CCBlueX/Documentation/blob/master/md/scriptapi_v2/getting_started.md").toURI()) + Desktop.getDesktop() + .browse(URL("https://github.com/CCBlueX/Documentation/blob/master/md/scriptapi_v2/getting_started.md").toURI()) } catch (e: Exception) { LOGGER.error("Something went wrong while trying to open the web scripts docs.", e) - MiscUtils.showErrorPopup("Scripts Error | Manual Link", "github.com/CCBlueX/Documentation/blob/master/md/scriptapi_v2/getting_started.md") + MiscUtils.showErrorPopup( + "Scripts Error | Manual Link", + "github.com/CCBlueX/Documentation/blob/master/md/scriptapi_v2/getting_started.md" + ) } 6 -> try { @@ -166,7 +172,7 @@ class GuiScripts(private val prevGui: GuiScreen) : GuiScreen() { } private inner class GuiList(gui: GuiScreen) : - GuiSlot(mc, gui.width, gui.height, 40, gui.height - 40, 30) { + GuiSlot(mc, gui.width, gui.height, 40, gui.height - 40, 30) { private var selectedSlot = 0 @@ -183,10 +189,20 @@ class GuiScripts(private val prevGui: GuiScreen) : GuiScreen() { override fun drawSlot(id: Int, x: Int, y: Int, var4: Int, var5: Int, var6: Int) { val script = scripts[id] - Fonts.font40.drawCenteredString("§9" + script.scriptName + " §7v" + script.scriptVersion, width / 2f, y + 2f, Color.LIGHT_GRAY.rgb) - Fonts.font40.drawCenteredString("by §c" + script.scriptAuthors.joinToString(", "), width / 2f, y + 15f, Color.LIGHT_GRAY.rgb).coerceAtLeast(x) + Fonts.font40.drawCenteredString( + "§9" + script.scriptName + " §7v" + script.scriptVersion, + width / 2f, + y + 2f, + Color.LIGHT_GRAY.rgb + ) + Fonts.font40.drawCenteredString( + "by §c" + script.scriptAuthors.joinToString(", "), + width / 2f, + y + 15f, + Color.LIGHT_GRAY.rgb + ).coerceAtLeast(x) } - override fun drawBackground() { } + override fun drawBackground() {} } } diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiServerStatus.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiServerStatus.kt index b450904b042..a5576e09bdc 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiServerStatus.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiServerStatus.kt @@ -9,16 +9,17 @@ import kotlinx.coroutines.launch import net.ccbluex.liquidbounce.lang.translationMenu import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.ui.font.Fonts -import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes import net.ccbluex.liquidbounce.utils.io.HttpUtils.responseCode +import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRect +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import org.lwjgl.input.Keyboard import java.awt.Color import java.io.IOException -class GuiServerStatus(private val prevGui: GuiScreen) : GuiScreen() { +class GuiServerStatus(private val prevGui: GuiScreen) : AbstractScreen() { private val status = hashMapOf( "https://api.mojang.com" to null, "http://session.minecraft.net" to null, @@ -30,7 +31,7 @@ class GuiServerStatus(private val prevGui: GuiScreen) : GuiScreen() { ) override fun initGui() { - buttonList.add(GuiButton(1, width / 2 - 100, height / 4 + 145, "Back")) + +GuiButton(1, width / 2 - 100, height / 4 + 145, "Back") loadInformation() } @@ -68,7 +69,13 @@ class GuiServerStatus(private val prevGui: GuiScreen) : GuiScreen() { i += Fonts.font40.fontHeight } - Fonts.fontBold180.drawCenteredString(translationMenu("serverStatus"), width / 2F, height / 8f + 5F, 4673984, true) + Fonts.fontBold180.drawCenteredString( + translationMenu("serverStatus"), + width / 2F, + height / 8f + 5F, + 4673984, + true + ) } @@ -76,9 +83,8 @@ class GuiServerStatus(private val prevGui: GuiScreen) : GuiScreen() { } private fun loadInformation() { - status.replaceAll { _, _ -> null } - for (url in status.keys) { + status[url] = null SharedScopes.IO.launch { try { val responseCode = responseCode(url, "GET") diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiUpdate.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiUpdate.kt index 480442bcb62..81b3bfa42f3 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiUpdate.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiUpdate.kt @@ -10,33 +10,41 @@ import net.ccbluex.liquidbounce.api.ClientUpdate import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.io.MiscUtils +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton -import net.minecraft.client.gui.GuiScreen import org.lwjgl.input.Keyboard import org.lwjgl.opengl.GL11.glScalef import java.awt.Color -class GuiUpdate : GuiScreen() { +class GuiUpdate : AbstractScreen() { override fun initGui() { val j = height / 4 + 48 - buttonList.run { - add(GuiButton(1, width / 2 + 2, j + 24 * 2, 98, 20, "Ignore")) - add(GuiButton(2, width / 2 - 100, j + 24 * 2, 98, 20, "Go to download page")) - } + +GuiButton(1, width / 2 + 2, j + 24 * 2, 98, 20, "Ignore") + +GuiButton(2, width / 2 - 100, j + 24 * 2, 98, 20, "Go to download page") } override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) = assumeNonVolatile { drawBackground(0) if (!IN_DEV) { - Fonts.font35.drawCenteredString("${ClientUpdate.newestVersion?.lbVersion} got released!", width / 2f, height / 8f + 80, 0xffffff) + Fonts.font35.drawCenteredString( + "${ClientUpdate.newestVersion?.lbVersion} got released!", + width / 2f, + height / 8f + 80, + 0xffffff + ) } else { Fonts.font35.drawCenteredString("New build available!", width / 2f, height / 8f + 80, 0xffffff) } - Fonts.font35.drawCenteredString("Press \"Download\" to visit our website or dismiss this message by pressing \"OK\".", width / 2f, height / 8f + 80 + Fonts.font35.fontHeight, 0xffffff) + Fonts.font35.drawCenteredString( + "Press \"Download\" to visit our website or dismiss this message by pressing \"OK\".", + width / 2f, + height / 8f + 80 + Fonts.font35.fontHeight, + 0xffffff + ) super.drawScreen(mouseX, mouseY, partialTicks) diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiWelcome.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiWelcome.kt index 37bf6f4496c..122b76052dc 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiWelcome.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/GuiWelcome.kt @@ -8,16 +8,16 @@ package net.ccbluex.liquidbounce.ui.client import net.ccbluex.liquidbounce.features.module.modules.render.ClickGUI import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.ui.font.Fonts +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton -import net.minecraft.client.gui.GuiScreen import org.lwjgl.input.Keyboard import org.lwjgl.opengl.GL11.glScalef import java.awt.Color -class GuiWelcome : GuiScreen() { +class GuiWelcome : AbstractScreen() { override fun initGui() { - buttonList.add(GuiButton(1, width / 2 - 100, height - 40, "Ok")) + +GuiButton(1, width / 2 - 100, height - 40, "OK") } override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) = assumeNonVolatile { @@ -25,20 +25,74 @@ class GuiWelcome : GuiScreen() { Fonts.font35.run { drawCenteredString("Thank you for downloading and installing our client!", width / 2F, 70f, 0xffffff, true) - drawCenteredString("Here is some information you might find useful if you are using LiquidBounce for the first time.", width / 2F, 70f + fontHeight, 0xffffff, true) + drawCenteredString( + "Here is some information you might find useful if you are using LiquidBounce for the first time.", + width / 2F, + 70f + fontHeight, + 0xffffff, + true + ) drawCenteredString("§lClickGUI:", width / 2F, 80f + fontHeight * 3, 0xffffff, true) - drawCenteredString("Press ${Keyboard.getKeyName(ClickGUI.keyBind)} to open up the ClickGUI", width / 2F, 80f + fontHeight * 4, 0xffffff, true) - drawCenteredString("Right-click modules with a '+' next to them to edit their settings.", width / 2F, 80f + fontHeight * 5, 0xffffff, true) - drawCenteredString("Hover a module to see it's description.", width / 2F, 80f + fontHeight * 6, 0xffffff, true) + drawCenteredString( + "Press ${Keyboard.getKeyName(ClickGUI.keyBind)} to open up the ClickGUI", + width / 2F, + 80f + fontHeight * 4, + 0xffffff, + true + ) + drawCenteredString( + "Right-click modules with a '+' next to them to edit their settings.", + width / 2F, + 80f + fontHeight * 5, + 0xffffff, + true + ) + drawCenteredString( + "Hover a module to see it's description.", + width / 2F, + 80f + fontHeight * 6, + 0xffffff, + true + ) drawCenteredString("§lImportant Commands:", width / 2F, 80f + fontHeight * 8, 0xffffff, true) - drawCenteredString(".bind / .bind none", width / 2F, 80f + fontHeight * 9, 0xffffff, true) - drawCenteredString(".autosettings load / .autosettings list", width / 2F, 80f + fontHeight * 10, 0xffffff, true) + drawCenteredString( + ".bind / .bind none", + width / 2F, + 80f + fontHeight * 9, + 0xffffff, + true + ) + drawCenteredString( + ".autosettings load / .autosettings list", + width / 2F, + 80f + fontHeight * 10, + 0xffffff, + true + ) - drawCenteredString("§lNeed help? Feel free to contact us!", width / 2F, 80f + fontHeight * 12, 0xffffff, true) - drawCenteredString("YouTube: https://youtube.com/ccbluex", width / 2F, 80f + fontHeight * 13, 0xffffff, true) - drawCenteredString("Twitter: https://twitter.com/ccbluex", width / 2F, 80f + fontHeight * 14, 0xffffff, true) + drawCenteredString( + "§lNeed help? Feel free to contact us!", + width / 2F, + 80f + fontHeight * 12, + 0xffffff, + true + ) + drawCenteredString( + "YouTube: https://youtube.com/ccbluex", + width / 2F, + 80f + fontHeight * 13, + 0xffffff, + true + ) + drawCenteredString( + "Twitter: https://twitter.com/ccbluex", + width / 2F, + 80f + fontHeight * 14, + 0xffffff, + true + ) drawCenteredString("Forum: https://forums.ccbluex.net/", width / 2F, 80f + fontHeight * 15, 0xffffff, true) } diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/GuiAltManager.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/GuiAltManager.kt index ed43c9cc72b..7408d472993 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/GuiAltManager.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/GuiAltManager.kt @@ -26,11 +26,12 @@ import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolat import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER import net.ccbluex.liquidbounce.utils.client.MinecraftInstance.Companion.mc -import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes -import net.ccbluex.liquidbounce.utils.login.UserUtils.isValidTokenOffline import net.ccbluex.liquidbounce.utils.io.HttpUtils.get import net.ccbluex.liquidbounce.utils.io.MiscUtils import net.ccbluex.liquidbounce.utils.kotlin.RandomUtils.randomAccount +import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes +import net.ccbluex.liquidbounce.utils.login.UserUtils.isValidTokenOffline +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiSlot @@ -42,7 +43,7 @@ import java.awt.Toolkit import java.awt.datatransfer.StringSelection import java.util.* -class GuiAltManager(private val prevGui: GuiScreen) : GuiScreen() { +class GuiAltManager(private val prevGui: GuiScreen) : AbstractScreen() { var status = "§7Idle..." @@ -74,25 +75,23 @@ class GuiAltManager(private val prevGui: GuiScreen) : GuiScreen() { // Setup buttons val startPositionY = 22 - with(buttonList) { - add(GuiButton(1, width - 80, startPositionY + 24, 70, 20, "Add").also { addButton = it }) - add(GuiButton(2, width - 80, startPositionY + 24 * 2, 70, 20, "Remove").also { removeButton = it }) - add(GuiButton(7, width - 80, startPositionY + 24 * 3, 70, 20, "Import")) - add(GuiButton(12, width - 80, startPositionY + 24 * 4, 70, 20, "Export")) - add(GuiButton(8, width - 80, startPositionY + 24 * 5, 70, 20, "Copy").also { copyButton = it }) - add(GuiButton(0, width - 80, height - 65, 70, 20, "Back")) - add(GuiButton(3, 5, startPositionY + 24, 90, 20, "Login").also { loginButton = it }) - add(GuiButton(4, 5, startPositionY + 24 * 2, 90, 20, "Random Alt").also { randomAltButton = it }) - add(GuiButton(5, 5, startPositionY + 24 * 3, 90, 20, "Random Name").also { randomNameButton = it }) - add(GuiButton(6, 5, startPositionY + 24 * 4, 90, 20, "Direct Login")) - add(GuiButton(10, 5, startPositionY + 24 * 5, 90, 20, "Session Login")) - - if (activeGenerators.getOrDefault("thealtening", true)) { - add(GuiButton(9, 5, startPositionY + 24 * 6, 90, 20, "TheAltening")) - } - - add(GuiButton(11, 5, startPositionY + 24 * 7, 90, 20, "Cape")) + addButton = +GuiButton(1, width - 80, startPositionY + 24, 70, 20, "Add") + removeButton = +GuiButton(2, width - 80, startPositionY + 24 * 2, 70, 20, "Remove") + +GuiButton(7, width - 80, startPositionY + 24 * 3, 70, 20, "Import") + +GuiButton(12, width - 80, startPositionY + 24 * 4, 70, 20, "Export") + copyButton = +GuiButton(8, width - 80, startPositionY + 24 * 5, 70, 20, "Copy") + +GuiButton(0, width - 80, height - 65, 70, 20, "Back") + loginButton = +GuiButton(3, 5, startPositionY + 24, 90, 20, "Login") + randomAltButton = +GuiButton(4, 5, startPositionY + 24 * 2, 90, 20, "Random Alt") + randomNameButton = +GuiButton(5, 5, startPositionY + 24 * 3, 90, 20, "Random Name") + +GuiButton(6, 5, startPositionY + 24 * 4, 90, 20, "Direct Login") + +GuiButton(10, 5, startPositionY + 24 * 5, 90, 20, "Session Login") + + if (activeGenerators.getOrDefault("thealtening", true)) { + +GuiButton(9, 5, startPositionY + 24 * 6, 90, 20, "TheAltening") } + + +GuiButton(11, 5, startPositionY + 24 * 7, 90, 20, "Cape") } override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiDonatorCape.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiDonatorCape.kt index 1741b786407..2191428feac 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiDonatorCape.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiDonatorCape.kt @@ -13,12 +13,12 @@ import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolat import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.io.MiscUtils import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRect +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton -import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiTextField import org.lwjgl.input.Keyboard -class GuiDonatorCape(private val prevGui: GuiAltManager) : GuiScreen() { +class GuiDonatorCape(private val prevGui: GuiAltManager) : AbstractScreen() { // Buttons private lateinit var upperButton: GuiButton @@ -48,13 +48,10 @@ class GuiDonatorCape(private val prevGui: GuiAltManager) : GuiScreen() { else "Enable visibility" - buttonList.run{ - add(GuiButton(1, width / 2 - 100, height / 2 - 60, upperButtonText).apply { upperButton = this }) - add(GuiButton(2, width / 2 - 100, height / 2 - 35, if (loggedIntoAccount) "Logout" else "Donate to get Cape").apply { lowerButton = this }) - add(GuiButton(0, width / 2 - 100, height / 2 + 30, "Back")) - } - - + upperButton = +GuiButton(1, width / 2 - 100, height / 2 - 60, upperButtonText) + lowerButton = + +GuiButton(2, width / 2 - 100, height / 2 - 35, if (loggedIntoAccount) "Logout" else "Donate to get Cape") + +GuiButton(0, width / 2 - 100, height / 2 + 30, "Back") // Add fields to screen transferCodeField = GuiPasswordField(666, Fonts.font40, width / 2 - 100, height / 2 - 90, 200, 20) @@ -69,7 +66,7 @@ class GuiDonatorCape(private val prevGui: GuiAltManager) : GuiScreen() { /** * Draw screen */ - override fun drawScreen(mouseX : Int, mouseY : Int, partialTicks : Float) { + override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { assumeNonVolatile { // Draw background to screen drawBackground(0) @@ -80,7 +77,12 @@ class GuiDonatorCape(private val prevGui: GuiAltManager) : GuiScreen() { if (loggedIntoAccount) { CapeService.clientCapeUser?.run { Fonts.font40.drawCenteredString("§cCape: §f$capeName", width / 2f, height / 2 - 100f, 0xffffff) - Fonts.font40.drawCenteredString("§cVisible to others: §f${if (enabled) "Yes" else "No"}", width / 2f, height / 2 - 90f, 0xffffff) + Fonts.font40.drawCenteredString( + "§cVisible to others: §f${if (enabled) "Yes" else "No"}", + width / 2f, + height / 2 - 90f, + 0xffffff + ) Fonts.font40.drawCenteredString("§cOn account: §f$uuid", width / 2f, height / 2 - 80f, 0xffffff) } } @@ -150,6 +152,7 @@ class GuiDonatorCape(private val prevGui: GuiAltManager) : GuiScreen() { } } } + 2 -> { if (loggedIntoAccount) { CapeService.logout() @@ -166,7 +169,7 @@ class GuiDonatorCape(private val prevGui: GuiAltManager) : GuiScreen() { /** * Handle key typed */ - override fun keyTyped(typedChar : Char, keyCode : Int) { + override fun keyTyped(typedChar: Char, keyCode: Int) { when (keyCode) { // Check if user want to escape from screen Keyboard.KEY_ESCAPE -> { @@ -197,7 +200,7 @@ class GuiDonatorCape(private val prevGui: GuiAltManager) : GuiScreen() { /** * Handle mouse clicked */ - override fun mouseClicked(mouseX : Int, mouseY : Int, mouseButton : Int) { + override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) { // Call mouse clicked to field if (!loggedIntoAccount) { transferCodeField.mouseClicked(mouseX, mouseY, mouseButton) diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiLoginIntoAccount.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiLoginIntoAccount.kt index 3acf43473ec..eb7684cb812 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiLoginIntoAccount.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiLoginIntoAccount.kt @@ -14,14 +14,14 @@ import net.ccbluex.liquidbounce.ui.client.altmanager.GuiAltManager import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.kotlin.RandomUtils.randomUsername +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton -import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiTextField import net.minecraft.util.Session import org.lwjgl.input.Keyboard import java.io.IOException -class GuiLoginIntoAccount(private val prevGui: GuiAltManager, val directLogin: Boolean = false) : GuiScreen() { +class GuiLoginIntoAccount(private val prevGui: GuiAltManager, val directLogin: Boolean = false) : AbstractScreen() { private lateinit var addButton: GuiButton private lateinit var username: GuiTextField @@ -32,19 +32,16 @@ class GuiLoginIntoAccount(private val prevGui: GuiAltManager, val directLogin: B Keyboard.enableRepeatEvents(true) // Add button - buttonList.run { - add(GuiButton(1, width / 2 - 100, height / 2 - 60 , if (directLogin) "Login" else "Add") - .also { addButton = it }) + addButton = +GuiButton(1, width / 2 - 100, height / 2 - 60, if (directLogin) "Login" else "Add") - // Random button - add(GuiButton(2, width / 2 + 105, height / 2 - 90, 40, 20, "Random")) + // Random button + +GuiButton(2, width / 2 + 105, height / 2 - 90, 40, 20, "Random") - // Login via Microsoft account - add(GuiButton(3, width / 2 - 100, height / 2, "${if (directLogin) "Login to" else "Add"} a Microsoft account")) + // Login via Microsoft account + +GuiButton(3, width / 2 - 100, height / 2, "${if (directLogin) "Login to" else "Add"} a Microsoft account") - // Back button - add(GuiButton(0, width / 2 - 100, height / 2 + 30, "Back")) - } + // Back button + +GuiButton(0, width / 2 - 100, height / 2 + 30, "Back") username = GuiTextField(2, Fonts.font40, width / 2 - 100, height / 2 - 90, 200, 20) username.isFocused = false @@ -56,8 +53,18 @@ class GuiLoginIntoAccount(private val prevGui: GuiAltManager, val directLogin: B drawBackground(0) drawRect(30, 30, width - 30, height - 30, Int.MIN_VALUE) - Fonts.font40.drawCenteredString(if (directLogin) "Direct Login" else "Add Account", width / 2f, height / 2 - 170f, 0xffffff) - Fonts.font40.drawCenteredString("§7${if (directLogin) "Login to" else "Add"} an offline account", width / 2f, height / 2 - 110f, 0xffffff) + Fonts.font40.drawCenteredString( + if (directLogin) "Direct Login" else "Add Account", + width / 2f, + height / 2 - 170f, + 0xffffff + ) + Fonts.font40.drawCenteredString( + "§7${if (directLogin) "Login to" else "Add"} an offline account", + width / 2f, + height / 2 - 110f, + 0xffffff + ) Fonts.font35.drawCenteredString(status, width / 2f, height / 2f - 30, 0xffffff) username.drawTextBox() diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiLoginProgress.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiLoginProgress.kt index 5c0ce4faf5b..5b906f9346f 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiLoginProgress.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiLoginProgress.kt @@ -9,9 +9,14 @@ import me.liuli.elixir.account.MinecraftAccount import net.ccbluex.liquidbounce.ui.client.altmanager.GuiAltManager.Companion.login import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawLoadingCircle -import net.minecraft.client.gui.GuiScreen +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen -class GuiLoginProgress(minecraftAccount: MinecraftAccount, success: () -> Unit, error: (Exception) -> Unit, done: () -> Unit) : GuiScreen() { +class GuiLoginProgress( + minecraftAccount: MinecraftAccount, + success: () -> Unit, + error: (Exception) -> Unit, + done: () -> Unit +) : AbstractScreen() { init { login(minecraftAccount, success, error, done) diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiMicrosoftLoginProgress.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiMicrosoftLoginProgress.kt index 17b602ce966..d655c503385 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiMicrosoftLoginProgress.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiMicrosoftLoginProgress.kt @@ -14,11 +14,11 @@ import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER import net.ccbluex.liquidbounce.utils.io.MiscUtils import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawLoadingCircle +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton -import net.minecraft.client.gui.GuiScreen import java.net.BindException -class GuiMicrosoftLoginProgress(val updateStatus: (String) -> Unit, val done: () -> Unit) : GuiScreen() { +class GuiMicrosoftLoginProgress(val updateStatus: (String) -> Unit, val done: () -> Unit) : AbstractScreen() { private var oAuthServer: OAuthServer? = null private var loginUrl: String? = null @@ -73,10 +73,9 @@ class GuiMicrosoftLoginProgress(val updateStatus: (String) -> Unit, val done: () LOGGER.error("Failed to start login server.", e) } - buttonList.run { - add(GuiButton(0, width / 2 - 100, height / 2 + 60, "Open URL")) - add(GuiButton(1, width / 2 - 100, height / 2 + 90, "Cancel")) - } + +GuiButton(0, width / 2 - 100, height / 2 + 60, "Open URL") + +GuiButton(1, width / 2 - 100, height / 2 + 90, "Cancel") + super.initGui() } diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiSessionLogin.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiSessionLogin.kt index b736c56aa5b..87666becf10 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiSessionLogin.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/GuiSessionLogin.kt @@ -14,12 +14,12 @@ import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes import net.ccbluex.liquidbounce.utils.login.LoginUtils import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRect +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton -import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiTextField import org.lwjgl.input.Keyboard -class GuiSessionLogin(private val prevGui: GuiAltManager) : GuiScreen() { +class GuiSessionLogin(private val prevGui: GuiAltManager) : AbstractScreen() { // Buttons private lateinit var loginButton: GuiButton @@ -38,12 +38,9 @@ class GuiSessionLogin(private val prevGui: GuiAltManager) : GuiScreen() { Keyboard.enableRepeatEvents(true) // Add buttons to screen + loginButton = +GuiButton(1, width / 2 - 100, height / 2 - 60, "Login") - buttonList.run { - add(GuiButton(1, width / 2 - 100, height / 2 - 60, "Login").also { loginButton = it }) - - add(GuiButton(0, width / 2 - 100, height / 2 - 30, "Back")) - } + +GuiButton(0, width / 2 - 100, height / 2 - 30, "Back") // Add fields to screen sessionTokenField = GuiTextField(666, Fonts.font40, width / 2 - 100, height / 2 - 90, 200, 20) @@ -107,6 +104,7 @@ class GuiSessionLogin(private val prevGui: GuiAltManager) : GuiScreen() { "§aLogged into §f§l${mc.session.username}§a." } + LoginUtils.LoginResult.FAILED_PARSE_TOKEN -> "§cFailed to parse Session ID!" LoginUtils.LoginResult.INVALID_ACCOUNT_DATA -> "§cInvalid Session ID!" } diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/altgenerator/GuiTheAltening.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/altgenerator/GuiTheAltening.kt index 73b6d866b2b..be078ef1db1 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/altgenerator/GuiTheAltening.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/altmanager/menus/altgenerator/GuiTheAltening.kt @@ -21,17 +21,17 @@ import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolat import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER import net.ccbluex.liquidbounce.utils.client.TabUtils -import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes import net.ccbluex.liquidbounce.utils.io.MiscUtils +import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRect +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton -import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiTextField import net.minecraft.util.Session import org.lwjgl.input.Keyboard import java.net.Proxy.NO_PROXY -class GuiTheAltening(private val prevGui: GuiAltManager) : GuiScreen() { +class GuiTheAltening(private val prevGui: GuiAltManager) : AbstractScreen() { // Data Storage companion object { @@ -57,16 +57,14 @@ class GuiTheAltening(private val prevGui: GuiAltManager) : GuiScreen() { Keyboard.enableRepeatEvents(true) // Login button - buttonList.run { - add(GuiButton(2, width / 2 - 100, height / 2 - 90, "Login").also { loginButton = it }) + loginButton = +GuiButton(2, width / 2 - 100, height / 2 - 90, "Login") - // Generate button - add(GuiButton(1, width / 2 - 100, height / 2, "Generate").also { generateButton = it }) + // Generate button + generateButton = +GuiButton(1, width / 2 - 100, height / 2, "Generate") - // Buy & Back buttons - add(GuiButton(3, width / 2 - 100, height / 2 + 70, 98, 20, "Buy")) - add(GuiButton(0, width / 2 + 2, height / 2 + 70, 98, 20, "Back")) - } + // Buy & Back buttons + +GuiButton(3, width / 2 - 100, height / 2 + 70, 98, 20, "Buy") + +GuiButton(0, width / 2 + 2, height / 2 + 70, 98, 20, "Back") // Token text field tokenField = GuiTextField(666, Fonts.font40, width / 2 - 100, height / 2 - 120, 200, 20) @@ -102,7 +100,12 @@ class GuiTheAltening(private val prevGui: GuiAltManager) : GuiScreen() { Fonts.font40.drawCenteredString("§7Token", width / 2f - 82, height / 2 - 114f, 0xffffff) if (apiKeyField.text.isEmpty() && !apiKeyField.isFocused) Fonts.font40.drawCenteredString("§7API-Key", width / 2f - 78, height / 2 - 24f, 0xffffff) - Fonts.font40.drawCenteredString("§7Use coupon code 'liquidbounce' for 20% off!", width / 2f, height / 2 + 55f, 0xffffff) + Fonts.font40.drawCenteredString( + "§7Use coupon code 'liquidbounce' for 20% off!", + width / 2f, + height / 2 + 55f, + 0xffffff + ) } super.drawScreen(mouseX, mouseY, partialTicks) @@ -137,19 +140,23 @@ class GuiTheAltening(private val prevGui: GuiAltManager) : GuiScreen() { status = "§cLogging in..." // Set token as username - val yggdrasilUserAuthentication = YggdrasilUserAuthentication(YggdrasilAuthenticationService(NO_PROXY, ""), MINECRAFT) + val yggdrasilUserAuthentication = + YggdrasilUserAuthentication(YggdrasilAuthenticationService(NO_PROXY, ""), MINECRAFT) yggdrasilUserAuthentication.setUsername(account.token) yggdrasilUserAuthentication.setPassword(CLIENT_NAME) status = try { yggdrasilUserAuthentication.logIn() - mc.session = Session(yggdrasilUserAuthentication.selectedProfile.name, yggdrasilUserAuthentication + mc.session = Session( + yggdrasilUserAuthentication.selectedProfile.name, yggdrasilUserAuthentication .selectedProfile.id.toString(), - yggdrasilUserAuthentication.authenticatedToken, "microsoft") + yggdrasilUserAuthentication.authenticatedToken, "microsoft" + ) call(SessionUpdateEvent) - prevGui.status = "§aYour name is now §b§l${yggdrasilUserAuthentication.selectedProfile.name}§c." + prevGui.status = + "§aYour name is now §b§l${yggdrasilUserAuthentication.selectedProfile.name}§c." mc.displayGuiScreen(prevGui) "" } catch (e: AuthenticationException) { @@ -173,6 +180,7 @@ class GuiTheAltening(private val prevGui: GuiAltManager) : GuiScreen() { generateButton.enabled = true } } + 2 -> { loginButton.enabled = false generateButton.enabled = false @@ -186,19 +194,23 @@ class GuiTheAltening(private val prevGui: GuiAltManager) : GuiScreen() { status = "§cLogging in..." // Set token as username - val yggdrasilUserAuthentication = YggdrasilUserAuthentication(YggdrasilAuthenticationService(NO_PROXY, ""), MINECRAFT) + val yggdrasilUserAuthentication = + YggdrasilUserAuthentication(YggdrasilAuthenticationService(NO_PROXY, ""), MINECRAFT) yggdrasilUserAuthentication.setUsername(tokenField.text) yggdrasilUserAuthentication.setPassword(CLIENT_NAME) status = try { yggdrasilUserAuthentication.logIn() - mc.session = Session(yggdrasilUserAuthentication.selectedProfile.name, yggdrasilUserAuthentication + mc.session = Session( + yggdrasilUserAuthentication.selectedProfile.name, yggdrasilUserAuthentication .selectedProfile.id.toString(), - yggdrasilUserAuthentication.authenticatedToken, "microsoft") + yggdrasilUserAuthentication.authenticatedToken, "microsoft" + ) call(SessionUpdateEvent) - prevGui.status = "§aYour name is now §b§l${yggdrasilUserAuthentication.selectedProfile.name}§c." + prevGui.status = + "§aYour name is now §b§l${yggdrasilUserAuthentication.selectedProfile.name}§c." mc.displayGuiScreen(prevGui) "§aYour name is now §b§l${yggdrasilUserAuthentication.selectedProfile.name}§c." } catch (e: AuthenticationException) { @@ -216,6 +228,7 @@ class GuiTheAltening(private val prevGui: GuiAltManager) : GuiScreen() { generateButton.enabled = true } } + 3 -> MiscUtils.showURL("https://thealtening.com/?ref=liquidbounce") } } diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt index fe41a280842..10cf488943b 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt @@ -12,6 +12,7 @@ import net.ccbluex.liquidbounce.ui.font.Fonts import net.ccbluex.liquidbounce.utils.client.TabUtils import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes import net.ccbluex.liquidbounce.utils.io.MiscUtils +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiTextField @@ -23,7 +24,7 @@ import java.net.Socket import java.util.concurrent.atomic.AtomicInteger import javax.swing.JOptionPane -class GuiPortScanner(private val prevGui: GuiScreen) : GuiScreen() { +class GuiPortScanner(private val prevGui: GuiScreen) : AbstractScreen() { private val ports = LinkedHashSet() @@ -79,9 +80,9 @@ class GuiPortScanner(private val prevGui: GuiScreen) : GuiScreen() { } } - buttonList.add(GuiButton(1, width / 2 - 100, height / 4 + 95, if (running) "Stop" else "Start").also { buttonToggle = it }) - buttonList.add(GuiButton(0, width / 2 - 100, height / 4 + 120, "Back")) - buttonList.add(GuiButton(2, width / 2 - 100, height / 4 + 155, "Export")) + buttonToggle = +GuiButton(1, width / 2 - 100, height / 4 + 95, if (running) "Stop" else "Start") + +GuiButton(0, width / 2 - 100, height / 4 + 120, "Back") + +GuiButton(2, width / 2 - 100, height / 4 + 155, "Export") super.initGui() } diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiTools.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiTools.kt index a08862e1d21..fbc254dd77d 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiTools.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiTools.kt @@ -7,17 +7,16 @@ package net.ccbluex.liquidbounce.ui.client.tools import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.ui.font.Fonts +import net.ccbluex.liquidbounce.utils.ui.AbstractScreen import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import org.lwjgl.input.Keyboard -class GuiTools(private val prevGui: GuiScreen) : GuiScreen() { +class GuiTools(private val prevGui: GuiScreen) : AbstractScreen() { override fun initGui() { - buttonList.run { - add(GuiButton(1, width / 2 - 100, height / 4 + 48 + 25, "Port Scanner")) - add(GuiButton(0, width / 2 - 100, height / 4 + 48 + 25 * 2 + 5, "Back")) - } + +GuiButton(1, width / 2 - 100, height / 4 + 48 + 25, "Port Scanner") + +GuiButton(0, width / 2 - 100, height / 4 + 48 + 25 * 2 + 5, "Back") } override fun actionPerformed(button: GuiButton) { diff --git a/src/main/java/net/ccbluex/liquidbounce/utils/ui/GuiExtensions.kt b/src/main/java/net/ccbluex/liquidbounce/utils/ui/GuiExtensions.kt new file mode 100644 index 00000000000..05d55f5648e --- /dev/null +++ b/src/main/java/net/ccbluex/liquidbounce/utils/ui/GuiExtensions.kt @@ -0,0 +1,13 @@ +package net.ccbluex.liquidbounce.utils.ui + +import net.minecraft.client.gui.GuiButton +import net.minecraft.client.gui.GuiScreen + +abstract class AbstractScreen : GuiScreen() { + + protected operator fun T.unaryPlus(): T { + buttonList.add(this) + return this + } + +} \ No newline at end of file From 804c22dcebf558e3264ac05856a179ce4bd78cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E8=91=89=20Scarlet?= <93977077+mukjepscarlet@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:09:37 +0800 Subject: [PATCH 4/4] GuiPortScanner file writer --- .../ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt index 10cf488943b..7aba049d72e 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/tools/GuiPortScanner.kt @@ -186,8 +186,8 @@ class GuiPortScanner(private val prevGui: GuiScreen) : AbstractScreen() { try { if (!selectedFile.exists()) selectedFile.createNewFile() - FileWriter(selectedFile).use { fileWriter -> - fileWriter.write("Portscan\r\n") + selectedFile.bufferedWriter().use { fileWriter -> + fileWriter.write("PortScanner Result\r\n") fileWriter.write("Host: $host\r\n\r\n") fileWriter.write("Ports ($minPort - $maxPort):\r\n") ports.forEach { port -> fileWriter.write("$port\r\n") }