Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
26ec7ab
close context menu on non hover click
brachy84 Feb 13, 2026
f0022fb
improve menu close logic
brachy84 Feb 14, 2026
ff52d0c
improve getOrCreateSlot
brachy84 Feb 14, 2026
0cfc843
add shorter name variant for getOrCreateSyncHandler()
brachy84 Feb 14, 2026
3234f96
nvm
brachy84 Feb 14, 2026
fdd3c50
properly check if sync handler is already registered
brachy84 Feb 14, 2026
5b2177d
call widget provider on init in DynamicLinkedSyncHandler
brachy84 Feb 14, 2026
dde199f
supersede #190
brachy84 Mar 1, 2026
2e5e421
Fix tooltipAutoUpdate targetting the wrong tooltip in AbstractCycleBu…
purebluez Mar 1, 2026
6ad94bb
call super in style setters in AbstractCycleButtonWidget
brachy84 Mar 1, 2026
b8a6df2
try attach resize node to root in relativeToScreen()
brachy84 Mar 1, 2026
979a04e
forgot super.tooltipTextShadow()
brachy84 Mar 2, 2026
26b48af
fix TreeUtil.findParent()
brachy84 Mar 2, 2026
6319022
deprecate align methods and add posRel(Alignment)
brachy84 Mar 11, 2026
82cd667
draw scroll shadows
brachy84 Mar 12, 2026
125199a
remove align usage
brachy84 Mar 12, 2026
014e9d1
add getters for most custom widget properties
brachy84 Mar 12, 2026
f601f08
ability to add background on top of theme
brachy84 Mar 12, 2026
1b56463
prevent locked hotbar slots from swapping
brachy84 Mar 17, 2026
9736187
ability to add widgets as "decoration"
brachy84 Mar 17, 2026
77306ff
add machine like test gui
brachy84 Mar 17, 2026
67fb512
only close panel after click is fully processed
brachy84 Mar 17, 2026
2d9ebcf
fix and improve texture serialization
brachy84 Mar 19, 2026
6da43df
fixes
brachy84 Mar 19, 2026
e2f6b61
Merge branch 'master' into syncupstream
brachy84 Mar 19, 2026
e1e988d
format
brachy84 Mar 19, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ default W coverChildren() {
return coverChildrenWidth().coverChildrenHeight();
}

/**
* Sets if this resizer is decoration. Decoration will be ignored during coverChildren and margin/padding calculations.
*
* @param decoration true if this resizer is decoration
* @return this
*/
default W decoration(boolean decoration) {
resizer().decoration(decoration);
return getThis();
}

default W decoration() {
return decoration(true);
}

