8484 * @version 1.10.0
8585 * @since 1.0.0
8686 */
87+ //~ if >= 26.2 'client.screen' -> 'client.gui.screen()' {
8788public class MidnightInput {
8889 public static final Map <Integer , Integer > BUTTON_COOLDOWNS = new HashMap <>();
8990 public static final KeyEvent ENTER_KEY_INPUT = new KeyEvent (GLFW_KEY_ENTER , 0 , 0 );
@@ -211,7 +212,7 @@ public void onPreRenderScreen(@NotNull Screen screen) {
211212 * This method is called to update the camera
212213 */
213214 public void updateCamera () {
214- if (!(client .screen == null || client .screen instanceof TouchscreenOverlay ))
215+ if (!(client .gui . screen () == null || client .gui . screen () instanceof TouchscreenOverlay ))
215216 return ;
216217
217218 var player = client .player ;
@@ -239,10 +240,10 @@ public void updateCamera() {
239240 * @param windowHeight the window height
240241 */
241242 public void onScreenOpen (int windowWidth , int windowHeight ) {
242- if (client .screen == null ) {
243+ if (client .gui . screen () == null ) {
243244 this .mouseSpeedX = this .mouseSpeedY = 0.0F ;
244245 InputManager .INPUT_MANAGER .resetMousePosition (windowWidth , windowHeight );
245- } else if (isScreenInteractive (client .screen ) && MidnightControlsConfig .virtualMouse ) {
246+ } else if (isScreenInteractive (client .gui . screen () ) && MidnightControlsConfig .virtualMouse ) {
246247 ((MouseAccessor ) client .mouseHandler ).midnightcontrols$onCursorPos (client .getWindow ().handle (), 0 , 0 );
247248 InputManager .INPUT_MANAGER .resetMouseTarget (client );
248249 }
@@ -293,7 +294,7 @@ private void fetchJoystickInput(@NotNull GLFWGamepadState gamepadState, boolean
293294 float rightX = polarUtil .polarX ;
294295 float rightY = polarUtil .polarY ;
295296
296- boolean isRadialMenu = client .screen instanceof RingScreen || (PlatformFunctions .isModLoaded ("emotecraft" ) && EmotecraftCompat .isEmotecraftScreen (client .screen ));
297+ boolean isRadialMenu = client .gui . screen () instanceof RingScreen || (PlatformFunctions .isModLoaded ("emotecraft" ) && EmotecraftCompat .isEmotecraftScreen (client .gui . screen () ));
297298
298299 if (!isRadialMenu ) {
299300 for (int i = cameraTick ? GLFW_GAMEPAD_AXIS_RIGHT_X : 0 ; i < (cameraTick ? GLFW_GAMEPAD_AXIS_LEFT_TRIGGER : GLFW_GAMEPAD_AXIS_RIGHT_X ); i ++) {
@@ -351,20 +352,20 @@ public void handleButton(ButtonStorage storage) {
351352 return ;
352353 }
353354
354- if (client .screen != null && storage .state .isPressed () && storage .button == GLFW_GAMEPAD_BUTTON_Y &&
355- MidnightControlsConfig .arrowScreens .contains (client .screen .getClass ().getCanonicalName ())) {
355+ if (client .gui . screen () != null && storage .state .isPressed () && storage .button == GLFW_GAMEPAD_BUTTON_Y &&
356+ MidnightControlsConfig .arrowScreens .contains (client .gui . screen () .getClass ().getCanonicalName ())) {
356357 pressKeyboardKey (client , GLFW .GLFW_KEY_ENTER );
357358 this .screenCloseCooldown = 5 ;
358359 }
359360 else if (storage .state .isPressed ()) {
360- if (client .screen != null && storage .isDpad () && this .actionGuiCooldown == 0 ) {
361+ if (client .gui . screen () != null && storage .isDpad () && this .actionGuiCooldown == 0 ) {
361362 switch (storage .button ) {
362- case GLFW_GAMEPAD_BUTTON_DPAD_UP -> this .changeFocus (client .screen , ScreenDirection .UP );
363- case GLFW_GAMEPAD_BUTTON_DPAD_DOWN -> this .changeFocus (client .screen , ScreenDirection .DOWN );
364- case GLFW_GAMEPAD_BUTTON_DPAD_LEFT -> this .handleLeftRight (client .screen , false );
365- case GLFW_GAMEPAD_BUTTON_DPAD_RIGHT -> this .handleLeftRight (client .screen , true );
363+ case GLFW_GAMEPAD_BUTTON_DPAD_UP -> this .changeFocus (client .gui . screen () , ScreenDirection .UP );
364+ case GLFW_GAMEPAD_BUTTON_DPAD_DOWN -> this .changeFocus (client .gui . screen () , ScreenDirection .DOWN );
365+ case GLFW_GAMEPAD_BUTTON_DPAD_LEFT -> this .handleLeftRight (client .gui . screen () , false );
366+ case GLFW_GAMEPAD_BUTTON_DPAD_RIGHT -> this .handleLeftRight (client .gui . screen () , true );
366367 }
367- if (MidnightControlsConfig .wasdScreens .contains (client .screen .getClass ().getCanonicalName ())) {
368+ if (MidnightControlsConfig .wasdScreens .contains (client .gui . screen () .getClass ().getCanonicalName ())) {
368369 switch (storage .button ) {
369370 case GLFW_GAMEPAD_BUTTON_DPAD_UP -> pressKeyboardKey (client , GLFW .GLFW_KEY_W );
370371 case GLFW_GAMEPAD_BUTTON_DPAD_DOWN -> pressKeyboardKey (client , GLFW .GLFW_KEY_S );
@@ -376,52 +377,52 @@ else if (storage.state.isPressed()) {
376377 }
377378 }
378379 else {
379- if (storage .button == GLFW .GLFW_GAMEPAD_BUTTON_A && client .screen != null ) {
380+ if (storage .button == GLFW .GLFW_GAMEPAD_BUTTON_A && client .gui . screen () != null ) {
380381 if (this .actionGuiCooldown == 0 ) {
381- var focused = client .screen .getFocused ();
382- if (focused != null && isScreenInteractive (client .screen )) {
383- if (this .handleAButton (client .screen , focused )) {
382+ var focused = client .gui . screen () .getFocused ();
383+ if (focused != null && isScreenInteractive (client .gui . screen () )) {
384+ if (this .handleAButton (client .gui . screen () , focused )) {
384385 this .actionGuiCooldown = 5 ; // Set the cooldown to 5 ticks to avoid unintended button presses.
385386 return ;
386387 }
387388 }
388389 //? fabric
389- else if (PlatformFunctions .isModLoaded ("libgui" )) LibGuiCompat .handlePress (client .screen );
390+ else if (PlatformFunctions .isModLoaded ("libgui" )) LibGuiCompat .handlePress (client .gui . screen () );
390391 }
391392 }
392393 }
393394
394- if (storage .button == GLFW .GLFW_GAMEPAD_BUTTON_A && client .screen != null && !isScreenInteractive (client .screen )
395+ if (storage .button == GLFW .GLFW_GAMEPAD_BUTTON_A && client .gui . screen () != null && !isScreenInteractive (client .gui . screen () )
395396 && this .actionGuiCooldown == 0 ) {
396- if (client .screen instanceof AbstractContainerScreen <?> handledScreen && ((HandledScreenAccessor ) handledScreen ).midnightcontrols$getSlotAt (
397+ if (client .gui . screen () instanceof AbstractContainerScreen <?> handledScreen && ((HandledScreenAccessor ) handledScreen ).midnightcontrols$getSlotAt (
397398 client .mouseHandler .xpos () * (double ) client .getWindow ().getGuiScaledWidth () / (double ) client .getWindow ().getScreenWidth (),
398399 client .mouseHandler .ypos () * (double ) client .getWindow ().getGuiScaledHeight () / (double ) client .getWindow ().getScreenHeight ()) != null ) return ;
399- if (!this .ignoreNextARelease && client .screen != null ) {
400+ if (!this .ignoreNextARelease && client .gui . screen () != null ) {
400401 var accessor = (MouseAccessor ) client .mouseHandler ;
401402 accessor .midnightcontrols$onCursorPos (client .getWindow ().handle (), client .mouseHandler .xpos (), client .mouseHandler .ypos ());
402403 switch (storage .state ) {
403404 // Button pressed
404405 case PRESS -> accessor .midnightcontrols$onMouseButton (client .getWindow ().handle (), new MouseButtonInfo (GLFW_MOUSE_BUTTON_LEFT , 0 ), 1 );
405406 case RELEASE -> { // Button released
406407 accessor .midnightcontrols$onMouseButton (client .getWindow ().handle (), new MouseButtonInfo (GLFW_MOUSE_BUTTON_LEFT , 0 ), 0 );
407- client .screen .setDragging (false );
408+ client .gui . screen () .setDragging (false );
408409 }
409- case REPEAT -> client .screen .setDragging (true ); // Button held down / dragging
410+ case REPEAT -> client .gui . screen () .setDragging (true ); // Button held down / dragging
410411 }
411412 this .screenCloseCooldown = 5 ;
412413 } else {
413414 this .ignoreNextARelease = false ;
414415 }
415416 }
416- else if (storage .button == GLFW .GLFW_GAMEPAD_BUTTON_X && client .screen != null && !isScreenInteractive (client .screen )
417+ else if (storage .button == GLFW .GLFW_GAMEPAD_BUTTON_X && client .gui . screen () != null && !isScreenInteractive (client .gui . screen () )
417418 && this .actionGuiCooldown == 0 ) {
418419 double mouseX = client .mouseHandler .xpos () * (double ) client .getWindow ().getGuiScaledWidth () / (double ) client .getWindow ().getScreenWidth ();
419420 double mouseY = client .mouseHandler .ypos () * (double ) client .getWindow ().getGuiScaledHeight () / (double ) client .getWindow ().getScreenHeight ();
420- if (client .screen instanceof AbstractContainerScreen <?> handledScreen && ((HandledScreenAccessor ) handledScreen ).midnightcontrols$getSlotAt (
421+ if (client .gui . screen () instanceof AbstractContainerScreen <?> handledScreen && ((HandledScreenAccessor ) handledScreen ).midnightcontrols$getSlotAt (
421422 mouseX , mouseY ) != null ) return ;
422- if (!this .ignoreNextXRelease && client .screen != null ) {
423- if (storage .state == ButtonState .PRESS ) client .screen .mouseClicked (new MouseButtonEvent (mouseX , mouseY , new MouseButtonInfo (GLFW .GLFW_MOUSE_BUTTON_2 , 1 )), false );
424- else if (storage .state == ButtonState .RELEASE ) client .screen .mouseReleased (new MouseButtonEvent (mouseX , mouseY , new MouseButtonInfo (GLFW .GLFW_MOUSE_BUTTON_2 , 0 )));
423+ if (!this .ignoreNextXRelease && client .gui . screen () != null ) {
424+ if (storage .state == ButtonState .PRESS ) client .gui . screen () .mouseClicked (new MouseButtonEvent (mouseX , mouseY , new MouseButtonInfo (GLFW .GLFW_MOUSE_BUTTON_2 , 1 )), false );
425+ else if (storage .state == ButtonState .RELEASE ) client .gui . screen () .mouseReleased (new MouseButtonEvent (mouseX , mouseY , new MouseButtonInfo (GLFW .GLFW_MOUSE_BUTTON_2 , 0 )));
425426 this .screenCloseCooldown = 5 ;
426427 } else {
427428 this .ignoreNextXRelease = false ;
@@ -437,24 +438,24 @@ private void handleJoystickAxis(AxisStorage storage) {
437438
438439 this .handleJoystickMovement (storage );
439440
440- if (this .handleScreenScrolling (client .screen , storage )) return ;
441+ if (this .handleScreenScrolling (client .gui . screen () , storage )) return ;
441442
442443 storage .absValue = (float ) Mth .clamp (storage .absValue / MidnightControlsConfig .getAxisMaxValue (storage .axis ), 0.f , 1.f );
443- if (client .screen == null ) {
444+ if (client .gui . screen () == null ) {
444445 // Handles the look direction.
445446 this .handleLook (storage );
446447 } else {
447448 boolean allowMouseControl = true ;
448449
449- if (this .actionGuiCooldown == 0 && MidnightControlsConfig .isMovementAxis (storage .axis ) && isScreenInteractive (client .screen )) {
450+ if (this .actionGuiCooldown == 0 && MidnightControlsConfig .isMovementAxis (storage .axis ) && isScreenInteractive (client .gui . screen () )) {
450451 if (MidnightControlsConfig .isForwardButton (storage .axis , false , storage .buttonState )) {
451- allowMouseControl = this .changeFocus (client .screen , ScreenDirection .UP );
452+ allowMouseControl = this .changeFocus (client .gui . screen () , ScreenDirection .UP );
452453 } else if (MidnightControlsConfig .isBackButton (storage .axis , false , storage .buttonState )) {
453- allowMouseControl = this .changeFocus (client .screen , ScreenDirection .DOWN );
454+ allowMouseControl = this .changeFocus (client .gui . screen () , ScreenDirection .DOWN );
454455 } else if (MidnightControlsConfig .isLeftButton (storage .axis , false , storage .buttonState )) {
455- allowMouseControl = this .handleLeftRight (client .screen , false );
456+ allowMouseControl = this .handleLeftRight (client .gui . screen () , false );
456457 } else if (MidnightControlsConfig .isRightButton (storage .axis , false , storage .buttonState )) {
457- allowMouseControl = this .handleLeftRight (client .screen , true );
458+ allowMouseControl = this .handleLeftRight (client .gui . screen () , true );
458459 }
459460 }
460461
@@ -471,7 +472,7 @@ private void handleJoystickAxis(AxisStorage storage) {
471472 movementX = storage .absValue ;
472473 }
473474
474- if (client .screen != null && allowMouseControl ) {
475+ if (client .gui . screen () != null && allowMouseControl ) {
475476 boolean moving = movementY != 0 || movementX != 0 ;
476477 if (moving ) {
477478 /*
@@ -496,7 +497,7 @@ private void handleJoystickAxis(AxisStorage storage) {
496497 );
497498 }
498499
499- InventoryUtil .moveMouseToClosestSlot (client .screen );
500+ InventoryUtil .moveMouseToClosestSlot (client .gui . screen () );
500501 }
501502
502503 this .prevXAxis = movementX ;
@@ -592,8 +593,8 @@ public void handleRadialMenu(float x, float y) {
592593 if (y < -border ) index = 1 ;
593594 else if (y > border ) index = 6 ;
594595 }
595- if (client .screen instanceof RingScreen && index > -1 ) RingPage .selected = index ;
596- if (PlatformFunctions .isModLoaded ("emotecraft" ) && EmotecraftCompat .isEmotecraftScreen (client .screen )) EmotecraftCompat .handleEmoteSelector (index );
596+ if (client .gui . screen () instanceof RingScreen && index > -1 ) RingPage .selected = index ;
597+ if (PlatformFunctions .isModLoaded ("emotecraft" ) && EmotecraftCompat .isEmotecraftScreen (client .gui . screen () )) EmotecraftCompat .handleEmoteSelector (index );
597598 }
598599
599600 public boolean handleListWidgetScrolling (List <? extends GuiEventListener > children , float value ) {
@@ -822,3 +823,4 @@ public void pressKeyboardKey(Screen screen, int key) {
822823 screen .keyPressed (new KeyEvent (key , 0 , 0 ));
823824 }
824825}
826+ //~}
0 commit comments