Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config screen sorting #2394

Open
wants to merge 2 commits into
base: 1.16
Choose a base branch
from
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
120 changes: 116 additions & 4 deletions src/main/java/mezz/jei/config/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
import org.apache.logging.log4j.Logger;

import javax.annotation.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class ClientConfig implements IJEIConfig, IClientConfig {
private static final Logger LOGGER = LogManager.getLogger();
Expand All @@ -36,17 +40,36 @@ public final class ClientConfig implements IJEIConfig, IClientConfig {
private final ConfigValues values;
private List<? extends String> searchColors = Arrays.asList(ColorGetter.getColorDefaults());
public static final List<IngredientSortStage> ingredientSorterStagesDefault = Arrays.asList(
IngredientSortStage.MOD_NAME,
IngredientSortStage.INGREDIENT_TYPE,
IngredientSortStage.CREATIVE_MENU,
IngredientSortStage.ALPHABETICAL,
IngredientSortStage.WEAPON_DAMAGE,
IngredientSortStage.TOOL_TYPE,
IngredientSortStage.ARMOR,
IngredientSortStage.TAG,
IngredientSortStage.ALPHABETICAL,
IngredientSortStage.MOD_NAME,
IngredientSortStage.INGREDIENT_TYPE,
IngredientSortStage.CREATIVE_MENU
IngredientSortStage.MAX_DURABILITY
);
private List<IngredientSortStage> ingredientSorterStages = ingredientSorterStagesDefault;

private class StageSorterConfig {
public IngredientSortStage stage;
public int initialWeight;
public int requestedWeight;

public StageSorterConfig(IngredientSortStage assignStage, int weight) {
stage = assignStage;
initialWeight = weight;
requestedWeight = weight;
}
public IngredientSortStage getStage() { return stage; }
public int getInitialWeight() { return initialWeight;}
public int getRequestedWeight() { return requestedWeight;}
}

private List<StageSorterConfig> ingredientSorterWeights;


// Forge config
private final ForgeConfigSpec.BooleanValue debugModeEnabled;
private final ForgeConfigSpec.BooleanValue centerSearchBarEnabled;
Expand Down Expand Up @@ -143,6 +166,24 @@ public void buildSettingsGUI(ConfigGroup group) {
values.maxRecipeGuiHeight = v;
}, defaultVals.maxRecipeGuiHeight, 1, Integer.MAX_VALUE);

int order = 1;
if (ingredientSorterStages.size() != ingredientSorterStagesDefault.size())
{
//We need all of them to appear because you can't add them.
//The new default has all of them.
ingredientSorterStages = ingredientSorterStagesDefault;
}
ingredientSorterWeights = new ArrayList<StageSorterConfig>(ingredientSorterStages.size());
for (IngredientSortStage stage : ingredientSorterStages) {
ingredientSorterWeights.add(new StageSorterConfig(stage, order * 10));
group.addInt(cfgTranslation("sort." + stage.name().toLowerCase()), order * 10,
v -> {setIngredientSorterStages(stage, v);},
order * 10,
Integer.MIN_VALUE,
Integer.MAX_VALUE
);
order++;
}
}

