Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/main/java/mezz/jei/autocrafting/RecipeBookmarkGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public boolean addItem(BookmarkItem<?> item) {
}
return false;
}

public boolean addItem(BookmarkItem<?> item, boolean toFront) {
if (super.addItem(item, toFront)) {
chain.addOutput((RecipeBookmarkItem<?>) item); // From canAddItem

return true;
}

return false;
}

public boolean canAddItem(BookmarkItem<?> item) {
return item instanceof RecipeBookmarkItem;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/mezz/jei/bookmarks/BookmarkList.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,12 @@ public boolean moveGroup(BookmarkGroup group, boolean up) {
}
return false;
}

public void swapGroups(int first, int second) {
int firstIndex = getBookmarkIndex(first);
int secondIndex = getBookmarkIndex(second);
Collections.swap(list, firstIndex, secondIndex);
notifyListenersOfChange();
saveBookmarks();
}
}
138 changes: 71 additions & 67 deletions src/main/java/mezz/jei/config/KeyBindings.java
Original file line number Diff line number Diff line change
@@ -1,67 +1,71 @@
package mezz.jei.config;

import com.google.common.collect.ImmutableList;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.settings.KeyConflictContext;
import net.minecraftforge.client.settings.KeyModifier;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import org.lwjgl.input.Keyboard;

import java.util.List;

public final class KeyBindings {
private static final String categoryName = Constants.MOD_ID + " (" + Constants.NAME + ')';

public static final KeyBinding toggleOverlay;
public static final KeyBinding focusSearch;
public static final KeyBinding toggleCheatMode;
public static final KeyBinding toggleEditMode;
public static final KeyBinding showRecipe;
public static final KeyBinding showUses;
public static final KeyBinding recipeBack;
public static final KeyBinding previousPage;
public static final KeyBinding nextPage;
public static final KeyBinding bookmark;
public static final KeyBinding toggleBookmarkOverlay;
public static final KeyBinding crafting;
private static final List<KeyBinding> allBindings;

static {
allBindings = ImmutableList.of(
toggleOverlay = new KeyBinding("key.jei.toggleOverlay", KeyConflictContext.GUI, KeyModifier.CONTROL, Keyboard.KEY_O, categoryName),
focusSearch = new KeyBinding("key.jei.focusSearch", KeyConflictContext.GUI, KeyModifier.CONTROL, Keyboard.KEY_F, categoryName),
toggleCheatMode = new KeyBinding("key.jei.toggleCheatMode", KeyConflictContext.GUI, Keyboard.KEY_NONE, categoryName),
toggleEditMode = new KeyBinding("key.jei.toggleEditMode", KeyConflictContext.GUI, Keyboard.KEY_NONE, categoryName),
showRecipe = new KeyBinding("key.jei.showRecipe", KeyConflictContext.GUI, Keyboard.KEY_R, categoryName),
showUses = new KeyBinding("key.jei.showUses", KeyConflictContext.GUI, Keyboard.KEY_U, categoryName),
recipeBack = new KeyBinding("key.jei.recipeBack", KeyConflictContext.GUI, Keyboard.KEY_BACK, categoryName),
previousPage = new KeyBinding("key.jei.previousPage", KeyConflictContext.GUI, Keyboard.KEY_PRIOR, categoryName),
nextPage = new KeyBinding("key.jei.nextPage", KeyConflictContext.GUI, Keyboard.KEY_NEXT, categoryName),
bookmark = new KeyBinding("key.jei.bookmark", KeyConflictContext.GUI, KeyModifier.NONE, Keyboard.KEY_A, categoryName),
toggleBookmarkOverlay = new KeyBinding("key.hei.toggleBookmarkOverlay", KeyConflictContext.GUI, Keyboard.KEY_NONE, categoryName),
crafting = new KeyBinding("key.hei.crafting", KeyConflictContext.GUI, KeyModifier.SHIFT, Keyboard.KEY_C, categoryName)
);
}

private KeyBindings() {
}

public static void init() {
for (KeyBinding binding : allBindings) {
ClientRegistry.registerKeyBinding(binding);
}
}

public static boolean isInventoryToggleKey(int keyCode) {
return Minecraft.getMinecraft().gameSettings.keyBindInventory.isActiveAndMatches(keyCode);
}

public static boolean isInventoryCloseKey(int keyCode) {
return keyCode == Keyboard.KEY_ESCAPE;
}

public static boolean isEnterKey(int keyCode) {
return keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER;
}
}
package mezz.jei.config;

import com.google.common.collect.ImmutableList;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.settings.KeyConflictContext;
import net.minecraftforge.client.settings.KeyModifier;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import org.lwjgl.input.Keyboard;

import java.util.List;

