diff options
author | nea <nea@nea.moe> | 2023-08-31 19:38:38 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-08-31 21:22:26 +0200 |
commit | cb032e7c221e40736ab26b193eea4e32d06113d9 (patch) | |
tree | e49047b3b78fb9887d72cbe9458af44ecbc179d4 /src/main/kotlin | |
parent | b7b01f1c6fbf889ae9bfcdb5b34c5ccfa48d5ba0 (diff) | |
download | firmament-cb032e7c221e40736ab26b193eea4e32d06113d9.tar.gz firmament-cb032e7c221e40736ab26b193eea4e32d06113d9.tar.bz2 firmament-cb032e7c221e40736ab26b193eea4e32d06113d9.zip |
Add price tooltips
Diffstat (limited to 'src/main/kotlin')
6 files changed, 142 insertions, 11 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/Firmament.kt b/src/main/kotlin/moe/nea/firmament/Firmament.kt index 1a2739e..e4b874a 100644 --- a/src/main/kotlin/moe/nea/firmament/Firmament.kt +++ b/src/main/kotlin/moe/nea/firmament/Firmament.kt @@ -14,13 +14,13 @@ import io.ktor.client.plugins.compression.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.logging.* import io.ktor.serialization.kotlinx.json.* -import java.lang.Exception import java.nio.file.Files import java.nio.file.Path import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents +import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents import net.fabricmc.loader.api.FabricLoader import net.fabricmc.loader.api.Version @@ -41,6 +41,7 @@ import net.minecraft.command.CommandRegistryAccess import net.minecraft.util.Identifier import moe.nea.firmament.commands.registerFirmamentCommand import moe.nea.firmament.dbus.FirmamentDbusObject +import moe.nea.firmament.events.ItemTooltipEvent import moe.nea.firmament.events.ScreenRenderPostEvent import moe.nea.firmament.events.TickEvent import moe.nea.firmament.features.FeatureManager @@ -133,6 +134,9 @@ object Firmament { globalJob.cancel() } }) + ItemTooltipCallback.EVENT.register { a, b, c -> + ItemTooltipEvent.publish(ItemTooltipEvent(a, b, c)) + } ScreenEvents.AFTER_INIT.register(ScreenEvents.AfterInit { client, screen, scaledWidth, scaledHeight -> ScreenEvents.afterRender(screen) .register(ScreenEvents.AfterRender { screen, drawContext, mouseX, mouseY, tickDelta -> diff --git a/src/main/kotlin/moe/nea/firmament/events/ItemTooltipEvent.kt b/src/main/kotlin/moe/nea/firmament/events/ItemTooltipEvent.kt new file mode 100644 index 0000000..ba597cd --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/ItemTooltipEvent.kt @@ -0,0 +1,17 @@ +/* + * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.events + +import net.minecraft.client.item.TooltipContext +import net.minecraft.item.ItemStack +import net.minecraft.text.Text + +data class ItemTooltipEvent( + val stack: ItemStack, val context: TooltipContext, val lines: MutableList<Text> +) : FirmamentEvent() { + companion object : FirmamentEventBus<ItemTooltipEvent>() +} diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt index facb821..91f5e03 100644 --- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt +++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt @@ -14,6 +14,7 @@ import moe.nea.firmament.features.debug.DebugView import moe.nea.firmament.features.debug.DeveloperFeatures import moe.nea.firmament.features.fixes.Fixes import moe.nea.firmament.features.inventory.CraftingOverlay +import moe.nea.firmament.features.inventory.PriceData import moe.nea.firmament.features.inventory.SaveCursorPosition import moe.nea.firmament.features.inventory.SlotLocking import moe.nea.firmament.features.inventory.storageoverlay.StorageOverlay @@ -48,6 +49,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature loadFeature(ChatLinks) loadFeature(SaveCursorPosition) loadFeature(CustomSkyBlockTextures) + loadFeature(PriceData) loadFeature(Fixes) if (Firmament.DEBUG) { loadFeature(DeveloperFeatures) diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt new file mode 100644 index 0000000..3ae7b00 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt @@ -0,0 +1,61 @@ +/* + * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.features.inventory + +import net.minecraft.text.Text +import moe.nea.firmament.events.ItemTooltipEvent +import moe.nea.firmament.features.FirmamentFeature +import moe.nea.firmament.gui.config.ManagedConfig +import moe.nea.firmament.repo.HypixelStaticData +import moe.nea.firmament.util.FirmFormatters +import moe.nea.firmament.util.skyBlockId + +object PriceData : FirmamentFeature { + override val identifier: String + get() = "price-data" + + object TConfig : ManagedConfig(identifier) { + val tooltipEnabled by toggle("enable-always") { true } + val enableKeybinding by keyBindingWithDefaultUnbound("enable-keybind") + } + + override val config get() = TConfig + + override fun onLoad() { + ItemTooltipEvent.subscribe { + if (!TConfig.tooltipEnabled && !TConfig.enableKeybinding.isPressed()) { + return@subscribe + } + val sbId = it.stack.skyBlockId + val bazaarData = HypixelStaticData.bazaarData[sbId] + val lowestBin = HypixelStaticData.lowestBin[sbId] + if (bazaarData != null) { + it.lines.add(Text.literal("")) + it.lines.add( + Text.translatable( + "firmament.tooltip.bazaar.sell-order", + FirmFormatters.toString(bazaarData.quickStatus.sellPrice, 1) + ) + ) + it.lines.add( + Text.translatable( + "firmament.tooltip.bazaar.buy-order", + FirmFormatters.toString(bazaarData.quickStatus.buyPrice, 1) + ) + ) + } else if (lowestBin != null) { + it.lines.add(Text.literal("")) + it.lines.add( + Text.translatable( + "firmament.tooltip.ah.lowestbin", + FirmFormatters.toString(lowestBin, 1) + ) + ) + } + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/ManagedConfig.kt b/src/main/kotlin/moe/nea/firmament/gui/config/ManagedConfig.kt index 8743293..8e05632 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/config/ManagedConfig.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/config/ManagedConfig.kt @@ -14,22 +14,23 @@ import io.github.cottonmc.cotton.gui.widget.WLabel import io.github.cottonmc.cotton.gui.widget.data.Axis import io.github.cottonmc.cotton.gui.widget.data.Insets import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment +import moe.nea.jarvis.api.Point +import org.lwjgl.glfw.GLFW import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject +import kotlin.io.path.createDirectories +import kotlin.io.path.readText +import kotlin.io.path.writeText +import kotlin.time.Duration +import net.minecraft.client.gui.screen.Screen +import net.minecraft.text.Text import moe.nea.firmament.Firmament import moe.nea.firmament.gui.WTightScrollPanel import moe.nea.firmament.keybindings.SavedKeyBinding import moe.nea.firmament.util.MC import moe.nea.firmament.util.ScreenUtil.setScreenLater -import moe.nea.jarvis.api.Point -import net.minecraft.client.gui.screen.Screen -import net.minecraft.text.Text -import kotlin.io.path.createDirectories -import kotlin.io.path.readText -import kotlin.io.path.writeText -import kotlin.time.Duration abstract class ManagedConfig(override val name: String) : ManagedConfigElement() { @@ -110,15 +111,21 @@ abstract class ManagedConfig(override val name: String) : ManagedConfigElement() protected fun keyBinding( propertyName: String, default: () -> Int, - ): ManagedOption<SavedKeyBinding> = keyBindingWithDefaultModifiers(propertyName) { SavedKeyBinding(default()) } + ): ManagedOption<SavedKeyBinding> = keyBindingWithOutDefaultModifiers(propertyName) { SavedKeyBinding(default()) } - protected fun keyBindingWithDefaultModifiers( + protected fun keyBindingWithOutDefaultModifiers( propertyName: String, default: () -> SavedKeyBinding, ): ManagedOption<SavedKeyBinding> { return option(propertyName, default, KeyBindingHandler("firmament.config.${name}.${propertyName}", this)) } + protected fun keyBindingWithDefaultUnbound( + propertyName: String, + ): ManagedOption<SavedKeyBinding> { + return keyBindingWithOutDefaultModifiers(propertyName) { SavedKeyBinding(GLFW.GLFW_KEY_UNKNOWN) } + } + protected fun integer( propertyName: String, min: Int, diff --git a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt index e0f0c50..606485b 100644 --- a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt +++ b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt @@ -6,8 +6,11 @@ package moe.nea.firmament.keybindings -import kotlinx.serialization.Serializable import org.lwjgl.glfw.GLFW +import kotlinx.serialization.Serializable +import net.minecraft.client.MinecraftClient +import net.minecraft.client.util.InputUtil +import moe.nea.firmament.util.MC @Serializable data class SavedKeyBinding( @@ -35,6 +38,43 @@ data class SavedKeyBinding( } } + fun hasShiftDown(): Boolean { + return InputUtil.isKeyPressed( + MinecraftClient.getInstance().window.handle, + GLFW.GLFW_KEY_LEFT_SHIFT + ) || InputUtil.isKeyPressed( + MinecraftClient.getInstance().window.handle, GLFW.GLFW_KEY_RIGHT_SHIFT + ) + } + + fun hasAltDown(): Boolean { + return InputUtil.isKeyPressed( + MinecraftClient.getInstance().window.handle, + GLFW.GLFW_KEY_LEFT_ALT + ) || InputUtil.isKeyPressed( + MinecraftClient.getInstance().window.handle, GLFW.GLFW_KEY_RIGHT_ALT + ) + } + + fun isPressed(): Boolean { + val h = MC.window.handle + if (!InputUtil.isKeyPressed(h, keyCode)) return false + + val ctrl = if (MinecraftClient.IS_SYSTEM_MAC) { + InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SUPER) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER) + } else InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_CONTROL) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL) + val shift = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SHIFT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SHIFT) + val alt = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_ALT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT) + + return (ctrl == this.ctrl) && + (alt == this.alt) && + (shift == this.shift) + } + override fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { return keyCode == this.keyCode && getMods(modifiers) == Triple(shift, ctrl, alt) } |