FlexGridPanel test

This commit is contained in:
DBotThePony 2021-08-23 17:47:17 +07:00
parent 68c4f83fc6
commit ae7629548a
Signed by: DBot
GPG Key ID: DCC23B5715498507
22 changed files with 424 additions and 85 deletions

View File

@ -20,9 +20,10 @@ public class BatteryBankMenu extends MatteryMenu {
protected BlockEntityBatteryBank tile; protected BlockEntityBatteryBank tile;
public BatteryLevelWidget battery_widget; public BatteryLevelWidget battery_widget;
public BatterySlot[] battery_slots = new BatterySlot[6 * 2];
public BatteryBankMenu(int p_38852_, Inventory inventory) { public BatteryBankMenu(int p_38852_, Inventory inventory) {
this(p_38852_, inventory, null, new SimpleContainer(5 * 3)); this(p_38852_, inventory, null, new SimpleContainer(6 * 2));
} }
public BatteryBankMenu(int p_38852_, Inventory inventory, BlockEntityBatteryBank tile, Container batteries) { public BatteryBankMenu(int p_38852_, Inventory inventory, BlockEntityBatteryBank tile, Container batteries) {
@ -35,9 +36,12 @@ public class BatteryBankMenu extends MatteryMenu {
battery_widget = new BatteryLevelWidget(this, 13, 24, tile.getCapability(MatteryCapability.ENERGY).resolve().get()); battery_widget = new BatteryLevelWidget(this, 13, 24, tile.getCapability(MatteryCapability.ENERGY).resolve().get());
} }
for (int row = 0; row < 2; row++) for (int row = 0; row < 2; row++) {
for (int column = 0; column < 6; column++) for (int column = 0; column < 6; column++) {
addMainSlot(new BatterySlot(batteries, row * 6 + column, 44 + column * 18, 24 + row * 18)); battery_slots[row * 6 + column] = new BatterySlot(batteries, row * 6 + column, 44 + column * 18, 24 + row * 18);
addSlot(battery_slots[row * 6 + column]);
}
}
addInventorySlots(); addInventorySlots();
} }
@ -49,6 +53,6 @@ public class BatteryBankMenu extends MatteryMenu {
@Override @Override
protected int getWorkingSlotEnd() { protected int getWorkingSlotEnd() {
return 5 * 3; return 6 * 2;
} }
} }

View File

@ -16,6 +16,8 @@ public class MatterCapacitorBankMenu extends MatteryMenu {
public MatterLevelWidget matter; public MatterLevelWidget matter;
public MatterContainerInputSlot[] container_slots = new MatterContainerInputSlot[2 * 6];
public MatterCapacitorBankMenu(int p_38852_, Inventory inventory, BlockEntityMatterCapacitorBank tile) { public MatterCapacitorBankMenu(int p_38852_, Inventory inventory, BlockEntityMatterCapacitorBank tile) {
super(Registry.Menus.MATTER_CAPACITOR_BANK, p_38852_, inventory, tile); super(Registry.Menus.MATTER_CAPACITOR_BANK, p_38852_, inventory, tile);
@ -25,11 +27,14 @@ public class MatterCapacitorBankMenu extends MatteryMenu {
matter = new MatterLevelWidget(this, 14, 20, tile.matter); matter = new MatterLevelWidget(this, 14, 20, tile.matter);
} }
Container container = tile != null ? tile.matter_container : new SimpleContainer(5 * 3); Container container = tile != null ? tile.matter_container : new SimpleContainer(2 * 6);
for (int row = 0; row < 2; row++) for (int row = 0; row < 2; row++){
for (int column = 0; column < 6; column++) for (int column = 0; column < 6; column++) {
addMainSlot(new MatterContainerInputSlot(container, row * 6 + column, 44 + column * 18, 20 + row * 18, true, IMatterHandler.MatterDirection.BIDIRECTIONAL)); container_slots[row * 6 + column] = new MatterContainerInputSlot(container, row * 6 + column, 44 + column * 18, 20 + row * 18, true, IMatterHandler.MatterDirection.BIDIRECTIONAL);
addSlot(container_slots[row * 6 + column]);
}
}
addInventorySlots(); addInventorySlots();
} }
@ -41,6 +46,6 @@ public class MatterCapacitorBankMenu extends MatteryMenu {
@Override @Override
protected int getWorkingSlotEnd() { protected int getWorkingSlotEnd() {
return 16; return 2 * 6;
} }
} }

View File

