Skip to content

Commit

Permalink
Refactoring of player drawing in atlas gui
Browse files Browse the repository at this point in the history
  • Loading branch information
tyra314 committed Sep 14, 2022
1 parent 56e9341 commit 7a7eb96
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public boolean isEnabled() {
if (hasShiftDown()) {
markerFinalizer.setMarkerData(player.getEntityWorld(),
getAtlasID(),
(int) player.getX(), (int) player.getZ());
player.getBlockX(), player.getBlockZ());
addChild(markerFinalizer);

blinkingIcon.setTexture(markerFinalizer.selectedType.getTexture(),
Expand Down Expand Up @@ -493,9 +493,9 @@ public void init() {

public void updateBookmarkerList() {
markers.removeAllContent();
markers.scrollTo(0,0);
markers.scrollTo(0, 0);

if(localMarkersData == null) return;
if (localMarkersData == null) return;


int contentY = 0;
Expand All @@ -506,12 +506,11 @@ public void updateBookmarkerList() {
GuiMarkerBookmark bookmark = new GuiMarkerBookmark(marker);

bookmark.addListener(button -> {
if(state.is(NORMAL)) {
if (state.is(NORMAL)) {
setTargetPosition(marker.getX(), marker.getZ());
followPlayer = false;
btnPosition.setEnabled(true);
}
else if(state.is(DELETING_MARKER)) {
} else if (state.is(DELETING_MARKER)) {
AtlasClientAPI.getMarkerAPI().deleteMarker(player.getEntityWorld(),
getAtlasID(), marker.getId());
player.getEntityWorld().playSound(player, player.getBlockPos(),
Expand Down Expand Up @@ -761,7 +760,7 @@ public void tick() {
super.tick();
if (player == null) return;
if (followPlayer) {
setMapPosition((int)player.getX(), (int)player.getZ());
setMapPosition(player.getBlockX(), player.getBlockZ());
}
if (player.getEntityWorld().getTime() > timeButtonPressed + BUTTON_PAUSE) {
navigateByButton(selectedButton);
Expand Down Expand Up @@ -847,11 +846,11 @@ private void setTargetPosition(int x, int z) {
}

private int getTargetPositionX() {
return (int)(-targetOffsetX * mapScale);
return (int) (-targetOffsetX * mapScale);
}

private int getTargetPositionY() {
return (int)(-targetOffsetY * mapScale);
return (int) (-targetOffsetY * mapScale);
}


Expand Down Expand Up @@ -952,7 +951,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float par3) {
matrices.push();
matrices.translate(mapStartScreenX, mapStartScreenY, 0);

for(SubTileQuartet subtiles : tiles) {
for (SubTileQuartet subtiles : tiles) {
for (SubTile subtile : subtiles) {
if (subtile == null || subtile.tile == null) continue;
ITexture texture = TileTextureMap.instance().getTexture(subtile);
Expand Down Expand Up @@ -1023,10 +1022,10 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float par3) {
} else {
String texture_set = TileTextureMap.instance().getTextureSet(tile).name.toString();
drawTooltip(Arrays.asList(
new LiteralText(coords),
new LiteralText(chunks),
new LiteralText("Tile: " + tile.toString()),
new LiteralText("TSet: " + texture_set)),
new LiteralText(coords),
new LiteralText(chunks),
new LiteralText("Tile: " + tile),
new LiteralText("TSet: " + texture_set)),
textRenderer);
}
}
Expand All @@ -1039,24 +1038,17 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float par3) {
}

private void renderPlayer(MatrixStack matrices, double iconScale) {
// How much the player has moved from the top left corner of the map, in pixels:
int playerOffsetX = (int) (player.getX() * mapScale) + mapOffsetX;
int playerOffsetZ = (int) (player.getZ() * mapScale) + mapOffsetY;
playerOffsetX = MathHelper.clamp(playerOffsetX, -MAP_WIDTH / 2, MAP_WIDTH / 2);
playerOffsetZ = MathHelper.clamp(playerOffsetZ, -MAP_HEIGHT / 2, MAP_HEIGHT / 2 - 2);
int playerOffsetX = worldXToScreenX(player.getBlockX());
int playerOffsetY = worldZToScreenY(player.getBlockZ());

playerOffsetX = MathHelper.clamp(playerOffsetX, getGuiX() + MAP_BORDER_WIDTH, getGuiX() + MAP_WIDTH + MAP_BORDER_WIDTH);
playerOffsetY = MathHelper.clamp(playerOffsetY, getGuiY() + MAP_BORDER_HEIGHT, getGuiY() + MAP_HEIGHT + MAP_BORDER_HEIGHT);

// Draw the icon:
RenderSystem.setShaderColor(1, 1, 1, state.is(PLACING_MARKER) ? 0.5f : 1);
matrices.push();

matrices.translate(getGuiX() + WIDTH / 2 + playerOffsetX, getGuiY() + HEIGHT / 2 + playerOffsetZ, 0);
float playerRotation = (float) Math.round(player.getYaw() / 360f * PLAYER_ROTATION_STEPS) / PLAYER_ROTATION_STEPS * 360f;
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(180 + playerRotation));
matrices.translate((float) (-PLAYER_ICON_WIDTH / 2 * iconScale), (float) (-PLAYER_ICON_HEIGHT / 2 * iconScale), 0f);

Textures.PLAYER.draw(matrices, 0, 0, (int) Math.round(PLAYER_ICON_WIDTH * iconScale), (int) Math.round(PLAYER_ICON_HEIGHT * iconScale));

matrices.pop();
Textures.PLAYER.drawCenteredWithRotation(matrices, playerOffsetX, playerOffsetY, (int) Math.round(PLAYER_ICON_WIDTH * iconScale), (int) Math.round(PLAYER_ICON_HEIGHT * iconScale), playerRotation);

RenderSystem.setShaderColor(1, 1, 1, 1);
}
Expand Down Expand Up @@ -1174,8 +1166,8 @@ private void renderMarker(MatrixStack matrices, Marker marker, double scale) {
info.scale(0.8);
}

markerX = MathHelper.clamp(markerX, getGuiX() + MAP_BORDER_WIDTH, getGuiX() + MAP_WIDTH + MAP_BORDER_WIDTH);
markerY = MathHelper.clamp(markerY, getGuiY() + MAP_BORDER_HEIGHT, getGuiY() + MAP_HEIGHT + MAP_BORDER_HEIGHT);
markerX = MathHelper.clamp(markerX, getGuiX() + MAP_BORDER_WIDTH, getGuiX() + MAP_WIDTH + MAP_BORDER_WIDTH);
markerY = MathHelper.clamp(markerY, getGuiY() + MAP_BORDER_HEIGHT, getGuiY() + MAP_HEIGHT + MAP_BORDER_HEIGHT);


info.tex.draw(matrices, markerX + info.x, markerY + info.y, info.width, info.height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3f;

/**
* An abstract base class, which implements the ITexture interface using
Expand Down Expand Up @@ -38,7 +38,6 @@ public Identifier getTexture() {
}

public void bind() {
// MinecraftClient.getInstance().getTextureManager().bindTexture(this.texture);
RenderSystem.setShaderTexture(0, texture);
}

Expand All @@ -61,6 +60,17 @@ public void draw(MatrixStack matrices, int x, int y, int width, int height, int
DrawableHelper.drawTexture(matrices, x, y, width, height, u, v, regionWidth, regionHeight, this.width(), this.height());
}

public void drawCenteredWithRotation(MatrixStack matrices, int x, int y, int width, int height, float rotation) {
matrices.push();
matrices.translate(x, y, 0);
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(180 + rotation));
matrices.translate(-width / 2f, -height / 2f, 0f);

draw(matrices, 0,0, width, height);

matrices.pop();
}

public void drawWithLight(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int light) {
drawWithLight(consumer, matrices, x, y, width, height, 0, 0, this.width(), this.height(), light);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface ITexture {

void draw(MatrixStack matrices, int x, int y, int width, int height);

void drawCenteredWithRotation(MatrixStack matrices, int x, int y, int width, int height, float rotation);

void draw(MatrixStack matrices, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight);

void draw(MatrixStack matrices, int x, int y, int u, int v, int regionWidth, int regionHeight);
Expand Down

0 comments on commit 7a7eb96

Please sign in to comment.