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