Skip to content

Commit

Permalink
remove redundant assets and use translation files instead
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed Nov 24, 2024
1 parent 3fe06db commit 6875e81
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 185 deletions.
73 changes: 24 additions & 49 deletions src/main/kotlin/org/polyfrost/crashpatch/gui/CrashGuiRewrite.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ import org.polyfrost.polyui.animate.Animations
import org.polyfrost.polyui.color.Colors
import org.polyfrost.polyui.color.PolyColor
import org.polyfrost.polyui.color.rgba
import org.polyfrost.polyui.component.Component
import org.polyfrost.polyui.component.extensions.*
import org.polyfrost.polyui.component.impl.*
import org.polyfrost.polyui.data.PolyImage
import org.polyfrost.polyui.operations.Move
import org.polyfrost.polyui.operations.Resize
import org.polyfrost.polyui.unit.Align
import org.polyfrost.polyui.unit.Vec2
import org.polyfrost.polyui.unit.Vec4
import org.polyfrost.polyui.unit.seconds
import org.polyfrost.polyui.utils.image
import org.polyfrost.polyui.utils.mapToArray
Expand Down Expand Up @@ -61,27 +58,15 @@ class CrashGuiRewrite @JvmOverloads constructor(
}
var shouldCrash = false

private val subtitle by lazy {
when (type) {
GuiType.INIT -> listOf(
SUBTITLE_INIT_1 + (if (crashScan != null) SUBTITLE_INIT_2 else "") + SUBTITLE_INIT_3,
""
)

GuiType.NORMAL -> listOf(SUBTITLE_1, SUBTITLE_2)
GuiType.DISCONNECT -> listOf(SUBTITLE_DISCONNECTED, SUBTITLE_DISCONNECTED_2)
}
}

