diff options
| author | Linnea Gräf <nea@nea.moe> | 2024-07-01 03:42:51 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2024-07-03 21:05:51 +0200 |
| commit | 5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e (patch) | |
| tree | a5b0a6fbc8878ae62bb2c3a01dbb255388353fda | |
| parent | dff1f9c0e2b728dba902d72816104abccc61f511 (diff) | |
| download | Firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.gz Firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.bz2 Firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.zip | |
[WIP] Remove LibGUI
44 files changed, 418 insertions, 1120 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index df4f25f..8fe454f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -122,11 +122,9 @@ dependencies { modImplementation(libs.fabric.loader) modImplementation(libs.fabric.kotlin) modImplementation(libs.modmenu) - modImplementation(libs.libgui) modImplementation(libs.moulconfig) modImplementation(libs.manninghamMills) modCompileOnly(libs.explosiveenhancement) - include(libs.libgui) include(libs.manninghamMills) include(libs.moulconfig) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e848e89..bda5817 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -44,7 +44,6 @@ moulconfig = { module = "org.notenoughupdates.moulconfig:modern", version.ref = repoparser = { module = "moe.nea:neurepoparser", version.ref = "neurepoparser" } dbus_java_core = { module = "com.github.hypfvieh:dbus-java-core", version.ref = "dbus_java" } dbus_java_unixsocket = { module = "com.github.hypfvieh:dbus-java-transport-native-unixsocket", version.ref = "dbus_java" } -libgui = { module = "io.github.cottonmc:LibGui", version.ref = "libgui" } mixinextras = { module = "io.github.llamalad7:mixinextras-fabric", version.ref = "mixinextras" } jarvis_api = { module = "moe.nea.jarvis:jarvis-api", version.ref = "jarvis" } jarvis_fabric = { module = "moe.nea.jarvis:jarvis-fabric", version.ref = "jarvis" } diff --git a/src/main/kotlin/moe/nea/firmament/commands/rome.kt b/src/main/kotlin/moe/nea/firmament/commands/rome.kt index dc46f1f..6ec09f2 100644 --- a/src/main/kotlin/moe/nea/firmament/commands/rome.kt +++ b/src/main/kotlin/moe/nea/firmament/commands/rome.kt @@ -20,7 +20,6 @@ import moe.nea.firmament.features.world.FairySouls import moe.nea.firmament.gui.config.AllConfigsGui import moe.nea.firmament.gui.config.BooleanHandler import moe.nea.firmament.gui.config.ManagedOption -import moe.nea.firmament.gui.profileviewer.ProfileViewer import moe.nea.firmament.repo.HypixelStaticData import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.FirmFormatters @@ -28,7 +27,6 @@ import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData import moe.nea.firmament.util.ScreenUtil import moe.nea.firmament.util.SkyblockId -import moe.nea.firmament.util.unformattedString fun firmamentCommand() = literal("firmament") { @@ -127,19 +125,6 @@ fun firmamentCommand() = literal("firmament") { } } } - thenLiteral("pv") { - thenExecute { - ProfileViewer.onCommand(source, MC.player!!.name.unformattedString) - } - thenArgument("name", string()) { name -> - suggestsList { - MC.world?.players?.filter { it.uuid?.version() == 4 }?.map { it.name.unformattedString } ?: listOf() - } - thenExecute { - ProfileViewer.onCommand(source, get(name)) - } - } - } thenLiteral("price") { thenArgument("item", string()) { item -> suggestsList { RepoManager.neuRepo.items.items.keys } @@ -155,7 +140,7 @@ fun firmamentCommand() = literal("firmament") { source.sendFeedback( Text.stringifiedTranslatable( "firmament.price.bazaar.buy.price", - FirmFormatters.formatCurrency(bazaarData.quickStatus.buyPrice, 1) + FirmFormatters.formatCommas(bazaarData.quickStatus.buyPrice, 1) ) ) source.sendFeedback( @@ -167,7 +152,7 @@ fun firmamentCommand() = literal("firmament") { source.sendFeedback( Text.stringifiedTranslatable( "firmament.price.bazaar.sell.price", - FirmFormatters.formatCurrency(bazaarData.quickStatus.sellPrice, 1) + FirmFormatters.formatCommas(bazaarData.quickStatus.sellPrice, 1) ) ) source.sendFeedback( @@ -182,7 +167,7 @@ fun firmamentCommand() = literal("firmament") { source.sendFeedback( Text.stringifiedTranslatable( "firmament.price.lowestbin", - FirmFormatters.formatCurrency(lowestBin, 1) + FirmFormatters.formatCommas(lowestBin, 1) ) ) } diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt b/src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt index 4ba8eee..972eb1f 100644 --- a/src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt +++ b/src/main/kotlin/moe/nea/firmament/features/debug/DebugView.kt @@ -6,12 +6,6 @@ package moe.nea.firmament.features.debug -import io.github.cottonmc.cotton.gui.client.CottonHud -import io.github.cottonmc.cotton.gui.widget.WBox -import io.github.cottonmc.cotton.gui.widget.WDynamicLabel -import io.github.cottonmc.cotton.gui.widget.data.Axis -import java.util.stream.Collectors -import kotlin.time.Duration.Companion.seconds import moe.nea.firmament.Firmament import moe.nea.firmament.events.TickEvent import moe.nea.firmament.features.FirmamentFeature @@ -36,24 +30,8 @@ object DebugView : FirmamentFeature { } fun recalculateDebugWidget() { - storedVariables.entries.removeIf { it.value.timer.passedTime() > 1.seconds } - debugWidget.streamChildren().collect(Collectors.toList()).forEach { - debugWidget.remove(it) - } - storedVariables.entries.forEach { - debugWidget.add(WDynamicLabel({ "${it.key}: ${it.value.obj}" })) - } - debugWidget.layout() - if (storedVariables.isNotEmpty()) { - CottonHud.add(debugWidget, 20, 20) - } else { - CottonHud.remove(debugWidget) - } } - val debugWidget = WBox(Axis.VERTICAL) - - override fun onLoad() { TickEvent.subscribe { synchronized(this) { diff --git a/src/main/kotlin/moe/nea/firmament/features/debug/ObjectRenderer.kt b/src/main/kotlin/moe/nea/firmament/features/debug/ObjectRenderer.kt deleted file mode 100644 index 18f502c..0000000 --- a/src/main/kotlin/moe/nea/firmament/features/debug/ObjectRenderer.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -package moe.nea.firmament.features.debug - -import io.github.cottonmc.cotton.gui.widget.WBox -import io.github.cottonmc.cotton.gui.widget.WLabel -import io.github.cottonmc.cotton.gui.widget.WWidget -import io.github.cottonmc.cotton.gui.widget.data.Axis -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json -import kotlin.reflect.KProperty1 -import net.minecraft.text.Text -import moe.nea.firmament.gui.WSpacer - -class ObjectRenderer(val box: WBox) { - var indent = 0 - - fun beginObject() { - indent++ - } - - fun endObject() { - indent-- - } - - fun emit(label: String, widget: WWidget) { - WSpacer(WBox(Axis.VERTICAL).also { - it.add(WWidget()) - it.add(widget) - }, indent * 18) - } - - fun <T : Any?> getDebuggingView(label: String, obj: T) { - if (obj == null) { - emit(label, WLabel(Text.literal("§cnull"))) - return - } - if (obj is String) { - emit(label, WLabel(Text.literal(Json.encodeToString(obj)))) - } - getObject(label, obj) - } - - fun <T : Any> getObject(label: String, obj: T) { - emit(label, WLabel(Text.literal(obj::class.simpleName ?: "<unknown>"))) - beginObject() - for (prop in obj::class.members.filterIsInstance<KProperty1<T, *>>()) { - val child = prop.get(obj) - getDebuggingView(prop.name, child) - } - endObject() - } - -} diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt index fb99c7c..2e6d5c6 100644 --- a/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt @@ -39,17 +39,17 @@ object PriceData : FirmamentFeature { it.lines.add(Text.literal("")) it.lines.add( Text.stringifiedTranslatable("firmament.tooltip.bazaar.sell-order", - FirmFormatters.formatCurrency(bazaarData.quickStatus.sellPrice, 1)) + FirmFormatters.formatCommas(bazaarData.quickStatus.sellPrice, 1)) ) it.lines.add( Text.stringifiedTranslatable("firmament.tooltip.bazaar.buy-order", - FirmFormatters.formatCurrency(bazaarData.quickStatus.buyPrice, 1)) + FirmFormatters.formatCommas(bazaarData.quickStatus.buyPrice, 1)) ) } else if (lowestBin != null) { it.lines.add(Text.literal("")) it.lines.add( Text.stringifiedTranslatable("firmament.tooltip.ah.lowestbin", - FirmFormatters.formatCurrency(lowestBin, 1)) + FirmFormatters.formatCommas(lowestBin, 1)) ) } } diff --git a/src/main/kotlin/moe/nea/firmament/features/mining/PristineProfitTracker.kt b/src/main/kotlin/moe/nea/firmament/features/mining/PristineProfitTracker.kt index 1597501..dd2d2fb 100644 --- a/src/main/kotlin/moe/nea/firmament/features/mining/PristineProfitTracker.kt +++ b/src/main/kotlin/moe/nea/firmament/features/mining/PristineProfitTracker.kt @@ -18,7 +18,7 @@ import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.gui.hud.MoulConfigHud import moe.nea.firmament.util.BazaarPriceStrategy -import moe.nea.firmament.util.FirmFormatters.formatCurrency +import moe.nea.firmament.util.FirmFormatters.formatCommas import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.data.ProfileSpecificDataHolder import moe.nea.firmament.util.formattedString @@ -99,11 +99,11 @@ object PristineProfitTracker : FirmamentFeature { if (collectionPerSecond == null || moneyPerSecond == null) return ProfitHud.collectionCurrent = collectionPerSecond ProfitHud.collectionText = Text.stringifiedTranslatable("firmament.pristine-profit.collection", - formatCurrency(collectionPerSecond * SECONDS_PER_HOUR, - 1)).formattedString() + formatCommas(collectionPerSecond * SECONDS_PER_HOUR, + 1)).formattedString() ProfitHud.moneyCurrent = moneyPerSecond ProfitHud.moneyText = Text.stringifiedTranslatable("firmament.pristine-profit.money", - formatCurrency(moneyPerSecond * SECONDS_PER_HOUR, 1)) + formatCommas(moneyPerSecond * SECONDS_PER_HOUR, 1)) .formattedString() val data = DConfig.data if (data != null) { diff --git a/src/main/kotlin/moe/nea/firmament/gui/BarComponent.kt b/src/main/kotlin/moe/nea/firmament/gui/BarComponent.kt index 91b5735..38e898d 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/BarComponent.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/BarComponent.kt @@ -7,8 +7,6 @@ package moe.nea.firmament.gui import com.mojang.blaze3d.systems.RenderSystem -import io.github.cottonmc.cotton.gui.client.ScreenDrawing -import io.github.cottonmc.cotton.gui.widget.data.Texture import io.github.notenoughupdates.moulconfig.common.MyResourceLocation import io.github.notenoughupdates.moulconfig.common.RenderContext import io.github.notenoughupdates.moulconfig.gui.GuiComponent @@ -33,6 +31,24 @@ class BarComponent( return 8 } + data class Texture( + val identifier: Identifier, + val u1: Float, val v1: Float, + val u2: Float, val v2: Float, + ) { + fun draw(context: DrawContext, x: Int, y: Int, width: Int, height: Int, color: Color) { + context.drawTexturedQuad( + identifier, + x, y, x + width, x + height, 0, + u1, u2, v1, v2, + color.red / 255F, + color.green / 255F, + color.blue / 255F, + color.alpha / 255F, + ) + } + } + companion object { val resource = Firmament.identifier("textures/gui/bar.png") val left = Texture(resource, 0 / 64F, 0 / 64F, 4 / 64F, 8 / 64F) @@ -51,20 +67,21 @@ class BarComponent( sectionEnd: Double ) { if (sectionEnd < progress.get() && width == 4) { - ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, fillColor.color) + texture.draw(context, x, y, 4, 8, fillColor) return } if (sectionStart > progress.get() && width == 4) { - ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, emptyColor.color) + texture.draw(context, x, y, 4, 8, emptyColor) return } val increasePerPixel = (sectionEnd - sectionStart) / width var valueAtPixel = sectionStart for (i in (0 until width)) { - ScreenDrawing.texturedRect( + val newTex = + Texture(texture.identifier, texture.u1 + i / 64F, texture.v1, texture.u1 + (i + 1) / 64F, texture.v2) + newTex.draw( context, x + i, y, 1, 8, - texture.image, texture.u1 + i / 64F, texture.v1, texture.u1 + (i + 1) / 64F, texture.v2, - if (valueAtPixel < progress.get()) fillColor.color else emptyColor.color + if (valueAtPixel < progress.get()) fillColor else emptyColor ) valueAtPixel += increasePerPixel } diff --git a/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt b/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt index 30f280c..d1e223e 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt @@ -15,24 +15,31 @@ import io.github.notenoughupdates.moulconfig.gui.component.PanelComponent import io.github.notenoughupdates.moulconfig.observer.GetSetter -class FirmButtonComponent( +open class FirmButtonComponent( child: GuiComponent, + val isEnabled: GetSetter<Boolean> = GetSetter.constant(true), val action: Runnable, - val isEnabled: GetSetter<Boolean> = GetSetter.constant(true) ) : PanelComponent(child) { /* TODO: make use of vanillas built in nine slicer */ - val hoveredBg = NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_highlighted.png")) - .cornerSize(5) - .cornerUv(5 / 200F, 5 / 20F) - .mode(NinePatch.Mode.STRETCHING) - .build() + val hoveredBg = + NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_highlighted.png")) + .cornerSize(5) + .cornerUv(5 / 200F, 5 / 20F) + .mode(NinePatch.Mode.STRETCHING) + .build() val unhoveredBg = NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button.png")) .cornerSize(5) .cornerUv(5 / 200F, 5 / 20F) .mode(NinePatch.Mode.STRETCHING) .build() - val disabledBg = NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_disabled.png")) + val disabledBg = + NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_disabled.png")) + .cornerSize(5) + .cornerUv(5 / 200F, 5 / 20F) + .mode(NinePatch.Mode.STRETCHING) + .build() + val activeBg = NinePatch.builder(MyResourceLocation("firmament", "textures/gui/sprites/widget/button_active.png")) .cornerSize(5) .cornerUv(5 / 200F, 5 / 20F) .mode(NinePatch.Mode.STRETCHING) @@ -59,12 +66,15 @@ class FirmButtonComponent( return false } + open fun getBackground(context: GuiImmediateContext): NinePatch<MyResourceLocation> = + if (!isEnabled.get()) disabledBg + else if (context.isHovered || isClicking) hoveredBg + else unhoveredBg + override fun render(context: GuiImmediateContext) { context.renderContext.pushMatrix() context.renderContext.drawNinePatch( - if (!isEnabled.get()) disabledBg - else if (context.isHovered || isClicking) hoveredBg - else unhoveredBg, + getBackground(context), 0f, 0f, context.width, context.height ) context.renderContext.translate(insets.toFloat(), insets.toFloat(), 0f) diff --git a/src/main/kotlin/moe/nea/firmament/gui/FixedComponent.kt b/src/main/kotlin/moe/nea/firmament/gui/FixedComponent.kt index c98feda..15d6bfc 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/FixedComponent.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/FixedComponent.kt @@ -14,20 +14,20 @@ import io.github.notenoughupdates.moulconfig.observer.GetSetter import java.util.function.BiFunction class FixedComponent( - val fixedWidth: GetSetter<Int>, - val fixedHeight: GetSetter<Int>, + val fixedWidth: GetSetter<Int>?, + val fixedHeight: GetSetter<Int>?, val component: GuiComponent, ) : GuiComponent() { - override fun getWidth(): Int = fixedWidth.get() + override fun getWidth(): Int = fixedWidth?.get() ?: component.width - override fun getHeight(): Int = fixedHeight.get() + override fun getHeight(): Int = fixedHeight?.get() ?: component.height override fun <T : Any?> foldChildren(initial: T, visitor: BiFunction<GuiComponent, T, T>): T { return visitor.apply(component, initial) } fun fixContext(context: GuiImmediateContext): GuiImmediateContext = - context.translated(0, 0, fixedWidth.get(), fixedHeight.get()) + context.translated(0, 0, width, height) override fun render(context: GuiImmediateContext) { component.render(fixContext(context)) diff --git a/src/main/kotlin/moe/nea/firmament/gui/WBar.kt b/src/main/kotlin/moe/nea/firmament/gui/WBar.kt deleted file mode 100644 index 5772aac..0000000 --- a/src/main/kotlin/moe/nea/firmament/gui/WBar.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -package moe.nea.firmament.gui - -import com.mojang.blaze3d.systems.RenderSystem -import io.github.cottonmc.cotton.gui.client.ScreenDrawing -import io.github.cottonmc.cotton.gui.widget.WWidget -import io.github.cottonmc.cotton.gui.widget.data.Texture -import me.shedaniel.math.Color -import net.minecraft.client.gui.DrawContext -import moe.nea.firmament.Firmament - -open class WBar( - var progress: Double, - var total: Double, - val fillColor: Color, - val emptyColor: Color = fillColor.darker(2.0), -) : WWidget() { - companion object { - val resource = Firmament.identifier("textures/gui/bar.png") - val left = Texture(resource, 0 / 64F, 0 / 64F, 4 / 64F, 8 / 64F) - val middle = Texture(resource, 4 / 64F, 0 / 64F, 8 / 64F, 8 / 64F) - val right = Texture(resource, 8 / 64F, 0 / 64F, 12 / 64F, 8 / 64F) - val segmentOverlay = Texture(resource, 12 / 64F, 0 / 64F, 15 / 64F, 8 / 64F) - } - - override fun canResize(): Boolean { - return true - } - - private fun drawSection( - context: DrawContext, - texture: Texture, - x: Int, - y: Int, - width: Int, - sectionStart: Double, - sectionEnd: Double - ) { - if (sectionEnd < progress && width == 4) { - ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, fillColor.color) - return - } - if (sectionStart > progress && width == 4) { - ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, emptyColor.color) - return - } - val increasePerPixel = (sectionEnd - sectionStart / 4) - var valueAtPixel = sectionStart - for (i in (0 until width)) { - ScreenDrawing.texturedRect( - context, x + i, y, 1, 8, - texture.image, texture.u1 + i / 64F, texture.v1, texture.u1 + (i + 1) / 64F, texture.v2, - if (valueAtPixel < progress) fillColor.color else emptyColor.color - ) - valueAtPixel += increasePerPixel - } - } - - override fun paint(context: DrawContext, x: Int, y: Int, mouseX: Int, mouseY: Int) { - var i = 0 - while (i < width - 4) { - drawSection( - context, - if (i == 0) left else middle, - x + i, y, - (width - (i + 4)).coerceAtMost(4), - i * total / width, (i + 4) * total / width - ) - i += 4 - } - drawSection(context, right, x + width - 4, y, 4, (width - 4) * total / width, total) - RenderSystem.setShaderColor(1F, 1F, 1F, 1F) - } -} diff --git a/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt b/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt deleted file mode 100644 index 69a59f5..0000000 --- a/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -package moe.nea.firmament.gui - -import io.github.cottonmc.cotton.gui.widget.WPanel -import io.github.cottonmc.cotton.gui.widget.WWidget -import io.github.cottonmc.cotton.gui.widget.data.Axis - -data class WCenteringPanel( - val child: WWidget, - val axis: Axis, -) : WPanel() { - init { - child.parent = this - } - - override fun setSize(x: Int, y: Int) { - super.setSize(x, y) - if (!child.canResize()) return - if (axis == Axis.HORIZONTAL) { - child.setSize(child.width, y) - } else { - child.setSize(x, child.height) - } - } - - override fun layout() { - super.layout() - child.setLocation( - axis.choose((child.width + width) / 2, child.x), - axis.choose(child.y, (child.height + height) / 2), - ) - } - - -} |
