/* * This file is a part of the SteamWar software. * * Copyright (C) 2026 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.lobby.particle.gui; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.lobby.particle.UnlockContext; import de.steamwar.lobby.particle.design.*; import de.steamwar.sql.SteamwarUser; import lombok.experimental.UtilityClass; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.entity.Player; import java.awt.Color; import java.util.*; import java.util.function.Consumer; import java.util.function.Function; import static de.steamwar.lobby.particle.gui.ParticleGuiText.*; @UtilityClass class Pickers { private final int BACK = 49; // Basic designs first, then rewards; locked rewards are shown with their requirement but cannot be picked. // The current design, if any, glows. void design(Player player, ParticleDesign current, Consumer onPick, Runnable onBack) { UnlockContext context = new UnlockContext(SteamwarUser.get(player.getUniqueId())); List> list = new ArrayList<>(); for (DesignVisibility visibility : List.of(DesignVisibility.BASIC, DesignVisibility.REWARD)) { for (ParticleDesign design : Designs.all()) { if (design.getVisibility() != visibility) continue; List lore = new ArrayList<>(requirement(design.getRequirement(), player)); boolean unlocked = design.getRequirement().test(context); if (!lore.isEmpty()) lore.add(""); lore.add(msg(design == current ? "PARTICLE_VALUE_SELECTED" : unlocked ? "PARTICLE_SELECT" : "PARTICLE_LOCKED", player)); list.add(new SWListInv.SWListEntry<>(new SWItem(design.getIcon(), designName(design, player), lore, design == current, clickType -> { }), unlocked ? design : null)); } } open(player, msg("PARTICLE_DESIGN_PICKER", player), list, onPick, onBack); } // Lists every option; the current one glows void choice(Player player, ChoiceParameter parameter, E current, Function icon, Consumer onPick, Runnable onBack) { List> list = new ArrayList<>(); for (E value : parameter.getBuildableValues()) { List lore = List.of(msg(value == current ? "PARTICLE_VALUE_SELECTED" : "PARTICLE_SELECT", player)); list.add(new SWListInv.SWListEntry<>(new SWItem(icon.apply(value), choiceName(parameter, value, player), lore, value == current, clickType -> { }), value)); } open(player, msg("PARTICLE_CHOICE_PICKER", player, name(parameter.getNameKey(), player)), list, onPick, onBack); } void color(Player player, Consumer onPick, Runnable onBack) { List> list = new ArrayList<>(); for (DyeColor dye : DyeColor.values()) { Color color = new Color(dye.getColor().asRGB()); list.add(new SWListInv.SWListEntry<>(new SWItem(Material.valueOf(dye.name() + "_DYE"), net.md_5.bungee.api.ChatColor.of(color) + prettify(dye.name()), clickType -> { }), color)); } open(player, msg("PARTICLE_COLOR_PICKER", player), list, onPick, onBack); } void icon(Player player, Consumer onPick, Runnable onBack) { Set icons = new LinkedHashSet<>(); for (ParticleType type : ParticleType.values()) { if (type.isBuildable()) icons.add(type.getIcon()); } for (ParticleDesign design : Designs.all()) { if (design.getVisibility() == DesignVisibility.BASIC) icons.add(design.getIcon()); } icons.addAll(List.of(Material.DIAMOND, Material.EMERALD, Material.GOLD_INGOT, Material.AMETHYST_SHARD, Material.HEART_OF_THE_SEA, Material.NETHER_STAR, Material.FEATHER, Material.TNT)); List> list = new ArrayList<>(); for (Material material : icons) { list.add(new SWListInv.SWListEntry<>(new SWItem(material, "§f" + prettify(material.name()), clickType -> { }), material)); } open(player, msg("PARTICLE_SLOT_ICON_TITLE", player), list, onPick, onBack); } private void open(Player player, String title, List> list, Consumer onPick, Runnable onBack) { SWListInv inventory = new SWListInv<>(player, title, false, list, (clickType, value) -> { if (value != null) onPick.accept(value); }); inventory.setItem(BACK, new SWItem(Material.ARROW, msg("PARTICLE_BACK", player), clickType -> onBack.run())); inventory.open(); } }