fun create(): GuiScreen {
val builder = OCPolyUIBuilder.create()
.blurs()
.atResolution(1920f, 1080f)
.backgroundColor(rgba(21, 21, 21))
.size(650f, 600f)
.renderer(UIManager.INSTANCE.renderer)
.renderer(UIManager.INSTANCE.renderer).translatorDelegate("assets/crashpatch")

val onClose: Consumer<PolyUI> = Consumer { _: PolyUI ->
val onClose = Consumer { _: PolyUI ->
leaveWorldCrash = false
}

Expand All @@ -98,16 +83,13 @@ class CrashGuiRewrite @JvmOverloads constructor(
0F
),

Text(type.title, fontSize = 24f).setFont { PolyUI.defaultFonts.medium }.padded(0f, 10f, 0f, 0f),
Text("${type.title}.desc.1", fontSize = 14f).setPalette { text.secondary }
.padded(0f, if (type != GuiType.INIT || crashScan != null) 16 + 14f else 16f, 0f, 0f),
if (type != GuiType.INIT || crashScan != null) Text("${type.title}.desc.2", fontSize = 14f).setPalette { text.secondary }
else null,
Text(
if (type == GuiType.DISCONNECT) DISCONNECTED_TITLE else TITLE,
fontSize = 24f,
).setFont { PolyUI.defaultFonts.medium }.padded(0f, 10f, 0f, 0f),
Text(subtitle[0], fontSize = 14f).setPalette { text.secondary }
.padded(0f, 16f, 0f, 0f),
Text(subtitle[1], fontSize = 14f).setPalette { text.secondary }
.padded(0f, 0F, 0f, 0f),
Text(
if (type == GuiType.DISCONNECT) CAUSE_TEXT_DISCONNECTED else CAUSE_TEXT,
if (type == GuiType.DISCONNECT) "crashpatch.disconnect.cause" else "crashpatch.crash.cause",
fontSize = 16f
).padded(0f, 24f, 0f, 0f),
Text(susThing, fontSize = 18f).setFont { PolyUI.defaultFonts.semiBold }.setPalette { brand.fg }
Expand All @@ -116,10 +98,8 @@ class CrashGuiRewrite @JvmOverloads constructor(
Block(
Block(
// Selector
Block(
color = BLUE_600,
size = Vec2(0f, 2f)
).ignoreLayout().radius(2f).afterParentInit(Int.MAX_VALUE) {
Block(size = Vec2(0f, 2f)).ignoreLayout().radius(2f).afterParentInit(Int.MAX_VALUE) {
palette = polyUI.colors.brand.fg
selectedSolution?.let { solution ->
this.y = parent.y + parent.height - 2f

Expand Down Expand Up @@ -223,26 +203,26 @@ class CrashGuiRewrite @JvmOverloads constructor(
color = GRAY_700
).also { block = it }.padded(0f, 40f, 0f, 0f),

Text(DISCORD_PROMPT, fontSize = 16f).padded(0f, 25f, 0f, 0f),
Text("crashpatch.discord.prompt", fontSize = 16f).padded(0f, 25f, 0f, 0f),
Group(
Image("/assets/crashpatch/discord.svg".image(), size = Vec2(28f, 28f)),
Text(POLYFROST_DISCORD, fontSize = 16f).setPalette { brand.fg }.padded(4f, 0f, 0f, 0f),
Text("crashpatch.link.discord.polyfrost", fontSize = 16f).setPalette { brand.fg }.padded(4f, 0f, 0f, 0f),
).onClick {
UDesktop.browse(URI.create(POLYFROST_DISCORD))
UDesktop.browse(URI.create("crashpatch.link.discord.polyfrost"))
true
},

// Buttons
Group(
Button(text = RETURN_TO_GAME, padding = Vec2(14f, 14f)).onClick {
Button(text = "crashpatch.continue", padding = Vec2(14f, 14f)).onClick {
if (type == GuiType.INIT) {
shouldCrash = true
} else {
UScreen.displayScreen(null)
}
}.setPalette { brand.fg },
Button(
text = OPEN_CRASH_LOG,
text = "crashpatch.log",
rightImage = "/assets/crashpatch/open-external.svg".image(),
padding = Vec2(14f, 14f)
).onClick {
Expand All @@ -256,25 +236,20 @@ class CrashGuiRewrite @JvmOverloads constructor(
),
)

val screen =
UIManager.INSTANCE.createPolyUIScreen(polyUI, 1920f, 1080f, false, true, onClose)
val screen = UIManager.INSTANCE.createPolyUIScreen(polyUI, 1920f, 1080f, false, true, onClose)
polyUI.window = UIManager.INSTANCE.createWindow()
return screen as GuiScreen
}

private fun createSolutionText(solution: CrashScan.Solution): Text {
return Text(
solution.solutions.joinToString("\n"),
fontSize = 12f,
visibleSize = Vec2(518f, 105f),
).setFont { PolyUI.monospaceFont }.padded(16f, 8f)
}
private fun createSolutionText(solution: CrashScan.Solution) = Text(
solution.solutions.joinToString("\n"),
fontSize = 12f,
visibleSize = Vec2(518f, 105f),
).setFont { PolyUI.monospaceFont }.padded(16f, 8f)

private fun createCustomButtonPalette(normal: PolyColor): Colors.Palette {
return Colors.Palette(normal, GRAY_700, GRAY_700, PolyColor.BLACK)
}
private fun createCustomButtonPalette(normal: PolyColor) = Colors.Palette(normal, GRAY_700, GRAY_700, PolyColor.TRANSPARENT)

enum class GuiType {
INIT, NORMAL, DISCONNECT
enum class GuiType(val title: String) {
INIT("crashpatch.init"), NORMAL("crashpatch.crash"), DISCONNECT("crashpatch.disconnect")
}
}
35 changes: 2 additions & 33 deletions src/main/kotlin/org/polyfrost/crashpatch/gui/constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,5 @@ package org.polyfrost.crashpatch.gui

import org.polyfrost.polyui.color.rgba

internal val GRAY_800 = rgba(21, 22, 23, 1f) // general background
internal val GRAY_700 = rgba(34, 35, 38, 1f) // log background
internal val GRAY_600 = rgba(42, 44, 48, 1f) // log header

internal val WHITE_90 = rgba(255, 255, 255, 229 / 255f) // text
internal val WHITE_80 = rgba(255, 255, 255, 204 / 255f) // subtext
internal val WHITE_60 = rgba(255, 255, 255, 153 / 255f) // logs

internal val BLUE_400 = rgba(77, 135, 229) // yeah
internal val BLUE_600 = rgba(20, 82, 204, 1F) // brand.hover

internal val HYPERLINK_BLUE = rgba(48, 129, 242)

internal val TITLE = "Uh-oh. Your game crashed!"
internal val DISCONNECTED_TITLE = "Uh-oh. You were disconnected from the server!"
internal val SUBTITLE_1 = "But, CrashPatch just saved the day! Feel free to ignore this, and"
internal val SUBTITLE_2 = "continue playing your game despite the crash."
internal val SUBTITLE_DISCONNECTED = "The full reason is below, but"
internal val SUBTITLE_DISCONNECTED_2 = "you can ignore this and continue playing."
internal val SUBTITLE_INIT_1 = "To fix this, "
internal val SUBTITLE_INIT_2 = "follow the tips listed below and / or "
internal val SUBTITLE_INIT_3 = "join the Discord server and make a support ticket."

internal val CAUSE_TEXT = "This could have been caused by:"
internal val CAUSE_TEXT_DISCONNECTED = "Reason for disconnect:"

internal val RETURN_TO_GAME = "Return to game"
internal val OPEN_CRASH_LOG = "Crash log"

internal val DISCORD_PROMPT = "If the solution above doesn't help, join"

internal val SKYCLIENT_DISCORD = "https://inv.wtf/skyclient"
internal val POLYFROST_DISCORD = "https://polyfrost.cc/discord"
internal val GRAY_700 = rgba(34, 35, 38) // log background
internal val GRAY_600 = rgba(42, 44, 48) // log header
22 changes: 22 additions & 0 deletions src/main/resources/assets/crashpatch/en_default.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
crashpatch.crash=Uh-oh. Your game crashed!
crashpatch.init=Uh-oh. Your game crashed on startup!
crashpatch.disconnect=Uh-oh. You were disconnected from the server!

crashpatch.crash.desc.1=But, CrashPatch just saved the day! Feel free to ignore this, and
crashpatch.crash.desc.2=continue playing your game despite the crash.

crashpatch.disconnect.desc.1=The full reason is below, but
crashpatch.disconnect.desc.2=you can ignore this and continue playing.

crashpatch.init.desc.1=To fix this, join the Discord server and make a support ticket.
crashpatch.init.desc.2=Additionally, try following at the tips listed below.

crashpatch.crash.cause=This could have been caused by:
crashpatch.disconnect.cause=Reason for disconnect:

crashpatch.continue=Return to game
crashpatch.log=Crash log

crashpatch.discord.prompt=If the solution above doesn't help, join
crashpatch.link.discord.skyclient=https://inv.wtf/skyclient
crashpatch.link.discord.polyfrost=https://polyfrost.org/discord
10 changes: 0 additions & 10 deletions src/main/resources/assets/crashpatch/fonts/AUTHORS.txt

This file was deleted.

Binary file not shown.
93 changes: 0 additions & 93 deletions src/main/resources/assets/crashpatch/fonts/OFL.txt

This file was deleted.

0 comments on commit 6875e81

Please sign in to comment.