mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-10-25 20:32:20 +00:00
Presets: Custom Subsets Mode (#671)
This commit is contained in:
1 parent
fa6fd01a3a
commit
c1f7489de1
8 files changed
+132
-20
No files matched your search
@@ -305,18 +305,20 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
|
||||
final RecipeId recipeId = slot.getRecipeId();
|
||||
final BookmarkGroup group = slot.getGroup();
|
||||
|
||||
if (recipeId == null || !removeFullRecipe) {
|
||||
this.grid.removeRecipe(slot.itemIndex, removeFullRecipe);
|
||||
if (group.crafting != null && group.collapsed) {
|
||||
|
||||
if (!removeFullRecipe) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.grid.removeGroup(groupId);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (group.crafting != null && group.collapsed && removeFullRecipe) {
|
||||
this.grid.removeGroup(groupId);
|
||||
return true;
|
||||
} else if (group.crafting != null) {
|
||||
if (recipeId != null && group.crafting != null) {
|
||||
Set<RecipeId> recipes = group.crafting.recipeRelations.getOrDefault(recipeId, Collections.emptySet());
|
||||
|
||||
if (removeFullRecipe && recipes.isEmpty()) {
|
||||
if (recipes.isEmpty()) {
|
||||
for (Map.Entry<RecipeId, Set<RecipeId>> entry : group.crafting.recipeRelations.entrySet()) {
|
||||
if (entry.getValue().contains(recipeId)) {
|
||||
recipes = entry.getValue();
|
||||
@@ -326,8 +328,12 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
|
||||
}
|
||||
|
||||
if (!recipes.isEmpty()) {
|
||||
boolean removed = false;
|
||||
|
||||
if (!removeFullRecipe) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean removed = false;
|
||||
for (RecipeId relRecipeId : recipes) {
|
||||
removed = this.grid.removeRecipe(relRecipeId, groupId) || removed;
|
||||
}
|
||||
@@ -336,6 +342,11 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
|
||||
}
|
||||
}
|
||||
|
||||
if (recipeId == null || !removeFullRecipe) {
|
||||
this.grid.removeRecipe(slot.itemIndex, removeFullRecipe);
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.grid.removeRecipe(recipeId, groupId);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import codechicken.core.CommonUtils;
|
||||
import codechicken.nei.SubsetWidget.SubsetTag;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.api.IRecipeFilter.IRecipeFilterProvider;
|
||||
@@ -33,6 +34,7 @@ import codechicken.nei.util.NBTJson;
|
||||
public class PresetsList {
|
||||
|
||||
public enum PresetMode {
|
||||
SUBSET,
|
||||
HIDE,
|
||||
REMOVE,
|
||||
GROUP;
|
||||
@@ -216,6 +218,8 @@ public class PresetsList {
|
||||
if (!preset.items.isEmpty()) {
|
||||
presets.add(preset);
|
||||
}
|
||||
|
||||
updateSubsets();
|
||||
}
|
||||
|
||||
public static void savePresets() {
|
||||
@@ -241,9 +245,24 @@ public class PresetsList {
|
||||
|
||||
recipeFilter.cache = null;
|
||||
itemFilter.cache = null;
|
||||
updateSubsets();
|
||||
CollapsibleItems.saveStates();
|
||||
CollapsibleItems.load();
|
||||
LayoutManager.markItemsDirty();
|
||||
}
|
||||
|
||||
private static void updateSubsets() {
|
||||
SubsetWidget.removeTag("Presets");
|
||||
|
||||
for (Preset preset : PresetsList.presets) {
|
||||
if (preset.enabled && preset.mode == PresetMode.SUBSET) {
|
||||
SubsetWidget.addTag(
|
||||
new SubsetTag(
|
||||
"Presets." + preset.name,
|
||||
stack -> preset.items.contains(Preset.getIdentifier(stack))));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -426,6 +426,17 @@ public class SubsetWidget extends Button implements ItemFilterProvider, IContain
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeTag(String path) {
|
||||
updateState.stop();
|
||||
|
||||
synchronized (tags) {
|
||||
tags.keySet().removeIf(
|
||||
parentpath -> parentpath.equals(path.toLowerCase())
|
||||
|| parentpath.startsWith(path.toLowerCase() + "."));
|
||||
updateHiddenItems();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isHidden(ItemStack item) {
|
||||
try {
|
||||
if (hiddenReadLock.tryLock(5, TimeUnit.SECONDS)) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.SearchField;
|
||||
import codechicken.nei.bookmark.BookmarkGrid;
|
||||
import codechicken.nei.bookmark.BookmarkGroup;
|
||||
import codechicken.nei.bookmark.BookmarkItem;
|
||||
import codechicken.nei.bookmark.BookmarksGridSlot;
|
||||
import codechicken.nei.recipe.AutoCraftingManager;
|
||||
@@ -417,15 +418,56 @@ public abstract class ShortcutInputHandler {
|
||||
final RecipeId recipeId = getHotkeyRecipeId(gui, mousex, mousey, stack, slot);
|
||||
|
||||
if (slot != null) {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark"),
|
||||
NEIClientUtils.translate(slot.isIngredient() ? "bookmark.remove_item" : "bookmark.remove_recipe"));
|
||||
final BookmarkGroup group = slot.getGroup();
|
||||
|
||||
if (slot.isIngredient()) {
|
||||
if (group.crafting != null && group.collapsed) {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
|
||||
NEIClientUtils.translate("bookmark.remove_recipe"));
|
||||
}
|
||||
NEIClientUtils.translate("bookmark.group.remove_recipe"));
|
||||
} else if (slot.getRecipeId() == null) {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark"),
|
||||
NEIClientUtils.translate("bookmark.remove_item"));
|
||||
} else if (group.crafting != null && group.crafting.recipeRelations.entrySet().stream().anyMatch(
|
||||
entry -> entry.getKey().equals(slot.getRecipeId())
|
||||
|| entry.getValue().contains(slot.getRecipeId()))) {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
|
||||
NEIClientUtils.translate("bookmark.remove_recipe"));
|
||||
} else {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
|
||||
NEIClientUtils.translate("bookmark.remove_recipe"));
|
||||
|
||||
if (slot.isIngredient()) {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark"),
|
||||
NEIClientUtils.translate("bookmark.remove_item"));
|
||||
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
|
||||
NEIClientUtils.translate("bookmark.remove_recipe"));
|
||||
} else {
|
||||
final BookmarkItem item = slot.getBookmarkItem();
|
||||
|
||||
if (ItemPanels.bookmarkPanel.getGrid().createChainItems(groupId).values().stream()
|
||||
.noneMatch(
|
||||
m -> !m.isIngredient && !m.equals(item) && item.equalsRecipe(m))) {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark"),
|
||||
NEIClientUtils.translate("bookmark.remove_recipe"));
|
||||
} else {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark"),
|
||||
NEIClientUtils.translate("bookmark.remove_item"));
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
|
||||
NEIClientUtils.translate("bookmark.remove_recipe"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (BookmarkContainerInfo.getBookmarkContainerHandler(gui) != null) {
|
||||
hotkeys.put(
|
||||
|
||||
@@ -908,7 +908,7 @@ public class BookmarkGrid extends ItemsGrid<BookmarksGridSlot, BookmarkGrid.Book
|
||||
|
||||
if (item.recipeId != null && removeFullRecipe) {
|
||||
removeRecipe(item.recipeId, item.groupId);
|
||||
} else {
|
||||
} else if (itemIndex >= 0) {
|
||||
this.bookmarkItems.remove(itemIndex);
|
||||
onItemsChanged();
|
||||
}
|
||||
|
||||
@@ -207,6 +207,10 @@ public class GuiPresetList extends GuiOptionPane {
|
||||
modeName = EnumChatFormatting.GOLD + NEIClientUtils.translate("presets.mode.hide.char")
|
||||
+ EnumChatFormatting.RESET;
|
||||
break;
|
||||
case SUBSET:
|
||||
modeName = EnumChatFormatting.DARK_PURPLE + NEIClientUtils.translate("presets.mode.subset.char")
|
||||
+ EnumChatFormatting.RESET;
|
||||
break;
|
||||
case REMOVE:
|
||||
modeName = EnumChatFormatting.RED + NEIClientUtils.translate("presets.mode.remove.char")
|
||||
+ EnumChatFormatting.RESET;
|
||||
|
||||
@@ -86,6 +86,7 @@ public class LeftPanel extends GuiWidget {
|
||||
protected Label modeLabel = new Label(NEIClientUtils.translate("presets.mode"), false);
|
||||
|
||||
protected CheckboxButton modeHide;
|
||||
protected CheckboxButton modeSubset;
|
||||
protected CheckboxButton modeRemove;
|
||||
protected CheckboxButton modeGroup;
|
||||
|
||||
@@ -114,6 +115,19 @@ public class LeftPanel extends GuiWidget {
|
||||
}
|
||||
};
|
||||
|
||||
modeSubset = new CheckboxButton(NEIClientUtils.translate("presets.mode.subset")) {
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return preset.mode == PresetMode.SUBSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onChange() {
|
||||
preset.mode = this.checked ? PresetMode.SUBSET : null;
|
||||
}
|
||||
};
|
||||
|
||||
modeRemove = new CheckboxButton(NEIClientUtils.translate("presets.mode.remove")) {
|
||||
|
||||
@Override
|
||||
@@ -164,6 +178,10 @@ public class LeftPanel extends GuiWidget {
|
||||
modeHide.handleClick(x, y, button);
|
||||
}
|
||||
|
||||
if (modeSubset.contains(x, y)) {
|
||||
modeSubset.handleClick(x, y, button);
|
||||
}
|
||||
|
||||
if (modeRemove.contains(x, y)) {
|
||||
modeRemove.handleClick(x, y, button);
|
||||
}
|
||||
@@ -248,7 +266,7 @@ public class LeftPanel extends GuiWidget {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
int CHECKBOX_WIDTH = (this.width - 12) / 3;
|
||||
int CHECKBOX_WIDTH = (this.width - 12) / 4;
|
||||
nameLabel.x = this.x + 2;
|
||||
nameLabel.y = this.y + 4;
|
||||
nameLabel.w = this.width;
|
||||
@@ -269,12 +287,13 @@ public class LeftPanel extends GuiWidget {
|
||||
modeLabel.w = this.width;
|
||||
modeLabel.h = 10;
|
||||
|
||||
modeHide.w = modeRemove.w = modeGroup.w = CHECKBOX_WIDTH;
|
||||
modeHide.h = modeRemove.h = modeGroup.h = INPUT_HEIGHT;
|
||||
modeHide.y = modeRemove.y = modeGroup.y = modeLabel.y + modeLabel.h;
|
||||
modeHide.w = modeSubset.w = modeRemove.w = modeGroup.w = CHECKBOX_WIDTH;
|
||||
modeHide.h = modeSubset.h = modeRemove.h = modeGroup.h = INPUT_HEIGHT;
|
||||
modeHide.y = modeSubset.y = modeRemove.y = modeGroup.y = modeLabel.y + modeLabel.h;
|
||||
|
||||
modeHide.x = this.x + 1;
|
||||
modeRemove.x = modeHide.x + modeHide.w + 6;
|
||||
modeSubset.x = modeHide.x + modeHide.w + 6;
|
||||
modeRemove.x = modeSubset.x + modeSubset.w + 6;
|
||||
modeGroup.x = modeRemove.x + modeRemove.w + 6;
|
||||
|
||||
grid.setGridSize(
|
||||
@@ -292,6 +311,7 @@ public class LeftPanel extends GuiWidget {
|
||||
|
||||
modeLabel.draw(mousex, mousey);
|
||||
modeHide.draw(mousex, mousey);
|
||||
modeSubset.draw(mousex, mousey);
|
||||
modeRemove.draw(mousex, mousey);
|
||||
modeGroup.draw(mousex, mousey);
|
||||
|
||||
@@ -326,6 +346,8 @@ public class LeftPanel extends GuiWidget {
|
||||
|
||||
} else if (modeHide.contains(mousex, mousey)) {
|
||||
tooltip.add(NEIClientUtils.translate("presets.mode.hide.tip"));
|
||||
} else if (modeSubset.contains(mousex, mousey)) {
|
||||
tooltip.add(NEIClientUtils.translate("presets.mode.subset.tip"));
|
||||
} else if (modeRemove.contains(mousex, mousey)) {
|
||||
tooltip.add(NEIClientUtils.translate("presets.mode.remove.tip"));
|
||||
} else if (modeGroup.contains(mousex, mousey)) {
|
||||
|
||||
@@ -588,6 +588,9 @@ nei.presets.mode=Mode
|
||||
nei.presets.mode.hide=Hide
|
||||
nei.presets.mode.hide.char=H
|
||||
nei.presets.mode.hide.tip=Hide items in panel
|
||||
nei.presets.mode.subset=Subset
|
||||
nei.presets.mode.subset.char=S
|
||||
nei.presets.mode.subset.tip=Create custom subsets
|
||||
nei.presets.mode.remove=Remove
|
||||
nei.presets.mode.remove.tip=Hide items in panel and their recipes
|
||||
nei.presets.mode.remove.char=R
|
||||
|
||||
Reference in new issue
Block a user