Skip to content

Commit c835bca

Browse files
TheYoingLadbrachy84
authored andcommitted
Added opacity to UITexture copy() method (#112)
(cherry picked from commit 7631a27)
1 parent 5d77fca commit c835bca

3 files changed

Lines changed: 33 additions & 15 deletions

File tree

src/main/java/com/cleanroommc/modularui/drawable/AdaptableUITexture.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public class AdaptableUITexture extends UITexture {
2222
/**
2323
* Use {@link UITexture#builder()} with {@link Builder#adaptable(int, int)}
2424
*/
25-
AdaptableUITexture(ResourceLocation location, float u0, float v0, float u1, float v1, ColorType colorType, boolean nonOpaque,
25+
AdaptableUITexture(ResourceLocation location, float u0, float v0, float u1, float v1, ColorType colorType, boolean nonOpaque, int colorOverride,
2626
int imageWidth, int imageHeight, int bl, int bt, int br, int bb, boolean tiled) {
27-
super(location, u0, v0, u1, v1, colorType, nonOpaque);
27+
super(location, u0, v0, u1, v1, colorType, nonOpaque, colorOverride);
2828
this.imageWidth = imageWidth;
2929
this.imageHeight = imageHeight;
3030
this.bl = bl;
@@ -42,7 +42,7 @@ public AdaptableUITexture register(String name) {
4242
@Override
4343
public AdaptableUITexture getSubArea(float uStart, float vStart, float uEnd, float vEnd) {
4444
return new AdaptableUITexture(this.location, lerpU(uStart), lerpV(vStart), lerpU(uEnd), lerpV(vEnd), this.colorType, this.nonOpaque,
45-
this.imageWidth, this.imageHeight, this.bl, this.bt, this.br, this.bb, this.tiled);
45+
this.colorOverride, this.imageWidth, this.imageHeight, this.bl, this.bt, this.br, this.bb, this.tiled);
4646
}
4747

4848
@Override
@@ -187,7 +187,7 @@ protected void saveTextureToJson(JsonObject json) {
187187

188188
@Override
189189
protected AdaptableUITexture copy() {
190-
return new AdaptableUITexture(location, u0, v0, u1, v1, colorType, nonOpaque, imageWidth, imageHeight, bl, bt, br, bb, tiled);
190+
return new AdaptableUITexture(location, u0, v0, u1, v1, colorType, nonOpaque, colorOverride, imageWidth, imageHeight, bl, bt, br, bb, tiled);
191191
}
192192

193193
@Override

src/main/java/com/cleanroommc/modularui/drawable/TiledUITexture.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public class TiledUITexture extends UITexture {
1313
/**
1414
* Use {@link UITexture#builder()} with {@link Builder#tiled()}
1515
*/
16-
TiledUITexture(ResourceLocation location, float u0, float v0, float u1, float v1, int imageWidth, int imageHeight, ColorType colorType,
17-
boolean nonOpaque) {
18-
super(location, u0, v0, u1, v1, colorType, nonOpaque);
16+
TiledUITexture(ResourceLocation location, float u0, float v0, float u1, float v1, ColorType colorType, boolean nonOpaque,
17+
int colorOverride, int imageWidth, int imageHeight) {
18+
super(location, u0, v0, u1, v1, colorType, nonOpaque, colorOverride);
1919
this.imageWidth = imageWidth;
2020
this.imageHeight = imageHeight;
2121
}
@@ -44,7 +44,7 @@ protected void saveTextureToJson(JsonObject json) {
4444

4545
@Override
4646
protected TiledUITexture copy() {
47-
return new TiledUITexture(location, u0, v0, u1, v1, imageWidth, imageHeight, colorType, nonOpaque);
47+
return new TiledUITexture(location, u0, v0, u1, v1, colorType, nonOpaque, colorOverride, imageWidth, imageHeight);
4848
}
4949

5050
@Override

src/main/java/com/cleanroommc/modularui/drawable/UITexture.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static UITexture icon(String name, int x, int y) {
5050
@Nullable public final ColorType colorType;
5151
public final boolean nonOpaque;
5252

53-
private int colorOverride = 0;
53+
protected int colorOverride;
5454

5555
/**
5656
* Creates a drawable texture
@@ -63,7 +63,7 @@ static UITexture icon(String name, int x, int y) {
6363
* @param colorType a function to get which color from a widget theme should be used to color this texture. Can be null.
6464
*/
6565
public UITexture(ResourceLocation location, float u0, float v0, float u1, float v1, @Nullable ColorType colorType) {
66-
this(location, u0, v0, u1, v1, colorType, false);
66+
this(location, u0, v0, u1, v1, colorType, false, 0);
6767
}
6868

6969
/**
@@ -78,6 +78,22 @@ public UITexture(ResourceLocation location, float u0, float v0, float u1, float
7878
* @param nonOpaque whether the texture should draw with blend (if true) or not (if false).
7979
*/
8080
public UITexture(ResourceLocation location, float u0, float v0, float u1, float v1, @Nullable ColorType colorType, boolean nonOpaque) {
81+
this(location, u0, v0, u1, v1, colorType, nonOpaque, 0);
82+
}
83+
84+
/**
85+
* Creates a drawable texture
86+
*
87+
* @param location location of the texture
88+
* @param u0 x offset of the image (0-1)
89+
* @param v0 y offset of the image (0-1)
90+
* @param u1 x end offset of the image (0-1)
91+
* @param v1 y end offset of the image (0-1)
92+
* @param colorType a function to get which color from a widget theme should be used to color this texture. Can be null.
93+
* @param nonOpaque whether the texture should draw with blend (if true) or not (if false).
94+
* @param colorOverride color override for the texture in ARGB format. 0 means no override
95+
*/
96+
public UITexture(ResourceLocation location, float u0, float v0, float u1, float v1, @Nullable ColorType colorType, boolean nonOpaque, int colorOverride) {
8197
this.colorType = colorType;
8298
boolean png = !location.getPath().endsWith(".png");
8399
boolean textures = !location.getPath().startsWith("textures/");
@@ -92,6 +108,7 @@ public UITexture(ResourceLocation location, float u0, float v0, float u1, float
92108
this.u1 = u1;
93109
this.v1 = v1;
94110
this.nonOpaque = nonOpaque;
111+
this.colorOverride = colorOverride;
95112
}
96113

97114
public static Builder builder() {
@@ -281,7 +298,7 @@ public int hashCode() {
281298
}
282299

283300
protected UITexture copy() {
284-
return new UITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.colorType);
301+
return new UITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.colorType, this.nonOpaque, this.colorOverride);
285302
}
286303

287304
public UITexture withColorOverride(int color) {
@@ -312,6 +329,7 @@ public static class Builder {
312329
private boolean tiled = false;
313330
private ColorType colorType = null;
314331
private boolean nonOpaque = false;
332+
private int colorOverride = 0;
315333

316334
/**
317335
* @param loc location of the image to draw
@@ -603,13 +621,13 @@ private UITexture create() {
603621
throw new IllegalArgumentException("UV values must be 0 - 1");
604622
if (this.bl > 0 || this.bt > 0 || this.br > 0 || this.bb > 0) {
605623
return new AdaptableUITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.colorType, this.nonOpaque,
606-
this.iw, this.ih, this.bl, this.bt, this.br, this.bb, this.tiled);
624+
this.colorOverride, this.iw, this.ih, this.bl, this.bt, this.br, this.bb, this.tiled);
607625
}
608626
if (this.tiled) {
609-
return new TiledUITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.iw, this.ih, this.colorType,
610-
this.nonOpaque);
627+
return new TiledUITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.colorType, this.nonOpaque,
628+
this.colorOverride, this.iw, this.ih);
611629
}
612-
return new UITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.colorType, this.nonOpaque);
630+
return new UITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.colorType, this.nonOpaque, this.colorOverride);
613631
}
614632
throw new IllegalStateException();
615633
}

0 commit comments

Comments
 (0)