Skip to content

Commit

Permalink
it works 🔥 (I believe, no way of *testing it* yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
screret committed Dec 7, 2024
1 parent e4968a3 commit 021be67
Show file tree
Hide file tree
Showing 134 changed files with 4,555 additions and 821 deletions.
1 change: 1 addition & 0 deletions gradle/scripts/moddevgradle.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ neoForge {

// This line is optional. Access Transformers are automatically detected
accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg')
interfaceInjectionData.from "interface_injection/interfaces.json"

addModdingDependenciesTo(sourceSets.test)
addModdingDependenciesTo(sourceSets.extra)
Expand Down
4 changes: 2 additions & 2 deletions gradle/scripts/repositories.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ repositories {
includeGroup "thedarkcolour"
}
}
maven { url "https://maven.architectury.dev/" }
maven { url = "https://maven.architectury.dev/" }
maven { url = "https://maven.jamieswhiteshirt.com/libs-release" } // Reach Entity Attributes
maven { url 'https://jitpack.io' } // Mixin Extras, Fabric ASM
maven { url = 'https://jitpack.io' } // Mixin Extras, Fabric ASM
}
12 changes: 12 additions & 0 deletions interface_injection/interfaces.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"net/minecraft/client/gui/components/AbstractWidget": [
"com/gregtechceu/gtceu/api/ui/inject/UIComponentStub"
],
"net/minecraft/client/renderer/entity/EntityRenderDispatcher": [
"com/gregtechceu/gtceu/api/ui/util/pond/UIEntityRenderDispatcherExtension"
],
"net/minecraft/world/inventory/AbstractContainerMenu": [
"com/gregtechceu/gtceu/client/ui/screens/UIAbstractContainerMenu",
"com/gregtechceu/gtceu/api/ui/util/pond/UIAbstractContainerMenuExtension"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.ui.core.*;
import com.gregtechceu.gtceu.api.ui.inject.GreedyInputUIComponent;
import com.gregtechceu.gtceu.api.ui.util.DisposableScreen;
import com.gregtechceu.gtceu.api.ui.util.UIErrorToast;
import com.gregtechceu.gtceu.api.ui.util.pond.UISlotExtension;
import com.gregtechceu.gtceu.core.mixins.ui.accessor.SlotAccessor;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
Expand All @@ -11,20 +16,24 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.Slot;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;

import java.util.function.BiFunction;

public abstract class BaseContainerScreen<R extends ParentUIComponent, S extends AbstractContainerMenu> extends AbstractContainerScreen<S> implements DisposableScreen {
public abstract class BaseContainerScreen<R extends ParentUIComponent, S extends AbstractContainerMenu>
extends AbstractContainerScreen<S> implements DisposableScreen {

/**
* The UI adapter of this screen. This handles
* all user input as well as setting up GL state for rendering
* and managing component focus
*/
@Getter
protected UIAdapter<R> uiAdapter = null;

/**
Expand Down Expand Up @@ -91,7 +100,7 @@ protected void init() {
* @param index The index of the slot to disable
*/
protected void disableSlot(int index) {
((SlotExtension) this.menu.slots.get(index)).owo$setDisabledOverride(true);
((UISlotExtension) this.menu.slots.get(index)).gtceu$setDisabledOverride(true);
}

/**
Expand All @@ -100,7 +109,7 @@ protected void disableSlot(int index) {
* re-enable itself
*/
protected void disableSlot(Slot slot) {
((SlotExtension) slot).owo$setDisabledOverride(true);
((UISlotExtension) slot).gtceu$setDisabledOverride(true);
}

/**
Expand All @@ -111,7 +120,7 @@ protected void disableSlot(Slot slot) {
* @param index The index of the slot to enable
*/
protected void enableSlot(int index) {
((SlotExtension) this.menu.slots.get(index)).owo$setDisabledOverride(false);
((UISlotExtension) this.menu.slots.get(index)).gtceu$setDisabledOverride(false);
}

/**
Expand All @@ -120,15 +129,15 @@ protected void enableSlot(int index) {
* a slot that is disabled through its own will
*/
protected void enableSlot(Slot slot) {
((SlotExtension) slot).owo$setDisabledOverride(true);
((UISlotExtension) slot).gtceu$setDisabledOverride(true);
}

protected boolean isSlotEnabled(int index) {
return ((SlotExtension) this.menu.slots.get(index)).owo$getDisabledOverride();
return ((UISlotExtension) this.menu.slots.get(index)).gtceu$getDisabledOverride();
}

protected boolean isSlotEnabled(Slot slot) {
return ((SlotExtension) slot).owo$getDisabledOverride();
return ((UISlotExtension) slot).gtceu$getDisabledOverride();
}

/**
Expand All @@ -144,15 +153,15 @@ protected SlotComponent slotAsComponent(int index) {

/**
* A convenience shorthand for querying a component from the adapter's
* root component via {@link ParentComponent#childById(Class, String)}
* root component via {@link ParentUIComponent#childById(Class, String)}
*/
protected <C extends Component> @Nullable C component(Class<C> expectedClass, String id) {
protected <C extends UIComponent> @Nullable C component(Class<C> expectedClass, String id) {
return this.uiAdapter.rootComponent.childById(expectedClass, id);
}

@Override
public void render(GuiGraphics vanillaContext, int mouseX, int mouseY, float delta) {
var context = UIGuiGraphics.of(vanillaContext);
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
var context = UIGuiGraphics.of(guiGraphics);
if (!this.invalid) {
super.render(context, mouseX, mouseY, delta);

Expand All @@ -164,13 +173,11 @@ public void render(GuiGraphics vanillaContext, int mouseX, int mouseY, float del
if (!slot.hasItem()) continue;

context.drawText(Component.literal("H:" + i),
this.x + slot.x + 15, this.y + slot.y + 9, .5f, 0x0096FF,
UIGuiGraphics.TextAnchor.BOTTOM_RIGHT
);
this.leftPos + slot.x + 15, this.topPos + slot.y + 9, .5f, 0x0096FF,
UIGuiGraphics.TextAnchor.BOTTOM_RIGHT);
context.drawText(Component.literal("I:" + slot.getContainerSlot()),
this.x + slot.x + 15, this.y + slot.y + 15, .5f, 0x5800FF,
UIGuiGraphics.TextAnchor.BOTTOM_RIGHT
);
this.leftPos + slot.x + 15, this.topPos + slot.y + 15, .5f, 0x5800FF,
UIGuiGraphics.TextAnchor.BOTTOM_RIGHT);
}

context.pose().translate(0, 0, -500);
Expand All @@ -189,14 +196,16 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return true;
}

return (modifiers & GLFW.GLFW_MOD_CONTROL) == 0 && this.uiAdapter.rootComponent.focusHandler().focused() instanceof GreedyInputComponent inputComponent
? inputComponent.onKeyPress(keyCode, scanCode, modifiers)
: super.keyPressed(keyCode, scanCode, modifiers);
return (modifiers & GLFW.GLFW_MOD_CONTROL) == 0 &&
this.uiAdapter.rootComponent.focusHandler().focused() instanceof GreedyInputUIComponent inputComponent ?
inputComponent.onKeyPress(keyCode, scanCode, modifiers) :
super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
return this.uiAdapter.mouseDragged(mouseX, mouseY, button, deltaX, deltaY) || super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
return this.uiAdapter.mouseDragged(mouseX, mouseY, button, deltaX, deltaY) ||
super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}

@Nullable
Expand Down Expand Up @@ -237,16 +246,15 @@ public void draw(UIGuiGraphics context, int mouseX, int mouseY, float partialTic
int[] scissor = new int[4];
GL11.glGetIntegerv(GL11.GL_SCISSOR_BOX, scissor);

((SlotExtension) this.slot).owo$setScissorArea(PositionedRectangle.of(
scissor[0], scissor[1], scissor[2], scissor[3]
));
((UISlotExtension) this.slot).gtceu$setScissorArea(PositionedRectangle.of(
scissor[0], scissor[1], scissor[2], scissor[3]));
}

@Override
public void update(float delta, int mouseX, int mouseY) {
super.update(delta, mouseX, mouseY);

((SlotExtension) this.slot).owo$setDisabledOverride(!this.didDraw);
((UISlotExtension) this.slot).gtceu$setDisabledOverride(!this.didDraw);

this.didDraw = false;
}
Expand Down Expand Up @@ -276,13 +284,13 @@ protected int determineVerticalContentSize(Sizing sizing) {
@Override
public void updateX(int x) {
super.updateX(x);
((SlotAccessor) this.slot).owo$setX(x - BaseContainerScreen.this.x);
((SlotAccessor) this.slot).gtceu$setX(x - BaseContainerScreen.this.leftPos);
}

@Override
public void updateY(int y) {
super.updateY(y);
((SlotAccessor) this.slot).owo$setY(y - BaseContainerScreen.this.y);
((SlotAccessor) this.slot).gtceu$setY(y - BaseContainerScreen.this.topPos);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.gregtechceu.gtceu.api.ui.util.FocusHandler;
import com.gregtechceu.gtceu.api.ui.util.Observable;
import com.gregtechceu.gtceu.api.ui.util.ScissorStack;

import net.minecraft.util.Mth;

import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;

Expand All @@ -19,6 +21,7 @@
* especially {@link io.wispforest.owo.ui.container.WrappingParentComponent} is often useful
*/
public abstract class BaseParentUIComponent extends BaseUIComponent implements ParentUIComponent {

protected final Observable<VerticalAlignment> verticalAlignment = Observable.of(VerticalAlignment.TOP);
protected final Observable<HorizontalAlignment> horizontalAlignment = Observable.of(HorizontalAlignment.LEFT);

Expand Down Expand Up @@ -207,8 +210,7 @@ public boolean onMouseDown(double mouseX, double mouseY, int button) {
this.focusHandler.updateClickFocus(this.x + mouseX, this.y + mouseY);
}

return ParentUIComponent.super.onMouseDown(mouseX, mouseY, button)
|| super.onMouseDown(mouseX, mouseY, button);
return ParentUIComponent.super.onMouseDown(mouseX, mouseY, button) || super.onMouseDown(mouseX, mouseY, button);
}

@Override
Expand All @@ -223,14 +225,16 @@ public boolean onMouseUp(double mouseX, double mouseY, int button) {

@Override
public boolean onMouseScroll(double mouseX, double mouseY, double amount) {
return ParentUIComponent.super.onMouseScroll(mouseX, mouseY, amount) || super.onMouseScroll(mouseX, mouseY, amount);
return ParentUIComponent.super.onMouseScroll(mouseX, mouseY, amount) ||
super.onMouseScroll(mouseX, mouseY, amount);
}

@Override
public boolean onMouseDrag(double mouseX, double mouseY, double deltaX, double deltaY, int button) {
if (this.focusHandler != null && this.focusHandler.focused() != null) {
final var focused = this.focusHandler.focused();
return focused.onMouseDrag(this.x + mouseX - focused.x(), this.y + mouseY - focused.y(), deltaX, deltaY, button);
return focused.onMouseDrag(this.x + mouseX - focused.x(), this.y + mouseY - focused.y(), deltaX, deltaY,
button);
} else {
return super.onMouseDrag(mouseX, mouseY, deltaX, deltaY, button);
}
Expand All @@ -242,12 +246,13 @@ public boolean onKeyPress(int keyCode, int scanCode, int modifiers) {

if (keyCode == GLFW.GLFW_KEY_TAB) {
this.focusHandler.cycle((modifiers & GLFW.GLFW_MOD_SHIFT) == 0);
} else if ((keyCode == GLFW.GLFW_KEY_RIGHT || keyCode == GLFW.GLFW_KEY_LEFT || keyCode == GLFW.GLFW_KEY_DOWN || keyCode == GLFW.GLFW_KEY_UP)
&& (modifiers & GLFW.GLFW_MOD_ALT) != 0) {
this.focusHandler.moveFocus(keyCode);
} else if (this.focusHandler.focused() != null) {
return this.focusHandler.focused().onKeyPress(keyCode, scanCode, modifiers);
}
} else if ((keyCode == GLFW.GLFW_KEY_RIGHT || keyCode == GLFW.GLFW_KEY_LEFT || keyCode == GLFW.GLFW_KEY_DOWN ||
keyCode == GLFW.GLFW_KEY_UP) && (modifiers & GLFW.GLFW_MOD_ALT) != 0) {
this.focusHandler.moveFocus(keyCode);
} else
if (this.focusHandler.focused() != null) {
return this.focusHandler.focused().onKeyPress(keyCode, scanCode, modifiers);
}

return super.onKeyPress(keyCode, scanCode, modifiers);
}
Expand Down Expand Up @@ -285,8 +290,8 @@ public void updateY(int y) {

/**
* @return The offset from the origin of this component
* at which children can start to be mounted. Accumulates
* padding as well as padding from content sizing
* at which children can start to be mounted. Accumulates
* padding as well as padding from content sizing
*/
protected Size childMountingOffset() {
var padding = this.padding.get();
Expand All @@ -295,8 +300,8 @@ protected Size childMountingOffset() {

/**
* @deprecated Use {@link #mountChild(UIComponent, Consumer)} instead. This new
* overload no longer inflates the child prior to mounting, as that is
* rarely ever necessary and was simply causing unnecessary calculations
* overload no longer inflates the child prior to mounting, as that is
* rarely ever necessary and was simply causing unnecessary calculations
*/
@Deprecated(forRemoval = true)
protected void mountChild(@Nullable UIComponent child, Size space, Consumer<UIComponent> layoutFunc) {
Expand Down Expand Up @@ -326,18 +331,20 @@ protected void mountChild(@Nullable UIComponent child, Consumer<UIComponent> lay
case ABSOLUTE -> child.mount(
this,
this.x + positioning.x + componentMargins.left() + padding.left(),
this.y + positioning.y + componentMargins.top() + padding.top()
);
this.y + positioning.y + componentMargins.top() + padding.top());
case RELATIVE -> child.mount(
this,
this.x + padding.left() + componentMargins.left() + Math.round((positioning.x / 100f) * (this.width() - child.fullSize().width() - padding.horizontal())),
this.y + padding.top() + componentMargins.top() + Math.round((positioning.y / 100f) * (this.height() - child.fullSize().height() - padding.vertical()))
);
this.x + padding.left() + componentMargins.left() +
Math.round((positioning.x / 100f) *
(this.width() - child.fullSize().width() - padding.horizontal())),
this.y + padding.top() + componentMargins.top() + Math.round(
(positioning.y / 100f) * (this.height() - child.fullSize().height() - padding.vertical())));
case ACROSS -> child.mount(
this,
this.x + padding.left() + componentMargins.left() + Math.round((positioning.x / 100f) * (this.width() - padding.horizontal())),
this.y + padding.top() + componentMargins.top() + Math.round((positioning.y / 100f) * (this.height() - padding.vertical()))
);
this.x + padding.left() + componentMargins.left() +
Math.round((positioning.x / 100f) * (this.width() - padding.horizontal())),
this.y + padding.top() + componentMargins.top() +
Math.round((positioning.y / 100f) * (this.height() - padding.vertical())));
}
}

Expand All @@ -348,14 +355,16 @@ protected void mountChild(@Nullable UIComponent child, Consumer<UIComponent> lay
*
* @param children The list of children to draw
*/
protected void drawChildren(UIGuiGraphics graphics, int mouseX, int mouseY, float partialTicks, float delta, List<? extends UIComponent> children) {
protected void drawChildren(UIGuiGraphics graphics, int mouseX, int mouseY, float partialTicks, float delta,
List<? extends UIComponent> children) {
if (!this.allowOverflow) {
var padding = this.padding.get();
ScissorStack.push(this.x + padding.left(), this.y + padding.top(), this.width - padding.horizontal(), this.height - padding.vertical(), graphics.pose());
ScissorStack.push(this.x + padding.left(), this.y + padding.top(), this.width - padding.horizontal(),
this.height - padding.vertical(), graphics.pose());
}

var focusHandler = this.focusHandler();
//noinspection ForLoopReplaceableByForEach
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < children.size(); i++) {
final var child = children.get(i);

Expand Down Expand Up @@ -386,9 +395,10 @@ protected Size calculateChildSpace(Size thisSpace) {
final var padding = this.padding.get();

return Size.of(
Mth.lerpInt(this.horizontalSizing.get().contentFactor(), this.width - padding.horizontal(), thisSpace.width() - padding.horizontal()),
Mth.lerpInt(this.verticalSizing.get().contentFactor(), this.height - padding.vertical(), thisSpace.height() - padding.vertical())
);
Mth.lerpInt(this.horizontalSizing.get().contentFactor(), this.width - padding.horizontal(),
thisSpace.width() - padding.horizontal()),
Mth.lerpInt(this.verticalSizing.get().contentFactor(), this.height - padding.vertical(),
thisSpace.height() - padding.vertical()));
}

@Override
Expand Down
Loading

0 comments on commit 021be67

Please sign in to comment.