Skip to content

Commit

Permalink
refactor(legacy): GuiScreen code cleanup and new API (#4960)
Browse files Browse the repository at this point in the history
  • Loading branch information
MukjepScarlet authored Dec 19, 2024
1 parent 7b2b321 commit 19fd14a
Show file tree
Hide file tree
Showing 20 changed files with 464 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +27,7 @@ import org.lwjgl.opengl.Display
import java.nio.file.Files
import javax.swing.filechooser.FileNameExtensionFilter

class GuiClientConfiguration(val prevGui: GuiScreen) : GuiScreen() {
class GuiClientConfiguration(val prevGui: GuiScreen) : AbstractScreen() {

companion object {
var enabledClientTitle = true
Expand Down Expand Up @@ -65,72 +66,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) {
Expand Down
58 changes: 41 additions & 17 deletions src/main/java/net/ccbluex/liquidbounce/ui/client/GuiClientFixes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,52 @@ 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
private lateinit var proxyButton: GuiButton
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) {
Expand All @@ -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)

Expand All @@ -72,18 +93,21 @@ 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)
}
}

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)
}

Expand All @@ -93,7 +117,7 @@ class GuiClientFixes(private val prevGui: GuiScreen) : GuiScreen() {
mc.displayGuiScreen(prevGui)
return
}

super.keyTyped(typedChar, keyCode)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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<GitHubContributor>::class.java
)

Expand All @@ -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<Credit>()

Expand All @@ -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()
Expand All @@ -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))
}
Expand Down
Loading

0 comments on commit 19fd14a

Please sign in to comment.