Add "approximate total" to chart tooltips

This commit is contained in:
DBotThePony 2024-10-02 10:59:55 +07:00
parent 4e3cf276e9
commit 5898ae0b19
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 20 additions and 10 deletions

View File

@ -362,6 +362,8 @@ private fun misc(provider: MatteryLanguageProvider) {
gui("progress_widget_stuck", "The machine can not work, check configuration") gui("progress_widget_stuck", "The machine can not work, check configuration")
gui("total_raw", "Total:") gui("total_raw", "Total:")
gui("total", "Total: %s")
gui("total_approx", "Total: ~%s")
gui("matter.percentage_level", "Matter level: %s%%") gui("matter.percentage_level", "Matter level: %s%%")
gui("matter.format", "Matter: %s") gui("matter.format", "Matter: %s")

View File

@ -367,6 +367,8 @@ private fun misc(provider: MatteryLanguageProvider) {
gui("progress_widget_stuck", "Это устройство не может продолжить работу, проверьте конфигурацию") gui("progress_widget_stuck", "Это устройство не может продолжить работу, проверьте конфигурацию")
gui("total_raw", "Всего:") gui("total_raw", "Всего:")
gui("total", "Всего: %s")
gui("total_approx", "Всего примерно: %s")
gui("matter.percentage_level", "Уровень материи: %s%%") gui("matter.percentage_level", "Уровень материи: %s%%")
gui("matter.format", "Материя: %s") gui("matter.format", "Материя: %s")

View File

@ -17,7 +17,7 @@ import ru.dbotthepony.mc.otm.core.util.formatTickDuration
open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>( open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>(
screen: S, screen: S,
parent: EditablePanel<*>, parent: EditablePanel<*>,
val graph: DecimalHistoryChart, val chart: DecimalHistoryChart,
val formatText: (Decimal) -> Component = { TextComponent(it.toString(2)) }, val formatText: (Decimal) -> Component = { TextComponent(it.toString(2)) },
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
@ -25,13 +25,13 @@ open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>(
height: Float = 10f height: Float = 10f
) : EditablePanel<S>(screen, parent, x, y, width, height) { ) : EditablePanel<S>(screen, parent, x, y, width, height) {
override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
val maximum = graph.max() val maximum = chart.max()
val normalized: FloatArray val normalized: FloatArray
val levelLabels: ChartLevelLabels val levelLabels: ChartLevelLabels
if (maximum.isZero || maximum.isInfinite) { if (maximum.isZero || maximum.isInfinite) {
normalized = FloatArray(graph.width) { normalized = FloatArray(chart.width) {
if (graph[it].isInfinite) 0.8f else 0.0f if (chart[it].isInfinite) 0.8f else 0.0f
} }
levelLabels = ChartLevelLabels( levelLabels = ChartLevelLabels(
@ -39,7 +39,7 @@ open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>(
font = font font = font
) )
} else { } else {
normalized = FloatArray(graph.width) { (graph[it] / maximum).toFloat() * 0.9f } normalized = FloatArray(chart.width) { (chart[it] / maximum).toFloat() * 0.9f }
val map = Float2ObjectArrayMap<Component>() val map = Float2ObjectArrayMap<Component>()
@ -65,11 +65,16 @@ open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>(
mouseX - absoluteX, mouseX - absoluteX,
mouseY - absoluteY, mouseY - absoluteY,
{ {
listOf( val result = ArrayList<Component>()
formatText(graph[it]), result.add(formatText(chart[it]))
TextComponent(""),
TranslatableComponent("otm.gui.ago", formatTickDuration(it * graph.resolution, true)) if (chart.resolution != 1 && chart[it].isFinite && chart[it].isNotZero) {
) result.add(TranslatableComponent("otm.gui.total_approx", formatText(chart[it] * chart.resolution)))
}
result.add(TextComponent(""))
result.add(TranslatableComponent("otm.gui.ago", formatTickDuration(it * chart.resolution, true)))
result
}, },
font, font,
), ),

View File

@ -120,6 +120,7 @@ sealed class Decimal : Number(), Comparable<Decimal> {
* Whenever this Decimal is zero * Whenever this Decimal is zero
*/ */
inline val isZero get() = signum() == 0 inline val isZero get() = signum() == 0
inline val isNotZero get() = signum() != 0
abstract val isInfinite: Boolean abstract val isInfinite: Boolean
abstract val isFinite: Boolean abstract val isFinite: Boolean