default W expanded() {
resizer().expanded();
return getThis();
Expand Down Expand Up @@ -353,6 +368,11 @@ default W posRel(float x, float y) {
return getThis();
}

default W posRel(Alignment alignment) {
leftRel(alignment.x).topRel(alignment.y);
return getThis();
}

default W size(int w, int h) {
width(w).height(h);
return getThis();
Expand Down Expand Up @@ -403,44 +423,59 @@ default W anchorBottom(float val) {
return getThis();
}

/**
* @deprecated This will get removed due to this method being missused often.
*/
@ApiStatus.ScheduledForRemoval(inVersion = "3.3.0")
@Deprecated
default W anchor(Alignment alignment) {
resizer().anchor(alignment);
return getThis();
}

@ApiStatus.ScheduledForRemoval(inVersion = "3.3.0")
@Deprecated
default W alignX(float val) {
leftRel(val).anchorLeft(val);
return getThis();
}

@ApiStatus.ScheduledForRemoval(inVersion = "3.3.0")
@Deprecated
default W alignX(Alignment alignment) {
return alignX(alignment.x);
}

@ApiStatus.ScheduledForRemoval(inVersion = "3.3.0")
@Deprecated
default W alignY(float val) {
topRel(val).anchorTop(val);
return getThis();
}

@ApiStatus.ScheduledForRemoval(inVersion = "3.3.0")
@Deprecated
default W alignY(Alignment alignment) {
return alignY(alignment.y);
}

@ApiStatus.ScheduledForRemoval(inVersion = "3.3.0")
@Deprecated
default W align(Alignment alignment) {
return alignX(alignment).
alignY(alignment);
}

default W horizontalCenter() {
return alignX(Alignment.CENTER);
return leftRel(0.5f);
}

default W verticalCenter() {
return alignY(Alignment.CENTER);
return topRel(0.5f);
}

default W center() {
return align(Alignment.Center);
return horizontalCenter().verticalCenter();
}

default W resizer(Consumer<StandardResizer> flexConsumer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.google.gson.JsonObject;

import java.util.Objects;

/**
* This class is a <a href="https://en.wikipedia.org/wiki/9-slice_scaling">9-slice texture</a>. It can be created using
* {@link UITexture.Builder#adaptable(int, int, int, int)}.
Expand All @@ -32,6 +34,11 @@ public class AdaptableUITexture extends UITexture {
this.tiled = tiled;
}

@Override
public AdaptableUITexture register(String name) {
return (AdaptableUITexture) super.register(name);
}

@Override
public AdaptableUITexture getSubArea(float uStart, float vStart, float uEnd, float vEnd) {
return new AdaptableUITexture(this.location, lerpU(uStart), lerpV(vStart), lerpU(uEnd), lerpV(vEnd), this.colorType, this.nonOpaque,
Expand Down Expand Up @@ -167,17 +174,15 @@ public void drawTiled(float x, float y, float width, float height) {
}

@Override
public boolean saveToJson(JsonObject json) {
protected void saveTextureToJson(JsonObject json) {
super.saveToJson(json);
if (json.entrySet().size() == 1) return true;
json.addProperty("imageWidth", this.imageWidth);
json.addProperty("imageHeight", this.imageHeight);
json.addProperty("bl", this.bl);
json.addProperty("br", this.br);
json.addProperty("bt", this.bt);
json.addProperty("bb", this.bb);
json.addProperty("tiled", this.tiled);
return true;
}

@Override
Expand All @@ -189,4 +194,19 @@ protected AdaptableUITexture copy() {
public AdaptableUITexture withColorOverride(int color) {
return (AdaptableUITexture) super.withColorOverride(color);
}

@Override
public boolean equals(Object o) {
return o != null && getClass() == o.getClass() && isEqual((AdaptableUITexture) o);
}

protected boolean isEqual(AdaptableUITexture texture) {
return super.isEqual(texture) && imageWidth == texture.imageWidth && imageHeight == texture.imageHeight &&
bl == texture.bl && bt == texture.bt && br == texture.br && bb == texture.bb && tiled == texture.tiled;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), imageWidth, imageHeight, bl, bt, br, bb, tiled);
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/cleanroommc/modularui/drawable/ColorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;

import java.util.Map;
import java.util.Objects;
import java.util.function.ToIntFunction;

public class ColorType {
Expand Down Expand Up @@ -35,4 +36,16 @@ public String getName() {
public int getColor(WidgetTheme theme) {
return colorGetter.applyAsInt(theme);
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
ColorType colorType = (ColorType) o;
return Objects.equals(name, colorType.name);
}

@Override
public int hashCode() {
return Objects.hashCode(name);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cleanroommc.modularui.drawable;

import com.cleanroommc.modularui.ModularUI;
import com.cleanroommc.modularui.ModularUIConfig;
import com.cleanroommc.modularui.api.IJsonSerializable;
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.drawable.IKey;
Expand All @@ -20,6 +21,7 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Type;
import java.util.ArrayList;
Expand All @@ -34,15 +36,59 @@ public class DrawableSerialization implements JsonSerializer<IDrawable>, JsonDes
private static final Map<String, UITexture> TEXTURES = new Object2ObjectOpenHashMap<>();
private static final Map<UITexture, String> REVERSE_TEXTURES = new Object2ObjectOpenHashMap<>();

public static void registerTexture(String s, UITexture texture) {
TEXTURES.put(s, texture);
REVERSE_TEXTURES.put(texture, s);
private static void registerTextureInternal(String name, UITexture texture) {
if (texture == null) return;
UITexture current = TEXTURES.put(name, texture);
REVERSE_TEXTURES.put(texture, name);
if (current != null && (ModularUI.isDevEnv || ModularUIConfig.guiDebugMode)) {
ModularUI.LOGGER.warn("[DEBUG] Replacing texture with name '{}' and location '{}' with texture with location '{}'", name, current.location, texture.location);
}
}

public static void registerTexture(String name, UITexture texture) {
String current = REVERSE_TEXTURES.get(texture);
if (current != null) {
if (name != null && !current.equals(name)) {
TEXTURES.put(name, texture);
REVERSE_TEXTURES.put(texture, name);
TEXTURES.remove(current);
}
return;
}
if (name == null) {
registerTextureAutoName(texture);
} else {
registerTextureInternal(name, texture);
}
}

public static void registerTextureAutoName(UITexture texture) {
if (texture == null) return;
String[] p = texture.location.getResourcePath().split("/");
p = p[p.length - 1].split("\\.");
String baseName = texture.location.getResourceDomain() + ":" + p[0];
String name = baseName;
int number = 0;
UITexture current;
while ((current = TEXTURES.get(name)) != null) {
if (current.equals(texture)) return;
number++;
name = baseName + "_" + number;
if (number == 20 && (ModularUI.isDevEnv || ModularUIConfig.guiDebugMode)) {
ModularUI.LOGGER.warn("[DEBUG] Trying to register a UITexture with location '{}' for at least 20 times. This is likely a bug and should be fixed.", texture.location);
} else if (number == 10000) {
throw new IllegalStateException("Trying to register a UITexture with location '" + texture.location + "' 10000 times.");
}
}
registerTexture(name, texture);
}

@Nullable
public static UITexture getTexture(String s) {
return TEXTURES.get(s);
}

@Nullable
public static String getTextureId(UITexture texture) {
return REVERSE_TEXTURES.get(texture);
}
Expand Down Expand Up @@ -70,11 +116,11 @@ public static void init() {
}

public static IDrawable deserialize(JsonElement json) {
return JsonHelper.deserialize(json, IDrawable.class);
return JsonHelper.DESERIALIZER.deserialize(json, IDrawable.class);
}

public static JsonElement serialize(IDrawable drawable) {
return JsonHelper.serialize(drawable);
return JsonHelper.SERIALIZER.serialize(drawable, IDrawable.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ItemDrawable implements IDrawable, IJsonSerializable {

public ItemDrawable() {}

public ItemDrawable(@NotNull ItemStack item) {
public ItemDrawable(@Nullable ItemStack item) {
setItem(item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import com.google.gson.JsonObject;

import java.util.Objects;

public class TiledUITexture extends UITexture {

private final int imageWidth, imageHeight;
Expand All @@ -18,6 +20,11 @@ public class TiledUITexture extends UITexture {
this.imageHeight = imageHeight;
}

@Override
public TiledUITexture register(String name) {
return (TiledUITexture) super.register(name);
}

@Override
public void draw(float x, float y, float width, float height) {
if (width == this.imageWidth && height == this.imageHeight) {
Expand All @@ -28,12 +35,11 @@ public void draw(float x, float y, float width, float height) {
}

@Override
public boolean saveToJson(JsonObject json) {
protected void saveTextureToJson(JsonObject json) {
super.saveToJson(json);
if (json.entrySet().size() > 1) {
json.addProperty("tiled", true);
}
return true;
json.addProperty("imageWidth", this.imageWidth);
json.addProperty("imageHeight", this.imageHeight);
json.addProperty("tiled", true);
}

@Override
Expand All @@ -45,4 +51,18 @@ protected TiledUITexture copy() {
public TiledUITexture withColorOverride(int color) {
return (TiledUITexture) super.withColorOverride(color);
}

@Override
public boolean equals(Object o) {
return o != null && getClass() == o.getClass() && isEqual((TiledUITexture) o);
}

protected boolean isEqual(TiledUITexture texture) {
return super.isEqual(texture) && imageWidth == texture.imageWidth && imageHeight == texture.imageHeight;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), imageWidth, imageHeight);
}
}
Loading
Loading