From 06cd255561e187504f9cda336ce4be7cdb280ba8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 3 May 2021 18:46:10 +0200 Subject: [PATCH] Add TraceShowGui --- .../features/tracer/TraceCommand.java | 3 +- .../bausystem/features/tracer/gui/.gitkeep | 0 .../features/tracer/gui/TraceShowGui.java | 130 ++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/.gitkeep create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/TraceShowGui.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 44d0fcd3..5da3971f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.tracer; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.features.tracer.gui.TraceShowGui; import de.steamwar.bausystem.features.tracer.record.RecordStateMachine; import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; import de.steamwar.bausystem.features.tracer.show.ShowModeParameterType; @@ -154,7 +155,7 @@ public class TraceCommand extends SWCommand { @Register({"show", "gui"}) public void showGuiCommand(Player p) { if (!permissionCheck(p)) return; - // GuiTraceShow.openGui(p); + TraceShowGui.openGui(p); } @Register({"hide"}) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/TraceShowGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/TraceShowGui.java new file mode 100644 index 00000000..93a8bad3 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/TraceShowGui.java @@ -0,0 +1,130 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer.gui; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tracer.TNTTracer_15; +import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; +import de.steamwar.bausystem.features.tracer.show.TraceShowManager; +import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode; +import de.steamwar.core.VersionedCallable; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import lombok.experimental.UtilityClass; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +@UtilityClass +public class TraceShowGui { + + private static final Map ShowModeParameterMap = new HashMap<>(); + + public static void openGui(Player player) { + ShowModeParameter playerShowMode = new ShowModeParameter(); + playerShowMode.setInterpolate_Y(false); + playerShowMode.setInterpolate_XZ(false); + ShowModeParameterMap.put(player, playerShowMode); + + SWInventory swInventory = new SWInventory(player, 9, "Trace Show GUI"); + swInventory.addCloseCallback(clickType -> ShowModeParameterMap.remove(player)); + setActiveShow(player, swInventory); + + SWItem water = new SWItem(Material.TNT, "§eWasser §7Positionen", Arrays.asList("§7Zeigt alles TNT, welches", "§7im Wasser explodiert ist."), false, clickType -> { + }); + swInventory.setItem(5, water); + swInventory.setCallback(5, clickType -> toggleHideTNTinWaterExploded(player, swInventory, water)); + + SWItem interpolateY = new SWItem(Material.QUARTZ_STAIRS, "§eInterpolation §7Y-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der Y-Achse."), false, clickType -> { + }); + swInventory.setItem(6, interpolateY); + swInventory.setCallback(6, clickType -> toggleInterpolateYPosition(player, swInventory, interpolateY)); + + Material xzMaterial = VersionedCallable.call(new VersionedCallable<>(TNTTracer_15::getTraceXZMaterial, 14)); + SWItem interpolateXZ = new SWItem(xzMaterial, (byte) 7, "§eInterpolation §7XZ-Achse", Arrays.asList("§7Zeigt die Interpolation", "§7auf der XZ-Achse."), false, clickType -> { + }); + swInventory.setItem(7, interpolateXZ); + swInventory.setCallback(7, clickType -> toggleInterpolateXZPosition(player, swInventory, interpolateXZ)); + // Water Bucket (-water) + // TNT (-water-exploded) + // Quartz_Stair (-interpolate-y) + // Quartz_Slab (-interpolate-xz) + swInventory.open(); + } + + private static void setActiveShow(Player player, SWInventory swInventory) { + if (TraceShowManager.hasActiveShow(player)) { + Material showMaterial = VersionedCallable.call(new VersionedCallable<>(TNTTracer_15::getTraceShowMaterial, 14)); + SWItem shown = new SWItem(showMaterial, "§aTraces angezeigt", new ArrayList<>(), false, clickType -> { + TraceShowManager.hide(player); + player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen ausgeblendet"); + setActiveShow(player, swInventory); + }); + swInventory.setItem(1, shown); + } else { + Material hideMaterial = VersionedCallable.call(new VersionedCallable<>(TNTTracer_15::getTraceHideMaterial, 14)); + SWItem hidden = new SWItem(hideMaterial, "§cTraces ausgeblendet", new ArrayList<>(), false, clickType -> { + show(player); + player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); + setActiveShow(player, swInventory); + }); + swInventory.setItem(1, hidden); + } + } + + private static void toggleHideTNTinWaterExploded(Player player, SWInventory swInventory, SWItem swItem) { + ShowModeParameter showModeParameter = ShowModeParameterMap.get(player); + showModeParameter.setWater(!showModeParameter.isWater()); + show(player); + + swItem.setEnchanted(showModeParameter.isWater()); + swInventory.setItem(5, swItem); + swInventory.setCallback(5, clickType -> toggleHideTNTinWaterExploded(player, swInventory, swItem)); + } + + private static void toggleInterpolateYPosition(Player player, SWInventory swInventory, SWItem swItem) { + ShowModeParameter showModeParameter = ShowModeParameterMap.get(player); + showModeParameter.setInterpolate_Y(!showModeParameter.isInterpolate_Y()); + show(player); + + swItem.setEnchanted(showModeParameter.isInterpolate_Y()); + swInventory.setItem(6, swItem); + swInventory.setCallback(6, clickType -> toggleInterpolateYPosition(player, swInventory, swItem)); + } + + private static void toggleInterpolateXZPosition(Player player, SWInventory swInventory, SWItem swItem) { + ShowModeParameter showModeParameter = ShowModeParameterMap.get(player); + showModeParameter.setInterpolate_XZ(!showModeParameter.isInterpolate_XZ()); + show(player); + + swItem.setEnchanted(showModeParameter.isInterpolate_XZ()); + swInventory.setItem(7, swItem); + swInventory.setCallback(7, clickType -> toggleInterpolateXZPosition(player, swInventory, swItem)); + } + + private static void show(Player player) { + TraceShowManager.show(player, new TraceEntityShowMode(player, ShowModeParameterMap.get(player))); + } + +}