aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-08-04 03:56:53 +0200
committernea <romangraef@gmail.com>2022-08-04 03:56:53 +0200
commitc83890afc8304fc0a1b1d0ea8da791c6d9b90439 (patch)
treef95b2816503b865d78e326448faca350dbec2445 /src/main/kotlin
parent2625eeb7dedb05b524b08721e1267acdcd93e5c1 (diff)
downloadFirmament-c83890afc8304fc0a1b1d0ea8da791c6d9b90439.tar.gz
Firmament-c83890afc8304fc0a1b1d0ea8da791c6d9b90439.tar.bz2
Firmament-c83890afc8304fc0a1b1d0ea8da791c6d9b90439.zip
screen padding
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt21
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt64
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt33
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt3
4 files changed, 92 insertions, 29 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
index ff816f5..1986339 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt
@@ -21,7 +21,6 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.loader.api.Version
import net.fabricmc.loader.api.metadata.ModMetadata
-import net.minecraft.client.Minecraft
import net.minecraft.commands.CommandBuildContext
import net.minecraft.network.chat.Component
import org.apache.logging.log4j.LogManager
@@ -32,7 +31,7 @@ import kotlin.coroutines.EmptyCoroutineContext
object NotEnoughUpdates : ModInitializer, ClientModInitializer {
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 CONFIG_DIR: Path = Path.of("config/notenoughupdates").also { Files.createDirectories(it) }
val logger = LogManager.getLogger("NotEnoughUpdates")
@@ -58,13 +57,13 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer {
val globalJob = Job()
val coroutineScope =
- CoroutineScope(EmptyCoroutineContext + CoroutineName("NotEnoughUpdates")) + SupervisorJob(globalJob)
+ CoroutineScope(EmptyCoroutineContext + CoroutineName("NotEnoughUpdates")) + SupervisorJob(globalJob)
val coroutineScopeIo = coroutineScope + Dispatchers.IO + SupervisorJob(globalJob)
private fun registerCommands(
- dispatcher: CommandDispatcher<FabricClientCommandSource>,
- @Suppress("UNUSED_PARAMETER")
- _ctx: CommandBuildContext
+ dispatcher: CommandDispatcher<FabricClientCommandSource>,
+ @Suppress("UNUSED_PARAMETER")
+ _ctx: CommandBuildContext
) {
dispatcher.register(ClientCommandManager.literal("neureload").executes {
it.source.sendFeedback(Component.literal("Reloading repository from disk. This may lag a bit."))
@@ -72,11 +71,11 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer {
Command.SINGLE_SUCCESS
})
dispatcher.register(ClientCommandManager.literal("neu")
- .then(ClientCommandManager.literal("repo").executes {
- it.source.sendFeedback(Component.literal("Hi, this should work"))
- Minecraft.getInstance().setScreenLater(CottonClientScreen(RepoManagementGui()))
- Command.SINGLE_SUCCESS
- }))
+ .then(ClientCommandManager.literal("repo").executes {
+ setScreenLater(CottonClientScreen(RepoManagementGui()))
+ Command.SINGLE_SUCCESS
+ })
+ )
}
override fun onInitialize() {
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt b/src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt
index 115b9f8..ecdb05b 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt
@@ -1,25 +1,35 @@
package moe.nea.notenoughupdates.gui
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.WTextField
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.VerticalAlignment
import moe.nea.notenoughupdates.repo.RepoManager
import net.minecraft.network.chat.Component
import java.util.function.Consumer
class RepoManagementGui : LightweightGuiDescription() {
init {
- val root = WGridPanel()
+ val root = WGridPanelWithPadding(verticalPadding = 5)
setRootPanel(root)
-
- root.setSize(256, 240)
+ root.setSize(0, 0)
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 {
- root.add(this, 0, 1, 5, 1)
+ root.add(this, 0, col, 5, 1)
+ this.verticalAlignment = VerticalAlignment.CENTER
}
WToggleButton(Component.literal("Auto Update")).apply {
@@ -28,50 +38,72 @@ class RepoManagementGui : LightweightGuiDescription() {
RepoManager.config.autoUpdate = it
RepoManager.markDirty()
}
- root.add(this, 5, 1, 1, 1)
+ root.add(this, 5, col, 1, 1)
}
-
+ col += 1
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.text = RepoManager.config.user
this.setChangedListener {
RepoManager.config.user = it
RepoManager.markDirty()
}
- root.add(this, 5, 2, 6, 1)
+ root.add(this, 5, col, 6, 1)
}
+ col += 1
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.text = RepoManager.config.repo
this.setChangedListener {
RepoManager.config.repo = it
RepoManager.markDirty()
}
- root.add(this, 5, 3, 6, 1)
+ root.add(this, 5, col, 6, 1)
}
+ col += 1
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.text = RepoManager.config.branch
this.setChangedListener {
RepoManager.config.branch = it
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)
}
}
} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt b/src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt
new file mode 100644
index 0000000..287483e
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt
@@ -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
+ }
+
+} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt
index c56560e..95dc982 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/ScreenUtil.kt
@@ -23,8 +23,7 @@ object ScreenUtil {
private var nextOpenedGui: Screen? = null
- @Suppress("UnusedReceiverParameter")
- fun Minecraft.setScreenLater(nextScreen: Screen) {
+ fun setScreenLater(nextScreen: Screen) {
val nog = nextOpenedGui
if (nog != null) {
NotEnoughUpdates.logger.warn("Setting screen ${nextScreen::class.qualifiedName} to be opened later, but ${nog::class.qualifiedName} is already queued.")