screen padding

This commit is contained in:
nea
2022-08-04 03:56:53 +02:00
parent 2625eeb7de
commit c83890afc8
4 changed files with 92 additions and 29 deletions

View File

@@ -21,7 +21,6 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.fabricmc.loader.api.FabricLoader import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.loader.api.Version import net.fabricmc.loader.api.Version
import net.fabricmc.loader.api.metadata.ModMetadata import net.fabricmc.loader.api.metadata.ModMetadata
import net.minecraft.client.Minecraft
import net.minecraft.commands.CommandBuildContext import net.minecraft.commands.CommandBuildContext
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
@@ -32,7 +31,7 @@ import kotlin.coroutines.EmptyCoroutineContext
object NotEnoughUpdates : ModInitializer, ClientModInitializer { object NotEnoughUpdates : ModInitializer, ClientModInitializer {
const val MOD_ID = "notenoughupdates" const val MOD_ID = "notenoughupdates"
val DEBUG = System.getenv("notenoughupdates.debug") == "true" val DEBUG = System.getProperty("notenoughupdates.debug") == "true"
val DATA_DIR: Path = Path.of(".notenoughupdates").also { Files.createDirectories(it) } val DATA_DIR: Path = Path.of(".notenoughupdates").also { Files.createDirectories(it) }
val CONFIG_DIR: Path = Path.of("config/notenoughupdates").also { Files.createDirectories(it) } val CONFIG_DIR: Path = Path.of("config/notenoughupdates").also { Files.createDirectories(it) }
val logger = LogManager.getLogger("NotEnoughUpdates") val logger = LogManager.getLogger("NotEnoughUpdates")
@@ -73,10 +72,10 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer {
}) })
dispatcher.register(ClientCommandManager.literal("neu") dispatcher.register(ClientCommandManager.literal("neu")
.then(ClientCommandManager.literal("repo").executes { .then(ClientCommandManager.literal("repo").executes {
it.source.sendFeedback(Component.literal("Hi, this should work")) setScreenLater(CottonClientScreen(RepoManagementGui()))
Minecraft.getInstance().setScreenLater(CottonClientScreen(RepoManagementGui()))
Command.SINGLE_SUCCESS Command.SINGLE_SUCCESS
})) })
)
} }
override fun onInitialize() { override fun onInitialize() {

View File

@@ -1,25 +1,35 @@
package moe.nea.notenoughupdates.gui package moe.nea.notenoughupdates.gui
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
import io.github.cottonmc.cotton.gui.widget.WGridPanel import io.github.cottonmc.cotton.gui.widget.WButton
import io.github.cottonmc.cotton.gui.widget.WLabel import io.github.cottonmc.cotton.gui.widget.WLabel
import io.github.cottonmc.cotton.gui.widget.WTextField import io.github.cottonmc.cotton.gui.widget.WTextField
import io.github.cottonmc.cotton.gui.widget.WToggleButton import io.github.cottonmc.cotton.gui.widget.WToggleButton
import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment
import io.github.cottonmc.cotton.gui.widget.data.Insets import io.github.cottonmc.cotton.gui.widget.data.Insets
import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
import moe.nea.notenoughupdates.repo.RepoManager import moe.nea.notenoughupdates.repo.RepoManager
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import java.util.function.Consumer import java.util.function.Consumer
class RepoManagementGui : LightweightGuiDescription() { class RepoManagementGui : LightweightGuiDescription() {
init { init {
val root = WGridPanel() val root = WGridPanelWithPadding(verticalPadding = 5)
setRootPanel(root) setRootPanel(root)
root.setSize(0, 0)
root.setSize(256, 240)
root.insets = Insets.ROOT_PANEL root.insets = Insets.ROOT_PANEL
var col = 0
WLabel(Component.literal("NotEnoughUpdates Repo Settings")).apply {
root.add(this, 0, col, 11, 1)
this.verticalAlignment = VerticalAlignment.TOP
this.horizontalAlignment = HorizontalAlignment.CENTER
}
col += 1
WLabel(Component.literal("Auto Update")).apply { WLabel(Component.literal("Auto Update")).apply {
root.add(this, 0, 1, 5, 1) root.add(this, 0, col, 5, 1)
this.verticalAlignment = VerticalAlignment.CENTER
} }
WToggleButton(Component.literal("Auto Update")).apply { WToggleButton(Component.literal("Auto Update")).apply {
@@ -28,50 +38,72 @@ class RepoManagementGui : LightweightGuiDescription() {
RepoManager.config.autoUpdate = it RepoManager.config.autoUpdate = it
RepoManager.markDirty() RepoManager.markDirty()
} }
root.add(this, 5, 1, 1, 1) root.add(this, 5, col, 1, 1)
} }
col += 1
WLabel(Component.literal("Repo Username")).apply { WLabel(Component.literal("Repo Username")).apply {
root.add(this, 0, 2, 5, 1) root.add(this, 0, col, 5, 1)
this.verticalAlignment = VerticalAlignment.CENTER
} }
WTextField(Component.literal("username")).apply { val userName = WTextField(Component.literal("username")).apply {
this.isEditable = true this.isEditable = true
this.text = RepoManager.config.user this.text = RepoManager.config.user
this.setChangedListener { this.setChangedListener {
RepoManager.config.user = it RepoManager.config.user = it
RepoManager.markDirty() RepoManager.markDirty()
} }
root.add(this, 5, 2, 6, 1) root.add(this, 5, col, 6, 1)
} }
col += 1
WLabel(Component.literal("Repo Name")).apply { WLabel(Component.literal("Repo Name")).apply {
root.add(this, 0, 3, 5, 1) root.add(this, 0, col, 5, 1)
this.verticalAlignment = VerticalAlignment.CENTER
} }
WTextField(Component.literal("repo name")).apply { val repoName = WTextField(Component.literal("repo name")).apply {
this.isEditable = true this.isEditable = true
this.text = RepoManager.config.repo this.text = RepoManager.config.repo
this.setChangedListener { this.setChangedListener {
RepoManager.config.repo = it RepoManager.config.repo = it
RepoManager.markDirty() RepoManager.markDirty()
} }
root.add(this, 5, 3, 6, 1) root.add(this, 5, col, 6, 1)
} }
col += 1
WLabel(Component.literal("Repo Branch")).apply { WLabel(Component.literal("Repo Branch")).apply {
root.add(this, 0, 4, 5, 1) root.add(this, 0, col, 5, 1)
this.verticalAlignment = VerticalAlignment.CENTER
} }
WTextField(Component.literal("repo name")).apply { val branchName = WTextField(Component.literal("repo branch")).apply {
this.isEditable = true this.isEditable = true
this.text = RepoManager.config.branch this.text = RepoManager.config.branch
this.setChangedListener { this.setChangedListener {
RepoManager.config.branch = it RepoManager.config.branch = it
RepoManager.markDirty() RepoManager.markDirty()
} }
root.add(this, 5, 4, 6, 1) root.add(this, 5, col, 6, 1)
}
col += 1
WLabel(Component.literal("Reset to Defaults")).apply {
root.add(this, 0, col, 5, 1)
this.verticalAlignment = VerticalAlignment.CENTER
}
WButton(Component.literal("Reset")).apply {
this.setOnClick {
branchName.text = "master"
userName.text = "NotEnoughUpdates"
repoName.text = "NotEnoughUpdates-REPO"
RepoManager.markDirty()
}
root.add(this, 5, col, 6, 1)
} }
} }
} }

View File

@@ -0,0 +1,33 @@
package moe.nea.notenoughupdates.gui
import io.github.cottonmc.cotton.gui.widget.WPanelWithInsets
import io.github.cottonmc.cotton.gui.widget.WWidget
import io.github.cottonmc.cotton.gui.widget.data.Insets
class WGridPanelWithPadding(
val grid: Int = 18,
val verticalPadding: Int = 0,
val horizontalPadding: Int = 0,
) : WPanelWithInsets() {
private inline val vertOffset get() = grid + verticalPadding
private inline val horiOffset get() = grid + horizontalPadding
fun add(w: WWidget, x: Int, y: Int, width: Int = 1, height: Int = 1) {
children.add(w)
w.parent = this
w.setLocation(x * horiOffset + insets.left, y * vertOffset + insets.top)
if (w.canResize())
w.setSize(
grid + (horiOffset * (width - 1)),
grid + (vertOffset * (height - 1)),
)
expandToFit(w, insets)
}
override fun setInsets(insets: Insets): WGridPanelWithPadding {
super.setInsets(insets)
return this
}
}

View File

@@ -23,8 +23,7 @@ object ScreenUtil {
private var nextOpenedGui: Screen? = null private var nextOpenedGui: Screen? = null
@Suppress("UnusedReceiverParameter") fun setScreenLater(nextScreen: Screen) {
fun Minecraft.setScreenLater(nextScreen: Screen) {
val nog = nextOpenedGui val nog = nextOpenedGui
if (nog != null) { if (nog != null) {
NotEnoughUpdates.logger.warn("Setting screen ${nextScreen::class.qualifiedName} to be opened later, but ${nog::class.qualifiedName} is already queued.") NotEnoughUpdates.logger.warn("Setting screen ${nextScreen::class.qualifiedName} to be opened later, but ${nog::class.qualifiedName} is already queued.")