Skip to content

Commit

Permalink
Update sizeSlider to sizeField
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrbysco committed Sep 1, 2024
1 parent ec342b9 commit 369955e
Showing 1 changed file with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class ArmorStandScreen extends Screen {
private NumberFieldBox rotationTextField;
private final ToggleButton[] toggleButtons = new ToggleButton[6];
protected final NumberFieldBox[] poseTextFields = new NumberFieldBox[3 * 7];
private SizeField sizeSlider;
private SizeField sizeField;
private LockIconButton lockButton;
private final boolean allowScrolling;

Expand Down Expand Up @@ -130,15 +130,15 @@ public void init() {
this.rotationTextField.setTooltip(Tooltip.create(Component.translatable("armorposer.gui.tooltip.rotation")));

// Size slider
this.sizeSlider = new SizeField(this.font, 1 + offsetX, offsetY + ((this.toggleButtons.length + 1) * 22), 38, 17, Component.translatable("armorposer.gui.label.scale"));
this.sizeField = new SizeField(this.font, 1 + offsetX, offsetY + ((this.toggleButtons.length + 1) * 22), 38, 17, Component.translatable("armorposer.gui.label.scale"));
// (double) this.entityArmorStand.getScale(), 0.01D, 10.0D, this)
this.sizeSlider.setValue(String.valueOf((double) this.entityArmorStand.getScale()));
this.sizeSlider.setMaxLength(4);
this.addWidget(this.sizeSlider);
this.sizeSlider.setTooltip(Tooltip.create(Component.translatable("armorposer.gui.tooltip.scale")));
this.sizeField.setValue(String.valueOf((double) this.entityArmorStand.getScale()));
this.sizeField.setMaxLength(4);
this.addWidget(this.sizeField);
this.sizeField.setTooltip(Tooltip.create(Component.translatable("armorposer.gui.tooltip.scale")));
if (minecraft != null && !Reference.canResize(minecraft.player)) {
this.sizeSlider.active = false;
this.sizeSlider.setTooltip(Tooltip.create(Component.translatable("armorposer.gui.tooltip.size.disabled").withStyle(ChatFormatting.RED)));
this.sizeField.active = false;
this.sizeField.setTooltip(Tooltip.create(Component.translatable("armorposer.gui.tooltip.size.disabled").withStyle(ChatFormatting.RED)));
}

// pose textboxes
Expand Down Expand Up @@ -198,7 +198,7 @@ public void init() {
if (clipboardData != null) {
CompoundTag compound = TagParser.parseTag(clipboardData);
this.readFieldsFromNBT(compound);
this.updateEntity(compound);
this.textFieldUpdated();
}
} catch (Exception e) {
//Nope
Expand Down Expand Up @@ -568,7 +568,7 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
this.rotationTextField.render(guiGraphics, mouseX, mouseY, partialTicks);
for (EditBox textField : this.poseTextFields)
textField.render(guiGraphics, mouseX, mouseY, partialTicks);
this.sizeSlider.render(guiGraphics, mouseX, mouseY, partialTicks);
this.sizeField.render(guiGraphics, mouseX, mouseY, partialTicks);

int offsetY = 20;

Expand Down Expand Up @@ -648,12 +648,12 @@ public boolean mouseScrolled(double mouseX, double mouseY, double xScroll, doubl
this.textFieldUpdated();
return true;
}
if (sizeSlider.canConsumeInput()) {
float nextValue = (float)(sizeSlider.getFloat() + (double)(multiplier * sizeSlider.scrollMultiplier));
nextValue = Math.clamp(nextValue, sizeSlider.minValue, sizeSlider.maxValue);
sizeSlider.setValue(String.valueOf(nextValue));
sizeSlider.setCursorPosition(0);
sizeSlider.setHighlightPos(0);
if (sizeField.canConsumeInput()) {
float nextValue = (float)(sizeField.getFloat() + (double)(multiplier * sizeField.scrollMultiplier));
nextValue = Math.clamp(nextValue, sizeField.minValue, sizeField.maxValue);
sizeField.setValue(String.valueOf(nextValue));
sizeField.setCursorPosition(0);
sizeField.setHighlightPos(0);
this.textFieldUpdated();
return true;
}
Expand All @@ -677,12 +677,12 @@ public boolean mouseScrolled(double mouseX, double mouseY, double xScroll, doubl
this.textFieldUpdated();
return true;
}
if (sizeSlider.canConsumeInput()) {
float previousValue = (float)(sizeSlider.getFloat() - (double)(multiplier * sizeSlider.scrollMultiplier));
previousValue = Math.clamp(previousValue, sizeSlider.minValue, sizeSlider.maxValue);
sizeSlider.setValue(String.valueOf(previousValue));
sizeSlider.setCursorPosition(0);
sizeSlider.setHighlightPos(0);
if (sizeField.canConsumeInput()) {
float previousValue = (float)(sizeField.getFloat() - (double)(multiplier * sizeField.scrollMultiplier));
previousValue = Math.clamp(previousValue, sizeField.minValue, sizeField.maxValue);
sizeField.setValue(String.valueOf(previousValue));
sizeField.setCursorPosition(0);
sizeField.setHighlightPos(0);
this.textFieldUpdated();
return true;
}
Expand Down Expand Up @@ -719,7 +719,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (this.rotationTextField.keyPressed(keyCode, scanCode, modifiers)) {
this.textFieldUpdated();
return true;
} else if (this.sizeSlider.keyPressed(keyCode, scanCode, modifiers)) {
} else if (this.sizeField.keyPressed(keyCode, scanCode, modifiers)) {
this.textFieldUpdated();
return true;
} else {
Expand All @@ -739,13 +739,6 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
return super.mouseClicked(mouseX, mouseY, button);
}

/**
* Update the size of the armor stand
*/
public void updateScale() {
this.textFieldUpdated();
}

protected void textFieldUpdated() {
this.updateEntity(this.writeFieldsToNBT());
}
Expand All @@ -760,7 +753,7 @@ protected CompoundTag writeFieldsToNBT() {
compound.putBoolean("CustomNameVisible", this.toggleButtons[5].getValue());
compound.putBoolean("Invulnerable", this.lockButton.isLocked());
compound.putInt("DisabledSlots", this.lockButton.isLocked() ? 4144959 : 0);
compound.putDouble("Scale", this.sizeSlider.getFloat());
compound.putDouble("Scale", this.sizeField.getFloat());

ListTag rotationTag = new ListTag();
rotationTag.add(FloatTag.valueOf(this.rotationTextField.getFloat()));
Expand Down

0 comments on commit 369955e

Please sign in to comment.