Skip to content

Commit

Permalink
feat: use Scrollable guiy's for blocky-menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jun 8, 2024
1 parent c47cc8b commit 4492012
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 98 deletions.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
group=com.mineinabyss
version=0.10
idofrontVersion=0.24.4
idofrontVersion=0.24.5

2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
gearyPaper = "0.30.1"
guiy="0.10.0"
guiy="0.12-dev"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" }
Expand Down
10 changes: 1 addition & 9 deletions src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.mineinabyss.blocky

import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.blocky.assets_generation.ResourcepackGeneration
import com.mineinabyss.blocky.components.core.BlockyFurniture
import com.mineinabyss.blocky.components.features.blocks.BlockyDirectional
import com.mineinabyss.blocky.helpers.gearyInventory
import com.mineinabyss.blocky.menus.BlockyMainMenu
import com.mineinabyss.blocky.systems.blockPrefabs
import com.mineinabyss.blocky.systems.megFurniturePrefabs
Expand All @@ -13,19 +11,14 @@ import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.prefabs
import com.mineinabyss.guiy.inventory.guiy
import com.mineinabyss.idofront.commands.arguments.optionArg
import com.mineinabyss.idofront.commands.arguments.stringArg
import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor
import com.mineinabyss.idofront.commands.extensions.actions.playerAction
import com.mineinabyss.idofront.items.asColorable
import com.mineinabyss.idofront.items.editItemMeta
import com.mineinabyss.idofront.messaging.error
import com.mineinabyss.idofront.messaging.success
import com.mineinabyss.idofront.util.toColor
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import org.bukkit.entity.Player
import org.bukkit.inventory.EquipmentSlot

