Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/main/java/inventorysetups/InventorySetupsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -630,6 +631,12 @@ else if (panel.getCurrentSelectedSetup() != null
}
}

public Comparator<InventorySetup> getSetupsComparator()
{
Comparator<InventorySetup> favoriteComparator = Comparator.<InventorySetup>comparingInt(s -> s.isFavorite() ? 0 : 1);
return (config.sortingMode() == InventorySetupsSortingID.ALPHABETICAL) ? favoriteComparator.thenComparing(Comparator.<InventorySetup, String>comparing(InventorySetup::getName, String.CASE_INSENSITIVE_ORDER)) : favoriteComparator;
}

private void createMenuEntriesForWornItems()
{
List<InventorySetup> filteredSetups = panel.getFilteredInventorysetups();
Expand All @@ -650,7 +657,7 @@ private void createMenuEntriesForWornItems()
setupsToShowOnWornItemsList = filteredSetups;
break;
}

setupsToShowOnWornItemsList.sort(getSetupsComparator());
// Section mode creates the section entries and sub menus
if (config.sectionMode() && config.wornItemSelectionSubmenu())
{
Expand All @@ -660,26 +667,24 @@ private void createMenuEntriesForWornItems()

// If the sorting mode is default, then the order to appear on the worn items list
// should be the order they appear in the section, which may not be the filtered order.
List<InventorySetupsSection> sortedSections = new ArrayList<>(getSections());
if (config.sortingMode() == InventorySetupsSortingID.ALPHABETICAL && config.sectionSorting())
{
sortedSections.sort(Comparator.comparing(InventorySetupsSection::getName, String.CASE_INSENSITIVE_ORDER));
}
if (config.sortingMode() == InventorySetupsSortingID.DEFAULT)
{
Set<String> setupsToShowOnWornItemsListCache = setupsToShowOnWornItemsList.stream()
.map(InventorySetup::getName)
.collect(Collectors.toSet());
sections.forEach(section ->
sortedSections.forEach(section ->
{
List<String> setupsInSection = section.getSetups();
setupsInSection.forEach(setupName ->
{
if (setupsToShowOnWornItemsListCache.contains(setupName))
{
setupsToShowOnWornItemsList.stream().filter(setup -> section.getSetups().stream().anyMatch(ssetups -> ssetups.equals(setup.getName())))
.forEach(setupName -> {
if (!sectionsToDisplay.containsKey(section.getName()))
{
sectionsToDisplay.put(section.getName(), new ArrayList<>());
}
final InventorySetup inventorySetup = cache.getInventorySetupNames().get(setupName);
sectionsToDisplay.get(section.getName()).add(inventorySetup);
}
});
});
});

setupsToShowOnWornItemsList.forEach(setupToShow ->
Expand Down Expand Up @@ -714,7 +719,7 @@ private void createMenuEntriesForWornItems()
});
}

sections.forEach(section ->
sortedSections.forEach(section ->
{

if (!sectionsToDisplay.containsKey(section.getName()))
Expand Down
16 changes: 1 addition & 15 deletions src/main/java/inventorysetups/ui/InventorySetupsPluginPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,9 @@ public void redrawOverviewPanel(boolean resetScrollBar)
else
{
filteredInventorysetups = new ArrayList<>(plugin.getInventorySetups());
moveFavoriteSetupsToTopOfList(filteredInventorysetups);
}

if (plugin.getConfig().sortingMode() == InventorySetupsSortingID.ALPHABETICAL)
{
filteredInventorysetups.sort(Comparator.comparing(InventorySetup::getName, String.CASE_INSENSITIVE_ORDER));
}
filteredInventorysetups.sort(plugin.getSetupsComparator());

layoutSetups(filteredInventorysetups);
returnToOverviewPanel(resetScrollBar);
Expand Down Expand Up @@ -732,16 +728,6 @@ else if (!hasDisplayedLayoutWarning && !plugin.getCanUseLayouts() && plugin.getC
}
}

public void moveFavoriteSetupsToTopOfList(final List<InventorySetup> setupsToAdd)
{
List<InventorySetup> favSetups = setupsToAdd.stream().filter(InventorySetup::isFavorite).collect(Collectors.toList());
setupsToAdd.removeAll(favSetups);
for (int i = favSetups.size() - 1; i >= 0; i--)
{
setupsToAdd.add(0, favSetups.get(i));
}
}

public void refreshCurrentSetup()
{
if (currentSelectedSetup != null)
Expand Down