TrevorMDev / tile-packs

A collection of tile markers
BSD 2-Clause "Simplified" License
7 stars 5 forks source link

Sorting the panel list in alphabetical order #17

Open Violet-Vibes opened 1 year ago

Violet-Vibes commented 1 year ago

Would it be possible to sort the panel list in alphabetical order instead of the current order?

One solution would be to use the quicksort algorithm

private void loadPacks() {
    listContainer.removeAll();
    String search = searchBar.getText();
    List<Integer> enabledPacks = plugin.loadEnabledPacks();

    List<TilePack> packsList = new ArrayList<>(PACKS.values());
    packsList.sort(new Comparator<TilePack>() {
        @Override
        public int compare(TilePack t1, TilePack t2) {
            return t1.packName.compareTo(t2.packName);
        }
    });

    for (TilePack pack : packsList) {
        if (Strings.isNullOrEmpty(search) || pack.packName.contains(search.toLowerCase())) {
            JPanel tile = new PackPanel(plugin, gson, pack, enabledPacks.contains(pack.id));
            listContainer.add(tile);
        }
    }
    listContainer.revalidate();
    listContainer.repaint();
}
TrevorMDev commented 1 year ago

They are sorted alphabetically, just split out with bosses first then skilling at the end. Giants foundry is out of order in the live version but that fix is pending release.

We could add a sorting button though, to give users the ability to re-sort up or down.

Violet-Vibes commented 1 year ago

They are sorted alphabetically, just split out with bosses first then skilling at the end. Giants foundry is out of order in the live version but that fix is pending release.

We could add a sorting button though, to give users the ability to re-sort up or down.

Ah I see, yes that'd be a nice addition :)