aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2023-11-12 04:29:53 +0100
committerLinnea Gräf <nea@nea.moe>2023-11-12 04:29:53 +0100
commitf5515b455d607ddda5b215a8c4c1df9ff03e4117 (patch)
tree4e0db3f0ae019f63abc8d0c0feb91195d9b6d760 /src
parent15a20ef60a397e46021fdbcfc58a3f89214c500e (diff)
downloadfirmament-f5515b455d607ddda5b215a8c4c1df9ff03e4117.tar.gz
firmament-f5515b455d607ddda5b215a8c4c1df9ff03e4117.tar.bz2
firmament-f5515b455d607ddda5b215a8c4c1df9ff03e4117.zip
Add saving and loading to inventory button
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt28
-rw-r--r--src/main/resources/assets/firmament/gui/button_editor_fragment.xml15
2 files changed, 32 insertions, 11 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt
index 982bf31..f269242 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtonEditor.kt
@@ -1,22 +1,38 @@
package moe.nea.firmament.features.inventory.buttons
+import io.github.moulberry.moulconfig.common.IItemStack
import io.github.moulberry.moulconfig.xml.Bind
+import io.github.notenoughupdates.moulconfig.platform.ModernItemStack
import me.shedaniel.math.Dimension
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
import org.lwjgl.glfw.GLFW
import net.minecraft.client.gui.DrawContext
+import moe.nea.firmament.repo.ItemCache.asItemStack
+import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.MoulConfigUtils
+import moe.nea.firmament.util.SkyblockId
class InventoryButtonEditor(
val lastGuiRect: Rectangle,
) : FragmentGuiScreen() {
- class Editor {
+ class Editor(val originalButton: Button) {
@field:Bind
- var command: String = ""
+ var command: String = originalButton.command ?: ""
@field:Bind
- var icon: String = ""
+ var icon: String = originalButton.icon ?: ""
+
+ @Bind
+ fun getItemIcon(): IItemStack {
+ save()
+ return ModernItemStack.of(RepoManager.getNEUItem(SkyblockId(icon)).asItemStack(idHint = SkyblockId(icon)))
+ }
+
+ fun save() {
+ originalButton.icon = icon
+ originalButton.command = command
+ }
}
data class Button(
@@ -24,8 +40,8 @@ class InventoryButtonEditor(
val y: Int,
val anchorRight: Boolean,
val anchorBottom: Boolean,
- val icon: String?,
- val command: String?,
+ var icon: String?,
+ var command: String?,
) {
fun isValid() = !icon.isNullOrBlank() && !command.isNullOrBlank()
@@ -70,7 +86,7 @@ class InventoryButtonEditor(
if (super.mouseClicked(mouseX, mouseY, button)) return true
val clickedButton = buttons.firstOrNull { it.getBounds(lastGuiRect).contains(Point(mouseX, mouseY)) }
if (clickedButton != null) {
- createPopup(MoulConfigUtils.loadGui("button_editor_fragment", Editor()), Point(mouseX, mouseY))
+ createPopup(MoulConfigUtils.loadGui("button_editor_fragment", Editor(clickedButton)), Point(mouseX, mouseY))
return true
}
if (lastGuiRect.contains(mouseX, mouseY) || lastGuiRect.contains(Point(mouseX + 18, mouseY + 18))) return true
diff --git a/src/main/resources/assets/firmament/gui/button_editor_fragment.xml b/src/main/resources/assets/firmament/gui/button_editor_fragment.xml
index 954401a..b450c41 100644
--- a/src/main/resources/assets/firmament/gui/button_editor_fragment.xml
+++ b/src/main/resources/assets/firmament/gui/button_editor_fragment.xml
@@ -3,13 +3,18 @@
xsi:schemaLocation="http://notenoughupdates.org/moulconfig https://raw.githubusercontent.com/NotEnoughUpdates/MoulConfig/master/MoulConfig.xsd">
<Panel>
<Column>
- <Text text="Icon"/>
- <TextField value="@icon" width="180"/>
- <Text text="Command"/>
<Row>
- <Text text="/"/>
- <TextField value="@command" width="180"/>
+ <Text textAlign="CENTER" text="Icon"/>
+ <ItemStack value="@getItemIcon"/>
</Row>
+ <TextField value="@icon" width="180"/>
+ <Text text="Command"/>
+ <Hover lines="Put the command in here.;The text box should not start with a /">
+ <Row>
+ <Text text="/"/>
+ <TextField value="@command" width="180"/>
+ </Row>
+ </Hover>
</Column>
</Panel>
</Root>