ui cleanup (kind of)
This commit is contained in:
@@ -12,6 +12,7 @@ import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
|||||||
import org.saturnclient.saturnclient.event.KeyInputHandler;
|
import org.saturnclient.saturnclient.event.KeyInputHandler;
|
||||||
import org.saturnclient.saturnmods.ModManager;
|
import org.saturnclient.saturnmods.ModManager;
|
||||||
import org.saturnclient.ui.SaturnAnimation;
|
import org.saturnclient.ui.SaturnAnimation;
|
||||||
|
import org.saturnclient.ui.SaturnUi;
|
||||||
import org.saturnclient.ui.animations.FadeIn;
|
import org.saturnclient.ui.animations.FadeIn;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -45,6 +46,10 @@ public class SaturnClient implements ModInitializer {
|
|||||||
return ((int) (alpha * 255) << 24) | (NORMAL.value & 0x00FFFFFF);
|
return ((int) (alpha * 255) << 24) | (NORMAL.value & 0x00FFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getColor(boolean hovering, float alpha) {
|
||||||
|
return SaturnUi.getAlpha(hovering ? SaturnClient.COLOR.value : NORMAL.value, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
public static SaturnAnimation[] getAnimations() {
|
public static SaturnAnimation[] getAnimations() {
|
||||||
return new SaturnAnimation[] { new FadeIn(1) };
|
return new SaturnAnimation[] { new FadeIn(1) };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class CloaksMenu extends SaturnUi {
|
|||||||
new SaturnClickableImage(Textures.CLOAK, () -> {
|
new SaturnClickableImage(Textures.CLOAK, () -> {
|
||||||
client.setScreen(new CloaksMenu());
|
client.setScreen(new CloaksMenu());
|
||||||
})
|
})
|
||||||
.setColor(SaturnClient.COLOR.value)
|
.setSelected(true)
|
||||||
.setX(tabsX - 12)
|
.setX(tabsX - 12)
|
||||||
.setY(tabsY + 3)
|
.setY(tabsY + 3)
|
||||||
.setWidth(tabSize)
|
.setWidth(tabSize)
|
||||||
@@ -91,7 +91,6 @@ public class CloaksMenu extends SaturnUi {
|
|||||||
new SaturnClickableSprite(Textures.BUTTON_BORDER, () -> {
|
new SaturnClickableSprite(Textures.BUTTON_BORDER, () -> {
|
||||||
Cloaks.setCloak(SaturnSocket.uuid, cloak);
|
Cloaks.setCloak(SaturnSocket.uuid, cloak);
|
||||||
})
|
})
|
||||||
.setColor(10526880)
|
|
||||||
.setX(modX)
|
.setX(modX)
|
||||||
.setY(modY)
|
.setY(modY)
|
||||||
.setWidth(cloakWidth + 6)
|
.setWidth(cloakWidth + 6)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class HatsMenu extends SaturnUi {
|
|||||||
new SaturnClickableImage(Textures.HAT, () -> {
|
new SaturnClickableImage(Textures.HAT, () -> {
|
||||||
client.setScreen(new HatsMenu());
|
client.setScreen(new HatsMenu());
|
||||||
})
|
})
|
||||||
.setColor(SaturnClient.COLOR.value)
|
.setSelected(true)
|
||||||
.setX(tabsX)
|
.setX(tabsX)
|
||||||
.setY(tabsY + 4)
|
.setY(tabsY + 4)
|
||||||
.setWidth(tabSize)
|
.setWidth(tabSize)
|
||||||
@@ -90,7 +90,6 @@ public class HatsMenu extends SaturnUi {
|
|||||||
new SaturnClickableSprite(Textures.BUTTON_BORDER, () -> {
|
new SaturnClickableSprite(Textures.BUTTON_BORDER, () -> {
|
||||||
Hats.setHat(SaturnSocket.uuid, hat);
|
Hats.setHat(SaturnSocket.uuid, hat);
|
||||||
})
|
})
|
||||||
.setColor(10526880)
|
|
||||||
.setX(modX)
|
.setX(modX)
|
||||||
.setY(modY)
|
.setY(modY)
|
||||||
.setWidth(hatSize + 6)
|
.setWidth(hatSize + 6)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class ModMenu extends SaturnUi {
|
|||||||
draw(
|
draw(
|
||||||
new SaturnClickableImage(Textures.MODS_TAB, () -> {
|
new SaturnClickableImage(Textures.MODS_TAB, () -> {
|
||||||
})
|
})
|
||||||
.setColor(SaturnClient.COLOR.value)
|
.setSelected(true)
|
||||||
.setX(tabsX - 12)
|
.setX(tabsX - 12)
|
||||||
.setY(tabsY + 3)
|
.setY(tabsY + 3)
|
||||||
.setWidth(tabSize)
|
.setWidth(tabSize)
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ public class SaturnUi extends Screen {
|
|||||||
matricies.pop();
|
matricies.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getAlpha(int color, float alpha) {
|
||||||
|
return ((int) (alpha * 255) << 24) |
|
||||||
|
(color & 0x00FFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
public List<SaturnWidget> widgets = new ArrayList<>();
|
public List<SaturnWidget> widgets = new ArrayList<>();
|
||||||
private int tick = 0;
|
private int tick = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.ui.SaturnUi;
|
import org.saturnclient.ui.SaturnUi;
|
||||||
@@ -17,8 +16,7 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
public String text;
|
public String text;
|
||||||
public Consumer<SaturnButton> onPress;
|
public Consumer<SaturnButton> onPress;
|
||||||
public boolean background = true;
|
public boolean background = true;
|
||||||
|
private float hoverAlpha = 0.0f;
|
||||||
private float hoverAlpha;
|
|
||||||
|
|
||||||
public SaturnButton(String text, Consumer<SaturnButton> onPress) {
|
public SaturnButton(String text, Consumer<SaturnButton> onPress) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
@@ -39,9 +37,6 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
int mouseY) {
|
int mouseY) {
|
||||||
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||||
|
|
||||||
int hoverColor = ((int) (alpha * 255) << 24) |
|
|
||||||
(SaturnClient.COLOR.value & 0x00FFFFFF);
|
|
||||||
|
|
||||||
if (background) {
|
if (background) {
|
||||||
RenderSystem.setShaderTexture(0, Textures.BUTTON);
|
RenderSystem.setShaderTexture(0, Textures.BUTTON);
|
||||||
|
|
||||||
@@ -52,7 +47,7 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
0,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
SaturnClient.getWhite(this.alpha));
|
SaturnClient.getColor(hovering, alpha));
|
||||||
|
|
||||||
if (hovering) {
|
if (hovering) {
|
||||||
if (hoverAlpha == 0.0f)
|
if (hoverAlpha == 0.0f)
|
||||||
@@ -65,14 +60,13 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
0,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
((int) (hoverAlpha * 255) << 24) | (hoverColor));
|
SaturnClient.getColor(hovering, alpha));
|
||||||
} else {
|
} else {
|
||||||
hoverAlpha = 0.0f;
|
hoverAlpha = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alpha != 0.0f) {
|
if (alpha != 0.0f) {
|
||||||
int i = this.active ? 16777215 : 10526880;
|
|
||||||
context.drawText(
|
context.drawText(
|
||||||
minecraftClient.textRenderer,
|
minecraftClient.textRenderer,
|
||||||
SaturnUi.text(text),
|
SaturnUi.text(text),
|
||||||
@@ -83,9 +77,7 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
2),
|
2),
|
||||||
((this.height - minecraftClient.textRenderer.fontHeight + 1) /
|
((this.height - minecraftClient.textRenderer.fontHeight + 1) /
|
||||||
2),
|
2),
|
||||||
hovering
|
SaturnClient.getColor(hovering, alpha),
|
||||||
? hoverColor
|
|
||||||
: i | (MathHelper.ceil(this.alpha * 255.0F) << 24),
|
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,7 +90,7 @@ public class SaturnButton extends SaturnWidget {
|
|||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
if (hoverAlpha > 0.0f && hoverAlpha < 0.9f)
|
if (hoverAlpha > 0.0f && hoverAlpha < 0.9f)
|
||||||
hoverAlpha += 0.06f;
|
hoverAlpha += 0.03f;
|
||||||
else if (hoverAlpha > 0.9f && hoverAlpha < 1.0f)
|
else if (hoverAlpha > 0.9f && hoverAlpha < 1.0f)
|
||||||
hoverAlpha = 1.0f;
|
hoverAlpha = 1.0f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.saturnclient.ui.widgets;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.ui.SaturnUi;
|
import org.saturnclient.ui.SaturnUi;
|
||||||
import org.saturnclient.ui.SaturnWidget;
|
import org.saturnclient.ui.SaturnWidget;
|
||||||
@@ -13,8 +12,7 @@ public class SaturnClickableImage extends SaturnWidget {
|
|||||||
public Identifier texture;
|
public Identifier texture;
|
||||||
public boolean selected = false;
|
public boolean selected = false;
|
||||||
public Consumer<SaturnClickableImage> onPress;
|
public Consumer<SaturnClickableImage> onPress;
|
||||||
public int color = SaturnClient.getWhite(1.0f);
|
private float hoverAlpha = 0.0f;
|
||||||
public int hoverColor = SaturnClient.COLOR.value;
|
|
||||||
|
|
||||||
public SaturnClickableImage(
|
public SaturnClickableImage(
|
||||||
Identifier texture,
|
Identifier texture,
|
||||||
@@ -35,6 +33,11 @@ public class SaturnClickableImage extends SaturnWidget {
|
|||||||
boolean hovering,
|
boolean hovering,
|
||||||
int mouseX,
|
int mouseX,
|
||||||
int mouseY) {
|
int mouseY) {
|
||||||
|
if (hovering) {
|
||||||
|
if (hoverAlpha == 0.0f)
|
||||||
|
hoverAlpha = 0.1f;
|
||||||
|
}
|
||||||
|
|
||||||
SaturnUi.drawHighResTexture(
|
SaturnUi.drawHighResTexture(
|
||||||
context,
|
context,
|
||||||
texture,
|
texture,
|
||||||
@@ -42,8 +45,7 @@ public class SaturnClickableImage extends SaturnWidget {
|
|||||||
0,
|
0,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
(hovering || selected ? hoverColor : color) |
|
SaturnClient.getColor(hovering || selected, alpha));
|
||||||
(MathHelper.ceil(this.alpha * 255.0F) << 24));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,8 +58,11 @@ public class SaturnClickableImage extends SaturnWidget {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SaturnClickableImage setColor(int c) {
|
@Override
|
||||||
this.color = c;
|
public void tick() {
|
||||||
return this;
|
if (hoverAlpha > 0.0f && hoverAlpha < 0.9f)
|
||||||
|
hoverAlpha += 0.03f;
|
||||||
|
else if (hoverAlpha > 0.9f && hoverAlpha < 1.0f)
|
||||||
|
hoverAlpha = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.saturnclient.ui.widgets;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.ui.SaturnUi;
|
import org.saturnclient.ui.SaturnUi;
|
||||||
import org.saturnclient.ui.SaturnWidget;
|
import org.saturnclient.ui.SaturnWidget;
|
||||||
@@ -13,8 +12,6 @@ public class SaturnClickableSprite extends SaturnWidget {
|
|||||||
public Identifier sprite;
|
public Identifier sprite;
|
||||||
public boolean selected = false;
|
public boolean selected = false;
|
||||||
public Consumer<SaturnClickableSprite> onPress;
|
public Consumer<SaturnClickableSprite> onPress;
|
||||||
public int color = SaturnClient.getWhite(1.0f);
|
|
||||||
public int hoverColor = SaturnClient.COLOR.value;
|
|
||||||
|
|
||||||
public SaturnClickableSprite(
|
public SaturnClickableSprite(
|
||||||
Identifier sprite,
|
Identifier sprite,
|
||||||
@@ -42,8 +39,7 @@ public class SaturnClickableSprite extends SaturnWidget {
|
|||||||
0,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
(hovering || selected ? hoverColor : color) |
|
SaturnClient.getColor(hovering, alpha));
|
||||||
(MathHelper.ceil(this.alpha * 255.0F) << 24));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,14 +51,4 @@ public class SaturnClickableSprite extends SaturnWidget {
|
|||||||
this.selected = selected;
|
this.selected = selected;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SaturnClickableSprite setColor(int color) {
|
|
||||||
this.color = color;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SaturnClickableSprite setHoverColor(int color) {
|
|
||||||
this.hoverColor = color;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class SaturnImageButton extends SaturnWidget {
|
|||||||
public int imageWidth;
|
public int imageWidth;
|
||||||
public int imageHeight;
|
public int imageHeight;
|
||||||
public Consumer<SaturnImageButton> onPress;
|
public Consumer<SaturnImageButton> onPress;
|
||||||
|
private float hoverAlpha = 0.0f;
|
||||||
|
|
||||||
public SaturnImageButton(
|
public SaturnImageButton(
|
||||||
Identifier sprite,
|
Identifier sprite,
|
||||||
@@ -45,8 +46,10 @@ public class SaturnImageButton extends SaturnWidget {
|
|||||||
boolean hovering,
|
boolean hovering,
|
||||||
int mouseX,
|
int mouseX,
|
||||||
int mouseY) {
|
int mouseY) {
|
||||||
int hoverColor = ((int) (alpha * 255) << 24) |
|
if (hovering) {
|
||||||
(SaturnClient.COLOR.value & 0x00FFFFFF);
|
if (hoverAlpha == 0.0f)
|
||||||
|
hoverAlpha = 0.1f;
|
||||||
|
}
|
||||||
RenderSystem.setShaderTexture(0, Textures.BUTTON);
|
RenderSystem.setShaderTexture(0, Textures.BUTTON);
|
||||||
|
|
||||||
SaturnUi.drawHighResGuiTexture(
|
SaturnUi.drawHighResGuiTexture(
|
||||||
@@ -56,7 +59,7 @@ public class SaturnImageButton extends SaturnWidget {
|
|||||||
0,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
SaturnClient.getWhite(this.alpha));
|
SaturnClient.getColor(hovering, alpha));
|
||||||
|
|
||||||
if (hovering) {
|
if (hovering) {
|
||||||
SaturnUi.drawHighResGuiTexture(
|
SaturnUi.drawHighResGuiTexture(
|
||||||
@@ -66,7 +69,7 @@ public class SaturnImageButton extends SaturnWidget {
|
|||||||
0,
|
0,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
hoverColor);
|
SaturnClient.getColor(hovering, alpha));
|
||||||
}
|
}
|
||||||
|
|
||||||
context.drawTexture(
|
context.drawTexture(
|
||||||
@@ -80,11 +83,19 @@ public class SaturnImageButton extends SaturnWidget {
|
|||||||
imageHeight,
|
imageHeight,
|
||||||
imageWidth,
|
imageWidth,
|
||||||
imageHeight,
|
imageHeight,
|
||||||
hovering ? hoverColor : SaturnClient.getWhite(alpha));
|
SaturnClient.getColor(hovering, alpha));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(int mouseX, int mouseY) {
|
public void click(int mouseX, int mouseY) {
|
||||||
this.onPress.accept(this);
|
this.onPress.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (hoverAlpha > 0.0f && hoverAlpha < 0.9f)
|
||||||
|
hoverAlpha += 0.03f;
|
||||||
|
else if (hoverAlpha > 0.9f && hoverAlpha < 1.0f)
|
||||||
|
hoverAlpha = 1.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.saturnclient.ui.widgets;
|
|||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.ColorHelper;
|
import net.minecraft.util.math.ColorHelper;
|
||||||
|
|
||||||
import org.saturnclient.ui.SaturnUi;
|
import org.saturnclient.ui.SaturnUi;
|
||||||
import org.saturnclient.ui.SaturnWidget;
|
import org.saturnclient.ui.SaturnWidget;
|
||||||
|
|
||||||
|
|||||||
@@ -21,18 +21,16 @@ public class SaturnText extends SaturnWidget {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(
|
public void render(
|
||||||
DrawContext context,
|
DrawContext context,
|
||||||
boolean hovering,
|
boolean hovering,
|
||||||
int mouseX,
|
int mouseX,
|
||||||
int mouseY
|
int mouseY) {
|
||||||
) {
|
|
||||||
context.drawText(
|
context.drawText(
|
||||||
SaturnClient.textRenderer,
|
SaturnClient.textRenderer,
|
||||||
SaturnUi.text(text),
|
SaturnUi.text(text),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
SaturnClient.getWhite(alpha),
|
SaturnClient.getColor(hovering, alpha),
|
||||||
false
|
false);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user