forked from CleanroomMC/ModularUI
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathClientScreenHandler.java
More file actions
780 lines (701 loc) · 34 KB
/
ClientScreenHandler.java
File metadata and controls
780 lines (701 loc) · 34 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
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
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
package com.cleanroommc.modularui.screen;
import com.cleanroommc.modularui.GuiErrorHandler;
import com.cleanroommc.modularui.ModularUI;
import com.cleanroommc.modularui.ModularUIConfig;
import com.cleanroommc.modularui.api.IMuiScreen;
import com.cleanroommc.modularui.api.ITheme;
import com.cleanroommc.modularui.api.MCHelper;
import com.cleanroommc.modularui.api.UpOrDown;
import com.cleanroommc.modularui.api.event.KeyboardInputEvent;
import com.cleanroommc.modularui.api.event.MouseInputEvent;
import com.cleanroommc.modularui.api.widget.IVanillaSlot;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.core.mixins.early.minecraft.GuiAccessor;
import com.cleanroommc.modularui.core.mixins.early.minecraft.GuiContainerAccessor;
import com.cleanroommc.modularui.core.mixins.early.minecraft.GuiScreenAccessor;
import com.cleanroommc.modularui.drawable.GuiDraw;
import com.cleanroommc.modularui.drawable.Stencil;
import com.cleanroommc.modularui.network.ModularNetwork;
import com.cleanroommc.modularui.overlay.DebugOptions;
import com.cleanroommc.modularui.overlay.OverlayStack;
import com.cleanroommc.modularui.screen.viewport.GuiContext;
import com.cleanroommc.modularui.screen.viewport.LocatedWidget;
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
import com.cleanroommc.modularui.utils.Color;
import com.cleanroommc.modularui.utils.FpsCounter;
import com.cleanroommc.modularui.utils.GlStateManager;
import com.cleanroommc.modularui.utils.MathUtils;
import com.cleanroommc.modularui.utils.Platform;
import com.cleanroommc.modularui.widget.sizer.Area;
import com.cleanroommc.modularui.widgets.RichTextWidget;
import com.cleanroommc.modularui.widgets.slot.ItemSlot;
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
import com.cleanroommc.modularui.widgets.slot.SlotGroup;
import com.cleanroommc.neverenoughanimations.animations.OpeningAnimation;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiLabel;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import codechicken.nei.LayoutManager;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerDrawHandler;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnmodifiableView;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
@ApiStatus.Internal
@SideOnly(Side.CLIENT)
public class ClientScreenHandler {
private static final GuiContext defaultContext = new GuiContext();
private static ModularScreen currentScreen = null;
private static Character lastChar = null;
private static final FpsCounter fpsCounter = new FpsCounter();
private static long ticks = 0L;
private static IMuiScreen lastMui;
private static final ObjectArrayList<IMuiScreen> muiStack = new ObjectArrayList<>(8);
// we need to know the actual gui and not some fake screen some other mod overwrites
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onGuiChange(GuiOpenEvent event) {
onGuiChanged(getMCScreen(), event.gui);
}
@SubscribeEvent
public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
defaultContext.updateScreenArea(event.gui.width, event.gui.height);
if (validateGui(event.gui)) {
currentScreen.onResize(event.gui.width, event.gui.height);
}
OverlayStack.foreach(ms -> ms.onResize(event.gui.width, event.gui.height), false);
}
// before recipe viewer
@SubscribeEvent(priority = EventPriority.HIGH)
public void onGuiInputHigh(KeyboardInputEvent.Pre event) throws IOException {
defaultContext.updateEventState();
inputEvent(event, InputPhase.EARLY);
}
// after recipe viewer
@SubscribeEvent(priority = EventPriority.LOW)
public void onGuiInputLow(KeyboardInputEvent.Pre event) throws IOException {
inputEvent(event, InputPhase.LATE);
}
private static void inputEvent(KeyboardInputEvent.Pre event, InputPhase phase) throws IOException {
if (validateGui(event.gui)) currentScreen.getContext().updateEventState();
if (ModularUI.Mods.NEI.isLoaded() && phase == InputPhase.EARLY && Keyboard.getEventKeyState()) {
// manually handles NEI key input
// TODO is this a good way to do this?
char c0 = Keyboard.getEventCharacter();
int key = Keyboard.getEventKey();
if ((LayoutManager.searchField != null && LayoutManager.searchField.handleKeyPress(key, c0)) ||
(LayoutManager.quantity != null && LayoutManager.quantity.handleKeyPress(key, c0))) {
event.setCanceled(true);
return;
}
}
if (handleKeyboardInput(currentScreen, event.gui, phase)) {
event.setCanceled(true);
}
}
// before recipe viewer
@SubscribeEvent(priority = EventPriority.HIGH)
public void onGuiInputLow(MouseInputEvent.Pre event) throws IOException {
defaultContext.updateEventState();
if (validateGui(event.gui)) currentScreen.getContext().updateEventState();
if (handleMouseInput(Mouse.getEventButton(), currentScreen, event.gui)) {
Platform.unFocusRecipeViewer();
event.setCanceled(true);
return;
}
int w = Mouse.getEventDWheel();
if (w == 0) return;
UpOrDown upOrDown = w > 0 ? UpOrDown.UP : UpOrDown.DOWN;
validateGui(event.gui);
if (doAction(currentScreen, ms -> ms.onMouseScroll(upOrDown, Math.abs(w)))) {
event.setCanceled(true);
}
}
@SubscribeEvent(priority = EventPriority.LOW)
public void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) {
int mx = event.mouseX, my = event.mouseY;
float pt = event.renderPartialTicks;
defaultContext.updateState(mx, my, pt);
defaultContext.reset();
if (validateGui(event.gui)) {
currentScreen.getContext().updateState(mx, my, pt);
drawScreen(currentScreen, currentScreen.getScreenWrapper().getGuiScreen(), mx, my, pt);
event.setCanceled(true);
}
Platform.setupDrawTex(); // recipe viewer and other mods may expect this state
}
@SubscribeEvent(priority = EventPriority.HIGH)
public void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Post event) {
OverlayStack.draw(event.mouseX, event.mouseY, event.renderPartialTicks);
Platform.setupDrawTex(); // recipe viewer and other mods may expect this state
}
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
OverlayStack.onTick();
defaultContext.tick();
if (validateGui()) {
currentScreen.onUpdate();
}
ticks++;
}
}
@SubscribeEvent
public void preDraw(TickEvent.RenderTickEvent event) {
if (event.phase == TickEvent.Phase.START) {
GL11.glEnable(GL11.GL_STENCIL_TEST);
}
Stencil.reset();
}
public static long getTicks() {
return ticks;
}
public static void onFrameUpdate() {
OverlayStack.foreach(ModularScreen::onFrameUpdate, true);
if (currentScreen != null) currentScreen.onFrameUpdate();
}
private static void onGuiChanged(GuiScreen oldScreen, GuiScreen newScreen) {
if (oldScreen == newScreen) return;
defaultContext.reset();
fpsCounter.reset();
GuiErrorHandler.INSTANCE.clear();
IMuiScreen lastLastMui = lastMui;
if (lastMui != null) {
// called on open and close
// invalidate last mui screen, but keep it in stack
invalidateCurrentScreen();
}
if (newScreen instanceof IMuiScreen muiScreen) {
lastMui = muiScreen;
currentScreen = muiScreen.getScreen();
muiStack.remove(muiScreen);
muiStack.add(muiScreen); // put screen to the top of the stack
GuiScreen lastParent = lastLastMui != null ? lastLastMui.getScreen().getContext().getParentScreen() : null;
if (lastParent != muiScreen) {
// new screen in the stack
currentScreen.getContext().setParentScreen(oldScreen);
} else {
// last parent is equal to new screen -> effectively popping the current screen from the stack
// the current screen will disconnect from the stack and therefore need to dispose it
muiStack.remove(lastLastMui);
lastLastMui.getScreen().getPanelManager().dispose();
}
Keyboard.enableRepeatEvents(true);
} else if (newScreen == null) {
// closing -> clear stack and dispose every screen
invalidateMuiStack();
// only when all screens are closed dispose all containers in the stack
ModularNetwork.CLIENT.closeAll();
// in game key binds assume this is disabled
Keyboard.enableRepeatEvents(false);
}
OverlayStack.onGuiOpen(newScreen);
}
private static void invalidateCurrentScreen() {
// reset mouse inputs, relevant when screen gets reopened
if (lastMui != null) {
((GuiScreenAccessor) lastMui.getGuiScreen()).setEventButton(-1);
((GuiScreenAccessor) lastMui.getGuiScreen()).setLastMouseEvent(-1);
lastMui.getScreen().getPanelManager().closeScreen();
lastMui = null;
}
currentScreen = null;
lastChar = null;
}
private static void invalidateMuiStack() {
muiStack.forEach(muiScreen -> muiScreen.getScreen().getPanelManager().dispose());
muiStack.clear();
}
private static boolean doAction(@Nullable ModularScreen muiScreen, Predicate<ModularScreen> action) {
return OverlayStack.interact(action, true) || (muiScreen != null && action.test(muiScreen));
}
private static boolean handleMouseInput(int button, @Nullable ModularScreen muiScreen, GuiScreen mcScreen) throws IOException {
GameSettings gameSettings = Minecraft.getMinecraft().gameSettings;
GuiScreenAccessor acc = (GuiScreenAccessor) mcScreen;
if (Mouse.getEventButtonState()) {
if (gameSettings.touchscreen) {
int val = acc.getTouchValue();
if (val > 0) {
// we will cancel the event now, so we have to set the value
// otherwise the screen will handle it
acc.setTouchValue(val + 1);
return true;
}
}
acc.setEventButton(button);
acc.setLastMouseEvent(Minecraft.getSystemTime());
if (muiScreen != null && muiScreen.onMouseInputPre(button, true)) return true;
return doAction(muiScreen, ms -> ms.onMousePressed(button));
}
if (button != -1) {
if (gameSettings.touchscreen) {
int val = acc.getTouchValue();
if (val - 1 > 0) {
// we will cancel the event now, so we have to set the value
// otherwise the screen will handle it
acc.setTouchValue(val - 1);
return true;
}
}
acc.setEventButton(-1);
if (muiScreen != null && muiScreen.onMouseInputPre(button, false)) return true;
return doAction(muiScreen, ms -> ms.onMouseRelease(button));
}
if (acc.getEventButton() != -1 && acc.getLastMouseEvent() > 0L) {
long l = Minecraft.getSystemTime() - acc.getLastMouseEvent();
return doAction(muiScreen, ms -> ms.onMouseDrag(acc.getEventButton(), l));
}
return false;
}
public static boolean handleKeyboardInput(@Nullable ModularScreen muiScreen, GuiScreen mcScreen) throws IOException {
return handleKeyboardInput(muiScreen, mcScreen, InputPhase.EARLY);
}
/**
* This replicates vanilla behavior while also injecting custom behavior for consistency
*/
private static boolean handleKeyboardInput(@Nullable ModularScreen muiScreen, GuiScreen mcScreen, InputPhase inputPhase) throws IOException {
char c0 = Keyboard.getEventCharacter();
int key = Keyboard.getEventKey();
boolean state = Keyboard.getEventKeyState();
if (state) {
// pressing a key
lastChar = c0;
return inputPhase.isEarly() ? doAction(muiScreen, ms -> ms.onKeyPressed(c0, key)) : keyTyped(mcScreen, c0, key);
} else {
// releasing a key
// for some reason when you press E after joining a world the button will not trigger the press event,
// but only the release event, causing this to be null
if (lastChar == null) return false;
// when the key is released, the event char is empty
if (inputPhase.isEarly() && doAction(muiScreen, ms -> ms.onKeyRelease(lastChar, key))) {
return true;
}
if (inputPhase.isLate() && key == 0 && c0 >= ' ') {
return keyTyped(mcScreen, c0, key);
}
}
return false;
}
private static boolean keyTyped(GuiScreen screen, char typedChar, int keyCode) throws IOException {
if (currentScreen == null) return false;
// debug mode C + CTRL + SHIFT + ALT
if (keyCode == 46 && GuiScreen.isCtrlKeyDown() && GuiScreen.isShiftKeyDown() && Interactable.hasAltDown()) {
ModularUIConfig.guiDebugMode = !ModularUIConfig.guiDebugMode;
return true;
}
if (keyCode == 1 || keyCode == Minecraft.getMinecraft().gameSettings.keyBindInventory.getKeyCode()) {
if (currentScreen.getContext().hasDraggable()) {
currentScreen.getContext().dropDraggable(true);
} else {
currentScreen.getPanelManager().closeTopPanel();
}
return true;
}
return false;
}
public static void dragSlot(long timeSinceLastClick) {
if (hasScreen() && getMCScreen() instanceof GuiScreenAccessor container) {
ModularGuiContext ctx = currentScreen.getContext();
container.invokeMouseClickMove(ctx.getAbsMouseX(), ctx.getAbsMouseY(), ctx.getMouseButton(), timeSinceLastClick);
}
}
public static void clickSlot(ModularScreen ms, Slot slot) {
GuiScreen screen = ms.getScreenWrapper().getGuiScreen();
if (screen instanceof GuiScreenAccessor acc && screen instanceof IClickableGuiContainer clickableGuiContainer && validateGui(screen)) {
ModularGuiContext ctx = ms.getContext();
List<GuiButton> buttonList = acc.getButtonList();
try {
// remove buttons to make sure they are not clicked
acc.setButtonList(Collections.emptyList());
// set clicked slot to make sure the container clicks the desired slot
clickableGuiContainer.modularUI$setClickedSlot(slot);
acc.invokeMouseClicked(ctx.getAbsMouseX(), ctx.getAbsMouseY(), ctx.getMouseButton());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
// undo modifications
clickableGuiContainer.modularUI$setClickedSlot(null);
acc.setButtonList(buttonList);
}
}
}
public static void releaseSlot() {
if (hasScreen() && getMCScreen() instanceof GuiScreenAccessor screen) {
ModularGuiContext ctx = currentScreen.getContext();
screen.invokeMouseReleased(ctx.getAbsMouseX(), ctx.getAbsMouseY(), ctx.getMouseButton());
}
}
public static boolean shouldDrawWorldBackground() {
return Minecraft.getMinecraft().theWorld == null;
}
public static void drawDarkBackground(GuiScreen screen, int tint) {
if (hasScreen()) {
float alpha = ModularUI.Mods.NEA.isLoaded() ? OpeningAnimation.getValue(screen) : 1f;
// vanilla color values as hex
int color = 0x101010;
int start = (int) (0xc0 * alpha);
int end = (int) (0xd0 * alpha);
start = Color.withAlpha(color, start);
end = Color.withAlpha(color, end);
GuiDraw.drawVerticalGradientRect(0, 0, screen.width, screen.height, start, end);
}
}
public static void drawScreen(ModularScreen muiScreen, GuiScreen mcScreen, int mouseX, int mouseY, float partialTicks) {
if (mcScreen instanceof GuiContainer container) {
drawContainer(muiScreen, container, mouseX, mouseY, partialTicks);
} else {
drawScreenInternal(muiScreen, mcScreen, mouseX, mouseY, partialTicks);
}
}
public static void drawScreenInternal(ModularScreen muiScreen, GuiScreen mcScreen, int mouseX, int mouseY, float partialTicks) {
GlStateManager.pushMatrix(); // needed for open animation currently
Stencil.reset();
Stencil.apply(muiScreen.getScreenArea(), null);
Platform.setupDrawTex();
GlStateManager.enableLighting();
GlStateManager.enableDepth();
GlStateManager.enableRescaleNormal();
RenderHelper.enableStandardItemLighting();
handleAnimationScale(mcScreen);
muiScreen.drawScreen();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
drawVanillaElements(mcScreen, mouseX, mouseY, partialTicks);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableRescaleNormal();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
RenderHelper.disableStandardItemLighting();
muiScreen.drawForeground();
GlStateManager.enableLighting();
GlStateManager.enableDepth();
GlStateManager.enableRescaleNormal();
RenderHelper.enableStandardItemLighting();
Stencil.remove();
GlStateManager.popMatrix();
}
public static void drawContainer(ModularScreen muiScreen, GuiContainer mcScreen, int mouseX, int mouseY, float partialTicks) {
GuiContainerAccessor acc = (GuiContainerAccessor) mcScreen;
Stencil.reset();
Stencil.apply(muiScreen.getScreenArea(), null);
Platform.setupDrawTex();
mcScreen.drawDefaultBackground();
int x = acc.getGuiLeft();
int y = acc.getGuiTop();
//handleAnimationScale(mcScreen);
acc.invokeDrawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
muiScreen.drawScreen();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
// mainly for invtweaks compat
drawVanillaElements(mcScreen, mouseX, mouseY, partialTicks);
acc.setHoveredSlot(null);
GlStateManager.pushMatrix();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
GlStateManager.enableRescaleNormal();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
RenderHelper.enableGUIStandardItemLighting();
if (muiScreen.getContext().getRecipeViewerSettings().isRecipeViewerEnabled(muiScreen)) {
// Copied from GuiContainerManager#renderObjects but without translation
for (IContainerDrawHandler drawHandler : GuiContainerManager.drawHandlers) {
drawHandler.renderObjects(mcScreen, mouseX, mouseY);
}
for (IContainerDrawHandler drawHandler : GuiContainerManager.drawHandlers) {
drawHandler.postRenderObjects(mcScreen, mouseX, mouseY);
}
if (shouldRenderNEITooltip(muiScreen)) {
GuiContainerManager.getManager().renderToolTips(mouseX, mouseY);
}
}
GlStateManager.disableDepth();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
RenderHelper.disableStandardItemLighting();
acc.invokeDrawGuiContainerForegroundLayer(mouseX, mouseY);
muiScreen.drawForeground();
acc.setHoveredSlot(null);
IWidget hovered = muiScreen.getContext().getTopHovered();
if (hovered instanceof IVanillaSlot vanillaSlot && vanillaSlot.handleAsVanillaSlot()) {
acc.setHoveredSlot(vanillaSlot.getVanillaSlot());
}
InventoryPlayer inventoryplayer = Minecraft.getMinecraft().thePlayer.inventory;
ItemStack itemstack = acc.getDraggedStack() == null ? inventoryplayer.getItemStack() : acc.getDraggedStack();
GlStateManager.translate((float) x, (float) y, 0.0F);
if (itemstack != null) {
int k2 = acc.getDraggedStack() == null ? 8 : 16;
String s = null;
if (acc.getDraggedStack() != null && acc.getIsRightMouseClick()) {
itemstack = itemstack.copy();
itemstack.stackSize = MathUtils.ceil((float) itemstack.stackSize / 2.0F);
} else if (acc.getDragSplitting() && acc.getDragSplittingSlots().size() > 1) {
itemstack = itemstack.copy();
itemstack.stackSize = acc.getDragSplittingRemnant();
if (itemstack.stackSize < 1) {
s = EnumChatFormatting.YELLOW + "0";
}
}
GlStateManager.translate(0, 0, 500);
drawItemStack(mcScreen, NEAAnimationHandler.injectVirtualCursorStack(mcScreen, itemstack), mouseX - x - 8, mouseY - y - k2, s);
GlStateManager.translate(0, 0, -500);
}
if (acc.getReturningStack() != null) {
float f = (float) (Minecraft.getSystemTime() - acc.getReturningStackTime()) / 100.0F;
if (f >= 1.0F) {
f = 1.0F;
acc.setReturningStack(null);
}
int l2 = acc.getReturningStackDestSlot().xDisplayPosition - acc.getTouchUpX();
int i3 = acc.getReturningStackDestSlot().yDisplayPosition - acc.getTouchUpY();
int l1 = acc.getTouchUpX() + (int) ((float) l2 * f);
int i2 = acc.getTouchUpY() + (int) ((float) i3 * f);
drawItemStack(mcScreen, acc.getReturningStack(), l1, i2, null);
}
NEAAnimationHandler.drawItemAnimation(mcScreen);
GlStateManager.popMatrix();
GlStateManager.enableLighting();
GlStateManager.enableDepth();
GlStateManager.enableRescaleNormal();
RenderHelper.enableStandardItemLighting();
Stencil.remove();
}
private static boolean shouldRenderNEITooltip(ModularScreen muiScreen) {
return !muiScreen.getContext().isHovered();
}
private static void drawItemStack(GuiContainer mcScreen, ItemStack stack, int x, int y, String altText) {
GlStateManager.translate(0.0F, 0.0F, 32.0F);
((GuiAccessor) mcScreen).setZLevel(200f);
GuiScreenAccessor.getItemRender().zLevel = 200.0F;
FontRenderer font = stack.getItem().getFontRenderer(stack);
if (font == null) font = ((GuiScreenAccessor) mcScreen).getFontRenderer();
Platform.setupDrawItem();
GuiScreenAccessor.getItemRender().renderItemAndEffectIntoGUI(font, Minecraft.getMinecraft().getTextureManager(), stack, x, y);
GuiDraw.afterRenderItemAndEffectIntoGUI(stack);
GuiScreenAccessor.getItemRender().renderItemOverlayIntoGUI(font, Minecraft.getMinecraft().getTextureManager(), stack, x, y - (((GuiContainerAccessor) mcScreen).getDraggedStack() == null ? 0 : 8), altText);
GlStateManager.disableDepth();
((GuiAccessor) mcScreen).setZLevel(0f);
GuiScreenAccessor.getItemRender().zLevel = 0.0F;
}
private static void drawVanillaElements(GuiScreen mcScreen, int mouseX, int mouseY, float partialTicks) {
for (GuiButton guiButton : ((GuiScreenAccessor) mcScreen).getButtonList()) {
guiButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY);
}
for (GuiLabel guiLabel : ((GuiScreenAccessor) mcScreen).getLabelList()) {
guiLabel.func_146159_a(Minecraft.getMinecraft(), mouseX, mouseY);
}
}
public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable ModularScreen fallback) {
fpsCounter.onDraw();
if (!ModularUIConfig.guiDebugMode) return;
if (muiScreen == null) {
if (validateGui()) {
muiScreen = currentScreen;
} else {
if (fallback == null) return;
muiScreen = fallback;
}
}
GlStateManager.disableDepth();
GlStateManager.disableLighting();
GlStateManager.enableBlend();
ModularGuiContext context = muiScreen.getContext();
int mouseX = context.getAbsMouseX(), mouseY = context.getAbsMouseY();
int screenH = muiScreen.getScreenArea().height;
int outlineColor = DebugOptions.INSTANCE.outlineColor.getIntValue();//Color.argb(180, 40, 115, 220);
int textColor = DebugOptions.INSTANCE.textColor.getIntValue();//Color.argb(180, 40, 115, 220);
float scale = DebugOptions.INSTANCE.scale.getFloatValue();
int shift = (int) (11 * scale + 0.5f);
int lineY = screenH - shift - 2;
if (ModularUI.Mods.NEI.isLoaded() &&
muiScreen.getContext().hasSettings() &&
muiScreen.getContext().getRecipeViewerSettings().isEnabled(muiScreen)) {
lineY -= 20;
}
GuiDraw.drawText("Mouse Pos: " + mouseX + ", " + mouseY, 5, lineY, scale, outlineColor, true);
lineY -= shift;
GuiDraw.drawText("FPS: " + fpsCounter.getFps(), 5, lineY, scale, outlineColor, true);
lineY -= shift;
LocatedWidget locatedHovered = muiScreen.getPanelManager().getTopWidgetLocated(true);
boolean showHovered = DebugOptions.INSTANCE.showHovered.getBoolValue();
boolean showParent = DebugOptions.INSTANCE.showParent.getBoolValue();
ITheme theme;
if (locatedHovered != null && (showHovered || showParent)) {
theme = locatedHovered.getElement().getPanel().getTheme();
} else {
theme = context.getTheme();
}
GuiDraw.drawText("Theme ID: " + theme.getId(), 5, lineY, scale, outlineColor, true);
if (locatedHovered != null && (showHovered || showParent)) {
drawSegmentLine(lineY -= 4, scale, outlineColor);
lineY -= 10;
IWidget hovered = locatedHovered.getElement();
locatedHovered.applyMatrix(context);
GlStateManager.pushMatrix();
context.applyToOpenGl();
Area area = hovered.getArea();
IWidget parent = hovered.getParent();
if (showHovered && DebugOptions.INSTANCE.showOutline.getBoolValue()) {
GuiDraw.drawBorderOutsideXYWH(0, 0, area.width, area.height, scale, outlineColor);
}
if (hovered.hasParent() && showParent && DebugOptions.INSTANCE.showParentOutline.getBoolValue()) {
GuiDraw.drawBorderOutsideXYWH(-area.rx, -area.ry, parent.getArea().width, parent.getArea().height, scale, Color.withAlpha(outlineColor, 0.3f));
}
GlStateManager.popMatrix();
locatedHovered.unapplyMatrix(context);
if (showHovered) {
if (DebugOptions.INSTANCE.showWidgetTheme.getBoolValue()) {
GuiDraw.drawText("Widget Theme: " + hovered.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName(), 5, lineY, scale, textColor, true);
lineY -= shift;
}
if (DebugOptions.INSTANCE.showSize.getBoolValue()) {
GuiDraw.drawText("Size: " + area.width + ", " + area.height, 5, lineY, scale, textColor, true);
lineY -= shift;
}
if (DebugOptions.INSTANCE.showPos.getBoolValue()) {
GuiDraw.drawText("Pos: " + area.x + ", " + area.y + " Rel: " + area.rx + ", " + area.ry, 5, lineY, scale, textColor, true);
lineY -= shift;
}
GuiDraw.drawText("Widget: " + hovered, 5, lineY, scale, textColor, true);
}
if (hovered.hasParent() && showParent) {
if (showHovered) {
drawSegmentLine(lineY -= 4, scale, textColor);
lineY -= 10;
}
if (DebugOptions.INSTANCE.showParentWidgetTheme.getBoolValue()) {
GuiDraw.drawText("Widget Theme: " + parent.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName(), 5, lineY, scale, textColor, true);
lineY -= shift;
}
area = parent.getArea();
if (DebugOptions.INSTANCE.showParentSize.getBoolValue()) {
GuiDraw.drawText("Parent size: " + area.width + ", " + area.height, 5, lineY, scale, textColor, true);
lineY -= shift;
}
if (DebugOptions.INSTANCE.showParentPos.getBoolValue()) {
GuiDraw.drawText("Parent pos: " + area.x + ", " + area.y + " Rel: " + area.rx + ", " + area.ry, 5, lineY, scale, textColor, true);
lineY -= shift;
}
GuiDraw.drawText("Parent: " + parent, 5, lineY, scale, outlineColor, true);
}
if (showHovered && DebugOptions.INSTANCE.showExtra.getBoolValue()) {
if (hovered instanceof ItemSlot slotWidget) {
drawSegmentLine(lineY -= 4, scale, textColor);
lineY -= 10;
ModularSlot slot = slotWidget.getSlot();
GuiDraw.drawText("Slot Index: " + slot.getSlotIndex(), 5, lineY, scale, textColor, true);
lineY -= shift;
GuiDraw.drawText("Slot Number: " + slot.slotNumber, 5, lineY, scale, textColor, true);
lineY -= shift;
if (slotWidget.isSynced()) {
SlotGroup slotGroup = slot.getSlotGroup();
boolean allowShiftTransfer = slotGroup != null && slotGroup.allowShiftTransfer();
GuiDraw.drawText("Shift-Click Priority: " + (allowShiftTransfer ? slotGroup.getShiftClickPriority() : "DISABLED"), 5, lineY, scale, textColor, true);
}
} else if (hovered instanceof RichTextWidget richTextWidget) {
drawSegmentLine(lineY -= 4, scale, outlineColor);
lineY -= 10;
locatedHovered.applyMatrix(context);
Object hoveredElement = richTextWidget.getHoveredElement();
locatedHovered.unapplyMatrix(context);
GuiDraw.drawText("Hovered: " + hoveredElement, 5, lineY, scale, textColor, true);
}
}
}
// dot at mouse pos
GuiDraw.drawRect(mouseX, mouseY, 1, 1, DebugOptions.INSTANCE.cursorColor.getIntValue());
GlStateManager.color(1f, 1f, 1f, 1f);
}
private static void drawSegmentLine(int y, float scale, int color) {
GuiDraw.drawRect(5, y, 140 * scale, 1 * scale, color);
}
public static void updateGuiArea(GuiContainer container, Rectangle area) {
GuiContainerAccessor acc = (GuiContainerAccessor) container;
acc.setGuiLeft(area.x);
acc.setGuiTop(area.y);
acc.setXSize(area.width);
acc.setYSize(area.height);
}
public static boolean hasScreen() {
return currentScreen != null;
}
@Nullable
public static GuiScreen getMCScreen() {
return MCHelper.getCurrentScreen();
}
@Nullable
public static ModularScreen getMuiScreen() {
return currentScreen;
}
@UnmodifiableView
public static List<IMuiScreen> getMuiStack() {
return Collections.unmodifiableList(muiStack);
}
private static boolean validateGui() {
return MCHelper.hasMc() && validateGui(Minecraft.getMinecraft().currentScreen);
}
private static boolean validateGui(GuiScreen screen) {
if (!MCHelper.hasMc() || currentScreen == null || !(screen instanceof IMuiScreen muiScreen)) {
// no mui screen currently open
return false;
}
if (screen != Minecraft.getMinecraft().currentScreen || muiScreen.getScreen() != currentScreen) {
// mui screen doesn't match the events screen -> invalidate
defaultContext.reset();
invalidateCurrentScreen();
if (MCHelper.getCurrentScreen() == null) {
invalidateMuiStack();
}
return false;
}
return true;
}
public static GuiContext getDefaultContext() {
return defaultContext;
}
public static GuiContext getBestContext() {
if (validateGui()) {
return currentScreen.getContext();
}
return defaultContext;
}
private enum InputPhase {
// for mui interactions
EARLY,
// for mc interactions (like E and ESC)
LATE;
public boolean isEarly() {
return this == EARLY;
}
public boolean isLate() {
return this == LATE;
}
}
public static void handleAnimationScale(GuiScreen screen) {
if (ModularUI.Mods.NEA.isLoaded()) {
OpeningAnimation.handleScale(screen, true);
}
}
}