Display total matter required, stored, and total complexity in pattern grid

This commit is contained in:
DBotThePony 2023-03-07 19:31:32 +07:00
parent b063175b8c
commit 75b06f34c2
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 128 additions and 49 deletions

View File

@ -215,19 +215,6 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("suffix_raw.zepto", "z")
misc("suffix_raw.yocto", "y")
misc("container.matter_panel.increase_by", "+%s")
misc("container.matter_panel.decrease_by", "-%s")
misc("container.matter_panel.send", "Send")
misc("container.matter_panel.close", "Close")
misc("container.matter_panel.cancel_task", "Cancel task")
misc("container.matter_panel.cancel", "Cancel")
misc("container.matter_panel.label", "Replication request")
misc("container.matter_panel.task", "Ongoing replication task")
misc("container.matter_panel.task_line", "%s: %s | %s / %s")
misc("container.matter_panel.tasks", "Tasks")
misc("container.matter_panel.patterns", "Patterns")
misc("item.power.infinite.storage", "Stored energy: ∞ / ∞")
misc("item.power.infinite.throughput", "Max I/O: ∞ / ∞")
misc("item.power.passed", "Passed energy: %s")
@ -330,8 +317,6 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("matter_bottler.switch_mode", "Switch work mode")
misc("container.matter_panel.number_input", "Input replication task count")
misc("item.quantum_battery.creative", "Fill this to win Minecraft.")
misc("item.quantum_battery.creative2", "See ya after millions of stars burn out.")
misc("item.quantum_battery.creative_power", "Stored energy: %s / Infinity")
@ -646,6 +631,25 @@ private fun gui(provider: MatteryLanguageProvider) {
gui("sorting.count", "Sort by amount")
gui("sorting.ascending", "Ascending")
gui("sorting.descending", "Descending")
gui("matter_panel.increase_by", "+%s")
gui("matter_panel.decrease_by", "-%s")
gui("matter_panel.send", "Send")
gui("matter_panel.close", "Close")
gui("matter_panel.cancel_task", "Cancel task")
gui("matter_panel.cancel", "Cancel")
gui("matter_panel.label", "Replication request")
gui("matter_panel.task", "Ongoing replication task")
gui("matter_panel.task_line", "%s: %s | %s / %s")
gui("matter_panel.tasks", "Tasks")
gui("matter_panel.patterns", "Patterns")
gui("matter_panel.number_input", "Input replication task count")
gui("matter_panel.matter_stored", "Matter stored: %s")
gui("matter_panel.matter_required", "Matter required: %s")
gui("matter_panel.complexity", "Total complexity: %s")
}
}

View File

@ -224,16 +224,6 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("suffix_raw.zepto", "з")
misc("suffix_raw.yocto", "и")
misc("container.matter_panel.send", "Запросить")
misc("container.matter_panel.close", "Закрыть")
misc("container.matter_panel.cancel_task", "Отменить задание")
misc("container.matter_panel.cancel", "Отмена")
misc("container.matter_panel.label", "Запрос на репликацию")
misc("container.matter_panel.task", "Будущий запрос на репликацию")
misc("container.matter_panel.tasks", "Задачи")
misc("container.matter_panel.patterns", "Шаблоны")
misc("item.power.infinite.storage", "Хранимая энергия неиссякаема")
misc("item.power.infinite.throughput", "Максимальный ввод/вывод неограничен")
misc("item.power.passed", "Переданная энергия: %s")
@ -335,8 +325,6 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("matter_bottler.switch_mode", "Переключить режим работы")
misc("container.matter_panel.number_input", "Введите кол-во единиц репликации")
misc("item.quantum_battery.creative", "Наполните этот аккумулятор чтоб выиграть Minecraft.")
misc("item.quantum_battery.creative2", "Встретимся после выгорания миллионов звёзд.")
misc("item.quantum_battery.creative_power", "Хранимая энергия: %s / ∞")
@ -651,6 +639,22 @@ private fun gui(provider: MatteryLanguageProvider) {
gui("sorting.count", "Сортировка по количеству")
gui("sorting.ascending", "Возрастающая")
gui("sorting.descending", "Убывающая")
gui("matter_panel.send", "Запросить")
gui("matter_panel.close", "Закрыть")
gui("matter_panel.cancel_task", "Отменить задание")
gui("matter_panel.cancel", "Отмена")
gui("matter_panel.label", "Запрос на репликацию")
gui("matter_panel.task", "Будущий запрос на репликацию")
gui("matter_panel.tasks", "Задачи")
gui("matter_panel.patterns", "Шаблоны")
gui("matter_panel.number_input", "Введите кол-во единиц репликации")
gui("matter_panel.matter_stored", "Материи хранится: %s")
gui("matter_panel.matter_required", "Материи требуется: %s")
gui("matter_panel.complexity", "Общая сложность: %s")
}
}

View File

