Skip to content

Commit

Permalink
Proof of concept of pose sliders working
Browse files Browse the repository at this point in the history
  • Loading branch information
Roundaround committed Feb 21, 2023
1 parent 35b4cfc commit 65a45ab
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import me.roundaround.armorstands.network.EulerAngleParameter;
import me.roundaround.armorstands.network.PosePart;
import me.roundaround.armorstands.screen.ArmorStandScreenHandler;
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.text.Text;

Expand All @@ -15,10 +17,15 @@ public class ArmorStandPoseScreen
public static final Text TITLE = Text.translatable("armorstands.screen.pose");
public static final int U_INDEX = 3;

private static final int CONTROL_WIDTH = 100;
private static final int CONTROL_HEIGHT = 16;
private static final int SCREEN_EDGE_PAD = 4;
private static final int BETWEEN_PAD = 2;

private AdjustPoseSliderWidget headYawSlider;
private CyclingButtonWidget<PosePart> posePartButton;
private AdjustPoseSliderWidget pitchSlider;
private AdjustPoseSliderWidget yawSlider;
private AdjustPoseSliderWidget rollSlider;

public ArmorStandPoseScreen(
ArmorStandScreenHandler handler,
Expand Down Expand Up @@ -63,14 +70,57 @@ public void init() {
ArmorStandInventoryScreen.U_INDEX,
ArmorStandInventoryScreen::new)));

this.headYawSlider = new AdjustPoseSliderWidget(
this.width - SCREEN_EDGE_PAD - 100,
this.height - SCREEN_EDGE_PAD - 20,
100,
20,
PosePart.HEAD,
this.posePartButton = CyclingButtonWidget.builder(PosePart::getDisplayName)
.values(PosePart.values())
.initially(PosePart.HEAD)
.build(
this.width - SCREEN_EDGE_PAD - CONTROL_WIDTH,
this.height - SCREEN_EDGE_PAD - 4 * CONTROL_HEIGHT - 3 * BETWEEN_PAD,
CONTROL_WIDTH,
CONTROL_HEIGHT,
Text.empty(),
(button, posePart) -> {
this.yawSlider.setPart(posePart);
this.pitchSlider.setPart(posePart);
this.rollSlider.setPart(posePart);
});
addSelectableChild(this.posePartButton);

this.pitchSlider = new AdjustPoseSliderWidget(
this.width - SCREEN_EDGE_PAD - CONTROL_WIDTH,
this.height - SCREEN_EDGE_PAD - 3 * CONTROL_HEIGHT - 2 * BETWEEN_PAD,
CONTROL_WIDTH,
CONTROL_HEIGHT,
this.posePartButton.getValue(),
EulerAngleParameter.PITCH,
this.armorStand);
addDrawableChild(this.pitchSlider);

this.yawSlider = new AdjustPoseSliderWidget(
this.width - SCREEN_EDGE_PAD - CONTROL_WIDTH,
this.height - SCREEN_EDGE_PAD - 2 * CONTROL_HEIGHT - BETWEEN_PAD,
CONTROL_WIDTH,
CONTROL_HEIGHT,
this.posePartButton.getValue(),
EulerAngleParameter.YAW,
this.armorStand);
addDrawableChild(this.headYawSlider);
addDrawableChild(this.yawSlider);

this.rollSlider = new AdjustPoseSliderWidget(
this.width - SCREEN_EDGE_PAD - CONTROL_WIDTH,
this.height - SCREEN_EDGE_PAD - CONTROL_HEIGHT,
CONTROL_WIDTH,
CONTROL_HEIGHT,
this.posePartButton.getValue(),
EulerAngleParameter.ROLL,
this.armorStand);
addDrawableChild(this.rollSlider);
}

@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
super.render(matrixStack, mouseX, mouseY, partialTicks);

this.posePartButton.render(matrixStack, mouseX, mouseY, partialTicks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.roundaround.armorstands.client.gui.widget.PresetPosesListWidget;
import me.roundaround.armorstands.client.util.LastUsedScreen.ScreenType;
import me.roundaround.armorstands.network.ArmorStandFlag;
import me.roundaround.armorstands.network.PosePart;
import me.roundaround.armorstands.screen.ArmorStandScreenHandler;
import me.roundaround.armorstands.util.PosePreset;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
Expand Down Expand Up @@ -53,6 +54,10 @@ public ArmorStandPresetsScreen(
flag.setValue(this.previewStand, flag.getValue(this.armorStand));
}

for (PosePart part : PosePart.values()) {
part.set(this.previewStand, part.get(this.armorStand));
}

setEquipmentType(Equipment.ACTUAL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void setParameter(EulerAngleParameter parameter) {
@Override
protected void updateMessage() {
setMessage(Text.translatable(
"armorstands.adjustpose.label",
getAngle()));
"armorstands.adjustPose.label",
String.format("%.2f", getAngle())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Arrays;

import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.EulerAngle;

public enum PosePart {
Expand All @@ -24,6 +25,10 @@ public String toString() {
return id;
}

public Text getDisplayName() {
return Text.translatable("armorstands.part." + id);
}

public EulerAngle get(ArmorStandEntity armorStand) {
switch (this) {
case HEAD:
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/assets/armorstands/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,12 @@
"armorstands.preset.cupid": "Cupid",
"armorstands.preset.stargazing": "Stargazing",
"armorstands.preset.block": "* Block",
"armorstands.preset.item": "* Item"
"armorstands.preset.item": "* Item",
"armorstands.part.head": "Head",
"armorstands.part.body": "Body",
"armorstands.part.rightArm": "Right arm",
"armorstands.part.leftArm": "Left arm",
"armorstands.part.rightLeg": "Right leg",
"armorstands.part.leftLeg": "Left leg",
"armorstands.adjustPose.label": "%s°"
}

0 comments on commit 65a45ab

Please sign in to comment.