diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt index d17add084..f36b45cd6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt @@ -12,6 +12,7 @@ import net.minecraft.client.gui.screens.DeathScreen import net.minecraft.client.gui.screens.InBedChatScreen import net.minecraft.client.player.LocalPlayer import net.minecraft.network.chat.Component +import net.minecraft.network.chat.Style import net.minecraft.world.effect.MobEffects import net.minecraft.world.entity.LivingEntity import net.minecraft.world.entity.player.Player @@ -112,6 +113,9 @@ object MatteryGUI { event.registerAbove(VanillaGuiLayers.CAMERA_OVERLAYS, loc("android_low_power"), AndroidLowPowerLayer()) } + private val SMALL_FONT = loc("small") + private val SMALL_FONT_STYLE = Style.EMPTY.withFont(SMALL_FONT) + class AndroidEnergyBarLayer : LayeredDraw.Layer { override fun render( graphics: GuiGraphics, @@ -163,9 +167,8 @@ object MatteryGUI { } val formattedPower = mattery.androidEnergy.batteryLevel.formatPower() - - val scale = ClientConfig.HUD.BAR_TEXT_SCALE.toFloat() - guiGraphics.draw(formattedPower, left + CHARGE_BG.width + 2f + scale, top + CHARGE_BG.height / 2f + scale, font = gui.font, scale = scale, gravity = RenderGravity.CENTER_LEFT, color = RGBAColor.YELLOW, drawOutline = true) + val scale = if (ClientConfig.HUD.USE_SMALL_FONT) 1f else ClientConfig.HUD.BAR_TEXT_SCALE.toFloat() + guiGraphics.draw(formattedPower.withStyle(if (ClientConfig.HUD.USE_SMALL_FONT) SMALL_FONT_STYLE else Style.EMPTY), left + CHARGE_BG.width + 2f + scale, top + CHARGE_BG.height / 2f + scale, font = gui.font, scale = scale, gravity = RenderGravity.CENTER_LEFT, color = RGBAColor.YELLOW, drawOutline = true) RenderSystem.disableBlend() RenderSystem.enableDepthTest() @@ -230,8 +233,8 @@ object MatteryGUI { if (ply.absorptionAmount > 0) formattedHealth = TextComponent("%d+%d/%d".format(ply.health.toInt(), ply.absorptionAmount.toInt(), ply.maxHealth.toInt())) - val scale = ClientConfig.HUD.BAR_TEXT_SCALE.toFloat() - guiGraphics.draw(formattedHealth, left - 2f, top + HEALTH_BG.height / 2f + 1f * scale, scale = scale, gravity = RenderGravity.CENTER_RIGHT, color = getHealthColorForPlayer(ply), drawOutline = true) + val scale = if (ClientConfig.HUD.USE_SMALL_FONT) 1f else ClientConfig.HUD.BAR_TEXT_SCALE.toFloat() + guiGraphics.draw(formattedHealth.withStyle(if (ClientConfig.HUD.USE_SMALL_FONT) SMALL_FONT_STYLE else Style.EMPTY), left - 2f, top + HEALTH_BG.height / 2f + 1f * scale, scale = scale, gravity = RenderGravity.CENTER_RIGHT, color = getHealthColorForPlayer(ply), drawOutline = true) RenderSystem.disableBlend() RenderSystem.enableDepthTest() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/config/ClientConfig.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/config/ClientConfig.kt index 03c74878e..b3048cde8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/ClientConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/ClientConfig.kt @@ -69,6 +69,10 @@ object ClientConfig : AbstractConfig("client", ModConfig.Type.CLIENT) { var BAR_TEXT_SCALE: Double by builder .defineInRange("BAR_TEXT_SCALE", 0.5, 0.5, 1.0) + var USE_SMALL_FONT: Boolean by builder + .comment("Use smaller font on HUD bars", "(Scale is ignored)") + .define("USE_SMALL_FONT", false) + init { builder.pop() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Formatting.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Formatting.kt index 7999f0f88..961540d14 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Formatting.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Formatting.kt @@ -25,7 +25,7 @@ import kotlin.math.absoluteValue import kotlin.math.max import kotlin.math.roundToInt -private fun concat(numbers: String, suffix: Any): Component { +private fun concat(numbers: String, suffix: Any): MutableComponent { if (suffix == "") return TextComponent(numbers) else if (suffix is Component) @@ -177,7 +177,7 @@ private fun resplice(number: String, decimals: Int): String { return String(resplice) } -fun Long.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component { +fun Long.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): MutableComponent { require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" } if (formatAsReadable.asBoolean) { @@ -193,18 +193,18 @@ fun Long.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsRea return TranslatableComponent(prefix.neighbour(bias).formatLocaleKey, "%.${decimalPlaces}f".format(this.toDouble() / prefix.long!!.toDouble()), suffix) } -fun Int.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component { +fun Int.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): MutableComponent { return toLong().formatSiComponent(suffix, decimalPlaces, formatAsReadable, bias) } -fun Double.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component { +fun Double.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): MutableComponent { require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" } if (formatAsReadable.asBoolean && this.absoluteValue >= 1.0) return concat(reformat("%.${decimalPlaces}f".format(this)), suffix) val prefix = SiPrefix.determine(this) return TranslatableComponent(prefix.neighbour(bias).formatLocaleKey, "%.${decimalPlaces}f".format(this / prefix.double), suffix) } -fun Decimal.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component { +fun Decimal.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): MutableComponent { require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" } if (this == Decimal.POSITIVE_INFINITY) return concat("∞", suffix) if (this == Decimal.NEGATIVE_INFINITY) return concat("-∞", suffix) diff --git a/src/main/resources/assets/overdrive_that_matters/font/small.json b/src/main/resources/assets/overdrive_that_matters/font/small.json new file mode 100644 index 000000000..612ba26a3 --- /dev/null +++ b/src/main/resources/assets/overdrive_that_matters/font/small.json @@ -0,0 +1,30 @@ +{ + "providers": [ + { + "type": "space", + "advances": { + " ": 4 + } + }, + { + "type": "bitmap", + "file": "overdrive_that_matters:font/small.png", + "chars": [ + "\u0020\u0021\u0022\u0023\u0024\u0025\u0026\u0027\u0028\u0029\u002a\u002b\u002c\u002d\u002e\u002f", + "\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039\u003a\u003b\u003c\u003d\u003e\u003f", + "\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047\u0048\u0049\u004a\u004b\u004c\u004d\u004e\u004f", + "\u0050\u0051\u0052\u0053\u0054\u0055\u0056\u0057\u0058\u0059\u005a\u005b\u005c\u005d\u005e\u005f", + "\u0060\u0061\u0062\u0063\u0064\u0065\u0066\u0067\u0068\u0069\u006a\u006b\u006c\u006d\u006e\u006f", + "\u0070\u0071\u0072\u0073\u0074\u0075\u0076\u0077\u0078\u0079\u007a\u007b\u007c\u007d\u007e\u0000", + "\u0410\u0411\u0412\u0413\u0414\u0415\u0401\u0416\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E", + "\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E", + "\u042F\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000", + "\u0430\u0431\u0432\u0433\u0434\u0435\u0451\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E", + "\u043F\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E", + "\u044F\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" + ], + "height": 6, + "ascent": 6 + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/overdrive_that_matters/textures/font/small.pdn b/src/main/resources/assets/overdrive_that_matters/textures/font/small.pdn new file mode 100644 index 000000000..8a8ddabb7 Binary files /dev/null and b/src/main/resources/assets/overdrive_that_matters/textures/font/small.pdn differ diff --git a/src/main/resources/assets/overdrive_that_matters/textures/font/small.png b/src/main/resources/assets/overdrive_that_matters/textures/font/small.png new file mode 100644 index 000000000..46a23eb36 Binary files /dev/null and b/src/main/resources/assets/overdrive_that_matters/textures/font/small.png differ