Make matter gauge panel more fun to interact with

Fixes #16
Fixes #20
This commit is contained in:
DBotThePony 2022-09-17 14:42:39 +07:00
parent e83075b5f1
commit 97457ab027
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -16,7 +16,9 @@ import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.formatMatterLevel import ru.dbotthepony.mc.otm.core.formatMatterLevel
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
import kotlin.math.absoluteValue
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.pow
import kotlin.math.sin import kotlin.math.sin
open class MatterGaugePanel<S : Screen> @JvmOverloads constructor( open class MatterGaugePanel<S : Screen> @JvmOverloads constructor(
@ -30,6 +32,12 @@ open class MatterGaugePanel<S : Screen> @JvmOverloads constructor(
scissor = true scissor = true
} }
private var wavesStrength = 0.5f
private var lastAbsoluteX = 0f
private var lastAbsoluteY = 0f
private var lastDraw = System.nanoTime()
private var lastLevel = 0f
protected open fun makeTooltip(): MutableList<Component> { protected open fun makeTooltip(): MutableList<Component> {
return mutableListOf( return mutableListOf(
TranslatableComponent( TranslatableComponent(
@ -41,9 +49,26 @@ open class MatterGaugePanel<S : Screen> @JvmOverloads constructor(
} }
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
if (lastAbsoluteX == 0f && lastAbsoluteY == 0f) {
lastAbsoluteX = absoluteX
lastAbsoluteY = absoluteY
lastDraw = System.nanoTime()
lastLevel = widget.percentage()
} else {
val diff = ((lastAbsoluteX - absoluteX).pow(2f) + (lastAbsoluteY - absoluteY).pow(2f)).pow(0.5f) / 10f + (lastLevel - widget.percentage()).absoluteValue * 1.5f
lastAbsoluteX = absoluteX
lastAbsoluteY = absoluteY
wavesStrength = (wavesStrength + diff - (System.nanoTime() - lastDraw) / 400_000_000f).coerceAtLeast(0.5f).coerceAtMost(16f)
lastDraw = System.nanoTime()
lastLevel = widget.percentage()
}
GAUGE_BACKGROUND.render(stack) GAUGE_BACKGROUND.render(stack)
val height = this.height * (1f - widget.percentage()) val height = this.height * (1f - widget.percentage())
if (widget.percentage() > 0.01f) {
RenderSystem.setShader(GameRenderer::getPositionTexShader) RenderSystem.setShader(GameRenderer::getPositionTexShader)
RenderSystem.enableTexture() RenderSystem.enableTexture()
RenderSystem.enableBlend() RenderSystem.enableBlend()
@ -65,8 +90,8 @@ open class MatterGaugePanel<S : Screen> @JvmOverloads constructor(
builder.vertex(matrix, width, this.height, 0f).uv(u1, v1).endVertex() builder.vertex(matrix, width, this.height, 0f).uv(u1, v1).endVertex()
for (i in 4 downTo 0) { for (i in 4 downTo 0) {
val sin = sin((System.currentTimeMillis() / 50L + i * 2L).toDouble() / 4.0).toFloat() val sin = sin((System.currentTimeMillis() / 50L + i * 2L).toDouble() / 4.0).toFloat() * wavesStrength.coerceAtMost(4f)
val cos = cos((System.currentTimeMillis() / 50L + i * 3L + 27L).toDouble() / 4.0).toFloat() val cos = cos((System.currentTimeMillis() / 50L + i * 3L + 27L).toDouble() / 4.0).toFloat() * wavesStrength.coerceAtMost(4f)
val thisX = (width * (i / 4f)) val thisX = (width * (i / 4f))
val thisY = (height + sin + cos).coerceAtLeast(0f) val thisY = (height + sin + cos).coerceAtLeast(0f)
@ -79,6 +104,7 @@ open class MatterGaugePanel<S : Screen> @JvmOverloads constructor(
BufferUploader.drawWithShader(builder.end()) BufferUploader.drawWithShader(builder.end())
} }
}
override fun innerRenderTooltips(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Boolean { override fun innerRenderTooltips(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Boolean {
if (isHovered) { if (isHovered) {