Skip to content

Commit 982342e

Browse files
committed
Almost working drawing the static wire images
1 parent a4e6531 commit 982342e

File tree

9 files changed

+176
-4
lines changed

9 files changed

+176
-4
lines changed

src/main/java/gregtech/api/GTValues.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ public static boolean isDeobfEnvironment() {
192192
public static final int FALLBACK = -1;
193193

194194
public static BooleanSupplier FOOLS = () -> {
195-
String[] yearMonthDay = LocalDate.now().toString().split("-");
196-
return ConfigHolder.misc.specialEvents && yearMonthDay[1].equals("04") && yearMonthDay[2].equals("01");
195+
return true;
196+
// String[] yearMonthDay = LocalDate.now().toString().split("-");
197+
// return ConfigHolder.misc.specialEvents && yearMonthDay[1].equals("04") && yearMonthDay[2].equals("01");
197198
};
198199

199200
public static BooleanSupplier XMAS = () -> {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package gregtech.api.mui;
2+
3+
import gregtech.api.util.GTUtility;
4+
5+
import com.cleanroommc.modularui.theme.WidgetTheme;
6+
7+
public class ColorableTheme extends WidgetTheme {
8+
9+
protected int color = 0;
10+
11+
public ColorableTheme() {
12+
super(null, null, 0, 0, false);
13+
}
14+
15+
public void setColor(int color) {
16+
this.color = color;
17+
}
18+
19+
public void setColor(int a, int r, int g, int b) {
20+
setColor(GTUtility.combineRGB(a, r, g, b));
21+
}
22+
23+
@Override
24+
public int getColor() {
25+
return color;
26+
}
27+
}

src/main/java/gregtech/api/mui/GTGuiTextures.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,11 @@ private static String id(String path) {
646646
public static final UITexture SPEAKER_ICON = fullImage("textures/gui/widget/speaker.png");
647647
public static final UITexture MAINTENANCE_ICON = fullImage("textures/gui/widget/button_maintenance.png", true);
648648

649+
// Maintenance among us minigame textures
650+
public static final UITexture AMONG_US_BACKGROUND = fullImage("textures/gui/widget/among_us/background.png");
651+
public static final UITexture AMONG_US_WIRE_BASE = fullImage("textures/gui/widget/among_us/wire_base.png", true);
652+
public static final UITexture AMONG_US_WIRE = fullImage("textures/gui/widget/among_us/wire.png");
653+
649654
public static void init() {/**/}
650655

651656
private static UITexture fullImage(String path) {
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package gregtech.api.mui.widget;
2+
3+
import gregtech.api.GTValues;
4+
import gregtech.api.mui.ColorableTheme;
5+
import gregtech.api.mui.GTGuiTextures;
6+
import gregtech.api.util.GTUtility;
7+
8+
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
9+
import com.cleanroommc.modularui.theme.WidgetTheme;
10+
import com.cleanroommc.modularui.widget.Widget;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import java.util.function.BooleanSupplier;
14+
15+
public class AmongUsWiringTaskWidget extends Widget<AmongUsWiringTaskWidget> {
16+
17+
// Due to how UITextures are coded, they apply their own Color.setGlColor() from the theme right before drawing.
18+
private static final ColorableTheme colorableTheme = new ColorableTheme();
19+
20+
@NotNull
21+
private final Runnable onCompletion;
22+
@NotNull
23+
private final BooleanSupplier canInteract;
24+
25+
private static final int wireAmount = 4;
26+
private final int[] colors = new int[wireAmount];
27+
private final int[] rightSideIndexesMapping = new int[wireAmount];
28+
private final boolean[] connected = new boolean[wireAmount];
29+
private int wireBeingDragged = -1;
30+
31+
public AmongUsWiringTaskWidget(@NotNull BooleanSupplier canInteract, @NotNull Runnable onCompletion) {
32+
this.onCompletion = onCompletion;
33+
this.canInteract = canInteract;
34+
size(80, 50);
35+
background(GTGuiTextures.AMONG_US_BACKGROUND);
36+
37+
for (int index = 0; index < wireAmount; index++) {
38+
colors[index] = GTValues.RNG.nextInt() | 0xff000000;
39+
}
40+
41+
for (int index = 0; index < wireAmount; index++) {
42+
rightSideIndexesMapping[index] = index;
43+
}
44+
GTUtility.shuffle(rightSideIndexesMapping);
45+
}
46+
47+
@Override
48+
public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
49+
float xScale = 0.15873016f;
50+
float yScale = 0.09920635f;
51+
52+
for (int index = 0; index < wireAmount; index++) {
53+
double y1 = yScale * ((index + 1) * 104 - 10);
54+
int color = colors[index];
55+
if (connected[index]) {
56+
57+
}
58+
}
59+
60+
for (int index = 0; index < wireAmount; index++) {
61+
double y1 = yScale * ((index + 1) * 104 - 10);
62+
int color = colors[index];
63+
64+
if (index == wireBeingDragged) {
65+
// draw connecting line
66+
}
67+
68+
colorableTheme.setColor(color);
69+
GTGuiTextures.AMONG_US_WIRE_BASE.drawSubArea(
70+
(xScale * 25),
71+
(float) ((y1 - yScale) * 5.0f),
72+
(xScale * 38),
73+
(yScale * 32),
74+
0.0f,
75+
0.0f,
76+
0.5f,
77+
1.0f,
78+
colorableTheme);
79+
80+
GTGuiTextures.AMONG_US_WIRE.drawSubArea(
81+
0.0f,
82+
(float) y1,
83+
(xScale * 50),
84+
(yScale * 32),
85+
0.0f,
86+
0.0f,
87+
0.5f,
88+
1.0f,
89+
colorableTheme);
90+
91+
colorableTheme.setColor(colors[rightSideIndexesMapping[index]]);
92+
GTGuiTextures.AMONG_US_WIRE_BASE.drawSubArea(
93+
80 - (xScale * (25 + 38)),
94+
(float) y1 - yScale * 5,
95+
(xScale * 38), (yScale * 32),
96+
0.5f,
97+
0.0f,
98+
1.0f,
99+
1.0f,
100+
colorableTheme);
101+
102+
GTGuiTextures.AMONG_US_WIRE.drawSubArea(
103+
80 - (xScale * 50),
104+
(float) y1, (xScale * 50),
105+
(yScale * 32),
106+
0.5f,
107+
0.0f,
108+
1.0f,
109+
1.0f,
110+
colorableTheme);
111+
}
112+
}
113+
114+
@Override
115+
public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) {}
116+
}

src/main/java/gregtech/api/util/GTUtility.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,11 @@ public static int combineRGB(@Range(from = 0, to = 255) int r, @Range(from = 0,
10111011
return (r << 16) | (g << 8) | b;
10121012
}
10131013

1014+
public static int combineRGB(@Range(from = 0, to = 255) int a, @Range(from = 0, to = 255) int r,
1015+
@Range(from = 0, to = 255) int g, @Range(from = 0, to = 255) int b) {
1016+
return (a << 24) | (r << 16) | (g << 8) | b;
1017+
}
1018+
10141019
/**
10151020
* @param map the map to get from
10161021
* @param key the key to retrieve with
@@ -1104,4 +1109,19 @@ public static int argbLerp(int start, int end, float position) {
11041109

11051110
return (aFinal << 24) | (rFinal << 16) | (gFinal << 8) | bFinal;
11061111
}
1112+
1113+
/**
1114+
* Swaps int[a] with int[b].
1115+
*/
1116+
public static void swap(int[] swappingArray, int a, int b) {
1117+
int tmp = swappingArray[a];
1118+
swappingArray[a] = swappingArray[b];
1119+
swappingArray[b] = tmp;
1120+
}
1121+
1122+
public static void shuffle(int[] shufflingArray) {
1123+
for (int index = shufflingArray.length; index > 1; index--) {
1124+
swap(shufflingArray, index - 1, GTValues.RNG.nextInt(index));
1125+
}
1126+
}
11071127
}

src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import gregtech.api.metatileentity.multiblock.*;
1111
import gregtech.api.mui.GTGuiTextures;
1212
import gregtech.api.mui.GTGuis;
13+
import gregtech.api.mui.widget.AmongUsWiringTaskWidget;
1314
import gregtech.api.util.GTUtility;
1415
import gregtech.client.renderer.texture.Textures;
1516
import gregtech.client.utils.TooltipHelper;
@@ -366,8 +367,10 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManage
366367
.child(IKey.lang(getMetaFullName())
367368
.asWidget()
368369
.pos(5, 5))
369-
// TODO: amongus
370-
// .childIf(!isConfigurable && wiringMinigame.getBoolValue(), () -> new FixWiringTaskWidgetButMUI2())
370+
.childIf(!isConfigurable && wiringMinigameSync.getBoolValue(),
371+
() -> new AmongUsWiringTaskWidget(this::isAttachedToMultiBlock,
372+
() -> ((IMaintenance) getController()).fixAllMaintenance())
373+
.pos(48, 15))
371374
.childIf(!wiringMinigameSync.getBoolValue(), () -> Flow.column()
372375
.top(17)
373376
.widthRel(1.0f)
60.1 KB
Loading
4.87 KB
Loading
1.78 KB
Loading

0 commit comments

Comments
 (0)