Add tooltip for the race icon on the profile and add the equipped spells

This commit is contained in:
Sollace 2022-09-15 21:50:15 +02:00
parent 5b0500a65d
commit 25d9ebba17
3 changed files with 124 additions and 9 deletions

View file

@ -0,0 +1,69 @@
package com.minelittlepony.unicopia.client.gui.spellbook;
import java.util.List;
import com.minelittlepony.common.client.gui.element.Button;
import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Vector4f;
public class EquippedSpellSlot extends Button {
protected final ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
private final CustomisedSpellType<?> spell;
public EquippedSpellSlot(int x, int y, CustomisedSpellType<?> spell) {
super(x, y, 16, 16);
this.spell = spell;
getStyle().setTooltip(() -> {
if (spell.isEmpty()) {
return List.of();
}
return spell.getDefaultStack().getTooltip(MinecraftClient.getInstance().player, TooltipContext.Default.NORMAL);
});
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float tickDelta) {
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.setShaderTexture(0, SpellbookScreen.SLOT);
RenderSystem.enableBlend();
drawTexture(matrices, x - 8, y - 8, 0, 0, 32, 32, 32, 32);
Vector4f pos = new Vector4f(x, y, 0, 1);
pos.transform(matrices.peek().getPositionMatrix());
if (spell.isEmpty()) {
RenderSystem.setShaderColor(1, 1, 1, 0.3F);
RenderSystem.setShaderTexture(0, SpellbookScreen.GEM);
drawTexture(matrices, x, y, 0, 0, 16, 16, 16, 16);
RenderSystem.disableBlend();
RenderSystem.setShaderColor(1, 1, 1, 1);
} else {
RenderSystem.disableBlend();
RenderSystem.setShaderColor(1, 1, 1, 1);
drawItem((int)pos.getX(), (int)pos.getY());
}
if (isHovered()) {
HandledScreen.drawSlotHighlight(matrices, x, y, 0);
this.onPress();
}
}
protected void drawItem(int x, int y) {
itemRenderer.renderInGui(spell.getDefaultStack(), x, y);
}
@Override
public void playDownSound(SoundManager soundManager) {
}
}

View file

@ -0,0 +1,21 @@
package com.minelittlepony.unicopia.client.gui.spellbook;
import java.util.List;
import com.minelittlepony.common.client.gui.Tooltip;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.text.Text;
public class ProfileTooltip {
public static Tooltip get(Pony pony) {
return () -> {
return List.of(
Text.literal(String.format("Level %d ", pony.getLevel().get() + 1)).append(pony.getSpecies().getDisplayName()).formatted(pony.getSpecies().getAffinity().getColor()),
Text.literal(String.format("Mana: %d%%", (int)(pony.getMagicalReserves().getMana().getPercentFill() * 100))),
Text.literal(String.format("Experience: %d", (int)(pony.getMagicalReserves().getXp().getPercentFill() * 100))),
Text.literal(String.format("Next level in: %d experience points", 100 - (int)(pony.getMagicalReserves().getXp().getPercentFill() * 100)))
);
};
}
}

View file

@ -2,10 +2,11 @@ package com.minelittlepony.unicopia.client.gui.spellbook;
import com.minelittlepony.common.client.gui.IViewRoot;
import com.minelittlepony.common.client.gui.dimension.Bounds;
import com.minelittlepony.common.client.gui.sprite.TextureSprite;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.client.gui.DrawableUtil;
import com.minelittlepony.unicopia.client.gui.*;
import com.minelittlepony.unicopia.entity.player.*;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
@ -13,6 +14,7 @@ import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
@ -30,6 +32,36 @@ public class SpellbookProfilePageContent extends DrawableHelper implements Spell
@Override
public void init(SpellbookScreen screen, Identifier pageId) {
Bounds bounds = screen.getFrameBounds();
Race race = pony.getSpecies();
int size = 32;
int textureSize = 512;
int ordinal = Race.REGISTRY.getRawId(race);
int x = screen.getX() + bounds.left + bounds.width / 4 - size + 10;
int y = screen.getY() + bounds.top + bounds.height / 2;
screen.addDrawable(new SpellbookScreen.ImageButton(x, y, size, size))
.getStyle()
.setIcon(new TextureSprite()
.setPosition(0, 0)
.setSize(size, size)
.setTextureSize(textureSize, textureSize)
.setTexture(Unicopia.id("textures/gui/icons.png"))
.setTextureOffset((size * ordinal) % textureSize, (ordinal / textureSize) * size)
)
.setTooltip(ProfileTooltip.get(pony));
float mainAngle = 90 * MathHelper.RADIANS_PER_DEGREE;
float offAngle = 60 * MathHelper.RADIANS_PER_DEGREE;
int radius = 75;
x += size / 4;
y += size / 3;
screen.addDrawable(new EquippedSpellSlot(x + (int)(Math.sin(mainAngle) * radius), y + (int)(Math.cos(mainAngle) * radius), pony.getCharms().getEquippedSpell(Hand.MAIN_HAND)));
screen.addDrawable(new EquippedSpellSlot(x + (int)(Math.sin(offAngle) * radius), y + (int)(Math.cos(offAngle) * radius), pony.getCharms().getEquippedSpell(Hand.OFF_HAND)));
}
@Override
@ -85,13 +117,6 @@ public class SpellbookProfilePageContent extends DrawableHelper implements Spell
font.draw(matrices, "Mana", -font.getWidth("Mana") / 2, y, SpellbookScreen.TITLE_COLOR);
font.draw(matrices, manaString, -font.getWidth(manaString) / 2, y += font.fontHeight, SpellbookScreen.TITLE_COLOR);
matrices.push();
matrices.scale(1.4F, 1.4F, 1);
RenderSystem.setShaderTexture(0, Unicopia.id("textures/gui/icons.png"));
drawTexture(matrices, -8, -8, 16 * 2, 0, 16, 16, 256, 256);
RenderSystem.setShaderTexture(0, SpellbookScreen.TEXTURE);
matrices.pop();
Text levelString = I18n.hasTranslation("enchantment.level." + (currentLevel + 1)) ? Text.translatable("enchantment.level." + (currentLevel + 1)) : Text.literal(currentLevel >= 999 ? ">999" : "" + (currentLevel + 1));
matrices.translate(-font.getWidth(levelString), -35, 0);