Improve transparent ui/ux and fix tab gradient for index 0

This commit is contained in:
Marcel Konrad
2020-10-23 14:52:05 +02:00
parent 9fae3eae45
commit 59c945a96f
4 changed files with 77 additions and 66 deletions

View File

@@ -125,14 +125,14 @@ public class ConfigCategorySkin
Config.set(this.headlineColor, color); Config.set(this.headlineColor, color);
} }
private int getBackgroundRed() public int getBackgroundRedInt()
{ {
return this.backgroundRed.get(); return this.backgroundRed.get();
} }
public float getBackgroundRedF() public float getBackgroundRed()
{ {
return this.getBackgroundRed() / 255F; return this.getBackgroundRedInt() / 255F;
} }
public void setBackgroundRed(int red) public void setBackgroundRed(int red)
@@ -140,14 +140,14 @@ public class ConfigCategorySkin
Config.set(this.backgroundRed, red); Config.set(this.backgroundRed, red);
} }
private int getBackgroundGreen() public int getBackgroundGreenInt()
{ {
return this.backgroundGreen.get(); return this.backgroundGreen.get();
} }
public float getBackgroundGreenF() public float getBackgroundGreen()
{ {
return this.getBackgroundGreen() / 255F; return this.getBackgroundGreenInt() / 255F;
} }
public void setBackgroundGreen(int green) public void setBackgroundGreen(int green)
@@ -155,14 +155,14 @@ public class ConfigCategorySkin
Config.set(this.backgroundGreen, green); Config.set(this.backgroundGreen, green);
} }
private int getBackgroundBlue() public int getBackgroundBlueInt()
{ {
return this.backgroundBlue.get(); return this.backgroundBlue.get();
} }
public float getBackgroundBlueF() public float getBackgroundBlue()
{ {
return this.getBackgroundBlue() / 255F; return this.getBackgroundBlueInt() / 255F;
} }
public void setBackgroundBlue(int blue) public void setBackgroundBlue(int blue)
@@ -170,14 +170,14 @@ public class ConfigCategorySkin
Config.set(this.backgroundBlue, blue); Config.set(this.backgroundBlue, blue);
} }
private int getButtonRed() public int getButtonRedInt()
{ {
return this.buttonRed.get(); return this.buttonRed.get();
} }
public float getButtonRedF() public float getButtonRed()
{ {
return this.getButtonRed() / 255F; return this.getButtonRedInt() / 255F;
} }
public void setButtonRed(int red) public void setButtonRed(int red)
@@ -185,14 +185,14 @@ public class ConfigCategorySkin
Config.set(this.backgroundRed, red); Config.set(this.backgroundRed, red);
} }
private int getButtonGreen() public int getButtonGreenInt()
{ {
return this.buttonGreen.get(); return this.buttonGreen.get();
} }
public float getButtonGreenF() public float getButtonGreen()
{ {
return this.getButtonGreen() / 255F; return this.getButtonGreenInt() / 255F;
} }
public void setButtonGreen(int green) public void setButtonGreen(int green)
@@ -200,14 +200,14 @@ public class ConfigCategorySkin
Config.set(this.buttonGreen, green); Config.set(this.buttonGreen, green);
} }
private int getButtonBlue() public int getButtonBlueInt()
{ {
return this.buttonBlue.get(); return this.buttonBlue.get();
} }
public float getButtonBlueF() public float getButtonBlue()
{ {
return this.getButtonBlue() / 255F; return this.getButtonBlueInt() / 255F;
} }
public void setButtonBlue(int blue) public void setButtonBlue(int blue)
@@ -245,14 +245,14 @@ public class ConfigCategorySkin
Config.set(this.drawBackground, enabled); Config.set(this.drawBackground, enabled);
} }
private int getBackgroundAlpha() public int getBackgroundAlphaInt()
{ {
return this.backgroundAlpha.get(); return this.backgroundAlpha.get();
} }
public float getBackgroundAlphaF() public float getBackgroundAlpha()
{ {
return this.getBackgroundAlpha() / 255F; return this.getBackgroundAlphaInt() / 255F;
} }
public void setBackgroundAlpha(int alpha) public void setBackgroundAlpha(int alpha)
@@ -260,14 +260,14 @@ public class ConfigCategorySkin
Config.set(this.backgroundAlpha, alpha); Config.set(this.backgroundAlpha, alpha);
} }
private int getButtonAlpha() public int getButtonAlphaInt()
{ {
return this.buttonAlpha.get(); return this.buttonAlpha.get();
} }
public float getButtonAlphaF() public float getButtonAlpha()
{ {
return this.getButtonAlpha() / 255F; return this.getButtonAlphaInt() / 255F;
} }
public void setButtonAlpha(int alpha) public void setButtonAlpha(int alpha)

