Skip to content

Commit

Permalink
disable SingularitySlot when there is no Quantum Bridge Card installed (
Browse files Browse the repository at this point in the history
fix #279)
  • Loading branch information
Mari023 committed Jun 30, 2024
1 parent 4a0aec0 commit e13ebd9
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- remove builtin ae2 style wireless crafting terminal resource pack
- make upgrade panel scrollable
- fix slot hover and focus textures
- disable SingularitySlot when there is no Quantum Bridge Card installed
2 changes: 2 additions & 0 deletions src/main/java/de/mari_023/ae2wtlib/terminal/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public record Icon(int x, int y, int width, int height, Texture texture) {
public static final Icon UPGRADE_BACKGROUND_SCROLLING_MIDDLE = new Icon(128, 23, 34, 18);
public static final Icon UPGRADE_BACKGROUND_SCROLLING_BOTTOM = new Icon(128, 41, 34, 25);

public static final Icon SINGULARITY_BACKGROUND = new Icon(105, 98, 23, 30);

private Icon(int x, int y) {
this(x, y, 16, 16);
}
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/de/mari_023/ae2wtlib/terminal/SingularityPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package de.mari_023.ae2wtlib.terminal;

import java.util.function.Supplier;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.Rect2i;

import appeng.api.upgrades.IUpgradeInventory;
import appeng.client.Point;
import appeng.client.gui.ICompositeWidget;
import appeng.menu.slot.AppEngSlot;

import de.mari_023.ae2wtlib.AE2wtlibItems;

public class SingularityPanel implements ICompositeWidget {
private final AppEngSlot singularity;
private final Supplier<IUpgradeInventory> upgrades;

// Relative to current screen origin (not window)
private int x;
private int y;

public SingularityPanel(AppEngSlot singularity, Supplier<IUpgradeInventory> upgrades) {
this.singularity = singularity;
this.upgrades = upgrades;
}

@Override
public boolean isVisible() {
boolean visible = !singularity.getItem().isEmpty()
|| upgrades.get().isInstalled(AE2wtlibItems.QUANTUM_BRIDGE_CARD);
singularity.setActive(visible);
return visible;
}

@Override
public void setPosition(Point position) {
x = position.getX();
y = position.getY();
singularity.x = x + 1;
singularity.y = y + 6;
}

@Override
public void setSize(int width, int height) {}

@Override
public Rect2i getBounds() {
return new Rect2i(x, y, Icon.SINGULARITY_BACKGROUND.width(), Icon.SINGULARITY_BACKGROUND.height());
}

@Override
public void drawBackgroundLayer(GuiGraphics guiGraphics, Rect2i bounds, Point mouse) {
Icon.SINGULARITY_BACKGROUND.getBlitter().dest(bounds.getX() + x, bounds.getY() + y).blit(guiGraphics);
}
}
3 changes: 1 addition & 2 deletions src/main/java/de/mari_023/ae2wtlib/wat/WATScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import appeng.client.gui.me.patternaccess.PatternAccessTermScreen;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.BackgroundPanel;
import appeng.client.gui.widgets.ToolboxPanel;
import appeng.menu.SlotSemantics;

Expand All @@ -23,7 +22,7 @@ public WATScreen(WATMenu container, Inventory playerInventory, Component title,
new ScrollingUpgradesPanel(menu.getSlots(SlotSemantics.UPGRADE), menu.getHost(), widgets));
if (getMenu().getToolbox().isPresent())
widgets.add("toolbox", new ToolboxPanel(style, getMenu().getToolbox().getName()));
widgets.add("singularityBackground", new BackgroundPanel(style.getImage("singularityBackground")));
addSingularityPanel(widgets, getMenu());
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/de/mari_023/ae2wtlib/wct/WCTScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import appeng.client.gui.me.items.CraftingTermScreen;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.BackgroundPanel;
import appeng.menu.SlotSemantics;

import de.mari_023.ae2wtlib.TextConstants;
Expand Down Expand Up @@ -39,7 +38,7 @@ public WCTScreen(WCTMenu container, Inventory playerInventory, Component title,
trashButton.setMessage(TextConstants.TRASH);

widgets.add("player", new PlayerEntityWidget(Objects.requireNonNull(Minecraft.getInstance().player)));
widgets.add("singularityBackground", new BackgroundPanel(style.getImage("singularityBackground")));
addSingularityPanel(widgets, getMenu());

widgets.add("scrollingUpgrades",
new ScrollingUpgradesPanel(menu.getSlots(SlotSemantics.UPGRADE), menu.getHost(), widgets));
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/de/mari_023/ae2wtlib/wet/WETScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import appeng.client.gui.me.items.PatternEncodingTermScreen;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.BackgroundPanel;
import appeng.menu.SlotSemantics;

import de.mari_023.ae2wtlib.terminal.ScrollingUpgradesPanel;
Expand All @@ -17,7 +16,7 @@ public WETScreen(WETMenu container, Inventory playerInventory, Component title,
super(container, playerInventory, title, style);
if (getMenu().isWUT())
addToLeftToolbar(cycleTerminalButton());
widgets.add("singularityBackground", new BackgroundPanel(style.getImage("singularityBackground")));
addSingularityPanel(widgets, getMenu());
widgets.add("scrollingUpgrades",
new ScrollingUpgradesPanel(menu.getSlots(SlotSemantics.UPGRADE), menu.getHost(), widgets));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import net.neoforged.neoforge.network.PacketDistributor;

import appeng.client.Hotkeys;
import appeng.client.gui.WidgetContainer;
import appeng.core.network.serverbound.HotkeyPacket;
import appeng.menu.AEBaseMenu;
import appeng.menu.slot.AppEngSlot;

import de.mari_023.ae2wtlib.AE2wtlibSlotSemantics;
import de.mari_023.ae2wtlib.TextConstants;
import de.mari_023.ae2wtlib.networking.CycleTerminalPacket;
import de.mari_023.ae2wtlib.terminal.IconButton;
import de.mari_023.ae2wtlib.terminal.SingularityPanel;
import de.mari_023.ae2wtlib.terminal.WTMenuHost;

public interface IUniversalTerminalCapable {
Expand Down Expand Up @@ -52,4 +57,16 @@ default IconButton cycleTerminalButton() {
return IconButton.withAE2Background(btn -> cycleTerminal(), next.icon())
.withTooltip(List.of(TextConstants.cycleNext(next), TextConstants.cyclePrevious(previous)));
}

/**
* creates and adds the background for the singularity
*
* @param widgets the WidgetContainer where the widget will be added
* @param menu the menu corresponding to this screen
*/
default void addSingularityPanel(WidgetContainer widgets, AEBaseMenu menu) {
widgets.add("singularity",
new SingularityPanel((AppEngSlot) menu.getSlots(AE2wtlibSlotSemantics.SINGULARITY).getFirst(),
() -> getHost().getUpgrades()));
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
{
"$schema": "schema.json",
"slots": {
"AE2WTLIB_SINGULARITY": {
"right": 1,
"top": 6
}
},
"images": {
"singularityBackground": {
"texture": "wtlib/guis/icons.png",
"textureWidth": 256,
"textureHeight": 256,
"srcRect": [
105,
98,
23,
30
]
}
},
"widgets": {
"scrollingUpgrades": {
"right": -1,
Expand All @@ -34,7 +15,7 @@
"left": -9999,
"top": -9999
},
"singularityBackground": {
"singularity": {
"right": 2,
"top": 0
}
Expand Down

0 comments on commit e13ebd9

Please sign in to comment.