Split gauge panels file
This commit is contained in:
parent
276cfeda00
commit
8df7cf76a8
@ -1,278 +0,0 @@
|
||||
package ru.dbotthepony.mc.otm.client.screen.widget
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.BufferUploader
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import com.mojang.blaze3d.vertex.VertexFormat
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.client.renderer.GameRenderer
|
||||
import net.minecraft.network.chat.Component
|
||||
import org.lwjgl.opengl.GL11
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.client.render.*
|
||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||
import ru.dbotthepony.mc.otm.core.formatMatterLevel
|
||||
import ru.dbotthepony.mc.otm.core.formatPowerLevel
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
||||
import java.util.Random
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
open class PowerGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
val widget: LevelGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 9f,
|
||||
height: Float = 48f
|
||||
) : EditablePanel(screen, parent, x, y, width, height) {
|
||||
init {
|
||||
scissor = true
|
||||
}
|
||||
|
||||
protected open fun makeTooltip(): MutableList<Component> {
|
||||
return mutableListOf(
|
||||
TranslatableComponent("otm.gui.power.percentage_level", String.format("%.2f", widget.percentage() * 100.0)),
|
||||
formatPowerLevel(widget.level(), widget.maxLevel())
|
||||
)
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
val height = this.height * widget.percentage()
|
||||
|
||||
if (width >= 18f) {
|
||||
GAUGE_BACKGROUND_WIDE.render(stack, width = width, height = this.height)
|
||||
GAUGE_FOREGROUND_WIDE.renderPartial(
|
||||
stack,
|
||||
y = this.height - height,
|
||||
height = height,
|
||||
width = width,
|
||||
winding = UVWindingOrder.U0_V1_U1_V0)
|
||||
} else {
|
||||
GAUGE_BACKGROUND.render(stack, width = width, height = this.height)
|
||||
GAUGE_FOREGROUND.renderPartial(
|
||||
stack,
|
||||
y = this.height - height,
|
||||
height = height,
|
||||
width = width,
|
||||
winding = UVWindingOrder.U0_V1_U1_V0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
||||
if (isHovered) {
|
||||
screen.renderComponentTooltip(stack, makeTooltip(), mouse_x.toInt(), mouse_y.toInt())
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 202f, y = 0f, w = 9f, h = 48f)
|
||||
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 211f, y = 0f, w = 9f, h = 48f)
|
||||
|
||||
val GAUGE_BACKGROUND_WIDE = WidgetLocation.WIDGETS.element(x = 238f, y = 0f, w = 18f, h = 48f)
|
||||
val GAUGE_FOREGROUND_WIDE = WidgetLocation.WIDGETS.element(x = 220f, y = 0f, w = 18f, h = 48f)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to [PowerGaugePanel] with doubled width
|
||||
*/
|
||||
fun WidePowerGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
widget: LevelGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 18f,
|
||||
height: Float = 48f
|
||||
) = PowerGaugePanel(screen, parent, widget, x, y, width, height)
|
||||
|
||||
open class MatterGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
val widget: LevelGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f
|
||||
): EditablePanel(screen, parent, x, y, width = GAUGE_BACKGROUND.w, height = GAUGE_BACKGROUND.h) {
|
||||
init {
|
||||
scissor = true
|
||||
}
|
||||
|
||||
protected open fun makeTooltip(): MutableList<Component> {
|
||||
return mutableListOf(
|
||||
TranslatableComponent("otm.gui.matter.percentage_level", String.format("%.2f", widget.percentage() * 100.0)),
|
||||
formatMatterLevel(widget.level(), widget.maxLevel())
|
||||
)
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
GAUGE_BACKGROUND.render(stack)
|
||||
val height = this.height * (1f - widget.percentage())
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
||||
RenderSystem.enableTexture()
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.defaultBlendFunc()
|
||||
RenderSystem.depthFunc(GL11.GL_ALWAYS)
|
||||
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
||||
|
||||
val u0 = GAUGE_FOREGROUND.x / GAUGE_FOREGROUND.imageWidth
|
||||
val u1 = (GAUGE_FOREGROUND.x + GAUGE_FOREGROUND.w) / GAUGE_FOREGROUND.imageWidth
|
||||
val v1 = (GAUGE_FOREGROUND.y + GAUGE_FOREGROUND.h) / GAUGE_FOREGROUND.imageHeight
|
||||
|
||||
val matrix = stack.last().pose()
|
||||
val builder = tesselator.builder
|
||||
|
||||
builder.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_TEX)
|
||||
|
||||
builder.vertex(matrix, 0f, this.height, 0f).uv(u0, v1).endVertex()
|
||||
builder.vertex(matrix, width, this.height, 0f).uv(u1, v1).endVertex()
|
||||
|
||||
for (i in 4 downTo 0) {
|
||||
val sin = sin((System.currentTimeMillis() / 50L + i * 2L).toDouble() / 4.0).toFloat()
|
||||
val cos = cos((System.currentTimeMillis() / 50L + i * 3L + 27L).toDouble() / 4.0).toFloat()
|
||||
|
||||
val thisX = (width * (i / 4f))
|
||||
val thisY = (height + sin + cos).coerceAtLeast(0f)
|
||||
|
||||
builder.vertex(matrix, thisX, thisY, 0f).uv(
|
||||
(GAUGE_FOREGROUND.x + (i / 4f) * GAUGE_FOREGROUND.w) / GAUGE_FOREGROUND.imageWidth,
|
||||
(GAUGE_FOREGROUND.y + thisY) / GAUGE_FOREGROUND.imageHeight,
|
||||
).endVertex()
|
||||
}
|
||||
|
||||
BufferUploader.drawWithShader(builder.end())
|
||||
}
|
||||
|
||||
override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
||||
if (isHovered) {
|
||||
screen.renderComponentTooltip(stack, makeTooltip(), mouse_x.toInt(), mouse_y.toInt())
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 184f, y = 0f, w = 9f, h = 48f)
|
||||
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 193f, y = 0f, w = 9f, h = 48f)
|
||||
}
|
||||
}
|
||||
|
||||
open class PatternGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
val widget: LevelGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f
|
||||
): EditablePanel(screen, parent, x, y, width = GAUGE_BACKGROUND.w, height = GAUGE_BACKGROUND.h) {
|
||||
init {
|
||||
scissor = true
|
||||
}
|
||||
|
||||
protected open fun makeTooltip(): MutableList<Component> {
|
||||
return mutableListOf(
|
||||
TranslatableComponent("otm.gui.pattern.percentage_level", String.format("%.2f", widget.percentage() * 100.0)),
|
||||
TranslatableComponent("otm.gui.pattern.format", widget.level().toString(0), widget.maxLevel().toString(0))
|
||||
)
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
GAUGE_BACKGROUND.render(stack)
|
||||
val height = this.height * widget.percentage()
|
||||
GAUGE_FOREGROUND.renderPartial(stack, y = this.height - height, height = height, winding = UVWindingOrder.U0_V1_U1_V0)
|
||||
}
|
||||
|
||||
override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
||||
if (isHovered) {
|
||||
screen.renderComponentTooltip(stack, makeTooltip(), mouse_x.toInt(), mouse_y.toInt())
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 166f, y = 0f, w = 9f, h = 48f)
|
||||
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 175f, y = 0f, w = 9f, h = 48f)
|
||||
}
|
||||
}
|
||||
|
||||
open class ProgressGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
val widget: ProgressGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f
|
||||
): EditablePanel(screen, parent, x, y, width = GAUGE_BACKGROUND.w, height = GAUGE_BACKGROUND.h) {
|
||||
init {
|
||||
scissor = true
|
||||
}
|
||||
|
||||
var flop = false
|
||||
|
||||
protected open fun makeTooltip(): MutableList<Component> {
|
||||
val tooltip: MutableList<Component>
|
||||
|
||||
if (widget.isStuck()) {
|
||||
tooltip = mutableListOf(
|
||||
TranslatableComponent(
|
||||
"otm.gui.progress_widget",
|
||||
String.format("%.2f", widget.percentage() * 100f)
|
||||
),
|
||||
TranslatableComponent("otm.gui.progress_widget_stuck").withStyle(ChatFormatting.DARK_RED)
|
||||
)
|
||||
} else {
|
||||
tooltip = mutableListOf(
|
||||
TranslatableComponent(
|
||||
"otm.gui.progress_widget",
|
||||
String.format("%.2f", widget.percentage() * 100f)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return tooltip
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
if (widget.isStuck() && tick % 40 <= 20) {
|
||||
RenderSystem.setShaderColor(0.75f, 0.4f, 0.4f, 1f)
|
||||
}
|
||||
|
||||
if (flop) {
|
||||
GAUGE_BACKGROUND.render(stack, winding = UVWindingOrder.U1_V0_U0_V1)
|
||||
val width = this.width * widget.percentage()
|
||||
GAUGE_FOREGROUND.renderPartial(stack, x = this.width - width, width = width, winding = UVWindingOrder.U1_V0_U0_V1)
|
||||
} else {
|
||||
GAUGE_BACKGROUND.render(stack)
|
||||
val width = this.width * widget.percentage()
|
||||
GAUGE_FOREGROUND.renderPartial(stack, width = width)
|
||||
}
|
||||
|
||||
if (widget.isStuck() && tick % 40 <= 20) {
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
||||
}
|
||||
}
|
||||
|
||||
override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
||||
if (isHovered) {
|
||||
screen.renderComponentTooltip(stack, makeTooltip(), mouse_x.toInt(), mouse_y.toInt())
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 0f, y = 240f, w = 22f, h = 16f)
|
||||
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 22f, y = 240f, w = 22f, h = 16f)
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package ru.dbotthepony.mc.otm.client.screen.widget
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.BufferUploader
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import com.mojang.blaze3d.vertex.VertexFormat
|
||||
import net.minecraft.client.renderer.GameRenderer
|
||||
import net.minecraft.network.chat.Component
|
||||
import org.lwjgl.opengl.GL11
|
||||
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
||||
import ru.dbotthepony.mc.otm.client.render.element
|
||||
import ru.dbotthepony.mc.otm.client.render.tesselator
|
||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.core.formatMatterLevel
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
open class MatterGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
val widget: LevelGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f
|
||||
): EditablePanel(screen, parent, x, y, width = GAUGE_BACKGROUND.w, height = GAUGE_BACKGROUND.h) {
|
||||
init {
|
||||
scissor = true
|
||||
}
|
||||
|
||||
protected open fun makeTooltip(): MutableList<Component> {
|
||||
return mutableListOf(
|
||||
TranslatableComponent(
|
||||
"otm.gui.matter.percentage_level",
|
||||
String.format("%.2f", widget.percentage() * 100.0)
|
||||
),
|
||||
formatMatterLevel(widget.level(), widget.maxLevel())
|
||||
)
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
GAUGE_BACKGROUND.render(stack)
|
||||
val height = this.height * (1f - widget.percentage())
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
||||
RenderSystem.enableTexture()
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.defaultBlendFunc()
|
||||
RenderSystem.depthFunc(GL11.GL_ALWAYS)
|
||||
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
||||
|
||||
val u0 = GAUGE_FOREGROUND.x / GAUGE_FOREGROUND.imageWidth
|
||||
val u1 = (GAUGE_FOREGROUND.x + GAUGE_FOREGROUND.w) / GAUGE_FOREGROUND.imageWidth
|
||||
val v1 = (GAUGE_FOREGROUND.y + GAUGE_FOREGROUND.h) / GAUGE_FOREGROUND.imageHeight
|
||||
|
||||
val matrix = stack.last().pose()
|
||||
val builder = tesselator.builder
|
||||
|
||||
builder.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_TEX)
|
||||
|
||||
builder.vertex(matrix, 0f, this.height, 0f).uv(u0, v1).endVertex()
|
||||
builder.vertex(matrix, width, this.height, 0f).uv(u1, v1).endVertex()
|
||||
|
||||
for (i in 4 downTo 0) {
|
||||
val sin = sin((System.currentTimeMillis() / 50L + i * 2L).toDouble() / 4.0).toFloat()
|
||||
val cos = cos((System.currentTimeMillis() / 50L + i * 3L + 27L).toDouble() / 4.0).toFloat()
|
||||
|
||||
val thisX = (width * (i / 4f))
|
||||
val thisY = (height + sin + cos).coerceAtLeast(0f)
|
||||
|
||||
builder.vertex(matrix, thisX, thisY, 0f).uv(
|
||||
(GAUGE_FOREGROUND.x + (i / 4f) * GAUGE_FOREGROUND.w) / GAUGE_FOREGROUND.imageWidth,
|
||||
(GAUGE_FOREGROUND.y + thisY) / GAUGE_FOREGROUND.imageHeight,
|
||||
).endVertex()
|
||||
}
|
||||
|
||||
BufferUploader.drawWithShader(builder.end())
|
||||
}
|
||||
|
||||
override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
||||
if (isHovered) {
|
||||
screen.renderComponentTooltip(stack, makeTooltip(), mouse_x.toInt(), mouse_y.toInt())
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 184f, y = 0f, w = 9f, h = 48f)
|
||||
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 193f, y = 0f, w = 9f, h = 48f)
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package ru.dbotthepony.mc.otm.client.screen.widget
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import net.minecraft.network.chat.Component
|
||||
import ru.dbotthepony.mc.otm.client.render.UVWindingOrder
|
||||
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
||||
import ru.dbotthepony.mc.otm.client.render.element
|
||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
|
||||
open class PatternGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
val widget: LevelGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f
|
||||
): EditablePanel(screen, parent, x, y, width = GAUGE_BACKGROUND.w, height = GAUGE_BACKGROUND.h) {
|
||||
init {
|
||||
scissor = true
|
||||
}
|
||||
|
||||
protected open fun makeTooltip(): MutableList<Component> {
|
||||
return mutableListOf(
|
||||
TranslatableComponent(
|
||||
"otm.gui.pattern.percentage_level",
|
||||
String.format("%.2f", widget.percentage() * 100.0)
|
||||
),
|
||||
TranslatableComponent("otm.gui.pattern.format", widget.level().toString(0), widget.maxLevel().toString(0))
|
||||
)
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
GAUGE_BACKGROUND.render(stack)
|
||||
val height = this.height * widget.percentage()
|
||||
GAUGE_FOREGROUND.renderPartial(stack, y = this.height - height, height = height, winding = UVWindingOrder.U0_V1_U1_V0)
|
||||
}
|
||||
|
||||
override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
||||
if (isHovered) {
|
||||
screen.renderComponentTooltip(stack, makeTooltip(), mouse_x.toInt(), mouse_y.toInt())
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 166f, y = 0f, w = 9f, h = 48f)
|
||||
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 175f, y = 0f, w = 9f, h = 48f)
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package ru.dbotthepony.mc.otm.client.screen.widget
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import net.minecraft.network.chat.Component
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.client.render.*
|
||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||
import ru.dbotthepony.mc.otm.core.formatPowerLevel
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
|
||||
open class PowerGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
val widget: LevelGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 9f,
|
||||
height: Float = 48f
|
||||
) : EditablePanel(screen, parent, x, y, width, height) {
|
||||
init {
|
||||
scissor = true
|
||||
}
|
||||
|
||||
protected open fun makeTooltip(): MutableList<Component> {
|
||||
return mutableListOf(
|
||||
TranslatableComponent("otm.gui.power.percentage_level", String.format("%.2f", widget.percentage() * 100.0)),
|
||||
formatPowerLevel(widget.level(), widget.maxLevel())
|
||||
)
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
val height = this.height * widget.percentage()
|
||||
|
||||
if (width >= 18f) {
|
||||
GAUGE_BACKGROUND_WIDE.render(stack, width = width, height = this.height)
|
||||
GAUGE_FOREGROUND_WIDE.renderPartial(
|
||||
stack,
|
||||
y = this.height - height,
|
||||
height = height,
|
||||
width = width,
|
||||
winding = UVWindingOrder.U0_V1_U1_V0)
|
||||
} else {
|
||||
GAUGE_BACKGROUND.render(stack, width = width, height = this.height)
|
||||
GAUGE_FOREGROUND.renderPartial(
|
||||
stack,
|
||||
y = this.height - height,
|
||||
height = height,
|
||||
width = width,
|
||||
winding = UVWindingOrder.U0_V1_U1_V0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
||||
if (isHovered) {
|
||||
screen.renderComponentTooltip(stack, makeTooltip(), mouse_x.toInt(), mouse_y.toInt())
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 202f, y = 0f, w = 9f, h = 48f)
|
||||
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 211f, y = 0f, w = 9f, h = 48f)
|
||||
|
||||
val GAUGE_BACKGROUND_WIDE = WidgetLocation.WIDGETS.element(x = 238f, y = 0f, w = 18f, h = 48f)
|
||||
val GAUGE_FOREGROUND_WIDE = WidgetLocation.WIDGETS.element(x = 220f, y = 0f, w = 18f, h = 48f)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to [PowerGaugePanel] with doubled width
|
||||
*/
|
||||
fun WidePowerGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
widget: LevelGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 18f,
|
||||
height: Float = 48f
|
||||
) = PowerGaugePanel(screen, parent, widget, x, y, width, height)
|
@ -0,0 +1,84 @@
|
||||
package ru.dbotthepony.mc.otm.client.screen.widget
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.network.chat.Component
|
||||
import ru.dbotthepony.mc.otm.client.render.UVWindingOrder
|
||||
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
||||
import ru.dbotthepony.mc.otm.client.render.element
|
||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
||||
|
||||
open class ProgressGaugePanel(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel? = null,
|
||||
val widget: ProgressGaugeWidget,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f
|
||||
): EditablePanel(screen, parent, x, y, width = GAUGE_BACKGROUND.w, height = GAUGE_BACKGROUND.h) {
|
||||
init {
|
||||
scissor = true
|
||||
}
|
||||
|
||||
var flop = false
|
||||
|
||||
protected open fun makeTooltip(): MutableList<Component> {
|
||||
val tooltip: MutableList<Component>
|
||||
|
||||
if (widget.isStuck()) {
|
||||
tooltip = mutableListOf(
|
||||
TranslatableComponent(
|
||||
"otm.gui.progress_widget",
|
||||
String.format("%.2f", widget.percentage() * 100f)
|
||||
),
|
||||
TranslatableComponent("otm.gui.progress_widget_stuck").withStyle(ChatFormatting.DARK_RED)
|
||||
)
|
||||
} else {
|
||||
tooltip = mutableListOf(
|
||||
TranslatableComponent(
|
||||
"otm.gui.progress_widget",
|
||||
String.format("%.2f", widget.percentage() * 100f)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return tooltip
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
if (widget.isStuck() && tick % 40 <= 20) {
|
||||
RenderSystem.setShaderColor(0.75f, 0.4f, 0.4f, 1f)
|
||||
}
|
||||
|
||||
if (flop) {
|
||||
GAUGE_BACKGROUND.render(stack, winding = UVWindingOrder.U1_V0_U0_V1)
|
||||
val width = this.width * widget.percentage()
|
||||
GAUGE_FOREGROUND.renderPartial(stack, x = this.width - width, width = width, winding = UVWindingOrder.U1_V0_U0_V1)
|
||||
} else {
|
||||
GAUGE_BACKGROUND.render(stack)
|
||||
val width = this.width * widget.percentage()
|
||||
GAUGE_FOREGROUND.renderPartial(stack, width = width)
|
||||
}
|
||||
|
||||
if (widget.isStuck() && tick % 40 <= 20) {
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
||||
}
|
||||
}
|
||||
|
||||
override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
|
||||
if (isHovered) {
|
||||
screen.renderComponentTooltip(stack, makeTooltip(), mouse_x.toInt(), mouse_y.toInt())
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 0f, y = 240f, w = 22f, h = 16f)
|
||||
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 22f, y = 240f, w = 22f, h = 16f)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user