Fixed tooltip not rendering for the last legend block

This commit is contained in:
Sollace 2023-07-10 19:29:10 +01:00
parent d6f8df66e8
commit 8d24807ae0
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -1,6 +1,8 @@
package com.minelittlepony.client.hdskins;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.VertexConsumerProvider.Immediate;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
@ -8,8 +10,7 @@ import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.api.pony.*;
import com.minelittlepony.api.pony.meta.TriggerPixel;
import com.minelittlepony.api.pony.meta.Wearable;
import com.minelittlepony.api.pony.meta.*;
import com.minelittlepony.client.render.entity.SeaponyRenderer;
import com.minelittlepony.common.client.gui.dimension.Bounds;
import com.minelittlepony.hdskins.client.dummy.*;
@ -23,6 +24,8 @@ import java.util.function.Consumer;
import java.util.stream.Collectors;
class PonyPreview extends PlayerPreview {
private static final Bounds LEGEND_BLOCK_BOUNDS = new Bounds(0, 0, 10, 10);
@Override
protected DummyPlayer createEntity(ClientWorld world, PlayerSkins<?> textures) {
return new DummyPony(world, textures);
@ -58,39 +61,30 @@ class PonyPreview extends PlayerPreview {
IPonyData data = IPony.getManager().getPony(p).metadata();
int[] index = new int[1];
data.getTriggerPixels().forEach((key, value) -> {
drawLegendBlock(context, index[0]++, frame.left, frame.top, mouseX, mouseY, key, value);
context.getMatrices().push();
int i = index[0]++;
int x = frame.left;
int y = frame.top + (i * 10 + 20);
context.getMatrices().translate(x, y, 1);
drawLegendBlock(context, 0, 0, 0, mouseX - x, mouseY - y, key, value);
context.getMatrices().pop();
});
MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers().draw();
});
}
private void drawLegendBlock(DrawContext context, int index, int x, int y, int mouseX, int mouseY, String key, TriggerPixelType<?> value) {
int size = 10;
int yPos = y + index * size + 20;
context.fill(
x, yPos,
x + size, yPos + size,
0xFF003333
);
context.fill(
x + 1, yPos + 1,
x - 1 + size, yPos - 1 + size,
value.getColorCode() | 0xFF000000
);
context.fill(0, 0, LEGEND_BLOCK_BOUNDS.width, LEGEND_BLOCK_BOUNDS.height, 0xFF003333);
context.fill(1, 1, LEGEND_BLOCK_BOUNDS.width - 1, LEGEND_BLOCK_BOUNDS.height - 1, value.getColorCode() | 0xFF000000);
char symbol = value.name().charAt(0);
if (symbol == '[') {
symbol = key.charAt(0);
}
context.drawTextWithShadow(getFont(),
Text.of(String.valueOf(symbol).toUpperCase()),
x + 2,
yPos + 1,
0xFFFFFFFF
);
if (mouseX > x && mouseX < (x + size) && mouseY > yPos && mouseY < (yPos + size)) {
context.drawTextWithShadow(getFont(), Text.literal(String.valueOf(symbol).toUpperCase()), 2, 1, 0xFFFFFFFF);
if (LEGEND_BLOCK_BOUNDS.contains(mouseX, mouseY)) {
List<Text> lines = value.getOptions().stream().map(option -> {
boolean selected = value.matches(option);
return Text.literal((selected ? "* " : " ") + option.name()).styled(s -> {
@ -106,8 +100,7 @@ class PonyPreview extends PlayerPreview {
return color == 0 ? s : s.withColor(value.getColorCode());
}));
}
context.drawTooltip(getFont(), lines, mouseX, mouseY);
context.drawTooltip(getFont(), lines, 2, 10);
}
}
}