Add price tooltips
This commit is contained in:
@@ -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 ->
|
||||
|
||||
17
src/main/kotlin/moe/nea/firmament/events/ItemTooltipEvent.kt
Normal file
17
src/main/kotlin/moe/nea/firmament/events/ItemTooltipEvent.kt
Normal file
@@ -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>()
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
"firmament.price.bazaar.productid": "Stock id: %s",
|
||||
"firmament.price.bazaar.buy.price": "Buy Price: %s",
|
||||
"firmament.price.bazaar.buy.order": "Buy orders: %d",
|
||||
"firmament.tooltip.bazaar.sell-order": "Bazaar Sell Order: %s",
|
||||
"firmament.tooltip.bazaar.buy-order": "Bazaar Buy Order: %s",
|
||||
"firmament.tooltip.ah.lowestbin": "Lowest BIN: %d",
|
||||
"firmament.pv.pets": "Pets",
|
||||
"firmament.debug.skyblockid": "SkyBlock ID: %s",
|
||||
"firmament.debug.skyblockid.copy": "Click to copy SkyBlock ID",
|
||||
@@ -36,6 +39,9 @@
|
||||
"firmament.sbinfo.gametype": "Locraw Gametype: %s",
|
||||
"firmament.sbinfo.mode": "Locraw Mode: %s",
|
||||
"firmament.sbinfo.map": "Locraw Map: %s",
|
||||
"firmament.config.price-data": "Price data",
|
||||
"firmament.config.price-data.enable-always": "Enable Item Price",
|
||||
"firmament.config.price-data.enable-keybind": "Enable only with Keybinding",
|
||||
"firmament.config.fairy-souls": "Fairy Souls",
|
||||
"firmament.config.fairy-souls.show": "Show Fairy Soul Waypoints",
|
||||
"firmament.config.fairy-souls.reset": "Reset Collected Fairy Souls",
|
||||
|
||||
Reference in New Issue
Block a user