@ -7,6 +7,7 @@ import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.capability.matter.IPatternState
import ru.dbotthepony.mc.otm.capability.matter.IReplicationTask
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
@ -19,13 +20,18 @@ import ru.dbotthepony.mc.otm.client.screen.panels.input.EditBoxPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.DiscreteScrollBarPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.ScrollBarConstants
import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.integerDivisionDown
import ru.dbotthepony.mc.otm.core.util.ItemSorter
import ru.dbotthepony.mc.otm.core.util.formatMatter
import ru.dbotthepony.mc.otm.core.util.formatTickDuration
import ru.dbotthepony.mc.otm.matter.MatterManager
import ru.dbotthepony.mc.otm.menu.matter.MatterPanelMenu
import ru.dbotthepony.mc.otm.menu.matter.ReplicationRequestPacket
import ru.dbotthepony.mc.otm.network.MenuNetworkChannel
import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak
import kotlin.math.roundToInt
@MouseTweaksDisableWheelTweak
class MatterPanelScreen(
@ -76,11 +82,11 @@ class MatterPanelScreen(
scrollBar.dock = Dock.RIGHT
frame.Tab(onOpen = { isPatternView = true; scrollBar.scroll = scrollPatterns }, activeIcon = PATTERN_LIST_ACTIVE, inactiveIcon = PATTERN_LIST_INACTIVE).also {
it.tooltip = TranslatableComponent("otm.container.matter_panel.patterns")
it.tooltip = TranslatableComponent("otm.gui.matter_panel.patterns")
}
frame.Tab(onOpen = { isPatternView = false; scrollBar.scroll = scrollTasks }, activeIcon = TASK_LIST_ACTIVE, inactiveIcon = TASK_LIST_INACTIVE).also {
it.tooltip = TranslatableComponent("otm.container.matter_panel.tasks")
it.tooltip = TranslatableComponent("otm.gui.matter_panel.tasks")
}
val canvas = object : EditablePanel<MatterPanelScreen>(this@MatterPanelScreen, frame, width = GRID_WIDTH * AbstractSlotPanel.SIZE) {
@ -163,7 +169,7 @@ class MatterPanelScreen(
}
private fun openTask(task: IReplicationTask<*>) {
val frame = FramePanel.padded(this, null, 170f, 20f, TranslatableComponent("otm.container.matter_panel.task"))
val frame = FramePanel.padded(this, null, 170f, 20f, TranslatableComponent("otm.gui.matter_panel.task"))
frame.closeOnEscape = true
@ -185,13 +191,13 @@ class MatterPanelScreen(
}
}
ButtonPanel(this@MatterPanelScreen, frame, width = 40f, label = TranslatableComponent("otm.container.matter_panel.close"), onPress = frame::remove).also {
ButtonPanel(this@MatterPanelScreen, frame, width = 40f, label = TranslatableComponent("otm.gui.matter_panel.close"), onPress = frame::remove).also {
it.dock = Dock.RIGHT
it.dockLeft = 2f
}
if (minecraft?.player?.isSpectator != true) {
ButtonPanel(this@MatterPanelScreen, frame, width = 80f, label = TranslatableComponent("otm.container.matter_panel.cancel_task"), onPress = Runnable {
ButtonPanel(this@MatterPanelScreen, frame, width = 80f, label = TranslatableComponent("otm.gui.matter_panel.cancel_task"), onPress = Runnable {
menu.requestTaskCancel(task.id)
frame.remove()
}).also {
@ -207,7 +213,7 @@ class MatterPanelScreen(
}
private fun openPattern(pattern: IPatternState) {
val frame = FramePanel.padded(this, null, 213f, (ButtonPanel.HEIGHT + 3f) * 4f, TranslatableComponent("otm.container.matter_panel.task"))
val frame = FramePanel.padded(this, null, 213f, (ButtonPanel.HEIGHT + 3f) * 4f + 38f, TranslatableComponent("otm.gui.matter_panel.task"))
frame.closeOnEscape = true
@ -253,6 +259,8 @@ class MatterPanelScreen(
}
}
var count = 1
val input = object : EditBoxPanel<MatterPanelScreen>(this@MatterPanelScreen, rowInput) {
init {
dock = Dock.FILL
@ -269,68 +277,77 @@ class MatterPanelScreen(
}
fun increase(amount: Int) {
var value = 1
count = 1
try {
value = getOrCreateWidget().value.toInt()
count = getOrCreateWidget().value.toInt().coerceIn(1, 99999)
} catch (_: NumberFormatException) {
}
if (value == 1 && amount > 0)
if (count == 1 && amount > 0)
getOrCreateWidget().value = amount.toString()
else
getOrCreateWidget().value = 1.coerceAtLeast(99999.coerceAtMost(value + amount)).toString()
getOrCreateWidget().value = (count + amount).coerceIn(1, 99999).toString()
}
override fun tickInner() {
super.tickInner()
try {
count = getOrCreateWidget().value.toInt().coerceIn(1, 99999)
} catch (_: NumberFormatException) {
}
}
fun send() {
var value = 1
count = 1
try {
value = getOrCreateWidget().value.toInt()
count = getOrCreateWidget().value.toInt().coerceIn(1, 99999)
} catch (_: NumberFormatException) {
}
MenuNetworkChannel.sendToServer(ReplicationRequestPacket(pattern.id, value))
MenuNetworkChannel.sendToServer(ReplicationRequestPacket(pattern.id, count))
frame.remove()
}
}
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 8), onPress = Runnable { input.increase(8) }).also {
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.gui.matter_panel.increase_by", 8), onPress = Runnable { input.increase(8) }).also {
it.dock = Dock.RIGHT
it.dockLeft = 2f
}
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 64), onPress = Runnable { input.increase(64) }).also {
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.gui.matter_panel.increase_by", 64), onPress = Runnable { input.increase(64) }).also {
it.dock = Dock.RIGHT
it.dockLeft = 2f
}
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 256), onPress = Runnable { input.increase(256) }).also {
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.gui.matter_panel.increase_by", 256), onPress = Runnable { input.increase(256) }).also {
it.dock = Dock.RIGHT
it.dockLeft = 2f
}
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.container.matter_panel.decrease_by", 8), onPress = Runnable { input.increase(-8) }).also {
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.gui.matter_panel.decrease_by", 8), onPress = Runnable { input.increase(-8) }).also {
it.dock = Dock.RIGHT
it.dockLeft = 2f
}
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.container.matter_panel.decrease_by", 64), onPress = Runnable { input.increase(-64) }).also {
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.gui.matter_panel.decrease_by", 64), onPress = Runnable { input.increase(-64) }).also {
it.dock = Dock.RIGHT
it.dockLeft = 2f
}
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.container.matter_panel.decrease_by", 256), onPress = Runnable { input.increase(-256) }).also {
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.gui.matter_panel.decrease_by", 256), onPress = Runnable { input.increase(-256) }).also {
it.dock = Dock.RIGHT
it.dockLeft = 2f
}
ButtonPanel(this, rowControls, width = 40f, label = TranslatableComponent("otm.container.matter_panel.cancel"), onPress = frame::remove).also {
ButtonPanel(this, rowControls, width = 40f, label = TranslatableComponent("otm.gui.matter_panel.cancel"), onPress = frame::remove).also {
it.dock = Dock.RIGHT
it.dockLeft = 2f
}
ButtonPanel(this, rowControls, width = 82f, label = TranslatableComponent("otm.container.matter_panel.send"), onPress = input::send).also {
ButtonPanel(this, rowControls, width = 82f, label = TranslatableComponent("otm.gui.matter_panel.send"), onPress = input::send).also {
it.dock = Dock.RIGHT
it.dockLeft = 2f
}
@ -338,6 +355,54 @@ class MatterPanelScreen(
addPanel(frame)
popup(frame)
object : Label<MatterPanelScreen>(this@MatterPanelScreen, frame, text = TextComponent("")) {
init {
dock = Dock.TOP
dockTop = 5f
}
override fun tickInner() {
super.tickInner()
text = TranslatableComponent(
"otm.gui.matter_panel.matter_stored",
menu.totalMatterStored.formatMatter(formatAsReadable = ShiftPressedCond),
)
}
}
object : Label<MatterPanelScreen>(this@MatterPanelScreen, frame, text = TextComponent("")) {
init {
dock = Dock.TOP
dockTop = 3f
}
override fun tickInner() {
super.tickInner()
text = TranslatableComponent(
"otm.gui.matter_panel.matter_required",
(MatterManager.get(pattern.item).matter * count).formatMatter(formatAsReadable = ShiftPressedCond),
)
}
}
object : Label<MatterPanelScreen>(this@MatterPanelScreen, frame, text = TextComponent("")) {
init {
dock = Dock.TOP
dockTop = 3f
}
override fun tickInner() {
super.tickInner()
text = TranslatableComponent(
"otm.gui.matter_panel.complexity",
formatTickDuration((MatterManager.get(pattern.item).complexity * count).roundToInt(), true),
)
}
}
frame.toScreenCenter()
}

View File

@ -12,8 +12,9 @@ import ru.dbotthepony.mc.otm.capability.matter.*
import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.core.addSorted
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.util.BooleanValueCodec
import ru.dbotthepony.mc.otm.core.util.EnumValueCodec
import ru.dbotthepony.mc.otm.core.util.DecimalValueCodec
import ru.dbotthepony.mc.otm.core.util.ItemSorter
import ru.dbotthepony.mc.otm.core.util.codec
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphListener
@ -168,6 +169,11 @@ class MatterPanelMenu @JvmOverloads constructor(
tasks.sortWith(actualTaskComparator)
})
val totalMatterStored: Decimal by mSynchronizer.ComputedField(
getter = { tile?.matterGraph?.getMatterStorageLevel() ?: Decimal.ZERO },
codec = DecimalValueCodec,
)
val changeIsAscending = booleanInput(allowSpectators = true) { tile?.getPlayerSettings(ply)?.ascending = it }
val changeSorting = PlayerInput(ItemSorter::class.codec(), allowSpectators = true) { tile?.getPlayerSettings(ply)?.sorter = it }