mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 23:27:59 +01:00
Wip new hud
This commit is contained in:
parent
c12b67e909
commit
07d59d7f0b
7 changed files with 85 additions and 164 deletions
|
@ -1,74 +0,0 @@
|
||||||
package com.minelittlepony.unicopia.client.gui;
|
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.DrawableHelper;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
class FlightExperienceBar extends DrawableHelper implements HudElement {
|
|
||||||
|
|
||||||
static final Identifier TEXTURE = new Identifier("textures/gui/bars.png");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRender(Pony player) {
|
|
||||||
return player.getSpecies().canFly()
|
|
||||||
&& !player.getOwner().abilities.creativeMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderHud(UHud context) {
|
|
||||||
float xp = context.player.getFlight().getFlightExperience();
|
|
||||||
float length = context.player.getFlight().getFlightDuration();
|
|
||||||
|
|
||||||
context.mc.getTextureManager().bindTexture(TEXTURE);
|
|
||||||
int x = (context.width - 182) / 2;
|
|
||||||
int y = context.height - 29;
|
|
||||||
|
|
||||||
int xpFill = (int)Math.floor(xp * 182);
|
|
||||||
int xpBuff = (int)Math.floor((183 - xpFill) * length);
|
|
||||||
|
|
||||||
int baseV = 0;
|
|
||||||
|
|
||||||
if (context.player.getFlight().isExperienceCritical()) {
|
|
||||||
|
|
||||||
int tickCount = (int)(context.mc.getTickDelta() * 10);
|
|
||||||
|
|
||||||
baseV += (tickCount % 3) * 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
blit(x, y, 0, baseV, 256, 5, 256, 256);
|
|
||||||
blit(x, y, 0, baseV + 5, xpFill, 5, 256, 256);
|
|
||||||
|
|
||||||
blit(x + xpFill, y, xpFill, baseV + 10, xpBuff, 5, 256, 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void repositionHud(UHud context) {
|
|
||||||
int offset = 6;
|
|
||||||
|
|
||||||
GlStateManager.translatef(0, context.begin ? -offset : offset, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.minelittlepony.unicopia.client.gui;
|
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
||||||
|
|
||||||
public interface HudElement {
|
|
||||||
|
|
||||||
void repositionHud(UHud context);
|
|
||||||
|
|
||||||
void renderHud(UHud context);
|
|
||||||
|
|
||||||
boolean shouldRender(Pony player);
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package com.minelittlepony.unicopia.client.gui;
|
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
// XXX: hud render events
|
|
||||||
class HudHooks {
|
|
||||||
public static void beforePreRenderHud() {
|
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
|
||||||
|
|
||||||
if (client.player != null && client.world != null) {
|
|
||||||
UHud.instance.repositionElements(Pony.of(client.player), client.getWindow(), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void postRenderHud() {
|
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
|
||||||
|
|
||||||
if (client.player != null && client.world != null) {
|
|
||||||
UHud.instance.renderHud(Pony.of(client.player), client.getWindow());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +1,94 @@
|
||||||
package com.minelittlepony.unicopia.client.gui;
|
package com.minelittlepony.unicopia.client.gui;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.DrawableHelper;
|
||||||
import net.minecraft.client.util.Window;
|
import net.minecraft.client.gui.hud.InGameHud;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
public class UHud {
|
public class UHud extends DrawableHelper {
|
||||||
|
|
||||||
public static final UHud instance = new UHud();
|
public static final UHud instance = new UHud();
|
||||||
|
|
||||||
private List<HudElement> elements = new ArrayList<>();
|
public static final Identifier HUD_TEXTURE = new Identifier("unicopia", "textures/gui/hud.png");
|
||||||
|
|
||||||
MinecraftClient mc = MinecraftClient.getInstance();
|
private Slot secondarySlot = new Slot(26, 0);
|
||||||
|
private Slot tertiarySlot = new Slot(36, 24);
|
||||||
|
|
||||||
TextRenderer fonts = mc.textRenderer;
|
public void render(InGameHud hud, float tickDelta) {
|
||||||
|
MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
|
||||||
Pony player;
|
int scaledWidth = client.getWindow().getScaledWidth();
|
||||||
|
int scaledHeight = client.getWindow().getScaledHeight();
|
||||||
|
|
||||||
int width;
|
int x = 104 + (scaledWidth - 50) / 2;
|
||||||
|
int y = 20 + scaledHeight - 70;
|
||||||
|
|
||||||
int height;
|
RenderSystem.enableAlphaTest();
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
|
||||||
boolean begin;
|
client.getTextureManager().bindTexture(HUD_TEXTURE);
|
||||||
|
|
||||||
private UHud() {
|
int frameHeight = 54;
|
||||||
elements.add(new FlightExperienceBar());
|
int frameWidth = 54;
|
||||||
|
|
||||||
|
blit(x, y, 0, 0, frameWidth, frameHeight, 128, 128); // background
|
||||||
|
|
||||||
|
float progressPercent = 0.25F;
|
||||||
|
int progressHeight = (int)(frameHeight * progressPercent);
|
||||||
|
|
||||||
|
blit(x, y + (frameHeight - progressHeight),
|
||||||
|
61, frameHeight - progressHeight,
|
||||||
|
frameWidth, progressHeight, 128, 128); // progress
|
||||||
|
|
||||||
|
blit(x, y, 0, 54, frameWidth, frameHeight, 128, 128); // frame
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
secondarySlot.render(x, y, 50, 100, tickDelta);
|
||||||
|
tertiarySlot.render(x, y, 5, 10, tickDelta);
|
||||||
|
|
||||||
|
RenderSystem.disableBlend();
|
||||||
|
RenderSystem.disableAlphaTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderHud(Pony player, Window resolution) {
|
|
||||||
this.width = resolution.getScaledWidth();
|
|
||||||
this.height = resolution.getScaledHeight();
|
|
||||||
this.player = player;
|
|
||||||
this.begin = true;
|
|
||||||
|
|
||||||
elements.forEach(this::renderElement);
|
static class Slot {
|
||||||
}
|
|
||||||
|
|
||||||
public void repositionElements(Pony player, Window window, boolean begin) {
|
private int x;
|
||||||
this.width = window.getScaledWidth();
|
private int y;
|
||||||
this.height = window.getScaledHeight();
|
|
||||||
this.player = player;
|
|
||||||
this.begin = begin;
|
|
||||||
|
|
||||||
elements.forEach(this::positionElement);
|
private float lastCooldown;
|
||||||
}
|
|
||||||
|
|
||||||
private void positionElement(HudElement element) {
|
public Slot(int x, int y) {
|
||||||
if (!element.shouldRender(player)) {
|
this.x = x;
|
||||||
return;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
element.repositionHud(this);
|
void render(int x, int y, float cooldown, float maxCooldown, float tickDelta) {
|
||||||
}
|
x += this.x;
|
||||||
|
y += this.y;
|
||||||
|
|
||||||
private void renderElement(HudElement element) {
|
if (cooldown > 0 && maxCooldown > 0 && cooldown < maxCooldown) {
|
||||||
if (!element.shouldRender(player)) {
|
float lerpCooldown = MathHelper.lerp(tickDelta, cooldown, lastCooldown);
|
||||||
return;
|
|
||||||
|
lastCooldown = lerpCooldown;
|
||||||
|
|
||||||
|
float cooldownPercent = 1 - lerpCooldown / maxCooldown;
|
||||||
|
|
||||||
|
int slotPadding = 4;
|
||||||
|
int slotSize = 15;
|
||||||
|
|
||||||
|
int progressBottom = y + slotPadding + slotSize;
|
||||||
|
int progressTop = progressBottom - (int)(15F * cooldownPercent);
|
||||||
|
|
||||||
|
fill(x + slotPadding, progressTop, x + slotPadding + slotSize, progressBottom, 0xAAFFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
blit(x, y, 105, 105, 30, 30, 128, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
|
||||||
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
GlStateManager.disableLighting();
|
|
||||||
GlStateManager.color4f(1, 1, 1, 1);
|
|
||||||
|
|
||||||
element.renderHud(this);
|
|
||||||
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
|
|
||||||
GL11.glPopAttrib();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.minelittlepony.unicopia.mixin.client;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.client.gui.UHud;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.hud.InGameHud;
|
||||||
|
|
||||||
|
@Mixin(InGameHud.class)
|
||||||
|
public class MixinInGameHud {
|
||||||
|
@Inject(method = "render(F)V", at = @At("HEAD"))
|
||||||
|
private void onRender(float tickDelta, CallbackInfo info) {
|
||||||
|
UHud.instance.render((InGameHud)(Object)this, tickDelta);
|
||||||
|
}
|
||||||
|
}
|
BIN
src/main/resources/assets/unicopia/textures/gui/hud.png
Normal file
BIN
src/main/resources/assets/unicopia/textures/gui/hud.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
|
@ -23,6 +23,7 @@
|
||||||
"client.DefaultTexturesRegistry",
|
"client.DefaultTexturesRegistry",
|
||||||
"client.MixinCamera",
|
"client.MixinCamera",
|
||||||
"client.MixinEntityRenderDispatcher",
|
"client.MixinEntityRenderDispatcher",
|
||||||
|
"client.MixinInGameHud",
|
||||||
"client.MixinGameRenderer",
|
"client.MixinGameRenderer",
|
||||||
"client.MixinItemModels",
|
"client.MixinItemModels",
|
||||||
"client.MixinKeyboardInput",
|
"client.MixinKeyboardInput",
|
||||||
|
|
Loading…
Reference in a new issue