Skip to content

Commit

Permalink
fix: scrolling sub-menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Aug 20, 2024
1 parent cd47588 commit dba5795
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group=com.mineinabyss
version=0.10
idofrontVersion=0.24.16
idofrontVersion=0.25.3

4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
gearyPaper = "0.30.10-dev.9"
guiy="0.12.1"
gearyPaper = "0.30.14"
guiy="0.12.4-dev.1"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" }
Expand Down
40 changes: 18 additions & 22 deletions src/main/kotlin/com/mineinabyss/blocky/BlockyDatapacks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,29 @@ object BlockyDatapacks {
}

private fun writeMcMeta() {
runCatching {
val packMeta = blockyDatapack.resolve("pack.mcmeta")
packMeta.writeText(buildJsonObject {
putJsonObject("pack") {
put("description", "Datapack for Blocky")
put("pack_format", 26)
}
}.toString())
}.onFailure { it.printStackTrace() }
val packMeta = blockyDatapack.resolve("pack.mcmeta")
packMeta.writeText(buildJsonObject {
putJsonObject("pack") {
put("description", "Datapack for Blocky")
put("pack_format", 26)
}
}.toString())
}

private fun generateMineableTag() {
runCatching {
val tagFile = blockyDatapack.resolve("data/minecraft/tags/block/mineable/axe.json")
tagFile.parentFile.mkdirs()
tagFile.createNewFile()

val tagObject = buildJsonObject {
put("replace", true)
putJsonArray("values") {
BuiltInRegistries.BLOCK.tags.toList().find { it.first == BlockTags.MINEABLE_WITH_AXE }?.second?.forEach {
if (it.registeredName != "minecraft:note_block") add(it.registeredName)
}
val tagFile = blockyDatapack.resolve("data/minecraft/tags/block/mineable/axe.json")
tagFile.parentFile.mkdirs()
tagFile.createNewFile()

val tagObject = buildJsonObject {
put("replace", true)
putJsonArray("values") {
BuiltInRegistries.BLOCK.tags.toList().find { it.first == BlockTags.MINEABLE_WITH_AXE }?.second?.forEach {
if (it.registeredName != "minecraft:note_block") add(it.registeredName)
}
}
}

tagFile.writeText(tagObject.toString())
}.onFailure { it.printStackTrace() }
tagFile.writeText(tagObject.toString())
}
}
54 changes: 28 additions & 26 deletions src/main/kotlin/com/mineinabyss/blocky/menus/BlockyNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.mineinabyss.guiy.components.Item
import com.mineinabyss.guiy.components.VerticalGrid
import com.mineinabyss.guiy.components.canvases.Chest
import com.mineinabyss.guiy.components.lists.NavbarPosition
import com.mineinabyss.guiy.components.lists.ScrollDirection
import com.mineinabyss.guiy.components.lists.Scrollable
import com.mineinabyss.guiy.inventory.LocalGuiyOwner
import com.mineinabyss.guiy.modifiers.Modifier
Expand Down Expand Up @@ -46,45 +47,47 @@ fun BlockyMainMenu(player: Player) {
val owner = LocalGuiyOwner.current
BlockyUIScope(player).apply {
nav.withScreen(setOf(player), onEmpty = owner::exit) { screen ->
var title by remember(screen) { mutableStateOf(screen.handleTitle(0)) }
val items = remember(screen) {
when (screen) {
is BlockyScreen.Block -> blockPrefabs
is BlockyScreen.Wire -> plantPrefabs
is BlockyScreen.Furniture -> furniturePrefabs
else -> return@remember emptyList()
}.sortedBy { it.prefabKey.full }.map { gearyItems.createItem(it.prefabKey) }
}
val hasMultiplePages by remember(screen) { mutableStateOf(items.size.toDouble().div(9 * 5) > 1) }
var title by remember(screen) { mutableStateOf(handleTitle(screen, 0, hasMultiplePages)) }
var line by remember(screen) { mutableStateOf(0) }

Chest(setOf(player), title, Modifier.height(screen.height), onClose = { owner.exit() }) {
when (screen) {
is BlockyScreen.Default -> BlockyMenu()
else -> {
var line by remember(screen) { mutableStateOf(0) }
val items = remember(screen) {
when (screen) {
is BlockyScreen.Block -> blockPrefabs
is BlockyScreen.Wire -> plantPrefabs
is BlockyScreen.Furniture -> furniturePrefabs
else -> return@remember emptyList()
}.sortedBy { it.prefabKey.full }.map { gearyItems.createItem(it.prefabKey) }
}

Scrollable(
items, line, 8, 5,
nextButton = { ScrollDownButton(Modifier.at(0, 3).clickable { line++; title = screen.handleTitle(line) }) },
previousButton = { ScrollUpButton(Modifier.at(0, 1).clickable { line--; title = screen.handleTitle(line) }) },
NavbarPosition.START, null
items, line, ScrollDirection.VERTICAL,
nextButton = { ScrollDownButton(Modifier.at(5, 0).clickable { line++; title = handleTitle(screen, line, hasMultiplePages) }) },
previousButton = { ScrollUpButton(Modifier.at(2, 0).clickable { line--; title = handleTitle(screen, line, hasMultiplePages) }) },
NavbarPosition.BOTTOM, null
) { pageItems ->
VerticalGrid(Modifier.size(8, 5)) {
VerticalGrid(Modifier.size(9, 5)) {
pageItems.forEach { CreativeItem(it) }
}
}

BackButton(Modifier.at(0, 5))
BackButton(Modifier.at(8, 5))
}
}
}
}
}
}

private fun BlockyScreen.handleTitle(page: Int): Component {
if (this is BlockyScreen.Default) return title
return Component.textOfChildren(title, buildString {
append(":space_-26:")
if (page > 0) append(":blocky_scrolling_up::space_-18:")
private fun handleTitle(screen: BlockyScreen, page: Int, hasMultiplePages: Boolean): Component {
if (screen is BlockyScreen.Default) return screen.title
return Component.textOfChildren(screen.title, buildString {
if (!hasMultiplePages) return@buildString
if (page > 0) append(":space_-132::blocky_scrolling_up::space_36:")
else append(":space_-80:")
append(":blocky_scrolling_down:")
}.miniMsg())
}
Expand All @@ -93,16 +96,15 @@ private fun BlockyScreen.handleTitle(page: Int): Component {
fun ScrollDownButton(modifier: Modifier = Modifier) {
Item(ItemStack(Material.PAPER).editItemMeta {
itemName("<green><b>Scroll Down".miniMsg())
setCustomModelData(0)
setCustomModelData(1)
}, modifier)
}

@Composable
fun ScrollUpButton(modifier: Modifier = Modifier) {
Item(ItemStack(Material.PAPER).editItemMeta {
itemName("<blue><b>Scroll Up".miniMsg())
isHideTooltip = true
setCustomModelData(0)
setCustomModelData(1)
}, modifier)
}

Expand All @@ -111,7 +113,7 @@ fun BlockyUIScope.BackButton(modifier: Modifier = Modifier, onClick: () -> Unit
Button(onClick = onClick, modifier = modifier) {
Item(ItemStack(Material.PAPER).editItemMeta {
itemName("<red><b>Back".miniMsg())
setCustomModelData(0)
setCustomModelData(1)
})
}
}

0 comments on commit dba5795

Please sign in to comment.