public final class KeyBindings {
private static final String categoryName = Constants.MOD_ID + " (" + Constants.NAME + ')';

public static final KeyBinding toggleOverlay;
public static final KeyBinding focusSearch;
public static final KeyBinding toggleCheatMode;
public static final KeyBinding toggleEditMode;
public static final KeyBinding showRecipe;
public static final KeyBinding showUses;
public static final KeyBinding recipeBack;
public static final KeyBinding previousPage;
public static final KeyBinding nextPage;
public static final KeyBinding bookmark;
public static final KeyBinding bookmarkToTop;
public static final KeyBinding recipeBookmark;
public static final KeyBinding toggleBookmarkOverlay;
public static final KeyBinding crafting;
private static final List<KeyBinding> allBindings;

static {
allBindings = ImmutableList.of(
toggleOverlay = new KeyBinding("key.jei.toggleOverlay", KeyConflictContext.GUI, KeyModifier.CONTROL, Keyboard.KEY_O, categoryName),
focusSearch = new KeyBinding("key.jei.focusSearch", KeyConflictContext.GUI, KeyModifier.CONTROL, Keyboard.KEY_F, categoryName),
toggleCheatMode = new KeyBinding("key.jei.toggleCheatMode", KeyConflictContext.GUI, Keyboard.KEY_NONE, categoryName),
toggleEditMode = new KeyBinding("key.jei.toggleEditMode", KeyConflictContext.GUI, Keyboard.KEY_NONE, categoryName),
showRecipe = new KeyBinding("key.jei.showRecipe", KeyConflictContext.GUI, Keyboard.KEY_R, categoryName),
showUses = new KeyBinding("key.jei.showUses", KeyConflictContext.GUI, Keyboard.KEY_U, categoryName),
recipeBack = new KeyBinding("key.jei.recipeBack", KeyConflictContext.GUI, Keyboard.KEY_BACK, categoryName),
previousPage = new KeyBinding("key.jei.previousPage", KeyConflictContext.GUI, Keyboard.KEY_PRIOR, categoryName),
nextPage = new KeyBinding("key.jei.nextPage", KeyConflictContext.GUI, Keyboard.KEY_NEXT, categoryName),
bookmark = new KeyBinding("key.jei.bookmark", KeyConflictContext.GUI, KeyModifier.NONE, Keyboard.KEY_A, categoryName),
bookmarkToTop = new KeyBinding("key.hei.bookmarkToTop", KeyConflictContext.GUI, KeyModifier.SHIFT, Keyboard.KEY_A, categoryName),
recipeBookmark = new KeyBinding("key.hei.recipeBookmark", KeyConflictContext.GUI, KeyModifier.CONTROL, Keyboard.KEY_A, categoryName),
toggleBookmarkOverlay = new KeyBinding("key.hei.toggleBookmarkOverlay", KeyConflictContext.GUI, Keyboard.KEY_NONE, categoryName),
crafting = new KeyBinding("key.hei.crafting", KeyConflictContext.GUI, KeyModifier.SHIFT, Keyboard.KEY_C, categoryName)
);
}

private KeyBindings() {
}

public static void init() {
for (KeyBinding binding : allBindings) {
ClientRegistry.registerKeyBinding(binding);
}
}

public static boolean isInventoryToggleKey(int keyCode) {
return Minecraft.getMinecraft().gameSettings.keyBindInventory.isActiveAndMatches(keyCode);
}

public static boolean isInventoryCloseKey(int keyCode) {
return keyCode == Keyboard.KEY_ESCAPE;
}

public static boolean isEnterKey(int keyCode) {
return keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,18 @@ public boolean isMouseOver(int mouseX, int mouseY) {

@Override
public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) {
return !guiScreenHelper.isInGuiExclusionArea(mouseX, mouseY) &&
(this.bookmarkGrid.handleMouseClicked(mouseX, mouseY) || this.navigation.handleMouseClickedButtons(mouseX, mouseY));
return !guiScreenHelper.isInGuiExclusionArea(mouseX, mouseY)
&& (this.groupOrganizer.handleMouseClicked(mouseX, mouseY, mouseButton)
|| this.bookmarkGrid.handleMouseClicked(mouseX, mouseY)
|| this.navigation.handleMouseClickedButtons(mouseX, mouseY));

}

// TODO: Add to interface?
public boolean handleMouseReleased(int mouseX, int mouseY, int mouseButton) {
return this.groupOrganizer.handleMouseReleased(mouseX, mouseY, mouseButton);
}

@Override
public boolean handleMouseScrolled(int mouseX, int mouseY, int scrollDelta) {
IIngredientListElement<?> element = this.getElementUnderMouse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) {
return false;
}

@Override
public boolean handleMouseReleased(int mouseX, int mouseY, int mouseButton) {
if (contents.isMouseOver(mouseX, mouseY)) {
return this.contents.handleMouseReleased(mouseX, mouseY, mouseButton);
}

return false;
}

@Override
public boolean onKeyPressed(char typedChar, int eventKey) {
return isListDisplayed() && this.contents.getBookmarkGroupOrganizer().onKeyPressed(typedChar, eventKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public interface ILeftAreaContent extends IShowsRecipeFocuses, IGhostIngredientD

boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton);

boolean handleMouseReleased(int mouseX, int mouseY, int mouseButton);

boolean onKeyPressed(char typedChar, int eventKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) {
return false;
}

public boolean handleMouseReleased(int mouseX, int mouseY, int mouseButton) {
if (!(canShow || hasContent())) {
return false;
}

if (displayArea.contains(mouseX, mouseY)) {
return contents.get(current).handleMouseReleased(mouseX, mouseY, mouseButton);
}

return false;
}

@Override
public boolean nextPage() {
current++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ public Rectangle getArea() {

@Override
public void accept(Object ingredient) {
accept(ingredient, false);
}

public void accept(Object ingredient, boolean toFront) {
if (ingredient instanceof BookmarkItem) {
BookmarkGroup oldGroup = ((BookmarkItem<?>) ingredient).getGroup();
boolean canAdd = group.addItem((BookmarkItem<?>) ingredient);
boolean canAdd = group.addItem((BookmarkItem<?>) ingredient, toFront);
if (canAdd) {
if (oldGroup != null) {
oldGroup.removeItem((BookmarkItem<?>) ingredient);
Expand All @@ -36,7 +40,7 @@ public void accept(Object ingredient) {
}
} else {
BookmarkItem<?> item = new BookmarkItem<>(ingredient);
if (group.addItem(item)) {
if (group.addItem(item, toFront)) {
if (!Config.isBookmarkOverlayEnabled())
Config.toggleBookmarkEnabled();
Internal.getBookmarkList().saveBookmarks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mezz.jei.autocrafting.RecipeBookmarkGroup;
import mezz.jei.autocrafting.RecipeBookmarkItem;
import mezz.jei.bookmarks.BookmarkGroup;
import mezz.jei.bookmarks.BookmarkItem;
import mezz.jei.bookmarks.BookmarkList;
import mezz.jei.config.Config;
import mezz.jei.config.KeyBindings;
Expand Down Expand Up @@ -37,6 +38,9 @@ public class BookmarkGroupOrganizer {
private Rectangle area = new Rectangle();
private int hoveredGroupId = -1;
private int missingIngredients = 0;
private int draggedGroupId = -1;
private boolean dragWholeGroup = false;
private int prevMouseY = 0;

public BookmarkGroupOrganizer() {
}
Expand Down Expand Up @@ -124,9 +128,15 @@ public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY) {
}
if (mouseX > area.x + BookmarkGridWithNavigation.BOOKMARK_TAB_WIDTH) {
hoveredGroupId = -1;
stopDrag();
return;
}

if (draggedGroupId != -1) {
handleGroupDrag(mouseX, mouseY);
prevMouseY = mouseY;
}

boolean hovered = false;
for (BookmarkGroupDisplay group : groups) {
if (mouseY < group.area.y || mouseY > group.area.y + group.area.height) {
Expand Down Expand Up @@ -224,6 +234,95 @@ public boolean onKeyPressed(char typedChar, int eventKey) {
}
}
}

if (KeyBindings.isInventoryCloseKey(eventKey) || KeyBindings.isInventoryToggleKey(eventKey)) {
stopDrag();
}

return false;
}

public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseX > area.x + BookmarkGridWithNavigation.BOOKMARK_TAB_WIDTH) {
return false;
}

if (draggedGroupId != -1 || mouseButton != 0 || !area.contains(mouseX, mouseY)) {
return false;
}

int groupId = getGroupIndexAt(mouseX, mouseY);
if (groupId != -1) {
draggedGroupId = groupId;
dragWholeGroup = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)
|| Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);

return true;
}

return false;
}

public boolean handleMouseReleased(int mouseX, int mouseY, int mouseButton) {
if (mouseButton != 0 || draggedGroupId == -1) {
return false;
}

stopDrag();
return true;
}

private void stopDrag() {
draggedGroupId = -1;
dragWholeGroup = false;
}

private void handleGroupDrag(int mouseX, int mouseY) {
if (dragWholeGroup) {
int currentGroupId = getGroupForSwap(mouseX, mouseY);
if (currentGroupId == -1 || currentGroupId == draggedGroupId) {
return;
}

BookmarkGroupDisplay currentGroup = groups.get(currentGroupId);
BookmarkGroupDisplay draggedGroup = groups.get(draggedGroupId);
Internal.getBookmarkList().swapGroups(currentGroup.group.id, draggedGroup.group.id);

draggedGroupId = currentGroupId;
} else {
// TODO: Handle group extension by dragging.
// For partial/broken implementation refer to commit 529ee9599efd1f2e964106ec32da364b88b7e13f
}
}

private int getGroupIndexAt(int mouseX, int mouseY) {
for (int i = 0; i < groups.size(); ++i) {
BookmarkGroupDisplay group = groups.get(i);
if (group.area.contains(mouseX, mouseY)) {
return i;
}
}

return -1;
}

private int getGroupForSwap(int mouseX, int mouseY) {
int mouseDeltaY = mouseY - prevMouseY;
if (mouseDeltaY == 0) {
return -1;
}

int sig = Integer.signum(mouseDeltaY);
int candidateId = getGroupIndexAt(mouseX, mouseY);
if (candidateId == -1) {
return -1;
}

BookmarkGroupDisplay candidate = groups.get(candidateId);
if (!candidate.area.contains(mouseX, mouseY + sig * INGREDIENT_HEIGHT)) {
return candidateId;
}

return -1;
}
}
Loading