Skip to content

Commit

Permalink
Merge remote-tracking branch 'Cardinalstars/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Jan 4, 2025
2 parents d41f55a + 0d133ad commit 917e494
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.common.util.ForgeDirection;

import com.github.lunatrius.core.client.gui.GuiNumericField;
import com.github.lunatrius.core.client.gui.GuiScreenBase;
import com.github.lunatrius.core.util.vector.Vector3i;
import com.github.lunatrius.schematica.Schematica;
import com.github.lunatrius.schematica.client.gui.util.GuiOrCheckBoxHandler;
import com.github.lunatrius.schematica.client.printer.SchematicPrinter;
import com.github.lunatrius.schematica.client.renderer.RendererSchematicGlobal;
import com.github.lunatrius.schematica.client.world.SchematicWorld;
import com.github.lunatrius.schematica.proxy.ClientProxy;
import com.github.lunatrius.schematica.reference.Constants;
import com.github.lunatrius.schematica.reference.Names;

import cpw.mods.fml.client.config.GuiCheckBox;

public class GuiSchematicControl extends GuiScreenBase {

private final SchematicWorld schematic;
Expand All @@ -38,8 +42,17 @@ public class GuiSchematicControl extends GuiScreenBase {
private GuiButton btnHide = null;
private GuiButton btnMove = null;
private GuiButton btnFlip = null;
private GuiCheckBox btnFlipX = null;
private GuiCheckBox btnFlipY = null;
private GuiCheckBox btnFlipZ = null;
private static int lastCheckedFlip = 0;
private GuiOrCheckBoxHandler flipBoxes;
private GuiButton btnRotate = null;

private GuiCheckBox btnRotateX = null;
private GuiCheckBox btnRotateY = null;
private GuiCheckBox btnRotateZ = null;
private static int lastCheckedRotation = 0;
private GuiOrCheckBoxHandler rotationBoxes;
private GuiButton btnMaterials = null;
private GuiButton btnPrint = null;

Expand Down Expand Up @@ -130,6 +143,14 @@ public void initGui() {
I18n.format(Names.Gui.Control.FLIP));
this.buttonList.add(this.btnFlip);

this.btnFlipX = new GuiCheckBox(id++, this.width - 90 - 60, this.height - 50, "X", false);
this.buttonList.add(this.btnFlipX);
this.btnFlipY = new GuiCheckBox(id++, this.width - 90 - 40, this.height - 50, "Y", false);
this.buttonList.add(this.btnFlipY);
this.btnFlipZ = new GuiCheckBox(id++, this.width - 90 - 20, this.height - 50, "Z", false);
this.buttonList.add(this.btnFlipZ);
flipBoxes = new GuiOrCheckBoxHandler(btnFlipX, btnFlipY, btnFlipZ);

this.btnRotate = new GuiButton(
id++,
this.width - 90,
Expand All @@ -139,6 +160,14 @@ public void initGui() {
I18n.format(Names.Gui.Control.ROTATE));
this.buttonList.add(this.btnRotate);

this.btnRotateX = new GuiCheckBox(id++, this.width - 90 - 60, this.height - 25, "X", false);
this.buttonList.add(this.btnRotateX);
this.btnRotateY = new GuiCheckBox(id++, this.width - 90 - 40, this.height - 25, "Y", false);
this.buttonList.add(this.btnRotateY);
this.btnRotateZ = new GuiCheckBox(id++, this.width - 90 - 20, this.height - 25, "Z", false);
this.buttonList.add(this.btnRotateZ);
rotationBoxes = new GuiOrCheckBoxHandler(btnRotateX, btnRotateY, btnRotateZ);

this.btnMaterials = new GuiButton(id++, 10, this.height - 70, 80, 20, this.strMaterials);
this.buttonList.add(this.btnMaterials);

Expand Down Expand Up @@ -171,8 +200,14 @@ public void initGui() {
this.btnHide.enabled = this.schematic != null;
this.btnMove.enabled = this.schematic != null;

this.btnFlip.enabled = false;
this.btnFlip.enabled = this.schematic != null;
this.btnFlipX.enabled = this.schematic != null;
this.btnFlipY.enabled = this.schematic != null;
this.btnFlipZ.enabled = this.schematic != null;
this.btnRotate.enabled = this.schematic != null;
this.btnRotateX.enabled = this.schematic != null;
this.btnRotateY.enabled = this.schematic != null;
this.btnRotateZ.enabled = this.schematic != null;
this.btnMaterials.enabled = this.schematic != null;
this.btnPrint.enabled = this.schematic != null && this.printer.isEnabled();

Expand All @@ -184,6 +219,8 @@ public void initGui() {

if (this.schematic != null) {
setPoint(this.numericX, this.numericY, this.numericZ, this.schematic.position);
rotationBoxes.checkBox(this.btnRotateX.id + lastCheckedRotation);
flipBoxes.checkBox(this.btnFlipX.id + lastCheckedFlip);
}

this.nfLayer.setMinimum(0);
Expand Down Expand Up @@ -238,13 +275,49 @@ protected void actionPerformed(GuiButton guiButton) {
RendererSchematicGlobal.INSTANCE.refresh();
setPoint(this.numericX, this.numericY, this.numericZ, this.schematic.position);
} else if (guiButton.id == this.btnFlip.id) {
this.schematic.flip();
int checkedBoxId = flipBoxes.getCheckedBoxId();
if (checkedBoxId == btnFlipX.id) {
this.schematic.flip(ForgeDirection.EAST);
} else if (checkedBoxId == btnFlipY.id) {
this.schematic.flip(ForgeDirection.UP);
} else if (checkedBoxId == btnFlipZ.id) {
this.schematic.flip(ForgeDirection.SOUTH);
} else {
throw new RuntimeException("Somehow no check box selected!");
}
RendererSchematicGlobal.INSTANCE.createRendererSchematicChunks(this.schematic);
SchematicPrinter.INSTANCE.refresh();
} else if (guiButton.id == this.btnFlipX.id) {
flipBoxes.checkBox(btnFlipX);
lastCheckedFlip = 0;
} else if (guiButton.id == this.btnFlipY.id) {
flipBoxes.checkBox(btnFlipY);
lastCheckedFlip = 1;
} else if (guiButton.id == this.btnFlipZ.id) {
flipBoxes.checkBox(btnFlipZ);
lastCheckedFlip = 2;
} else if (guiButton.id == this.btnRotate.id) {
this.schematic.rotate();
int checkedBoxId = rotationBoxes.getCheckedBoxId();
if (checkedBoxId == btnRotateX.id) {
this.schematic.rotate(ForgeDirection.EAST);
} else if (checkedBoxId == btnRotateY.id) {
this.schematic.rotate(ForgeDirection.UP);
} else if (checkedBoxId == btnRotateZ.id) {
this.schematic.rotate(ForgeDirection.SOUTH);
} else {
throw new RuntimeException("Somehow no check box selected!");
}
RendererSchematicGlobal.INSTANCE.createRendererSchematicChunks(this.schematic);
SchematicPrinter.INSTANCE.refresh();
} else if (guiButton.id == this.btnRotateX.id) {
rotationBoxes.checkBox(btnRotateX);
lastCheckedRotation = 0;
} else if (guiButton.id == this.btnRotateY.id) {
rotationBoxes.checkBox(btnRotateY);
lastCheckedRotation = 1;
} else if (guiButton.id == this.btnRotateZ.id) {
rotationBoxes.checkBox(btnRotateZ);
lastCheckedRotation = 2;
} else if (guiButton.id == this.btnMaterials.id) {
this.mc.displayGuiScreen(new GuiSchematicMaterials(this));
} else if (guiButton.id == this.btnPrint.id && this.printer.isEnabled()) {
Expand All @@ -260,7 +333,12 @@ protected void actionPerformed(GuiButton guiButton) {
this.numericX.getValue(),
this.numericY.getValue(),
this.numericZ.getValue(),
this.schematic.rotationState)) {
this.schematic.rotationStateX,
this.schematic.rotationStateY,
this.schematic.rotationStateZ,
this.schematic.flipStateX,
this.schematic.flipStateY,
this.schematic.flipStateZ)) {
mc.thePlayer.addChatMessage(new ChatComponentText(strSaveCoordinatesSuccess));
} else {
mc.thePlayer.addChatMessage(new ChatComponentText(strSaveCoordinatesFail));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraftforge.common.util.ForgeDirection;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.lwjgl.Sys;

Expand Down Expand Up @@ -170,16 +172,37 @@ private void loadSchematic() {
if (Schematica.proxy.loadSchematic(null, this.currentDirectory, schematicEntry.getName())) {
SchematicWorld schematic = ClientProxy.schematic;
if (schematic != null) {
ImmutableTriple<Boolean, Integer, ImmutableTriple<Integer, Integer, Integer>> schematicCoordinate = ClientProxy
ImmutableTriple<Boolean, ImmutablePair<ImmutableTriple<Integer, Integer, Integer>, ImmutableTriple<Integer, Integer, Integer>>, ImmutableTriple<Integer, Integer, Integer>> schematicCoordinate = ClientProxy
.getCoordinates(worldServerName(this.mc), schematic.name);
if (schematicCoordinate.left) {
ClientProxy.moveSchematic(
schematic,
schematicCoordinate.right.left,
schematicCoordinate.right.middle,
schematicCoordinate.right.right);
for (int i = 0; i < schematicCoordinate.middle; i++) {
schematic.rotate();
for (int i = 0; i < schematicCoordinate.middle.left.left; i++) // RotationX
{
schematic.rotate(ForgeDirection.EAST);
}
for (int i = 0; i < schematicCoordinate.middle.left.middle; i++) // RotationY
{
schematic.rotate(ForgeDirection.UP);
}
for (int i = 0; i < schematicCoordinate.middle.left.right; i++) // RotationZ
{
schematic.rotate(ForgeDirection.SOUTH);
}
for (int i = 0; i < schematicCoordinate.middle.right.left; i++) // FlipX
{
schematic.flip(ForgeDirection.EAST);
}
for (int i = 0; i < schematicCoordinate.middle.right.middle; i++) // FlipY
{
schematic.flip(ForgeDirection.UP);
}
for (int i = 0; i < schematicCoordinate.middle.right.right; i++) // FlipZ
{
schematic.flip(ForgeDirection.SOUTH);
}
RendererSchematicGlobal.INSTANCE.createRendererSchematicChunks(schematic);
SchematicPrinter.INSTANCE.refresh();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.github.lunatrius.schematica.client.gui.util;

import cpw.mods.fml.client.config.GuiCheckBox;

public class GuiOrCheckBoxHandler {

private int checkedBoxId;
private final GuiCheckBox[] boxes;

// Sets up a set of check boxes that are OR'd together. First box input will be set to the starting true checkbox.
public GuiOrCheckBoxHandler(GuiCheckBox... boxes) {
this.boxes = boxes;
checkBox(boxes[0]);
}

public void checkBox(GuiCheckBox boxToCheck) {
checkBox(boxToCheck.id);
}

public void checkBox(int id) {
boolean foundCheck = false;
for (GuiCheckBox box : boxes) {
if (box.id == id) {
box.setIsChecked(true);
checkedBoxId = id;
foundCheck = true;
} else {
box.setIsChecked(false);
}
}
if (!foundCheck) {
throw new RuntimeException(
"Check box passed in that doesn't exist in the handler! Check to make sure you're passing in the correct box.");
}
}

public int getCheckedBoxId() {
return checkedBoxId;
}
}
Loading

0 comments on commit 917e494

Please sign in to comment.