private String cfgTranslation(String name) {
Expand Down Expand Up @@ -206,6 +247,77 @@ public List<IngredientSortStage> getIngredientSorterStages() {
return ingredientSorterStages;
}

public List<String> getIngredientSorterDefaults() {
return ingredientSorterStagesDefault.stream()
.map(Enum::name)
.collect(Collectors.toList());

}

public String getIngredientSorterDefaultString() {
return ingredientSorterStagesDefault.stream()
.map(Enum::name)
.collect(Collectors.joining(","));
}

public String getIngredientSorterStagesString() {
return String.join(",", ingredientSorterStagesCfg.get());
//ingredientSorterStagesCfg.get().stream().collect(Collectors.joining(","));
}

public void setIngredientSorterStringStages(String stagesCSV) {
List<String> stagesList = Stream.of(stagesCSV.split(",", -1)).map(s -> s.trim().toUpperCase()).collect(Collectors.toList());
setIngredientSorterStringStages(stagesList);
}

public void setIngredientSorterStringStages(List<String> stagesList) {
ingredientSorterStagesCfg.set(stagesList);
this.ingredientSorterStages = ingredientSorterStagesCfg.get()
.stream()
.map(s -> EnumUtils.getEnum(IngredientSortStage.class, s))
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (ingredientSorterStages.isEmpty()) {
this.ingredientSorterStages = ingredientSorterStagesDefault;
}
Internal.getIngredientFilter().invalidateCache();
}

public void setIngredientSorterStages(List<IngredientSortStage> stagesList) {
this.ingredientSorterStages = stagesList;
if (ingredientSorterStages.isEmpty()) {
this.ingredientSorterStages = ingredientSorterStagesDefault;
}
List<String> stagesStrings = ingredientSorterStages.stream()
.map(Enum::name)
.collect(Collectors.toList());
this.ingredientSorterStagesCfg.set(stagesStrings);
Internal.getIngredientFilter().invalidateCache();
}

public void setIngredientSorterStages(IngredientSortStage setStage, int setWeight) {
boolean saveIt = false;
for (StageSorterConfig sorterWeight : ingredientSorterWeights) {
if (sorterWeight.stage == setStage) {
sorterWeight.requestedWeight = setWeight;
//We shouldn't try to save until we have updated the last one.
saveIt = (sorterWeight.initialWeight == (ingredientSorterStages.size() * 10));
break;
}
}

if (saveIt) {
Comparator<StageSorterConfig> requestedWeight = Comparator.comparing(StageSorterConfig::getRequestedWeight);
Comparator<StageSorterConfig> initalWeight = Comparator.comparing(StageSorterConfig::getInitialWeight);

List<IngredientSortStage> stagesList = ingredientSorterWeights.stream()
.sorted(requestedWeight.thenComparing(initalWeight))
.map(StageSorterConfig::getStage)
.collect(Collectors.toList());
setIngredientSorterStages(stagesList);
}
}

private void syncSearchColorsConfig() {
final ImmutableMap.Builder<Integer, String> searchColorsMapBuilder = ImmutableMap.builder();
for (String entry : searchColors) {
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/mezz/jei/ingredients/IngredientFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,20 @@ public List<IIngredientListElementInfo<?>> getIngredientListPreSort(Comparator<I
//First step is to get the full list.
List<IIngredientListElementInfo<?>> ingredientList = getIngredientListUncached("");
LoggedTimer filterTimer = new LoggedTimer();
if (debugMode) {
filterTimer.start("Pre-Sorting.");
}
filterTimer.start("Pre-Sorting.");
//Then we sort it.
List<IIngredientListElementInfo<?>> fullSortedList = ingredientList.stream()
List<IIngredientListElementInfo<?>> fullSortedList;
try {
fullSortedList = ingredientList.stream()
.sorted(directComparator)
.collect(Collectors.toList());
if (debugMode) {
filterTimer.stop();
LogManager.getLogger().info("Sort has " + ingredientList.size());
} catch (Exception e) {
//Be even more defensive.
LogManager.getLogger().error("Error pre-sorting items.", e);
fullSortedList = ingredientList;
}
filterTimer.stop();
LogManager.getLogger().info("Sort has " + ingredientList.size());
return fullSortedList;
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/assets/jei/lang/en_au.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@
"config.jei.advanced.giveMode": "Give Mode",
"config.jei.advanced.giveMode.comment": "Choose if JEI should give items direct to the inventory (inventory) or pick them up with the mouse (mouse_pickup).",

"config.jei.advanced.sort.weapon_damage": "Weapon Sort Weight",
"config.jei.advanced.sort.weapon_damage.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.tool_type": "Tool Sort Weight",
"config.jei.advanced.sort.tool_type.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.armor": "Armor Sort Weight",
"config.jei.advanced.sort.armor.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.tag": "Item Tag Sort Weight",
"config.jei.advanced.sort.tab.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.alphabetical": "Alphabetical Sort Weight",
"config.jei.advanced.sort.alphabetical.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.mod_name": "Mod Name Sort Weight",
"config.jei.advanced.sort.mod_name.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.ingredient_type": "Item Java Type Sort Weight",
"config.jei.advanced.sort.ingredient_type.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.creative_menu": "Creative Panel Order Sort Weight",
"config.jei.advanced.sort.creative_menu.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.max_durability": "Maximum Durability Sort Weight",
"config.jei.advanced.sort.max_durability.comment": "Set the sorter priority weight to prioritize how to sort the panel.",

"_comment": "Hide Ingredients Mode",
"gui.jei.editMode.description": "JEI Hide Ingredients Mode:",
"gui.jei.editMode.description.hide": "%s-Click to Hide",
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/assets/jei/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@
"config.jei.advanced.maxRecipeGuiHeight.comment": "The maximum height of the recipe GUI.",
"config.jei.advanced.giveMode": "Give Mode",
"config.jei.advanced.giveMode.comment": "Choose if JEI should give ingredients direct to the inventory (inventory) or pick them up with the mouse (mouse_pickup).",

"config.jei.advanced.sort.weapon_damage": "Weapon Sort Weight",
"config.jei.advanced.sort.weapon_damage.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.tool_type": "Tool Sort Weight",
"config.jei.advanced.sort.tool_type.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.armor": "Armor Sort Weight",
"config.jei.advanced.sort.armor.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.tag": "Item Tag Sort Weight",
"config.jei.advanced.sort.tab.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.alphabetical": "Alphabetical Sort Weight",
"config.jei.advanced.sort.alphabetical.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.mod_name": "Mod Name Sort Weight",
"config.jei.advanced.sort.mod_name.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.ingredient_type": "Item Java Type Sort Weight",
"config.jei.advanced.sort.ingredient_type.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.creative_menu": "Creative Panel Order Sort Weight",
"config.jei.advanced.sort.creative_menu.comment": "Set the sorter priority weight to prioritize how to sort the panel.",
"config.jei.advanced.sort.max_durability": "Maximum Durability Sort Weight",
"config.jei.advanced.sort.max_durability.comment": "Set the sorter priority weight to prioritize how to sort the panel.",

"_comment": "Hide Ingredients Mode",
"gui.jei.editMode.description": "JEI Hide Ingredients Mode:",
Expand Down