Skip to content

Commit 8da6d7a

Browse files
Add Widget to show cover functional status
Three separate indicators. Need better names for everything
1 parent 59cf924 commit 8da6d7a

File tree

7 files changed

+133
-0
lines changed

7 files changed

+133
-0
lines changed

src/main/java/gregtech/api/gui/GuiTextures.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class GuiTextures {
4545
//WIDGET UI RELATED
4646
public static final TextureArea SLIDER_BACKGROUND = TextureArea.fullImage("textures/gui/widget/slider_background.png");
4747
public static final TextureArea SLIDER_ICON = TextureArea.fullImage("textures/gui/widget/slider.png");
48+
public static final TextureArea DIAGNOSE_IDLING = TextureArea.fullImage("textures/gui/widget/idling.png");
49+
public static final TextureArea DIAGNOSE_WORKING = TextureArea.fullImage("textures/gui/widget/working.png");
50+
public static final TextureArea DIAGNOSE_ISSUE =TextureArea.fullImage("textures/gui/widget/issue.png");
4851

4952
//BRONZE
5053
public static final TextureArea BRONZE_BACKGROUND = TextureArea.fullImage("textures/gui/steam/bronze/bronze_gui.png");
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package gregtech.api.gui.widgets;
2+
3+
import com.sun.jna.platform.win32.Guid;
4+
import gregtech.api.gui.GuiTextures;
5+
import gregtech.api.gui.IRenderContext;
6+
import gregtech.api.gui.Widget;
7+
import gregtech.api.gui.resources.TextureArea;
8+
import gregtech.api.util.GTUtility;
9+
import gregtech.api.util.Position;
10+
import gregtech.api.util.Size;
11+
import net.minecraft.client.resources.I18n;
12+
import net.minecraft.item.ItemStack;
13+
import net.minecraft.network.PacketBuffer;
14+
import net.minecraft.util.IStringSerializable;
15+
import net.minecraftforge.fml.relauncher.Side;
16+
import net.minecraftforge.fml.relauncher.SideOnly;
17+
18+
import java.util.Collections;
19+
import java.util.function.IntSupplier;
20+
import java.util.function.Supplier;
21+
22+
23+
public class DiagnoseWidget extends Widget {
24+
25+
private final String[] issueNames;
26+
private IntSupplier currentIssue;
27+
protected String tooltipHoverString;
28+
protected long hoverStartTime = -1L;
29+
protected boolean isMouseHovered;
30+
protected int currentError;
31+
32+
protected TextureArea area;
33+
private boolean isVisible = true;
34+
35+
public <T extends Enum<T> & IStringSerializable> DiagnoseWidget(int xPosition, int yPosition, int width, int height, Class<T> enumClass, Supplier<T> supplier) {
36+
super(new Position(xPosition, yPosition), new Size(width, height));
37+
T[] enumConstantPool = enumClass.getEnumConstants();
38+
this.issueNames = GTUtility.mapToString(enumConstantPool, it -> ((IStringSerializable) it).getName());
39+
this.currentIssue = () -> supplier.get().ordinal();
40+
setImage();
41+
}
42+
43+
public void setTooltipHoverString() {
44+
this.tooltipHoverString = I18n.format(issueNames[currentError]);
45+
}
46+
47+
public DiagnoseWidget setImage() {
48+
if (currentError == 0) {
49+
this.area = GuiTextures.DIAGNOSE_IDLING;
50+
}
51+
if (currentError == 1) {
52+
this.area = GuiTextures.DIAGNOSE_WORKING;
53+
}
54+
else if (currentError > 1) {
55+
this.area = GuiTextures.DIAGNOSE_ISSUE;
56+
}
57+
return this;
58+
}
59+
60+
@Override
61+
public void detectAndSendChanges() {
62+
super.detectAndSendChanges();
63+
if (currentIssue.getAsInt() != currentError) {
64+
this.currentError = currentIssue.getAsInt();
65+
writeUpdateInfo(1, buf -> buf.writeVarInt(currentError));
66+
}
67+
}
68+
69+
@Override
70+
public void readUpdateInfo(int id, PacketBuffer buffer) {
71+
super.readUpdateInfo(id, buffer);
72+
if (id == 1) {
73+
this.currentError = buffer.readVarInt();
74+
setImage();
75+
}
76+
}
77+
78+
@Override
79+
@SideOnly(Side.CLIENT)
80+
public void drawInForeground(int mouseX, int mouseY) {
81+
boolean isHovered = isMouseOverElement(mouseX, mouseY);
82+
boolean wasHovered = isMouseHovered;
83+
if (isHovered && !wasHovered) {
84+
this.isMouseHovered = true;
85+
this.hoverStartTime = System.currentTimeMillis();
86+
} else if (!isHovered && wasHovered) {
87+
this.isMouseHovered = false;
88+
this.hoverStartTime = 0L;
89+
} else if (isHovered) {
90+
long timeSinceHover = System.currentTimeMillis() - hoverStartTime;
91+
setTooltipHoverString();
92+
if (timeSinceHover > 1000L && tooltipHoverString != null) {
93+
drawHoveringText(ItemStack.EMPTY, Collections.singletonList(tooltipHoverString), 300, mouseX, mouseY);
94+
}
95+
}
96+
}
97+
98+
@Override
99+
@SideOnly(Side.CLIENT)
100+
public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
101+
if (!this.isVisible || area == null) return;
102+
Position position = getPosition();
103+
Size size = getSize();
104+
area.draw(position.x, position.y, size.width, size.height);
105+
}
106+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package gregtech.common.covers;
2+
3+
import net.minecraft.util.IStringSerializable;
4+
5+
public enum DiagnoseIssue implements IStringSerializable {
6+
7+
IDLING("cover.universal.diagnose.issue.idling"),
8+
WORKING("cover.universal.diagnose.issue.working"),
9+
EXPECTED_CAPABILITY_UNAVAILABLE("cover.universal.diagnose.issue.expected_capability_unavailable");
10+
11+
public final String localeName;
12+
13+
DiagnoseIssue(String localeName) {
14+
this.localeName = localeName;
15+
}
16+
17+
@Override
18+
public String getName() {
19+
return localeName;
20+
}
21+
}

src/main/resources/assets/gregtech/lang/en_us.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,9 @@ cover.conveyor.title=Conveyor Cover Settings (%s)
706706
cover.conveyor.transfer_rate=%s items/sec
707707
cover.conveyor.mode.export=Mode: Export
708708
cover.conveyor.mode.import=Mode: Import
709+
cover.universal.diagnose.issue.idling=This cover is idling
710+
cover.universal.diagnose.issue.working=This cover is working without issue
711+
cover.universal.diagnose.issue.expected_capability_unavailable=This cover currently cant access this inventory from this side. No work will be done.
709712
cover.universal.manual_import_export.mode.disabled=Manual I/O: Disabled
710713
cover.universal.manual_import_export.mode.filtered=Manual I/O: Filtered
711714
cover.universal.manual_import_export.mode.unfiltered=Manual I/O: Unfiltered
1.43 KB
Loading
1.84 KB
Loading
1.78 KB
Loading

0 commit comments

Comments
 (0)