Save Tree State (#1052)

This commit is contained in:
slprime authored and GitHub committed 2026-09-27 11:00:27 +03:00
1 parent f84c4ef2bd
commit 5868187410
6 files changed
+48 -8

No files matched your search

@@ -224,6 +224,10 @@ public class NEIClientConfig {
.getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.bookmarks.bookmarkRecipeWithCount", true));
tag.getTag("inventory.bookmarks.craftingTreeZoomWithoutModifier")
.setComment("Zoom Crafting Tree with mouse wheel without holding Ctrl").getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.bookmarks.craftingTreeZoomWithoutModifier", true));
tag.getTag("inventory.guirecipe.jeiStyleTabs").setComment("Enable/disable JEI Style Tabs")
.getBooleanValue(true);
API.addOption(new OptionToggleButtonBoubs("inventory.guirecipe.jeiStyleTabs", true));
@@ -1150,6 +1154,10 @@ public class NEIClientConfig {
return getBooleanSetting("inventory.bookmarks.ignorePotionOverlap");
}
public static boolean craftingTreeZoomWithoutModifier() {
return getBooleanSetting("inventory.bookmarks.craftingTreeZoomWithoutModifier");
}
public static boolean optimizeGuiOverlapComputation() {
return getBooleanSetting("inventory.optimize_gui_overlap_computation");
}
@@ -142,7 +142,11 @@ class CraftingTreeCanvas {
public int treeWidth = 0;
public int treeHeight = 0;
private final Camera camera = new Camera();
private final Camera camera;
public CraftingTreeCanvas(Camera camera) {
this.camera = camera;
}
public void setViewport(int x, int y, int w, int h) {
this.camera.setViewport(x, y, w, h);
@@ -2,9 +2,12 @@ package codechicken.nei.bookmark.tree;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.bookmark.BookmarkGroup;
import codechicken.nei.bookmark.BookmarkItem;
class CraftingTreeState {
@@ -25,6 +28,8 @@ class CraftingTreeState {
HANDLERS
}
private static final Map<BookmarkGroup, CraftingTreeState> GROUP_STATES = new WeakHashMap<>();
private static final String KEY_STATS_VISIBLE = "craftingTree.statsVisible";
private static final String KEY_STATS_SECTIONS = "craftingTree.statsSections";
private static final String KEY_USE_INVENTORY_SNAPSHOT = "craftingTree.useInventorySnapshot";
@@ -35,6 +40,8 @@ class CraftingTreeState {
public boolean useInventorySnapshot = false;
public CollapseMode collapseMode = CollapseMode.EXPANDED;
public boolean initialized;
public final Camera camera = new Camera();
public final Set<BookmarkItem> collapsedItems = new HashSet<>();
public ItemTreeSlot replaceRecipeNode;
@@ -65,6 +72,9 @@ class CraftingTreeState {
? collapseModes[savedCollapseMode]
: CollapseMode.EXPANDED;
this.replaceRecipeNode = null;
this.searchItemResult = null;
this.searchStatsResult = null;
this.camera.endDrag();
}
public void toggleStatsPanelVisible() {
@@ -98,6 +108,10 @@ class CraftingTreeState {
NEIClientConfig.world.nbt.setInteger(KEY_COLLAPSE_MODE, this.collapseMode.ordinal());
}
public static CraftingTreeState of(BookmarkGroup group) {
return GROUP_STATES.computeIfAbsent(group, g -> new CraftingTreeState());
}
public SearchResult activeSearchResult() {
return this.searchItemResult != null ? this.searchItemResult : this.searchStatsResult;
}
@@ -39,6 +39,7 @@ import codechicken.lib.gui.GuiDraw;
import codechicken.nei.KeyManager;
import codechicken.nei.LRUCache;
import codechicken.nei.NEICPH;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.SearchField.GuiSearchField;
@@ -118,7 +119,6 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
private final LRUCache<String, String> handlerTitleCache = new LRUCache<>(100);
private GuiScreen prevGui;
private boolean isFirstScreen = true;
private final BookmarkGrid grid;
private final int groupId;
@@ -127,7 +127,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
private final StatsPanel statsPanel = new StatsPanel();
private final StatsSectionsMenu statsSectionsMenu = new StatsSectionsMenu();
private final CraftingTreeCanvas canvas = new CraftingTreeCanvas();
private final CraftingTreeCanvas canvas;
private boolean statsPanelVisible;
private GuiSearchField searchField;
@@ -136,7 +136,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
private AcceptsFollowingTooltipLineHandler acceptsFollowingTooltipLineHandler;
private RecipeItemsTooltipLineHandler recipeItemsTooltipLineHandler;
private final CraftingTreeState uiState = new CraftingTreeState();
private final CraftingTreeState uiState;
private final CraftingTreeToolbar toolbar;
private ItemTreeSlot hoveredNode;
@@ -148,6 +148,8 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
this.grid = grid;
this.groupId = groupId;
this.uiState = CraftingTreeState.of(grid.getGroup(groupId));
this.canvas = new CraftingTreeCanvas(this.uiState.camera);
this.toolbar = new CraftingTreeToolbar(this.uiState);
}
@@ -284,7 +286,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
this.canvas.graph.rebuild(this.math);
if (this.isFirstScreen) {
if (!this.uiState.initialized) {
updateCollapsedItems();
} else {
this.canvas.recalculateCoordinates(this.collapsedRecipes, this.uiState.collapsedItems, anchor);
@@ -292,8 +294,8 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
rebuildStatsPanel();
if (this.isFirstScreen) {
this.isFirstScreen = false;
if (!this.uiState.initialized) {
this.uiState.initialized = true;
this.canvas.fitToView();
}
}
@@ -842,7 +844,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
(int) mouse.getY(),
direction,
NEIClientUtils.shiftKey(),
NEIClientUtils.controlKey());
NEIClientUtils.controlKey() || NEIClientConfig.craftingTreeZoomWithoutModifier());
}
private boolean handleItemWheel(int wheel, Point2D mouse) {
@@ -904,6 +906,12 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
}
}
if (keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
this.mc.displayGuiScreen(this.prevGui);
NEICPH.sendRequestContainer();
return;
}
if (this.statsPanelVisible && KeyManager.isKeyDown("recipe.recipe")) {
final Point2D mouse = getMousePosition();
final Widget widget = this.statsPanel.getWidgetUnderMouse((int) mouse.getX(), (int) mouse.getY());
@@ -306,6 +306,9 @@ nei.options.inventory.bookmarks.bookmarkItemsWithRecipe.false=No
nei.options.inventory.bookmarks.bookmarkRecipeWithCount=Bookmark recipe with count
nei.options.inventory.bookmarks.bookmarkRecipeWithCount.true=Yes
nei.options.inventory.bookmarks.bookmarkRecipeWithCount.false=No
nei.options.inventory.bookmarks.craftingTreeZoomWithoutModifier=Tree Zoom without Ctrl
nei.options.inventory.bookmarks.craftingTreeZoomWithoutModifier.true=Yes
nei.options.inventory.bookmarks.craftingTreeZoomWithoutModifier.false=No
nei.options.inventory.favorites=Favorites
nei.options.inventory.favorites.enabled=Visibility
nei.options.inventory.favorites.enabled.true=Visible
@@ -197,6 +197,9 @@ nei.options.inventory.bookmarks.ignorePotionOverlap.false=Нет
nei.options.inventory.bookmarks.worldSpecific=Закладки для конкретного мира
nei.options.inventory.bookmarks.worldSpecific.true=Да
nei.options.inventory.bookmarks.worldSpecific.false=Нет
nei.options.inventory.bookmarks.craftingTreeZoomWithoutModifier=Масштаб дерева без Ctrl
nei.options.inventory.bookmarks.craftingTreeZoomWithoutModifier.true=Да
nei.options.inventory.bookmarks.craftingTreeZoomWithoutModifier.false=Нет
nei.options.inventory.guirecipe=Интерфейс рецептов
nei.options.inventory.guirecipe.jeiStyleTabs=Вкладки в стиле JEI
nei.options.inventory.guirecipe.jeiStyleTabs.true=Да