class BlockyCommandExecutor : IdofrontCommandExecutor(), TabCompleter {
override val commands = commands(blocky.plugin) {
Expand Down Expand Up @@ -70,8 +63,7 @@ class BlockyCommandExecutor : IdofrontCommandExecutor(), TabCompleter {
}
"menu" {
playerAction {
val player = sender as Player
guiy { BlockyMainMenu(player) }
guiy { BlockyMainMenu(sender as Player) }
}
}
}
Expand Down
22 changes: 0 additions & 22 deletions src/main/kotlin/com/mineinabyss/blocky/menus/BlockyBlockMenu.kt

This file was deleted.

This file was deleted.

22 changes: 10 additions & 12 deletions src/main/kotlin/com/mineinabyss/blocky/menus/BlockyMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import androidx.compose.runtime.Composable
import com.mineinabyss.blocky.blocky
import com.mineinabyss.guiy.components.Item
import com.mineinabyss.guiy.modifiers.Modifier
import com.mineinabyss.guiy.modifiers.at
import com.mineinabyss.guiy.modifiers.click.clickable
import com.mineinabyss.guiy.modifiers.placement.absolute.at

@Composable
fun BlockyUIScope.BlockyMenu() {
Item(blocky.config.menus.defaultMenu.blockButton.toItemStack(), Modifier.at(2,1).clickable {
nav.open(BlockyScreen.Block())
})
Item(blocky.config.menus.defaultMenu.blockButton.toItemStack(), Modifier.at(2, 1).clickable {
nav.open(BlockyScreen.Block())
})

Item(blocky.config.menus.defaultMenu.wireButton.toItemStack(), Modifier.at(4,1).clickable {
nav.open(BlockyScreen.Wire())
})
Item(blocky.config.menus.defaultMenu.wireButton.toItemStack(), Modifier.at(4, 1).clickable {
nav.open(BlockyScreen.Wire())
})

Item(blocky.config.menus.defaultMenu.furnitureButton.toItemStack(), Modifier.at(6,1).clickable {
nav.open(BlockyScreen.Furniture())
})

BackButton(Modifier.at(0, 4))
Item(blocky.config.menus.defaultMenu.furnitureButton.toItemStack(), Modifier.at(6, 1).clickable {
nav.open(BlockyScreen.Furniture())
})
}
98 changes: 89 additions & 9 deletions src/main/kotlin/com/mineinabyss/blocky/menus/BlockyNavigation.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.mineinabyss.blocky.menus

import androidx.compose.runtime.Composable
import androidx.compose.runtime.*
import com.mineinabyss.blocky.blocky
import com.mineinabyss.blocky.helpers.composables.Button
import com.mineinabyss.blocky.systems.furniturePrefabs
import com.mineinabyss.blocky.systems.plantPrefabs
import com.mineinabyss.geary.papermc.tracking.items.gearyItems
import com.mineinabyss.guiy.components.CreativeItem
import com.mineinabyss.guiy.components.HorizontalGrid
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.Scrollable
import com.mineinabyss.guiy.inventory.LocalGuiyOwner
import com.mineinabyss.guiy.modifiers.Modifier
import com.mineinabyss.guiy.modifiers.click.clickable
import com.mineinabyss.guiy.modifiers.height
import com.mineinabyss.guiy.modifiers.placement.absolute.at
import com.mineinabyss.guiy.modifiers.size
import com.mineinabyss.guiy.navigation.Navigator
import com.mineinabyss.idofront.items.editItemMeta
import com.mineinabyss.idofront.textcomponents.miniMsg
Expand All @@ -34,24 +45,93 @@ fun BlockyMainMenu(player: Player) {
val owner = LocalGuiyOwner.current
BlockyUIScope(player).apply {
nav.withScreen(setOf(player), onEmpty = owner::exit) { screen ->
Chest(setOf(player), screen.title, Modifier.height(screen.height), onClose = { player.closeInventory() }) {
var title by remember(screen) { mutableStateOf(screen.handleTitle(0)) }
Chest(setOf(player), title, Modifier.height(screen.height), onClose = { owner.exit() }) {
when (screen) {
is BlockyScreen.Default -> BlockyMenu()
is BlockyScreen.Block -> BlockyBlockMenu()
is BlockyScreen.Wire -> BlockyWireMenu()
is BlockyScreen.Furniture -> BlockyFurnitureMenu()
else -> {
var line by remember(screen) { mutableStateOf(0) }
val items = remember(screen) {
when (screen) {
is BlockyScreen.Block -> return@remember Material.entries.drop(1).map { ItemStack(it) }
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
) { pageItems ->
VerticalGrid(Modifier.size(8, 5)) {
pageItems.forEach { CreativeItem(it) }
}
}

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

private fun BlockyScreen.handleTitle(page: Int): String {
if (this is BlockyScreen.Default) return title
return buildString {
append(title)
append(":space_-26:")
if (page > 0) append(":blocky_scrolling_up::space_-18:")
append(":blocky_scrolling_down:")
}
}

@Composable
fun PaginatedNextButton(modifier: Modifier = Modifier, onClick: () -> Unit) {
Button(onClick = onClick, modifier = modifier) {
Item(ItemStack(Material.PAPER).editItemMeta {
itemName("<green><b>Next".miniMsg())
setCustomModelData(0)
}, modifier)
}
}

@Composable
fun PaginatedPrevButton(modifier: Modifier = Modifier, onClick: () -> Unit) {
Button(onClick = onClick, modifier = modifier) {
Item(ItemStack(Material.PAPER).editItemMeta {
itemName("<red><b>Previous".miniMsg())
setCustomModelData(0)
}, modifier)
}
}

@Composable
fun ScrollDownButton(modifier: Modifier = Modifier) {
Item(ItemStack(Material.PAPER).editItemMeta {
itemName("<green><b>Scroll Down".miniMsg())
setCustomModelData(0)
}, modifier)
}

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

@Composable
fun BlockyUIScope.BackButton(modifier: Modifier = Modifier) {
Button(onClick = { nav.back() }, modifier = modifier) {
fun BlockyUIScope.BackButton(modifier: Modifier = Modifier, onClick: () -> Unit = { nav.back() }) {
Button(onClick = onClick, modifier = modifier) {
Item(ItemStack(Material.PAPER).editItemMeta {
displayName("<red><b>Back".miniMsg())
setCustomModelData(1)
itemName("<red><b>Back".miniMsg())
setCustomModelData(0)
})
}
}
22 changes: 0 additions & 22 deletions src/main/kotlin/com/mineinabyss/blocky/menus/BlockyWireMenu.kt

This file was deleted.

0 comments on commit 4492012

Please sign in to comment.