-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathGTGuis.java
More file actions
128 lines (104 loc) · 4.87 KB
/
GTGuis.java
File metadata and controls
128 lines (104 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package gregtech.api.mui;
import gregtech.api.cover.Cover;
import gregtech.api.items.metaitem.MetaItem;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.mui.factory.CoverGuiFactory;
import gregtech.api.mui.factory.MetaItemGuiFactory;
import gregtech.api.mui.factory.MetaTileEntityGuiFactory;
import net.minecraft.item.ItemStack;
import com.cleanroommc.modularui.api.IPanelHandler;
import com.cleanroommc.modularui.factory.GuiManager;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Alignment;
import com.cleanroommc.modularui.widgets.ButtonWidget;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
public class GTGuis {
public static final int DEFAULT_WIDTH = 176, DEFAULT_HIEGHT = 166;
@ApiStatus.Internal
public static void registerFactories() {
GuiManager.registerFactory(MetaTileEntityGuiFactory.INSTANCE);
GuiManager.registerFactory(MetaItemGuiFactory.INSTANCE);
GuiManager.registerFactory(CoverGuiFactory.INSTANCE);
}
public static ModularPanel createPanel(String name, int width, int height) {
return ModularPanel.defaultPanel(name, width, height);
}
public static ModularPanel createPanel(MetaTileEntity mte, int width, int height) {
return createPanel(mte.metaTileEntityId.getPath(), width, height);
}
public static ModularPanel createPanel(Cover cover, int width, int height) {
return createPanel(cover.getDefinition().getResourceLocation().getPath(), width, height);
}
public static ModularPanel createPanel(ItemStack stack, int width, int height) {
String locale;
if (stack.getItem() instanceof MetaItem<?>metaItem) {
var valueItem = metaItem.getItem(stack);
if (valueItem == null) throw new IllegalArgumentException("Item must be a meta item!");
locale = valueItem.unlocalizedName;
} else {
locale = stack.getTranslationKey();
}
return createPanel(locale, width, height);
}
public static ModularPanel createPanel(String name) {
return ModularPanel.defaultPanel(name, DEFAULT_WIDTH, DEFAULT_HIEGHT);
}
public static ModularPanel defaultPanel(MetaTileEntity mte) {
return createPanel(mte.metaTileEntityId.getPath());
}
public static ModularPanel defaultPanel(Cover cover) {
return createPanel(cover.getDefinition().getResourceLocation().getPath());
}
public static ModularPanel defaultPanel(ItemStack stack) {
return createPanel(stack, DEFAULT_WIDTH, DEFAULT_HIEGHT);
}
public static ModularPanel defaultPanel(MetaItem<?>.MetaValueItem valueItem) {
return createPanel(valueItem.unlocalizedName);
}
public static ModularPanel createPopupPanel(String name, int width, int height) {
return createPopupPanel(name, width, height, false, false);
}
public static ModularPanel createPopupPanel(String name, int width, int height, boolean disableBelow,
boolean closeOnOutsideClick) {
return new PopupPanel(name, width, height, disableBelow, closeOnOutsideClick);
}
public static ModularPanel defaultPopupPanel(String name) {
return defaultPopupPanel(name, false, false);
}
public static ModularPanel defaultPopupPanel(String name, boolean disableBelow,
boolean closeOnOutsideClick) {
return new PopupPanel(name, DEFAULT_WIDTH, DEFAULT_HIEGHT, disableBelow, closeOnOutsideClick);
}
private static class PopupPanel extends ModularPanel {
private final boolean disableBelow;
private final boolean closeOnOutsideClick;
public PopupPanel(@NotNull String name, int width, int height, boolean disableBelow,
boolean closeOnOutsideClick) {
super(name);
size(width, height).align(Alignment.Center);
background(GTGuiTextures.BACKGROUND_POPUP);
child(ButtonWidget.panelCloseButton().top(5).right(5)
.onMousePressed(mouseButton -> {
if (mouseButton == 0 || mouseButton == 1) {
this.closeIfOpen(true);
if (isSynced() && getSyncHandler() instanceof IPanelHandler handler) {
handler.deleteCachedPanel();
}
return true;
}
return false;
}));
this.disableBelow = disableBelow;
this.closeOnOutsideClick = closeOnOutsideClick;
}
@Override
public boolean disablePanelsBelow() {
return disableBelow;
}
@Override
public boolean closeOnOutOfBoundsClick() {
return closeOnOutsideClick;
}
}
}