Move pattern monitor screen to Kotlin
This commit is contained in:
parent
519be9389e
commit
cc3e5f5550
@ -1,401 +0,0 @@
|
||||
package ru.dbotthepony.mc.otm.client.screen;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterTask;
|
||||
import ru.dbotthepony.mc.otm.capability.matter.PatternState;
|
||||
import ru.dbotthepony.mc.otm.menu.MatterPanelMenu;
|
||||
import ru.dbotthepony.mc.otm.menu.ReplicationRequestPacket;
|
||||
import ru.dbotthepony.mc.otm.network.MenuNetworkChannel;
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static ru.dbotthepony.mc.otm.core.UnOverengineeringKt.TextComponent;
|
||||
import static ru.dbotthepony.mc.otm.core.UnOverengineeringKt.TranslatableComponent;
|
||||
|
||||
public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
private static final int MODAL_WIDTH = 213;
|
||||
private static final int MODAL_HEIGHT = 110;
|
||||
|
||||
public MatterPanelScreen(MatterPanelMenu p_97741_, Inventory p_97742_, Component p_97743_) {
|
||||
super(p_97741_, p_97742_, p_97743_);
|
||||
|
||||
imageWidth = 176;
|
||||
imageHeight = 187;
|
||||
|
||||
titleLabelY = 5;
|
||||
}
|
||||
|
||||
public static final int GRID_WIDTH = 8;
|
||||
public static final int GRID_HEIGHT = 9;
|
||||
|
||||
private final ArrayList<AbstractSlotPanel> pattern_slots = new ArrayList<>();
|
||||
private final ArrayList<AbstractSlotPanel> task_slots = new ArrayList<>();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected FramePanel makeMainFrame() {
|
||||
float width = GRID_WIDTH * AbstractSlotPanel.SIZE + ScrollBarConstants.WIDTH + FramePanel.PADDING * 2 + 8;
|
||||
float height = GRID_HEIGHT * AbstractSlotPanel.SIZE + FramePanel.PADDING_TOP + FramePanel.PADDING;
|
||||
|
||||
var scroll_panel = new ContinuousScrollBarPanel(this, null, 0, 0, 0);
|
||||
|
||||
var frame = new FramePanel(this, null, 0, 0, width, height, getTitle()) {
|
||||
@Override
|
||||
protected boolean mouseScrolledInner(double x, double y, double scroll) {
|
||||
return scroll_panel.mouseScrolledInner(x, y, scroll);
|
||||
}
|
||||
};
|
||||
|
||||
var patterns_tab = frame.addTab(FramePanel.Position.TOP, () -> {
|
||||
for (var slot : pattern_slots) {
|
||||
slot.setVisible(true);
|
||||
}
|
||||
}, () -> {
|
||||
for (var slot : pattern_slots) {
|
||||
slot.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
var tasks_tab = frame.addTab(FramePanel.Position.TOP, () -> {
|
||||
for (var slot : task_slots) {
|
||||
slot.setVisible(true);
|
||||
}
|
||||
}, () -> {
|
||||
for (var slot : task_slots) {
|
||||
slot.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
scroll_panel.setParent(frame);
|
||||
scroll_panel.setDock(Dock.RIGHT);
|
||||
scroll_panel.setupRowMultiplier(() -> {
|
||||
if (tasks_tab.isActive()) {
|
||||
return menu.getTasks().size() / GRID_WIDTH;
|
||||
}
|
||||
|
||||
return menu.getPatterns().size() / GRID_WIDTH;
|
||||
});
|
||||
|
||||
var grid = new GridPanel(this, frame, 0, 0, GRID_WIDTH * AbstractSlotPanel.SIZE, 0, GRID_WIDTH, GRID_HEIGHT) {
|
||||
@Override
|
||||
protected boolean mouseScrolledInner(double x, double y, double scroll) {
|
||||
return scroll_panel.mouseScrolledInner(x, y, scroll);
|
||||
}
|
||||
};
|
||||
|
||||
grid.setDock(Dock.LEFT);
|
||||
grid.setDockMargin(4, 0, 0, 0);
|
||||
|
||||
for (int i = 0; i < GRID_WIDTH * GRID_HEIGHT; i++) {
|
||||
int slot = i;
|
||||
|
||||
pattern_slots.add(new AbstractSlotPanel(this, grid, 0, 0) {
|
||||
@Nonnull
|
||||
@Override
|
||||
protected ItemStack getItemStack() {
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.getPatterns().size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
|
||||
if (slot1 >= menu.getPatterns().size()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return menu.getPatterns().get(slot1).stack();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected List<Component> getItemStackTooltip(@Nonnull ItemStack stack) {
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.getPatterns().size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
|
||||
if (slot1 >= menu.getPatterns().size()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
return getPatternTooltip(super.getItemStackTooltip(stack), menu.getPatterns().get(slot1));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean mouseScrolledInner(double x, double y, double scroll) {
|
||||
return scroll_panel.mouseScrolledInner(x, y, scroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean mouseClickedInner(double x, double y, int flag) {
|
||||
if (slot >= menu.getPatterns().size()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
openPattern(menu.getPatterns().get(slot));
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
task_slots.add(new AbstractSlotPanel(this, grid, 0, 0) {
|
||||
@Nonnull
|
||||
@Override
|
||||
protected ItemStack getItemStack() {
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.getTasks().size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
|
||||
if (slot1 >= menu.getTasks().size()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
var task = menu.getTasks().get(slot1);
|
||||
return task.stack(Math.max(task.required(), 1));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected List<Component> getItemStackTooltip(@Nonnull ItemStack stack) {
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.getTasks().size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
|
||||
if (slot1 >= menu.getTasks().size()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
return getTaskTooltip(super.getItemStackTooltip(stack), menu.getTasks().get(slot1));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean mouseScrolledInner(double x, double y, double scroll) {
|
||||
return scroll_panel.mouseScrolledInner(x, y, scroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean mouseClickedInner(double x, double y, int flag) {
|
||||
if (slot >= menu.getTasks().size()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
openTask(menu.getTasks().get(slot));
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (var slot : task_slots) {
|
||||
slot.setVisible(false);
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
private List<Component> getTaskTooltip(List<Component> input, MatterTask task) {
|
||||
input.add(TranslatableComponent("otm.gui.matter_task.total", task.total()).withStyle(ChatFormatting.GRAY));
|
||||
input.add(TranslatableComponent("otm.gui.matter_task.required", task.required()).withStyle(ChatFormatting.GRAY));
|
||||
input.add(TranslatableComponent("otm.gui.matter_task.in_progress", task.in_progress()).withStyle(ChatFormatting.GRAY));
|
||||
input.add(TranslatableComponent("otm.gui.matter_task.finished", task.finished()).withStyle(ChatFormatting.GRAY));
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
private List<Component> getPatternTooltip(List<Component> input, PatternState pattern) {
|
||||
input.add(TranslatableComponent("otm.item.pattern.research", String.format("%.2f", pattern.research() * 100d)).withStyle(ChatFormatting.AQUA));
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
private void openTask(MatterTask task) {
|
||||
var task_frame = new FramePanel(this, null, 0, 0, 170, 40, TranslatableComponent("otm.container.matter_panel.task")) {
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (!menu.getTasks().contains(task)) {
|
||||
remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var slot = new AbstractSlotPanel(this, task_frame, 0, 0) {
|
||||
@Nonnull
|
||||
@Override
|
||||
protected ItemStack getItemStack() {
|
||||
var task1_index = menu.getTasks().indexOf(task);
|
||||
|
||||
if (task1_index != -1) {
|
||||
var task1 = menu.getTasks().get(task1_index);
|
||||
return task1.stack(Math.max(task1.required(), 1));
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected List<Component> getItemStackTooltip(@Nonnull ItemStack stack) {
|
||||
var task1_index = menu.getTasks().indexOf(task);
|
||||
List<Component> get_list = super.getItemStackTooltip(stack);
|
||||
|
||||
if (task1_index != -1) {
|
||||
getTaskTooltip(get_list, menu.getTasks().get(task1_index));
|
||||
}
|
||||
|
||||
return get_list;
|
||||
}
|
||||
};
|
||||
|
||||
slot.setDock(Dock.LEFT);
|
||||
|
||||
var button = new ButtonPanel(this, task_frame, 0, 0, 40, 20, TranslatableComponent("otm.container.matter_panel.close"));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
button.bind(task_frame::remove);
|
||||
|
||||
button = new ButtonPanel(this, task_frame, 0, 0, 80, 20, TranslatableComponent("otm.container.matter_panel.cancel_task"));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
button.bind(() -> {
|
||||
menu.requestTaskCancel(task.id());
|
||||
task_frame.remove();
|
||||
});
|
||||
|
||||
task_frame.toScreenCenter();
|
||||
addPanel(task_frame);
|
||||
}
|
||||
|
||||
private void openPattern(PatternState state) {
|
||||
var pattern_frame = new FramePanel(this, null, 0, 0, MODAL_WIDTH, MODAL_HEIGHT, TranslatableComponent("otm.container.matter_panel.label")){
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (!menu.getPatterns().contains(state)) {
|
||||
remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var row_1 = new EditablePanel(this, pattern_frame);
|
||||
var row_2 = new EditablePanel(this, pattern_frame);
|
||||
var row_3 = new EditablePanel(this, pattern_frame);
|
||||
var row_4 = new EditablePanel(this, pattern_frame);
|
||||
|
||||
row_1.setDock(Dock.TOP);
|
||||
row_2.setDock(Dock.TOP);
|
||||
row_3.setDock(Dock.TOP);
|
||||
row_4.setDock(Dock.TOP);
|
||||
|
||||
row_1.setHeight(20);
|
||||
row_2.setHeight(20);
|
||||
row_3.setHeight(20);
|
||||
row_4.setHeight(20);
|
||||
|
||||
row_1.setDockMargin(0, 2, 0, 0);
|
||||
row_2.setDockMargin(0, 2, 0, 0);
|
||||
row_3.setDockMargin(0, 2, 0, 0);
|
||||
row_4.setDockMargin(0, 2, 0, 0);
|
||||
|
||||
var slot = new AbstractSlotPanel(this, row_2, 0, 0) {
|
||||
@Nonnull
|
||||
@Override
|
||||
protected ItemStack getItemStack() {
|
||||
return new ItemStack(state.item(), 1);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected List<Component> getItemStackTooltip(@Nonnull ItemStack stack) {
|
||||
return getPatternTooltip(super.getItemStackTooltip(stack), state);
|
||||
}
|
||||
};
|
||||
|
||||
var input_amount = new EditBoxPanel(this, row_2, 0, 0, 10, 20, TextComponent("Input amount")) {
|
||||
@Override
|
||||
protected void configureNew(@Nonnull EditBox widget, boolean recreation) {
|
||||
super.configureNew(widget, recreation);
|
||||
|
||||
widget.setMaxLength(6);
|
||||
|
||||
if (!recreation) {
|
||||
widget.setValue("1");
|
||||
}
|
||||
}
|
||||
|
||||
private void increase(int amount) {
|
||||
int value = 1;
|
||||
|
||||
try {
|
||||
value = Integer.parseInt(getOrCreateWidget().getValue());
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
|
||||
if (value == 1 && amount > 0)
|
||||
getOrCreateWidget().setValue(Integer.toString(amount));
|
||||
else
|
||||
getOrCreateWidget().setValue(Integer.toString(Math.max(1, Math.min(99999, value + amount))));
|
||||
}
|
||||
};
|
||||
|
||||
var button = new ButtonPanel(this, row_1, 0, 0, 40, 20, TranslatableComponent("otm.container.matter_panel.increase_by", 8));
|
||||
button.bind(() -> input_amount.increase(8));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
|
||||
button = new ButtonPanel(this, row_1, 0, 0, 40, 20, TranslatableComponent("otm.container.matter_panel.increase_by", 64));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.bind(() -> input_amount.increase(64));
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
|
||||
button = new ButtonPanel(this, row_1, 0, 0, 40, 20, TranslatableComponent("otm.container.matter_panel.increase_by", 256));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.bind(() -> input_amount.increase(256));
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
|
||||
slot.setDock(Dock.LEFT);
|
||||
slot.setDockMargin(0, 0, 4, 0);
|
||||
input_amount.setDock(Dock.FILL);
|
||||
|
||||
button = new ButtonPanel(this, row_3, 0, 0, 40, 20, TranslatableComponent("otm.container.matter_panel.decrease_by", 8));
|
||||
button.bind(() -> input_amount.increase(-8));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
|
||||
button = new ButtonPanel(this, row_3, 0, 0, 40, 20, TranslatableComponent("otm.container.matter_panel.decrease_by", 64));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.bind(() -> input_amount.increase(-64));
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
|
||||
button = new ButtonPanel(this, row_3, 0, 0, 40, 20, TranslatableComponent("otm.container.matter_panel.decrease_by", 256));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.bind(() -> input_amount.increase(-256));
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
|
||||
button = new ButtonPanel(this, row_4, 0, 0, 40, 20, TranslatableComponent("otm.container.matter_panel.cancel"));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.bind(pattern_frame::remove);
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
|
||||
button = new ButtonPanel(this, row_4, 0, 0, 82, 20, TranslatableComponent("otm.container.matter_panel.send"));
|
||||
button.setDock(Dock.RIGHT);
|
||||
button.bind(() -> {
|
||||
int value = 1;
|
||||
|
||||
try {
|
||||
value = Integer.parseInt(input_amount.getOrCreateWidget().getValue());
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
|
||||
MenuNetworkChannel.INSTANCE.sendToServer(new ReplicationRequestPacket(state, value));
|
||||
pattern_frame.remove();
|
||||
});
|
||||
|
||||
button.setDockMargin(2, 0, 0, 0);
|
||||
|
||||
addPanel(pattern_frame);
|
||||
pattern_frame.toScreenCenter();
|
||||
popup(pattern_frame);
|
||||
}
|
||||
}
|
@ -0,0 +1,294 @@
|
||||
package ru.dbotthepony.mc.otm.client.screen
|
||||
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.client.gui.components.EditBox
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterTask
|
||||
import ru.dbotthepony.mc.otm.capability.matter.PatternState
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.core.maxScrollDivision
|
||||
import ru.dbotthepony.mc.otm.menu.MatterPanelMenu
|
||||
import ru.dbotthepony.mc.otm.menu.ReplicationRequestPacket
|
||||
import ru.dbotthepony.mc.otm.network.MenuNetworkChannel
|
||||
|
||||
class MatterPanelScreen(
|
||||
menu: MatterPanelMenu,
|
||||
inventory: Inventory,
|
||||
title: Component
|
||||
) : MatteryScreen<MatterPanelMenu>(menu, inventory, title) {
|
||||
override fun makeMainFrame(): FramePanel {
|
||||
var isPatternView = true
|
||||
|
||||
val frame = FramePanel.padded(this, null, GRID_WIDTH * AbstractSlotPanel.SIZE + ScrollBarConstants.WIDTH + 4f, GRID_HEIGHT * AbstractSlotPanel.SIZE, title)
|
||||
|
||||
val scrollBar = DiscreteScrollBarPanel(this, frame, {
|
||||
if (isPatternView) {
|
||||
maxScrollDivision(menu.patterns.size, GRID_WIDTH)
|
||||
} else {
|
||||
maxScrollDivision(menu.tasks.size, GRID_WIDTH)
|
||||
}
|
||||
}, { _, _, _ -> })
|
||||
|
||||
scrollBar.dock = Dock.RIGHT
|
||||
|
||||
frame.addTab(FramePanel.Position.TOP, open = { isPatternView = true })
|
||||
frame.addTab(FramePanel.Position.TOP, open = { isPatternView = false })
|
||||
|
||||
val canvas = object : EditablePanel(this@MatterPanelScreen, frame, width = GRID_WIDTH * AbstractSlotPanel.SIZE) {
|
||||
init {
|
||||
dock = Dock.LEFT
|
||||
}
|
||||
|
||||
override fun mouseScrolledInner(x: Double, y: Double, scroll: Double): Boolean {
|
||||
return scrollBar.mouseScrolledInner(x, y, scroll)
|
||||
}
|
||||
}
|
||||
|
||||
for (row in 0 until GRID_HEIGHT) {
|
||||
val rowCanvas = object : EditablePanel(this@MatterPanelScreen, canvas, height = AbstractSlotPanel.SIZE) {
|
||||
init {
|
||||
dock = Dock.TOP
|
||||
}
|
||||
|
||||
override fun mouseScrolledInner(x: Double, y: Double, scroll: Double): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for (i in 0 until GRID_WIDTH) {
|
||||
object : AbstractSlotPanel(this@MatterPanelScreen, rowCanvas) {
|
||||
init {
|
||||
dock = Dock.LEFT
|
||||
}
|
||||
|
||||
private val index: Int get() = (scrollBar.scroll + row) * GRID_WIDTH + i
|
||||
|
||||
override fun getItemStack(): ItemStack {
|
||||
if (isPatternView) {
|
||||
return menu.patterns.getOrNull(index)?.stack() ?: ItemStack.EMPTY
|
||||
} else {
|
||||
return menu.tasks.getOrNull(index)?.stack() ?: ItemStack.EMPTY
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemStackTooltip(stack: ItemStack): List<Component> {
|
||||
val list = super.getItemStackTooltip(stack).toMutableList()
|
||||
|
||||
if (isPatternView) {
|
||||
menu.patterns.getOrNull(index)?.let {
|
||||
list.add(TranslatableComponent(
|
||||
"otm.item.pattern.research",
|
||||
String.format("%.2f", it.research() * 100.0)
|
||||
).withStyle(ChatFormatting.AQUA)) }
|
||||
} else {
|
||||
menu.tasks.getOrNull(index)?.let {
|
||||
list.add(TranslatableComponent("otm.gui.matter_task.total", it.total()).withStyle(ChatFormatting.GRAY))
|
||||
list.add(TranslatableComponent("otm.gui.matter_task.required", it.required()).withStyle(ChatFormatting.GRAY))
|
||||
list.add(TranslatableComponent("otm.gui.matter_task.in_progress", it.in_progress()).withStyle(ChatFormatting.GRAY))
|
||||
list.add(TranslatableComponent("otm.gui.matter_task.finished", it.finished()).withStyle(ChatFormatting.GRAY))
|
||||
}
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||
if (isPatternView) {
|
||||
menu.patterns.getOrNull(index)?.let(this@MatterPanelScreen::openPattern)
|
||||
} else {
|
||||
menu.tasks.getOrNull(index)?.let(this@MatterPanelScreen::openTask)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun mouseScrolledInner(x: Double, y: Double, scroll: Double): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return frame
|
||||
}
|
||||
|
||||
private fun openTask(task: MatterTask) {
|
||||
val frame = FramePanel.padded(this, null, 170f, 20f, TranslatableComponent("otm.container.matter_panel.task"))
|
||||
|
||||
object : AbstractSlotPanel(this@MatterPanelScreen, frame) {
|
||||
init {
|
||||
dock = Dock.LEFT
|
||||
}
|
||||
|
||||
override fun getItemStack(): ItemStack {
|
||||
return menu.tasks.firstOrNull { it.id == task.id }?.let { it.stack(it.required.coerceAtLeast(1)) } ?: task.stack(task.required.coerceAtLeast(1))
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
super.tick()
|
||||
|
||||
if (!menu.tasks.any { it.id == task.id }) {
|
||||
frame.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ButtonPanel(this@MatterPanelScreen, frame, width = 40f, label = TranslatableComponent("otm.container.matter_panel.close"), onPress = frame::remove).also {
|
||||
it.dock = Dock.RIGHT
|
||||
it.dockLeft = 2f
|
||||
}
|
||||
|
||||
ButtonPanel(this@MatterPanelScreen, frame, width = 80f, label = TranslatableComponent("otm.container.matter_panel.cancel_task"), onPress = {
|
||||
menu.requestTaskCancel(task.id)
|
||||
frame.remove()
|
||||
}).also {
|
||||
it.dock = Dock.RIGHT
|
||||
it.dockLeft = 2f
|
||||
}
|
||||
|
||||
addPanel(frame)
|
||||
popup(frame)
|
||||
|
||||
frame.toScreenCenter()
|
||||
}
|
||||
|
||||
private fun openPattern(pattern: PatternState) {
|
||||
val frame = FramePanel.padded(this, null, 213f, (ButtonPanel.HEIGHT + 3f) * 4f, TranslatableComponent("otm.container.matter_panel.task"))
|
||||
|
||||
val rowTop = EditablePanel(this, frame, height = ButtonPanel.HEIGHT)
|
||||
val rowInput = EditablePanel(this, frame, height = ButtonPanel.HEIGHT)
|
||||
val rowBottom = EditablePanel(this, frame, height = ButtonPanel.HEIGHT)
|
||||
val rowControls = EditablePanel(this, frame, height = ButtonPanel.HEIGHT)
|
||||
|
||||
rowTop.dock = Dock.TOP
|
||||
rowTop.dockTop = 3f
|
||||
rowInput.dock = Dock.TOP
|
||||
rowInput.dockTop = 3f
|
||||
rowBottom.dock = Dock.TOP
|
||||
rowBottom.dockTop = 3f
|
||||
rowControls.dock = Dock.TOP
|
||||
rowControls.dockTop = 3f
|
||||
|
||||
object : AbstractSlotPanel(this@MatterPanelScreen, rowInput) {
|
||||
init {
|
||||
dock = Dock.LEFT
|
||||
dockRight = 2f
|
||||
}
|
||||
|
||||
override fun getItemStack(): ItemStack {
|
||||
return pattern.stack()
|
||||
}
|
||||
|
||||
override fun getItemStackTooltip(stack: ItemStack): List<Component> {
|
||||
return super.getItemStackTooltip(stack).toMutableList().also {
|
||||
it.add(TranslatableComponent(
|
||||
"otm.item.pattern.research",
|
||||
String.format("%.2f", pattern.research() * 100.0)
|
||||
).withStyle(ChatFormatting.AQUA))
|
||||
}
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
super.tick()
|
||||
|
||||
if (!menu.patterns.any { it.id == pattern.id }) {
|
||||
frame.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val input = object : EditBoxPanel(this@MatterPanelScreen, rowInput) {
|
||||
init {
|
||||
dock = Dock.FILL
|
||||
}
|
||||
|
||||
override fun configureNew(widget: EditBox, recreation: Boolean) {
|
||||
super.configureNew(widget, recreation)
|
||||
widget.setMaxLength(6)
|
||||
|
||||
if (!recreation) {
|
||||
widget.value = "1"
|
||||
}
|
||||
}
|
||||
|
||||
fun increase(amount: Int) {
|
||||
var value = 1
|
||||
|
||||
try {
|
||||
value = getOrCreateWidget().value.toInt()
|
||||
} catch (_: NumberFormatException) {
|
||||
}
|
||||
|
||||
if (value == 1 && amount > 0)
|
||||
getOrCreateWidget().value = amount.toString()
|
||||
else
|
||||
getOrCreateWidget().value = 1.coerceAtLeast(99999.coerceAtMost(value + amount)).toString()
|
||||
}
|
||||
|
||||
fun send() {
|
||||
var value = 1
|
||||
|
||||
try {
|
||||
value = getOrCreateWidget().value.toInt()
|
||||
} catch (_: NumberFormatException) {
|
||||
}
|
||||
|
||||
MenuNetworkChannel.sendToServer(ReplicationRequestPacket(pattern, value))
|
||||
frame.remove()
|
||||
}
|
||||
}
|
||||
|
||||
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 8), onPress = { 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 = { 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 = { 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 = { 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 = { 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 = { 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 {
|
||||
it.dock = Dock.RIGHT
|
||||
it.dockLeft = 2f
|
||||
}
|
||||
|
||||
ButtonPanel(this, rowControls, width = 82f, label = TranslatableComponent("otm.container.matter_panel.send"), onPress = input::send).also {
|
||||
it.dock = Dock.RIGHT
|
||||
it.dockLeft = 2f
|
||||
}
|
||||
|
||||
addPanel(frame)
|
||||
popup(frame)
|
||||
|
||||
frame.toScreenCenter()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val GRID_HEIGHT = 8
|
||||
const val GRID_WIDTH = 9
|
||||
}
|
||||
}
|
@ -24,10 +24,22 @@ open class ButtonPanel(
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 40f,
|
||||
height: Float = 20f,
|
||||
height: Float = HEIGHT,
|
||||
label: Component
|
||||
) : MinecraftWidgetPanel<Button>(screen, parent, x, y, width, height) {
|
||||
constructor(screen: MatteryScreen<*>, parent: EditablePanel?, label: Component) : this(screen, parent, x = 0f, label = label)
|
||||
constructor(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel?,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 40f,
|
||||
height: Float = HEIGHT,
|
||||
label: Component,
|
||||
onPress: Runnable
|
||||
) : this(screen, parent, x, y, width, height, label) {
|
||||
this.callback = onPress
|
||||
}
|
||||
|
||||
var label = label
|
||||
set(value) {
|
||||
@ -55,6 +67,10 @@ open class ButtonPanel(
|
||||
protected open fun onPress() {
|
||||
callback?.run()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val HEIGHT = 20f
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("PropertyName")
|
||||
|
@ -171,8 +171,8 @@ open class FramePanel(
|
||||
protected val tabsBottom = ArrayList<FrameTabPanel>()
|
||||
|
||||
@JvmOverloads
|
||||
fun addTab(position: Position, on_open: Runnable? = null, on_close: Runnable? = null): FrameTabPanel {
|
||||
val tab = FrameTabPanel(position, on_open, on_close)
|
||||
fun addTab(position: Position, open: Runnable? = null, close: Runnable? = null): FrameTabPanel {
|
||||
val tab = FrameTabPanel(position, open, close)
|
||||
doAddTab(tab)
|
||||
return tab
|
||||
}
|
||||
@ -257,6 +257,24 @@ open class FramePanel(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun padded(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel?,
|
||||
x: Float,
|
||||
y: Float,
|
||||
width: Float,
|
||||
height: Float,
|
||||
title: Component
|
||||
) = FramePanel(screen, parent, x, y, width + PADDING * 2, height + PADDING_TOP + PADDING, title)
|
||||
|
||||
fun padded(
|
||||
screen: MatteryScreen<*>,
|
||||
parent: EditablePanel?,
|
||||
width: Float,
|
||||
height: Float,
|
||||
title: Component
|
||||
) = FramePanel(screen, parent, 0f, 0f, width + PADDING * 2, height + PADDING_TOP + PADDING, title)
|
||||
|
||||
const val PADDING = 8f
|
||||
const val PADDING_TOP = 14f
|
||||
|
||||
|
@ -125,6 +125,12 @@ class ReplicationRequestPacket(val state: PatternState, amount: Int) : MatteryPa
|
||||
menu.requestReplication(sender, state, amount)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(buff: FriendlyByteBuf): ReplicationRequestPacket {
|
||||
return ReplicationRequestPacket(PatternState.read(buff)!!, buff.readInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MatterPanelMenu @JvmOverloads constructor(
|
||||
|
@ -8,10 +8,7 @@ import net.minecraftforge.network.NetworkEvent
|
||||
import ru.dbotthepony.mc.otm.block.entity.storage.ItemMonitorPlayerSettings
|
||||
import ru.dbotthepony.mc.otm.client.minecraft
|
||||
import ru.dbotthepony.mc.otm.container.ItemFilterSlotPacket
|
||||
import ru.dbotthepony.mc.otm.menu.CancelTaskPacket
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.menu.PatternsChangePacket
|
||||
import ru.dbotthepony.mc.otm.menu.TasksChangePacket
|
||||
import ru.dbotthepony.mc.otm.menu.*
|
||||
import ru.dbotthepony.mc.otm.menu.data.*
|
||||
import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputPacket
|
||||
import ru.dbotthepony.mc.otm.menu.widget.NumberPlayerInputPacket
|
||||
@ -90,5 +87,6 @@ object MenuNetworkChannel : MatteryNetworkChannel(
|
||||
add(CancelTaskPacket::class.java, CancelTaskPacket.Companion::read, NetworkDirection.PLAY_TO_SERVER)
|
||||
add(PatternsChangePacket::class.java, PatternsChangePacket.Companion::read, NetworkDirection.PLAY_TO_CLIENT)
|
||||
add(TasksChangePacket::class.java, TasksChangePacket.Companion::read, NetworkDirection.PLAY_TO_CLIENT)
|
||||
add(ReplicationRequestPacket::class.java, ReplicationRequestPacket.Companion::read, NetworkDirection.PLAY_TO_SERVER)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user