-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
537 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/kotlin/dev/nyon/autodrop/config/screen/create/CreateArchiveScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package dev.nyon.autodrop.config.screen.create | ||
|
||
import dev.nyon.autodrop.config.Archive | ||
import dev.nyon.autodrop.config.config | ||
import dev.nyon.autodrop.extensions.screenComponent | ||
import dev.nyon.konfig.config.saveConfig | ||
import net.minecraft.client.gui.GuiGraphics | ||
import net.minecraft.client.gui.components.Button | ||
import net.minecraft.client.gui.components.EditBox | ||
import net.minecraft.client.gui.screens.Screen | ||
import dev.nyon.autodrop.minecraft as internalMinecraft | ||
|
||
class CreateArchiveScreen(private val parent: Screen?, private val onClose: (Archive) -> Unit) : | ||
Screen(screenComponent("create.title")) { | ||
private val matcher: (String) -> Boolean = { input -> | ||
input.isNotBlank() && config.archives.none { archive -> archive.name == input } | ||
} | ||
|
||
private val archiveNameEditBox = | ||
EditBox(internalMinecraft.font, 0, 0, 20, 20, screenComponent("create.empty")).also { | ||
addWidget(it) | ||
it.onClick(10.0, 10.0) | ||
it.setFilter(matcher) | ||
it.cursorPosition = 0 | ||
it.setHighlightPos(0) | ||
} | ||
|
||
private val doneButton = Button.builder(screenComponent("done")) { | ||
onClose() | ||
}.build().also { addWidget(it) } | ||
|
||
override fun render(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, tickDelta: Float) { | ||
renderBackground(guiGraphics, mouseX, mouseY, tickDelta) | ||
|
||
// render description | ||
guiGraphics.drawCenteredString( | ||
internalMinecraft.font, | ||
screenComponent("create.description"), | ||
internalMinecraft.screen!!.width / 2, | ||
internalMinecraft.screen!!.height / 6, | ||
0xFFFFFF | ||
) | ||
|
||
// render edit box | ||
archiveNameEditBox.setPosition(internalMinecraft.screen!!.width / 3, internalMinecraft.screen!!.height / 4) | ||
archiveNameEditBox.width = internalMinecraft.screen!!.width / 3 | ||
archiveNameEditBox.render(guiGraphics, mouseX, mouseY, tickDelta) | ||
|
||
// render done button | ||
doneButton.setPosition(internalMinecraft.screen!!.width / 3, (internalMinecraft.screen!!.height * .8).toInt()) | ||
doneButton.width = internalMinecraft.screen!!.width / 3 | ||
doneButton.render(guiGraphics, mouseX, mouseY, tickDelta) | ||
doneButton.active = matcher(archiveNameEditBox.value) | ||
} | ||
|
||
override fun shouldCloseOnEsc(): Boolean { | ||
return matcher(archiveNameEditBox.value) | ||
} | ||
|
||
override fun onClose() { | ||
val archive = Archive( | ||
true, archiveNameEditBox.value, mutableListOf(), mutableListOf() | ||
) | ||
config.archives.add(archive) | ||
onClose(archive) | ||
|
||
internalMinecraft.setScreen(parent) | ||
saveConfig(config) | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/main/kotlin/dev/nyon/autodrop/config/screen/ignored/IgnoredSlotsScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package dev.nyon.autodrop.config.screen.ignored | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem | ||
import dev.nyon.autodrop.config.Archive | ||
import dev.nyon.autodrop.config.config | ||
import dev.nyon.autodrop.extensions.resourceLocation | ||
import dev.nyon.autodrop.extensions.screenComponent | ||
import dev.nyon.konfig.config.saveConfig | ||
import net.minecraft.client.gui.GuiGraphics | ||
import net.minecraft.client.gui.components.Button | ||
import net.minecraft.client.gui.components.EditBox | ||
import net.minecraft.client.gui.screens.Screen | ||
import net.minecraft.client.renderer.GameRenderer | ||
import dev.nyon.autodrop.minecraft as internalMinecraft | ||
|
||
private const val IMAGE_SIZE = 254 | ||
|
||
class IgnoredSlotsScreen(private val archive: Archive, private val parent: Screen?) : | ||
Screen(screenComponent("ignored.title")) { | ||
private val matcher: (String) -> Boolean = { input -> | ||
val list = input.split(',').toMutableList().also { list -> | ||
list.removeIf { s -> s.isEmpty() } | ||
} | ||
list.all { s -> | ||
s.toIntOrNull() in 0 .. 99 | ||
} | ||
} | ||
|
||
private val ignoredSlotsEditBox = | ||
EditBox(internalMinecraft.font, 0, 0, 20, 20, screenComponent("ignored.empty")).also { | ||
addWidget(it) | ||
it.value = archive.ignoredSlots.joinToString(separator = ",") { input -> input.toString() } | ||
it.setMaxLength(136) | ||
it.setFilter(matcher) | ||
it.onClick(10.0, 10.0) | ||
it.cursorPosition = 0 | ||
it.setHighlightPos(0) | ||
} | ||
|
||
private val doneButton = Button.builder(screenComponent("done")) { | ||
onClose() | ||
}.build().also { addWidget(it) } | ||
|
||
override fun render(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, tickDelta: Float) { | ||
renderBackground(guiGraphics, mouseX, mouseY, tickDelta) | ||
|
||
// render description | ||
guiGraphics.drawCenteredString( | ||
internalMinecraft.font, | ||
screenComponent("ignored.description"), | ||
internalMinecraft.screen!!.width / 2, | ||
internalMinecraft.screen!!.height / 6, | ||
0xFFFFFF | ||
) | ||
|
||
// render edit box | ||
ignoredSlotsEditBox.setPosition(internalMinecraft.screen!!.width / 3, internalMinecraft.screen!!.height / 4) | ||
ignoredSlotsEditBox.width = internalMinecraft.screen!!.width / 3 | ||
ignoredSlotsEditBox.render(guiGraphics, mouseX, mouseY, tickDelta) | ||
|
||
// render image | ||
val imageLocation = resourceLocation("autodrop:image/inventory-slots.png") | ||
RenderSystem.setShader(GameRenderer::getPositionTexShader) | ||
RenderSystem.setShaderTexture(0, imageLocation) | ||
RenderSystem.enableBlend() | ||
RenderSystem.defaultBlendFunc() | ||
RenderSystem.enableDepthTest() | ||
guiGraphics.blit( | ||
imageLocation, | ||
internalMinecraft.screen!!.width / 2 - IMAGE_SIZE / 2, | ||
(internalMinecraft.screen!!.height * .55).toInt() - IMAGE_SIZE / 2, | ||
0, | ||
0, | ||
IMAGE_SIZE, | ||
IMAGE_SIZE | ||
) | ||
RenderSystem.disableBlend() | ||
RenderSystem.disableDepthTest() | ||
|
||
// render done button | ||
doneButton.setPosition(internalMinecraft.screen!!.width / 3, (internalMinecraft.screen!!.height * .8).toInt()) | ||
doneButton.width = internalMinecraft.screen!!.width / 3 | ||
doneButton.render(guiGraphics, mouseX, mouseY, tickDelta) | ||
doneButton.active = matcher(ignoredSlotsEditBox.value) | ||
} | ||
|
||
override fun shouldCloseOnEsc(): Boolean { | ||
return matcher(ignoredSlotsEditBox.value) | ||
} | ||
|
||
override fun onClose() { | ||
internalMinecraft.setScreen(parent) | ||
archive.ignoredSlots = ignoredSlotsEditBox.value.split(',').mapNotNull { it.toIntOrNull() }.toMutableList() | ||
saveConfig(config) | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
src/main/kotlin/dev/nyon/autodrop/config/screen/modify/ModifyIdentifierScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package dev.nyon.autodrop.config.screen.modify | ||
|
||
import dev.nyon.autodrop.config.ItemIdentifier | ||
import dev.nyon.autodrop.config.config | ||
import dev.nyon.autodrop.config.screen.root.ArchiveScreen | ||
import dev.nyon.autodrop.extensions.DataComponentPatchSerializer | ||
import dev.nyon.autodrop.extensions.resourceLocation | ||
import dev.nyon.autodrop.extensions.screenComponent | ||
import dev.nyon.konfig.config.saveConfig | ||
import kotlinx.datetime.Clock | ||
import kotlinx.datetime.Instant | ||
import net.minecraft.client.gui.GuiGraphics | ||
import net.minecraft.client.gui.components.Button | ||
import net.minecraft.client.gui.components.EditBox | ||
import net.minecraft.client.gui.screens.Screen | ||
import net.minecraft.core.registries.BuiltInRegistries | ||
import kotlin.time.Duration.Companion.milliseconds | ||
import dev.nyon.autodrop.minecraft as internalMinecraft | ||
|
||
class ModifyIdentifierScreen(private val parent: ArchiveScreen, private val itemIdentifier: ItemIdentifier) : | ||
Screen(screenComponent("modify.title")) { | ||
private val matcher: () -> Boolean = { | ||
(itemEditBox.value.isBlank() || BuiltInRegistries.ITEM.getOptional(resourceLocation(itemEditBox.value)).isPresent) && kotlin.runCatching { | ||
DataComponentPatchSerializer.toPatch( | ||
componentsEditBox.value | ||
) | ||
}.isSuccess && amountEditBox.value.toIntOrNull().let { it != null && it in 0 .. 64 } | ||
} | ||
|
||
private val lastIndex: Instant = Clock.System.now() | ||
private val itemEditBox: EditBox = | ||
EditBox(internalMinecraft.font, 0, 0, 20, 20, screenComponent("modify.empty")).also { | ||
addWidget(it) | ||
it.onClick(10.0, 10.0) | ||
it.setResponder { input -> | ||
val now = Clock.System.now() | ||
if (now - lastIndex > 500.milliseconds) { | ||
itemListWidget.input = input | ||
itemListWidget.refreshEntries() | ||
} | ||
} | ||
it.value = itemIdentifier.type?.let { item -> BuiltInRegistries.ITEM.getKey(item).toString() } ?: "" | ||
it.cursorPosition = 0 | ||
it.setHighlightPos(0) | ||
} | ||
|
||
private val componentsEditBox: EditBox = | ||
EditBox(internalMinecraft.font, 0, 0, 20, 20, screenComponent("modify.empty")).also { | ||
addWidget(it) | ||
it.onClick(10.0, 10.0) | ||
it.setMaxLength(300) | ||
it.value = DataComponentPatchSerializer.toString(itemIdentifier.components) | ||
it.cursorPosition = 0 | ||
it.setHighlightPos(0) | ||
} | ||
|
||
private val amountEditBox: EditBox = | ||
EditBox(internalMinecraft.font, 0, 0, 20, 20, screenComponent("modify.empty")).also { | ||
addWidget(it) | ||
it.onClick(10.0, 10.0) | ||
it.setMaxLength(2) | ||
it.value = itemIdentifier.amount.toString() | ||
it.setFilter { input -> | ||
val int = input.toIntOrNull() ?: return@setFilter false | ||
int in 0 .. 64 | ||
} | ||
it.cursorPosition = 0 | ||
it.setHighlightPos(0) | ||
} | ||
|
||
private val itemListWidget: ModifyItemsWidget = ModifyItemsWidget(itemEditBox.value) item@{ | ||
itemIdentifier.type = this@item | ||
itemEditBox.value = BuiltInRegistries.ITEM.getKey(this@item).toString() | ||
}.also { | ||
addWidget(it) | ||
it.refreshEntries() | ||
} | ||
|
||
private val doneButton = Button.builder(screenComponent("done")) { | ||
onClose() | ||
}.build().also { addWidget(it) } | ||
|
||
override fun render(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, tickDelta: Float) { | ||
renderBackground(guiGraphics, mouseX, mouseY, tickDelta) | ||
|
||
// render description | ||
guiGraphics.drawCenteredString( | ||
internalMinecraft.font, | ||
screenComponent("modify.item.description"), | ||
internalMinecraft.screen!!.width / 2, | ||
internalMinecraft.screen!!.height / 10, | ||
0xFFFFFF | ||
) | ||
|
||
// render item edit box | ||
itemEditBox.setPosition(internalMinecraft.screen!!.width / 3, internalMinecraft.screen!!.height / 8) | ||
itemEditBox.width = internalMinecraft.screen!!.width / 3 | ||
itemEditBox.render(guiGraphics, mouseX, mouseY, tickDelta) | ||
|
||
// render item list if edit box is selected | ||
itemListWidget.render(guiGraphics, mouseX, mouseY, tickDelta) | ||
|
||
// render components text and edit box | ||
guiGraphics.drawCenteredString( | ||
internalMinecraft.font, | ||
screenComponent("modify.components.description"), | ||
internalMinecraft.screen!!.width / 2, | ||
(internalMinecraft.screen!!.height * .4).toInt(), | ||
0xFFFFFF | ||
) | ||
|
||
componentsEditBox.setPosition( | ||
internalMinecraft.screen!!.width / 3, (internalMinecraft.screen!!.height * .45).toInt() | ||
) | ||
componentsEditBox.width = internalMinecraft.screen!!.width / 3 | ||
componentsEditBox.render(guiGraphics, mouseX, mouseY, tickDelta) | ||
|
||
// render amount text and edit box | ||
guiGraphics.drawCenteredString( | ||
internalMinecraft.font, | ||
screenComponent("modify.amount.description"), | ||
internalMinecraft.screen!!.width / 2, | ||
(internalMinecraft.screen!!.height * .575).toInt(), | ||
0xFFFFFF | ||
) | ||
|
||
amountEditBox.setPosition( | ||
internalMinecraft.screen!!.width / 3, (internalMinecraft.screen!!.height * .625).toInt() | ||
) | ||
amountEditBox.width = internalMinecraft.screen!!.width / 3 | ||
amountEditBox.render(guiGraphics, mouseX, mouseY, tickDelta) | ||
|
||
// render done button | ||
doneButton.setPosition(internalMinecraft.screen!!.width / 3, (internalMinecraft.screen!!.height * .8).toInt()) | ||
doneButton.width = internalMinecraft.screen!!.width / 3 | ||
doneButton.render(guiGraphics, mouseX, mouseY, tickDelta) | ||
doneButton.active = matcher() | ||
} | ||
|
||
override fun shouldCloseOnEsc(): Boolean { | ||
return matcher() | ||
} | ||
|
||
override fun onClose() { | ||
itemIdentifier.components = DataComponentPatchSerializer.toPatch(componentsEditBox.value) | ||
itemIdentifier.amount = amountEditBox.value.toInt() | ||
internalMinecraft.setScreen(parent) | ||
saveConfig(config) | ||
parent.archiveItemsWidget.refreshEntries() | ||
} | ||
} |
Oops, something went wrong.