diff --git a/src/main/kotlin/dev/nyon/autodrop/AutoDrop.kt b/src/main/kotlin/dev/nyon/autodrop/AutoDrop.kt index 2ad38da..7712ce9 100644 --- a/src/main/kotlin/dev/nyon/autodrop/AutoDrop.kt +++ b/src/main/kotlin/dev/nyon/autodrop/AutoDrop.kt @@ -45,7 +45,7 @@ object AutoDrop : ClientModInitializer { ) if (config.enabled) invokeAutodrop() } - // TODO: screen if (menuKeyBind.consumeClick()) client.setScreen(createYaclScreen(null)) + if (menuKeyBind.consumeClick()) client.setScreen(createYaclScreen(null)) } private var jobWaiting = false diff --git a/src/main/kotlin/dev/nyon/autodrop/config/Config.kt b/src/main/kotlin/dev/nyon/autodrop/config/Config.kt index 34db83d..0d782d2 100644 --- a/src/main/kotlin/dev/nyon/autodrop/config/Config.kt +++ b/src/main/kotlin/dev/nyon/autodrop/config/Config.kt @@ -33,10 +33,10 @@ data class Config( @Suppress("SpellCheckingInspection") @Serializable data class TriggerConfig( - val onPickup: Boolean = true, - val onSneak: Boolean = false, - val onJump: Boolean = false, - val onSlotSwitch: Boolean = false + var onPickup: Boolean = true, + var onSneak: Boolean = false, + var onJump: Boolean = false, + var onSlotSwitch: Boolean = false ) /** diff --git a/src/main/kotlin/dev/nyon/autodrop/config/ModMenuImpl.kt b/src/main/kotlin/dev/nyon/autodrop/config/ModMenuImpl.kt index f63acde..95dc044 100644 --- a/src/main/kotlin/dev/nyon/autodrop/config/ModMenuImpl.kt +++ b/src/main/kotlin/dev/nyon/autodrop/config/ModMenuImpl.kt @@ -7,8 +7,7 @@ import com.terraformersmc.modmenu.api.ModMenuApi class ModMenuImpl : ModMenuApi { override fun getModConfigScreenFactory(): ConfigScreenFactory<*> { return ConfigScreenFactory { - // TODO: screen - it + createYaclScreen(it) } } } diff --git a/src/main/kotlin/dev/nyon/autodrop/config/YaclScreen.kt b/src/main/kotlin/dev/nyon/autodrop/config/YaclScreen.kt index bf4711d..ff59197 100644 --- a/src/main/kotlin/dev/nyon/autodrop/config/YaclScreen.kt +++ b/src/main/kotlin/dev/nyon/autodrop/config/YaclScreen.kt @@ -1,128 +1,65 @@ package dev.nyon.autodrop.config -import dev.isxander.yacl3.api.* -import dev.isxander.yacl3.api.controller.IntegerFieldControllerBuilder -import dev.isxander.yacl3.api.controller.ItemControllerBuilder -import dev.isxander.yacl3.api.controller.LongFieldControllerBuilder -import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder -import dev.nyon.autodrop.config.models.Archive +import dev.isxander.yacl3.dsl.* import dev.nyon.konfig.config.saveConfig import net.minecraft.client.gui.screens.Screen -import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.network.chat.Component -import net.minecraft.resources.ResourceLocation -import net.minecraft.world.item.Item -import net.minecraft.world.item.Items -fun createYaclScreen(parent: Screen? = null): Screen { - val builder = YetAnotherConfigLib.createBuilder() - builder.title(Component.translatable("menu.autodrop.name")) - builder.category( - ConfigCategory.createBuilder().name(Component.translatable("menu.autodrop.archives.title")) - .appendCreateArchiveOption().appendArchivesOptions().build() - ) - builder.category( - ConfigCategory.createBuilder().name(Component.translatable("menu.autodrop.lockedslots.title")) - .appendLockedSlotsOptions().build() - ) +fun createYaclScreen(parent: Screen? = null): Screen = YetAnotherConfigLib("autodrop") { + val general by categories.registering { + val enabled by rootOptions.registering { + binding(true, { config.enabled }, { config.enabled = it }) + controller = tickBox() + descriptionBuilder { + addDefaultText(1) + } + } - builder.category( - ConfigCategory.createBuilder().name(Component.translatable("menu.autodrop.general.title")) - .appendGeneralConfigOptions().appendActiveArchivesOptionGroup().build() - ) + val delay by rootOptions.registering { + binding(200, { config.dropDelay }, { config.dropDelay = it }) + controller = numberField(min = 0L) + descriptionBuilder { + addDefaultText(1) + } + } - builder.save { saveConfig(settings) } - val screen = builder.build() - return screen.generateScreen(parent) -} + val triggers by groups.registering { + descriptionBuilder { + addDefaultText(1) + } -private fun ConfigCategory.Builder.appendGeneralConfigOptions(): ConfigCategory.Builder { - option( - Option.createBuilder().name(Component.translatable("menu.autodrop.general.active.title")) - .description(OptionDescription.of(Component.translatable("menu.autodrop.general.active.description"))) - .binding(true, { settings.enabled }, { settings.enabled = it }).controller(TickBoxControllerBuilder::create) - .build() - ) - option( - Option.createBuilder().name(Component.translatable("menu.autodrop.general.dropdelay.title")) - .description(OptionDescription.of(Component.translatable("menu.autodrop.general.dropdelay.description"))) - .binding(200, { settings.dropDelay }, { settings.dropDelay = it }) - .controller(LongFieldControllerBuilder::create).build() - ) + val pick by options.registering { + binding(true, { config.triggerConfig.onPickup }, { config.triggerConfig.onPickup = it }) + controller = tickBox() + descriptionBuilder { + addDefaultText(1) + } + } - return this -} + val sneak by options.registering { + binding(false, { config.triggerConfig.onSneak }, { config.triggerConfig.onSneak = it }) + controller = tickBox() + descriptionBuilder { + addDefaultText(1) + } + } -private fun ConfigCategory.Builder.appendActiveArchivesOptionGroup(): ConfigCategory.Builder { - if (settings.archives.isEmpty()) return this - val group = OptionGroup.createBuilder().name(Component.translatable("menu.autodrop.general.enabledarchives.title")) - .description(OptionDescription.of(Component.translatable("menu.autodrop.general.enabledarchives.description"))) + val jump by options.registering { + binding(false, { config.triggerConfig.onJump }, { config.triggerConfig.onJump = it }) + controller = tickBox() + descriptionBuilder { + addDefaultText(1) + } + } - settings.archives.forEach { archive -> - group.option( - Option.createBuilder().name(Component.translatable(archive.name)) - .description(OptionDescription.of(Component.translatable("menu.autodrop.general.enabledarchives.tickbox"))) - .binding(true, { settings.activeArchives.contains(archive.name) }, { - if (it) { - settings.activeArchives.add(archive.name) - } else { - settings.activeArchives.removeIf { archiveName -> archiveName == archive.name } - } - reloadArchiveProperties() - }).controller(TickBoxControllerBuilder::create).build() - ) + val switch by options.registering { + binding(false, { config.triggerConfig.onSlotSwitch }, { config.triggerConfig.onSlotSwitch = it }) + controller = tickBox() + descriptionBuilder { + addDefaultText(1) + } + } + } } - group(group.build()) - return this -} - -private fun ConfigCategory.Builder.appendCreateArchiveOption(): ConfigCategory.Builder { - option( - ButtonOption.createBuilder().name(Component.translatable("menu.autodrop.archives.createarchive.title")) - .description( - OptionDescription.of( - Component.translatable("menu.autodrop.archives.createarchive.description"), - Component.translatable("menu.autodrop.archives.createarchive.note") - ) - ).action { _, _ -> - settings.archives.add( - Archive( - "Archive ${settings.archives.size + 1}", mutableListOf(), mutableListOf() - ) - ) - saveConfig(settings) - }.build() - ) - return this -} - -private fun ConfigCategory.Builder.appendArchivesOptions(): ConfigCategory.Builder { - settings.archives.map { it.name }.forEach { archiveName -> - group(ListOption.createBuilder().name(Component.literal(archiveName)) - .description(OptionDescription.of(Component.translatable("menu.autodrop.archives.edit.description"))) - .binding(mutableListOf(), - { settings.archives.first { it.name == archiveName }.items.map { BuiltInRegistries.ITEM.get(it) } }, - { - settings.archives.first { archive -> archive.name == archiveName }.items = - it.map { item -> BuiltInRegistries.ITEM.getKey(item) }.toMutableList() - reloadArchiveProperties() - }).controller(ItemControllerBuilder::create).initial(Items.STONE).collapsed(true).build()) - } - return this -} - -private fun ConfigCategory.Builder.appendLockedSlotsOptions(): ConfigCategory.Builder { - settings.archives.map { it.name }.forEach { archiveName -> - group( - ListOption.createBuilder().name(Component.literal(archiveName)).description( - OptionDescription.createBuilder().text(Component.translatable("menu.autodrop.lockedslots.description")) - .image(/*? if >=1.21 {*/ ResourceLocation.parse("autodrop:image/inventory-slots.png") /*?} else {*/ /*ResourceLocation("autodrop", "image/inventory-slots.png") *//*?}*/, 352, 331).build() - ).binding(mutableListOf(), { settings.archives.first { it.name == archiveName }.lockedSlots }, { - settings.archives.first { archive -> archive.name == archiveName }.lockedSlots = it.toMutableList() - reloadArchiveProperties() - }).controller(IntegerFieldControllerBuilder::create).initial(0).collapsed(true).build() - ) - } - return this -} + save { saveConfig(config) } +}.generateScreen(parent) \ No newline at end of file diff --git a/src/main/resources/assets/autodrop/lang/de_de.json b/src/main/resources/assets/autodrop/lang/de_de.json index 9e2f126..e5f4148 100644 --- a/src/main/resources/assets/autodrop/lang/de_de.json +++ b/src/main/resources/assets/autodrop/lang/de_de.json @@ -2,22 +2,23 @@ "menu.autodrop.overlay.enabled": "aktiviert", "menu.autodrop.overlay.disabled": "deaktiviert", "menu.autodrop.name": "AutoDrop", - "menu.autodrop.general.title": "Allgemein", - "menu.autodrop.general.active.title": "Aktiviert", - "menu.autodrop.general.active.description": "Aktiviert bzw. deaktiviert die Funktion dieser Mod.", - "menu.autodrop.general.dropdelay.title": "Wurf Verzögerung", - "menu.autodrop.general.dropdelay.description": "Gibt die Verzögerung in Millisekunden an, nach der das Item weggeworfen werfen soll, welches gerade aufgesammelt wurde.", - "menu.autodrop.archives.title": "Listen", - "menu.autodrop.lockedslots.title": "Gesperrte Inventarplätze", - "menu.autodrop.archives.createarchive.title": "Liste erstellen", - "menu.autodrop.archives.createarchive.description": "Klicke um eine neue Liste zu erstellen.", - "menu.autodrop.archives.createarchive.note": "NOTIZ: Um die neue Liste zu editieren, musst du diesen Bildschirm erneut öffnen.", - "menu.autodrop.lockedslots.description": "Editiere hier deine gesperrten Inventarplätze. Du kannst oben die Nummern von den jeweiligen Inventarplätzen sehen.", - "menu.autodrop.general.enabledarchives.title": "Aktivierte Listen", - "menu.autodrop.general.enabledarchives.description": "Aktiviere bzw. deaktivierte bestimmte Listen.", - "menu.autodrop.general.enabledarchives.tickbox": "Klicke um die Liste zu de-/aktivieren.", - "menu.autodrop.archives.edit.description": "Editiere hier deine Listen.", "key.autodrop.toggle": "De-/Aktiviere AutoDrop", "key.autodrop.gui": "Öffne das GUI", - "key.autodrop.category": "AutoDrop" + "key.autodrop.category": "AutoDrop", + "yacl3.config.autodrop.title": "AutoDrop", + "yacl3.config.autodrop.category.general": "Allgemeines", + "yacl3.config.autodrop.category.general.root.option.enabled": "Aktiviert", + "yacl3.config.autodrop.category.general.root.option.enabled.description": "De-/Aktiviert die Funktionalität der Mod.", + "yacl3.config.autodrop.category.general.root.option.delay": "Abwurfverzögerung", + "yacl3.config.autodrop.category.general.root.option.delay.description": "Bestimmt die Verzögerung nach dem Auslöser, nach der die Items weggeworfen werden sollen.", + "yacl3.config.autodrop.category.general.group.triggers": "Auslöser", + "yacl3.config.autodrop.category.general.group.triggers.description": "Legt fest wann die AutoDrop Funktion ausgeführt werden soll.", + "yacl3.config.autodrop.category.general.group.triggers.option.pick": "Nach dem Aufheben eines Items", + "yacl3.config.autodrop.category.general.group.triggers.option.pick.description": "Entscheidet ob die AutoDrop Funktion nach dem Aufheben eines Items ausgeführt werden soll.", + "yacl3.config.autodrop.category.general.group.triggers.option.sneak": "Nach dem Ducken", + "yacl3.config.autodrop.category.general.group.triggers.option.sneak.description": "Entscheidet ob die AutoDrop Funktion nach dem Ducken ausgeführt werden soll.", + "yacl3.config.autodrop.category.general.group.triggers.option.jump": "Nach dem Springen", + "yacl3.config.autodrop.category.general.group.triggers.option.jump.description": "Entscheidet ob die AutoDrop Funktion nach dem Springen ausgeführt werden soll.", + "yacl3.config.autodrop.category.general.group.triggers.option.switch": "Nach dem Wechseln eines Schnellleisten-Platzes", + "yacl3.config.autodrop.category.general.group.triggers.option.switch.description": "Entscheidet ob die AutoDrop Funktion nach dem Wechseln eines Schnellleisten-Platzes ausgeführt werden soll." } \ No newline at end of file diff --git a/src/main/resources/assets/autodrop/lang/en_us.json b/src/main/resources/assets/autodrop/lang/en_us.json index 1ed3cdc..c8c60a2 100644 --- a/src/main/resources/assets/autodrop/lang/en_us.json +++ b/src/main/resources/assets/autodrop/lang/en_us.json @@ -1,23 +1,24 @@ { "menu.autodrop.overlay.enabled": "enabled", "menu.autodrop.overlay.disabled": "disabled", - "menu.autodrop.name": "autodrop", - "menu.autodrop.general.title": "General", - "menu.autodrop.general.active.title": "Active", - "menu.autodrop.general.active.description": "Decides whether this mod should be enabled.", - "menu.autodrop.general.dropdelay.title": "Drop delay", - "menu.autodrop.general.dropdelay.description": "Defines the delay in milliseconds that the mod waits before dropping the item after it's picked up.", - "menu.autodrop.archives.title": "Archives", - "menu.autodrop.lockedslots.title": "Locked slots", - "menu.autodrop.archives.createarchive.title": "Create archive", - "menu.autodrop.archives.createarchive.description": "Click to create a new archive:", - "menu.autodrop.archives.createarchive.note": "NOTE: To edit the new archive you have to re-enter this screen!", - "menu.autodrop.lockedslots.description": "Edit your locked slots here. You can see the inventory numbers of each slot above.", - "menu.autodrop.general.enabledarchives.title": "Enabled archives", - "menu.autodrop.general.enabledarchives.description": "Edit your enabled archives here.", - "menu.autodrop.general.enabledarchives.tickbox": "Click to disable/enable this archive.", - "menu.autodrop.archives.edit.description": "Edit your archives here.", + "menu.autodrop.name": "AutoDrop", "key.autodrop.toggle": "Toggle AutoDrop", "key.autodrop.gui": "Open GUI", - "key.autodrop.category": "AutoDrop" + "key.autodrop.category": "AutoDrop", + "yacl3.config.autodrop.title": "AutoDrop", + "yacl3.config.autodrop.category.general": "General", + "yacl3.config.autodrop.category.general.root.option.enabled": "Enabled", + "yacl3.config.autodrop.category.general.root.option.enabled.description": "Toggles the functionality of the mod.", + "yacl3.config.autodrop.category.general.root.option.delay": "Drop Delay", + "yacl3.config.autodrop.category.general.root.option.delay.description": "Defines the delay that is applied after the trigger for a drop.", + "yacl3.config.autodrop.category.general.group.triggers": "Triggers", + "yacl3.config.autodrop.category.general.group.triggers.description": "Define when the autodrop function is invoked.", + "yacl3.config.autodrop.category.general.group.triggers.option.pick": "On Item Pickup", + "yacl3.config.autodrop.category.general.group.triggers.option.pick.description": "Toggles whether the autodrop function should run when picking up an item.", + "yacl3.config.autodrop.category.general.group.triggers.option.sneak": "On Sneak", + "yacl3.config.autodrop.category.general.group.triggers.option.sneak.description": "Toggles whether the autodrop function should run when sneaking.", + "yacl3.config.autodrop.category.general.group.triggers.option.jump": "On Jump", + "yacl3.config.autodrop.category.general.group.triggers.option.jump.description": "Toggles whether the autodrop function should run when jumping.", + "yacl3.config.autodrop.category.general.group.triggers.option.switch": "On Slot Switch", + "yacl3.config.autodrop.category.general.group.triggers.option.switch.description": "Toggles whether the autodrop function should run when switching an hotbar slot." } \ No newline at end of file