Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust assembler GUI, add Machine title offset #60

Merged
merged 1 commit into from
Aug 7, 2021
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
10 changes: 7 additions & 3 deletions src/main/java/gregtech/api/gui/ModularUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public static Builder defaultBuilder() {
return new Builder(GuiTextures.BACKGROUND, 176, 166);
}

public static Builder defaultBuilder(int yOffset) {
return new Builder(GuiTextures.BACKGROUND, 176, 166 + yOffset);
}

public static Builder borderedBuilder() {
return new Builder(GuiTextures.BORDERED_BACKGROUND, 195, 136);
}
Expand Down Expand Up @@ -175,7 +179,7 @@ public Builder progressBar(DoubleSupplier progressSupplier, int x, int y, int wi
}

public Builder bindPlayerInventory(InventoryPlayer inventoryPlayer) {
bindPlayerInventory(inventoryPlayer, GuiTextures.SLOT);
bindPlayerInventory(inventoryPlayer, GuiTextures.SLOT, 0);
return this;
}

Expand All @@ -184,8 +188,8 @@ public Builder bindPlayerInventory(InventoryPlayer inventoryPlayer, int startY)
return this;
}

public Builder bindPlayerInventory(InventoryPlayer inventoryPlayer, TextureArea imageLocation) {
return bindPlayerInventory(inventoryPlayer, imageLocation, 7, 84);
public Builder bindPlayerInventory(InventoryPlayer inventoryPlayer, TextureArea imageLocation, int yOffset) {
return bindPlayerInventory(inventoryPlayer, imageLocation, 7, 84 + yOffset);
}

public Builder bindPlayerInventory(InventoryPlayer inventoryPlayer, TextureArea imageLocation, int x, int y) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class SimpleMachineMetaTileEntity extends WorkableTieredMetaTileEntity im

private static int inputTankCapacity = ConfigHolder.U.GT5u.useCustomMachineTankSizes ? ConfigHolder.U.GT5u.customMachineTankSizes[0] : 64000;
private static int outputTankCapacity = ConfigHolder.U.GT5u.useCustomMachineTankSizes ? ConfigHolder.U.GT5u.customMachineTankSizes[1] : 64000;
private static final int FONT_HEIGHT = 9; // Minecraft's FontRenderer FONT_HEIGHT value

public SimpleMachineMetaTileEntity(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap, OrientedOverlayRenderer renderer, int tier) {
this(metaTileEntityId, recipeMap, renderer, tier, true);
Expand Down Expand Up @@ -316,30 +317,36 @@ protected RecipeLogicEnergy createWorkable(RecipeMap<?> recipeMap) {
}

protected ModularUI.Builder createGuiTemplate(EntityPlayer player) {
ModularUI.Builder builder = workable.recipeMap.createUITemplate(workable::getProgressPercent, importItems, exportItems, importFluids, exportFluids)
RecipeMap<?> workableRecipeMap = workable.recipeMap;
int yOffset = 0;
if (workableRecipeMap.getMaxInputs() > 6 || workableRecipeMap.getMaxFluidInputs() > 6 || workableRecipeMap.getMaxOutputs() > 6 || workableRecipeMap.getMaxFluidOutputs() > 6) {
yOffset = FONT_HEIGHT;
}

ModularUI.Builder builder = workableRecipeMap.createUITemplate(workable::getProgressPercent, importItems, exportItems, importFluids, exportFluids, yOffset)
.widget(new LabelWidget(5, 5, getMetaFullName()))
.widget(new SlotWidget(chargerInventory, 0, 79, 62)
.widget(new SlotWidget(chargerInventory, 0, 79, 62 + yOffset)
.setBackgroundTexture(GuiTextures.SLOT, GuiTextures.CHARGER_OVERLAY))
.widget(new ImageWidget(79, 42, 18, 18, GuiTextures.INDICATOR_NO_ENERGY)
.widget(new ImageWidget(79, 42 + yOffset, 18, 18, GuiTextures.INDICATOR_NO_ENERGY)
.setPredicate(workable::isHasNotEnoughEnergy))
.bindPlayerInventory(player.inventory);
.bindPlayerInventory(player.inventory, GuiTextures.SLOT, yOffset);

int leftButtonStartX = 7;

if (exportItems.getSlots() > 0) {
builder.widget(new ToggleButtonWidget(leftButtonStartX, 62, 18, 18,
builder.widget(new ToggleButtonWidget(leftButtonStartX, 62 + yOffset, 18, 18,
GuiTextures.BUTTON_ITEM_OUTPUT, this::isAutoOutputItems, this::setAutoOutputItems)
.setTooltipText("gregtech.gui.item_auto_output.tooltip"));
leftButtonStartX += 18;
}
if (exportFluids.getTanks() > 0) {
builder.widget(new ToggleButtonWidget(leftButtonStartX, 62, 18, 18,
builder.widget(new ToggleButtonWidget(leftButtonStartX, 62 + yOffset, 18, 18,
GuiTextures.BUTTON_FLUID_OUTPUT, this::isAutoOutputFluids, this::setAutoOutputFluids)
.setTooltipText("gregtech.gui.fluid_auto_output.tooltip"));
leftButtonStartX += 18;
}

builder.widget(new CycleButtonWidget(leftButtonStartX, 62, 18, 18,
builder.widget(new CycleButtonWidget(leftButtonStartX, 62 + yOffset, 18, 18,
workable.getAvailableOverclockingTiers(), workable::getOverclockTier, workable::setOverclockTier)
.setTooltipHoverString("gregtech.gui.overclock.description")
.setButtonTexture(GuiTextures.BUTTON_OVERCLOCK));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@ public ModularUI.Builder createUITemplate(EntityPlayer player) {
.widget(new LabelWidget(6, 6, getMetaFullName()))
.widget(new ImageWidget(79, 42, 18, 18, getFullGuiTexture("not_enough_steam_%s"))
.setPredicate(() -> workableHandler.isHasNotEnoughEnergy()))
.bindPlayerInventory(player.inventory, BRONZE_SLOT_BACKGROUND_TEXTURE);
.bindPlayerInventory(player.inventory, BRONZE_SLOT_BACKGROUND_TEXTURE, 0);
}
}
23 changes: 10 additions & 13 deletions src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ private Recipe findByInputs(long voltage, List<ItemStack> inputs, List<FluidStac
return null;
}

public ModularUI.Builder createJeiUITemplate(IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids) {
return createUITemplate(this::jeiProgressBar, importItems, exportItems, importFluids, exportFluids);
public ModularUI.Builder createJeiUITemplate(IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids, int yOffset) {
return createUITemplate(this::jeiProgressBar, importItems, exportItems, importFluids, exportFluids, yOffset);
}

private double timer = 0;
Expand All @@ -283,17 +283,17 @@ private double jeiProgressBar() {
}

//this DOES NOT include machine control widgets or binds player inventory
public ModularUI.Builder createUITemplate(DoubleSupplier progressSupplier, IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids) {
ModularUI.Builder builder = ModularUI.defaultBuilder();
builder.widget(new ProgressWidget(progressSupplier, 78, 23, 20, 20, progressBarTexture, moveType));
addInventorySlotGroup(builder, importItems, importFluids, false);
addInventorySlotGroup(builder, exportItems, exportFluids, true);
public ModularUI.Builder createUITemplate(DoubleSupplier progressSupplier, IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids, int yOffset) {
ModularUI.Builder builder = ModularUI.defaultBuilder(yOffset);
builder.widget(new ProgressWidget(progressSupplier, 78, 23 + yOffset, 20, 20, progressBarTexture, moveType));
addInventorySlotGroup(builder, importItems, importFluids, false, yOffset);
addInventorySlotGroup(builder, exportItems, exportFluids, true, yOffset);
if (this.specialTexture != null && this.specialTexturePosition != null)
addSpecialTexture(builder);
return builder;
}

protected void addInventorySlotGroup(ModularUI.Builder builder, IItemHandlerModifiable itemHandler, FluidTankList fluidHandler, boolean isOutputs) {
protected void addInventorySlotGroup(ModularUI.Builder builder, IItemHandlerModifiable itemHandler, FluidTankList fluidHandler, boolean isOutputs, int yOffset) {
int itemInputsCount = itemHandler.getSlots();
int fluidInputsCount = fluidHandler.getTanks();
boolean invertFluids = false;
Expand All @@ -307,7 +307,7 @@ protected void addInventorySlotGroup(ModularUI.Builder builder, IItemHandlerModi
int itemSlotsToLeft = inputSlotGrid[0];
int itemSlotsToDown = inputSlotGrid[1];
int startInputsX = isOutputs ? 106 : 70 - itemSlotsToLeft * 18;
int startInputsY = 33 - (int) (itemSlotsToDown / 2.0 * 18);
int startInputsY = 33 - (int) (itemSlotsToDown / 2.0 * 18) + yOffset;
boolean wasGroupOutput = itemHandler.getSlots() + fluidHandler.getTanks() == 12;
if (wasGroupOutput) startInputsY -= 9;
for (int i = 0; i < itemSlotsToDown; i++) {
Expand All @@ -331,10 +331,7 @@ protected void addInventorySlotGroup(ModularUI.Builder builder, IItemHandlerModi
for (int i = 0; i < fluidInputsCount; i++) {
int x = isOutputs ? startInputsX + 18 * (i % 3) : startInputsX + itemSlotsToLeft * 18 - 18 - 18 * (i % 3);
int y = startSpecY + (i / 3) * 18;
if (itemHandler.getSlots() >= 9)
addSlot(builder, x, y + 2, i, itemHandler, fluidHandler, !invertFluids, isOutputs);
else
addSlot(builder, x, y, i, itemHandler, fluidHandler, !invertFluids, isOutputs);
addSlot(builder, x, y, i, itemHandler, fluidHandler, !invertFluids, isOutputs);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public RecipeMapAssemblyLine<R> setProgressBar(TextureArea progressBar, Progress

@Override
@Nonnull
public ModularUI.Builder createUITemplate(DoubleSupplier progressSupplier, IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids) {
public ModularUI.Builder createUITemplate(DoubleSupplier progressSupplier, IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids, int yOffset) {
ModularUI.Builder builder = new ModularUI.Builder(GuiTextures.BACKGROUND, 176, 216) {
@Override
public ModularUI.Builder bindPlayerInventory(InventoryPlayer inventoryPlayer) {
Expand All @@ -42,13 +42,13 @@ public ModularUI.Builder bindPlayerInventory(InventoryPlayer inventoryPlayer) {

};
builder.widget(new ProgressWidget(progressSupplier, 109, 22, 20, 20, this.progressBarTexture, this.moveType));
this.addInventorySlotGroup(builder, importItems, importFluids, false);
this.addInventorySlotGroup(builder, exportItems, exportFluids, true);
this.addInventorySlotGroup(builder, importItems, importFluids, false, yOffset);
this.addInventorySlotGroup(builder, exportItems, exportFluids, true, yOffset);
return builder;
}

@Override
protected void addInventorySlotGroup(ModularUI.Builder builder, IItemHandlerModifiable itemHandler, FluidTankList fluidHandler, boolean isOutputs) {
protected void addInventorySlotGroup(ModularUI.Builder builder, IItemHandlerModifiable itemHandler, FluidTankList fluidHandler, boolean isOutputs, int yOffset) {
int itemInputsCount = itemHandler.getSlots();
int fluidInputsCount = fluidHandler.getTanks();
boolean invertFluids = false;
Expand All @@ -62,7 +62,7 @@ protected void addInventorySlotGroup(ModularUI.Builder builder, IItemHandlerModi
int itemSlotsToLeft = inputSlotGrid[0];
int itemSlotsToDown = inputSlotGrid[1];
int startInputsX = isOutputs ? 138 : 101 - itemSlotsToLeft * 18;
int startInputsY = 32 - (int) (itemSlotsToDown / 2.0 * 18);
int startInputsY = 32 - (int) (itemSlotsToDown / 2.0 * 18) + yOffset;
for (int i = 0; i < itemSlotsToDown; i++) {
for (int j = 0; j < itemSlotsToLeft; j++) {
int slotIndex = i * itemSlotsToLeft + j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
.setBackgroundTexture(GuiTextures.FLUID_TANK_BACKGROUND)
.setOverlayTexture(GuiTextures.FLUID_TANK_OVERLAY)
.setContainerClicking(true, false))
.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT)
.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 0)
.build(getHolder(), entityPlayer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
.setBackgroundTexture(GuiTextures.SLOT, GuiTextures.INGOT_OVERLAY))
.widget(new SlotWidget(exportItems, 1, 103, 24, true, false)
.setBackgroundTexture(GuiTextures.SLOT, GuiTextures.DUST_OVERLAY))
.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT)
.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 0)
.build(getHolder(), entityPlayer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public ModularUI.Builder createUITemplate(EntityPlayer player) {
.widget(new ImageWidget(43, 44, 18, 18)
.setImage(getGuiTexture("overlay_%s_fluid_container")))

.bindPlayerInventory(player.inventory, BRONZE_SLOT_BACKGROUND_TEXTURE);
.bindPlayerInventory(player.inventory, BRONZE_SLOT_BACKGROUND_TEXTURE, 0);
}

private int getBoilingCycleLength() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class RecipeMapCategory implements IRecipeCategory<GTRecipeWrapper> {
private final FluidTankList importFluids, exportFluids;
private final IDrawable backgroundDrawable;

private final int FONT_HEIGHT = 9;

public RecipeMapCategory(RecipeMap<?> recipeMap, IGuiHelper guiHelper) {
this.recipeMap = recipeMap;
FluidTank[] importFluidTanks = new FluidTank[recipeMap.getMaxFluidInputs()];
Expand All @@ -47,7 +49,9 @@ public RecipeMapCategory(RecipeMap<?> recipeMap, IGuiHelper guiHelper) {
(importItems = new ItemStackHandler(recipeMap.getMaxInputs())),
(exportItems = new ItemStackHandler(recipeMap.getMaxOutputs())),
(importFluids = new FluidTankList(false, importFluidTanks)),
(exportFluids = new FluidTankList(false, exportFluidTanks))
(exportFluids = new FluidTankList(false, exportFluidTanks)),
(recipeMap.getMaxOutputs() > 6 || recipeMap.getMaxInputs() > 6 ||
recipeMap.getMaxFluidOutputs() > 6 || recipeMap.getMaxFluidInputs() > 6) ? FONT_HEIGHT : 0
).build(new BlankUIHolder(), Minecraft.getMinecraft().player);
this.modularUI.initWidgets();
this.backgroundDrawable = guiHelper.createBlankDrawable(modularUI.getWidth(), modularUI.getHeight() * 2 / 3);
Expand Down