@ -20,29 +20,38 @@ public class MatterDecomposerMenu extends PoweredMatteryMenu {
this(containerID, inventory, null); this(containerID, inventory, null);
} }
public MatterySlot input;
public MachineOutputSlot output;
public ProgressGaugeWidget progress;
public MatterDecomposerMenu(int containerID, Inventory inventory, @Nullable BlockEntityMatterDecomposer tile) { public MatterDecomposerMenu(int containerID, Inventory inventory, @Nullable BlockEntityMatterDecomposer tile) {
super(Registry.Menus.MATTER_DECOMPOSER, containerID, inventory, tile); super(Registry.Menus.MATTER_DECOMPOSER, containerID, inventory, tile);
Container container = tile != null ? tile.item_container : new SimpleContainer(2); Container container = tile != null ? tile.item_container : new SimpleContainer(2);
// Вход // Вход
addMainSlot(new MatterySlot(container, 0, 61, 36) { input = new MatterySlot(container, 0, 61, 36) {
@Override @Override
public boolean mayPlace(ItemStack p_40231_) { public boolean mayPlace(ItemStack p_40231_) {
return MatterRegistry.hasMatterValue(p_40231_); return MatterRegistry.hasMatterValue(p_40231_);
} }
}); };
addSlot(input);
// Выход // Выход
addMainSlot(new MachineOutputSlot(container, 1, 61 + 18 + 10 + 3 + 22, 36, true, true)); output = new MachineOutputSlot(container, 1, 61 + 18 + 10 + 3 + 22, 36, true);
addSlot(output);
if (tile == null || tile.getCapability(MatteryCapability.MATTER).resolve().isEmpty()) { if (tile == null || tile.getCapability(MatteryCapability.MATTER).resolve().isEmpty()) {
new MatterLevelWidget(this, 22, 14); new MatterLevelWidget(this, 22, 14);
new ProgressGaugeWidget(this, 61 + 18 + 3, 36); progress = new ProgressGaugeWidget(this, 61 + 18 + 3, 36);
} else { } else {
new MatterLevelWidget(this, 22, 14, tile.getCapability(MatteryCapability.MATTER).resolve().get()); new MatterLevelWidget(this, 22, 14, tile.getCapability(MatteryCapability.MATTER).resolve().get());
new ProgressGaugeWidget(this, 61 + 18 + 3, 36, () -> (float) tile.getWorkProgress(), tile::cantProcessJob); progress = new ProgressGaugeWidget(this, 61 + 18 + 3, 36, () -> (float) tile.getWorkProgress(), tile::cantProcessJob);
} }
progress.noAutoParent();
addBatterySlot(14); addBatterySlot(14);
addInventorySlots(); addInventorySlots();
} }

View File

@ -14,22 +14,29 @@ public class MatterReplicatorMenu extends PoweredMatteryMenu {
this(p_38852_, inventory, null); this(p_38852_, inventory, null);
} }
public ProgressGaugeWidget progress;
public MachineOutputSlot[] output_slots = new MachineOutputSlot[3];
public MatterReplicatorMenu(int p_38852_, Inventory inventory, BlockEntityMatterReplicator tile) { public MatterReplicatorMenu(int p_38852_, Inventory inventory, BlockEntityMatterReplicator tile) {
super(Registry.Menus.MATTER_REPLICATOR, p_38852_, inventory, tile); super(Registry.Menus.MATTER_REPLICATOR, p_38852_, inventory, tile);
Container container = tile != null ? tile.regular_slots : new SimpleContainer(3); Container container = tile != null ? tile.regular_slots : new SimpleContainer(3);
for (int i = 0; i < container.getContainerSize(); i++) for (int i = 0; i < container.getContainerSize(); i++) {
addMainSlot(new MachineOutputSlot(container, i, 64 + 18 * i, 38, true, false)); output_slots[i] = new MachineOutputSlot(container, i, 64 + 18 * i, 38, true);
addSlot(output_slots[i]);
}
if (tile != null) { if (tile != null) {
new MatterLevelWidget(this, 22, 14, tile.matter); new MatterLevelWidget(this, 22, 14, tile.matter);
new ProgressGaugeWidget(this, 38, 38, () -> (float) tile.getWorkProgress(), tile::cantProcessJob); progress = new ProgressGaugeWidget(this, 38, 38, () -> (float) tile.getWorkProgress(), tile::cantProcessJob);
} else { } else {
new MatterLevelWidget(this, 22, 14); new MatterLevelWidget(this, 22, 14);
new ProgressGaugeWidget(this, 38, 38); progress = new ProgressGaugeWidget(this, 38, 38);
} }
progress.noAutoParent();
addBatterySlot(14); addBatterySlot(14);
addInventorySlots(); addInventorySlots();
} }

View File

@ -15,24 +15,31 @@ public class MatterScannerMenu extends PoweredMatteryMenu {
this(p_38852_, inventory, null); this(p_38852_, inventory, null);
} }
public MatterySlot input;
public ProgressGaugeWidget progress;
public MatterScannerMenu(int p_38852_, Inventory inventory, BlockEntityMatterScanner tile) { public MatterScannerMenu(int p_38852_, Inventory inventory, BlockEntityMatterScanner tile) {
super(Registry.Menus.MATTER_SCANNER, p_38852_, inventory, tile); super(Registry.Menus.MATTER_SCANNER, p_38852_, inventory, tile);
Container container = tile != null ? tile.input_slot : new SimpleContainer(1); Container container = tile != null ? tile.input_slot : new SimpleContainer(1);
addMainSlot(new MatterySlot(container, 0, 64, 38) { input = new MatterySlot(container, 0, 64, 38) {
@Override @Override
public boolean mayPlace(ItemStack p_40231_) { public boolean mayPlace(ItemStack p_40231_) {
return MatterRegistry.hasMatterValue(p_40231_); return MatterRegistry.hasMatterValue(p_40231_);
} }
}); };
addSlot(input);
if (tile != null) { if (tile != null) {
new ProgressGaugeWidget(this, 88, 38, () -> (float) tile.getWorkProgress(), tile::cantProcessJob); progress = new ProgressGaugeWidget(this, 88, 38, () -> (float) tile.getWorkProgress(), tile::cantProcessJob);
} else { } else {
new ProgressGaugeWidget(this, 88, 38); progress = new ProgressGaugeWidget(this, 88, 38);
} }
progress.noAutoParent();
addBatterySlot(); addBatterySlot();
addInventorySlots(); addInventorySlots();

View File

@ -12,14 +12,19 @@ public class PatternStorageMenu extends MatteryMenu {
this(p_38852_, inventory, null); this(p_38852_, inventory, null);
} }
public PatternSlot[] pattern_slots = new PatternSlot[2 * 4];
public PatternStorageMenu(int p_38852_, Inventory inventory, BlockEntityPatternStorage tile) { public PatternStorageMenu(int p_38852_, Inventory inventory, BlockEntityPatternStorage tile) {
super(Registry.Menus.PATTERN_STORAGE, p_38852_, inventory, tile); super(Registry.Menus.PATTERN_STORAGE, p_38852_, inventory, tile);
Container patterns = tile != null ? tile.patterns : new SimpleContainer(3 * 3); Container patterns = tile != null ? tile.patterns : new SimpleContainer(2 * 4);
for (int row = 0; row < 2; row++) for (int row = 0; row < 2; row++) {
for (int column = 0; column < 4; column++) for (int column = 0; column < 4; column++) {
addMainSlot(new PatternSlot(patterns, row * 4 + column, 48 + column * 20, 27 + row * 24)); pattern_slots[row * 4 + column] = new PatternSlot(patterns, row * 4 + column, 48 + column * 20, 27 + row * 24);
addSlot(pattern_slots[row * 4 + column]);
}
}
addInventorySlots(); addInventorySlots();
} }
@ -31,6 +36,6 @@ public class PatternStorageMenu extends MatteryMenu {
@Override @Override
protected int getWorkingSlotEnd() { protected int getWorkingSlotEnd() {
return 3 * 3; return 2 * 4;
} }
} }

