Fix splashoverlay and saturnmodule
This commit is contained in:
@@ -60,18 +60,29 @@ public class Theme {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets alpha using 0–255 range.
|
||||
* Multiplies existing alpha with 0–255 alpha.
|
||||
*/
|
||||
public static int withAlpha(int alpha, int color) {
|
||||
alpha = Math.max(0, Math.min(255, alpha));
|
||||
return (color & 0x00FFFFFF) | (alpha << 24);
|
||||
|
||||
int originalAlpha = (color >>> 24) & 0xFF;
|
||||
|
||||
// Merge (multiply) alphas
|
||||
int merged = (originalAlpha * alpha) / 255;
|
||||
|
||||
return (color & 0x00FFFFFF) | (merged << 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets alpha using 0.0–1.0 range.
|
||||
* Multiplies existing alpha with 0.0–1.0 alpha.
|
||||
*/
|
||||
public static int withAlpha(float alpha, int color) {
|
||||
alpha = Math.max(0f, Math.min(1f, alpha));
|
||||
return withAlpha((int) (alpha * 255f), color);
|
||||
|
||||
int originalAlpha = (color >>> 24) & 0xFF;
|
||||
|
||||
int merged = (int) (originalAlpha * alpha);
|
||||
|
||||
return (color & 0x00FFFFFF) | (merged << 24);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,16 +78,16 @@ public abstract class SplashOverlayMixin {
|
||||
renderCurrentScreen(context, mouseX, mouseY, delta);
|
||||
int overlayAlpha = computeOverlayAlpha(fadeOutProgress - 1f);
|
||||
scope.drawTexture(Textures.SPLASH, 0, 0, 0, 0, screenWidth, screenHeight,
|
||||
Theme.withAlpha(0xFFFFFFFF, overlayAlpha));
|
||||
Theme.withAlpha(overlayAlpha, 0xFFFFFFFF));
|
||||
} else if (reloading) {
|
||||
if (reloadProgress < 1.0F) {
|
||||
renderCurrentScreen(context, mouseX, mouseY, delta);
|
||||
}
|
||||
scope.drawTexture(Textures.SPLASH, 0, 0, 0, 0, screenWidth, screenHeight,
|
||||
Theme.withAlpha(0xFFFFFFFF, alpha));
|
||||
Theme.withAlpha(alpha, 0xFFFFFFFF));
|
||||
} else {
|
||||
scope.drawTexture(Textures.SPLASH, 0, 0, 0, 0, screenWidth, screenHeight,
|
||||
Theme.withAlpha(0xFFFFFFFF, alpha));
|
||||
Theme.withAlpha(alpha, 0xFFFFFFFF));
|
||||
}
|
||||
|
||||
float u = this.reload.getProgress();
|
||||
@@ -115,19 +115,19 @@ public abstract class SplashOverlayMixin {
|
||||
/** Draw the main logo centered */
|
||||
private void drawLogo(RenderScope scope, int screenWidth, int screenHeight, int alpha) {
|
||||
scope.drawTexture(Textures.LOGO, (screenWidth - 60) / 2, ((screenHeight - 60) / 2) - 20, 0, 0, 60, 60,
|
||||
Theme.withAlpha(0xFFFFFFFF, alpha));
|
||||
Theme.withAlpha(alpha, 0xFFFFFFFF));
|
||||
}
|
||||
|
||||
private void renderProgressBar(RenderScope scope, DrawContext context, int screenWidth, int screenHeight,
|
||||
int alpha) {
|
||||
int progressY = ((screenHeight - 5) / 2) + 25;
|
||||
context.drawBorder((screenWidth - 120) / 2, progressY, 120, 5, Theme.withAlpha(0xFFFFFFFF, alpha));
|
||||
context.drawBorder((screenWidth - 120) / 2, progressY, 120, 5, Theme.withAlpha(alpha, 0xFFFFFFFF));
|
||||
|
||||
int progressWidth = Math.min((int) (progress * 120), 120);
|
||||
int progressX = (screenWidth - 120) / 2;
|
||||
|
||||
context.fill(progressX, progressY, progressX + progressWidth, progressY + 5,
|
||||
Theme.withAlpha(0xFFFFFFFF, alpha));
|
||||
Theme.withAlpha(alpha, 0xFFFFFFFF));
|
||||
}
|
||||
|
||||
/** Compute overlay alpha from fade progress */
|
||||
|
||||
@@ -14,14 +14,8 @@ import org.saturnclient.ui2.screens.ConfigEditor;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
|
||||
public class SaturnModule extends Element {
|
||||
// TODO make these states
|
||||
// static {
|
||||
// theme.propertyStateDefault("enabled", "bg", 0xFF1d202d);
|
||||
// theme.propertyStateDefault("enabled", "icon-bg", 0xFF845eee);
|
||||
// theme.propertyStateDefault("hovering", "fg", 0xFF845eee);
|
||||
// }
|
||||
|
||||
private Module mod;
|
||||
private final Module mod;
|
||||
|
||||
public SaturnModule(Module mod) {
|
||||
this.mod = mod;
|
||||
@@ -31,44 +25,111 @@ public class SaturnModule extends Element {
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||
int p = 10;
|
||||
int s = 14;
|
||||
boolean settingsHover = false;
|
||||
int p = 10; // padding
|
||||
int s = 14; // settings icon size
|
||||
|
||||
boolean hovered = ctx.isHovering();
|
||||
boolean enabled = mod.isEnabled();
|
||||
|
||||
boolean settingsHover = Utils.isHovering(
|
||||
ctx.mouseX - (width - s - p - 5),
|
||||
ctx.mouseY - (height - s - p - 5),
|
||||
s + 10,
|
||||
s + 10,
|
||||
1.0f);
|
||||
|
||||
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
|
||||
|
||||
// TODO use this
|
||||
if (mod.isEnabled()) {
|
||||
}
|
||||
// Resolve theme colors
|
||||
int bgColor = Theme.PRIMARY.value;
|
||||
int fgColor = hovered && !settingsHover ? Theme.ACCENT.value : Theme.PRIMARY_FG.value;
|
||||
|
||||
renderScope.drawRoundedRectangle(0, 0, width, height, Theme.WIDGET_RADIUS.value, Theme.PRIMARY.value);
|
||||
int iconBg = enabled ? Theme.ACCENT.value : Theme.PRIMARY.value;
|
||||
int iconFg = enabled ? Theme.ACCENT_FG.value : fgColor;
|
||||
|
||||
int settingsColor = settingsHover
|
||||
? Theme.ACCENT.value
|
||||
: Theme.withAlpha(160, fgColor);
|
||||
|
||||
int h = height - (p * 2);
|
||||
|
||||
renderScope.drawRoundedRectangle(p, p, h, h, Theme.WIDGET_RADIUS.value, Theme.PRIMARY.value);
|
||||
// Main background
|
||||
renderScope.drawRoundedRectangle(
|
||||
0, 0,
|
||||
width, height,
|
||||
Theme.WIDGET_RADIUS.value,
|
||||
bgColor);
|
||||
|
||||
renderScope.drawTexture(mod.getIconTexture(), p + (p / 2), p + (p / 2), 0, 0, h - p, h - p,
|
||||
Theme.PRIMARY_FG.value);
|
||||
// Icon background
|
||||
renderScope.drawRoundedRectangle(
|
||||
p, p,
|
||||
h, h,
|
||||
Theme.WIDGET_RADIUS.value,
|
||||
iconBg);
|
||||
|
||||
renderScope.drawText(0.6f, mod.getName(), p + h + 4, p + 1, Theme.FONT.value, Theme.PRIMARY_FG.value);
|
||||
// Icon
|
||||
renderScope.drawTexture(
|
||||
mod.getIconTexture(),
|
||||
p + (p / 2),
|
||||
p + (p / 2),
|
||||
0, 0,
|
||||
h - p,
|
||||
h - p,
|
||||
iconFg);
|
||||
|
||||
renderScope.drawText(0.35f, mod.getVersion(),
|
||||
width - p - (int) (Fonts.getWidth(mod.getVersion(), Theme.FONT.value) * 0.35f), p + 1, Theme.FONT.value,
|
||||
Theme.PRIMARY_FG.value);
|
||||
// Module name
|
||||
renderScope.drawText(
|
||||
0.6f,
|
||||
mod.getName(),
|
||||
p + h + 4,
|
||||
p + 1,
|
||||
Theme.FONT.value,
|
||||
fgColor);
|
||||
|
||||
// Version (right aligned)
|
||||
String version = mod.getVersion();
|
||||
int versionWidth = (int) (Fonts.getWidth(version, Theme.FONT.value) * 0.35f);
|
||||
|
||||
renderScope.drawText(
|
||||
0.35f,
|
||||
version,
|
||||
width - p - versionWidth,
|
||||
p + 1,
|
||||
Theme.FONT.value,
|
||||
fgColor);
|
||||
|
||||
// Tags
|
||||
int xt = p + h + 4;
|
||||
for (String tag : mod.getTags()) {
|
||||
int xtb = (int) (Fonts.getWidth(tag, Theme.FONT.value) * 0.4f);
|
||||
renderScope.drawRoundedRectangle(xt, p + (h / 2), xtb + 6, 12, 5, Theme.ACCENT.value);
|
||||
renderScope.drawText(0.4f, tag, xt + 2, p + (h / 2) + 3, Theme.FONT.value, Theme.ACCENT_FG.value);
|
||||
xt += xtb + 9;
|
||||
int tagWidth = (int) (Fonts.getWidth(tag, Theme.FONT.value) * 0.4f);
|
||||
|
||||
renderScope.drawRoundedRectangle(
|
||||
xt,
|
||||
p + (h / 2),
|
||||
tagWidth + 6,
|
||||
12,
|
||||
5,
|
||||
Theme.ACCENT.value);
|
||||
|
||||
renderScope.drawText(
|
||||
0.4f,
|
||||
tag,
|
||||
xt + 2,
|
||||
p + (h / 2) + 3,
|
||||
Theme.FONT.value,
|
||||
Theme.ACCENT_FG.value);
|
||||
|
||||
xt += tagWidth + 9;
|
||||
}
|
||||
|
||||
// TODO
|
||||
if (settingsHover) {
|
||||
}
|
||||
|
||||
renderScope.drawTexture(Textures.SETTINGS, width - s - p, height - s - p, 0, 0, s, s, Theme.PRIMARY_FG.value);
|
||||
// Settings icon
|
||||
renderScope.drawTexture(
|
||||
Textures.SETTINGS,
|
||||
width - s - p,
|
||||
height - s - p,
|
||||
0, 0,
|
||||
s, s,
|
||||
settingsColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,10 +137,17 @@ public class SaturnModule extends Element {
|
||||
int p = 10;
|
||||
int s = 14;
|
||||
|
||||
if (Utils.isHovering(mouseX - (width - s - p - 5), mouseY - (height - s - p - 5), s + 10, s + 10, 1.0f)) {
|
||||
boolean settingsHover = Utils.isHovering(
|
||||
mouseX - (width - s - p - 5),
|
||||
mouseY - (height - s - p - 5),
|
||||
s + 10,
|
||||
s + 10,
|
||||
1.0f);
|
||||
|
||||
if (settingsHover) {
|
||||
SaturnClient.client.setScreen(new ConfigEditor(mod.getConfig()));
|
||||
} else {
|
||||
mod.setEnabled(!mod.isEnabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user