Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/
dependencies {
api("com.github.GTNewHorizons:GTNHLib:0.9.16:dev")
compileOnlyApi("com.github.GTNewHorizons:lwjgl3ify:3.0.15:api") { transitive = false }

// used in evalex
compileOnly("org.projectlombok:lombok:1.18.42")
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/com/cleanroommc/modularui/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ public static void setCursorResizeIcon(ResizeDragArea dragArea) {
resetCursorIcon();
return;
}
Cursor cursor = switch (dragArea) {
case TOP_LEFT, BOTTOM_RIGHT -> resizeCursorDiagInverse;
case TOP_RIGHT, BOTTOM_LEFT -> resizeCursorDiag;
case TOP, BOTTOM -> resizeCursorV;
case LEFT, RIGHT -> resizeCursorH;
};
try {
Cursor cursor = switch (dragArea) {
case TOP_LEFT, BOTTOM_RIGHT -> resizeCursorDiagInverse;
case TOP_RIGHT, BOTTOM_LEFT -> resizeCursorDiag;
case TOP, BOTTOM -> resizeCursorV;
case LEFT, RIGHT -> resizeCursorH;
};
currentCursor = Mouse.setNativeCursor(cursor);
} catch (LWJGLException e) {
throw new RuntimeException(e);
Expand All @@ -154,14 +154,15 @@ public static void setCursorResizeIcon(ResizeDragArea dragArea) {

public static void resetCursorIcon() {
if (resizeCursorV == null) return; // cursors failed to initialized
if (currentCursor == resizeCursorDiag || currentCursor == resizeCursorDiagInverse || currentCursor == resizeCursorH || currentCursor == resizeCursorV) {
currentCursor = null;
}
try {
if (currentCursor == resizeCursorDiag || currentCursor == resizeCursorDiagInverse || currentCursor == resizeCursorH || currentCursor == resizeCursorV) {
currentCursor = null;
}
Mouse.setNativeCursor(currentCursor);
currentCursor = null;
} catch (LWJGLException e) {
throw new RuntimeException(e);
} finally {
currentCursor = null;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/cleanroommc/modularui/ModularUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void onServerLoad(FMLServerStartingEvent event) {

public enum Mods {

LWJGL3IFY(ModIds.LWJGL3IFY),
BAUBLES(ModIds.BAUBLES),
BOGOSORTER(ModIds.BOGOSORTER),
GT5U(ModIds.GT5U, mod -> !Loader.isModLoaded(ModIds.GT6)),
Expand Down Expand Up @@ -95,6 +96,7 @@ public boolean isLoaded() {

public static class ModIds {

public static final String LWJGL3IFY = "lwjgl3ify";
public static final String BOGOSORTER = "bogosorter";
public static final String GT5U = "gregtech";
public static final String GT6 = "gregapi_post";
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/com/cleanroommc/modularui/api/IMuiScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import me.eigenraven.lwjgl3ify.api.InputEvents;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

Expand All @@ -27,10 +28,15 @@
* Additionally, the GuiScreen MUST call {@link ModularScreen#construct(IMuiScreen)} in its constructor.
* See {@link com.cleanroommc.modularui.screen.GuiScreenWrapper GuiScreenWrapper} and {@link com.cleanroommc.modularui.screen.GuiContainerWrapper GuiContainerWrapper}
* for default implementations.
* <p>
* {@link InputEvents.KeyboardListener} is implemented for Lwjgl3ify compat.
*/
@Optional.Interface(modid = ModularUI.ModIds.NEA, iface = "com.cleanroommc.neverenoughanimations.api.IAnimatedScreen")
@Optional.InterfaceList({
@Optional.Interface(modid = ModularUI.ModIds.NEA, iface = "com.cleanroommc.neverenoughanimations.api.IAnimatedScreen"),
@Optional.Interface(modid = ModularUI.ModIds.LWJGL3IFY, iface = "me.eigenraven.lwjgl3ify.api.InputEvents$KeyboardListener")
})
@SideOnly(Side.CLIENT)
public interface IMuiScreen extends IAnimatedScreen {
public interface IMuiScreen extends IAnimatedScreen, InputEvents.KeyboardListener {

/**
* Returns the {@link ModularScreen} that is being wrapped. This should return a final instance field.
Expand Down Expand Up @@ -133,4 +139,16 @@ default GuiScreen getGuiScreen() {
default int nea$getHeight() {
return getScreen().getMainPanel().getArea().height;
}

@ApiStatus.Internal
@Override
default void onKeyEvent(InputEvents.KeyEvent event) {
getScreen().onKeyEvent(event);
}

@ApiStatus.Internal
@Override
default void onTextEvent(InputEvents.TextEvent event) {
getScreen().onTextEvent(event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.cleanroommc.modularui.api.widget;

import com.cleanroommc.modularui.ModularUI;

import cpw.mods.fml.common.Optional;

import me.eigenraven.lwjgl3ify.api.InputEvents;

public interface ModernInteractable {

@Optional.Method(modid = ModularUI.ModIds.LWJGL3IFY)
default Interactable.Result onKeyEvent(InputEvents.KeyEvent event) {
return Interactable.Result.IGNORE;
}

@Optional.Method(modid = ModularUI.ModIds.LWJGL3IFY)
default boolean onTextInput(InputEvents.TextEvent event) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.input.Keyboard;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -79,6 +80,9 @@ public static void open(ModularScreen screen) {
}
overlay.add(screen);
screen.onOpen();
if (!Keyboard.areRepeatEventsEnabled()) {
Keyboard.enableRepeatEvents(true);
}
}

public static void close(ModularScreen screen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ private static void onGuiChanged(GuiScreen oldScreen, GuiScreen newScreen) {
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);
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/com/cleanroommc/modularui/screen/ModularPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.cleanroommc.modularui.api.widget.IFocusedWidget;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.api.widget.ModernInteractable;
import com.cleanroommc.modularui.api.widget.ResizeDragArea;
import com.cleanroommc.modularui.integration.nei.NEIUtil;
import com.cleanroommc.modularui.integration.recipeviewer.RecipeViewerGhostIngredientSlot;
Expand All @@ -33,6 +34,10 @@
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
import com.cleanroommc.neverenoughanimations.NEAConfig;

import cpw.mods.fml.common.Optional;

import me.eigenraven.lwjgl3ify.api.InputEvents;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;

Expand Down Expand Up @@ -636,6 +641,66 @@ public boolean onMouseDrag(int mouseButton, long timeSinceClick) {
});
}

/** Lwjgl3 key press event */
@Optional.Method(modid = ModularUI.ModIds.LWJGL3IFY)
public boolean onKeyEvent(InputEvents.KeyEvent event) {
return doSafeBool(() -> {
switch (modernInteractFocused(w -> w.onKeyEvent(event), Interactable.Result.IGNORE)) {
case STOP:
this.keyboard.pressed(LocatedWidget.EMPTY, event.sdlKeyCode);
return true;
case SUCCESS:
this.keyboard.pressed(getContext().getFocusedWidget(), event.sdlKeyCode);
return true;
}
LocatedWidget pressed = null;
boolean result = false;
for (LocatedWidget widget : this.hovering) {
if (widget.getElement() == null || !widget.getElement().isValid()) continue;
if (widget.getElement() instanceof ModernInteractable interactable) {
widget.applyMatrix(getContext());
Interactable.Result interactResult = interactable.onKeyEvent(event);
widget.unapplyMatrix(getContext());
if (interactResult.accepts) {
this.keyboard.addAcceptedInteractable((Interactable) interactable);
pressed = widget;
} else if (interactResult.stops) {
pressed = null;
}
if (interactResult.stops) {
result = true;
break;
}
}
if (!widget.getElement().canClickThrough()) break;
}
this.keyboard.pressed(pressed, event.sdlKeyCode);
return result;
});
}

/** Lwjgl3 text input event */
@Optional.Method(modid = ModularUI.ModIds.LWJGL3IFY)
public boolean onTextEvent(InputEvents.TextEvent event) {
return doSafeBool(() -> {
if (modernInteractFocused(w -> w.onTextInput(event), false)) {
return true;
}
for (LocatedWidget widget : this.hovering) {
if (widget.getElement() == null || !widget.getElement().isValid()) continue;
if (widget.getElement() instanceof ModernInteractable interactable) {
widget.applyMatrix(getContext());
boolean res = interactable.onTextInput(event);
widget.unapplyMatrix(getContext());
if (res) {
return true;
}
}
}
return false;
});
}

@SuppressWarnings("unchecked")
private <T, W extends IWidget & IFocusedWidget & Interactable> T interactFocused(Function<W, T> function, T defaultValue) {
LocatedWidget focused = this.getContext().getFocusedWidget();
Expand All @@ -648,6 +713,18 @@ private <T, W extends IWidget & IFocusedWidget & Interactable> T interactFocused
return result;
}

@SuppressWarnings("unchecked")
private <T, W extends IWidget & IFocusedWidget & ModernInteractable> T modernInteractFocused(Function<W, T> function, T defaultValue) {
LocatedWidget focused = this.getContext().getFocusedWidget();
T result = defaultValue;
if (focused.getElement() instanceof ModernInteractable interactable && focused.getElement().isValid()) {
focused.applyMatrix(getContext());
result = function.apply((W) interactable);
focused.unapplyMatrix(getContext());
}
return result;
}

/**
* @return if this panel can be dragged. Never works on the main panel.
*/
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import com.cleanroommc.modularui.widget.sizer.ResizeNode;
import com.cleanroommc.modularui.widget.sizer.ScreenResizeNode;

import cpw.mods.fml.common.Optional;

import me.eigenraven.lwjgl3ify.api.InputEvents;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
Expand Down Expand Up @@ -511,6 +515,32 @@ public boolean onMouseDrag(int mouseButton, long timeSinceClick) {
return false;
}

/** Lwjgl3 key press event */
@Optional.Method(modid = ModularUI.ModIds.LWJGL3IFY)
public void onKeyEvent(InputEvents.KeyEvent event) {
for (ModularPanel panel : this.panelManager.getOpenPanels()) {
if (panel.onKeyEvent(event)) {
return;
}
if (panel.disablePanelsBelow()) {
break;
}
}
}

/** Lwjgl3 text input event */
@Optional.Method(modid = ModularUI.ModIds.LWJGL3IFY)
public void onTextEvent(InputEvents.TextEvent event) {
for (ModularPanel panel : this.panelManager.getOpenPanels()) {
if (panel.onTextEvent(event)) {
return;
}
if (panel.disablePanelsBelow()) {
break;
}
}
}

/**
* Called with {@code true} after a widget which implements {@link com.cleanroommc.modularui.api.widget.IFocusedWidget IFocusedWidget}
* has consumed a mouse press and called with {@code false} if a widget is currently focused and anything else has consumed a mouse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void onItemUse(PlayerInteractEvent event) {
ItemStack itemStack = event.entityPlayer.getHeldItem();
if (itemStack.getItem() == Items.diamond) {
ClientGUI.open(new TestGuis());
event.setCanceled(true);
} // todo: fix ScreenEntityRender / TestGui().
//else if (itemStack.getItem() == Items.emerald) {
// HoloUI.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ public void dispose() {
@Override
public void onMouseStartHover() {
super.onMouseStartHover();
this.animator.resume(false);
if (this.animator != null) {
this.animator.resume(false);
}
}

@Override
public void onMouseEndHover() {
super.onMouseEndHover();
this.animator.stop(true);
this.animator.reset();
if (this.animator != null) {
this.animator.stop(true);
this.animator.reset();
}
this.progress = 0;
}

Expand Down
Loading
Loading