Skip to content
Merged

3.1 MUI #4547

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
8 changes: 4 additions & 4 deletions src/main/java/com/gregtechceu/gtceu/api/mui/GuiError.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gregtechceu.gtceu.api.mui;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.mui.base.widget.IGuiElement;
import com.gregtechceu.gtceu.api.mui.base.widget.IWidget;

import lombok.Getter;
import org.apache.logging.log4j.Level;
Expand All @@ -10,7 +10,7 @@

public class GuiError {

public static void throwNew(IGuiElement guiElement, Type type, String msg) {
public static void throwNew(IWidget guiElement, Type type, String msg) {
if (GTCEu.isClientSide()) {
GuiErrorHandler.INSTANCE.pushError(guiElement, type, msg);
}
Expand All @@ -21,11 +21,11 @@ public static void throwNew(IGuiElement guiElement, Type type, String msg) {
@Getter
private final String msg;
@Getter
private final IGuiElement reference;
private final IWidget reference;
@Getter
private final Type type;

protected GuiError(String msg, IGuiElement reference, Type type) {
protected GuiError(String msg, IWidget reference, Type type) {
this.msg = msg;
this.reference = reference;
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.gregtechceu.gtceu.api.mui;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.mui.base.widget.IGuiElement;
import com.gregtechceu.gtceu.api.mui.base.widget.IWidget;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand All @@ -28,7 +28,7 @@ public void clear() {
this.errors.clear();
}

void pushError(IGuiElement reference, GuiError.Type type, String msg) {
void pushError(IWidget reference, GuiError.Type type, String msg) {
GuiError error = new GuiError(msg, reference, type);
if (this.errorSet.add(error)) {
GTCEu.LOGGER.log(error.getLevel(), error);
Expand Down
33 changes: 31 additions & 2 deletions src/main/java/com/gregtechceu/gtceu/api/mui/base/IThemeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gregtechceu.gtceu.api.mui.base.drawable.IDrawable;
import com.gregtechceu.gtceu.api.mui.drawable.Scrollbar;
import com.gregtechceu.gtceu.api.mui.theme.*;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;
import com.gregtechceu.gtceu.client.mui.screen.ModularScreen;
import com.gregtechceu.gtceu.common.mui.GTGuiTextures;
import com.gregtechceu.gtceu.utils.serialization.json.JsonBuilder;
Expand Down Expand Up @@ -149,7 +150,35 @@ default void registerTheme(ThemeBuilder<?> themeBuilder) {
* @param defaultTheme default theme if no theme was found
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
*/
ITheme getThemeForScreen(String owner, String name, @Nullable String defaultTheme);
default ITheme getThemeForScreen(String owner, String name, @Nullable String defaultTheme,
@Nullable String fallbackTheme) {
return getThemeForScreen(owner, name, null, defaultTheme, fallbackTheme);
}

/**
* Gets the appropriate theme for a screen.
*
* @param owner owner of the screen
* @param name name of the screen
* @param panel the name
* @param defaultTheme default theme if no theme was found
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
*/
ITheme getThemeForScreen(String owner, String name, @Nullable String panel, @Nullable String defaultTheme,
@Nullable String fallbackTheme);

/**
* Gets the appropriate theme for a specific panel.
*
* @param panel the panel to find a theme for
* @param defaultTheme default theme if no theme was found
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
*/
default ITheme getThemeForScreen(ModularPanel panel, @Nullable String defaultTheme) {
ModularScreen screen = panel.getScreen();
return getThemeForScreen(screen.getOwner(), screen.getName(), panel.getName(), defaultTheme,
screen.getThemeOverride());
}

/**
* Gets the appropriate theme for a screen.
Expand All @@ -159,7 +188,7 @@ default void registerTheme(ThemeBuilder<?> themeBuilder) {
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
*/
default ITheme getThemeForScreen(ModularScreen screen, @Nullable String defaultTheme) {
return getThemeForScreen(screen.getOwner(), screen.getName(), defaultTheme);
return getThemeForScreen(screen.getOwner(), screen.getName(), defaultTheme, null);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/api/mui/base/ITreeNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gregtechceu.gtceu.api.mui.base;

import java.util.List;

public interface ITreeNode<T extends ITreeNode<T>> {

T getParent();

default boolean hasParent() {
return getParent() != null;
}

List<T> getChildren();

default boolean hasChildren() {
return !getChildren().isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.api.mui.base;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.mui.factory.GuiData;
import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;
Expand All @@ -25,7 +26,10 @@ public interface IUIHolder<T extends GuiData> {
*/
@OnlyIn(Dist.CLIENT)
default ModularScreen createScreen(T data, ModularPanel mainPanel) {
return new ModularScreen(mainPanel);
GTCEu.LOGGER
.warn("IGuiHolder.createScreen() should be overridden to pass your own mod id to the ModularScreen. " +
"In future versions this method must be overridden or else it will crash!");
return new ModularScreen(GTCEu.MOD_ID, mainPanel);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.gregtechceu.gtceu.api.mui.base.layout;

import com.gregtechceu.gtceu.api.mui.base.GuiAxis;
import com.gregtechceu.gtceu.api.mui.widget.sizer.Area;

public interface IResizeParent {

/**
* @return area of the element
*/
Area getArea();

/**
* @return true if the relative x position is calculated
*/
boolean isXCalculated();

/**
* @return true if the relative y position is calculated
*/
boolean isYCalculated();

/**
* @return true if the width is calculated
*/
boolean isWidthCalculated();

/**
* @return true if the height is calculated
*/
boolean isHeightCalculated();

boolean areChildrenCalculated();

boolean isLayoutDone();

boolean canRelayout(boolean isParentLayout);

default boolean isSizeCalculated(GuiAxis axis) {
return axis.isHorizontal() ? isWidthCalculated() : isHeightCalculated();
}

default boolean isPosCalculated(GuiAxis axis) {
return axis.isHorizontal() ? isXCalculated() : isYCalculated();
}

/**
* @return true if the relative position and size are fully calculated
*/
default boolean isSelfFullyCalculated(boolean isParentLayout) {
return isSelfFullyCalculated() && !canRelayout(isParentLayout);
}

default boolean isSelfFullyCalculated() {
return isXCalculated() && isYCalculated() && isWidthCalculated() && isHeightCalculated();
}

default boolean isFullyCalculated() {
return isSelfFullyCalculated() && areChildrenCalculated() && isLayoutDone();
}

default boolean isFullyCalculated(boolean isParentLayout) {
return isFullyCalculated() && !canRelayout(isParentLayout);
}

/**
* @return true if margin and padding are applied on the x-axis
*/
boolean isXMarginPaddingApplied();

/**
* @return true if margin and padding are applied on the y-axis
*/
boolean isYMarginPaddingApplied();
}
Original file line number Diff line number Diff line change
@@ -1,103 +1,43 @@
package com.gregtechceu.gtceu.api.mui.base.layout;

import com.gregtechceu.gtceu.api.mui.base.GuiAxis;
import com.gregtechceu.gtceu.api.mui.base.widget.IGuiElement;
import com.gregtechceu.gtceu.api.mui.widget.sizer.Area;

/**
* An interface that handles resizing of widgets.
* Usually this interface is not implemented by the users of this library or will even interact with it.
*/
public interface IResizeable {
public interface IResizeable extends IResizeParent {

/**
* Called once before resizing
*/
void initResizing();
void initResizing(boolean onOpen);

/**
* Resizes the given element
*
* @param guiElement element to resize
* @param isParentLayout if the parent is a layout widget
* @return true if element is fully resized
*/
boolean resize(IGuiElement guiElement, boolean isParentLayout);
boolean resize(boolean isParentLayout);

/**
* Called if {@link #resize(IGuiElement, boolean)} returned false after children have been resized.
* Called if {@link #resize(boolean)} returned false after children have been resized.
*
* @param guiElement element to resize
* @return if element is fully resized
*/
boolean postResize(IGuiElement guiElement);
boolean postResize();

/**
* Called after all elements in the tree are resized and the absolute positions needs to be calculated from the
* relative position.
*
* @param guiElement element that was resized
*/
default void applyPos(IGuiElement guiElement) {}

/**
* @return area of the element
*/
// TODO doesnt fit with the other api methods in this interface
Area getArea();

/**
* @return true if the relative x position is calculated
*/
boolean isXCalculated();

/**
* @return true if the relative y position is calculated
*/
boolean isYCalculated();

/**
* @return true if the width is calculated
*/
boolean isWidthCalculated();

/**
* @return true if the height is calculated
*/
boolean isHeightCalculated();

boolean areChildrenCalculated();

boolean isLayoutDone();

default boolean isSizeCalculated(GuiAxis axis) {
return axis.isHorizontal() ? isWidthCalculated() : isHeightCalculated();
}

default boolean isPosCalculated(GuiAxis axis) {
return axis.isHorizontal() ? isXCalculated() : isYCalculated();
}
default void preApplyPos() {}

/**
* @return true if the relative position and size are fully calculated
* This converts the relative pos to resizer parent to relative pos to widget parent.
*/
default boolean isSelfFullyCalculated(boolean isParentLayout) {
return isSelfFullyCalculated() && !canRelayout(isParentLayout);
}

default boolean isSelfFullyCalculated() {
return isXCalculated() && isYCalculated() && isWidthCalculated() && isHeightCalculated();
}

default boolean isFullyCalculated() {
return isSelfFullyCalculated() && areChildrenCalculated() && isLayoutDone();
}

default boolean isFullyCalculated(boolean isParentLayout) {
return isSelfFullyCalculated(isParentLayout) && areChildrenCalculated() && isLayoutDone();
}

boolean canRelayout(boolean isParentLayout);
default void applyPos() {}

void setChildrenResized(boolean resized);

Expand Down Expand Up @@ -182,14 +122,4 @@ default void setMarginPaddingApplied(GuiAxis axis, boolean b) {
setYMarginPaddingApplied(b);
}
}

/**
* @return true if margin and padding are applied on the x-axis
*/
boolean isXMarginPaddingApplied();

/**
* @return true if margin and padding are applied on the y-axis
*/
boolean isYMarginPaddingApplied();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gregtechceu.gtceu.api.mui.base.widget;

import net.minecraft.world.inventory.Slot;

public interface IDelegatingWidget extends IWidget, IVanillaSlot {

IWidget getDelegate();

@Override
default Slot getVanillaSlot() {
return getDelegate() instanceof IVanillaSlot vanillaSlot ? vanillaSlot.getVanillaSlot() : null;
}

@Override
default boolean handleAsVanillaSlot() {
return getDelegate() instanceof IVanillaSlot vanillaSlot && vanillaSlot.handleAsVanillaSlot();
}
}
Loading
Loading