mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-08 12:34:46 +00:00
Add Horizontal Scroll to Recipe GUI (#924)
This commit is contained in:
1 parent
2f4f72a2d6
commit
ccbf94790a
9 files changed
+109
-39
No files matched your search
@@ -99,8 +99,9 @@ public class IMCHandler {
|
||||
NEIClientConfig.logger.info("Error setting handler dimensions for {}", handler);
|
||||
}
|
||||
|
||||
// true if not set to false
|
||||
info.setUseCustomScroll(tag.hasKey("useCustomScroll") && tag.getBoolean("useCustomScroll"));
|
||||
final boolean allowOverflow = tag.hasKey("useCustomScroll") && tag.getBoolean("useCustomScroll");
|
||||
info.setAllowOverflowX(tag.hasKey("allowOverflowX") ? tag.getBoolean("allowOverflowX") : true);
|
||||
info.setAllowOverflowY(tag.hasKey("allowOverflowY") ? tag.getBoolean("allowOverflowY") : allowOverflow);
|
||||
info.setShowFavoritesButton(!tag.hasKey("showFavoritesButton") || tag.getBoolean("showFavoritesButton"));
|
||||
info.setShowOverlayButton(!tag.hasKey("showOverlayButton") || tag.getBoolean("showOverlayButton"));
|
||||
info.setShowBadge(tag.hasKey("showBadge") && tag.getBoolean("showBadge"));
|
||||
|
||||
@@ -308,7 +308,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
@Override
|
||||
public Widget getWidgetUnderMouse(int mousex, int mousey) {
|
||||
|
||||
if (handlerInfo.getUseCustomScroll() && !this.widgets.isEmpty()) {
|
||||
if (handlerInfo.isAllowOverflowY() && !this.widgets.isEmpty()) {
|
||||
return this.widgets.get(0);
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
this.container.x = this.guiLeft + 3;
|
||||
this.container.y = this.guiTop + 32;
|
||||
this.container.h = this.ySize - 32 - 5;
|
||||
this.container.h = this.ySize - 32 - 4;
|
||||
|
||||
GuiRecipe.toggleSearch.icon = new DrawableBuilder("nei:textures/nei_sprites.png", 0, 76, 10, 10).build();
|
||||
GuiRecipe.toggleSearch.w = GuiRecipe.toggleSearch.h = 12;
|
||||
@@ -372,9 +372,17 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
if (this.handlerPages.rebuildPages() || this.lastPage != this.handlerPages.getCurrentPageIndex()) {
|
||||
this.lastPage = this.handlerPages.getCurrentPageIndex();
|
||||
updateContainerSize();
|
||||
|
||||
this.container.setWidgets(this.handlerPages.getCurrentPageWidgets());
|
||||
|
||||
if (this.handlerInfo.getUseCustomScroll()) {
|
||||
if (!this.handlerInfo.isAllowOverflowX() && this.handlerInfo.getWidth() > this.xSize - 6) {
|
||||
this.container.setHorizontalScroll(ScrollBar.defaultHorizontalBar().setTrackPadding(1, 0, 1, 0));
|
||||
} else {
|
||||
this.container.setHorizontalScroll(null);
|
||||
}
|
||||
|
||||
if (this.handlerInfo.isAllowOverflowY()) {
|
||||
this.container.setVerticalScroll(null);
|
||||
} else if (this.container.w == this.xSize - 6) {
|
||||
this.container.setVerticalScroll(VERTICAL_SCROLLBAR);
|
||||
@@ -416,7 +424,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
this.recipetype = (this.currenthandlers.size() + idx) % this.currenthandlers.size();
|
||||
this.handler = new SearchRecipeHandler<>(this.currenthandlers.get(this.recipetype));
|
||||
this.handlerInfo = GuiRecipeTab.getHandlerInfo(this.handler.original);
|
||||
this.container.w = Math.max(this.xSize - 6, this.handlerInfo.getWidth());
|
||||
updateContainerSize();
|
||||
this.handlerPages = new RecipePageManager(this.handler, this.handlerInfo, this.container);
|
||||
this.prevpage.enabled = this.nextpage.enabled = this.handlerPages.getNumPages() > 1;
|
||||
this.lastPage = -1;
|
||||
@@ -426,9 +434,21 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
GuiRecipe.toggleSearch.state = 0;
|
||||
|
||||
this.container.setVerticalScrollOffset(0);
|
||||
this.container.setHorizontalScrollOffset(0);
|
||||
this.recipeTabs.update(this);
|
||||
}
|
||||
|
||||
private void updateContainerSize() {
|
||||
final int width = this.xSize - 6;
|
||||
this.container.w = Math.max(width, this.handlerInfo.getWidth());
|
||||
this.container.h = this.ySize - 32 - 4;
|
||||
|
||||
if (!this.handlerInfo.isAllowOverflowX() && this.handlerInfo.getWidth() > width) {
|
||||
this.container.w = width;
|
||||
this.container.h -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
public int openTargetRecipe(RecipeId recipeId) {
|
||||
int refIndex = -1;
|
||||
int recipetype = 0;
|
||||
|
||||
@@ -263,8 +263,13 @@ public abstract class GuiRecipeTab extends Widget {
|
||||
NEIClientConfig.logger.info("Error setting handler dimensions for " + handler);
|
||||
}
|
||||
|
||||
info.setUseCustomScroll(
|
||||
record.isSet("useCustomScroll") ? Boolean.parseBoolean(record.get("useCustomScroll")) : false);
|
||||
final boolean allowOverflow = record.isSet("useCustomScroll")
|
||||
&& Boolean.parseBoolean(record.get("useCustomScroll"));
|
||||
info.setAllowOverflowX(
|
||||
record.isSet("allowOverflowX") ? Boolean.parseBoolean(record.get("allowOverflowX")) : true);
|
||||
info.setAllowOverflowY(
|
||||
record.isSet("allowOverflowY") ? Boolean.parseBoolean(record.get("allowOverflowY"))
|
||||
: allowOverflow);
|
||||
handlerMap.put(handler, info);
|
||||
NEIClientConfig.logger.info("Loaded " + handler);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,9 @@ public class HandlerInfo {
|
||||
private boolean showFavoritesButton = true;
|
||||
private boolean showOverlayButton = true;
|
||||
private boolean showBadge = false;
|
||||
private boolean useCustomScroll = false;
|
||||
|
||||
private boolean allowOverflowX = true;
|
||||
private boolean allowOverflowY = false;
|
||||
|
||||
private ItemStack itemStack = null;
|
||||
private DrawableResource image = null;
|
||||
@@ -151,12 +153,26 @@ public class HandlerInfo {
|
||||
this.showBadge = showBadge;
|
||||
}
|
||||
|
||||
public boolean getUseCustomScroll() {
|
||||
return this.useCustomScroll;
|
||||
@Deprecated
|
||||
public void setUseCustomScroll(boolean useCustomScroll) {
|
||||
this.allowOverflowX = useCustomScroll;
|
||||
this.allowOverflowY = useCustomScroll;
|
||||
}
|
||||
|
||||
public void setUseCustomScroll(boolean useCustomScroll) {
|
||||
this.useCustomScroll = useCustomScroll;
|
||||
public boolean isAllowOverflowX() {
|
||||
return this.allowOverflowX;
|
||||
}
|
||||
|
||||
public void setAllowOverflowX(boolean allowOverflowX) {
|
||||
this.allowOverflowX = allowOverflowX;
|
||||
}
|
||||
|
||||
public boolean isAllowOverflowY() {
|
||||
return this.allowOverflowY;
|
||||
}
|
||||
|
||||
public void setAllowOverflowY(boolean allowOverflowY) {
|
||||
this.allowOverflowY = allowOverflowY;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@@ -195,6 +211,7 @@ public class HandlerInfo {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Builder setUseCustomScroll(boolean useCustomScroll) {
|
||||
this.info.setUseCustomScroll(useCustomScroll);
|
||||
return this;
|
||||
@@ -241,6 +258,16 @@ public class HandlerInfo {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAllowOverflowX(boolean allowOverflowX) {
|
||||
this.info.allowOverflowX = allowOverflowX;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAllowOverflowY(boolean allowOverflowY) {
|
||||
this.info.allowOverflowY = allowOverflowY;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HandlerInfo build() {
|
||||
return this.info;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class NEIRecipeWidget extends Widget {
|
||||
|
||||
public void update() {
|
||||
|
||||
if (this.showAsWidget || !this.handlerInfo.getUseCustomScroll()) {
|
||||
if (this.showAsWidget || !this.handlerInfo.isAllowOverflowY()) {
|
||||
final int recipeHeight = this.handlerRef.handler.getRecipeHeight(this.handlerRef.recipeIndex);
|
||||
this.w = Math.max(166, this.handlerInfo.getWidth());
|
||||
this.h = recipeHeight > 0 ? recipeHeight : this.handlerInfo.getHeight();
|
||||
@@ -145,7 +145,7 @@ public class NEIRecipeWidget extends Widget {
|
||||
final List<GuiRecipeButton> buttons = new ArrayList<>();
|
||||
final boolean showFavorites = NEIClientConfig.favoritesEnabled() && handlerInfo.getShowFavoritesButton();
|
||||
final boolean showOverlay = handlerInfo.getShowOverlayButton();
|
||||
final int x = Math.min(168, this.w) - GuiRecipeButton.BUTTON_WIDTH;
|
||||
final int x = Math.min(166, this.w) - GuiRecipeButton.BUTTON_WIDTH;
|
||||
int y = this.h - GuiRecipeButton.BUTTON_HEIGHT - 6;
|
||||
|
||||
if (guiContainer instanceof IGuiContainerOverlay overlay) {
|
||||
|
||||
@@ -42,10 +42,10 @@ public class RecipePageManager {
|
||||
this.cacheKey = cacheKey;
|
||||
this.pageWidgets.clear();
|
||||
|
||||
final boolean useCustomScroll = this.handlerInfo.getUseCustomScroll();
|
||||
final boolean allowOverflowY = this.handlerInfo.isAllowOverflowY();
|
||||
final int handlerHeight = this.handlerInfo.getHeight() + this.handlerInfo.getYShift();
|
||||
final boolean multipleWidgetsAllowed = !useCustomScroll && handlerInfo.isMultipleWidgetsAllowed();
|
||||
final boolean infiniteScroll = !useCustomScroll
|
||||
final boolean multipleWidgetsAllowed = !allowOverflowY && handlerInfo.isMultipleWidgetsAllowed();
|
||||
final boolean infiniteScroll = !allowOverflowY
|
||||
&& NEIClientConfig.getBooleanSetting("inventory.guirecipe.infiniteScroll");
|
||||
|
||||
final int heightAvailable = this.container.getVisibleHeight();
|
||||
@@ -59,7 +59,7 @@ public class RecipePageManager {
|
||||
final NEIRecipeWidget widget = RecipeHandlerRef.of(this.handler.original, recipeIndex).getRecipeWidget();
|
||||
widget.w = width;
|
||||
|
||||
if (useCustomScroll) {
|
||||
if (allowOverflowY) {
|
||||
widget.h = Math.min(handlerHeight, heightAvailable);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class RecipePageManager {
|
||||
}
|
||||
|
||||
public boolean isMultipleWidgetsAllowed() {
|
||||
return !this.handlerInfo.getUseCustomScroll() && this.handlerInfo.isMultipleWidgetsAllowed();
|
||||
return !this.handlerInfo.isAllowOverflowY() && this.handlerInfo.isMultipleWidgetsAllowed();
|
||||
}
|
||||
|
||||
public int getNumRecipes() {
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -53,7 +52,8 @@ public class DebugHandlerWidget extends Widget {
|
||||
public int height;
|
||||
public boolean multiWidgets;
|
||||
public int order;
|
||||
public boolean useCustomScroll;
|
||||
public boolean allowOverflowX;
|
||||
public boolean allowOverflowY;
|
||||
public boolean showFavorites;
|
||||
public boolean showOverlay;
|
||||
public boolean showBadge;
|
||||
@@ -68,7 +68,8 @@ public class DebugHandlerWidget extends Widget {
|
||||
this.height = info.getHeight();
|
||||
this.multiWidgets = info.isMultipleWidgetsAllowed();
|
||||
this.order = NEIClientConfig.handlerOrdering.getOrDefault(handlerKey, 0);
|
||||
this.useCustomScroll = info.getUseCustomScroll();
|
||||
this.allowOverflowX = info.isAllowOverflowX();
|
||||
this.allowOverflowY = info.isAllowOverflowY();
|
||||
this.showFavorites = info.getShowFavoritesButton();
|
||||
this.showOverlay = info.getShowOverlayButton();
|
||||
this.showBadge = info.getShowBadge();
|
||||
@@ -79,7 +80,8 @@ public class DebugHandlerWidget extends Widget {
|
||||
this.info.setYShift(this.yShift);
|
||||
this.info.setHandlerDimensions(this.width, this.height);
|
||||
this.info.setMultipleWidgetsAllowed(this.multiWidgets);
|
||||
this.info.setUseCustomScroll(this.useCustomScroll);
|
||||
this.info.setAllowOverflowX(this.allowOverflowX);
|
||||
this.info.setAllowOverflowY(this.allowOverflowY);
|
||||
this.info.setShowFavoritesButton(this.showFavorites);
|
||||
this.info.setShowOverlayButton(this.showOverlay);
|
||||
this.info.setShowBadge(this.showBadge);
|
||||
@@ -94,10 +96,11 @@ public class DebugHandlerWidget extends Widget {
|
||||
this.width = intOrDefault(parts[3], this.width);
|
||||
this.multiWidgets = intOrDefault(parts[4], this.multiWidgets ? 1 : 0) == 1;
|
||||
this.order = intOrDefault(parts[5], this.order);
|
||||
this.useCustomScroll = intOrDefault(parts[6], this.useCustomScroll ? 1 : 0) == 1;
|
||||
this.showFavorites = intOrDefault(parts[7], this.showFavorites ? 1 : 0) == 1;
|
||||
this.showOverlay = intOrDefault(parts[8], this.showOverlay ? 1 : 0) == 1;
|
||||
this.showBadge = intOrDefault(parts[9], this.showBadge ? 1 : 0) == 1;
|
||||
this.allowOverflowX = intOrDefault(parts[6], this.allowOverflowX ? 1 : 0) == 1;
|
||||
this.allowOverflowY = intOrDefault(parts[7], this.allowOverflowY ? 1 : 0) == 1;
|
||||
this.showFavorites = intOrDefault(parts[8], this.showFavorites ? 1 : 0) == 1;
|
||||
this.showOverlay = intOrDefault(parts[9], this.showOverlay ? 1 : 0) == 1;
|
||||
this.showBadge = intOrDefault(parts[10], this.showBadge ? 1 : 0) == 1;
|
||||
|
||||
apply();
|
||||
}
|
||||
@@ -111,7 +114,8 @@ public class DebugHandlerWidget extends Widget {
|
||||
String.valueOf(this.width),
|
||||
String.valueOf(this.multiWidgets ? 1 : 0),
|
||||
String.valueOf(this.order),
|
||||
String.valueOf(this.useCustomScroll ? 1 : 0),
|
||||
String.valueOf(this.allowOverflowX ? 1 : 0),
|
||||
String.valueOf(this.allowOverflowY ? 1 : 0),
|
||||
String.valueOf(this.showFavorites ? 1 : 0),
|
||||
String.valueOf(this.showOverlay ? 1 : 0),
|
||||
String.valueOf(this.showBadge ? 1 : 0));
|
||||
@@ -137,7 +141,7 @@ public class DebugHandlerWidget extends Widget {
|
||||
private static final int LABEL_WIDTH = 50;
|
||||
|
||||
private static final String TOOLTIP_PREFIX = "debug.RecipeHandler.";
|
||||
private static final String HEADER = "HandlerId,YShift,Height,Width,MultiWidgets,Order,UseCustomScroll,ShowFavorites,ShowOverlay,ShowBadge";
|
||||
private static final String HEADER = "HandlerId,YShift,Height,Width,MultiWidgets,Order,AllowOverflowX,AllowOverflowY,ShowFavorites,ShowOverlay,ShowBadge";
|
||||
private final int[] COLORS = new int[] { 0x2200FF00, 0x22FF0000, 0x220000FF, 0x2200FFFF, 0x22FF00FF, 0x22FFFF00 };
|
||||
|
||||
public static DebugHandlerWidget instance = new DebugHandlerWidget();
|
||||
@@ -212,8 +216,13 @@ public class DebugHandlerWidget extends Widget {
|
||||
saveHandlerInfoPatch();
|
||||
}, y);
|
||||
|
||||
y = addCheckboxWidget("UseCustomScroll", button -> {
|
||||
record.useCustomScroll = button.value;
|
||||
y = addCheckboxWidget("AllowOverflowX", button -> {
|
||||
record.allowOverflowX = button.value;
|
||||
saveHandlerInfoPatch();
|
||||
}, y);
|
||||
|
||||
y = addCheckboxWidget("AllowOverflowY", button -> {
|
||||
record.allowOverflowY = button.value;
|
||||
saveHandlerInfoPatch();
|
||||
}, y);
|
||||
|
||||
@@ -397,7 +406,8 @@ public class DebugHandlerWidget extends Widget {
|
||||
this.values.get("width").updateValue(String.valueOf(this.record.width));
|
||||
|
||||
this.values.get("multiwidgets").updateValue(String.valueOf(this.record.multiWidgets));
|
||||
this.values.get("usecustomscroll").updateValue(String.valueOf(this.record.useCustomScroll));
|
||||
this.values.get("allowoverflowx").updateValue(String.valueOf(this.record.allowOverflowX));
|
||||
this.values.get("allowoverflowy").updateValue(String.valueOf(this.record.allowOverflowY));
|
||||
|
||||
this.values.get("showfavorites").updateValue(String.valueOf(this.record.showFavorites));
|
||||
this.values.get("showoverlay").updateValue(String.valueOf(this.record.showOverlay));
|
||||
@@ -589,17 +599,23 @@ public class DebugHandlerWidget extends Widget {
|
||||
public void loadHandlerInfoPatch() {
|
||||
|
||||
ClientHandler.loadSettingsFile("handlers.patch", lines -> {
|
||||
final List<String> linesList = lines.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
for (String line : lines.collect(Collectors.toCollection(HashSet::new))) {
|
||||
if (HEADER.equals(line)) continue;
|
||||
final String[] parts = (line).split(",");
|
||||
if (linesList.isEmpty() || !HEADER.equals(linesList.get(0))) {
|
||||
return;
|
||||
}
|
||||
|
||||
linesList.remove(0);
|
||||
|
||||
for (String line : linesList) {
|
||||
final String[] parts = line.split(",");
|
||||
final String handlerKey = parts[0];
|
||||
|
||||
if (GuiRecipeTab.handlerMap.containsKey(handlerKey)) {
|
||||
final HandlerInfoRecord record = patches.computeIfAbsent(
|
||||
handlerKey,
|
||||
key -> new HandlerInfoRecord(key, GuiRecipeTab.handlerMap.get(key)));
|
||||
record.apply((line + ",null,null,null,null,null,null,null,null,null"));
|
||||
record.apply((line + ",null,null,null,null,null,null,null,null,null,null"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class IntegerField extends TextField implements IUpdatableWidget {
|
||||
@Override
|
||||
public boolean onMouseWheel(int i, int mx, int my) {
|
||||
if (!contains(mx, my)) return false;
|
||||
setText(Integer.toString(getInteger() + i));
|
||||
setText(Integer.toString(getInteger() - i));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -542,7 +542,8 @@ nei.debug.RecipeHandler.Width=Width
|
||||
nei.debug.RecipeHandler.ShowFavorites=Show Favorites
|
||||
nei.debug.RecipeHandler.ShowOverlay=Show Overlays
|
||||
nei.debug.RecipeHandler.ShowBadge=Show Badge
|
||||
nei.debug.RecipeHandler.UseCustomScroll=Use Custom Scroll
|
||||
nei.debug.RecipeHandler.AllowOverflowY=Allow Overflow Y
|
||||
nei.debug.RecipeHandler.AllowOverflowX=Allow Overflow X
|
||||
nei.debug.RecipeHandler.Override=Override
|
||||
nei.debug.RecipeHandler.checkbox.on=On
|
||||
nei.debug.RecipeHandler.checkbox.off=Off
|
||||
|
||||
Reference in new issue
Block a user