Add text outlining to hud values
This commit is contained in:
parent
e9f982eb6b
commit
00c3f17dd2
@ -254,8 +254,7 @@ object MatteryGUI {
|
|||||||
|
|
||||||
val formattedPower = mattery.androidEnergy.batteryLevel.formatPower()
|
val formattedPower = mattery.androidEnergy.batteryLevel.formatPower()
|
||||||
|
|
||||||
event.guiGraphics.draw(gui.font, formattedPower, left + CHARGE_BG.width + 2f, top + CHARGE_BG.height / 2f + 1f, scale = 0.5f, gravity = RenderGravity.CENTER_LEFT, color = RGBAColor.BLACK)
|
event.guiGraphics.draw(gui.font, formattedPower, left + CHARGE_BG.width + 1f, top + CHARGE_BG.height / 2f, scale = 0.5f, gravity = RenderGravity.CENTER_LEFT, color = RGBAColor.YELLOW, drawOutline = true)
|
||||||
event.guiGraphics.draw(gui.font, formattedPower, left + CHARGE_BG.width + 1f, top + CHARGE_BG.height / 2f, scale = 0.5f, gravity = RenderGravity.CENTER_LEFT, color = RGBAColor.YELLOW)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,8 +330,7 @@ object MatteryGUI {
|
|||||||
if (ply.absorptionAmount > 0)
|
if (ply.absorptionAmount > 0)
|
||||||
formattedHealth = TextComponent("%d+%d/%d".format(ply.health.toInt(), ply.absorptionAmount.toInt(), ply.maxHealth.toInt()))
|
formattedHealth = TextComponent("%d+%d/%d".format(ply.health.toInt(), ply.absorptionAmount.toInt(), ply.maxHealth.toInt()))
|
||||||
|
|
||||||
event.guiGraphics.draw(minecraft.font, formattedHealth, left - 1f, top + HEALTH_BG.height / 2f + 1f, scale = 0.5f, gravity = RenderGravity.CENTER_RIGHT, color = RGBAColor.BLACK)
|
event.guiGraphics.draw(minecraft.font, formattedHealth, left - 2f, top + HEALTH_BG.height / 2f, scale = 0.5f, gravity = RenderGravity.CENTER_RIGHT, color = getHealthColorForPlayer(ply), drawOutline = true)
|
||||||
event.guiGraphics.draw(minecraft.font, formattedHealth, left - 2f, top + HEALTH_BG.height / 2f, scale = 0.5f, gravity = RenderGravity.CENTER_RIGHT, color = getHealthColorForPlayer(ply))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,59 @@ inline val PoseStack.Pose.pose: Matrix4f get() = pose()
|
|||||||
private val buffer = DynamicBufferSource(vertexSorting = VertexSorting.ORTHOGRAPHIC_Z)
|
private val buffer = DynamicBufferSource(vertexSorting = VertexSorting.ORTHOGRAPHIC_Z)
|
||||||
private fun buffer() = buffer
|
private fun buffer() = buffer
|
||||||
|
|
||||||
|
private fun Font.drawInBatch(
|
||||||
|
text: Any, x: Float, y: Float, color: Int, drawShadow: Boolean,
|
||||||
|
matrix4f: Matrix4f, buffer: MultiBufferSource, displayMode: Font.DisplayMode,
|
||||||
|
effectColor: Int, packedLightCoords: Int, gravity: RenderGravity,
|
||||||
|
rounding: GravityRounding
|
||||||
|
): Int {
|
||||||
|
if (text is String)
|
||||||
|
return drawInBatch(
|
||||||
|
text,
|
||||||
|
gravity.x(x, this, text, rounding = rounding),
|
||||||
|
gravity.y(y, lineHeight.toFloat(), rounding = rounding),
|
||||||
|
color,
|
||||||
|
drawShadow,
|
||||||
|
matrix4f,
|
||||||
|
buffer,
|
||||||
|
displayMode,
|
||||||
|
effectColor,
|
||||||
|
packedLightCoords)
|
||||||
|
else if (text is Component)
|
||||||
|
return drawInBatch(
|
||||||
|
text,
|
||||||
|
gravity.x(x, this, text, rounding = rounding),
|
||||||
|
gravity.y(y, lineHeight.toFloat(), rounding = rounding),
|
||||||
|
color,
|
||||||
|
drawShadow,
|
||||||
|
matrix4f,
|
||||||
|
buffer,
|
||||||
|
displayMode,
|
||||||
|
effectColor,
|
||||||
|
packedLightCoords)
|
||||||
|
else if (text is FormattedCharSequence)
|
||||||
|
return drawInBatch(
|
||||||
|
text,
|
||||||
|
gravity.x(x, this, text, rounding = rounding),
|
||||||
|
gravity.y(y, lineHeight.toFloat(), rounding = rounding),
|
||||||
|
color,
|
||||||
|
drawShadow,
|
||||||
|
matrix4f,
|
||||||
|
buffer,
|
||||||
|
displayMode,
|
||||||
|
effectColor,
|
||||||
|
packedLightCoords)
|
||||||
|
else
|
||||||
|
throw IllegalArgumentException(text::class.qualifiedName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val outlinePositions = listOf(
|
||||||
|
1 to 0,
|
||||||
|
-1 to 0,
|
||||||
|
0 to 1,
|
||||||
|
0 to -1,
|
||||||
|
)
|
||||||
|
|
||||||
private fun Font.drawInternal(
|
private fun Font.drawInternal(
|
||||||
poseStack: PoseStack,
|
poseStack: PoseStack,
|
||||||
text: Any,
|
text: Any,
|
||||||
@ -92,9 +145,10 @@ private fun Font.drawInternal(
|
|||||||
shadowZ: Float,
|
shadowZ: Float,
|
||||||
customShadow: Boolean,
|
customShadow: Boolean,
|
||||||
rounding: GravityRounding,
|
rounding: GravityRounding,
|
||||||
|
drawOutline: Boolean,
|
||||||
|
outlineColor: RGBAColor,
|
||||||
|
outlineZ: Float,
|
||||||
): Float {
|
): Float {
|
||||||
require(!drawShadow && !customShadow || drawShadow != customShadow) { "Can not draw built in shadow and custom shadow at the same time" }
|
|
||||||
|
|
||||||
val inv: Float
|
val inv: Float
|
||||||
|
|
||||||
if (scale != 1f) {
|
if (scale != 1f) {
|
||||||
@ -115,64 +169,61 @@ private fun Font.drawInternal(
|
|||||||
poseStack.translate(0f, 0f, shadowZ)
|
poseStack.translate(0f, 0f, shadowZ)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text is String)
|
|
||||||
drawInBatch(
|
drawInBatch(
|
||||||
text,
|
text,
|
||||||
gravity.x((x + shadowX) * inv, this, text, 1f, rounding),
|
(x + shadowX) * inv,
|
||||||
gravity.y((y + shadowY) * inv, lineHeight.toFloat(), 1f, rounding),
|
(y + shadowY) * inv,
|
||||||
shadowColor.toRGB(),
|
shadowColor.toRGB(),
|
||||||
false,
|
false,
|
||||||
poseStack.last().pose(),
|
poseStack.last().pose(),
|
||||||
buffer,
|
buffer,
|
||||||
displayMode,
|
displayMode,
|
||||||
effectColor,
|
effectColor,
|
||||||
packedLightCoords)
|
packedLightCoords,
|
||||||
else if (text is Component)
|
gravity, rounding)
|
||||||
drawInBatch(
|
|
||||||
text,
|
|
||||||
gravity.x((x + shadowX) * inv, this, text, 1f, rounding),
|
|
||||||
gravity.y((y + shadowY) * inv, lineHeight.toFloat(), 1f, rounding),
|
|
||||||
shadowColor.toRGB(),
|
|
||||||
false,
|
|
||||||
poseStack.last().pose(),
|
|
||||||
buffer,
|
|
||||||
displayMode,
|
|
||||||
effectColor,
|
|
||||||
packedLightCoords)
|
|
||||||
|
|
||||||
if (shadowZ != 0f) {
|
if (shadowZ != 0f) {
|
||||||
poseStack.translate(0f, 0f, -shadowZ)
|
poseStack.translate(0f, 0f, -shadowZ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val width: Int
|
if (drawOutline) {
|
||||||
|
if (outlineZ != 0f) {
|
||||||
|
poseStack.translate(0f, 0f, outlineZ)
|
||||||
|
}
|
||||||
|
|
||||||
if (text is String)
|
for ((_x, _y) in outlinePositions) {
|
||||||
width = drawInBatch(
|
drawInBatch(
|
||||||
text,
|
text,
|
||||||
gravity.x(x * inv, this, text, 1f, rounding),
|
x * inv + _x,
|
||||||
gravity.y(y * inv, lineHeight.toFloat(), 1f, rounding),
|
y * inv + _y,
|
||||||
|
outlineColor.toRGB(),
|
||||||
|
drawShadow,
|
||||||
|
poseStack.last().pose(),
|
||||||
|
buffer,
|
||||||
|
displayMode,
|
||||||
|
effectColor,
|
||||||
|
packedLightCoords,
|
||||||
|
gravity, rounding)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outlineZ != 0f) {
|
||||||
|
poseStack.translate(0f, 0f, -outlineZ)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val width = drawInBatch(
|
||||||
|
text,
|
||||||
|
x * inv,
|
||||||
|
y * inv,
|
||||||
color.toRGB(),
|
color.toRGB(),
|
||||||
drawShadow,
|
drawShadow,
|
||||||
poseStack.last().pose(),
|
poseStack.last().pose(),
|
||||||
buffer,
|
buffer,
|
||||||
displayMode,
|
displayMode,
|
||||||
effectColor,
|
effectColor,
|
||||||
packedLightCoords)
|
packedLightCoords,
|
||||||
else if (text is Component)
|
gravity, rounding)
|
||||||
width = drawInBatch(
|
|
||||||
text,
|
|
||||||
gravity.x(x * inv, this, text, 1f, rounding),
|
|
||||||
gravity.y(y * inv, lineHeight.toFloat(), 1f, rounding),
|
|
||||||
color.toRGB(),
|
|
||||||
drawShadow,
|
|
||||||
poseStack.last().pose(),
|
|
||||||
buffer,
|
|
||||||
displayMode,
|
|
||||||
effectColor,
|
|
||||||
packedLightCoords)
|
|
||||||
else
|
|
||||||
throw IllegalArgumentException(text::class.qualifiedName)
|
|
||||||
|
|
||||||
if (scale != 1f) {
|
if (scale != 1f) {
|
||||||
poseStack.popPose()
|
poseStack.popPose()
|
||||||
@ -201,9 +252,12 @@ fun Font.draw(
|
|||||||
shadowColor: RGBAColor = RGBAColor.BLACK,
|
shadowColor: RGBAColor = RGBAColor.BLACK,
|
||||||
shadowX: Float = 1f,
|
shadowX: Float = 1f,
|
||||||
shadowY: Float = 1f,
|
shadowY: Float = 1f,
|
||||||
shadowZ: Float = 0f,
|
shadowZ: Float = -0.1f,
|
||||||
customShadow: Boolean = false,
|
customShadow: Boolean = false,
|
||||||
rounding: GravityRounding = if (scale == 1f) GravityRounding.DEFAULT else GravityRounding.NO,
|
rounding: GravityRounding = if (scale == 1f) GravityRounding.DEFAULT else GravityRounding.NO,
|
||||||
|
drawOutline: Boolean = false,
|
||||||
|
outlineColor: RGBAColor = RGBAColor.BLACK,
|
||||||
|
outlineZ: Float = -0.1f,
|
||||||
): Float {
|
): Float {
|
||||||
return drawInternal(
|
return drawInternal(
|
||||||
poseStack = poseStack,
|
poseStack = poseStack,
|
||||||
@ -224,6 +278,9 @@ fun Font.draw(
|
|||||||
shadowZ = shadowZ,
|
shadowZ = shadowZ,
|
||||||
customShadow = customShadow,
|
customShadow = customShadow,
|
||||||
rounding = rounding,
|
rounding = rounding,
|
||||||
|
drawOutline = drawOutline,
|
||||||
|
outlineColor = outlineColor,
|
||||||
|
outlineZ = outlineZ,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,9 +300,12 @@ fun Font.draw(
|
|||||||
shadowColor: RGBAColor = RGBAColor.BLACK,
|
shadowColor: RGBAColor = RGBAColor.BLACK,
|
||||||
shadowX: Float = 1f,
|
shadowX: Float = 1f,
|
||||||
shadowY: Float = 1f,
|
shadowY: Float = 1f,
|
||||||
shadowZ: Float = 0f,
|
shadowZ: Float = -0.1f,
|
||||||
customShadow: Boolean = false,
|
customShadow: Boolean = false,
|
||||||
rounding: GravityRounding = if (scale == 1f) GravityRounding.DEFAULT else GravityRounding.NO,
|
rounding: GravityRounding = if (scale == 1f) GravityRounding.DEFAULT else GravityRounding.NO,
|
||||||
|
drawOutline: Boolean = false,
|
||||||
|
outlineColor: RGBAColor = RGBAColor.BLACK,
|
||||||
|
outlineZ: Float = -0.1f,
|
||||||
): Float {
|
): Float {
|
||||||
return drawInternal(
|
return drawInternal(
|
||||||
poseStack = poseStack,
|
poseStack = poseStack,
|
||||||
@ -265,7 +325,10 @@ fun Font.draw(
|
|||||||
shadowY = shadowY,
|
shadowY = shadowY,
|
||||||
shadowZ = shadowZ,
|
shadowZ = shadowZ,
|
||||||
customShadow = customShadow,
|
customShadow = customShadow,
|
||||||
rounding = rounding
|
rounding = rounding,
|
||||||
|
drawOutline = drawOutline,
|
||||||
|
outlineColor = outlineColor,
|
||||||
|
outlineZ = outlineZ,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,11 +345,14 @@ fun GuiGraphics.draw(
|
|||||||
packedLightCoords: Int = 15728880,
|
packedLightCoords: Int = 15728880,
|
||||||
effectColor: Int = 0,
|
effectColor: Int = 0,
|
||||||
shadowColor: RGBAColor = RGBAColor.BLACK,
|
shadowColor: RGBAColor = RGBAColor.BLACK,
|
||||||
shadowX: Float = 0f,
|
shadowX: Float = 1f,
|
||||||
shadowY: Float = 0f,
|
shadowY: Float = 1f,
|
||||||
shadowZ: Float = 0f,
|
shadowZ: Float = -0.1f,
|
||||||
customShadow: Boolean = false,
|
customShadow: Boolean = false,
|
||||||
rounding: GravityRounding = if (scale == 1f) GravityRounding.DEFAULT else GravityRounding.NO,
|
rounding: GravityRounding = if (scale == 1f) GravityRounding.DEFAULT else GravityRounding.NO,
|
||||||
|
drawOutline: Boolean = false,
|
||||||
|
outlineColor: RGBAColor = RGBAColor.BLACK,
|
||||||
|
outlineZ: Float = -0.1f,
|
||||||
): Float {
|
): Float {
|
||||||
val width = font.draw(
|
val width = font.draw(
|
||||||
poseStack = pose(),
|
poseStack = pose(),
|
||||||
@ -307,6 +373,9 @@ fun GuiGraphics.draw(
|
|||||||
shadowZ = shadowZ,
|
shadowZ = shadowZ,
|
||||||
customShadow = customShadow,
|
customShadow = customShadow,
|
||||||
rounding = rounding,
|
rounding = rounding,
|
||||||
|
drawOutline = drawOutline,
|
||||||
|
outlineColor = outlineColor,
|
||||||
|
outlineZ = outlineZ,
|
||||||
)
|
)
|
||||||
|
|
||||||
flush()
|
flush()
|
||||||
@ -326,11 +395,14 @@ fun GuiGraphics.draw(
|
|||||||
packedLightCoords: Int = 15728880,
|
packedLightCoords: Int = 15728880,
|
||||||
effectColor: Int = 0,
|
effectColor: Int = 0,
|
||||||
shadowColor: RGBAColor = RGBAColor.BLACK,
|
shadowColor: RGBAColor = RGBAColor.BLACK,
|
||||||
shadowX: Float = 0f,
|
shadowX: Float = 1f,
|
||||||
shadowY: Float = 0f,
|
shadowY: Float = 1f,
|
||||||
shadowZ: Float = 0f,
|
shadowZ: Float = -0.1f,
|
||||||
customShadow: Boolean = false,
|
customShadow: Boolean = false,
|
||||||
rounding: GravityRounding = if (scale == 1f) GravityRounding.DEFAULT else GravityRounding.NO,
|
rounding: GravityRounding = if (scale == 1f) GravityRounding.DEFAULT else GravityRounding.NO,
|
||||||
|
drawOutline: Boolean = false,
|
||||||
|
outlineColor: RGBAColor = RGBAColor.BLACK,
|
||||||
|
outlineZ: Float = -0.1f,
|
||||||
): Float {
|
): Float {
|
||||||
val width = font.draw(
|
val width = font.draw(
|
||||||
poseStack = pose(),
|
poseStack = pose(),
|
||||||
@ -351,6 +423,9 @@ fun GuiGraphics.draw(
|
|||||||
shadowZ = shadowZ,
|
shadowZ = shadowZ,
|
||||||
customShadow = customShadow,
|
customShadow = customShadow,
|
||||||
rounding = rounding,
|
rounding = rounding,
|
||||||
|
drawOutline = drawOutline,
|
||||||
|
outlineColor = outlineColor,
|
||||||
|
outlineZ = outlineZ,
|
||||||
)
|
)
|
||||||
|
|
||||||
flush()
|
flush()
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.client.render
|
|||||||
|
|
||||||
import net.minecraft.client.gui.Font
|
import net.minecraft.client.gui.Font
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.util.FormattedCharSequence
|
||||||
import ru.dbotthepony.mc.otm.core.FloatSupplier
|
import ru.dbotthepony.mc.otm.core.FloatSupplier
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@ -65,6 +66,9 @@ interface IXGravity {
|
|||||||
fun x(x: Float, font: Font, text: String): Float = x(x, font, text, 1f)
|
fun x(x: Float, font: Font, text: String): Float = x(x, font, text, 1f)
|
||||||
fun x(x: Float, font: Font, text: String, scale: Float = 1f, rounding: GravityRounding = GravityRounding.DEFAULT): Float
|
fun x(x: Float, font: Font, text: String, scale: Float = 1f, rounding: GravityRounding = GravityRounding.DEFAULT): Float
|
||||||
|
|
||||||
|
fun x(x: Float, font: Font, text: FormattedCharSequence): Float = x(x, font, text, 1f)
|
||||||
|
fun x(x: Float, font: Font, text: FormattedCharSequence, scale: Float = 1f, rounding: GravityRounding = GravityRounding.DEFAULT): Float
|
||||||
|
|
||||||
fun x(x: Float, width: Int, scale: Float = 1f): Float {
|
fun x(x: Float, width: Int, scale: Float = 1f): Float {
|
||||||
return x(x, width.toFloat() * scale).roundToInt().toFloat()
|
return x(x, width.toFloat() * scale).roundToInt().toFloat()
|
||||||
}
|
}
|
||||||
@ -98,6 +102,10 @@ enum class XGravity : IXGravity {
|
|||||||
override fun x(x: Float, font: Font, text: String, scale: Float, rounding: GravityRounding): Float {
|
override fun x(x: Float, font: Font, text: String, scale: Float, rounding: GravityRounding): Float {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun x(x: Float, font: Font, text: FormattedCharSequence, scale: Float, rounding: GravityRounding): Float {
|
||||||
|
return x
|
||||||
|
}
|
||||||
},
|
},
|
||||||
CENTER {
|
CENTER {
|
||||||
override fun x(x: Float, width: FloatSupplier, scale: Float, rounding: GravityRounding): Float {
|
override fun x(x: Float, width: FloatSupplier, scale: Float, rounding: GravityRounding): Float {
|
||||||
@ -115,6 +123,10 @@ enum class XGravity : IXGravity {
|
|||||||
override fun x(x: Float, font: Font, text: String, scale: Float, rounding: GravityRounding): Float {
|
override fun x(x: Float, font: Font, text: String, scale: Float, rounding: GravityRounding): Float {
|
||||||
return rounding.round(x, font.width(text) / 2f * scale)
|
return rounding.round(x, font.width(text) / 2f * scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun x(x: Float, font: Font, text: FormattedCharSequence, scale: Float, rounding: GravityRounding): Float {
|
||||||
|
return rounding.round(x, font.width(text) / 2f * scale)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
RIGHT {
|
RIGHT {
|
||||||
override fun x(x: Float, width: FloatSupplier, scale: Float, rounding: GravityRounding): Float {
|
override fun x(x: Float, width: FloatSupplier, scale: Float, rounding: GravityRounding): Float {
|
||||||
@ -132,6 +144,10 @@ enum class XGravity : IXGravity {
|
|||||||
override fun x(x: Float, font: Font, text: String, scale: Float, rounding: GravityRounding): Float {
|
override fun x(x: Float, font: Font, text: String, scale: Float, rounding: GravityRounding): Float {
|
||||||
return rounding.round(x, font.width(text) * scale)
|
return rounding.round(x, font.width(text) * scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun x(x: Float, font: Font, text: FormattedCharSequence, scale: Float, rounding: GravityRounding): Float {
|
||||||
|
return rounding.round(x, font.width(text) * scale)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user