Skip to content

Commit cf7ca31

Browse files
authored
3.1 (#189)
* context menu things * a bunch of things * compiles * finally works * context menus finally working again * mroe stuff * new delegating widget, remove obsolete ContextMenuOption * panels can have their own theme * improve context menu theme * deprecate single arg ModularScreen ctor * open overlays via new event & deprecate OverlayManager & OverlayHandler * clean up * more clean up * dropdown widget * javadoc * relativeToScreen works again * reorganize IWidget * fixes & cleanup * fix applyPos issue * minor adjustments and fixes
1 parent 4a5c1fd commit cf7ca31

File tree

97 files changed

+4285
-2061
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4285
-2061
lines changed

src/main/java/com/cleanroommc/modularui/ClientProxy.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.cleanroommc.modularui.keybind.KeyBindHandler;
1111
import com.cleanroommc.modularui.screen.ClientScreenHandler;
1212
import com.cleanroommc.modularui.test.EventHandler;
13-
import com.cleanroommc.modularui.test.OverlayTest;
1413
import com.cleanroommc.modularui.test.TestItem;
1514
import com.cleanroommc.modularui.theme.ThemeManager;
1615
import com.cleanroommc.modularui.theme.ThemeReloadCommand;
@@ -70,9 +69,6 @@ void preInit(FMLPreInitializationEvent event) {
7069
testKey = new KeyBinding("key.test", KeyConflictContext.IN_GAME, Keyboard.KEY_NUMPAD4, "key.categories.modularui");
7170
ClientRegistry.registerKeyBinding(testKey);
7271
}
73-
if (ModularUIConfig.enableTestOverlays) {
74-
OverlayTest.init();
75-
}
7672

7773
DrawableSerialization.init();
7874
RenderingRegistry.registerEntityRenderingHandler(HoloScreenEntity.class, ScreenEntityRender::new);

src/main/java/com/cleanroommc/modularui/GuiError.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.cleanroommc.modularui;
22

3-
import com.cleanroommc.modularui.api.widget.IGuiElement;
4-
5-
import com.cleanroommc.modularui.network.NetworkHandler;
6-
3+
import com.cleanroommc.modularui.api.widget.IWidget;
74
import com.cleanroommc.modularui.network.NetworkUtils;
85

96
import org.apache.logging.log4j.Level;
@@ -12,18 +9,18 @@
129

1310
public class GuiError {
1411

15-
public static void throwNew(IGuiElement guiElement, Type type, String msg) {
12+
public static void throwNew(IWidget guiElement, Type type, String msg) {
1613
if (NetworkUtils.isClient()) {
1714
GuiErrorHandler.INSTANCE.pushError(guiElement, type, msg);
1815
}
1916
}
2017

2118
private final Level level = Level.ERROR;
2219
private final String msg;
23-
private final IGuiElement reference;
20+
private final IWidget reference;
2421
private final Type type;
2522

26-
protected GuiError(String msg, IGuiElement reference, Type type) {
23+
protected GuiError(String msg, IWidget reference, Type type) {
2724
this.msg = msg;
2825
this.reference = reference;
2926
this.type = type;
@@ -33,7 +30,7 @@ public Level getLevel() {
3330
return level;
3431
}
3532

36-
public IGuiElement getReference() {
33+
public IWidget getReference() {
3734
return reference;
3835
}
3936

src/main/java/com/cleanroommc/modularui/GuiErrorHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.cleanroommc.modularui;
22

3-
import com.cleanroommc.modularui.api.widget.IGuiElement;
3+
import com.cleanroommc.modularui.api.widget.IWidget;
44

55
import net.minecraftforge.fml.relauncher.Side;
66
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -25,7 +25,7 @@ public void clear() {
2525
this.errors.clear();
2626
}
2727

28-
void pushError(IGuiElement reference, GuiError.Type type, String msg) {
28+
void pushError(IWidget reference, GuiError.Type type, String msg) {
2929
GuiError error = new GuiError(msg, reference, type);
3030
if (this.errorSet.add(error)) {
3131
ModularUI.LOGGER.log(error.getLevel(), error);

src/main/java/com/cleanroommc/modularui/ModularUI.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
88
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
99
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
10+
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
1011

1112
import org.apache.logging.log4j.LogManager;
1213
import org.apache.logging.log4j.Logger;
@@ -36,6 +37,8 @@ public class ModularUI {
3637
serverSide = "com.cleanroommc.modularui.CommonProxy")
3738
public static CommonProxy proxy;
3839

40+
public static final boolean isDev = FMLLaunchHandler.isDeobfuscatedEnvironment();
41+
3942
@Mod.Instance
4043
public static ModularUI INSTANCE;
4144

src/main/java/com/cleanroommc/modularui/animation/Animator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ public Animator curve(IInterpolation curve) {
171171
return this;
172172
}
173173

174-
175-
176174
/**
177175
* Sets a function which is executed everytime the progress updates, that is on every frame.
178176
* The argument of the function is the interpolated value.

src/main/java/com/cleanroommc/modularui/api/IGuiHolder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cleanroommc.modularui.api;
22

3+
import com.cleanroommc.modularui.ModularUI;
34
import com.cleanroommc.modularui.factory.GuiData;
45
import com.cleanroommc.modularui.screen.ModularPanel;
56
import com.cleanroommc.modularui.screen.ModularScreen;
@@ -24,7 +25,8 @@ public interface IGuiHolder<T extends GuiData> {
2425
*/
2526
@SideOnly(Side.CLIENT)
2627
default ModularScreen createScreen(T data, ModularPanel mainPanel) {
27-
return new ModularScreen(mainPanel);
28+
ModularUI.LOGGER.warn("IGuiHolder.createScreen() should be overridden to pass you own mod id to the ModularScreen. In future versions this method must be overridden or else it will crash!");
29+
return new ModularScreen(ModularUI.ID, mainPanel);
2830
}
2931

3032
/**

src/main/java/com/cleanroommc/modularui/api/IThemeApi.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.cleanroommc.modularui.api.drawable.IDrawable;
44
import com.cleanroommc.modularui.drawable.GuiTextures;
55
import com.cleanroommc.modularui.drawable.Scrollbar;
6+
import com.cleanroommc.modularui.screen.ModularPanel;
67
import com.cleanroommc.modularui.screen.ModularScreen;
78
import com.cleanroommc.modularui.theme.SelectableTheme;
89
import com.cleanroommc.modularui.theme.SlotTheme;
@@ -167,7 +168,32 @@ default void registerTheme(ThemeBuilder<?> themeBuilder) {
167168
* @param defaultTheme default theme if no theme was found
168169
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
169170
*/
170-
ITheme getThemeForScreen(String owner, String name, @Nullable String defaultTheme);
171+
default ITheme getThemeForScreen(String owner, String name, @Nullable String defaultTheme, @Nullable String fallbackTheme) {
172+
return getThemeForScreen(owner, name, null, defaultTheme, fallbackTheme);
173+
}
174+
175+
/**
176+
* Gets the appropriate theme for a screen.
177+
*
178+
* @param owner owner of the screen
179+
* @param name name of the screen
180+
* @param panel the name
181+
* @param defaultTheme default theme if no theme was found
182+
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
183+
*/
184+
ITheme getThemeForScreen(String owner, String name, @Nullable String panel, @Nullable String defaultTheme, @Nullable String fallbackTheme);
185+
186+
/**
187+
* Gets the appropriate theme for a specific panel.
188+
*
189+
* @param panel the panel to find a theme for
190+
* @param defaultTheme default theme if no theme was found
191+
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
192+
*/
193+
default ITheme getThemeForScreen(ModularPanel panel, @Nullable String defaultTheme) {
194+
ModularScreen screen = panel.getScreen();
195+
return getThemeForScreen(screen.getOwner(), screen.getName(), panel.getName(), defaultTheme, screen.getThemeOverride());
196+
}
171197

172198
/**
173199
* Gets the appropriate theme for a screen.
@@ -177,7 +203,7 @@ default void registerTheme(ThemeBuilder<?> themeBuilder) {
177203
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
178204
*/
179205
default ITheme getThemeForScreen(ModularScreen screen, @Nullable String defaultTheme) {
180-
return getThemeForScreen(screen.getOwner(), screen.getName(), defaultTheme);
206+
return getThemeForScreen(screen.getOwner(), screen.getName(), defaultTheme, null);
181207
}
182208

183209
/**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.cleanroommc.modularui.api;
2+
3+
import java.util.List;
4+
5+
public interface ITreeNode<T extends ITreeNode<T>> {
6+
7+
T getParent();
8+
9+
default boolean hasParent() {
10+
return getParent() != null;
11+
}
12+
13+
List<T> getChildren();
14+
15+
default boolean hasChildren() {
16+
return !getChildren().isEmpty();
17+
}
18+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.cleanroommc.modularui.api.layout;
2+
3+
import com.cleanroommc.modularui.api.GuiAxis;
4+
import com.cleanroommc.modularui.widget.sizer.Area;
5+
6+
public interface IResizeParent {
7+
8+
/**
9+
* @return area of the element
10+
*/
11+
Area getArea();
12+
13+
/**
14+
* @return true if the relative x position is calculated
15+
*/
16+
boolean isXCalculated();
17+
18+
/**
19+
* @return true if the relative y position is calculated
20+
*/
21+
boolean isYCalculated();
22+
23+
/**
24+
* @return true if the width is calculated
25+
*/
26+
boolean isWidthCalculated();
27+
28+
/**
29+
* @return true if the height is calculated
30+
*/
31+
boolean isHeightCalculated();
32+
33+
boolean areChildrenCalculated();
34+
35+
boolean isLayoutDone();
36+
37+
boolean canRelayout(boolean isParentLayout);
38+
39+
default boolean isSizeCalculated(GuiAxis axis) {
40+
return axis.isHorizontal() ? isWidthCalculated() : isHeightCalculated();
41+
}
42+
43+
default boolean isPosCalculated(GuiAxis axis) {
44+
return axis.isHorizontal() ? isXCalculated() : isYCalculated();
45+
}
46+
47+
/**
48+
* @return true if the relative position and size are fully calculated
49+
*/
50+
default boolean isSelfFullyCalculated(boolean isParentLayout) {
51+
return isSelfFullyCalculated() && !canRelayout(isParentLayout);
52+
}
53+
54+
default boolean isSelfFullyCalculated() {
55+
return isXCalculated() && isYCalculated() && isWidthCalculated() && isHeightCalculated();
56+
}
57+
58+
default boolean isFullyCalculated() {
59+
return isSelfFullyCalculated() && areChildrenCalculated() && isLayoutDone();
60+
}
61+
62+
default boolean isFullyCalculated(boolean isParentLayout) {
63+
return isFullyCalculated() && !canRelayout(isParentLayout);
64+
}
65+
66+
/**
67+
* @return true if margin and padding are applied on the x-axis
68+
*/
69+
boolean isXMarginPaddingApplied();
70+
71+
/**
72+
* @return true if margin and padding are applied on the y-axis
73+
*/
74+
boolean isYMarginPaddingApplied();
75+
}
Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,43 @@
11
package com.cleanroommc.modularui.api.layout;
22

33
import com.cleanroommc.modularui.api.GuiAxis;
4-
import com.cleanroommc.modularui.api.widget.IGuiElement;
5-
import com.cleanroommc.modularui.widget.sizer.Area;
64

75
/**
86
* An interface that handles resizing of widgets.
97
* Usually this interface is not implemented by the users of this library or will even interact with it.
108
*/
11-
public interface IResizeable {
9+
public interface IResizeable extends IResizeParent {
1210

1311
/**
1412
* Called once before resizing
1513
*/
16-
void initResizing();
14+
void initResizing(boolean onOpen);
1715

1816
/**
1917
* Resizes the given element
2018
*
21-
* @param guiElement element to resize
2219
* @param isParentLayout if the parent is a layout widget
2320
* @return true if element is fully resized
2421
*/
25-
boolean resize(IGuiElement guiElement, boolean isParentLayout);
22+
boolean resize(boolean isParentLayout);
2623

2724
/**
28-
* Called if {@link #resize(IGuiElement, boolean)} returned false after children have been resized.
25+
* Called if {@link #resize(boolean)} returned false after children have been resized.
2926
*
30-
* @param guiElement element to resize
3127
* @return if element is fully resized
3228
*/
33-
boolean postResize(IGuiElement guiElement);
29+
boolean postResize();
3430

3531
/**
3632
* Called after all elements in the tree are resized and the absolute positions needs to be calculated from the
3733
* relative postion.
38-
*
39-
* @param guiElement element that was resized
40-
*/
41-
default void applyPos(IGuiElement guiElement) {}
42-
43-
/**
44-
* @return area of the element
45-
*/
46-
// TODO doesnt fit with the other api methods in this interface
47-
Area getArea();
48-
49-
/**
50-
* @return true if the relative x position is calculated
51-
*/
52-
boolean isXCalculated();
53-
54-
/**
55-
* @return true if the relative y position is calculated
5634
*/
57-
boolean isYCalculated();
58-
59-
/**
60-
* @return true if the width is calculated
61-
*/
62-
boolean isWidthCalculated();
63-
64-
/**
65-
* @return true if the height is calculated
66-
*/
67-
boolean isHeightCalculated();
68-
69-
boolean areChildrenCalculated();
70-
71-
boolean isLayoutDone();
72-
73-
default boolean isSizeCalculated(GuiAxis axis) {
74-
return axis.isHorizontal() ? isWidthCalculated() : isHeightCalculated();
75-
}
76-
77-
default boolean isPosCalculated(GuiAxis axis) {
78-
return axis.isHorizontal() ? isXCalculated() : isYCalculated();
79-
}
35+
default void preApplyPos() {}
8036

8137
/**
82-
* @return true if the relative position and size are fully calculated
38+
* This converts the relative pos to resizer parent to relative pos to widget parent.
8339
*/
84-
default boolean isSelfFullyCalculated(boolean isParentLayout) {
85-
return isSelfFullyCalculated() && !canRelayout(isParentLayout);
86-
}
87-
88-
default boolean isSelfFullyCalculated() {
89-
return isXCalculated() && isYCalculated() && isWidthCalculated() && isHeightCalculated();
90-
}
91-
92-
default boolean isFullyCalculated() {
93-
return isSelfFullyCalculated() && areChildrenCalculated() && isLayoutDone();
94-
}
95-
96-
default boolean isFullyCalculated(boolean isParentLayout) {
97-
return isSelfFullyCalculated(isParentLayout) && areChildrenCalculated() && isLayoutDone();
98-
}
99-
100-
boolean canRelayout(boolean isParentLayout);
40+
default void applyPos() {}
10141

10242
void setChildrenResized(boolean resized);
10343

@@ -182,14 +122,4 @@ default void setMarginPaddingApplied(GuiAxis axis, boolean b) {
182122
setYMarginPaddingApplied(b);
183123
}
184124
}
185-
186-
/**
187-
* @return true if margin and padding are applied on the x-axis
188-
*/
189-
boolean isXMarginPaddingApplied();
190-
191-
/**
192-
* @return true if margin and padding are applied on the y-axis
193-
*/
194-
boolean isYMarginPaddingApplied();
195125
}

0 commit comments

Comments
 (0)