From b4466e6444446ae363267a5e72d9cb7f1e3fb80e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 28 Aug 2022 21:45:02 +0200 Subject: [PATCH] Add selection edit group options Signed-off-by: yoyosource --- .../simulator/gui/TNTGroupEditGUI.java | 98 +++++++++++++++++++ .../simulator/gui/TNTSimulatorGui.java | 35 ++++--- 2 files changed, 120 insertions(+), 13 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java index 7d1d604c..3f2cc7e8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java @@ -26,6 +26,8 @@ import de.steamwar.bausystem.features.simulator.TNTSimulator; import de.steamwar.bausystem.features.simulator.gui.components.ChangeMaterial; import de.steamwar.bausystem.features.simulator.gui.components.ChangePosition; import de.steamwar.bausystem.features.simulator.gui.components.Disabled; +import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; +import de.steamwar.bausystem.features.simulator.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.tnt.TNTGroup; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; @@ -35,15 +37,111 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.util.Consumer; +import org.bukkit.util.Vector; import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.UnaryOperator; +import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; + @UtilityClass public class TNTGroupEditGUI { + private static final Vector X_VECTOR = new Vector(0.0625, 0, 0); + private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0); + private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625); + + private static final Vector FX_VECTOR = new Vector(1, 0, 0); + private static final Vector FY_VECTOR = new Vector(0, 1, 0); + private static final Vector FZ_VECTOR = new Vector(0, 0, 1); + + public void open(Player player, TNTSimulator tntSimulator, List simulatorElements, Runnable back) { + SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_MOVE_ALL_GUI_NAME", player)); + SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {}); + for (int i = 0; i < 9; i++) { + inv.setItem(i, gray); + inv.setItem(i + 36, gray); + } + + if (back != null) { + inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); + } + + String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player); + String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player); + List plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player)); + List minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player)); + List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); + + Vector vector = simulatorElements.get(0).getPosition(); + + // X Position + inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; + tntSimulator.hide(); + moveAll(simulatorElements, clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); + tntSimulator.show(); + tntSimulator.change(); + }))); + inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, vector.getX()), lore, false, clickType -> {})); + inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; + tntSimulator.hide(); + moveAll(simulatorElements, (clickType.isShiftClick() ? X_VECTOR : FX_VECTOR).clone().multiply(-1)); + tntSimulator.show(); + tntSimulator.change(); + }))); + + // Y Position + inv.setItem(13, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; + tntSimulator.hide(); + moveAll(simulatorElements, clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); + tntSimulator.show(); + tntSimulator.change(); + }))); + inv.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, vector.getY()), lore, false, clickType -> {})); + inv.setItem(31, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; + tntSimulator.hide(); + moveAll(simulatorElements, (clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR).clone().multiply(-1)); + tntSimulator.show(); + tntSimulator.change(); + }))); + + // Z Position + inv.setItem(14, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; + tntSimulator.hide(); + moveAll(simulatorElements, clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); + tntSimulator.show(); + tntSimulator.change(); + }))); + inv.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, vector.getZ()), lore, false, clickType -> {})); + inv.setItem(32, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + if (clickType == ClickType.DOUBLE_CLICK) return; + tntSimulator.hide(); + moveAll(simulatorElements, (clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR).clone().multiply(-1)); + tntSimulator.show(); + }))); + + inv.open(); + } + + public void moveAll(List simulatorElements, Vector vector) { + for (SimulatorElement element : simulatorElements) { + if (element instanceof TNTGroup) { + TNTGroup group = (TNTGroup) element; + group.getPosition().add(vector); + } else if (element instanceof TNTElement) { + TNTElement tntElement = (TNTElement) element; + tntElement.getOwnPosition().add(vector); + } + } + } + public void open(Player player, TNTGroup tntGroup, Runnable back) { SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP_MENU", player)); SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {}); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java index fb32e42f..d87b36d5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java @@ -42,6 +42,8 @@ import java.util.Comparator; import java.util.List; import java.util.function.Supplier; +import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; + @UtilityClass public class TNTSimulatorGui { @@ -90,7 +92,8 @@ public class TNTSimulatorGui { SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TOTAL_TNT", player, totalTNTCount), clickType -> { }); swItem.getItemStack().setAmount(totalTNTCount); - inv.setItem(currentTntSimulator != null || currentTntGroup != null ? 50 : 49, swItem); + List elements = simulatorElements.get(); + inv.setItem(elements.isEmpty() ? 49 : 50, swItem); if (currentTntGroup != null) { Runnable editObserver = () -> { List otherLore = new ArrayList<>(); @@ -117,6 +120,12 @@ public class TNTSimulatorGui { SimulatorPreviewStorage.recalculate(currentTntSimulator); }); } else { + if (!elements.isEmpty()) { + TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); + inv.setItem(48, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP", player), new ArrayList<>(), false, clickType -> { + TNTGroupEditGUI.open(player, tntSimulator, elements, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); + })); + } inv.addCloseCallback(clickType -> { SimulatorPreviewStorage.recalculate(currentTntSimulator); }); @@ -158,54 +167,54 @@ public class TNTSimulatorGui { List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); // X Position - inv.setItem(12, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; tntSimulator.hide(); moveAll(tntSimulator, clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); tntSimulator.show(); tntSimulator.change(); - })); + }))); inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_X", player), lore, false, clickType -> {})); - inv.setItem(30, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; tntSimulator.hide(); moveAll(tntSimulator, (clickType.isShiftClick() ? X_VECTOR : FX_VECTOR).clone().multiply(-1)); tntSimulator.show(); tntSimulator.change(); - })); + }))); // Y Position - inv.setItem(13, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + inv.setItem(13, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; tntSimulator.hide(); moveAll(tntSimulator, clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); tntSimulator.show(); tntSimulator.change(); - })); + }))); inv.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Y", player), lore, false, clickType -> {})); - inv.setItem(31, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + inv.setItem(31, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; tntSimulator.hide(); moveAll(tntSimulator, (clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR).clone().multiply(-1)); tntSimulator.show(); tntSimulator.change(); - })); + }))); // Z Position - inv.setItem(14, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { + inv.setItem(14, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; tntSimulator.hide(); moveAll(tntSimulator, clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); tntSimulator.show(); tntSimulator.change(); - })); + }))); inv.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Z", player), lore, false, clickType -> {})); - inv.setItem(32, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { + inv.setItem(32, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; tntSimulator.hide(); moveAll(tntSimulator, (clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR).clone().multiply(-1)); tntSimulator.show(); - })); + }))); inv.open(); }