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 @@ -68,6 +69,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
8 changes: 8 additions & 0 deletions src/main/java/com/cleanroommc/modularui/api/IThemeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public interface IThemeApi {
.defaultHoverTheme(SelectableTheme.whiteTextShadow(18, 18, GuiTextures.MC_BUTTON_HOVERED, IDrawable.NONE))
.register();

WidgetThemeKey<WidgetTheme> CONTEXT_MENU = get().widgetThemeKeyBuilder("menu", WidgetTheme.class)
.defaultTheme(WidgetTheme.darkTextNoShadow(80, 100, GuiTextures.MENU_BACKGROUND))
.register();

WidgetThemeKey<WidgetTheme> MENU_OPTION = get().widgetThemeKeyBuilder("menuOption", WidgetTheme.class)
.defaultTheme(WidgetTheme.darkTextNoShadow(80, 12, IDrawable.EMPTY))
.register();

// sub widget themes
WidgetThemeKey<SlotTheme> ITEM_SLOT_PLAYER = ITEM_SLOT.createSubKey("player");
WidgetThemeKey<SlotTheme> ITEM_SLOT_PLAYER_HOTBAR = ITEM_SLOT_PLAYER.createSubKey("playerHotbar");
Expand Down
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();
}
120 changes: 120 additions & 0 deletions src/main/java/com/cleanroommc/modularui/api/layout/IResizeable2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.cleanroommc.modularui.api.layout;

import com.cleanroommc.modularui.api.GuiAxis;

/**
* 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 IResizeable2 extends IResizeParent {

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

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

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

/**
* Called after all elements in the tree are resized and the absolute positions needs to be calculated from the
* relative postion.
*/
default void applyPos() {}

void setChildrenResized(boolean resized);

void setLayoutDone(boolean done);

/**
* Marks position and size as calculated.
*/
void setResized(boolean x, boolean y, boolean w, boolean h);

default void setPosResized(boolean x, boolean y) {
setResized(x, y, isWidthCalculated(), isHeightCalculated());
}

default void setSizeResized(boolean w, boolean h) {
setResized(isXCalculated(), isYCalculated(), w, h);
}

default void setXResized(boolean v) {
setResized(v, isYCalculated(), isWidthCalculated(), isHeightCalculated());
}

default void setYResized(boolean v) {
setResized(isXCalculated(), v, isWidthCalculated(), isHeightCalculated());
}

default void setPosResized(GuiAxis axis, boolean v) {
if (axis.isHorizontal()) {
setXResized(v);
} else {
setYResized(v);
}
}

default void setWidthResized(boolean v) {
setResized(isXCalculated(), isYCalculated(), v, isHeightCalculated());
}

default void setHeightResized(boolean v) {
setResized(isXCalculated(), isYCalculated(), isWidthCalculated(), v);
}

default void setSizeResized(GuiAxis axis, boolean v) {
if (axis.isHorizontal()) {
setWidthResized(v);
} else {
setHeightResized(v);
}
}

default void setResized(boolean b) {
setResized(b, b, b, b);
}

default void updateResized() {
setResized(isXCalculated(), isYCalculated(), isWidthCalculated(), isHeightCalculated());
}

/**
* Sets if margin and padding on the x-axis is applied
*
* @param b true if margin and padding are applied
*/
void setXMarginPaddingApplied(boolean b);

/**
* Sets if margin and padding on the y-axis is applied
*
* @param b true if margin and padding are applied
*/
void setYMarginPaddingApplied(boolean b);

default void setMarginPaddingApplied(boolean b) {
setXMarginPaddingApplied(b);
setYMarginPaddingApplied(b);
}

default void setMarginPaddingApplied(GuiAxis axis, boolean b) {
if (axis.isHorizontal()) {
setXMarginPaddingApplied(b);
} else {
setYMarginPaddingApplied(b);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.cleanroommc.modularui.api.widget;

import net.minecraft.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