Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ legacyForge {
}
client {
client()
jvmArguments.add("-XX:+AllowEnhancedClassRedefinition")
}
gametestWorld {
client()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package appeng.client.gui.me.crafting;

import java.util.ArrayList;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

Expand All @@ -29,11 +31,14 @@
import net.minecraft.world.entity.player.Inventory;

import appeng.api.config.ActionItems;
import appeng.api.config.Settings;
import appeng.client.gui.AEBaseScreen;
import appeng.client.gui.StackWithBounds;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.style.TerminalStyle;
import appeng.client.gui.widgets.ActionButton;
import appeng.client.gui.widgets.Scrollbar;
import appeng.client.gui.widgets.SettingToggleButton;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.helpers.CraftExporter;
Expand All @@ -47,18 +52,29 @@
*/
public class CraftConfirmScreen extends AEBaseScreen<CraftConfirmMenu> {

private final CraftConfirmTableRenderer table;
private CraftConfirmTableRenderer table;

private final Button start, startWithFollow;
private final Button selectCPU;
private final Scrollbar scrollbar;
private final boolean isNotifyForFinishedCraftingJobs;

private SettingToggleButton<appeng.api.config.TerminalStyle> terminalStyleButton;

private TerminalStyle terminalStyle;
private int rows = 0;

public CraftConfirmScreen(CraftConfirmMenu menu, Inventory playerInventory, Component title,
ScreenStyle style) {
super(menu, playerInventory, title, style);
this.isNotifyForFinishedCraftingJobs = AEConfig.instance().isNotifyForFinishedCraftingJobs();
this.table = new CraftConfirmTableRenderer(this, 9, 19);
this.terminalStyle = style.getTerminalStyle();
if (this.terminalStyle == null) {
this.table = new CraftConfirmTableRenderer(this, 9, 19);
} else {
this.imageWidth = this.terminalStyle.getScreenWidth();
this.imageHeight = this.terminalStyle.getScreenHeight(0);
}

this.scrollbar = widgets.addScrollBar("scrollbar");

Expand All @@ -76,6 +92,30 @@ public CraftConfirmScreen(CraftConfirmMenu menu, Inventory playerInventory, Comp
this.addToLeftToolbar(new ActionButton(ActionItems.EXPORT_CRAFT, this::exportCraft));

widgets.addButton("cancel", GuiText.Cancel.text(), menu::goBack);

if (this.terminalStyle != null) {
var currentStyle = AEConfig.instance().getTerminalStyle();
this.terminalStyleButton = new SettingToggleButton<>(Settings.TERMINAL_STYLE, currentStyle,
this::toggleTerminalStyle);
this.addToLeftToolbar(this.terminalStyleButton);
}
}

@Override
protected void init() {
if (this.terminalStyle != null) {
var availableHeight = height - 2 * AEConfig.instance().getTerminalMargin();
this.rows = Math.max(2, AEConfig.instance().getTerminalStyle()
.getRows(this.terminalStyle.getPossibleRows(availableHeight)));

this.imageHeight = this.terminalStyle.getScreenHeight(this.rows);
this.table = new CraftConfirmTableRenderer(this, 9, 19, this.rows);

if (this.scrollbar != null) {
this.scrollbar.setHeight(this.rows * this.terminalStyle.getRow().getSrcHeight() - 1);
}
}
super.init();
}

@Override
Expand Down Expand Up @@ -120,7 +160,12 @@ protected void updateBeforeRender() {
setTextContent("cpu_status", cpuDetails);

final int size = plan != null ? plan.getEntries().size() : 0;
scrollbar.setRange(0, this.table.getScrollableRows(size), 1);
if (this.table != null) {
scrollbar.setRange(0, Math.max(0, this.table.getScrollableRows(size)), 1);
}
if (this.terminalStyleButton != null) {
this.terminalStyleButton.set(AEConfig.instance().getTerminalStyle());
}
}

private Component getNextCpuButtonLabel() {
Expand All @@ -143,18 +188,47 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX
int mouseY) {

CraftingPlanSummary plan = menu.getPlan();
if (plan != null) {
if (plan != null && this.table != null) {
this.table.render(guiGraphics, mouseX, mouseY, plan.getEntries(), scrollbar.getCurrentScroll());
}

}

@Override
public void drawBG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX, int mouseY, float partialTicks) {
if (this.terminalStyle == null) {
super.drawBG(guiGraphics, offsetX, offsetY, mouseX, mouseY, partialTicks);
return;
}

terminalStyle.getHeader()
.dest(offsetX, offsetY)
.blit(guiGraphics);

int y = offsetY + terminalStyle.getHeader().getSrcHeight();

int rowsToDraw = Math.max(2, this.rows);
for (int i = 0; i < rowsToDraw; i++) {
var blitter = terminalStyle.getRow();
if (i == 0) {
blitter = terminalStyle.getFirstRow();
} else if (i + 1 == rowsToDraw) {
blitter = terminalStyle.getLastRow();
}
blitter.dest(offsetX, y).blit(guiGraphics);
y += terminalStyle.getRow().getSrcHeight();
}
terminalStyle.getBottom().dest(offsetX, y - 1).blit(guiGraphics);
}

@org.jetbrains.annotations.Nullable
@Override
public StackWithBounds getStackUnderMouse(double mouseX, double mouseY) {
var hovered = table.getHoveredStack();
if (hovered != null) {
return hovered;
if (this.table != null) {
var hovered = table.getHoveredStack();
if (hovered != null) {
return hovered;
}
}
return super.getStackUnderMouse(mouseX, mouseY);
}
Expand Down Expand Up @@ -201,4 +275,12 @@ private void exportCraft() {
exportObject.add("getEntries", entryArray);
CraftExporter.exportCraft(exportObject, getPlayer(), CraftExporter.ExportType.CRAFTING_PLAN);
}

private void toggleTerminalStyle(SettingToggleButton<appeng.api.config.TerminalStyle> btn, boolean backwards) {
var next = btn.getNextValue(backwards);
AEConfig.instance().setTerminalStyle(next);
btn.set(next);
new ArrayList<>(this.children()).forEach(this::removeWidget);
this.init();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@

public class CraftConfirmTableRenderer extends AbstractTableRenderer<CraftingPlanSummaryEntry> {

private static final int DEFAULT_ROWS = 5;

public CraftConfirmTableRenderer(AEBaseScreen<?> screen, int x, int y) {
super(screen, x, y, 5);
super(screen, x, y, DEFAULT_ROWS);
}

public CraftConfirmTableRenderer(AEBaseScreen<?> screen, int x, int y, int rows) {
super(screen, x, y, rows);
}

@Override
Expand Down
94 changes: 91 additions & 3 deletions src/main/java/appeng/client/gui/me/crafting/CraftingCPUScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
import appeng.client.gui.AEBaseScreen;
import appeng.client.gui.StackWithBounds;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.style.TerminalStyle;
import appeng.client.gui.widgets.ActionButton;
import appeng.client.gui.widgets.Scrollbar;
import appeng.client.gui.widgets.ServerSettingToggleButton;
import appeng.client.gui.widgets.SettingToggleButton;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.BlockHighlightPacket;
Expand All @@ -59,8 +61,9 @@
* This screen shows the current crafting job that a crafting CPU is working on (if any).
*/
public class CraftingCPUScreen<T extends CraftingCPUMenu> extends AEBaseScreen<T> {
private static final int MIN_ROWS = 2;

private final CraftingStatusTableRenderer table;
private CraftingStatusTableRenderer table;

private final Button cancel, suspend;

Expand All @@ -72,10 +75,21 @@ public class CraftingCPUScreen<T extends CraftingCPUMenu> extends AEBaseScreen<T

private CraftingStatus status;

private SettingToggleButton<appeng.api.config.TerminalStyle> terminalStyleButton;
private final TerminalStyle terminalStyle;
private int rows = 0;

public CraftingCPUScreen(T menu, Inventory playerInventory, Component title, ScreenStyle style) {
super(menu, playerInventory, title, style);

this.table = new CraftingStatusTableRenderer(this, 9, 19);
this.terminalStyle = style.getTerminalStyle();
if (this.terminalStyle == null) {
// Fallback
this.table = new CraftingStatusTableRenderer(this, 9, 19);
} else {
this.imageWidth = this.terminalStyle.getScreenWidth();
this.imageHeight = this.terminalStyle.getScreenHeight(0);
}

this.scrollbar = widgets.addScrollBar("scrollbar");

Expand All @@ -90,6 +104,30 @@ public CraftingCPUScreen(T menu, Inventory playerInventory, Component title, Scr
if (menu.allowConfiguration()) {
this.addToLeftToolbar(this.schedulingModeButton);
}
if (this.terminalStyle != null) {
var currentStyle = AEConfig.instance().getTerminalStyle();
this.terminalStyleButton = new SettingToggleButton<>(Settings.TERMINAL_STYLE, currentStyle,
this::toggleTerminalStyle);
this.addToLeftToolbar(this.terminalStyleButton);
}
}

@Override
protected void init() {
if (this.terminalStyle != null) {
var availableHeight = height - 2 * AEConfig.instance().getTerminalMargin();
this.rows = Math.max(MIN_ROWS, AEConfig.instance().getTerminalStyle()
.getRows(this.terminalStyle.getPossibleRows(availableHeight)));

this.imageHeight = this.terminalStyle.getScreenHeight(this.rows);
this.table = new CraftingStatusTableRenderer(this, 9, 19, this.rows);

if (this.scrollbar != null) {
this.scrollbar.setHeight(this.rows * this.terminalStyle.getRow().getSrcHeight() - 1);
}
}

super.init();
}

@Override
Expand Down Expand Up @@ -119,11 +157,17 @@ protected void updateBeforeRender() {
setTextContent(TEXT_ID_DIALOG_TITLE, title);

final int size = this.status != null ? this.status.getEntries().size() : 0;
scrollbar.setRange(0, this.table.getScrollableRows(size), 1);
if (this.table != null) {
scrollbar.setRange(0, Math.max(0, this.table.getScrollableRows(size)), 1);
}

this.schedulingModeButton.set(this.menu.getSchedulingMode());

this.exportCraft.visible = !getVisualEntries().isEmpty();

if (this.terminalStyleButton != null) {
this.terminalStyleButton.set(AEConfig.instance().getTerminalStyle());
}
}

private List<CraftingStatusEntry> getVisualEntries() {
Expand All @@ -147,6 +191,34 @@ public void drawFG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX
}
}

@Override
public void drawBG(GuiGraphics guiGraphics, int offsetX, int offsetY, int mouseX, int mouseY, float partialTicks) {
if (this.terminalStyle == null) {
super.drawBG(guiGraphics, offsetX, offsetY, mouseX, mouseY, partialTicks);
return;
}

terminalStyle.getHeader()
.dest(offsetX, offsetY)
.blit(guiGraphics);

int y = offsetY + terminalStyle.getHeader().getSrcHeight();

int rowsToDraw = Math.max(2, this.rows);
for (int i = 0; i < rowsToDraw; i++) {
var blitter = terminalStyle.getRow();
if (i == 0) {
blitter = terminalStyle.getFirstRow();
} else if (i + 1 == rowsToDraw) {
blitter = terminalStyle.getLastRow();
}
blitter.dest(offsetX, y).blit(guiGraphics);
y += terminalStyle.getRow().getSrcHeight();
}

terminalStyle.getBottom().dest(offsetX, y - 1).blit(guiGraphics);
}

@org.jetbrains.annotations.Nullable
@Override
public StackWithBounds getStackUnderMouse(double mouseX, double mouseY) {
Expand Down Expand Up @@ -231,4 +303,20 @@ protected void exportCraft() {
exportObject.add("entries", entryArray);
CraftExporter.exportCraft(exportObject, getPlayer(), CraftExporter.ExportType.CRAFTING_STATUS);
}

private void toggleTerminalStyle(SettingToggleButton<appeng.api.config.TerminalStyle> button, boolean backwards) {
var next = button.getNextValue(backwards);
AEConfig.instance().setTerminalStyle(next);
button.set(next);
new ArrayList<>(this.children()).forEach(this::removeWidget);
this.init();
}

protected int getVisibleRows() {
return (terminalStyle != null && rows > 0) ? rows : 0;
}

protected TerminalStyle getTerminalStyle() {
return terminalStyle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import appeng.client.gui.implementations.AESubScreen;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.CPUSelectionList;
import appeng.client.gui.widgets.Scrollbar;
import appeng.menu.me.crafting.CraftingStatusMenu;

/**
Expand All @@ -32,15 +33,34 @@
*/
public class CraftingStatusScreen extends CraftingCPUScreen<CraftingStatusMenu> {

private final CPUSelectionList cpuList;
private final Scrollbar scrollbar;

public CraftingStatusScreen(CraftingStatusMenu menu,
Inventory playerInventory,
Component title, ScreenStyle style) {
super(menu, playerInventory, title, style);

AESubScreen.addBackButton(menu, "back", widgets);

var scrollbar = widgets.addScrollBar("selectCpuScrollbar");
widgets.add("selectCpuList", new CPUSelectionList(menu, scrollbar, style));
this.scrollbar = widgets.addScrollBar("selectCpuScrollbar");

this.cpuList = new CPUSelectionList(menu, scrollbar, style);
widgets.add("selectCpuList", this.cpuList);
}

@Override
protected void init() {
super.init();

var terminalStyle = getTerminalStyle();
if (terminalStyle != null) {
var visibleRows = getVisibleRows();
var listHeight = imageHeight - 8;
cpuList.setVisibleRows(visibleRows);
cpuList.setSize(cpuList.getBounds().getWidth(), listHeight);
scrollbar.setHeight(visibleRows * terminalStyle.getRow().getSrcHeight() - 1);
}
}

@Override
Expand Down
Loading