View File

@ -6,16 +6,14 @@ import net.minecraft.world.item.ItemStack;
public class MachineOutputSlot extends MatterySlot { public class MachineOutputSlot extends MatterySlot {
public boolean auto_bg; public boolean auto_bg;
public boolean is_main_output;
public MachineOutputSlot(Container p_40223_, int index, int x, int y, boolean auto_bg, boolean is_main_output) { public MachineOutputSlot(Container p_40223_, int index, int x, int y, boolean auto_bg) {
super(p_40223_, index, x, y); super(p_40223_, index, x, y);
this.is_main_output = is_main_output;
this.auto_bg = auto_bg; this.auto_bg = auto_bg;
} }
public MachineOutputSlot(Container p_40223_, int index, int x, int y) { public MachineOutputSlot(Container p_40223_, int index, int x, int y) {
this(p_40223_, index, x, y, true, false); this(p_40223_, index, x, y, true);
} }
@Override @Override

View File

@ -29,6 +29,8 @@ public abstract class AbstractWidget {
public int y; public int y;
protected Consumer<ContainerData> register_data; protected Consumer<ContainerData> register_data;
public boolean auto_parent = true;
public abstract int getImageWidth(); public abstract int getImageWidth();
public abstract int getImageHeight(); public abstract int getImageHeight();
@ -42,6 +44,11 @@ public abstract class AbstractWidget {
menu.addWidget(this, (consumer) -> register_data = consumer); menu.addWidget(this, (consumer) -> register_data = consumer);
} }
public AbstractWidget noAutoParent() {
auto_parent = false;
return this;
}
protected void addDataSlots(ContainerData slots) { protected void addDataSlots(ContainerData slots) {
register_data.accept(slots); register_data.accept(slots);
} }

View File

@ -113,7 +113,7 @@ public class AndroidStationScreen extends MatteryScreen<AndroidStationMenu> {
} }
}); });
grid.setDocking(Dock.RIGHT); grid.setDock(Dock.RIGHT);
return frame; return frame;
} }

View File

@ -8,9 +8,30 @@ import ru.dbotthepony.mc.otm.OverdriveThatMatters;
import ru.dbotthepony.mc.otm.menu.AndroidStationMenu; import ru.dbotthepony.mc.otm.menu.AndroidStationMenu;
import ru.dbotthepony.mc.otm.menu.BatteryBankMenu; import ru.dbotthepony.mc.otm.menu.BatteryBankMenu;
import ru.dbotthepony.mc.otm.menu.MatteryMenu; import ru.dbotthepony.mc.otm.menu.MatteryMenu;
import ru.dbotthepony.mc.otm.screen.panels.Dock;
import ru.dbotthepony.mc.otm.screen.panels.FlexGridPanel;
import ru.dbotthepony.mc.otm.screen.panels.FramePanel;
import ru.dbotthepony.mc.otm.screen.panels.SlotPanel;
import javax.annotation.Nullable;
public class BatteryBankScreen extends MatteryScreen<BatteryBankMenu> { public class BatteryBankScreen extends MatteryScreen<BatteryBankMenu> {
public BatteryBankScreen(BatteryBankMenu p_97741_, Inventory p_97742_, Component p_97743_) { public BatteryBankScreen(BatteryBankMenu p_97741_, Inventory p_97742_, Component p_97743_) {
super(p_97741_, p_97742_, p_97743_); super(p_97741_, p_97742_, p_97743_);
} }
@Nullable
@Override
protected FramePanel makeMainFrame() {
var frame = super.makeMainFrame();
var grid = new FlexGridPanel(this, frame, 0, 0, 0, 0);
grid.setDock(Dock.FILL);
for (var slot : menu.battery_slots) {
new SlotPanel(this, grid, 0, 0, slot);
}
return frame;
}
} }

View File

