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

add history overlay #3834

Open
wants to merge 1 commit into
base: 1.21.x
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
27 changes: 27 additions & 0 deletions Common/src/main/java/mezz/jei/common/config/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public final class ClientConfig implements IClientConfig {
private final Supplier<Boolean> holdShiftToShowBookmarkTooltipFeaturesEnabled;
private final Supplier<Boolean> dragToRearrangeBookmarksEnabled;

// history
private final Supplier<Boolean> historyEnabled;
private final Supplier<Integer> maxHistoryRows;

// advanced
private final Supplier<Boolean> lowMemorySlowSearchEnabled;
private final Supplier<Boolean> catchRenderErrorsEnabled;
Expand Down Expand Up @@ -112,6 +116,19 @@ public ClientConfig(IConfigSchemaBuilder schema) {
"Drag bookmarks to rearrange them in the list."
);

historyEnabled = bookmarks.addBoolean(
"HistoryEnabled",
false,
"Enable the history overlay."
);
maxHistoryRows = bookmarks.addInteger(
"MaxHistoryRows",
1,
0,
5,
"Max number of rows in the history overlay."
);

IConfigCategoryBuilder advanced = schema.addCategory("advanced");
lowMemorySlowSearchEnabled = advanced.addBoolean(
"LowMemorySlowSearchEnabled",
Expand Down Expand Up @@ -256,6 +273,16 @@ public boolean isDragToRearrangeBookmarksEnabled() {
return dragToRearrangeBookmarksEnabled.get();
}

@Override
public boolean isHistoryEnabled() {
return historyEnabled.get();
}

@Override
public int getMaxHistoryRows() {
return maxHistoryRows.get();
}

@Override
public int getDragDelayMs() {
return dragDelayMs.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public interface IClientConfig {

boolean isDragToRearrangeBookmarksEnabled();

boolean isHistoryEnabled();

int getMaxHistoryRows();

int getDragDelayMs();

int getSmoothScrollRate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import mezz.jei.api.ingredients.ITypedIngredient;
import mezz.jei.api.runtime.IBookmarkOverlay;
import mezz.jei.api.runtime.IScreenHelper;
import mezz.jei.common.Internal;
import mezz.jei.common.config.IClientConfig;
import mezz.jei.common.config.IClientToggleState;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.util.ImmutablePoint2i;
Expand All @@ -27,6 +29,7 @@
import mezz.jei.gui.overlay.IngredientGridWithNavigation;
import mezz.jei.gui.overlay.IngredientListSlot;
import mezz.jei.gui.overlay.ScreenPropertiesCache;
import mezz.jei.gui.overlay.bookmarks.history.HistoryOverlay;
import mezz.jei.gui.overlay.elements.IElement;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
Expand All @@ -51,23 +54,29 @@ public class BookmarkOverlay implements IRecipeFocusSource, IBookmarkOverlay {

// display elements
private final IngredientGridWithNavigation contents;
private final HistoryOverlay historyOverlay;
private final GuiIconToggleButton bookmarkButton;

// data
private final BookmarkList bookmarkList;
private final IClientToggleState toggleState;
private final IClientConfig clientConfig;

public BookmarkOverlay(
BookmarkList bookmarkList,
IngredientGridWithNavigation contents,
HistoryOverlay historyOverlay,
IClientToggleState toggleState,
IClientConfig clientConfig,
IScreenHelper screenHelper,
IInternalKeyMappings keyBindings
) {
this.bookmarkList = bookmarkList;
this.toggleState = toggleState;
this.clientConfig = clientConfig;
this.bookmarkButton = BookmarkButton.create(this, bookmarkList, toggleState, keyBindings);
this.contents = contents;
this.historyOverlay = historyOverlay;
this.screenPropertiesCache = new ScreenPropertiesCache(screenHelper);
this.bookmarkDragManager = new BookmarkDragManager(this);
bookmarkList.addSourceListChangedListener(() -> {
Expand All @@ -77,6 +86,12 @@ public BookmarkOverlay(
.updateScreen(minecraft.screen)
.update();
});
historyOverlay.getHistoryList().addSourceListChangedListener(() -> {
Minecraft minecraft = Minecraft.getInstance();
this.getScreenPropertiesUpdater()
.updateScreen(minecraft.screen)
.update();
});
}

public boolean isListDisplayed() {
Expand All @@ -103,8 +118,17 @@ private void updateBounds(IGuiProperties guiProperties) {
ImmutableRect2i displayArea = getDisplayArea(guiProperties);
Set<ImmutableRect2i> guiExclusionAreas = this.screenPropertiesCache.getGuiExclusionAreas();
ImmutablePoint2i mouseExclusionArea = this.screenPropertiesCache.getMouseExclusionArea();

ImmutableRect2i availableContentsArea = displayArea.cropBottom(BUTTON_SIZE + INNER_PADDING);
if (clientConfig.isHistoryEnabled()) {
int historyRows = clientConfig.getMaxHistoryRows();
availableContentsArea = availableContentsArea.cropBottom(historyRows * HistoryOverlay.SLOT_HEIGHT);
ImmutableRect2i historyArea = displayArea
.insetBy(BORDER_MARGIN)
.moveUp(BUTTON_SIZE + INNER_PADDING)
.keepBottom(historyRows * HistoryOverlay.SLOT_HEIGHT);
this.historyOverlay.updateBounds(historyArea, guiExclusionAreas, mouseExclusionArea);
this.historyOverlay.updateLayout();
}
this.contents.updateBounds(availableContentsArea, guiExclusionAreas, mouseExclusionArea);
this.contents.updateLayout(false);

Expand Down Expand Up @@ -138,6 +162,7 @@ public void drawScreen(Minecraft minecraft, GuiGraphics guiGraphics, int mouseX,
if (isListDisplayed()) {
this.bookmarkDragManager.updateDrag(mouseX, mouseY);
this.contents.draw(minecraft, guiGraphics, mouseX, mouseY, partialTicks);
this.historyOverlay.draw(minecraft, guiGraphics, mouseX, mouseY, partialTicks);
}
if (this.screenPropertiesCache.hasValidScreen()) {
this.bookmarkButton.draw(guiGraphics, mouseX, mouseY, partialTicks);
Expand All @@ -148,6 +173,7 @@ public void drawTooltips(Minecraft minecraft, GuiGraphics guiGraphics, int mouse
if (isListDisplayed()) {
if (!this.bookmarkDragManager.drawDraggedItem(guiGraphics, mouseX, mouseY)) {
this.contents.drawTooltips(minecraft, guiGraphics, mouseX, mouseY);
this.historyOverlay.drawTooltips(minecraft, guiGraphics, mouseX, mouseY);
}
}
if (this.screenPropertiesCache.hasValidScreen()) {
Expand All @@ -158,15 +184,15 @@ public void drawTooltips(Minecraft minecraft, GuiGraphics guiGraphics, int mouse
@Override
public Stream<IClickableIngredientInternal<?>> getIngredientUnderMouse(double mouseX, double mouseY) {
if (isListDisplayed()) {
return this.contents.getIngredientUnderMouse(mouseX, mouseY);
return Stream.concat(this.contents.getIngredientUnderMouse(mouseX, mouseY),this.historyOverlay.getIngredientUnderMouse(mouseX, mouseY));
}
return Stream.empty();
}

@Override
public Stream<IDraggableIngredientInternal<?>> getDraggableIngredientUnderMouse(double mouseX, double mouseY) {
if (isListDisplayed()) {
return this.contents.getDraggableIngredientUnderMouse(mouseX, mouseY);
return Stream.concat(this.contents.getDraggableIngredientUnderMouse(mouseX, mouseY),this.historyOverlay.getDraggableIngredientUnderMouse(mouseX, mouseY));
}
return Stream.empty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package mezz.jei.gui.overlay.bookmarks.history;

import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.gui.input.CombinedRecipeFocusSource;
import mezz.jei.gui.input.IUserInputHandler;
import mezz.jei.gui.input.UserInput;
import mezz.jei.gui.input.handlers.FocusInputHandler;
import net.minecraft.client.gui.screens.Screen;

import java.util.Optional;

public class HistoryInputHandler implements IUserInputHandler {

private final HistoryList historyList;
private final CombinedRecipeFocusSource focusSource;
private final FocusInputHandler focusInputHandler;

public HistoryInputHandler(HistoryList historyList, CombinedRecipeFocusSource focusSource, FocusInputHandler focusInputHandler) {
this.historyList = historyList;
this.focusSource = focusSource;
this.focusInputHandler = focusInputHandler;
}

@Override
public Optional<IUserInputHandler> handleUserInput(Screen screen, UserInput input, IInternalKeyMappings keyBindings) {
Optional<IUserInputHandler> result = focusInputHandler.handleUserInput(screen, input, keyBindings);
if ((input.is(keyBindings.getShowRecipe()) || input.is(keyBindings.getShowUses())) && result.isPresent()) {
focusSource.getIngredientUnderMouse(input, keyBindings)
.filter(clicked -> clicked.getElement().isVisible())
.findFirst()
.ifPresent(clicked -> historyList.add(clicked.getElement()));
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package mezz.jei.gui.overlay.bookmarks.history;

import mezz.jei.gui.overlay.IIngredientGridSource;
import mezz.jei.gui.overlay.elements.IElement;
import org.jetbrains.annotations.Unmodifiable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class HistoryList implements IIngredientGridSource {

private final List<IElement<?>> elements = new ArrayList<>();
private final List<SourceListChangedListener> listeners = new ArrayList<>();
private int maxSize;

public void setMaxSize(int maxSize) {
this.maxSize = maxSize;
}

public void add(IElement<?> element) {
if (elements.contains(element)) {
return;
}
elements.addFirst(element);
if (elements.size() > maxSize) {
elements.removeLast();
}
notifyListeners();
}

public void remove(IElement<?> element) {
elements.remove(element);
notifyListeners();
}

@Override
public @Unmodifiable List<IElement<?>> getElements() {
return Collections.unmodifiableList(elements);
}

@Override
public void addSourceListChangedListener(SourceListChangedListener listener) {
listeners.add(listener);
}

private void notifyListeners() {
for (SourceListChangedListener listener : listeners) {
listener.onSourceListChanged();
}
}
}
Loading