Skip to content

Commit

Permalink
feat: (Custom) FontManager
Browse files Browse the repository at this point in the history
  • Loading branch information
opZywl committed Feb 2, 2025
1 parent d7bf8ca commit 8b6d160
Show file tree
Hide file tree
Showing 5 changed files with 472 additions and 147 deletions.
170 changes: 48 additions & 122 deletions src/main/java/net/ccbluex/liquidbounce/ui/client/gui/GuiMainMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import net.ccbluex.liquidbounce.ui.client.gui.button.QuitButton
import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile
import net.ccbluex.liquidbounce.ui.font.Fonts
import net.ccbluex.liquidbounce.ui.font.Fonts.minecraftFont
import net.ccbluex.liquidbounce.ui.font.fontmanager.GuiFontManager
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils.bugs
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils.canConnect
import net.ccbluex.liquidbounce.utils.io.APIConnectorUtils.changelogs
Expand All @@ -37,6 +38,8 @@ class GuiMainMenu : AbstractScreen(), GuiYesNoCallback {
private lateinit var btnSinglePlayer: GuiButton
private lateinit var btnMultiplayer: GuiButton
private lateinit var btnClientOptions: GuiButton
private lateinit var btnFontManager: GuiButton

private lateinit var btnCheckUpdate: GuiButton

private lateinit var btnClickGUI: ImageButton
Expand All @@ -50,51 +53,32 @@ class GuiMainMenu : AbstractScreen(), GuiYesNoCallback {
private lateinit var btnQuit: QuitButton

override fun initGui() {
val basePath = "${CLIENT_NAME.lowercase()}/texture/mainmenu/"
logo = ResourceLocation("${CLIENT_NAME.lowercase()}/texture/mainmenu/logo.png")

val centerY = height / 2 - 80
val buttonWidth = 133
val buttonHeight = 20
btnSinglePlayer = +GuiButton(
0, // ID
width / 2 - 66,
centerY + 70,
buttonWidth, buttonHeight,
"SINGLE PLAYER"
)
btnMultiplayer = +GuiButton(
1,
width / 2 - 66,
centerY + 95 - 2,
buttonWidth, buttonHeight,
"MULTI PLAYER"
)
btnClientOptions = +GuiButton(
2,
width / 2 - 66,
centerY + 120 - 4,
buttonWidth, buttonHeight,
"SETTINGS"
)
btnCheckUpdate = +GuiButton(
3,
width / 2 - 66,
centerY + 145 - 6,
buttonWidth, buttonHeight,
"CHECK UPDATE"
)

btnSinglePlayer = +GuiButton(0, width / 2 - 66, centerY + 70, buttonWidth, buttonHeight, "SINGLE PLAYER")
btnMultiplayer = +GuiButton(1, width / 2 - 66, centerY + 93, buttonWidth, buttonHeight, "MULTI PLAYER")
btnClientOptions = +GuiButton(2, width / 2 - 66, centerY + 116, buttonWidth, buttonHeight, "SETTINGS")
btnFontManager = +GuiButton(3, width / 2 - 66, centerY + 139, buttonWidth, buttonHeight, "FONT MANAGER")

btnCheckUpdate = GuiButton(4, width - 150, 7, 85, 20, "CHECK UPDATE")

buttonList.addAll(listOf(btnSinglePlayer, btnMultiplayer, btnClientOptions, btnFontManager, btnCheckUpdate))

val bottomY = height - 20
btnClickGUI = ImageButton("CLICKGUI", ResourceLocation("${CLIENT_NAME.lowercase()}/texture/mainmenu/clickgui.png"), width / 2 - 45, bottomY)
btnCommitInfo = ImageButton("COMMIT INFO", ResourceLocation("${CLIENT_NAME.lowercase()}/texture/mainmenu/github.png"), width / 2 - 30, bottomY)
btnCosmetics = ImageButton("COSMETICS", ResourceLocation("${CLIENT_NAME.lowercase()}/texture/mainmenu/cosmetics.png"), width / 2 - 15, bottomY)
btnMinecraftOptions = ImageButton("MINECRAFT SETTINGS", ResourceLocation("${CLIENT_NAME.lowercase()}/texture/mainmenu/cog.png"), width / 2, bottomY)
btnLanguage = ImageButton("LANGUAGE", ResourceLocation("${CLIENT_NAME.lowercase()}/texture/mainmenu/globe.png"), width / 2 + 15, bottomY)
btnForgeModList = ImageButton("FORGE MODS", ResourceLocation("${CLIENT_NAME.lowercase()}/texture/mainmenu/forge.png"), width / 2 + 30, bottomY)

btnAddAccount = ImageButton("ALT MANAGER", ResourceLocation("${CLIENT_NAME.lowercase()}/texture/mainmenu/add-account.png"), width - 55, 7)
btnClickGUI = ImageButton("CLICKGUI", ResourceLocation("${basePath}clickgui.png"), width / 2 - 45, bottomY)
btnCommitInfo = ImageButton("COMMIT INFO", ResourceLocation("${basePath}github.png"), width / 2 - 30, bottomY)
btnCosmetics = ImageButton("COSMETICS", ResourceLocation("${basePath}cosmetics.png"), width / 2 - 15, bottomY)
btnMinecraftOptions = ImageButton("MINECRAFT SETTINGS", ResourceLocation("${basePath}cog.png"), width / 2, bottomY)
btnLanguage = ImageButton("LANGUAGE", ResourceLocation("${basePath}globe.png"), width / 2 + 15, bottomY)
btnForgeModList = ImageButton("FORGE MODS", ResourceLocation("${basePath}forge.png"), width / 2 + 30, bottomY)

btnAddAccount = ImageButton("ALT MANAGER", ResourceLocation("${basePath}add-account.png"), width - 55, 7)
btnQuit = QuitButton(width - 17, 7)

buttonList.addAll(listOf(btnSinglePlayer, btnMultiplayer, btnClientOptions, btnCheckUpdate))
}

override fun mouseClicked(mouseX: Int, mouseY: Int, button: Int) {
Expand All @@ -106,20 +90,13 @@ class GuiMainMenu : AbstractScreen(), GuiYesNoCallback {

when {
btnQuit.hoverFade > 0 -> mc.shutdown()
btnMinecraftOptions.hoverFade > 0 ->
mc.displayGuiScreen(GuiOptions(this, mc.gameSettings))
btnLanguage.hoverFade > 0 ->
mc.displayGuiScreen(GuiLanguage(this, mc.gameSettings, mc.languageManager))
btnCommitInfo.hoverFade > 0 ->
mc.displayGuiScreen(GuiCommitInfo())
btnForgeModList.hoverFade > 0 ->
mc.displayGuiScreen(GuiModList(mc.currentScreen))
btnCosmetics.hoverFade > 0 ->
mc.displayGuiScreen(GuiCommitInfo())
btnClickGUI.hoverFade > 0 ->
mc.displayGuiScreen(ClickGui)
btnAddAccount.hoverFade > 0 ->
mc.displayGuiScreen(GuiAltManager(this))
btnMinecraftOptions.hoverFade > 0 -> mc.displayGuiScreen(GuiOptions(this, mc.gameSettings))
btnLanguage.hoverFade > 0 -> mc.displayGuiScreen(GuiLanguage(this, mc.gameSettings, mc.languageManager))
btnCommitInfo.hoverFade > 0 -> mc.displayGuiScreen(GuiCommitInfo())
btnForgeModList.hoverFade > 0 -> mc.displayGuiScreen(GuiModList(mc.currentScreen))
btnCosmetics.hoverFade > 0 -> mc.displayGuiScreen(GuiCommitInfo())
btnClickGUI.hoverFade > 0 -> mc.displayGuiScreen(ClickGui)
btnAddAccount.hoverFade > 0 -> mc.displayGuiScreen(GuiAltManager(this))
}
}

Expand All @@ -128,13 +105,13 @@ class GuiMainMenu : AbstractScreen(), GuiYesNoCallback {
0 -> mc.displayGuiScreen(GuiSelectWorld(this))
1 -> mc.displayGuiScreen(GuiMultiplayer(this))
2 -> mc.displayGuiScreen(GuiInfo(this))
3 -> mc.displayGuiScreen(GuiUpdate())
3 -> mc.displayGuiScreen(GuiFontManager(this))
4 -> mc.displayGuiScreen(GuiUpdate())
}
}

override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) {
assumeNonVolatile = true

drawBackground(0)

if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
Expand All @@ -143,6 +120,7 @@ class GuiMainMenu : AbstractScreen(), GuiYesNoCallback {

GlStateManager.pushMatrix()

// background
drawShadowRect(
(width / 2 - 130).toFloat(),
(height / 2 - 90).toFloat(),
Expand All @@ -169,21 +147,11 @@ class GuiMainMenu : AbstractScreen(), GuiYesNoCallback {
)

val apiMessage = if (canConnect) "§eOK" else "§cNo"
val aply = width - 10f - minecraftFont.getStringWidth("API Connection: $apiMessage")
minecraftFont.drawStringWithShadow(
"API Connection: $apiMessage",
aply,
32f,
Color(255, 255, 255, 140).rgb
)
val apiTextX = width - 10f - minecraftFont.getStringWidth("API Connection: $apiMessage")
minecraftFont.drawStringWithShadow("API Connection: $apiMessage", apiTextX, 32f, Color(255, 255, 255, 140).rgb)

val textClientNameX = width - 4f - minecraftFont.getStringWidth(CLIENT_NAME)
minecraftFont.drawStringWithShadow(
CLIENT_NAME,
textClientNameX,
height - 23f,
Color(255, 255, 255, 140).rgb
)
val clientNameX = width - 4f - minecraftFont.getStringWidth(CLIENT_NAME)
minecraftFont.drawStringWithShadow(CLIENT_NAME, clientNameX, height - 23f, Color(255, 255, 255, 140).rgb)

val uiMessage = when {
canConnect && isLatest -> " §e(Latest)"
Expand All @@ -192,90 +160,48 @@ class GuiMainMenu : AbstractScreen(), GuiYesNoCallback {
}
val buildInfoText = "Your currently build is $clientVersionText$uiMessage"
val buildInfoX = width - 4f - minecraftFont.getStringWidth(buildInfoText)
minecraftFont.drawStringWithShadow(
buildInfoText,
buildInfoX,
height - 12f,
Color(255, 255, 255, 140).rgb
)
minecraftFont.drawStringWithShadow(buildInfoText, buildInfoX, height - 12f, Color(255, 255, 255, 140).rgb)

minecraftFont.drawStringWithShadow(
"Changelogs:",
3f,
32f,
Color(255, 255, 255, 150).rgb
)
minecraftFont.drawStringWithShadow("Changelogs:", 3f, 32f, Color(255, 255, 255, 150).rgb)

var changeY = 48
val changeDetails = changelogs.split("\n")
for (line in changeDetails) {
val formatted = formatChangelogLine(line)
minecraftFont.drawStringWithShadow(
formatted,
4f,
changeY.toFloat(),
Color(255, 255, 255, 150).rgb
)
minecraftFont.drawStringWithShadow(formatted, 4f, changeY.toFloat(), Color(255, 255, 255, 150).rgb)
changeY += 8
}

val knownBugsText = "Known Bugs:"
val mess = width - 10f - minecraftFont.getStringWidth(knownBugsText)
minecraftFont.drawStringWithShadow(
knownBugsText,
mess,
43f,
Color(255, 255, 255, 140).rgb
)
val bugsLabelX = width - 10f - minecraftFont.getStringWidth(knownBugsText)
minecraftFont.drawStringWithShadow(knownBugsText, bugsLabelX, 43f, Color(255, 255, 255, 140).rgb)

var bugsY = 55
val bugDetails = bugs.split("\n")
for (line in bugDetails) {
val lineWidth = minecraftFont.getStringWidth(line)
val xPos = width - 12f - lineWidth
minecraftFont.drawStringWithShadow(
line,
xPos,
bugsY.toFloat(),
Color(255, 255, 255, 140).rgb
)
minecraftFont.drawStringWithShadow(line, xPos, bugsY.toFloat(), Color(255, 255, 255, 140).rgb)
bugsY += 11
}

Fonts.InterMedium_15.drawCenteredStringShadow(
"by Zywl <3 ",
width / 2f,
height / 2f - 19,
Color(255, 255, 255, 100).rgb
)
Fonts.InterMedium_15.drawCenteredStringShadow("by Zywl <3 ", width / 2f, height / 2f - 19, Color(255, 255, 255, 100).rgb)

listOf(btnSinglePlayer, btnMultiplayer, btnClientOptions, btnCheckUpdate).forEach {
it.drawButton(mc, mouseX, mouseY)
}
buttonList.forEach { it.drawButton(mc, mouseX, mouseY) }

listOf(
btnClickGUI, btnCommitInfo, btnCosmetics, btnMinecraftOptions,
btnLanguage, btnForgeModList, btnAddAccount, btnQuit
).forEach {
it.drawButton(mc, mouseX, mouseY)
}
listOf(btnClickGUI, btnCommitInfo, btnCosmetics, btnMinecraftOptions, btnLanguage, btnForgeModList, btnAddAccount, btnQuit)
.forEach { it.drawButton(mc, mouseX, mouseY) }

val branch = GitUtils.gitBranch
val commitIdAbbrev = GitUtils.gitInfo.getProperty("git.commit.id.abbrev")
val infoStr = "$CLIENT_NAME($branch/$commitIdAbbrev) | Minecraft 1.8.9"
Fonts.fontSemibold35.drawCenteredString(
infoStr,
7F,
(this.height - 11).toFloat(),
Color(255, 255, 255, 100).rgb
)
Fonts.fontSemibold35.drawCenteredString(infoStr, 7F, (height - 11).toFloat(), Color(255, 255, 255, 100).rgb)

drawBloom(mouseX - 5, mouseY - 5, 10, 10, 16, Color(guiColor))

GlStateManager.popMatrix()

assumeNonVolatile = false

super.drawScreen(mouseX, mouseY, partialTicks)
}

Expand All @@ -288,7 +214,7 @@ class GuiMainMenu : AbstractScreen(), GuiYesNoCallback {
*/
private fun formatChangelogLine(line: String): String {
return when {
line.startsWith("~ ") -> "§7[§r~§7] §r" + line.removePrefix("~ ").trim()
line.startsWith("~ ") -> "§7[§r~§7] §r" + line.removePrefix("~ ").trim()
line.startsWith("+ ") -> "§7[§a+§7] §r" + line.removePrefix("+ ").trim()
line.startsWith("- ") -> "§7[§c-§7] §r" + line.removePrefix("- ").trim()
line.startsWith("* ") -> "§7[§e*§7] §r" + line.removePrefix("* ").trim()
Expand Down
Loading

0 comments on commit 8b6d160

Please sign in to comment.