From 93260d4662144bb76d74a0ebdae164f9b86f5eab Mon Sep 17 00:00:00 2001 From: Abdullah Date: Tue, 7 Jul 2026 22:06:28 +0300 Subject: [PATCH 01/13] Improve sound selector UI --- core/src/mindustry/logic/LStatements.java | 147 +++++++++++++++++++--- 1 file changed, 132 insertions(+), 15 deletions(-) diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index ff887d3920..3f7a68b16f 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -2,6 +2,7 @@ package mindustry.logic; import arc.*; import arc.audio.*; +import arc.files.*; import arc.func.*; import arc.graphics.*; import arc.scene.style.*; @@ -2367,6 +2368,20 @@ public class LStatements{ @RegisterStatement("playsound") public static class PlaySoundStatement extends LStatement{ + private static @Nullable Sound lastPreview; + + private static class SoundChoice{ + final String category; + final String name; + final Sound sound; + + SoundChoice(String category, String name, Sound sound){ + this.category = category; + this.name = name; + this.sound = sound; + } + } + public boolean positional; public String id = "@sfx-shoot", volume = "1", pitch = "1", pan = "0", x = "@thisx", y = "@thisy", limit = "true"; @@ -2385,21 +2400,7 @@ public class LStatements{ table.button(b -> { b.image(Icon.pencilSmall); - - Seq soundNames = new Seq<>(); - - for(var entry : Core.assets.getAllEntries(Sound.class, new Seq<>())){ - if(entry.value != Sounds.none && entry.value.file != null){ - soundNames.add(Strings.getFileNameWithoutExtension(entry.key)); - } - } - soundNames.sort(); - - String soundName = id.startsWith("@sfx-") ? id.substring(5) : id; - b.clicked(() -> showSelect(b, soundNames.toArray(String.class), soundName, t -> { - id = "@sfx-" + t; - build(table); - }, 3, cell -> cell.size(170, 50))); + b.clicked(() -> showSoundSelect(b, table)); }, Styles.logict, () -> {}).size(40).color(table.color).left().padLeft(-1); row(table); @@ -2436,6 +2437,122 @@ public class LStatements{ public LCategory category(){ return LCategory.world; } + + private void showSoundSelect(Button button, Table table){ + Seq choices = new Seq<>(); + ObjectMap> categories = new ObjectMap<>(); + + for(var entry : Core.assets.getAllEntries(Sound.class, new Seq<>())){ + Sound sound = entry.value; + if(sound == Sounds.none || sound.file == null) continue; + + String name = sound.file.nameWithoutExtension(); + Fi parent = sound.file.parent(); + String category = parent == null ? "other" : parent.name(); + + SoundChoice choice = new SoundChoice(category, name, sound); + choices.add(choice); + categories.get(category, Seq::new).add(choice); + } + + if(choices.isEmpty()) return; + + choices.sort((a, b) -> { + int cmp = a.category.compareTo(b.category); + return cmp == 0 ? a.name.compareTo(b.name) : cmp; + }); + + Seq categoryNames = categories.keys().toSeq().sort(); + categoryNames.insert(0, "all"); + + for(var seq : categories.values()){ + seq.sort((a, b) -> a.name.compareTo(b.name)); + } + + String current = id.startsWith("@sfx-") ? id.substring(5) : id; + String currentCategory = "all"; + for(var choice : choices){ + if(choice.name.equals(current)){ + currentCategory = choice.category; + break; + } + } + + final String selectedCurrentCategory = currentCategory; + + showSelectTable(button, (root, hide) -> { + root.left().top(); + + String[] selectedCategory = {categories.containsKey(selectedCurrentCategory) ? selectedCurrentCategory : "all"}; + Table soundList = new Table(); + ButtonGroup