-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: Document any user facing api like Composables and Modifiers
refactor: Remove interactable inventory composable due to high exploit potential feat: CreativeItem composable that mimics creative inventory item selector chore: Clean up some code relying on index in inventory to use x-y coordinate pairs chore: Update example to showcase CreativeItem chore: Update idofront, compose compiler, Kotlin
- Loading branch information
Showing
33 changed files
with
499 additions
and
316 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
kotlin.code.style=official | ||
group=com.mineinabyss | ||
version=0.9 | ||
idofrontVersion=0.23.0 | ||
version=0.10 | ||
idofrontVersion=0.24.0 |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
30 changes: 15 additions & 15 deletions
30
guiy-example/src/main/kotlin/com/mineinabyss/guiy/example/gui/MainMenu.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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
package com.mineinabyss.guiy.example.gui | ||
|
||
import androidx.compose.runtime.* | ||
import com.mineinabyss.guiy.components.CreativeItem | ||
import com.mineinabyss.guiy.components.Item | ||
import com.mineinabyss.guiy.components.ItemGrid | ||
import com.mineinabyss.guiy.components.canvases.Chest | ||
import com.mineinabyss.guiy.components.rememberItemGridState | ||
import com.mineinabyss.guiy.inventory.GuiyOwner | ||
import com.mineinabyss.guiy.components.state.ItemPositions | ||
import com.mineinabyss.guiy.inventory.LocalGuiyOwner | ||
import com.mineinabyss.guiy.layout.Row | ||
import com.mineinabyss.guiy.modifiers.Modifier | ||
import com.mineinabyss.guiy.modifiers.clickable | ||
import com.mineinabyss.guiy.modifiers.fillMaxWidth | ||
import com.mineinabyss.guiy.modifiers.size | ||
import kotlinx.coroutines.delay | ||
import org.bukkit.Material | ||
import org.bukkit.entity.Player | ||
import org.bukkit.event.inventory.ClickType | ||
import org.bukkit.inventory.ItemStack | ||
|
||
@Composable | ||
fun GuiyOwner.MainMenu(player: Player) { | ||
fun MainMenu(player: Player) { | ||
val owner = LocalGuiyOwner.current | ||
val title = "Hello world" | ||
val state = rememberItemGridState() | ||
Chest( | ||
setOf(player), | ||
title, | ||
onClose = { exit() }, | ||
modifier = Modifier.clickable { | ||
if(clickType == ClickType.SHIFT_LEFT) { | ||
cursor = cursor?.let { state.add(it, 4, 1) } | ||
} | ||
} | ||
onClose = { owner.exit() }, | ||
) { | ||
ItemGrid(state, Modifier.size(4, 1)) | ||
Row { | ||
listOf(Material.DIAMOND, Material.EMERALD, Material.GOLD_INGOT, Material.IRON_INGOT) | ||
.forEach { | ||
CreativeItem(ItemStack(it)) | ||
} | ||
Item(Material.BARRIER, "<red>No interaction here", modifier = Modifier.fillMaxWidth()) | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/com/mineinabyss/guiy/components/CreativeItem.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,38 @@ | ||
package com.mineinabyss.guiy.components | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.mineinabyss.guiy.modifiers.Modifier | ||
import com.mineinabyss.guiy.modifiers.click.clickable | ||
import org.bukkit.event.inventory.ClickType | ||
import org.bukkit.inventory.ItemStack | ||
|
||
/** | ||
* An item that acts like a creative inventory item that can be copied on click. | ||
*/ | ||
@Composable | ||
fun CreativeItem( | ||
itemStack: ItemStack?, modifier: Modifier = Modifier | ||
) { | ||
Item(itemStack, modifier.clickable { | ||
// Mimic all vanilla interactions | ||
val shiftClick = clickType == ClickType.SHIFT_LEFT || clickType == ClickType.SHIFT_RIGHT | ||
val result: ItemStack? = when { | ||
(shiftClick || clickType == ClickType.MIDDLE) && cursor == null -> itemStack?.clone() | ||
?.apply { amount = maxStackSize } | ||
|
||
clickType == ClickType.MIDDLE -> return@clickable | ||
|
||
(clickType == ClickType.SHIFT_LEFT && cursor != null && cursor.isSimilar(itemStack)) -> | ||
cursor.clone().apply { amount = maxStackSize } | ||
|
||
cursor == null -> itemStack?.clone()?.apply { amount = 1 } | ||
|
||
clickType == ClickType.RIGHT || clickType == ClickType.SHIFT_RIGHT -> cursor.clone().subtract() | ||
|
||
(clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT) && !cursor.isSimilar(itemStack) -> null | ||
|
||
else -> cursor.clone().add() | ||
} | ||
whoClicked.setItemOnCursor(result) | ||
}) | ||
} |
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
82 changes: 82 additions & 0 deletions
82
src/main/kotlin/com/mineinabyss/guiy/components/InteractableItemGrid.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,82 @@ | ||
package com.mineinabyss.guiy.components | ||
|
||
import androidx.compose.runtime.* | ||
|
||
// TODO implement a component where inventory events are NOT cancelled and state is propagated both ways | ||
// The current system makes it hard to do so safely (without allowing for dupes) | ||
/** | ||
* A grid of items that can be interacted with in an inventory. | ||
* | ||
* @param grid Positions of items in the grid. | ||
* @param onItemsChanged Executes when an item is changed (added, removed, or moved.) | ||
* @param modifier The modifier for the grid. | ||
*/ | ||
//@Composable | ||
//fun InteractableItemGrid( | ||
// grid: ItemPositions, | ||
// onItemsChanged: (pos: ItemPositions) -> Unit, | ||
// modifier: Modifier = Modifier, | ||
//) { | ||
// var size by remember { mutableStateOf(Size(0, 0)) } | ||
// Grid(modifier.onSizeChanged { size = it }.draggable { | ||
// //TODO | ||
//// grid.items + updatedItems.map { (i, item) -> IntCoordinates(i) to item } | ||
//// updatedItems.forEach { (i, item) -> | ||
//// cursor!!.amount -= abs(item.amount - (state.items[i]?.amount ?: 0)) | ||
//// state.items[i] = item | ||
//// } | ||
// }) { | ||
// for (x in 0 until size.width) { | ||
// for (y in 0 until size.height) { | ||
// val item = grid[x, y] | ||
// Item(item, Modifier.clickable(cancelClickEvent = true) { | ||
// onItemsChanged(grid.with(x, y, resultItem)) | ||
// val newItem = when (clickType) { | ||
// ClickType.LEFT -> { | ||
// if (item != null && cursor?.isSimilar(item) == true) { | ||
// val total = (item.amount + (cursor?.amount ?: 0)) | ||
// item.amount = total.coerceAtMost(item.maxStackSize) | ||
// cursor?.amount = total - item.amount | ||
// item | ||
// } else { | ||
// val temp = cursor | ||
// cursor = item | ||
// temp | ||
// } | ||
// } | ||
// | ||
// ClickType.RIGHT -> { | ||
// when { | ||
// cursor != null && item != null && cursor!!.type != item.type -> { | ||
// val temp = cursor | ||
// cursor = item | ||
// temp | ||
// } | ||
// | ||
// cursor == null && item != null -> { | ||
// val c = item.clone() | ||
// item.amount /= 2 | ||
// cursor = c.apply { | ||
// amount -= item.amount | ||
// } | ||
// item | ||
// } | ||
// | ||
// cursor != null -> { | ||
// val newItem = cursor!!.clone().apply { amount = (item?.amount ?: 0) + 1 } | ||
// cursor!!.amount -= 1 | ||
// newItem | ||
// } | ||
// | ||
// else -> return@clickable | ||
// } | ||
// } | ||
// | ||
// else -> return@clickable | ||
// } | ||
// onItemsChanged(grid.with(x, y, newItem)) | ||
// }) | ||
// } | ||
// } | ||
// } | ||
//} |
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
Oops, something went wrong.