Skip to content

Commit

Permalink
start on IFancyUIMachine migration, dynamic texture support
Browse files Browse the repository at this point in the history
  • Loading branch information
screret committed Dec 11, 2024
1 parent 54066ea commit f4d323a
Show file tree
Hide file tree
Showing 27 changed files with 1,265 additions and 164 deletions.
3 changes: 0 additions & 3 deletions interface_injection/interfaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"net/minecraft/client/gui/components/AbstractWidget": [
"com/gregtechceu/gtceu/api/ui/inject/UIComponentStub"
],
"net/minecraft/world/inventory/Slot": [
"com/gregtechceu/gtceu/api/ui/util/pond/UISlotExtension"
],
"net/minecraft/client/renderer/entity/EntityRenderDispatcher": [
"com/gregtechceu/gtceu/api/ui/util/pond/UIEntityRenderDispatcherExtension"
],
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/api/gui/GuiTextures.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.gregtechceu.gtceu.api.gui;

import com.gregtechceu.gtceu.GTCEu;
import com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture;
import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture;

import lombok.val;
import net.minecraft.resources.ResourceLocation;

/**
* @author KilaBash
Expand Down Expand Up @@ -69,6 +71,11 @@ public class GuiTextures {
public static final ResourceBorderTexture TITLE_BAR_BACKGROUND = new ResourceBorderTexture(
"gtceu:textures/gui/base/title_bar_background.png", 16, 16, 4, 4);

public static final ResourceLocation UI_BACKGROUND_TEXTURE = GTCEu.id("background");
public static final ResourceLocation UI_BACKGROUND_INVERSE_TEXTURE = GTCEu.id("background_inverse");
public static final ResourceLocation TITLE_BAR_BACKGROUND_TEXTURE = GTCEu.id("title_bar_background");


public static final ResourceTexture DISPLAY = new ResourceTexture("gtceu:textures/gui/base/display.png");
public static final SteamTexture DISPLAY_STEAM = SteamTexture.fullImage("gtceu:textures/gui/base/display_%s.png");
public static final ResourceTexture BLANK = new ResourceBorderTexture("gtceu:textures/gui/base/blank.png", 1, 1, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.gregtechceu.gtceu.api.block.IMachineBlock;
import com.gregtechceu.gtceu.api.capability.recipe.RecipeCapability;
import com.gregtechceu.gtceu.api.gui.editor.EditableMachineUI;
import com.gregtechceu.gtceu.api.item.MetaMachineItem;
import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
import com.gregtechceu.gtceu.api.recipe.modifier.RecipeModifier;

import com.gregtechceu.gtceu.api.ui.editable.EditableMachineUI;
import com.lowdragmc.lowdraglib.client.renderer.IRenderer;
import com.lowdragmc.lowdraglib.utils.ShapeUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import com.gregtechceu.gtceu.api.machine.fancyconfigurator.MachineModeFancyConfigurator;
import com.gregtechceu.gtceu.api.machine.fancyconfigurator.OverclockFancyConfigurator;

import com.lowdragmc.lowdraglib.gui.modular.ModularUI;
import com.gregtechceu.gtceu.api.ui.container.RootContainer;
import com.gregtechceu.gtceu.api.ui.container.UIContainers;
import com.gregtechceu.gtceu.api.ui.core.ParentUIComponent;
import com.gregtechceu.gtceu.api.ui.core.Sizing;
import com.gregtechceu.gtceu.api.ui.core.UIAdapter;
import com.gregtechceu.gtceu.api.ui.fancy.FancyMachineUIComponent;
import com.gregtechceu.gtceu.api.ui.fancy.IFancyUIProvider;
import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture;
import com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture;
import com.lowdragmc.lowdraglib.gui.widget.ImageWidget;
Expand Down Expand Up @@ -36,18 +42,19 @@
* @date 2023/6/28
* @implNote IFancyUIMachine
*/
public interface IFancyUIMachine extends IUIMachine, IFancyUIProvider {
public interface IFancyUIMachine extends IUIMachine2, IFancyUIProvider {

@Override
default ModularUI createUI(Player entityPlayer) {
return new ModularUI(176, 166, this, entityPlayer).widget(new FancyMachineUIWidget(this, 176, 166));
@OnlyIn(Dist.CLIENT)
default void loadClientUI(Player player, UIAdapter<RootContainer> adapter) {
adapter.rootComponent
.child(new FancyMachineUIComponent(this, Sizing.fixed(176), Sizing.fixed(166)));
}

/**
* We should not override this method in general, and use {@link IFancyUIMachine#createUIWidget()} instead,
*/
@Override
default Widget createMainPage(FancyMachineUIWidget widget) {
default ParentUIComponent createMainPage(FancyMachineUIWidget widget) {
var editableUI = self().getDefinition().getEditableUI();
if (editableUI != null) {
var template = editableUI.createCustomUI();
Expand All @@ -63,9 +70,9 @@ default Widget createMainPage(FancyMachineUIWidget widget) {
/**
* Create the core widget of this machine.
*/
default Widget createUIWidget() {
var group = new WidgetGroup(0, 0, 100, 100);
if (isRemote()) {
default ParentUIComponent createUIWidget() {
var group = UIContainers.root(Sizing.content(), Sizing.content());
if (isClientSide()) {
group.addWidget(new ImageWidget((100 - 48) / 2, 60, 48, 16, GuiTextures.SCENE));
TrackedDummyWorld world = new TrackedDummyWorld();
world.addBlock(BlockPos.ZERO, BlockInfo.fromBlockState(self().getBlockState()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,32 @@
import com.gregtechceu.gtceu.api.ui.parsing.UIModel;
import com.gregtechceu.gtceu.api.ui.parsing.UIParsing;

import net.minecraft.resources.ResourceLocation;
import com.gregtechceu.gtceu.api.ui.texture.ResourceTexture;
import com.gregtechceu.gtceu.api.ui.texture.UITexture;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import com.mojang.blaze3d.systems.RenderSystem;
import org.w3c.dom.Element;

import java.util.Map;

@Accessors(fluent = true, chain = true)
public class TextureComponent extends BaseUIComponent {

protected final ResourceLocation texture;
protected final UITexture texture;
protected final int u, v;
protected final int regionWidth, regionHeight;
protected final int textureWidth, textureHeight;

@Getter
protected final AnimatableProperty<PositionedRectangle> visibleArea;
@Getter
@Setter
protected boolean blend = false;

protected TextureComponent(ResourceLocation texture, int u, int v, int regionWidth, int regionHeight,
protected TextureComponent(UITexture texture, int u, int v, int regionWidth, int regionHeight,
int textureWidth, int textureHeight) {
this.texture = texture;
this.u = u;
Expand Down Expand Up @@ -56,6 +64,10 @@ public void update(float delta, int mouseX, int mouseY) {

@Override
public void draw(UIGuiGraphics graphics, int mouseX, int mouseY, float partialTicks, float delta) {
if (texture == null) {
return;
}

RenderSystem.enableDepthTest();

if (this.blend) {
Expand All @@ -70,9 +82,16 @@ public void draw(UIGuiGraphics graphics, int mouseX, int mouseY, float partialTi

var visibleArea = this.visibleArea.get();

int bottomEdge = Math.min(visibleArea.y() + visibleArea.height(), regionHeight);
int rightEdge = Math.min(visibleArea.x() + visibleArea.width(), regionWidth);
int width = Math.min(visibleArea.width(), regionWidth);
int height = Math.min(visibleArea.height(), regionHeight);
this.texture.drawSubArea(graphics, visibleArea.x(), visibleArea.y(),
width, height,
(float) (this.u + visibleArea.x()) / visibleArea.y(),
(float) (this.v + visibleArea.y()) / visibleArea.y(),
(float) width / visibleArea.x(),
(float) height / visibleArea.y());

/*
graphics.blit(this.texture,
visibleArea.x(),
visibleArea.y(),
Expand All @@ -83,6 +102,7 @@ public void draw(UIGuiGraphics graphics, int mouseX, int mouseY, float partialTi
rightEdge - visibleArea.x(),
bottomEdge - visibleArea.y(),
this.textureWidth, this.textureHeight);
*/

if (this.blend) {
RenderSystem.disableBlend();
Expand All @@ -101,19 +121,6 @@ public TextureComponent resetVisibleArea() {
return this;
}

public AnimatableProperty<PositionedRectangle> visibleArea() {
return this.visibleArea;
}

public TextureComponent blend(boolean blend) {
this.blend = blend;
return this;
}

public boolean blend() {
return this.blend;
}

@Override
public void parseProperties(UIModel model, Element element, Map<String, Element> children) {
super.parseProperties(model, element, children);
Expand Down Expand Up @@ -173,6 +180,7 @@ public static TextureComponent parse(Element element) {
textureHeight = UIParsing.parseSignedInt(element.getAttributeNode("texture-height"));
}

return new TextureComponent(textureId, u, v, regionWidth, regionHeight, textureWidth, textureHeight);
// TODO UITexture parser
return new TextureComponent(new ResourceTexture(textureId), u, v, regionWidth, regionHeight, textureWidth, textureHeight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
import com.gregtechceu.gtceu.api.ui.parsing.UIModel;
import com.gregtechceu.gtceu.api.ui.parsing.UIParsing;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Element;

import java.util.Map;

@Accessors(fluent = true, chain = true)
public class DraggableContainer<C extends UIComponent> extends WrappingParentUIComponent<C> {

@Getter
protected int foreheadSize = 10;
@Getter
@Setter
protected boolean alwaysOnTop = false;

@Getter
protected int baseX = 0, baseY = 0;
protected double xOffset = 0, yOffset = 0;

Expand Down Expand Up @@ -75,16 +83,6 @@ public DraggableContainer<C> y(int y) {
return this;
}

@Override
public int baseX() {
return this.baseX;
}

@Override
public int baseY() {
return this.baseY;
}

@Override
public ParentUIComponent padding(Insets padding) {
return super.padding(
Expand All @@ -100,19 +98,6 @@ public DraggableContainer<C> foreheadSize(int foreheadSize) {
return this;
}

public int foreheadSize() {
return this.foreheadSize;
}

public DraggableContainer<C> alwaysOnTop(boolean alwaysOnTop) {
this.alwaysOnTop = alwaysOnTop;
return this;
}

public boolean alwaysOnTop() {
return this.alwaysOnTop;
}

@Override
public void parseProperties(UIModel model, Element element, Map<String, Element> children) {
super.parseProperties(model, element, children);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import com.gregtechceu.gtceu.api.ui.core.*;

import lombok.Getter;
import lombok.Setter;
import org.lwjgl.glfw.GLFW;

public class OverlayContainer<C extends UIComponent> extends WrappingParentUIComponent<C> {

/**
* Whether this overlay should close when a mouse
* click occurs outside the bounds of its contents
*/
@Getter
@Setter
protected boolean closeOnClick = true;

protected OverlayContainer(C child) {
Expand Down Expand Up @@ -69,21 +77,4 @@ protected int childMountX() {
protected int childMountY() {
return this.padding.get().top() + (this.height() - this.child.fullSize().height()) / 2;
}

/**
* Set whether this overlay should close when a mouse
* click occurs outside the bounds of its contents
*/
public OverlayContainer<C> closeOnClick(boolean closeOnClick) {
this.closeOnClick = closeOnClick;
return this;
}

/**
* Whether this overlay should close when a mouse
* click occurs outside the bounds of its contents
*/
public boolean closeOnClick() {
return closeOnClick;
}
}
Loading

0 comments on commit f4d323a

Please sign in to comment.