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("total_raw", "Total:")
gui("total", "Total: %s")
gui("total_approx", "Total: ~%s")
gui("matter.percentage_level", "Matter level: %s%%")
gui("matter.format", "Matter: %s")

View File

@ -367,6 +367,8 @@ private fun misc(provider: MatteryLanguageProvider) {
gui("progress_widget_stuck", "Это устройство не может продолжить работу, проверьте конфигурацию")
gui("total_raw", "Всего:")
gui("total", "Всего: %s")
gui("total_approx", "Всего примерно: %s")
gui("matter.percentage_level", "Уровень материи: %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<*>>(
screen: S,
parent: EditablePanel<*>,
val graph: DecimalHistoryChart,
val chart: DecimalHistoryChart,
val formatText: (Decimal) -> Component = { TextComponent(it.toString(2)) },
x: Float = 0f,
y: Float = 0f,
@ -25,13 +25,13 @@ open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>(
height: Float = 10f
) : EditablePanel<S>(screen, parent, x, y, width, height) {
override fun innerRender(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
val maximum = graph.max()
val maximum = chart.max()
val normalized: FloatArray
val levelLabels: ChartLevelLabels
if (maximum.isZero || maximum.isInfinite) {
normalized = FloatArray(graph.width) {
if (graph[it].isInfinite) 0.8f else 0.0f
normalized = FloatArray(chart.width) {
if (chart[it].isInfinite) 0.8f else 0.0f
}
levelLabels = ChartLevelLabels(
@ -39,7 +39,7 @@ open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>(
font = font
)
} 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>()
@ -65,11 +65,16 @@ open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>(
mouseX - absoluteX,
mouseY - absoluteY,
{
listOf(
formatText(graph[it]),
TextComponent(""),
TranslatableComponent("otm.gui.ago", formatTickDuration(it * graph.resolution, true))
)
val result = ArrayList<Component>()
result.add(formatText(chart[it]))
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,
),

View File

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