Skip to content

Commit

Permalink
Make it possible to switch single sided / double sided which closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ustc-zzzz committed Dec 17, 2020
1 parent 7520dda commit 064cc39
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 103 deletions.
24 changes: 24 additions & 0 deletions src/main/java/org/teacon/slides/network/SlideData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public final class SlideData implements INBTSerializable<CompoundNBT> {
private int imgColor;
private Vector2f imgSize;
private Vector3f imgOffset;
private boolean backVisibility;
private boolean frontVisibility;

public SlideData() {
this.url = "";
Expand Down Expand Up @@ -62,6 +64,24 @@ public SlideData setOffset(Vector3f offset) {
return this;
}

public boolean isBackVisible() {
return this.backVisibility;
}

public SlideData setBackVisible(boolean visible) {
this.backVisibility = visible;
return this;
}

public boolean isFrontVisible() {
return this.frontVisibility;
}

public SlideData setFrontVisible(boolean visible) {
this.frontVisibility = visible;
return this;
}

@Override
public CompoundNBT serializeNBT() {
CompoundNBT nbt = new CompoundNBT();
Expand All @@ -72,6 +92,8 @@ public CompoundNBT serializeNBT() {
nbt.putFloat("OffsetX", this.imgOffset.getX());
nbt.putFloat("OffsetY", this.imgOffset.getY());
nbt.putFloat("OffsetZ", this.imgOffset.getZ());
nbt.putBoolean("BackInvisible", !this.backVisibility);
nbt.putBoolean("FrontInvisible", !this.frontVisibility);
return nbt;
}

Expand All @@ -81,5 +103,7 @@ public void deserializeNBT(CompoundNBT nbt) {
this.imgColor = nbt.getInt("Color");
this.imgSize = new Vector2f(nbt.getFloat("Width"), nbt.getFloat("Height"));
this.imgOffset = new Vector3f(nbt.getFloat("OffsetX"), nbt.getFloat("OffsetY"), nbt.getFloat("OffsetZ"));
this.backVisibility = !nbt.getBoolean("BackInvisible");
this.frontVisibility = !nbt.getBoolean("FrontInvisible");
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/teacon/slides/projector/ProjectorBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public InternalRotation invert() {
return InternalRotation.values()[INV_ORDINALS[this.ordinal()]];
}

public boolean isFlipped() {
return this.ordinal() >= 4;
}

public Matrix4f getTransformation() {
return this.transformation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public final class ProjectorControlScreen extends ContainerScreen<ProjectorContr
private TextFieldWidget offsetYInput;
private TextFieldWidget offsetZInput;

private Button switchSingleSided;
private Button switchDoubleSided;

private String url = "";
private boolean isDoubleSided;
private int imgColor = 0x00000000;
private Vector2f imgSize = Vector2f.ONE;
private Vector3f imgOffset = new Vector3f();
Expand Down Expand Up @@ -80,7 +84,7 @@ protected void init() {
this.children.add(this.urlInput);

// color input
this.colorInput = new TextFieldWidget(this.font, this.guiLeft + 38, this.guiTop + 155, 56, 16, new TranslationTextComponent("gui.slide_show.color"));
this.colorInput = new TextFieldWidget(this.font, this.guiLeft + 55, this.guiTop + 155, 56, 16, new TranslationTextComponent("gui.slide_show.color"));
this.colorInput.setMaxStringLength(8);
this.colorInput.setResponder(input -> {
try {
Expand Down Expand Up @@ -210,6 +214,21 @@ protected void init() {
this.rotation = newRotation;
}));
this.rotation = this.container.rotation;

// single sided / double sided
this.switchSingleSided = this.addButton(new Button(this.guiLeft + 9, this.guiTop + 153, 179, 113, 18, 19, new TranslationTextComponent("gui.slide_show.single_double_sided"), () -> {
this.isDoubleSided = false;
this.switchDoubleSided.visible = true;
this.switchSingleSided.visible = false;
}));
this.switchDoubleSided = this.addButton(new Button(this.guiLeft + 9, this.guiTop + 153, 179, 133, 18, 19, new TranslationTextComponent("gui.slide_show.single_double_sided"), () -> {
this.isDoubleSided = true;
this.switchSingleSided.visible = true;
this.switchDoubleSided.visible = false;
}));
this.isDoubleSided = this.rotation.isFlipped() ? this.container.currentSlide.isBackVisible() : this.container.currentSlide.isFrontVisible();
this.switchDoubleSided.visible = !this.isDoubleSided;
this.switchSingleSided.visible = this.isDoubleSided;
}

@Override
Expand All @@ -235,7 +254,9 @@ public void onClose() {
.setImageLocation(this.invalidURL ? oldData.getImageLocation() : this.url)
.setColor(this.invalidColor ? oldData.getColor() : this.imgColor)
.setSize(invalidSize ? oldData.getSize() : this.imgSize)
.setOffset(invalidOffset ? oldData.getOffset() : this.imgOffset);
.setOffset(invalidOffset ? oldData.getOffset() : this.imgOffset)
.setFrontVisible(this.isDoubleSided || this.rotation.isFlipped())
.setBackVisible(this.isDoubleSided || !this.rotation.isFlipped());
packet.rotation = this.rotation;
SlideShow.channel.sendToServer(packet);
super.onClose();
Expand Down Expand Up @@ -279,7 +300,7 @@ protected void renderHoveredTooltip(MatrixStack stack, int mouseX, int mouseY) {
if (offsetX >= 9 && offsetY >= 27 && offsetX < 27 && offsetY < 46) {
this.renderTooltip(stack, new TranslationTextComponent("gui.slide_show.url"), mouseX, mouseY);
}
if (offsetX >= 17 && offsetY >= 153 && offsetX < 35 && offsetY < 172) {
if (offsetX >= 34 && offsetY >= 153 && offsetX < 52 && offsetY < 172) {
this.renderTooltip(stack, new TranslationTextComponent("gui.slide_show.color"), mouseX, mouseY);
}
if (offsetX >= 9 && offsetY >= 49 && offsetX < 27 && offsetY < 68) {
Expand All @@ -303,6 +324,9 @@ protected void renderHoveredTooltip(MatrixStack stack, int mouseX, int mouseY) {
if (offsetX >= 142 && offsetY >= 153 && offsetX < 160 && offsetY < 172) {
this.renderTooltip(stack, new TranslationTextComponent("gui.slide_show.rotate"), mouseX, mouseY);
}
if (offsetX >= 9 && offsetY >= 153 && offsetX < 27 && offsetY < 172) {
this.renderTooltip(stack, new TranslationTextComponent("gui.slide_show.single_double_sided"), mouseX, mouseY);
}
}

@Override
Expand All @@ -325,7 +349,7 @@ protected void drawGuiContainerForegroundLayer(MatrixStack stack, int mouseX, in
int red = (this.imgColor >>> 16) & 255, green = (this.imgColor >>> 8) & 255, blue = this.imgColor & 255;
Objects.requireNonNull(this.minecraft).getTextureManager().bindTexture(GUI_TEXTURE);
RenderSystem.color4f(red / 255.0F, green / 255.0F, blue / 255.0F, alpha / 255.0F);
this.blit(stack, 21, 157, 180, 194, 10, 10);
this.blit(stack, 38, 157, 180, 194, 10, 10);
this.blit(stack, 82, 185, 180, 194, 17, 17);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public void render(ProjectorTileEntity tile, float partialTicks, MatrixStack mat
final Matrix4f transformation = matrixStack.getLast().getMatrix();
final float width = tile.currentSlide.getSize().x, height = tile.currentSlide.getSize().y;
final SlideRenderEntry entry = SlideRenderData.getEntry(tile.currentSlide.getImageLocation());
final boolean renderFront = tile.currentSlide.isFrontVisible(), renderBack = tile.currentSlide.isBackVisible();

transformation.mul(tile.getTransformation());
entry.render(buffer, transformation, width, height, tile.currentSlide.getColor(), combinedLight);
entry.render(buffer, transformation, width, height, tile.currentSlide.getColor(), combinedLight, renderFront, renderBack);

matrixStack.pop();
}
Expand Down
Loading

0 comments on commit 064cc39

Please sign in to comment.