View File

@@ -73,7 +73,8 @@ public class WidgetTabRenderer implements IContainerWidget
if(content.getActiveContent().equals(tab)) if(content.getActiveContent().equals(tab))
{ {
this.drawActiveTab(matrix, container, index, size, xPos + offset, yPos - 22, width, 25, title); int height = Config.getSkin().getBackgroundAlphaInt() == 255 ? 25 : 22;
this.drawActiveTab(matrix, container, index, size, xPos + offset, yPos - 22, width, height, title);
} }
else else
{ {
@@ -93,24 +94,31 @@ public class WidgetTabRenderer implements IContainerWidget
{ {
RenderSystem.enableBlend(); RenderSystem.enableBlend();
if(index > 0) if(Config.getSkin().getBackgroundAlphaInt() == 255)
{ {
RenderUtils.drawTexturedTriangleBL(matrix, container, x, y + height - 2, x - container.getBackgroundX(), 1, 2); if(index > 0)
{
RenderUtils.drawTexturedTriangleBL(matrix, container, x, y + height - 2, x - container.getBackgroundX(), 1, 2);
}
if(index < size - 1 || size == 1)
{
RenderUtils.drawTexturedTriangleBR(matrix, container, x + width - 2, y + height - 2, x - container.getBackgroundX() + width, 1, 2);
}
if(index == 0)
{
RenderUtils.drawTexturedWedgeGradientTL(matrix, container, x, y + height, 0, height, width, WidgetTabRenderer.WEDGE_HEIGHT);
}
if(index == size - 1 && size > 1)
{
RenderUtils.drawTexturedWedgeGradientTR(matrix, container, x, y + height, x - container.getBackgroundX(), height, width, WidgetTabRenderer.WEDGE_HEIGHT);
}
} }
else
if(index < size - 1 || size == 1)
{ {
RenderUtils.drawTexturedTriangleBR(matrix, container, x + width - 2, y + height - 2, x - container.getBackgroundX() + width, 1, 2); this.drawTabBackgroundMerge(matrix, container, index, size, x, y, width, height);
}
if(index == 0)
{
RenderUtils.drawTexturedWedgeGradientTL(matrix, container, x, y + height, 0, height, width, WidgetTabRenderer.WEDGE_HEIGHT);
}
if(index == size - 1 && size > 1)
{
RenderUtils.drawTexturedWedgeGradientTR(matrix, container, x, y + height, x - container.getBackgroundX(), height, width, WidgetTabRenderer.WEDGE_HEIGHT);
} }
RenderSystem.disableBlend(); RenderSystem.disableBlend();
@@ -127,23 +135,26 @@ public class WidgetTabRenderer implements IContainerWidget
if(!Config.getSkin().sharpEdges()) if(!Config.getSkin().sharpEdges())
{ {
RenderSystem.enableBlend(); RenderSystem.enableBlend();
this.drawTabBackgroundMerge(matrix, container, index, size, x, y, width, height);
if(index == 0)
{
RenderUtils.drawTexturedTriangleTL(matrix, container, x, y + height, 0, height, 2);
}
if(index == size - 1)
{
RenderUtils.drawTexturedTriangleTR(matrix, container, x + width - 3, y + height, container.getBackgroundWidth() - 3, height, 3);
}
RenderSystem.disableBlend(); RenderSystem.disableBlend();
} }
this.drawTabTitle(matrix, container, title, x + width / 2, y + 7, 0xE0E0E0); this.drawTabTitle(matrix, container, title, x + width / 2, y + 7, 0xE0E0E0);
} }
private void drawTabBackgroundMerge(MatrixStack matrix, Container container, int index, int size, int x, int y, int width, int height)
{
if(index == 0)
{
RenderUtils.drawTexturedTriangleTL(matrix, container, x, y + height, 0, height, 2);
}
if(index == size - 1)
{
RenderUtils.drawTexturedTriangleTR(matrix, container, x + width - 3, y + height, container.getBackgroundWidth() - 3, height, 3);
}
}
private void drawTabBackground(MatrixStack matrix, Container container, int x, int y, int width, int height) private void drawTabBackground(MatrixStack matrix, Container container, int x, int y, int width, int height)
{ {
container.bindBackground(); container.bindBackground();

View File

@@ -54,7 +54,7 @@ public class GuiButtonPiano extends GuiButtonBase
} }
int hovered = this.getYImage(this.isHovered()); int hovered = this.getYImage(this.isHovered());
RenderUtils.color(1.0F, 1.0F, 1.0F, Config.getSkin().getButtonAlphaF()); RenderUtils.color(1.0F, 1.0F, 1.0F, Config.getSkin().getButtonAlpha());
Minecraft.getInstance().getTextureManager().bindTexture(NOTE); Minecraft.getInstance().getTextureManager().bindTexture(NOTE);
switch(this.type) switch(this.type)

View File

@@ -53,7 +53,7 @@ public class RenderUtils
matrix.pop(); matrix.pop();
RenderUtils.color(Config.getSkin().getButtonRedF(), Config.getSkin().getButtonGreenF(), Config.getSkin().getButtonBlueF(), Config.getSkin().getButtonAlphaF()); RenderUtils.colorDefaultButton();
Minecraft.getInstance().getTextureManager().bindTexture(ResourceHelper.iconTexture()); Minecraft.getInstance().getTextureManager().bindTexture(ResourceHelper.iconTexture());
gui.blit(matrix, width + 0, height, 48, 0, 10, 10); gui.blit(matrix, width + 0, height, 48, 0, 10, 10);
@@ -155,10 +155,10 @@ public class RenderUtils
public static void colorDefaultButton() public static void colorDefaultButton()
{ {
float r = Config.getSkin().getButtonRedF(); float r = Config.getSkin().getButtonRed();
float g = Config.getSkin().getButtonGreenF(); float g = Config.getSkin().getButtonGreen();
float b = Config.getSkin().getButtonBlueF(); float b = Config.getSkin().getButtonBlue();
float a = Config.getSkin().getButtonAlphaF(); float a = Config.getSkin().getButtonAlpha();
RenderUtils.color(r, g, b, a); RenderUtils.color(r, g, b, a);
} }
@@ -170,20 +170,20 @@ public class RenderUtils
public static void colorDefaultBackground(double alpha) public static void colorDefaultBackground(double alpha)
{ {
float r = Config.getSkin().getBackgroundRedF(); float r = Config.getSkin().getBackgroundRed();
float g = Config.getSkin().getBackgroundGreenF(); float g = Config.getSkin().getBackgroundGreen();
float b = Config.getSkin().getBackgroundBlueF(); float b = Config.getSkin().getBackgroundBlue();
float a = (float) alpha * Config.getSkin().getBackgroundAlphaF(); float a = (float) alpha * Config.getSkin().getBackgroundAlpha();
RenderUtils.color(r, g, b, a); RenderUtils.color(r, g, b, a);
} }
public static void colorDarkBackground() public static void colorDarkBackground()
{ {
float r = Config.getSkin().getBackgroundRedF(); float r = Config.getSkin().getBackgroundRed();
float g = Config.getSkin().getBackgroundGreenF(); float g = Config.getSkin().getBackgroundGreen();
float b = Config.getSkin().getBackgroundBlueF(); float b = Config.getSkin().getBackgroundBlue();
float a = Config.getSkin().getBackgroundAlphaF(); float a = Config.getSkin().getBackgroundAlpha();
RenderUtils.color(Math.max(0, r - 0.3F), Math.max(0, g - 0.3F), Math.max(0, b - 0.3F), a); RenderUtils.color(Math.max(0, r - 0.3F), Math.max(0, g - 0.3F), Math.max(0, b - 0.3F), a);
} }
@@ -243,7 +243,7 @@ public class RenderUtils
for(int i = 0; i < height; i++) for(int i = 0; i < height; i++)
{ {
double w = (height - i) / (double) (height + 1); double w = (height - i) / (double) (height + 1);
int z = width - (int) (w * width); int z = (int) (w * width);
RenderUtils.colorDefaultBackground(w); RenderUtils.colorDefaultBackground(w);
gui.blit(matrix, x, y + i, textureX, textureY + i, z, 1); gui.blit(matrix, x, y + i, textureX, textureY + i, z, 1);