diff options
Diffstat (limited to 'src/main')
4 files changed, 74 insertions, 27 deletions
diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButton.kt b/src/main/kotlin/features/inventory/buttons/InventoryButton.kt index 955ae88..0a1121d 100644 --- a/src/main/kotlin/features/inventory/buttons/InventoryButton.kt +++ b/src/main/kotlin/features/inventory/buttons/InventoryButton.kt @@ -5,6 +5,7 @@ import me.shedaniel.math.Dimension import me.shedaniel.math.Point import me.shedaniel.math.Rectangle import kotlinx.serialization.Serializable +import net.minecraft.client.gl.RenderPipelines import net.minecraft.client.gui.DrawContext import net.minecraft.command.CommandRegistryAccess import net.minecraft.command.argument.ItemStackArgumentType @@ -13,7 +14,9 @@ import net.minecraft.resource.featuretoggle.FeatureFlags import net.minecraft.util.Identifier import moe.nea.firmament.repo.ExpensiveItemCacheApi import moe.nea.firmament.repo.ItemCache.asItemStack +import moe.nea.firmament.repo.ItemCache.isBroken import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.MC import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.collections.memoize @@ -29,7 +32,11 @@ data class InventoryButton( var anchorBottom: Boolean, var icon: String? = "", var command: String? = "", + var isGigantic: Boolean = false, ) { + + val myDimension get() = if (isGigantic) bigDimension else dimensions + companion object { val itemStackParser by lazy { ItemStackArgumentType.itemStack( @@ -40,7 +47,10 @@ data class InventoryButton( ) } val dimensions = Dimension(18, 18) + val gap = 2 + val bigDimension = Dimension(dimensions.width * 2 + gap, dimensions.height * 2 + gap) val getItemForName = ::getItemForName0.memoize(1024) + @OptIn(ExpensiveItemCacheApi::class) fun getItemForName0(icon: String): ItemStack { val repoItem = RepoManager.getNEUItem(SkyblockId(icon)) @@ -67,20 +77,30 @@ data class InventoryButton( } } } + if (itemStack.isBroken) + ErrorUtil.logError("created broken itemstack for inventory button $icon: $itemStack") return itemStack } } fun render(context: DrawContext) { context.drawGuiTexture( + RenderPipelines.GUI_TEXTURED, + Identifier.of("firmament:inventory_button_background"), 0, 0, - 0, - dimensions.width, - dimensions.height, - Identifier.of("firmament:inventory_button_background") + myDimension.width, + myDimension.height, ) - context.drawItem(getItem(), 1, 1) + if (isGigantic) { + context.matrices.pushMatrix() + context.matrices.translate(myDimension.width / 2F, myDimension.height / 2F) + context.matrices.scale(2F) + context.drawItem(getItem(), -8, -8) + context.matrices.popMatrix() + } else { + context.drawItem(getItem(), 1, 1) + } } fun isValid() = !icon.isNullOrBlank() && !command.isNullOrBlank() @@ -93,7 +113,7 @@ data class InventoryButton( } fun getBounds(guiRect: Rectangle): Rectangle { - return Rectangle(getPosition(guiRect), dimensions) + return Rectangle(getPosition(guiRect), myDimension) } fun getItem(): ItemStack { diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt index 7334c82..d862bb1 100644 --- a/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt +++ b/src/main/kotlin/features/inventory/buttons/InventoryButtonEditor.kt @@ -32,6 +32,9 @@ class InventoryButtonEditor( @field:Bind var icon: String = originalButton.icon ?: "" + @field:Bind + var isGigantic: Boolean = originalButton.isGigantic + @Bind fun getItemIcon(): IItemStack { save() @@ -46,6 +49,7 @@ class InventoryButtonEditor( fun save() { originalButton.icon = icon + originalButton.isGigantic = isGigantic originalButton.command = command } } @@ -254,6 +258,14 @@ class InventoryButtonEditor( dragging.y = offsetY dragging.anchorRight = anchorRight dragging.anchorBottom = anchorBottom + if (!anchorRight && offsetX > -dragging.myDimension.width + && dragging.getBounds(lastGuiRect).intersects(lastGuiRect) + ) + dragging.x = -dragging.myDimension.width + if (!anchorRight && offsetY > -dragging.myDimension.height + && dragging.getBounds(lastGuiRect).intersects(lastGuiRect) + ) + dragging.y = -dragging.myDimension.height } } return false 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 6444236..6656634 100644 --- a/src/main/resources/assets/firmament/gui/button_editor_fragment.xml +++ b/src/main/resources/assets/firmament/gui/button_editor_fragment.xml @@ -1,24 +1,29 @@ <?xml version="1.0" encoding="UTF-8" ?> <Root xmlns="http://notenoughupdates.org/moulconfig"> - <Panel background="VANILLA" insets="10"> - <Column> - <Row> - <ItemStack value="@getItemIcon"/> - <Text text="Icon"/> - </Row> - <Hover lines="Put your display item in here.;Can be any SkyBlock item id.;;Alternatively you can paste in a /give command"> - <TextField value="@icon" width="180"/> - </Hover> - <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> - <Button onClick="@delete"> - <Text text="Delete"/> - </Button> - </Column> - </Panel> + <Panel background="VANILLA" insets="10"> + <Column> + <Row> + <ItemStack value="@getItemIcon"/> + <Text text="Icon"/> + </Row> + <Hover + lines="Put your display item in here.;Can be any SkyBlock item id.;;Alternatively you can paste in a /give command"> + <TextField value="@icon" width="180"/> + </Hover> + <Row> + <Switch value="@isGigantic"/> + <Text text="Big Button"/> + </Row> + <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> + <Button onClick="@delete"> + <Text text="Delete"/> + </Button> + </Column> + </Panel> </Root> diff --git a/src/main/resources/assets/firmament/textures/gui/sprites/inventory_button_background.png.mcmeta b/src/main/resources/assets/firmament/textures/gui/sprites/inventory_button_background.png.mcmeta new file mode 100644 index 0000000..55fb892 --- /dev/null +++ b/src/main/resources/assets/firmament/textures/gui/sprites/inventory_button_background.png.mcmeta @@ -0,0 +1,10 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 18, + "height": 18, + "border": 4 + } + } +} |
