Skip to content
Draft

3.1 #189

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
2 changes: 2 additions & 0 deletions src/main/java/com/cleanroommc/modularui/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.cleanroommc.modularui.holoui.HoloScreenEntity;
import com.cleanroommc.modularui.holoui.ScreenEntityRender;
import com.cleanroommc.modularui.keybind.KeyBindHandler;
import com.cleanroommc.modularui.overlay.DebugOverlay;
import com.cleanroommc.modularui.screen.ClientScreenHandler;
import com.cleanroommc.modularui.test.EventHandler;
import com.cleanroommc.modularui.test.OverlayTest;
Expand Down Expand Up @@ -70,6 +71,7 @@ void preInit(FMLPreInitializationEvent event) {
testKey = new KeyBinding("key.test", KeyConflictContext.IN_GAME, Keyboard.KEY_NUMPAD4, "key.categories.modularui");
ClientRegistry.registerKeyBinding(testKey);
}
DebugOverlay.register();
if (ModularUIConfig.enableTestOverlays) {
OverlayTest.init();
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/com/cleanroommc/modularui/GuiError.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.cleanroommc.modularui;

import com.cleanroommc.modularui.api.widget.IGuiElement;

import com.cleanroommc.modularui.network.NetworkHandler;

import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.network.NetworkUtils;

import org.apache.logging.log4j.Level;
Expand All @@ -12,18 +9,18 @@

public class GuiError {

public static void throwNew(IGuiElement guiElement, Type type, String msg) {
public static void throwNew(IWidget guiElement, Type type, String msg) {
if (NetworkUtils.isClient()) {
GuiErrorHandler.INSTANCE.pushError(guiElement, type, msg);
}
}

private final Level level = Level.ERROR;
private final String msg;
private final IGuiElement reference;
private final IWidget reference;
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 All @@ -33,7 +30,7 @@ public Level getLevel() {
return level;
}

public IGuiElement getReference() {
public IWidget getReference() {
return reference;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/cleanroommc/modularui/GuiErrorHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.cleanroommc.modularui;

import com.cleanroommc.modularui.api.widget.IGuiElement;
import com.cleanroommc.modularui.api.widget.IWidget;

import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand All @@ -25,7 +25,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)) {
ModularUI.LOGGER.log(error.getLevel(), error);
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/com/cleanroommc/modularui/api/IThemeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.drawable.GuiTextures;
import com.cleanroommc.modularui.drawable.Scrollbar;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.theme.SelectableTheme;
import com.cleanroommc.modularui.theme.SlotTheme;
Expand Down Expand Up @@ -167,7 +168,32 @@ 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 @@ -177,7 +203,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/cleanroommc/modularui/api/ITreeNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.cleanroommc.modularui.api;

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
@@ -0,0 +1,76 @@
package com.cleanroommc.modularui.api.layout;

import com.cleanroommc.modularui.api.GuiAxis;
import com.cleanroommc.modularui.widget.sizer.Area;

public interface IResizeParent {

/**
* @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();

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
Expand Up @@ -8,7 +8,7 @@
* 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
Expand Down Expand Up @@ -40,65 +40,6 @@ public interface IResizeable {
*/
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();
}

/**
* @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 isSelfFullyCalculated(isParentLayout) && areChildrenCalculated() && isLayoutDone();
}

boolean canRelayout(boolean isParentLayout);

void setChildrenResized(boolean resized);

void setLayoutDone(boolean done);
Expand Down Expand Up @@ -182,14 +123,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();
}
Loading