-
-
Notifications
You must be signed in to change notification settings - Fork 504
/
GuiMekanism.java
601 lines (544 loc) · 26.5 KB
/
GuiMekanism.java
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
package mekanism.client.gui;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import mekanism.api.text.ILangEntry;
import mekanism.client.gui.element.GuiElement;
import mekanism.client.gui.element.GuiElement.IHoverable;
import mekanism.client.gui.element.slot.GuiSlot;
import mekanism.client.gui.element.slot.GuiVirtualSlot;
import mekanism.client.gui.element.slot.SlotType;
import mekanism.client.gui.element.tab.GuiWarningTab;
import mekanism.client.gui.element.window.GuiWindow;
import mekanism.client.gui.warning.IWarningTracker;
import mekanism.client.gui.warning.WarningTracker;
import mekanism.client.gui.warning.WarningTracker.WarningType;
import mekanism.client.render.IFancyFontRenderer;
import mekanism.client.render.MekanismRenderer;
import mekanism.common.Mekanism;
import mekanism.common.inventory.container.MekanismContainer;
import mekanism.common.inventory.container.SelectedWindowData;
import mekanism.common.inventory.container.slot.ContainerSlotType;
import mekanism.common.inventory.container.slot.IVirtualSlot;
import mekanism.common.inventory.container.slot.InventoryContainerSlot;
import mekanism.common.inventory.container.slot.SlotOverlay;
import mekanism.common.inventory.container.tile.MekanismTileContainer;
import mekanism.common.lib.collection.LRU;
import mekanism.common.tile.base.TileEntityMekanism;
import mekanism.common.tile.component.config.DataType;
import mekanism.common.tile.interfaces.ISideConfiguration;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import org.apache.commons.lang3.tuple.Pair;
//TODO: Add our own "addButton" type thing for elements that are just "drawn" but don't actually have any logic behind them
public abstract class GuiMekanism<CONTAINER extends Container> extends VirtualSlotContainerScreen<CONTAINER> implements IGuiWrapper, IFancyFontRenderer {
public static final ResourceLocation BASE_BACKGROUND = MekanismUtils.getResource(ResourceType.GUI, "base.png");
public static final ResourceLocation SHADOW = MekanismUtils.getResource(ResourceType.GUI, "shadow.png");
public static final ResourceLocation BLUR = MekanismUtils.getResource(ResourceType.GUI, "blur.png");
//TODO: Look into defaulting this to true
protected boolean dynamicSlots;
protected final LRU<GuiWindow> windows = new LRU<>();
protected final List<GuiElement> focusListeners = new ArrayList<>();
public boolean switchingToJEI;
@Nullable
private IWarningTracker warningTracker;
private boolean hasClicked = false;
public static int maxZOffset;
protected GuiMekanism(CONTAINER container, PlayerInventory inv, ITextComponent title) {
super(container, inv, title);
}
@Nonnull
@Override
public BooleanSupplier trackWarning(@Nonnull WarningType type, @Nonnull BooleanSupplier warningSupplier) {
if (warningTracker == null) {
warningTracker = new WarningTracker();
}
return warningTracker.trackWarning(type, warningSupplier);
}
@Override
public void removed() {
if (!switchingToJEI) {
//If we are not switching to JEI then run the super close method
// which will exit the container. We don't want to mark the
// container as exited if it will be revived when leaving JEI
super.removed();
}
}
@Override
public void init() {
super.init();
if (warningTracker != null) {
//If our warning tracker isn't null (so this isn't the first time we are initializing, such as after resizing)
// clear out any tracked warnings so we don't have duplicates being tracked when we add our elements again
warningTracker.clearTrackedWarnings();
}
addGuiElements();
if (warningTracker != null) {
//If we have a warning tracker add it as a button, we do so via a method in case any of the sub GUIs need to reposition where it ends up
addWarningTab(warningTracker);
}
}
protected void addWarningTab(IWarningTracker warningTracker) {
//TODO - WARNING SYSTEM: Move this for any GUIs that also have a heat tab (81 y would be above heat)
addButton(new GuiWarningTab(this, warningTracker, 109));
}
/**
* Called to add gui elements to the GUI. Add elements before calling super if they should be before the slots, and after if they should be after the slots. Most
* elements can and should be added after the slots.
*/
protected void addGuiElements() {
if (dynamicSlots) {
addSlots();
}
}
@Override
public void tick() {
super.tick();
children.stream().filter(child -> child instanceof GuiElement).map(child -> (GuiElement) child).forEach(GuiElement::tick);
windows.forEach(GuiWindow::tick);
}
protected IHoverable getOnHover(ILangEntry translationHelper) {
return getOnHover((Supplier<ITextComponent>) translationHelper::translate);
}
protected IHoverable getOnHover(Supplier<ITextComponent> componentSupplier) {
return (onHover, matrix, xAxis, yAxis) -> displayTooltip(matrix, componentSupplier.get(), xAxis, yAxis);
}
protected ResourceLocation getButtonLocation(String name) {
return MekanismUtils.getResource(ResourceType.GUI_BUTTON, name + ".png");
}
@Override
public void addFocusListener(GuiElement element) {
focusListeners.add(element);
}
@Override
public void removeFocusListener(GuiElement element) {
focusListeners.remove(element);
}
@Override
public void focusChange(GuiElement changed) {
focusListeners.stream().filter(e -> e != changed).forEach(e -> e.setFocused(false));
}
@Override
public void incrementFocus(GuiElement current) {
int index = focusListeners.indexOf(current);
if (index != -1) {
GuiElement next = focusListeners.get((index + 1) % focusListeners.size());
next.setFocused(true);
focusChange(next);
}
}
@Override
protected boolean hasClickedOutside(double mouseX, double mouseY, int guiLeftIn, int guiTopIn, int mouseButton) {
return getWindowHovering(mouseX, mouseY) == null && super.hasClickedOutside(mouseX, mouseY, guiLeftIn, guiTopIn, mouseButton);
}
@Override
public void init(@Nonnull Minecraft minecraft, int width, int height) {
//Mark that we are not switching to JEI if we start being initialized again
switchingToJEI = false;
//Note: We are forced to do the logic that normally would be inside the "resize" method
// here in init, as when mods like JEI take over the screen to show recipes, and then
// return the screen to the "state" it was beforehand it does not actually properly
// transfer the state from the previous instance to the new instance. If we run the
// code we normally would run for when things get resized, we then are able to
// properly reinstate/transfer the states of the various elements
List<Pair<Integer, GuiElement>> prevElements = new ArrayList<>();
for (int i = 0; i < buttons.size(); i++) {
Widget widget = buttons.get(i);
if (widget instanceof GuiElement && ((GuiElement) widget).hasPersistentData()) {
prevElements.add(Pair.of(i, (GuiElement) widget));
}
}
// flush the focus listeners list unless it's an overlay
focusListeners.removeIf(element -> !element.isOverlay);
int prevLeft = leftPos, prevTop = topPos;
super.init(minecraft, width, height);
windows.forEach(window -> {
window.resize(prevLeft, prevTop, leftPos, topPos);
children.add(window);
});
prevElements.forEach(e -> {
if (e.getLeft() < buttons.size()) {
Widget widget = buttons.get(e.getLeft());
// we're forced to assume that the children list is the same before and after the resize.
// for verification, we run a lightweight class equality check
// Note: We do not perform an instance check on widget to ensure it is a GuiElement, as that is
// ensured by the class comparison, and the restrictions of what can go in prevElements
if (widget.getClass() == e.getRight().getClass()) {
((GuiElement) widget).syncFrom(e.getRight());
}
}
});
}
@Override
protected void renderLabels(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
matrix.translate(0, 0, 300);
RenderSystem.translatef(-leftPos, -topPos, 0);
children().stream().filter(c -> c instanceof GuiElement).forEach(c -> ((GuiElement) c).onDrawBackground(matrix, mouseX, mouseY, MekanismRenderer.getPartialTick()));
RenderSystem.translatef(leftPos, topPos, 0);
drawForegroundText(matrix, mouseX, mouseY);
int xAxis = mouseX - leftPos;
int yAxis = mouseY - topPos;
// first render general foregrounds
maxZOffset = 200;
int zOffset = 200;
for (Widget widget : this.buttons) {
if (widget instanceof GuiElement) {
matrix.pushPose();
((GuiElement) widget).onRenderForeground(matrix, mouseX, mouseY, zOffset, zOffset);
matrix.popPose();
}
}
// now render overlays in reverse-order (i.e. back to front)
zOffset = maxZOffset;
for (LRU<GuiWindow>.LRUIterator iter = getWindowsDescendingIterator(); iter.hasNext(); ) {
GuiWindow overlay = iter.next();
zOffset += 150;
matrix.pushPose();
overlay.onRenderForeground(matrix, mouseX, mouseY, zOffset, zOffset);
if (iter.hasNext()) {
// if this isn't the focused window, render a 'blur' effect over it
overlay.renderBlur(matrix);
}
matrix.popPose();
}
// then render tooltips, translating above max z offset to prevent clashing
GuiElement tooltipElement = getWindowHovering(mouseX, mouseY);
if (tooltipElement == null) {
for (int i = buttons.size() - 1; i >= 0; i--) {
Widget widget = buttons.get(i);
if (widget instanceof GuiElement && widget.isMouseOver(mouseX, mouseY)) {
tooltipElement = (GuiElement) widget;
break;
}
}
}
// translate forwards using RenderSystem. this should never have to happen as we do all the necessary translations with MatrixStacks,
// but Minecraft has decided to not fully adopt MatrixStacks for many crucial ContainerScreen render operations. should be re-evaluated
// when mc updates related logic on their end (IMPORTANT)
RenderSystem.translatef(0, 0, maxZOffset);
if (tooltipElement != null) {
tooltipElement.renderToolTip(matrix, xAxis, yAxis);
}
// render item tooltips
RenderSystem.translatef(-leftPos, -topPos, 0);
renderTooltip(matrix, mouseX, mouseY);
RenderSystem.translatef(leftPos, topPos, 0);
// IMPORTANT: additional hacky translation so held items render okay. re-evaluate as discussed above
RenderSystem.translatef(0, 0, 200);
}
protected void drawForegroundText(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
}
@Nonnull
@Override
public Optional<IGuiEventListener> getChildAt(double mouseX, double mouseY) {
GuiWindow window = getWindowHovering(mouseX, mouseY);
return window != null ? Optional.of(window) : super.getChildAt(mouseX, mouseY);
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
hasClicked = true;
// first try to send the mouse event to our overlays
GuiWindow top = windows.isEmpty() ? null : windows.iterator().next();
GuiWindow focused = windows.stream().filter(overlay -> overlay.mouseClicked(mouseX, mouseY, button)).findFirst().orElse(null);
if (focused != null) {
if (windows.contains(focused)) {
//Validate that the focused window is still one of our windows, as if it wasn't focused/on top and
// it is being closed, we don't want to update and mark it as focused, as our defocusing code won't
// run as we ran it when we pressed the button
setFocused(focused);
if (button == 0) {
setDragging(true);
}
// this check prevents us from moving the window to the top of the stack if the clicked window opened up an additional window
if (top != focused) {
top.onFocusLost();
windows.moveUp(focused);
focused.onFocused();
}
}
return true;
}
// otherwise we send it to the current element
for (int i = buttons.size() - 1; i >= 0; i--) {
IGuiEventListener listener = buttons.get(i);
if (listener.mouseClicked(mouseX, mouseY, button)) {
setFocused(listener);
if (button == 0) {
setDragging(true);
}
return true;
}
}
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
if (hasClicked) {
// always pass mouse released events to windows for drag checks
windows.forEach(w -> w.onRelease(mouseX, mouseY));
return super.mouseReleased(mouseX, mouseY, button);
}
return false;
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return windows.stream().anyMatch(window -> window.keyPressed(keyCode, scanCode, modifiers)) ||
GuiUtils.checkChildren(buttons, child -> child.keyPressed(keyCode, scanCode, modifiers)) || super.keyPressed(keyCode, scanCode, modifiers);
}
@Override
public boolean charTyped(char c, int keyCode) {
return windows.stream().anyMatch(window -> window.charTyped(c, keyCode)) || GuiUtils.checkChildren(buttons, child -> child.charTyped(c, keyCode)) ||
super.charTyped(c, keyCode);
}
/**
* @apiNote mouseXOld and mouseYOld are just guessed mappings I couldn't find any usage from a quick glance.
*/
@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double mouseXOld, double mouseYOld) {
super.mouseDragged(mouseX, mouseY, button, mouseXOld, mouseYOld);
return getFocused() != null && isDragging() && button == 0 && getFocused().mouseDragged(mouseX, mouseY, button, mouseXOld, mouseYOld);
}
@Nullable
@Override
@Deprecated//Don't use directly, this is normally private in ContainerScreen
protected Slot findSlot(double mouseX, double mouseY) {
//We override the implementation we have in VirtualSlotContainerScreen so that we can cache getting our window
// and have some general performance improvements given we can batch a bunch of lookups together
boolean checkedWindow = false;
boolean overNoButtons = false;
GuiWindow window = null;
for (Slot slot : menu.slots) {
boolean virtual = slot instanceof IVirtualSlot;
int xPos = slot.x;
int yPos = slot.y;
if (virtual) {
//Virtual slots need special handling to allow for matching them to the window they may be attached to
IVirtualSlot virtualSlot = (IVirtualSlot) slot;
xPos = virtualSlot.getActualX();
yPos = virtualSlot.getActualY();
}
if (super.isHovering(xPos, yPos, 16, 16, mouseX, mouseY)) {
if (!checkedWindow) {
//Only lookup the window once
checkedWindow = true;
window = getWindowHovering(mouseX, mouseY);
overNoButtons = overNoButtons(window, mouseX, mouseY);
}
if (overNoButtons && slot.isActive()) {
if (window == null) {
return slot;
} else if (virtual && window.childrenContainsElement(element ->
element instanceof GuiVirtualSlot && ((GuiVirtualSlot) element).isElementForSlot((IVirtualSlot) slot))) {
return slot;
}
}
}
}
return null;
}
@Override
protected boolean isMouseOverSlot(@Nonnull Slot slot, double mouseX, double mouseY) {
if (slot instanceof IVirtualSlot) {
//Virtual slots need special handling to allow for matching them to the window they may be attached to
IVirtualSlot virtualSlot = (IVirtualSlot) slot;
int xPos = virtualSlot.getActualX();
int yPos = virtualSlot.getActualY();
if (super.isHovering(xPos, yPos, 16, 16, mouseX, mouseY)) {
GuiWindow window = getWindowHovering(mouseX, mouseY);
//If we are hovering over a window, check if the virtual slot is a child of the window
if (window == null || window.childrenContainsElement(element -> element instanceof GuiVirtualSlot && ((GuiVirtualSlot) element).isElementForSlot(virtualSlot))) {
return overNoButtons(window, mouseX, mouseY);
}
}
return false;
}
return isHovering(slot.x, slot.y, 16, 16, mouseX, mouseY);
}
private boolean overNoButtons(@Nullable GuiWindow window, double mouseX, double mouseY) {
if (window == null) {
return buttons.stream().noneMatch(button -> button.isMouseOver(mouseX, mouseY));
}
return !window.childrenContainsElement(e -> e.isMouseOver(mouseX, mouseY));
}
@Override
protected boolean isHovering(int x, int y, int width, int height, double mouseX, double mouseY) {
// overridden to prevent slot interactions when a GuiElement is blocking
return super.isHovering(x, y, width, height, mouseX, mouseY) && getWindowHovering(mouseX, mouseY) == null &&
overNoButtons(null, mouseX, mouseY);
}
protected void addSlots() {
int size = menu.slots.size();
for (int i = 0; i < size; i++) {
Slot slot = menu.slots.get(i);
if (slot instanceof InventoryContainerSlot) {
InventoryContainerSlot containerSlot = (InventoryContainerSlot) slot;
ContainerSlotType slotType = containerSlot.getSlotType();
DataType dataType = findDataType(containerSlot);
//Shift the slots by one as the elements include the border of the slot
SlotType type;
if (dataType != null) {
type = SlotType.get(dataType);
} else if (slotType == ContainerSlotType.INPUT || slotType == ContainerSlotType.OUTPUT || slotType == ContainerSlotType.EXTRA) {
type = SlotType.NORMAL;
} else if (slotType == ContainerSlotType.POWER) {
type = SlotType.POWER;
} else if (slotType == ContainerSlotType.NORMAL || slotType == ContainerSlotType.VALIDITY) {
type = SlotType.NORMAL;
} else {//slotType == ContainerSlotType.IGNORED: don't do anything
continue;
}
GuiSlot guiSlot = new GuiSlot(type, this, slot.x - 1, slot.y - 1);
SlotOverlay slotOverlay = containerSlot.getSlotOverlay();
if (slotOverlay != null) {
guiSlot.with(slotOverlay);
}
if (slotType == ContainerSlotType.VALIDITY) {
int index = i;
guiSlot.validity(() -> checkValidity(index));
}
addButton(guiSlot);
} else {
addButton(new GuiSlot(SlotType.NORMAL, this, slot.x - 1, slot.y - 1));
}
}
}
@Nullable
protected DataType findDataType(InventoryContainerSlot slot) {
if (menu instanceof MekanismTileContainer) {
TileEntityMekanism tileEntity = ((MekanismTileContainer<?>) menu).getTileEntity();
if (tileEntity instanceof ISideConfiguration) {
return ((ISideConfiguration) tileEntity).getActiveDataType(slot.getInventorySlot());
}
}
return null;
}
protected ItemStack checkValidity(int slotIndex) {
return ItemStack.EMPTY;
}
@Override
protected void renderBg(@Nonnull MatrixStack matrix, float partialTick, int mouseX, int mouseY) {
//Ensure the GL color is white as mods adding an overlay (such as JEI for bookmarks), might have left
// it in an unexpected state.
MekanismRenderer.resetColor();
if (width < 8 || height < 8) {
Mekanism.logger.warn("Gui: {}, was too small to draw the background of. Unable to draw a background for a gui smaller than 8 by 8.", getClass().getSimpleName());
return;
}
GuiUtils.renderBackgroundTexture(matrix, BASE_BACKGROUND, 4, 4, leftPos, topPos, imageWidth, imageHeight, 256, 256);
}
@Override
public FontRenderer getFont() {
return font;
}
@Override
public void render(@Nonnull MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
// shift back a whole lot so we can stack more windows
RenderSystem.translated(0, 0, -500);
matrix.pushPose();
renderBackground(matrix);
//Apply our matrix stack to the render system and pass an unmodified one to the super method
// Vanilla still renders the items into the GUI using render system transformations so this
// is required to not have tooltips of GuiElements rendering behind the items
super.render(matrix, mouseX, mouseY, partialTicks);
matrix.popPose();
RenderSystem.translated(0, 0, 500);
}
@Override
public void renderItemTooltip(MatrixStack matrix, @Nonnull ItemStack stack, int xAxis, int yAxis) {
renderTooltip(matrix, stack, xAxis, yAxis);
}
@Override
public void renderItemTooltipWithExtra(MatrixStack matrix, @Nonnull ItemStack stack, int xAxis, int yAxis, List<ITextComponent> toAppend) {
if (toAppend.isEmpty()) {
renderItemTooltip(matrix, stack, xAxis, yAxis);
} else {
FontRenderer font = stack.getItem().getFontRenderer(stack);
net.minecraftforge.fml.client.gui.GuiUtils.preItemToolTip(stack);
List<ITextComponent> tooltip = new ArrayList<>(getTooltipFromItem(stack));
tooltip.addAll(toAppend);
renderWrappedToolTip(matrix, tooltip, xAxis, yAxis, (font == null ? this.font : font));
net.minecraftforge.fml.client.gui.GuiUtils.postItemToolTip();
}
}
@Override
public ItemRenderer getItemRenderer() {
return itemRenderer;
}
@Override
public boolean currentlyQuickCrafting() {
return isQuickCrafting && !quickCraftSlots.isEmpty();
}
@Override
public void addWindow(GuiWindow window) {
GuiWindow top = windows.isEmpty() ? null : windows.iterator().next();
if (top != null) {
top.onFocusLost();
}
windows.add(window);
window.onFocused();
}
@Override
public void removeWindow(GuiWindow window) {
if (!windows.isEmpty()) {
GuiWindow top = windows.iterator().next();
windows.remove(window);
if (window == top) {
//If the window was the top window, make it lose focus
window.onFocusLost();
//Amd check if a new window is now in focus
GuiWindow newTop = windows.isEmpty() ? null : windows.iterator().next();
if (newTop == null) {
//If there isn't any because they have all been removed
// fire an "event" for any post all windows being closed
lastWindowRemoved();
} else {
//Otherwise mark the new window as being focused
newTop.onFocused();
}
//Update the listener to being the window that is now selected or null if none are
setFocused(newTop);
}
}
}
protected void lastWindowRemoved() {
//Mark that no windows are now selected
if (menu instanceof MekanismContainer) {
((MekanismContainer) menu).setSelectedWindow(null);
}
}
@Override
public void setSelectedWindow(SelectedWindowData selectedWindow) {
if (menu instanceof MekanismContainer) {
((MekanismContainer) menu).setSelectedWindow(selectedWindow);
}
}
@Nullable
@Override
public GuiWindow getWindowHovering(double mouseX, double mouseY) {
return windows.stream().filter(w -> w.isMouseOver(mouseX, mouseY)).findFirst().orElse(null);
}
public Collection<GuiWindow> getWindows() {
return windows;
}
public LRU<GuiWindow>.LRUIterator getWindowsDescendingIterator() {
return windows.descendingIterator();
}
}