Clean up the hud and only show the super bar when it's useful. Also use the xp bar to show level and corruption

This commit is contained in:
Sollace 2024-05-28 23:18:54 +01:00
parent 1f714b3ed0
commit 66d0dc8750
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
7 changed files with 77 additions and 105 deletions

View file

@ -84,8 +84,8 @@ public class DismissSpellScreen extends GameGui {
matrices.push();
matrices.translate(width - mouseX, height - mouseY, 0);
DrawableUtil.drawLine(matrices, 0, 0, relativeMouseX, relativeMouseY, 0xFFFFFF88);
DrawableUtil.drawArc(matrices, 40, 80, 0, DrawableUtil.TAU, 0x00000010, false);
DrawableUtil.drawArc(matrices, 160, 1600, 0, DrawableUtil.TAU, 0x00000020, false);
DrawableUtil.drawArc(matrices, 40, 80, 0, DrawableUtil.TAU, 0x00000010);
DrawableUtil.drawArc(matrices, 160, 1600, 0, DrawableUtil.TAU, 0x00000020);
super.render(context, mouseX, mouseY, delta);
DrawableUtil.renderRaceIcon(context, pony.getObservedSpecies(), 0, 0, 16);
@ -187,10 +187,10 @@ public class DismissSpellScreen extends GameGui {
boolean hovered = isMouseOver(relativeMouseX, relativeMouseY);
double radius = (hovered ? 9 + MathHelper.sin((MinecraftClient.getInstance().player.age + tickDelta) / 9F) : 7);
DrawableUtil.drawArc(matrices, radius, radius + 1, 0, DrawableUtil.TAU, color | 0x00000088, false);
DrawableUtil.drawArc(matrices, radius, radius + 1, 0, DrawableUtil.TAU, color | 0x00000088);
if (hovered) {
DrawableUtil.drawArc(matrices, 0, 8, 0, DrawableUtil.TAU, color | 0x000000FF, false);
DrawableUtil.drawArc(matrices, 0, 8, 0, DrawableUtil.TAU, color | 0x000000FF);
List<Text> tooltip = new ArrayList<>();

View file

@ -71,27 +71,41 @@ public interface DrawableUtil {
RenderSystem.disableBlend();
}
/**
* Renders a colored arc with notches.
*
* @param mirrorHorizontally Whether or not the arc must be mirrored across the horizontal plane. Will produce a bar that grows from the middle filling both sides.
*/
static void drawNotchedArc(MatrixStack matrices, double innerRadius, double outerRadius, double startAngle, double arcAngle, double notchAngle, double notchSpacing, int color) {
double notchBegin = startAngle;
double endAngle = startAngle + arcAngle;
while (notchBegin < endAngle) {
double notchEnd = Math.min(notchBegin + notchAngle, endAngle);
if (notchEnd <= notchBegin) {
return;
}
drawArc(matrices, innerRadius, outerRadius, notchBegin, notchEnd - notchBegin, color);
notchBegin += notchAngle + notchSpacing;
}
}
/**
* Renders a colored arc.
*
* @param mirrorHorizontally Whether or not the arc must be mirrored across the horizontal plane. Will produce a bar that grows from the middle filling both sides.
*/
static void drawArc(MatrixStack matrices, double innerRadius, double outerRadius, double startAngle, double arcAngle, int color, boolean mirrorHorizontally) {
static void drawArc(MatrixStack matrices, double innerRadius, double outerRadius, double startAngle, double arcAngle, int color) {
if (arcAngle < INCREMENT) {
return;
}
float r = (color >> 24 & 255) / 255F;
float g = (color >> 16 & 255) / 255F;
float b = (color >> 8 & 255) / 255F;
float k = (color & 255) / 255F;
if (arcAngle < INCREMENT) {
return;
}
final double maxAngle = MathHelper.clamp(startAngle + arcAngle, 0, TAU - INCREMENT);
if (!mirrorHorizontally) {
startAngle = -startAngle;
}
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
RenderSystem.enableBlend();
@ -102,7 +116,7 @@ public interface DrawableUtil {
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
for (double angle = startAngle; angle >= -maxAngle; angle -= INCREMENT) {
for (double angle = -startAngle; angle >= -maxAngle; angle -= INCREMENT) {
// center
cylendricalVertex(bufferBuilder, model, innerRadius, angle, r, g, b, k);
// point one
@ -116,70 +130,6 @@ public interface DrawableUtil {
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
}
/**
* Renders hollow circle
*
* @param mirrorHorizontally Whether or not the arc must be mirrored across the horizontal plane. Will produce a bar that grows from the middle filling both sides.
*/
static void drawArc(MatrixStack matrices, double radius, double startAngle, double arcAngle, int color, boolean mirrorHorizontally) {
drawCircle(matrices, radius, startAngle, arcAngle, color, mirrorHorizontally, VertexFormat.DrawMode.DEBUG_LINES);
}
/**
* Renders a filled circle.
*
* @param mirrorHorizontally Whether or not the arc must be mirrored across the horizontal plane. Will produce a bar that grows from the middle filling both sides.
*/
static void drawCircle(MatrixStack matrices, double radius, double startAngle, double arcAngle, int color, boolean mirrorHorizontally) {
drawCircle(matrices, radius, startAngle, arcAngle, color, mirrorHorizontally, VertexFormat.DrawMode.QUADS);
}
private static void drawCircle(MatrixStack matrices, double radius, double startAngle, double arcAngle, int color, boolean mirrorHorizontally, VertexFormat.DrawMode mode) {
float r = (color >> 24 & 255) / 255F;
float g = (color >> 16 & 255) / 255F;
float b = (color >> 8 & 255) / 255F;
float k = (color & 255) / 255F;
if (arcAngle < INCREMENT) {
return;
}
final double maxAngle = MathHelper.clamp(startAngle + arcAngle, 0, TAU - INCREMENT);
if (!mirrorHorizontally) {
startAngle = -startAngle;
}
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
Matrix4f model = matrices.peek().getPositionMatrix();
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
bufferBuilder.begin(mode, VertexFormats.POSITION_COLOR);
boolean joinEnds = mode == VertexFormat.DrawMode.QUADS;
// center
for (double angle = startAngle; angle >= -maxAngle; angle -= INCREMENT) {
if (joinEnds) {
bufferBuilder.vertex(model, 0, 0, 0).color(r, g, b, k).next();
}
// point one
cylendricalVertex(bufferBuilder, model, radius, angle, r, g, b, k);
// point two
cylendricalVertex(bufferBuilder, model, radius, angle + INCREMENT, r, g, b, k);
if (joinEnds) {
bufferBuilder.vertex(model, 0, 0, 0).color(r, g, b, k).next();
}
}
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
}
private static void cylendricalVertex(BufferBuilder bufferBuilder, Matrix4f model, double radius, double angle, float r, float g, float b, float k) {
bufferBuilder.vertex(model,
(float)(radius * MathHelper.sin((float)angle)),

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.client.gui;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.Abilities;
import com.minelittlepony.unicopia.ability.AbilityDispatcher;
import com.minelittlepony.unicopia.ability.AbilitySlot;
import com.minelittlepony.unicopia.entity.player.MagicReserves;
@ -21,19 +22,44 @@ class ManaRingSlot extends Slot {
@Override
protected void renderContents(DrawContext context, AbilityDispatcher abilities, boolean bSwap, float tickDelta) {
MatrixStack matrices = context.getMatrices();
matrices.push();
matrices.translate(24.5, 25.5, 0);
matrices.translate(24.125, 24.75, 0);
Pony pony = Pony.of(uHud.client.player);
MagicReserves mana = pony.getMagicalReserves();
double arcBegin = 0;
boolean canUseSuper = Abilities.RAGE.canUse(pony.getCompositeRace()) || Abilities.RAINBOOM.canUse(pony.getCompositeRace());
arcBegin = renderRing(matrices, 17, 13, 0, mana.getMana(), 0xFF88FF99, tickDelta);
double maxManaBarSize = canUseSuper ? DrawableUtil.PI : DrawableUtil.TAU;
double arcBegin = renderRing(matrices, 17, 13, 0, maxManaBarSize, mana.getMana(), 0xFF88FF99, tickDelta);
renderRing(matrices, 17, 13, 0, maxManaBarSize, mana.getExhaustion(), 0xFF002299, tickDelta);
if (!uHud.client.player.isCreative()) {
renderRing(matrices, 13, 9, 0, mana.getXp(), 0x88880099, tickDelta);
renderRing(matrices, 9, 0, 0, mana.getCharge(), 0x0000FF99, tickDelta);
int level = pony.getLevel().get();
int seconds = level % 16;
int minutes = (level / 16) % 16;
int hours = level / 32;
DrawableUtil.drawNotchedArc(matrices, 10, 13, 0, hours * 0.2, 0.1, 0.1, 0x00AA88FF);
DrawableUtil.drawNotchedArc(matrices, 10, 13, hours * 0.2, minutes * 0.2, 0.1, 0.1, 0x008888AA);
DrawableUtil.drawNotchedArc(matrices, 10, 13, (hours + minutes) * 0.2, seconds * 0.2, 0.1, 0.1, 0x88880099);
level = pony.getCorruption().get();
seconds = level % 16;
minutes = (level / 16) % 16;
hours = level / 32;
DrawableUtil.drawNotchedArc(matrices, 7, 10, DrawableUtil.PI, hours * 0.2, 0.1, 0.1, 0x000088FF);
DrawableUtil.drawNotchedArc(matrices, 7, 10, hours * 0.2 + DrawableUtil.PI, minutes * 0.2, 0.1, 0.1, 0x000088AA);
DrawableUtil.drawNotchedArc(matrices, 7, 10, (hours + minutes) * 0.2 + DrawableUtil.PI, seconds * 0.2, 0.1, 0.1, 0x00008899);
if (canUseSuper) {
renderRing(matrices, 17, 13, Math.min(arcBegin, DrawableUtil.PI), Math.max(DrawableUtil.PI, DrawableUtil.TAU - arcBegin), mana.getCharge(), 0x88FF9999, tickDelta);
}
double cost = abilities.getStats().stream()
.mapToDouble(s -> s.getCost(Unicopia.getConfig().hudPage.get()))
@ -53,28 +79,25 @@ class ManaRingSlot extends Slot {
double angle = cost * Math.PI * 2;
DrawableUtil.drawArc(matrices, 13, 17, arcBegin - angle, angle, color, false);
DrawableUtil.drawArc(matrices, 13, 17, arcBegin - angle, angle, color);
}
}
arcBegin = renderRing(matrices, 17, 13, arcBegin, mana.getExhaustion(), 0xFF002299, tickDelta);
matrices.pop();
super.renderContents(context, abilities, bSwap, tickDelta);
}
private double renderRing(MatrixStack matrices, double outerRadius, double innerRadius, double offsetAngle, Bar bar, int color, float tickDelta) {
double fill = bar.getPercentFill(tickDelta) * DrawableUtil.TAU;
double shadow = bar.getShadowFill(tickDelta) * DrawableUtil.TAU;
private double renderRing(MatrixStack matrices, double outerRadius, double innerRadius, double offsetAngle, double maxAngle, Bar bar, int color, float tickDelta) {
double fill = bar.getPercentFill(tickDelta) * maxAngle;
double shadow = bar.getShadowFill(tickDelta) * maxAngle;
DrawableUtil.drawArc(matrices, innerRadius, outerRadius, offsetAngle, fill, color, true);
DrawableUtil.drawArc(matrices, innerRadius, outerRadius, offsetAngle, fill, color);
if (shadow > fill) {
color = (color & 0xFFFFFF00)
| ((color & 0x000000FF) / 2);
DrawableUtil.drawArc(matrices, innerRadius, outerRadius, offsetAngle + fill, shadow - fill, color, false);
DrawableUtil.drawArc(matrices, innerRadius, outerRadius, offsetAngle + fill, shadow - fill, color);
}
return offsetAngle + fill;
}

View file

@ -33,10 +33,10 @@ public interface SpellIconRenderer {
int color = spell.type().getColor() | 0x000000FF;
double radius = (1.5F + Math.sin(client.player.age / 9D) / 4) * ringScale;
DrawableUtil.drawArc(modelStack, radius, radius + 3, 0, DrawableUtil.TAU, color & 0xFFFFFF2F, false);
DrawableUtil.drawArc(modelStack, radius + 3, radius + 4, 0, DrawableUtil.TAU, color & 0xFFFFFFAF, false);
DrawableUtil.drawArc(modelStack, radius, radius + 3, 0, DrawableUtil.TAU, color & 0xFFFFFF2F);
DrawableUtil.drawArc(modelStack, radius + 3, radius + 4, 0, DrawableUtil.TAU, color & 0xFFFFFFAF);
pony.getSpellSlot().get(spell.and(SpellPredicate.IS_TIMED)).map(TimedSpell::getTimer).ifPresent(timer -> {
DrawableUtil.drawArc(modelStack, radius, radius + 3, 0, DrawableUtil.TAU * timer.getPercentTimeRemaining(client.getTickDelta()), 0xFFFFFFFF, false);
DrawableUtil.drawArc(modelStack, radius, radius + 3, 0, DrawableUtil.TAU * timer.getPercentTimeRemaining(client.getTickDelta()), 0xFFFFFFFF);
});
long count = pony.getSpellSlot().stream(spell).count();

View file

@ -101,7 +101,7 @@ public class UHud {
float flapCooldown = pony.getPhysics().getFlapCooldown(tickDelta);
if (flapCooldown > 0) {
float angle = MathHelper.TAU * flapCooldown;
DrawableUtil.drawArc(context.getMatrices(), 3, 6, -angle / 2F, angle, 0x888888AF, false);
DrawableUtil.drawArc(context.getMatrices(), 3, 6, -angle / 2F, angle, 0x888888AF);
}
matrices.pop();
@ -205,7 +205,7 @@ public class UHud {
context.fill(RenderLayers.getEndPortal(), 0, 0, scaledWidth, scaledHeight, 0);
context.getMatrices().push();
context.getMatrices().translate(scaledWidth / 2, scaledHeight / 2, 0);
DrawableUtil.drawArc(context.getMatrices(), 0, 20, 0, MathHelper.TAU, 0x000000FF, false);
DrawableUtil.drawArc(context.getMatrices(), 0, 20, 0, MathHelper.TAU, 0x000000FF);
context.getMatrices().pop();
return;
} else if (vortexDistortion > 0) {

View file

@ -110,8 +110,8 @@ public class SpellbookProfilePageContent implements SpellbookChapterList.Content
}
manaColor |= (int)((0.3F + 0.7F * alphaF) * 0x40) << 16;
DrawableUtil.drawArc(matrices, 0, radius + 24, 0, DrawableUtil.TAU, color, false);
DrawableUtil.drawArc(matrices, radius / 3, radius + 6, 0, DrawableUtil.TAU, color, false);
DrawableUtil.drawArc(matrices, 0, radius + 24, 0, DrawableUtil.TAU, color);
DrawableUtil.drawArc(matrices, radius / 3, radius + 6, 0, DrawableUtil.TAU, color);
if (currentLevel >= pony.getLevel().getMax()) {
int rayCount = 6;
@ -129,14 +129,14 @@ public class SpellbookProfilePageContent implements SpellbookChapterList.Content
double rad = (radius + glowSize) * 0.8F + growth - (i % 2) * 5;
float rot = (rotate + raySeparation * i) % MathHelper.TAU;
DrawableUtil.drawArc(matrices, 0, rad, rot, 0.2F, bandAColor, false);
DrawableUtil.drawArc(matrices, 0, rad + 0.3F, rot + 0.37F, 0.25F, bandBColor, false);
DrawableUtil.drawArc(matrices, 0, rad, rot, 0.2F, bandAColor);
DrawableUtil.drawArc(matrices, 0, rad + 0.3F, rot + 0.37F, 0.25F, bandBColor);
}
}
DrawableUtil.drawArc(matrices, radius / 3, radius + 6, 0, xpPercentage * DrawableUtil.TAU, xpColor, false);
DrawableUtil.drawArc(matrices, radius / 3, radius + 6, 0, xpPercentage * DrawableUtil.TAU, xpColor);
radius += 8;
DrawableUtil.drawArc(matrices, radius, radius + 6 + growth, 0, manaPercentage * DrawableUtil.TAU, manaColor, false);
DrawableUtil.drawArc(matrices, radius, radius + 6 + growth, 0, manaPercentage * DrawableUtil.TAU, manaColor);
String manaString = (int)reserves.getMana().get() + "/" + (int)reserves.getMana().getMax();

View file

@ -58,8 +58,7 @@ public class SpellRenderer<T extends Spell> {
float timeRemaining = spell.getTimer().getPercentTimeRemaining(tickDelta);
DrawableUtil.drawArc(matrices, radius, radius + 0.3F, 0, DrawableUtil.TAU * timeRemaining,
ColorHelper.lerp(MathHelper.clamp(timeRemaining * 4, 0, 1), 0xFF0000FF, 0xFFFFFFFF),
false
ColorHelper.lerp(MathHelper.clamp(timeRemaining * 4, 0, 1), 0xFF0000FF, 0xFFFFFFFF)
);
}