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 41d74b4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 55 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())
}
}
13 changes: 13 additions & 0 deletions src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.mineinabyss.blocky.assets_generation.ResourcepackGeneration
import com.mineinabyss.blocky.compatibility.worldedit.WorldEditListener
import com.mineinabyss.blocky.compatibility.worldedit.WorldEditSupport
import com.mineinabyss.blocky.listeners.*
import com.mineinabyss.blocky.menus.BlockyScreen
import com.mineinabyss.blocky.systems.*
import com.mineinabyss.blocky.systems.actions.createFurnitureItemSetter
import com.mineinabyss.blocky.systems.actions.createFurnitureMEGModelSetter
Expand All @@ -20,8 +21,10 @@ import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.messaging.observeLogger
import com.mineinabyss.idofront.plugin.Plugins
import com.mineinabyss.idofront.plugin.listeners
import com.mineinabyss.idofront.textcomponents.miniMsg
import com.sk89q.worldedit.WorldEdit
import io.papermc.paper.configuration.GlobalConfiguration
import net.kyori.adventure.text.Component
import org.bukkit.block.data.BlockData
import org.bukkit.plugin.java.JavaPlugin

Expand All @@ -36,6 +39,16 @@ class BlockyPlugin : JavaPlugin() {
}
}

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())
}

override fun onEnable() {
createBlockyContext()

Expand Down
52 changes: 22 additions & 30 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,63 +47,54 @@ 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(blocky.plugin.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 = blocky.plugin.handleTitle(screen, line, hasMultiplePages) }) },
previousButton = { ScrollUpButton(Modifier.at(2, 0).clickable { line--; title = blocky.plugin.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:")
append(":blocky_scrolling_down:")
}.miniMsg())
}

@Composable
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 +103,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 41d74b4

Please sign in to comment.