From 19e35f67a73cc137dfc98b72d617d4a8a7d5ce29 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 17 Jul 2023 02:26:36 +0800 Subject: [PATCH] Make displays favorite miniature displays by default --- .../gui/widget/DisplayCompositeWidget.java | 24 ++++++++++++------- .../impl/client/gui/widget/EntryWidget.java | 8 ------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayCompositeWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayCompositeWidget.java index a2a1b915f..a613374c8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayCompositeWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayCompositeWidget.java @@ -27,6 +27,8 @@ import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.favorites.FavoriteEntry; +import me.shedaniel.rei.api.client.favorites.FavoriteEntryType; import me.shedaniel.rei.api.client.gui.config.RecipeBorderType; import me.shedaniel.rei.api.client.gui.drag.DraggedAcceptorResult; import me.shedaniel.rei.api.client.gui.drag.DraggingContext; @@ -82,10 +84,13 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { if (ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(mouse())) { if (ConfigObject.getInstance().getFavoriteKeyCode().matchesKey(keyCode, scanCode)) { - FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget(); - - if (favoritesListWidget != null) { - favoritesListWidget.displayHistory.addDisplay(getBounds().clone(), display.provideInternalDisplay()); + FavoriteEntry favoriteEntry = FavoriteEntryType.registry().get(FavoriteEntryType.DISPLAY) + .fromArgs(display.provideInternalDisplay()) + .get() + .left() + .orElse(null); + if (favoriteEntry != null) { + ConfigObject.getInstance().getFavoriteEntries().add(favoriteEntry); return true; } } @@ -102,10 +107,13 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { if (ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(mouseX, mouseY)) { if (ConfigObject.getInstance().getFavoriteKeyCode().matchesMouse(button)) { - FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget(); - - if (favoritesListWidget != null) { - favoritesListWidget.displayHistory.addDisplay(getBounds().clone(), display.provideInternalDisplay()); + FavoriteEntry favoriteEntry = FavoriteEntryType.registry().get(FavoriteEntryType.DISPLAY) + .fromArgs(display.provideInternalDisplay()) + .get() + .left() + .orElse(null); + if (favoriteEntry != null) { + ConfigObject.getInstance().getFavoriteEntries().add(favoriteEntry); return true; } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java index fe49f39e5..d1c5de30b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java @@ -591,10 +591,6 @@ protected boolean doAction(double mouseX, double mouseY, int button) { } else { ConfigObject.getInstance().getFavoriteEntries().add(favoriteEntry); } - ConfigManager.getInstance().saveConfig(); - FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget(); - if (favoritesListWidget != null) - favoritesListWidget.updateSearch(); return true; } } @@ -673,10 +669,6 @@ public boolean keyPressedIgnoreContains(int keyCode, int scanCode, int modifiers } else { ConfigObject.getInstance().getFavoriteEntries().add(favoriteEntry); } - ConfigManager.getInstance().saveConfig(); - FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget(); - if (favoritesListWidget != null) - favoritesListWidget.updateSearch(); return true; } }