@ -3,9 +3,27 @@ package ru.dbotthepony.mc.otm.screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import ru.dbotthepony.mc.otm.menu.MatterCapacitorBankMenu; import ru.dbotthepony.mc.otm.menu.MatterCapacitorBankMenu;
import ru.dbotthepony.mc.otm.screen.panels.*;
import javax.annotation.Nullable;
public class MatterCapacitorBankScreen extends MatteryScreen<MatterCapacitorBankMenu> { public class MatterCapacitorBankScreen extends MatteryScreen<MatterCapacitorBankMenu> {
public MatterCapacitorBankScreen(MatterCapacitorBankMenu p_97741_, Inventory p_97742_, Component p_97743_) { public MatterCapacitorBankScreen(MatterCapacitorBankMenu p_97741_, Inventory p_97742_, Component p_97743_) {
super(p_97741_, p_97742_, p_97743_); super(p_97741_, p_97742_, p_97743_);
} }
@Nullable
@Override
protected FramePanel makeMainFrame() {
var frame = super.makeMainFrame();
var grid = new FlexGridPanel(this, frame, 0, 0, 0, 0);
grid.setDock(Dock.FILL);
for (var slot : menu.container_slots) {
new SlotPanel(this, grid, 0, 0, slot);
}
return frame;
}
} }

View File

@ -4,9 +4,28 @@ import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import ru.dbotthepony.mc.otm.menu.MatterDecomposerMenu; import ru.dbotthepony.mc.otm.menu.MatterDecomposerMenu;
import ru.dbotthepony.mc.otm.screen.panels.*;
import javax.annotation.Nullable;
public class MatterDecomposerScreen extends MatteryScreen<MatterDecomposerMenu> { public class MatterDecomposerScreen extends MatteryScreen<MatterDecomposerMenu> {
public MatterDecomposerScreen(MatterDecomposerMenu p_97741_, Inventory p_97742_, Component p_97743_) { public MatterDecomposerScreen(MatterDecomposerMenu p_97741_, Inventory p_97742_, Component p_97743_) {
super(p_97741_, p_97742_, p_97743_); super(p_97741_, p_97742_, p_97743_);
} }
@Nullable
@Override
protected FramePanel makeMainFrame() {
var frame = super.makeMainFrame();
var grid = new FlexGridPanel(this, frame, 0, 0, 0, 0);
grid.setDock(Dock.FILL);
grid.setDockPadding(0, 0, 40, 12);
new SlotPanel(this, grid, 0, 0, menu.input).setDockMargin(2, 0, 2, 0);
new MatteryWidgetPanel(this, grid, menu.progress).setDockMargin(2, 0, 2, 0);
new SlotPanel(this, grid, 0, 0, menu.output).setDockMargin(2, 0, 2, 0);
return frame;
}
} }

View File

