Add lobby particle slot menus

Replace the particle inventory with a main menu showing the 7 slots and
unlocked presets, a slot editor with a read-only view for locked slots,
and an entry editor with pickers for designs, choices, colours and icons.
Slots are limited to 10 entries and a particles-per-tick budget.
This commit is contained in:
2026-10-26 09:48:00 +01:00
parent 211e2693cf
commit c95901bc42
12 changed files with 1041 additions and 77 deletions
@@ -0,0 +1,148 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.lobby.particle.gui;
import de.steamwar.lobby.LobbySystem;
import de.steamwar.lobby.particle.ParticleRequirement;
import de.steamwar.lobby.particle.UnlockContext;
import de.steamwar.lobby.particle.design.*;
import de.steamwar.lobby.particle.slot.ParticleEntry;
import de.steamwar.lobby.particle.slot.ParticleSlot;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import static de.steamwar.lobby.particle.design.EntryParameters.*;
@UtilityClass
class ParticleGuiText {
String msg(String key, Player player, Object... params) {
return LobbySystem.getMessage().parse(key, player, params);
}
// Falls back to a readable form of the key for names without a translation
String name(String key, Player player) {
try {
return LobbySystem.getMessage().parse(key, player);
} catch (MissingResourceException e) {
return "§f" + prettify(key.replaceFirst("^PARTICLE_(TYPE_|DESIGN_|PARAM_)?", ""));
}
}
String prettify(String id) {
StringBuilder builder = new StringBuilder();
for (String word : id.toLowerCase(Locale.ROOT).split("_")) {
if (word.isEmpty()) continue;
if (!builder.isEmpty()) builder.append(' ');
builder.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1));
}
return builder.toString();
}
String designName(ParticleDesign design, Player player) {
return name(design.getNameKey(), player);
}
String particleName(ParticleType type, Player player) {
return name(type.getNameKey(), player);
}
<E> String choiceName(ChoiceParameter<E> parameter, E value, Player player) {
for (ChoiceParameter.Choice<E> choice : parameter.getChoices()) {
if (choice.value() != value) continue;
if (value instanceof ParticleType type) return particleName(type, player);
return name("PARTICLE_CHOICE_" + parameter.getKey().toUpperCase(Locale.ROOT) + "_" + choice.id().toUpperCase(Locale.ROOT), player);
}
return String.valueOf(value);
}
String number(double value) {
return value == Math.rint(value) ? String.valueOf((long) value) : String.format(Locale.ROOT, "%.2f", value).replaceAll("0+$", "");
}
@SuppressWarnings("unchecked")
String valueText(Parameter<?> parameter, Object value, Player player) {
if (parameter instanceof DoubleParameter) return "§e" + number((Double) value);
if (parameter instanceof IntParameter) return "§e" + value;
if (parameter instanceof BooleanParameter) return msg((Boolean) value ? "PARTICLE_VALUE_YES" : "PARTICLE_VALUE_NO", player);
if (parameter instanceof ChoiceParameter<?> choice) return choiceName((ChoiceParameter<Object>) choice, value, player);
if (parameter instanceof GradientParameter) {
List<Color> colors = (List<Color>) value;
if (colors.isEmpty()) return msg("PARTICLE_VALUE_RANDOM", player);
StringBuilder builder = new StringBuilder();
colors.forEach(color -> builder.append(net.md_5.bungee.api.ChatColor.of(color)).append('█'));
return builder.toString();
}
return String.valueOf(value);
}
// Requirement lines for an item's lore, empty when there is no requirement
List<String> requirement(ParticleRequirement requirement, Player player) {
List<String> lore = new ArrayList<>();
String name = requirement.getRequirementName(player);
if (name != null) {
lore.add(msg("PARTICLE_UNLOCKED_BY", player));
lore.add(name);
}
return lore;
}
// Short description of an entry: design, particle and the conditions that are set
List<String> entrySummary(ParticleEntry entry, UnlockContext context, Player player) {
List<String> lore = new ArrayList<>();
ParameterValues values = entry.getValues();
lore.add(msg("PARTICLE_ENTRY_DESIGN", player, designName(entry.getDesign(), player)));
if (entry.getDesign().usesEntryParticle()) {
lore.add(msg("PARTICLE_ENTRY_PARTICLE", player, particleName(values.get(PARTICLE), player)));
}
lore.add("§8- " + choiceName(TICK_MODE, values.get(TICK_MODE), player));
addCondition(lore, MOVEMENT, values.get(MOVEMENT), Movement.ANY, player);
addCondition(lore, GLIDING, values.get(GLIDING), Gliding.ANY, player);
addCondition(lore, GROUND, values.get(GROUND), Ground.ANY, player);
addCondition(lore, SNEAK, values.get(SNEAK), Sneak.ANY, player);
addCondition(lore, VISIBILITY, values.get(VISIBILITY), Visibility.EVERYONE, player);
if (!entry.getDesign().getRequirement().test(context)) {
lore.add(msg("PARTICLE_ENTRY_LOCKED", player));
}
return lore;
}
private <E> void addCondition(List<String> lore, ChoiceParameter<E> parameter, E value, E none, Player player) {
if (value != none) {
lore.add("§8- " + choiceName(parameter, value, player));
}
}
List<String> slotSummary(ParticleSlot slot, Player player) {
List<String> lore = new ArrayList<>();
lore.add(msg("PARTICLE_SLOT_ENTRIES", player, slot.getEntries().size()));
for (ParticleEntry entry : slot.getEntries()) {
String particle = entry.getDesign().usesEntryParticle() ? " §8(" + particleName(entry.getValues().get(PARTICLE), player) + "§8)" : "";
lore.add("§8- " + designName(entry.getDesign(), player) + particle);
}
return lore;
}
}