mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 13:57:59 +01:00
More work on the hud and spell dismissal dialogue
This commit is contained in:
parent
7738f01d3a
commit
3fa945d97a
4 changed files with 90 additions and 90 deletions
|
@ -11,7 +11,6 @@ import com.minelittlepony.unicopia.client.particle.SphereModel;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
import com.minelittlepony.unicopia.network.Channel;
|
import com.minelittlepony.unicopia.network.Channel;
|
||||||
import com.minelittlepony.unicopia.network.MsgRemoveSpell;
|
import com.minelittlepony.unicopia.network.MsgRemoveSpell;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.Drawable;
|
import net.minecraft.client.gui.Drawable;
|
||||||
|
@ -30,35 +29,22 @@ import net.minecraft.util.math.Vector4f;
|
||||||
public class DismissSpellScreen extends GameGui {
|
public class DismissSpellScreen extends GameGui {
|
||||||
private final Pony pony = Pony.of(MinecraftClient.getInstance().player);
|
private final Pony pony = Pony.of(MinecraftClient.getInstance().player);
|
||||||
|
|
||||||
private final List<Spell> spells;
|
private int relativeMouseX;
|
||||||
|
private int relativeMouseY;
|
||||||
|
|
||||||
public DismissSpellScreen() {
|
public DismissSpellScreen() {
|
||||||
super(new TranslatableText("gui.unicopia.dismiss_spell"));
|
super(new TranslatableText("gui.unicopia.dismiss_spell"));
|
||||||
|
|
||||||
spells = pony.getSpellSlot().stream(true).toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
double azimuth = 0;
|
double azimuth = 0;
|
||||||
int ring = 1;
|
double ring = 2;
|
||||||
|
|
||||||
for (Spell spell : spells) {
|
for (Spell spell : pony.getSpellSlot().stream(true).toList()) {
|
||||||
|
addDrawableChild(new Entry(spell, 75 * ring - 25, azimuth));
|
||||||
double increment = Math.PI / (8 * ring);
|
ring *= 1 + 0.03 / ring;
|
||||||
|
azimuth += Math.PI / (8 * ring);
|
||||||
azimuth += increment;
|
|
||||||
if (azimuth > Math.PI) {
|
|
||||||
azimuth = 0;
|
|
||||||
ring++;
|
|
||||||
}
|
|
||||||
|
|
||||||
double radius = 75 * ring - 25;
|
|
||||||
|
|
||||||
Vector4f pos = SphereModel.convertToCartesianCoord(radius, azimuth, azimuth);
|
|
||||||
pos.add(0, -(float)radius / 2F, 0, 0);
|
|
||||||
|
|
||||||
addDrawableChild(new Entry(spell, pos));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,26 +53,22 @@ public class DismissSpellScreen extends GameGui {
|
||||||
fillGradient(matrices, 0, 0, width, height / 2, 0xF0101010, 0x80101010);
|
fillGradient(matrices, 0, 0, width, height / 2, 0xF0101010, 0x80101010);
|
||||||
fillGradient(matrices, 0, height / 2, width, height, 0x80101010, 0xF0101010);
|
fillGradient(matrices, 0, height / 2, width, height, 0x80101010, 0xF0101010);
|
||||||
|
|
||||||
|
relativeMouseX = -width + mouseX * 2;
|
||||||
|
relativeMouseY = -height + mouseY * 2;
|
||||||
|
|
||||||
matrices.push();
|
matrices.push();
|
||||||
matrices.translate(width - mouseX, height - mouseY, 0);
|
matrices.translate(width - mouseX, height - mouseY, 0);
|
||||||
|
DrawableUtil.drawLine(matrices, 0, 0, relativeMouseX, relativeMouseY, 0xFFFFFF88);
|
||||||
mouseX = -width + mouseX * 2;
|
DrawableUtil.drawArc(matrices, 40, 80, 0, DrawableUtil.TWO_PI, 0x00000010, false);
|
||||||
mouseY = -height + mouseY * 2;
|
DrawableUtil.drawArc(matrices, 160, 1600, 0, DrawableUtil.TWO_PI, 0x00000020, false);
|
||||||
|
|
||||||
DrawableUtil.drawLine(matrices, 0, 0, mouseX, mouseY, 0xFFFFFF88);
|
|
||||||
DrawableUtil.drawArc(matrices, 40, 80, 0, Math.PI * 2, 0x00000010, false);
|
|
||||||
DrawableUtil.drawArc(matrices, 160, 1600, 0, Math.PI * 2, 0x00000020, false);
|
|
||||||
|
|
||||||
super.render(matrices, mouseX, mouseY, delta);
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
|
|
||||||
matrices.push();
|
DrawableUtil.drawCircle(matrices, 2, 0, DrawableUtil.TWO_PI, 0xFFAAFF99, false);
|
||||||
DrawableUtil.drawCircle(matrices, 2, 0, Math.PI * 2, 0xFFAAFF99, false);
|
|
||||||
matrices.translate(mouseX, mouseY, 0);
|
|
||||||
DrawableUtil.drawLine(matrices, 0, -4, 0, 4, 0xFFAAFF99);
|
|
||||||
DrawableUtil.drawLine(matrices, -4, 0, 4, 0, 0xFFAAFF99);
|
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
|
|
||||||
matrices.pop();
|
DrawableUtil.drawLine(matrices, mouseX, mouseY - 4, mouseX, mouseY + 4, 0xFFAAFF99);
|
||||||
|
DrawableUtil.drawLine(matrices, mouseX - 4, mouseY, mouseX + 4, mouseY, 0xFFAAFF99);
|
||||||
|
|
||||||
matrices.push();
|
matrices.push();
|
||||||
matrices.translate(0, 0, 300);
|
matrices.translate(0, 0, 300);
|
||||||
|
@ -105,21 +87,24 @@ public class DismissSpellScreen extends GameGui {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Entry implements Element, Drawable, Selectable {
|
class Entry extends Vector4f implements Element, Drawable, Selectable {
|
||||||
|
|
||||||
private final List<Text> tooltip = new ArrayList<>();
|
private final List<Text> tooltip = new ArrayList<>();
|
||||||
|
|
||||||
private final Spell spell;
|
private final Spell spell;
|
||||||
private final Spell actualSpell;
|
private final Spell actualSpell;
|
||||||
private final Vector4f pos;
|
|
||||||
|
|
||||||
private boolean lastMouseOver;
|
private boolean lastMouseOver;
|
||||||
|
|
||||||
public Entry(Spell spell, Vector4f pos) {
|
private final Vector4f copy = new Vector4f();
|
||||||
|
|
||||||
|
public Entry(Spell spell, double radius, double azimuth) {
|
||||||
this.spell = spell;
|
this.spell = spell;
|
||||||
this.pos = pos;
|
|
||||||
this.actualSpell = getActualSpell();
|
this.actualSpell = getActualSpell();
|
||||||
|
|
||||||
|
SphereModel.convertToCartesianCoord(this, radius, azimuth, azimuth);
|
||||||
|
add(0, -(float)radius / 2F, 0, 0);
|
||||||
|
|
||||||
MutableText name = actualSpell.getType().getName().shallowCopy();
|
MutableText name = actualSpell.getType().getName().shallowCopy();
|
||||||
int color = actualSpell.getType().getColor();
|
int color = actualSpell.getType().getColor();
|
||||||
name.setStyle(name.getStyle().withColor(color == 0 ? 0xFFAAAAAA : color));
|
name.setStyle(name.getStyle().withColor(color == 0 ? 0xFFAAAAAA : color));
|
||||||
|
@ -143,46 +128,41 @@ public class DismissSpellScreen extends GameGui {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||||
|
if (isMouseOver(relativeMouseX, relativeMouseY)) {
|
||||||
remove(this);
|
remove(this);
|
||||||
pony.getSpellSlot().removeIf(spell -> spell == this.spell, true);
|
pony.getSpellSlot().removeIf(spell -> spell == this.spell, true);
|
||||||
Channel.REMOVE_SPELL.send(new MsgRemoveSpell(spell));
|
Channel.REMOVE_SPELL.send(new MsgRemoveSpell(spell));
|
||||||
playClickEffect();
|
playClickEffect();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMouseOver(double mouseX, double mouseY) {
|
public boolean isMouseOver(double mouseX, double mouseY) {
|
||||||
return squareDistance(mouseX, mouseY, pos.getX(), pos.getY()) < 75;
|
return squareDistance(mouseX, mouseY, getX(), getY()) < 75;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float tickDelta) {
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float tickDelta) {
|
||||||
Vector4f copy = new Vector4f(pos.getX(), pos.getY(), pos.getZ(), pos.getW());
|
copy.set(getX(), getY(), getZ(), getW());
|
||||||
copy.transform(matrices.peek().getPositionMatrix());
|
copy.transform(matrices.peek().getPositionMatrix());
|
||||||
|
|
||||||
boolean hovered = isMouseOver(mouseX, mouseY);
|
DrawableUtil.renderItemIcon(actualSpell.getType().getDefualtStack(),
|
||||||
|
copy.getX() - 8 + (copy.getX() - mouseX - 5) / 60D,
|
||||||
MatrixStack modelStack = RenderSystem.getModelViewStack();
|
copy.getY() - 8 + (copy.getY() - mouseY - 5) / 60D,
|
||||||
modelStack.push();
|
1
|
||||||
float scale = 1.1F;
|
);
|
||||||
modelStack.translate(-21, -14, 0);
|
|
||||||
modelStack.scale(scale, scale, 1);
|
|
||||||
RenderSystem.applyModelViewMatrix();
|
|
||||||
|
|
||||||
client.getItemRenderer().renderGuiItemIcon(actualSpell.getType().getDefualtStack(), (int)copy.getX() - 8, (int)copy.getY() - 8);
|
|
||||||
|
|
||||||
modelStack.pop();
|
|
||||||
RenderSystem.applyModelViewMatrix();
|
|
||||||
|
|
||||||
matrices.push();
|
matrices.push();
|
||||||
matrices.translate(pos.getX(), pos.getY(), 0);
|
matrices.translate(getX(), getY(), 0);
|
||||||
|
|
||||||
int color = actualSpell.getType().getColor() << 2;
|
int color = actualSpell.getType().getColor() << 2;
|
||||||
|
|
||||||
DrawableUtil.drawArc(matrices, 7, 8, 0, Math.PI * 2, color | 0x00000088, false);
|
DrawableUtil.drawArc(matrices, 7, 8, 0, DrawableUtil.TWO_PI, color | 0x00000088, false);
|
||||||
|
|
||||||
if (hovered) {
|
if (isMouseOver(relativeMouseX, relativeMouseY)) {
|
||||||
DrawableUtil.drawArc(matrices, 0, 8, 0, Math.PI * 2, color | 0x000000FF, false);
|
DrawableUtil.drawArc(matrices, 0, 8, 0, DrawableUtil.TWO_PI, color | 0x000000FF, false);
|
||||||
renderTooltip(matrices, tooltip, 0, 0);
|
renderTooltip(matrices, tooltip, 0, 0);
|
||||||
|
|
||||||
if (!lastMouseOver) {
|
if (!lastMouseOver) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.render.BufferBuilder;
|
import net.minecraft.client.render.BufferBuilder;
|
||||||
import net.minecraft.client.render.BufferRenderer;
|
import net.minecraft.client.render.BufferRenderer;
|
||||||
import net.minecraft.client.render.GameRenderer;
|
import net.minecraft.client.render.GameRenderer;
|
||||||
|
@ -9,6 +10,7 @@ import net.minecraft.client.render.Tessellator;
|
||||||
import net.minecraft.client.render.VertexFormat;
|
import net.minecraft.client.render.VertexFormat;
|
||||||
import net.minecraft.client.render.VertexFormats;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Matrix4f;
|
import net.minecraft.util.math.Matrix4f;
|
||||||
|
|
||||||
|
@ -17,6 +19,22 @@ public class DrawableUtil {
|
||||||
private static final double NUM_RINGS = 300;
|
private static final double NUM_RINGS = 300;
|
||||||
private static final double INCREMENT = TWO_PI / NUM_RINGS;
|
private static final double INCREMENT = TWO_PI / NUM_RINGS;
|
||||||
|
|
||||||
|
|
||||||
|
public static void renderItemIcon(ItemStack stack, double x, double y, float scale) {
|
||||||
|
MatrixStack modelStack = RenderSystem.getModelViewStack();
|
||||||
|
modelStack.push();
|
||||||
|
modelStack.translate(x, y, 0);
|
||||||
|
if (scale != 1) {
|
||||||
|
modelStack.scale(scale, scale, 1);
|
||||||
|
}
|
||||||
|
RenderSystem.applyModelViewMatrix();
|
||||||
|
|
||||||
|
MinecraftClient.getInstance().getItemRenderer().renderGuiItemIcon(stack, 0, 0);
|
||||||
|
|
||||||
|
modelStack.pop();
|
||||||
|
RenderSystem.applyModelViewMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
public static void drawLine(MatrixStack matrices, int x1, int y1, int x2, int y2, int color) {
|
public static void drawLine(MatrixStack matrices, int x1, int y1, int x2, int y2, int color) {
|
||||||
RenderSystem.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
RenderSystem.disableTexture();
|
RenderSystem.disableTexture();
|
||||||
|
|
|
@ -156,26 +156,24 @@ public class UHud extends DrawableHelper {
|
||||||
|
|
||||||
public void renderSpell(CustomisedSpellType<?> spell, double x, double y) {
|
public void renderSpell(CustomisedSpellType<?> spell, double x, double y) {
|
||||||
if (!spell.isEmpty()) {
|
if (!spell.isEmpty()) {
|
||||||
MatrixStack modelStack = RenderSystem.getModelViewStack();
|
|
||||||
|
|
||||||
modelStack.push();
|
|
||||||
modelStack.translate(x, y, 0);
|
|
||||||
modelStack.scale(EQUIPPED_GEMSTONE_SCALE, EQUIPPED_GEMSTONE_SCALE, 1);
|
|
||||||
|
|
||||||
RenderSystem.applyModelViewMatrix();
|
|
||||||
client.getItemRenderer().renderGuiItemIcon(spell.getDefaultStack(), 0, 0);
|
|
||||||
|
|
||||||
modelStack.loadIdentity();
|
|
||||||
modelStack.translate(7.5, 8.5, 0);
|
|
||||||
|
|
||||||
Pony pony = Pony.of(client.player);
|
Pony pony = Pony.of(client.player);
|
||||||
|
|
||||||
if (spell.isOn(pony)) {
|
if (spell.isOn(pony)) {
|
||||||
DrawableUtil.drawArc(modelStack, 5, 7, 0, Math.PI * 2, (spell.type().getColor() | 0x000000FF) & 0xFFFFFFAF, false);
|
MatrixStack modelStack = new MatrixStack();
|
||||||
DrawableUtil.drawArc(modelStack, 7, 8, 0, Math.PI * 2, 0xAAAAFFFF, false);
|
|
||||||
}
|
modelStack.push();
|
||||||
|
modelStack.translate(x + 5.5, y + 5.5, 0);
|
||||||
|
|
||||||
|
int color = spell.type().getColor() | 0x000000FF;
|
||||||
|
double radius = 2 + Math.sin(client.player.age / 9D) / 4;
|
||||||
|
|
||||||
|
DrawableUtil.drawArc(modelStack, radius, radius + 3, 0, DrawableUtil.TWO_PI, color & 0xFFFFFF2F, false);
|
||||||
|
DrawableUtil.drawArc(modelStack, radius + 3, radius + 4, 0, DrawableUtil.TWO_PI, color & 0xFFFFFFAF, false);
|
||||||
|
|
||||||
modelStack.pop();
|
modelStack.pop();
|
||||||
RenderSystem.applyModelViewMatrix();
|
}
|
||||||
|
|
||||||
|
DrawableUtil.renderItemIcon(spell.getDefaultStack(), x, y, EQUIPPED_GEMSTONE_SCALE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,21 +30,22 @@ public class SphereModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4f position = matrices.peek().getPositionMatrix();
|
Matrix4f position = matrices.peek().getPositionMatrix();
|
||||||
|
Vector4f vec = new Vector4f();
|
||||||
|
|
||||||
for (double zenith = -PI; zenith < PI; zenith += zenithIncrement) {
|
for (double zenith = -PI; zenith < PI; zenith += zenithIncrement) {
|
||||||
for (double azimuth = -azimuthRange; azimuth < azimuthRange; azimuth += azimuthIncrement) {
|
for (double azimuth = -azimuthRange; azimuth < azimuthRange; azimuth += azimuthIncrement) {
|
||||||
drawQuad(position, vertexWriter, radius, zenith, azimuth, light, overlay, r, g, b, a);
|
drawQuad(position, vec, vertexWriter, radius, zenith, azimuth, light, overlay, r, g, b, a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawQuad(Matrix4f model, VertexConsumer vertexWriter,
|
private void drawQuad(Matrix4f model, Vector4f vec, VertexConsumer vertexWriter,
|
||||||
double radius, double zenith, double azimuth,
|
double radius, double zenith, double azimuth,
|
||||||
int light, int overlay, float r, float g, float b, float a) {
|
int light, int overlay, float r, float g, float b, float a) {
|
||||||
drawVertex(model, vertexWriter, convertToCartesianCoord(radius, zenith, azimuth), light, overlay, r, g, b, a);
|
drawVertex(model, vertexWriter, convertToCartesianCoord(vec, radius, zenith, azimuth), light, overlay, r, g, b, a);
|
||||||
drawVertex(model, vertexWriter, convertToCartesianCoord(radius, zenith + zenithIncrement, azimuth), light, overlay, r, g, b, a);
|
drawVertex(model, vertexWriter, convertToCartesianCoord(vec, radius, zenith + zenithIncrement, azimuth), light, overlay, r, g, b, a);
|
||||||
drawVertex(model, vertexWriter, convertToCartesianCoord(radius, zenith + zenithIncrement, azimuth + azimuthIncrement), light, overlay, r, g, b, a);
|
drawVertex(model, vertexWriter, convertToCartesianCoord(vec, radius, zenith + zenithIncrement, azimuth + azimuthIncrement), light, overlay, r, g, b, a);
|
||||||
drawVertex(model, vertexWriter, convertToCartesianCoord(radius, zenith, azimuth + azimuthIncrement), light, overlay, r, g, b, a);
|
drawVertex(model, vertexWriter, convertToCartesianCoord(vec, radius, zenith, azimuth + azimuthIncrement), light, overlay, r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawVertex(Matrix4f model, VertexConsumer vertexWriter, Vector4f position, int light, int overlay, float r, float g, float b, float a) {
|
private static void drawVertex(Matrix4f model, VertexConsumer vertexWriter, Vector4f position, int light, int overlay, float r, float g, float b, float a) {
|
||||||
|
@ -52,11 +53,14 @@ public class SphereModel {
|
||||||
vertexWriter.vertex(position.getX(), position.getY(), position.getZ(), r, g, b, a, 0, 0, overlay, light, 0, 0, 0);
|
vertexWriter.vertex(position.getX(), position.getY(), position.getZ(), r, g, b, a, 0, 0, overlay, light, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector4f convertToCartesianCoord(double r, double theta, double phi) {
|
public static Vector4f convertToCartesianCoord(Vector4f output, double r, double theta, double phi) {
|
||||||
double x = r * Math.sin(theta) * Math.cos(phi);
|
double st = Math.sin(theta);
|
||||||
double y = r * Math.sin(theta) * Math.sin(phi);
|
output.set(
|
||||||
double z = r * Math.cos(theta);
|
(float)(r * st * Math.cos(phi)),
|
||||||
|
(float)(r * st * Math.sin(phi)),
|
||||||
return new Vector4f((float)x, (float)y, (float)z, 1);
|
(float)(r * Math.cos(theta)),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue