diff options
author | nea <nea@nea.moe> | 2023-08-24 18:12:39 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-08-24 18:12:39 +0200 |
commit | b0cb9a70cd9a3f02b86e0386ab6bb70974bba35a (patch) | |
tree | ddb5e478c321e87c424f002b959265b25891b943 /src/main/kotlin/moe/nea/firmament/gui | |
parent | 8c5570bfe6ab93855e24e6924fac1105fe8342ff (diff) | |
download | Firmament-b0cb9a70cd9a3f02b86e0386ab6bb70974bba35a.tar.gz Firmament-b0cb9a70cd9a3f02b86e0386ab6bb70974bba35a.tar.bz2 Firmament-b0cb9a70cd9a3f02b86e0386ab6bb70974bba35a.zip |
Revive old profile viewer
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt | 63 |
2 files changed, 64 insertions, 1 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt index bebcbcc..5561476 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt @@ -9,7 +9,7 @@ package moe.nea.firmament.gui.profileviewer import io.github.cottonmc.cotton.gui.client.CottonClientScreen import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription import io.github.cottonmc.cotton.gui.widget.WTabPanel -import java.util.UUID +import java.util.* import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import kotlinx.coroutines.launch import net.minecraft.text.Text diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt new file mode 100644 index 0000000..3c49443 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt @@ -0,0 +1,63 @@ +package moe.nea.firmament.gui.profileviewer + +import com.mojang.brigadier.StringReader +import io.github.cottonmc.cotton.gui.client.CottonClientScreen +import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription +import io.github.cottonmc.cotton.gui.widget.WGridPanel +import io.github.cottonmc.cotton.gui.widget.WText +import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment +import moe.nea.firmament.gui.WTitledItem +import moe.nea.firmament.util.ScreenUtil +import moe.nea.firmament.util.modifyLore +import moe.nea.lisp.LispData +import moe.nea.lisp.LispExecutionContext +import moe.nea.lisp.LispParser +import moe.nea.lisp.bind.AutoBinder +import moe.nea.lisp.bind.LispBinding +import moe.nea.lisp.bind.UnmapForeignObject +import net.minecraft.command.argument.ItemStringReader +import net.minecraft.item.ItemStack +import net.minecraft.registry.Registries +import net.minecraft.text.Text + +class ProfileViewerLibrary { + + @LispBinding("mk-item") + fun makeItem(itemType: String, title: String, vararg lore: String): LispData.ForeignObject<ItemStack> { + val item = ItemStringReader.item(Registries.ITEM.readOnlyWrapper, StringReader(itemType)) + val itemStack = ItemStack(item.item.value()) + itemStack.nbt = item.nbt + itemStack.modifyLore { lore.map { Text.literal(it) } } + itemStack.setCustomName(Text.literal(title)) + return LispData.ForeignObject(itemStack) + } + + @LispBinding("def-page") + fun defPage(name: String, @UnmapForeignObject icon: ItemStack) { + pages.add(Pair(name, icon)) + } + + val pages = mutableListOf<Pair<String, ItemStack>>() + val coreEnvironment = LispExecutionContext() + + fun run() { + val t = coreEnvironment.genBindings() + val ab = AutoBinder() + ab.bindTo(this, t) + val prog = LispParser.parse( + "testfile.lisp", """ + (def-page "Test" (mk-item "minecraft:tnt" "§aThis is a test page" "§aMore text")) + (def-page "Skills" (mk-item "minecraft:diamond_sword" "§aThis is a test page" "§aMore text")) + """.trimIndent() + ) + coreEnvironment.executeProgram(t, prog) + val light = LightweightGuiDescription() + val root = light.rootPanel as WGridPanel + root.setGaps(8, 8) + pages.forEachIndexed { i, (name, item) -> + root.add(WTitledItem(item), 0, i) + root.add(WText(Text.literal(name)).also { it.verticalAlignment = VerticalAlignment.CENTER }, 1, i, 6, 1) + } + ScreenUtil.setScreenLater(CottonClientScreen(light)) + } +} |