Skip to content

Commit

Permalink
move connection widget construction to MTEQuantumStorage
Browse files Browse the repository at this point in the history
add connection widget to Creative qchest and qtank
use GT logo for connection image
update image on controller update/removal
  • Loading branch information
ghzdude committed Dec 22, 2023
1 parent 6d41de4 commit 76142d9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
builder.widget(new CycleButtonWidget(7, 101, 162, 20, () -> active, value -> active = value,
"gregtech.creative.activity.off", "gregtech.creative.activity.on"));

builder.widget(createConnectedGui(6));

return builder.build(getHolder(), entityPlayer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
builder.widget(new CycleButtonWidget(7, 101, 162, 20, () -> active, value -> active = value,
"gregtech.creative.activity.off", "gregtech.creative.activity.on"));

builder.widget(createConnectedGui(6));

return builder.build(getHolder(), entityPlayer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.ModularUI.Builder;
import gregtech.api.gui.widgets.AdvancedTextWidget;
import gregtech.api.gui.widgets.ImageWidget;
import gregtech.api.gui.widgets.SlotWidget;
import gregtech.api.gui.widgets.ToggleButtonWidget;
import gregtech.api.items.itemhandlers.GTItemStackHandler;
Expand Down Expand Up @@ -350,11 +349,8 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
.setTooltipText("gregtech.gui.item_voiding.tooltip")
.shouldUseBaseBackground())
.bindPlayerInventory(entityPlayer.inventory);
if (isConnected()) {
// todo testing purposes
builder.widget(new ImageWidget(116, 32, 20, 20, GuiTextures.INFO_ICON)
.setTooltip("Connected to Quantum Controller: " + getControllerPos()));
}

builder.widget(createConnectedGui(64));

return builder.build(getHolder(), entityPlayer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import gregtech.api.capability.IQuantumController;
import gregtech.api.capability.IQuantumStorage;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.widgets.ImageWidget;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.util.GTUtility;
Expand Down Expand Up @@ -33,6 +35,8 @@ public abstract class MetaTileEntityQuantumStorage<T> extends MetaTileEntity imp
/** synced, server and client */
private BlockPos controllerPos;

private ImageWidget connectedIcon;

public MetaTileEntityQuantumStorage(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
}
Expand Down Expand Up @@ -161,9 +165,17 @@ public void receiveCustomData(int dataId, PacketBuffer buf) {
if (dataId == UPDATE_CONTROLLER_POS) {
this.controllerPos = buf.readBlockPos();
this.controller.clear();

if (this.connectedIcon != null) {
this.connectedIcon.setImage(GuiTextures.GREGTECH_LOGO);
String pos = String.format("X=%d, Z=%d, Y=%d", controllerPos.getX(), controllerPos.getZ(), controllerPos.getY());
this.connectedIcon.setTooltip("Connected to Quantum Controller at/n" + pos);
}
} else if (dataId == REMOVE_CONTROLLER) {
this.controllerPos = null;
this.controller.clear();
this.connectedIcon.setImage(GuiTextures.GREGTECH_LOGO_DARK);
this.connectedIcon.setTooltip(null);
}
}

Expand All @@ -185,6 +197,18 @@ public void readFromNBT(NBTTagCompound data) {
}
}

protected ImageWidget createConnectedGui(int y) {
// todo do something for rendering a highlight at the controller
connectedIcon = new ImageWidget(151, y, 18, 18, isConnected() ? GuiTextures.GREGTECH_LOGO : GuiTextures.GREGTECH_LOGO_DARK);

if (isConnected()) {
String pos = String.format("X=%d, Z=%d, Y=%d", controllerPos.getX(), controllerPos.getZ(), controllerPos.getY());
connectedIcon.setTooltip("Connected to Quantum Controller at/n" + pos);
}

return connectedIcon;
}

@Override
public void addInformation(ItemStack stack, @Nullable World world, @NotNull List<String> tooltip,
boolean advanced) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,9 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
GuiTextures.BUTTON_FLUID_VOID, this::isVoiding, this::setVoiding)
.setTooltipText("gregtech.gui.fluid_voiding.tooltip")
.shouldUseBaseBackground());
if (isConnected()) {
// todo testing purposes
builder.widget(new ImageWidget(116, 32, 20, 20, GuiTextures.INFO_ICON)
.setTooltip("Connected to Quantum Controller " + getControllerPos()));
}

builder.widget(createConnectedGui(64));

return builder.bindPlayerInventory(entityPlayer.inventory)
.build(getHolder(), entityPlayer);
}
Expand Down

0 comments on commit 76142d9

Please sign in to comment.