@ -1,21 +1,13 @@
package ru.dbotthepony.mc.otm.screen; package ru.dbotthepony.mc.otm.screen;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import ru.dbotthepony.mc.otm.OverdriveThatMatters; import ru.dbotthepony.mc.otm.OverdriveThatMatters;
import ru.dbotthepony.mc.otm.capability.MatterTask; import ru.dbotthepony.mc.otm.capability.MatterTask;
import ru.dbotthepony.mc.otm.capability.PatternState; import ru.dbotthepony.mc.otm.capability.PatternState;
@ -28,10 +20,6 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
import static org.lwjgl.opengl.GL11.GL_ALWAYS;
import static org.lwjgl.opengl.GL11.GL_LESS;
public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> { public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
private static final int MODAL_WIDTH = 213; private static final int MODAL_WIDTH = 213;
@ -94,7 +82,7 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
}); });
scroll_panel.setParent(frame); scroll_panel.setParent(frame);
scroll_panel.setDocking(Dock.RIGHT); scroll_panel.setDock(Dock.RIGHT);
scroll_panel.setupRowMultiplier(() -> { scroll_panel.setupRowMultiplier(() -> {
if (tasks_tab.isActive()) { if (tasks_tab.isActive()) {
return menu.tasks.size() / GRID_WIDTH; return menu.tasks.size() / GRID_WIDTH;
@ -110,7 +98,7 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
} }
}; };
grid.setDocking(Dock.LEFT); grid.setDock(Dock.LEFT);
grid.setDockMargin(4, 0, 0, 0); grid.setDockMargin(4, 0, 0, 0);
for (int i = 0; i < GRID_WIDTH * GRID_HEIGHT; i++) { for (int i = 0; i < GRID_WIDTH * GRID_HEIGHT; i++) {
@ -261,15 +249,15 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
} }
}; };
slot.setDocking(Dock.LEFT); slot.setDock(Dock.LEFT);
var button = new ButtonPanel(this, task_frame, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.close")); var button = new ButtonPanel(this, task_frame, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.close"));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.setDockMargin(2, 0, 0, 0); button.setDockMargin(2, 0, 0, 0);
button.bindOnPress(task_frame::remove); button.bindOnPress(task_frame::remove);
button = new ButtonPanel(this, task_frame, 0, 0, 80, 20, new TranslatableComponent("otm.container.matter_panel.cancel_task")); button = new ButtonPanel(this, task_frame, 0, 0, 80, 20, new TranslatableComponent("otm.container.matter_panel.cancel_task"));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.setDockMargin(2, 0, 0, 0); button.setDockMargin(2, 0, 0, 0);
button.bindOnPress(() -> { button.bindOnPress(() -> {
menu.requestTaskCancel(task.id()); menu.requestTaskCancel(task.id());
@ -297,10 +285,10 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
var row_3 = new EditablePanel(this, pattern_frame); var row_3 = new EditablePanel(this, pattern_frame);
var row_4 = new EditablePanel(this, pattern_frame); var row_4 = new EditablePanel(this, pattern_frame);
row_1.setDocking(Dock.TOP); row_1.setDock(Dock.TOP);
row_2.setDocking(Dock.TOP); row_2.setDock(Dock.TOP);
row_3.setDocking(Dock.TOP); row_3.setDock(Dock.TOP);
row_4.setDocking(Dock.TOP); row_4.setDock(Dock.TOP);
row_1.setHeight(20); row_1.setHeight(20);
row_2.setHeight(20); row_2.setHeight(20);
@ -355,45 +343,45 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
var button = new ButtonPanel(this, row_1, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.increase_by", 8)); var button = new ButtonPanel(this, row_1, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.increase_by", 8));
button.bindOnPress(() -> input_amount.increase(8)); button.bindOnPress(() -> input_amount.increase(8));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.setDockMargin(2, 0, 0, 0); button.setDockMargin(2, 0, 0, 0);
button = new ButtonPanel(this, row_1, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.increase_by", 64)); button = new ButtonPanel(this, row_1, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.increase_by", 64));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.bindOnPress(() -> input_amount.increase(64)); button.bindOnPress(() -> input_amount.increase(64));
button.setDockMargin(2, 0, 0, 0); button.setDockMargin(2, 0, 0, 0);
button = new ButtonPanel(this, row_1, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.increase_by", 256)); button = new ButtonPanel(this, row_1, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.increase_by", 256));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.bindOnPress(() -> input_amount.increase(256)); button.bindOnPress(() -> input_amount.increase(256));
button.setDockMargin(2, 0, 0, 0); button.setDockMargin(2, 0, 0, 0);
slot.setDocking(Dock.LEFT); slot.setDock(Dock.LEFT);
slot.setDockMargin(0, 0, 4, 0); slot.setDockMargin(0, 0, 4, 0);
input_amount.setDocking(Dock.FILL); input_amount.setDock(Dock.FILL);
button = new ButtonPanel(this, row_3, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.decrease_by", 8)); button = new ButtonPanel(this, row_3, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.decrease_by", 8));
button.bindOnPress(() -> input_amount.increase(-8)); button.bindOnPress(() -> input_amount.increase(-8));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.setDockMargin(2, 0, 0, 0); button.setDockMargin(2, 0, 0, 0);
button = new ButtonPanel(this, row_3, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.decrease_by", 64)); button = new ButtonPanel(this, row_3, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.decrease_by", 64));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.bindOnPress(() -> input_amount.increase(-64)); button.bindOnPress(() -> input_amount.increase(-64));
button.setDockMargin(2, 0, 0, 0); button.setDockMargin(2, 0, 0, 0);
button = new ButtonPanel(this, row_3, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.decrease_by", 256)); button = new ButtonPanel(this, row_3, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.decrease_by", 256));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.bindOnPress(() -> input_amount.increase(-256)); button.bindOnPress(() -> input_amount.increase(-256));
button.setDockMargin(2, 0, 0, 0); button.setDockMargin(2, 0, 0, 0);
button = new ButtonPanel(this, row_4, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.cancel")); button = new ButtonPanel(this, row_4, 0, 0, 40, 20, new TranslatableComponent("otm.container.matter_panel.cancel"));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.bindOnPress(pattern_frame::remove); button.bindOnPress(pattern_frame::remove);
button.setDockMargin(2, 0, 0, 0); button.setDockMargin(2, 0, 0, 0);
button = new ButtonPanel(this, row_4, 0, 0, 82, 20, new TranslatableComponent("otm.container.matter_panel.send")); button = new ButtonPanel(this, row_4, 0, 0, 82, 20, new TranslatableComponent("otm.container.matter_panel.send"));
button.setDocking(Dock.RIGHT); button.setDock(Dock.RIGHT);
button.bindOnPress(() -> { button.bindOnPress(() -> {
int value = 1; int value = 1;

View File

@ -3,9 +3,30 @@ package ru.dbotthepony.mc.otm.screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import ru.dbotthepony.mc.otm.menu.MatterReplicatorMenu; import ru.dbotthepony.mc.otm.menu.MatterReplicatorMenu;
import ru.dbotthepony.mc.otm.screen.panels.*;
import javax.annotation.Nullable;
public class MatterReplicatorScreen extends MatteryScreen<MatterReplicatorMenu> { public class MatterReplicatorScreen extends MatteryScreen<MatterReplicatorMenu> {
public MatterReplicatorScreen(MatterReplicatorMenu p_97741_, Inventory p_97742_, Component p_97743_) { public MatterReplicatorScreen(MatterReplicatorMenu p_97741_, Inventory p_97742_, Component p_97743_) {
super(p_97741_, p_97742_, p_97743_); super(p_97741_, p_97742_, p_97743_);
} }
@Nullable
@Override
protected FramePanel makeMainFrame() {
var frame = super.makeMainFrame();
var grid = new FlexGridPanel(this, frame, 0, 0, 0, 0);
grid.setDock(Dock.FILL);
grid.setDockPadding(0, 0, 40, 12);
new MatteryWidgetPanel(this, grid, menu.progress).setDockMargin(2, 0, 2, 0);
for (var slot : menu.output_slots) {
new SlotPanel(this, grid, 0, 0, slot);
}
return frame;
}
} }

View File

@ -3,9 +3,27 @@ package ru.dbotthepony.mc.otm.screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import ru.dbotthepony.mc.otm.menu.MatterScannerMenu; import ru.dbotthepony.mc.otm.menu.MatterScannerMenu;
import ru.dbotthepony.mc.otm.screen.panels.*;
import javax.annotation.Nullable;
public class MatterScannerScreen extends MatteryScreen<MatterScannerMenu> { public class MatterScannerScreen extends MatteryScreen<MatterScannerMenu> {
public MatterScannerScreen(MatterScannerMenu p_97741_, Inventory p_97742_, Component p_97743_) { public MatterScannerScreen(MatterScannerMenu p_97741_, Inventory p_97742_, Component p_97743_) {
super(p_97741_, p_97742_, p_97743_); super(p_97741_, p_97742_, p_97743_);
} }
@Nullable
@Override
protected FramePanel makeMainFrame() {
var frame = super.makeMainFrame();
var grid = new FlexGridPanel(this, frame, 0, 0, 0, 0);
grid.setDock(Dock.FILL);
grid.setDockPadding(0, 0, 40, 12);
new SlotPanel(this, grid, 0, 0, menu.input).setDockMargin(2, 0, 2, 0);
new MatteryWidgetPanel(this, grid, menu.progress).setDockMargin(2, 0, 2, 0);
return frame;
}
} }

View File

@ -21,11 +21,9 @@ import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import ru.dbotthepony.mc.otm.OverdriveThatMatters; import ru.dbotthepony.mc.otm.OverdriveThatMatters;
import ru.dbotthepony.mc.otm.menu.MatteryMenu; import ru.dbotthepony.mc.otm.menu.MatteryMenu;
import ru.dbotthepony.mc.otm.menu.PoweredMatteryMenu;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot; import ru.dbotthepony.mc.otm.menu.slot.MatterySlot;
import ru.dbotthepony.mc.otm.screen.panels.EditablePanel; import ru.dbotthepony.mc.otm.screen.panels.*;
import ru.dbotthepony.mc.otm.screen.panels.FramePanel;
import ru.dbotthepony.mc.otm.screen.panels.MatteryWidgetPanel;
import ru.dbotthepony.mc.otm.screen.panels.SlotPanel;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -132,7 +130,15 @@ public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractConta
@Nullable @Nullable
protected FramePanel makeMainFrame() { protected FramePanel makeMainFrame() {
return new FramePanel(this, null, 0, 0, 18 * 9 + 16, 100, getTitle()); var frame = new FramePanel(this, null, 0, 0, 18 * 9 + 16, 100, getTitle());
if (menu instanceof PoweredMatteryMenu) {
// reserve 30 pixels on left
var reserve = new EditablePanel(this, frame, 0, 0, 30, 0);
reserve.setDock(Dock.LEFT);
}
return frame;
} }
public ItemRenderer getItemRenderer() { public ItemRenderer getItemRenderer() {
@ -337,7 +343,8 @@ public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractConta
addPanel(main_frame); addPanel(main_frame);
for (var widget : menu.mattery_widgets) { for (var widget : menu.mattery_widgets) {
new MatteryWidgetPanel(this, main_frame, widget); if (widget.auto_parent)
new MatteryWidgetPanel(this, main_frame, widget);
} }
for (var slot : menu.main_slots) { for (var slot : menu.main_slots) {

View File

@ -3,9 +3,30 @@ package ru.dbotthepony.mc.otm.screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import ru.dbotthepony.mc.otm.menu.PatternStorageMenu; import ru.dbotthepony.mc.otm.menu.PatternStorageMenu;
import ru.dbotthepony.mc.otm.screen.panels.Dock;
import ru.dbotthepony.mc.otm.screen.panels.FlexGridPanel;
import ru.dbotthepony.mc.otm.screen.panels.FramePanel;
import ru.dbotthepony.mc.otm.screen.panels.SlotPanel;
import javax.annotation.Nullable;
public class PatternStorageScreen extends MatteryScreen<PatternStorageMenu> { public class PatternStorageScreen extends MatteryScreen<PatternStorageMenu> {
public PatternStorageScreen(PatternStorageMenu p_97741_, Inventory p_97742_, Component p_97743_) { public PatternStorageScreen(PatternStorageMenu p_97741_, Inventory p_97742_, Component p_97743_) {
super(p_97741_, p_97742_, p_97743_); super(p_97741_, p_97742_, p_97743_);
} }
@Nullable
@Override
protected FramePanel makeMainFrame() {
var frame = super.makeMainFrame();
var grid = new FlexGridPanel(this, frame, 0, 0, 0, 0);
grid.setDock(Dock.FILL);
for (var slot : menu.pattern_slots) {
new SlotPanel(this, grid, 0, 0, slot).setDockMargin(1, 1, 1, 1);
}
return frame;
}
} }

View File

@ -3,7 +3,6 @@ package ru.dbotthepony.mc.otm.screen.panels;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.components.events.GuiEventListener;
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
import ru.dbotthepony.mc.otm.screen.MatteryScreen; import ru.dbotthepony.mc.otm.screen.MatteryScreen;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -17,9 +16,7 @@ import java.util.List;
* which allows much simpler GUI composition * which allows much simpler GUI composition
*/ */
public class EditablePanel implements GuiEventListener { public class EditablePanel implements GuiEventListener {
public record ScreenPos(float x, float y) { public record ScreenPos(float x, float y) {}
}
private EditablePanel parent; private EditablePanel parent;
public final MatteryScreen<?> screen; public final MatteryScreen<?> screen;
@ -83,7 +80,7 @@ public class EditablePanel implements GuiEventListener {
private final ArrayList<EditablePanel> children = new ArrayList<>(); private final ArrayList<EditablePanel> children = new ArrayList<>();
private Dock docking = Dock.NONE; private Dock dock = Dock.NONE;
public EditablePanel(@Nonnull MatteryScreen<?> screen, @Nullable EditablePanel parent, float x, float y, float width, float height) { public EditablePanel(@Nonnull MatteryScreen<?> screen, @Nullable EditablePanel parent, float x, float y, float width, float height) {
this.parent = parent; this.parent = parent;
@ -212,15 +209,19 @@ public class EditablePanel implements GuiEventListener {
return false; return false;
} }
public void setDocking(Dock docking) { public void setDock(Dock dock) {
if (docking != this.docking) { if (dock != this.dock) {
this.docking = docking; this.dock = dock;
if (parent != null) if (parent != null)
parent.invalidateLayout(); parent.invalidateLayout();
} }
} }
public Dock getDock() {
return this.dock;
}
public static record DockProperty(float left, float top, float right, float bottom) { public static record DockProperty(float left, float top, float right, float bottom) {
public boolean equals(Object dock_margin) { public boolean equals(Object dock_margin) {
if (dock_margin instanceof DockProperty prop) { if (dock_margin instanceof DockProperty prop) {
@ -248,7 +249,7 @@ public class EditablePanel implements GuiEventListener {
if (!dock.equals(dock_margin)) { if (!dock.equals(dock_margin)) {
dock_margin = dock; dock_margin = dock;
if (docking != Dock.NONE && parent != null) if (this.dock != Dock.NONE && parent != null)
parent.invalidateLayout(); parent.invalidateLayout();
return true; return true;
@ -587,6 +588,26 @@ public class EditablePanel implements GuiEventListener {
return List.copyOf(children); return List.copyOf(children);
} }
public List<EditablePanel> getUndockedChildren() {
int count = 0;
for (var child : children) {
if (child.dock == Dock.NONE) {
count++;
}
}
var list = new ArrayList<EditablePanel>(count);
for (var child : children) {
if (child.dock == Dock.NONE) {
list.add(child);
}
}
return list;
}
protected ArrayList<EditablePanel> getChildrenInternal() { protected ArrayList<EditablePanel> getChildrenInternal() {
return children; return children;
} }
@ -612,7 +633,7 @@ public class EditablePanel implements GuiEventListener {
// determine sizes // determine sizes
for (var child : children) { for (var child : children) {
if (child.getVisible()) { if (child.getVisible()) {
switch (child.docking) { switch (child.dock) {
case TOP -> dock_top += child.height + child.dock_margin.top; case TOP -> dock_top += child.height + child.dock_margin.top;
case BOTTOM -> dock_bottom += child.height + child.dock_margin.bottom; case BOTTOM -> dock_bottom += child.height + child.dock_margin.bottom;
case LEFT -> dock_left += child.width + child.dock_margin.left; case LEFT -> dock_left += child.width + child.dock_margin.left;
@ -635,7 +656,7 @@ public class EditablePanel implements GuiEventListener {
// apply values // apply values
for (var child : children) { for (var child : children) {
if (child.getVisible()) { if (child.getVisible()) {
switch (child.docking) { switch (child.dock) {
case TOP -> { case TOP -> {
child.setPos(dock_left + child.dock_margin.left, dock_top2 + child.dock_margin.top); child.setPos(dock_left + child.dock_margin.left, dock_top2 + child.dock_margin.top);
dock_top2 += child.height + child.dock_margin.top + child.dock_margin.bottom; dock_top2 += child.height + child.dock_margin.top + child.dock_margin.bottom;
@ -665,7 +686,7 @@ public class EditablePanel implements GuiEventListener {
for (var child : children) { for (var child : children) {
if (child.getVisible()) { if (child.getVisible()) {
if (child.docking == Dock.FILL) { if (child.dock == Dock.FILL) {
child.setDimensions( child.setDimensions(
dock_left2 + child.dock_margin.left, dock_left2 + child.dock_margin.left,
dock_top2 + child.dock_margin.top, dock_top2 + child.dock_margin.top,

View File

@ -0,0 +1,152 @@
package ru.dbotthepony.mc.otm.screen.panels;
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
import ru.dbotthepony.mc.otm.screen.MatteryScreen;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class FlexGridPanel extends EditablePanel {
public enum FlexAlign {
TOP_LEFT,
TOP_CENTER,
TOP_RIGHT,
MIDDLE_LEFT,
MIDDLE_CENTER,
MIDDLE_RIGHT,
BOTTOM_LEFT,
BOTTOM_CENTER,
BOTTOM_RIGHT
}
protected FlexAlign align;
public FlexGridPanel(@Nonnull MatteryScreen<?> screen, @Nullable EditablePanel parent, float x, float y, float width, float height) {
super(screen, parent, x, y, width, height);
align = FlexAlign.MIDDLE_CENTER;
}
public FlexAlign getAlign() {
return align;
}
public FlexGridPanel setAlign(FlexAlign align) {
this.align = align;
return this;
}
@Override
protected void performLayout() {
if (align == FlexAlign.MIDDLE_CENTER) {
// список потомков
var children = getUndockedChildren();
// хранит общую ширину всех потомков в ряд
// а так же ограничитель ширины ряда после
// определения количества рядов
float desired_width = 0;
// минимально допустимая ширина одного ряда
float min_width = getWidth();
// "финальная" ширина этой панели
float this_width = getWidth() - getDockPadding().left() - getDockPadding().right();
for (var child : children) {
min_width = Math.min(min_width, child.getWidth() + child.getDockMargin().left() + child.getDockMargin().right());
desired_width += child.getWidth() + child.getDockMargin().left() + child.getDockMargin().right();
}
int rows = 1;
// если общая ширина больше чем ширина панели, делим пополам пока не найдем нужную ширину и количество рядов
while (desired_width > this_width && desired_width > min_width) {
desired_width /= 2;
rows++;
}
if (desired_width < min_width) {
desired_width = min_width;
}
// ширину на середину для позиционирования по центру
this_width /= 2;
int index = 0;
// определение высоты всех рядов вместе
float total_height = 0;
for (int row = 0; row < rows; row++) {
float max_height = 0;
float total_width = 0;
for (int i = index; i < children.size(); i++) {
var child = children.get(i);
var gain_width = child.getWidth() + child.getDockMargin().left() + child.getDockMargin().right();
index = i;
if (gain_width + total_width > desired_width) {
break;
}
max_height = Math.max(max_height, child.getHeight() + child.getDockMargin().top() + child.getDockMargin().bottom());
total_width += gain_width;
}
total_height += max_height;
}
index = 0;
// определение точки по середине по высоте
float h_middle = (getHeight() - getDockPadding().bottom() - getDockPadding().top() - total_height) / 2;
OverdriveThatMatters.LOGGER.info("Общая высота {}, рядов {}, середина {}", total_height, rows, h_middle);
for (int row = 0; row < rows; row++) {
float max_height = 0;
float total_width = 0;
int until = index;
for (int i = index; i < children.size(); i++) {
var child = children.get(i);
var gain_width = child.getWidth() + child.getDockMargin().left() + child.getDockMargin().right();
until = i;
if (gain_width + total_width > desired_width) {
break;
}
max_height = Math.max(max_height, child.getHeight() + child.getDockMargin().top() + child.getDockMargin().bottom());
total_width += gain_width;
}
total_width /= 2;
max_height /= 2;
OverdriveThatMatters.LOGGER.info("Ряд {}, общая ширина {}, максимальная высота {}, позиция {}, c {} до {}", row, total_width * 2, max_height * 2, h_middle, index, until);
float accumulate_width = 0;
for (int i = index; i <= until; i++) {
var child = children.get(i);
child.setPos((int) (this_width - total_width + accumulate_width + child.getDockMargin().left()), (int) (h_middle + max_height - child.getHeight() / 2));
accumulate_width += child.getWidth() + child.getDockMargin().left() + child.getDockMargin().right();
}
h_middle += max_height * 2;
index = until;
}
}
super.performLayout();
}
}

View File

@ -26,8 +26,6 @@ public class GridPanel extends EditablePanel {
@Override @Override
protected void performLayout() { protected void performLayout() {
super.performLayout();
float current_x = 0; float current_x = 0;
float current_y = 0; float current_y = 0;
float line_y = 0; float line_y = 0;
@ -42,7 +40,7 @@ public class GridPanel extends EditablePanel {
break; break;
} }
if (child.getVisible()) { if (child.getVisible() && child.getDock() == Dock.NONE) {
line_y = Math.max(line_y, child.getHeight() + child.getDockMargin().top() + child.getDockMargin().bottom()); line_y = Math.max(line_y, child.getHeight() + child.getDockMargin().top() + child.getDockMargin().bottom());
child.setPos(current_x + child.getDockMargin().left(), current_y + child.getDockMargin().top()); child.setPos(current_x + child.getDockMargin().left(), current_y + child.getDockMargin().top());
current_x += child.getWidth() + child.getDockMargin().left() + child.getDockMargin().right(); current_x += child.getWidth() + child.getDockMargin().left() + child.getDockMargin().right();
@ -61,5 +59,7 @@ public class GridPanel extends EditablePanel {
break; break;
} }
} }
super.performLayout();
} }
} }

View File

@ -18,6 +18,13 @@ public class MatteryWidgetPanel extends EditablePanel {
this.widget = widget; this.widget = widget;
} }
public MatteryWidgetPanel(@Nonnull MatteryScreen screen, @Nullable EditablePanel parent, float x, float y, AbstractWidget widget) {
super(screen, parent, x, y, widget.getImageWidth(), widget.getImageHeight());
widget.x = 0;
widget.y = 0;
this.widget = widget;
}
@Override @Override
protected void innerRender(PoseStack stack, float mouse_x, float mouse_y, float flag) { protected void innerRender(PoseStack stack, float mouse_x, float mouse_y, float flag) {
widget.renderBackground(stack, 0, 0); widget.renderBackground(stack, 0, 0);

View File

@ -31,6 +31,10 @@ public class SlotPanel<T extends MatterySlot> extends AbstractSlotPanel {
this(screen, parent, slot.x, slot.y, 18, 18, slot); this(screen, parent, slot.x, slot.y, 18, 18, slot);
} }
public SlotPanel(@Nonnull MatteryScreen<?> screen, @Nullable EditablePanel parent, float x, float y, T slot) {
this(screen, parent, x, y, 18, 18, slot);
}
@Override @Override
protected boolean mouseClickedInner(double mouse_x, double mouse_y, int button) { protected boolean mouseClickedInner(double mouse_x, double mouse_y, int button) {
screen.onSlotClicked(slot, button); screen.onSlotClicked(slot, button);