New crafting monitor GUI
This commit is contained in:
@@ -54,4 +54,9 @@ public interface ICraftingTask {
|
||||
* @return The status
|
||||
*/
|
||||
String getStatus();
|
||||
|
||||
/**
|
||||
* @return The progress for display in the crafting monitor, -1 for no progress
|
||||
*/
|
||||
int getProgress();
|
||||
}
|
||||
|
||||
@@ -122,4 +122,17 @@ public class CraftingTaskNormal extends CraftingTask {
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProgress() {
|
||||
int satisfiedAmount = 0;
|
||||
|
||||
for (boolean item : satisfied) {
|
||||
if (item) {
|
||||
satisfiedAmount++;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) ((float) satisfiedAmount / (float) satisfied.length * 100F);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,4 +179,17 @@ public class CraftingTaskProcessing extends CraftingTask {
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProgress() {
|
||||
int satisfiedAmount = 0;
|
||||
|
||||
for (boolean item : satisfied) {
|
||||
if (item) {
|
||||
satisfiedAmount++;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) ((float) satisfiedAmount / (float) satisfied.length * 100F);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiCraftingMonitor extends GuiBase {
|
||||
private static final int VISIBLE_ROWS = 3;
|
||||
private static final int VISIBLE_ROWS = 5;
|
||||
|
||||
private static final int ITEM_WIDTH = 72;
|
||||
private static final int ITEM_HEIGHT = 30;
|
||||
private static final int ITEM_WIDTH = 143;
|
||||
private static final int ITEM_HEIGHT = 18;
|
||||
|
||||
private TileCraftingMonitor craftingMonitor;
|
||||
|
||||
@@ -28,9 +28,8 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
|
||||
private int itemSelected = -1;
|
||||
|
||||
private boolean renderItemSelection;
|
||||
private int renderItemSelectionX;
|
||||
private int renderItemSelectionY;
|
||||
private int itemSelectedX = -1;
|
||||
private int itemSelectedY = -1;
|
||||
|
||||
public GuiCraftingMonitor(ContainerCraftingMonitor container, TileCraftingMonitor craftingMonitor) {
|
||||
super(container, 176, 230);
|
||||
@@ -50,8 +49,8 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
int cancelButtonWidth = 14 + fontRendererObj.getStringWidth(cancel);
|
||||
int cancelAllButtonWidth = 14 + fontRendererObj.getStringWidth(cancelAll);
|
||||
|
||||
cancelButton = addButton(x + 7, y + 113, cancelButtonWidth, 20, cancel, false);
|
||||
cancelAllButton = addButton(x + 7 + cancelButtonWidth + 4, y + 113, cancelAllButtonWidth, 20, cancelAll, false);
|
||||
cancelButton = addButton(x + 7, y + 113, cancelButtonWidth, 21, cancel, false);
|
||||
cancelAllButton = addButton(x + 7 + cancelButtonWidth + 4, y + 113, cancelAllButtonWidth, 21, cancelAll, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,8 +72,8 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
|
||||
drawTexture(x, y, 0, 0, width, height);
|
||||
|
||||
if (renderItemSelection) {
|
||||
drawTexture(x + renderItemSelectionX, y + renderItemSelectionY, 178, 0, ITEM_WIDTH, ITEM_HEIGHT);
|
||||
if (itemSelectedX != -1 && itemSelectedY != -1) {
|
||||
drawTexture(x + itemSelectedX, y + itemSelectedY, 0, 232, ITEM_WIDTH, ITEM_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,39 +82,46 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
drawString(7, 7, t("gui.refinedstorage:crafting_monitor"));
|
||||
drawString(7, 137, t("container.inventory"));
|
||||
|
||||
int x = 8;
|
||||
int y = 20;
|
||||
|
||||
int item = getScrollbar().getOffset() * 2;
|
||||
int item = getScrollbar().getOffset();
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
String[] lines = null;
|
||||
|
||||
renderItemSelection = false;
|
||||
int ox = 8;
|
||||
int x = ox;
|
||||
int y = 20;
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
itemSelectedX = -1;
|
||||
itemSelectedY = -1;
|
||||
|
||||
for (int i = 0; i < VISIBLE_ROWS; ++i) {
|
||||
if (item < getTasks().size()) {
|
||||
if (item == itemSelected) {
|
||||
renderItemSelection = true;
|
||||
renderItemSelectionX = x;
|
||||
renderItemSelectionY = y;
|
||||
}
|
||||
|
||||
ClientCraftingTask task = getTasks().get(i);
|
||||
|
||||
drawItem(x + 4, y + 11, task.getOutput());
|
||||
if (i == itemSelected) {
|
||||
itemSelectedX = x;
|
||||
itemSelectedY = y;
|
||||
}
|
||||
|
||||
x += task.getDepth() * 16;
|
||||
|
||||
drawItem(x + 2, y + 1, task.getOutput());
|
||||
|
||||
float scale = 0.5f;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
drawString(calculateOffsetOnScale(x + 5, scale), calculateOffsetOnScale(y + 4, scale), task.getOutput().getDisplayName());
|
||||
drawString(calculateOffsetOnScale(x + 21, scale), calculateOffsetOnScale(y + 7, scale), task.getOutput().getDisplayName());
|
||||
|
||||
if (task.getProgress() != -1) {
|
||||
drawString(calculateOffsetOnScale(ox + ITEM_WIDTH - 15, scale), calculateOffsetOnScale(y + 7, scale), task.getProgress() + "%");
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
if (inBounds(x + 5, y + 10, 16, 16, mouseX, mouseY) && !task.getStatus().trim().equals("")) {
|
||||
if (inBounds(x + 4, y + 4, 16, 16, mouseX, mouseY) && !task.getStatus().trim().equals("")) {
|
||||
lines = task.getStatus().split("\n");
|
||||
|
||||
for (int j = 0; j < lines.length; ++j) {
|
||||
@@ -130,13 +136,9 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
lines[j] = line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 1 || i == 3) {
|
||||
x = 8;
|
||||
x = ox;
|
||||
y += ITEM_HEIGHT;
|
||||
} else {
|
||||
x += ITEM_WIDTH;
|
||||
}
|
||||
|
||||
item++;
|
||||
@@ -148,7 +150,7 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
}
|
||||
|
||||
private int getRows() {
|
||||
return Math.max(0, (int) Math.ceil((float) getTasks().size() / (float) 2));
|
||||
return getTasks().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -168,21 +170,17 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
itemSelected = -1;
|
||||
|
||||
if (mouseButton == 0 && inBounds(8, 20, 144, 90, mouseX - guiLeft, mouseY - guiTop)) {
|
||||
itemSelected = -1;
|
||||
int item = getScrollbar().getOffset();
|
||||
|
||||
int item = getScrollbar().getOffset() * 2;
|
||||
for (int i = 0; i < VISIBLE_ROWS; ++i) {
|
||||
int ix = 8;
|
||||
int iy = 20 + (i * ITEM_HEIGHT);
|
||||
|
||||
for (int y = 0; y < 3; ++y) {
|
||||
for (int x = 0; x < 2; ++x) {
|
||||
int ix = 8 + (x * ITEM_WIDTH);
|
||||
int iy = 20 + (y * ITEM_HEIGHT);
|
||||
|
||||
if (inBounds(ix, iy, ITEM_WIDTH, ITEM_HEIGHT, mouseX - guiLeft, mouseY - guiTop) && item < getTasks().size()) {
|
||||
itemSelected = item;
|
||||
}
|
||||
|
||||
item++;
|
||||
if (inBounds(ix, iy, ITEM_WIDTH, ITEM_HEIGHT, mouseX - guiLeft, mouseY - guiTop) && item < getTasks().size()) {
|
||||
itemSelected = item + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,25 @@ public class ClientCraftingTask {
|
||||
private int id;
|
||||
private String status;
|
||||
private int depth;
|
||||
private int progress;
|
||||
|
||||
// Used server-side while sending
|
||||
private ItemStack[] outputs;
|
||||
private ClientCraftingTask child;
|
||||
|
||||
public ClientCraftingTask(ItemStack output, int id, String status, int depth) {
|
||||
public ClientCraftingTask(ItemStack output, int id, String status, int depth, int progress) {
|
||||
this.output = output;
|
||||
this.id = id;
|
||||
this.status = status;
|
||||
this.depth = depth;
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public ClientCraftingTask(String status, ItemStack[] outputs, ICraftingTask child) {
|
||||
public ClientCraftingTask(String status, ItemStack[] outputs, int progress, ICraftingTask child) {
|
||||
this.status = status;
|
||||
this.outputs = outputs;
|
||||
this.child = child != null ? new ClientCraftingTask(child.getStatus(), child.getPattern().getOutputs(), child.getChild()) : null;
|
||||
this.progress = progress;
|
||||
this.child = child != null ? new ClientCraftingTask(child.getStatus(), child.getPattern().getOutputs(), child.getProgress(), child.getChild()) : null;
|
||||
}
|
||||
|
||||
public ItemStack getOutput() {
|
||||
@@ -49,4 +52,8 @@ public class ClientCraftingTask {
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class TileCraftingMonitor extends TileNode {
|
||||
List<ClientCraftingTask> tasks = tile.network.getCraftingTasks().stream().map(t -> new ClientCraftingTask(
|
||||
t.getStatus(),
|
||||
t.getPattern().getOutputs(),
|
||||
t.getProgress(),
|
||||
t.getChild()
|
||||
)).collect(Collectors.toList());
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import refinedstorage.tile.ClientNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class RefinedStorageSerializers {
|
||||
@@ -60,6 +59,8 @@ public final class RefinedStorageSerializers {
|
||||
private void writeTask(PacketBuffer buf, ClientCraftingTask task) {
|
||||
ByteBufUtils.writeUTF8String(buf, task.getStatus());
|
||||
|
||||
buf.writeInt(task.getProgress());
|
||||
|
||||
buf.writeInt(task.getOutputs().length);
|
||||
|
||||
for (ItemStack output : task.getOutputs()) {
|
||||
@@ -83,18 +84,18 @@ public final class RefinedStorageSerializers {
|
||||
readTask(buf, i, 0, tasks);
|
||||
}
|
||||
|
||||
Collections.reverse(tasks);
|
||||
|
||||
return tasks;
|
||||
}
|
||||
|
||||
private void readTask(PacketBuffer buf, int i, int depth, List<ClientCraftingTask> tasks) {
|
||||
String status = ByteBufUtils.readUTF8String(buf);
|
||||
|
||||
int progress = buf.readInt();
|
||||
|
||||
int outputs = buf.readInt();
|
||||
|
||||
for (int j = 0; j < outputs; ++j) {
|
||||
tasks.add(new ClientCraftingTask(ByteBufUtils.readItemStack(buf), i, status, depth));
|
||||
tasks.add(new ClientCraftingTask(ByteBufUtils.readItemStack(buf), i, status, depth, progress));
|
||||
}
|
||||
|
||||
if (buf.readBoolean()) {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Reference in New Issue
Block a user