-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathGTGuis.java
More file actions
186 lines (151 loc) · 6.29 KB
/
GTGuis.java
File metadata and controls
186 lines (151 loc) · 6.29 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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;
import org.jetbrains.annotations.Nullable;
public class GTGuis {
public static final int DEFAULT_WIDTH = 176, DEFAULT_HEIGHT = 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_HEIGHT);
}
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_HEIGHT);
}
public static ModularPanel defaultPanel(MetaItem<?>.MetaValueItem valueItem) {
return createPanel(valueItem.unlocalizedName);
}
public static PopupPanel createPopupPanel(String name, int width, int height) {
return defaultPopupPanel(name)
.size(width, height);
}
public static PopupPanel createPopupPanel(String name, int width, int height, boolean deleteCachedPanel) {
return createPopupPanel(name, width, height)
.deleteCachedPanel(deleteCachedPanel);
}
public static PopupPanel defaultPopupPanel(String name) {
return new PopupPanel(name, true)
.size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
public static PopupPanel blankPopupPanel(String name, int width, int height) {
return new PopupPanel(name, false)
.size(width, height);
}
public static PopupPanel blankPopupPanel(String name) {
return blankPopupPanel(name, DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
public static PopupPanel defaultPopupPanel(String name, boolean disableBelow,
boolean closeOnOutsideClick, boolean deleteCachedPanel) {
return defaultPopupPanel(name)
.disablePanelsBelow(disableBelow)
.closeOnOutOfBoundsClick(closeOnOutsideClick)
.deleteCachedPanel(deleteCachedPanel);
}
public static class PopupPanel extends ModularPanel {
private boolean disableBelow;
private boolean closeOnOutsideClick;
private boolean deleteCachedPanel;
@Nullable
private Runnable closeListener;
private PopupPanel(@NotNull String name, boolean addCloseButton) {
super(name);
align(Alignment.Center);
background(GTGuiTextures.BACKGROUND_POPUP);
childIf(addCloseButton, () -> ButtonWidget.panelCloseButton()
.top(5).right(5)
.onMousePressed(mouseButton -> {
if (mouseButton == 0 || mouseButton == 1) {
closeIfOpen();
return true;
}
return false;
}));
}
@Override
public void onClose() {
super.onClose();
if (deleteCachedPanel && isSynced() && getSyncHandler() instanceof IPanelHandler handler) {
handler.deleteCachedPanel();
}
if (closeListener != null) {
closeListener.run();
}
}
public PopupPanel disablePanelsBelow(boolean disableBelow) {
this.disableBelow = disableBelow;
return this;
}
public PopupPanel closeOnOutOfBoundsClick(boolean closeOnOutsideClick) {
this.closeOnOutsideClick = closeOnOutsideClick;
return this;
}
public PopupPanel deleteCachedPanel(boolean deleteCachedPanel) {
this.deleteCachedPanel = deleteCachedPanel;
return this;
}
@Override
public PopupPanel size(int w, int h) {
super.size(w, h);
return this;
}
@Override
public PopupPanel size(int val) {
super.size(val);
return this;
}
@Override
public boolean disablePanelsBelow() {
return disableBelow;
}
@Override
public boolean closeOnOutOfBoundsClick() {
return closeOnOutsideClick;
}
public PopupPanel closeListener(@Nullable Runnable closeListener) {
this.closeListener = closeListener;
return this;
}
}
}