Cobblesync GUI and Packet Handler Update

This commit is contained in:
2025-12-12 21:18:44 +00:00
parent dd78f89164
commit 1d9a551350
14 changed files with 693 additions and 173 deletions

View File

@@ -0,0 +1,151 @@
package co.sirblob.gui
import co.sirblob.network.CobbleSyncPackets
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.Button
import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component
@Environment(EnvType.CLIENT)
class CobbleSyncScreen : Screen(Component.literal("CobbleSync")) {
// Status message to display feedback
private var statusMessage: Component = Component.literal("")
private var statusColor: Int = 0xFFFFFF
// Buttons
private lateinit var syncButton: Button
private lateinit var loadButton: Button
private lateinit var closeButton: Button
override fun init() {
super.init()
val buttonWidth = 200
val buttonHeight = 20
val centerX = width / 2
val centerY = height / 2
// Sync Button - uploads Box 30 to the server
syncButton = Button.builder(Component.literal("⬆ Sync Box 30")) { _ ->
setStatus(Component.literal("Syncing..."), 0xFFFF55)
ClientPlayNetworking.send(CobbleSyncPackets.SyncRequestPayload())
}
.bounds(centerX - buttonWidth / 2, centerY - 40, buttonWidth, buttonHeight)
.build()
// Load Button - downloads saved Pokemon to Box 1
loadButton = Button.builder(Component.literal("⬇ Load to Box 1")) { _ ->
setStatus(Component.literal("Loading..."), 0xFFFF55)
ClientPlayNetworking.send(CobbleSyncPackets.LoadRequestPayload())
}
.bounds(centerX - buttonWidth / 2, centerY - 10, buttonWidth, buttonHeight)
.build()
// Close Button
closeButton = Button.builder(Component.literal("Close")) { _ ->
onClose()
}
.bounds(centerX - buttonWidth / 2, centerY + 30, buttonWidth, buttonHeight)
.build()
addRenderableWidget(syncButton)
addRenderableWidget(loadButton)
addRenderableWidget(closeButton)
}
override fun render(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, partialTick: Float) {
// Render background
renderBackground(guiGraphics, mouseX, mouseY, partialTick)
// Draw title
guiGraphics.drawCenteredString(
font,
Component.literal("§6§lCobbleSync"),
width / 2,
height / 2 - 80,
0xFFFFFF
)
// Draw subtitle/description
guiGraphics.drawCenteredString(
font,
Component.literal("§7Sync your Pokémon across servers"),
width / 2,
height / 2 - 65,
0xAAAAAA
)
// Draw separator line
guiGraphics.fill(
width / 2 - 100,
height / 2 - 55,
width / 2 + 100,
height / 2 - 54,
0xFF444444.toInt()
)
// Draw status message
if (statusMessage.string.isNotEmpty()) {
guiGraphics.drawCenteredString(
font,
statusMessage,
width / 2,
height / 2 + 60,
statusColor
)
}
// Draw info text
guiGraphics.drawCenteredString(
font,
Component.literal("§8Sync: Upload Box 30 (max 12 Pokémon)"),
width / 2,
height / 2 + 80,
0x888888
)
guiGraphics.drawCenteredString(
font,
Component.literal("§8Load: Download to Box 1 (must be empty)"),
width / 2,
height / 2 + 92,
0x888888
)
super.render(guiGraphics, mouseX, mouseY, partialTick)
}
override fun isPauseScreen(): Boolean = false
fun setStatus(message: Component, color: Int) {
this.statusMessage = message
this.statusColor = color
}
companion object {
// Singleton instance for updating status from network handlers
var currentInstance: CobbleSyncScreen? = null
private set
fun open(screen: CobbleSyncScreen) {
currentInstance = screen
}
fun close() {
currentInstance = null
}
}
override fun onClose() {
CobbleSyncScreen.close()
super.onClose()
}
override fun added() {
super.added()
CobbleSyncScreen.open(this)
}
}