mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-17 11:05:07 +00:00
Small fixes & changes (#523)
* fix hotkeys * code cleanup * fix recipe tooltip overlay * search item by original name * overlay button refactoring * fix subset filter * change keyname; issue 524 * cleanup code * move overlayformat logic --------- Co-authored-by: slprime <[email protected]>
This commit is contained in:
1 parent
bd5e991a84
commit
65652e5896
15 files changed
+166
-98
No files matched your search
@@ -62,7 +62,44 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
}
|
||||
}
|
||||
|
||||
private final static int OVERLAY_BUTTON_ID_START = 4;
|
||||
public enum ItemOverlayFormat {
|
||||
|
||||
BACKGROUND,
|
||||
ICON;
|
||||
|
||||
public static ItemOverlayFormat from(int overlay) {
|
||||
return overlay == 2 ? ItemOverlayFormat.BACKGROUND : ItemOverlayFormat.ICON;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemOverlayState {
|
||||
|
||||
protected PositionedStack slot;
|
||||
protected boolean isPresent;
|
||||
|
||||
public ItemOverlayState(PositionedStack slot, boolean isPresent) {
|
||||
this.slot = slot;
|
||||
this.isPresent = isPresent;
|
||||
}
|
||||
|
||||
public boolean isPresent() {
|
||||
return this.isPresent;
|
||||
}
|
||||
|
||||
public PositionedStack getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
public void draw(ItemOverlayFormat format) {
|
||||
LayoutManager.drawItemPresenceOverlay(
|
||||
this.slot.relx,
|
||||
this.slot.rely,
|
||||
this.isPresent,
|
||||
format == ItemOverlayFormat.BACKGROUND);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int OVERLAY_BUTTON_ID_START = 4;
|
||||
|
||||
public final GuiContainer firstGui;
|
||||
public final IRecipeHandler handler;
|
||||
@@ -71,7 +108,7 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
protected ItemsTooltipLineHandler missedMaterialsTooltipLineHandler;
|
||||
|
||||
protected final IOverlayHandler overlayHandler;
|
||||
protected final List<Boolean> itemPresenceCache = new ArrayList<>();
|
||||
protected final List<ItemOverlayState> itemPresenceCache = new ArrayList<>();
|
||||
protected boolean requireShiftForOverlayRecipe = true;
|
||||
protected boolean useOverlayRenderer = false;
|
||||
protected boolean hasOverlay = false;
|
||||
@@ -113,26 +150,26 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
|
||||
public Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys) {
|
||||
|
||||
if (this.requireShiftForOverlayRecipe) {
|
||||
if (this.requireShiftForOverlayRecipe && this.useOverlayRenderer) {
|
||||
hotkeys.put(translate("recipe.overlay.fillCraftingGrid.key"), translate("recipe.overlay.fillCraftingGrid"));
|
||||
}
|
||||
|
||||
String keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark"), true);
|
||||
String keyName = NEIClientConfig.getKeyName("gui.bookmark");
|
||||
if (keyName != null) {
|
||||
hotkeys.put(keyName, translate("recipe.overlay.bookmark"));
|
||||
}
|
||||
|
||||
keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_recipe"), true);
|
||||
keyName = NEIClientConfig.getKeyName("gui.bookmark_recipe");
|
||||
if (keyName != null) {
|
||||
hotkeys.put(keyName, translate("recipe.overlay.bookmarkRecipe"));
|
||||
}
|
||||
|
||||
keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_count"), true);
|
||||
keyName = NEIClientConfig.getKeyName("gui.bookmark_count");
|
||||
if (keyName != null) {
|
||||
hotkeys.put(keyName, translate("recipe.overlay.bookmarkAmount"));
|
||||
}
|
||||
|
||||
keyName = NEIClientConfig.getKeyName(NEIClientConfig.getKeyBinding("gui.bookmark_recipe_count"), true);
|
||||
keyName = NEIClientConfig.getKeyName("gui.bookmark_recipe_count");
|
||||
if (keyName != null) {
|
||||
hotkeys.put(keyName, translate("recipe.overlay.bookmarkRecipeAndAmount"));
|
||||
}
|
||||
@@ -151,20 +188,16 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
public void drawItemPresenceOverlay() {
|
||||
final int presenceOverlay = NEIClientConfig.itemPresenceOverlay();
|
||||
final boolean highlightPresentItem = NEIClientConfig.isSlotHighlightPresent();
|
||||
final List<PositionedStack> ingredients = this.handler.getIngredientStacks(recipeIndex);
|
||||
final List<Boolean> itemPresenceCache = ingredientsOverlay();
|
||||
final ItemOverlayFormat format = ItemOverlayFormat.from(presenceOverlay);
|
||||
|
||||
for (int j = 0; j < ingredients.size(); j++) {
|
||||
PositionedStack stack = ingredients.get(j);
|
||||
Boolean isPresent = j < itemPresenceCache.size() ? itemPresenceCache.get(j) : null;
|
||||
|
||||
if (isPresent != null && (highlightPresentItem || !isPresent)) {
|
||||
LayoutManager.drawItemPresenceOverlay(stack.relx, stack.rely, isPresent, presenceOverlay == 2);
|
||||
for (ItemOverlayState overlay : ingredientsOverlay()) {
|
||||
if (highlightPresentItem || !overlay.isPresent()) {
|
||||
overlay.draw(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Boolean> ingredientsOverlay() {
|
||||
protected List<ItemOverlayState> ingredientsOverlay() {
|
||||
List<PositionedStack> ingredients = this.handler.getIngredientStacks(recipeIndex);
|
||||
|
||||
if (this.itemPresenceCache.size() != ingredients.size()) {
|
||||
@@ -177,13 +210,8 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
this.itemPresenceCache.addAll(presenceOverlay(ingredients));
|
||||
}
|
||||
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
for (int j = 0; j < ingredients.size(); j++) {
|
||||
if (j >= this.itemPresenceCache.size() || !this.itemPresenceCache.get(j)) {
|
||||
items.add(ingredients.get(j).item);
|
||||
}
|
||||
}
|
||||
List<ItemStack> items = this.itemPresenceCache.stream().filter(state -> !state.isPresent())
|
||||
.map(state -> state.getSlot().item).collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
if (!items.isEmpty()) {
|
||||
this.missedMaterialsTooltipLineHandler = new ItemsTooltipLineHandler(
|
||||
@@ -220,8 +248,8 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
return this.hasOverlay;
|
||||
}
|
||||
|
||||
private List<Boolean> presenceOverlay(List<PositionedStack> ingredients) {
|
||||
final List<Boolean> itemPresenceSlots = new ArrayList<>();
|
||||
private List<ItemOverlayState> presenceOverlay(List<PositionedStack> ingredients) {
|
||||
final List<ItemOverlayState> itemPresenceSlots = new ArrayList<>();
|
||||
final List<ItemStack> invStacks = this.firstGui.inventorySlots.inventorySlots.stream()
|
||||
.filter(
|
||||
s -> s != null && s.getStack() != null
|
||||
@@ -232,9 +260,9 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
|
||||
for (PositionedStack stack : ingredients) {
|
||||
Optional<ItemStack> used = invStacks.stream().filter(is -> is.stackSize > 0 && stack.contains(is))
|
||||
.findFirst();
|
||||
.findAny();
|
||||
|
||||
itemPresenceSlots.add(used.isPresent());
|
||||
itemPresenceSlots.add(new ItemOverlayState(stack, used.isPresent()));
|
||||
|
||||
if (used.isPresent()) {
|
||||
ItemStack is = used.get();
|
||||
|
||||
Reference in new issue
Block a user