@@ -48,6 +48,8 @@ static UITexture icon(String name, int x, int y) {
4848 @ Nullable public final ColorType colorType ;
4949 public final boolean nonOpaque ;
5050
51+ private int colorOverride = 0 ;
52+
5153 /**
5254 * Creates a drawable texture
5355 *
@@ -164,11 +166,7 @@ public void drawSubArea(float x, float y, float width, float height, float uStar
164166 }
165167
166168 public void drawSubArea (float x , float y , float width , float height , float uStart , float vStart , float uEnd , float vEnd , WidgetTheme widgetTheme ) {
167- if (canApplyTheme ()) {
168- Color .setGlColor (widgetTheme .getColor ());
169- } else {
170- Color .setGlColorOpaque (Color .WHITE .main );
171- }
169+ applyColor (this .colorType != null ? this .colorType .getColor (widgetTheme ) : ColorType .DEFAULT .getColor (widgetTheme ));
172170 GuiDraw .drawTexture (this .location , x , y , x + width , y + height , lerpU (uStart ), lerpV (vStart ), lerpU (uEnd ), lerpV (vEnd ), this .nonOpaque );
173171 }
174172
@@ -177,6 +175,15 @@ public boolean canApplyTheme() {
177175 return colorType != null ;
178176 }
179177
178+ @ Override
179+ public void applyColor (int themeColor ) {
180+ if (this .colorOverride != 0 ) {
181+ Color .setGlColor (this .colorOverride );
182+ } else {
183+ IDrawable .super .applyColor (themeColor );
184+ }
185+ }
186+
180187 public static UITexture parseFromJson (JsonObject json ) {
181188 String name = JsonHelper .getString (json , null , "name" , "id" );
182189 if (name != null ) {
@@ -218,6 +225,8 @@ public static UITexture parseFromJson(JsonObject json) {
218225 } else if (JsonHelper .getBoolean (json , false , "canApplyTheme" )) {
219226 builder .canApplyTheme ();
220227 }
228+ UITexture uiTexture = builder .build ();
229+ uiTexture .colorOverride = JsonHelper .getColor (json , 0 , "colorOverride" );
221230 return builder .build ();
222231 }
223232
@@ -234,9 +243,20 @@ public boolean saveToJson(JsonObject json) {
234243 json .addProperty ("u1" , this .u1 );
235244 json .addProperty ("v1" , this .v1 );
236245 if (this .colorType != null ) json .addProperty ("colorType" , this .colorType .getName ());
246+ json .addProperty ("colorOverride" , this .colorOverride );
237247 return true ;
238248 }
239249
250+ protected UITexture copy () {
251+ return new UITexture (this .location , this .u0 , this .v0 , this .u1 , this .v1 , this .colorType );
252+ }
253+
254+ public UITexture withColorOverride (int color ) {
255+ UITexture t = copy ();
256+ t .colorOverride = color ;
257+ return t ;
258+ }
259+
240260 private static int defaultImageWidth = 16 , defaultImageHeight = 16 ;
241261
242262 public static void setDefaultImageSize (int w , int h ) {
0 commit comments