aboutsummaryrefslogtreecommitdiff
path: root/RoughlyEnoughItems-runtime/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-11-19 17:09:52 +0800
committershedaniel <daniel@shedaniel.me>2020-11-19 17:09:52 +0800
commit2a4cb0445d3dca1ef67bb8875ac93c2b04fa9b48 (patch)
tree1a2fd33cad1352b91d1b5689ca396b0823e9f386 /RoughlyEnoughItems-runtime/src/main/java
parent883738ac49e261eb1b9cfbd68a14900cb4450cf2 (diff)
downloadRoughlyEnoughItems-2a4cb0445d3dca1ef67bb8875ac93c2b04fa9b48.tar.gz
RoughlyEnoughItems-2a4cb0445d3dca1ef67bb8875ac93c2b04fa9b48.tar.bz2
RoughlyEnoughItems-2a4cb0445d3dca1ef67bb8875ac93c2b04fa9b48.zip
Fix #442
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'RoughlyEnoughItems-runtime/src/main/java')
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java10
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java26
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java23
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java25
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java5
5 files changed, 59 insertions, 30 deletions
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java
index fdfb8d6f8..958158775 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java
@@ -221,7 +221,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl
// favoritesListWidget.favoritePanel.resetRows();
widgets.add(favoritesListWidget);
}
- ENTRY_LIST_WIDGET.updateArea(ScreenHelper.getSearchField() == null ? "" : null);
+ ENTRY_LIST_WIDGET.updateArea(ScreenHelper.getSearchField() == null ? "" : ScreenHelper.getSearchField().getText());
if (ScreenHelper.getSearchField() == null) {
ScreenHelper.setSearchField(new OverlaySearchField(0, 0, 0, 0));
}
@@ -656,7 +656,10 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl
if (overlayMenu != null && overlayMenu.wrappedMenu.mouseScrolled(mouseX, mouseY, amount))
return true;
if (isInside(PointHelper.ofMouse())) {
- if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) {
+ if (ENTRY_LIST_WIDGET.mouseScrolled(mouseX, mouseY, amount)) {
+ return true;
+ }
+ if (!Screen.hasControlDown() && !ConfigObject.getInstance().isEntryListWidgetScrolled()) {
if (amount > 0 && leftButton.isEnabled())
leftButton.onClick();
else if (amount < 0 && rightButton.isEnabled())
@@ -664,8 +667,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl
else
return false;
return true;
- } else if (ENTRY_LIST_WIDGET.mouseScrolled(mouseX, mouseY, amount))
- return true;
+ }
}
if (isNotInExclusionZones(PointHelper.getMouseX(), PointHelper.getMouseY())) {
if (favoritesListWidget != null && favoritesListWidget.mouseScrolled(mouseX, mouseY, amount))
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java
index 37762eef1..a36beea28 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java
@@ -43,11 +43,10 @@ import me.shedaniel.rei.api.*;
import me.shedaniel.rei.api.widgets.Tooltip;
import me.shedaniel.rei.gui.ContainerScreenOverlay;
import me.shedaniel.rei.gui.config.EntryPanelOrdering;
-import me.shedaniel.rei.impl.OptimalEntryStack;
-import me.shedaniel.rei.impl.ScreenHelper;
-import me.shedaniel.rei.impl.SearchArgument;
+import me.shedaniel.rei.impl.*;
import me.shedaniel.rei.utils.CollectionUtils;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.network.chat.Component;
@@ -162,9 +161,18 @@ public class EntryListWidget extends WidgetWithBounds {
@Override
public boolean mouseScrolled(double double_1, double double_2, double double_3) {
- if (ConfigObject.getInstance().isEntryListWidgetScrolled() && bounds.contains(double_1, double_2)) {
- scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true);
- return true;
+ if (bounds.contains(double_1, double_2)) {
+ if (Screen.hasControlDown()) {
+ ConfigObjectImpl config = ConfigManagerImpl.getInstance().getConfig();
+ if (config.setEntrySize(config.getEntrySize() + double_3 * 0.075)) {
+ ConfigManager.getInstance().saveConfig();
+ REIHelper.getInstance().getOverlay().ifPresent(REIOverlay::queueReloadOverlay);
+ return true;
+ }
+ } else if (ConfigObject.getInstance().isEntryListWidgetScrolled()) {
+ scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true);
+ return true;
+ }
}
return super.mouseScrolled(double_1, double_2, double_3);
}
@@ -385,15 +393,13 @@ public class EntryListWidget extends WidgetWithBounds {
return false;
}
- public void updateArea(@Nullable String searchTerm) {
+ public void updateArea(@NotNull String searchTerm) {
this.bounds = ScreenHelper.getItemListArea(ScreenHelper.getLastOverlay().getBounds());
FavoritesListWidget favoritesListWidget = ContainerScreenOverlay.getFavoritesListWidget();
if (favoritesListWidget != null)
favoritesListWidget.updateFavoritesBounds(searchTerm);
- if (searchTerm != null)
+ if (searchTerm != null || allStacks == null || (ConfigObject.getInstance().isFavoritesEnabled() && favoritesListWidget == null))
updateSearch(searchTerm, true);
- else if (allStacks == null || favoritesListWidget == null)
- updateSearch("", true);
else
updateEntriesPosition();
}
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java
index 6d30c4cef..62400a033 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java
@@ -36,21 +36,17 @@ import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
-import me.shedaniel.rei.api.ConfigManager;
-import me.shedaniel.rei.api.ConfigObject;
-import me.shedaniel.rei.api.DisplayHelper;
-import me.shedaniel.rei.api.REIHelper;
+import me.shedaniel.rei.api.*;
import me.shedaniel.rei.api.favorites.FavoriteEntry;
import me.shedaniel.rei.api.favorites.FavoriteMenuEntry;
import me.shedaniel.rei.gui.ContainerScreenOverlay;
import me.shedaniel.rei.gui.modules.Menu;
import me.shedaniel.rei.gui.modules.MenuEntry;
-import me.shedaniel.rei.impl.Animator;
-import me.shedaniel.rei.impl.OptimalEntryStack;
-import me.shedaniel.rei.impl.ScreenHelper;
+import me.shedaniel.rei.impl.*;
import me.shedaniel.rei.utils.CollectionUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.events.GuiEventListener;
+import net.minecraft.client.gui.screens.Screen;
import net.minecraft.util.Mth;
import net.minecraft.util.Tuple;
import org.jetbrains.annotations.ApiStatus;
@@ -108,11 +104,20 @@ public class FavoritesListWidget extends WidgetWithBounds {
@Override
public boolean mouseScrolled(double double_1, double double_2, double double_3) {
if (currentBounds.contains(double_1, double_2)) {
+ if (Screen.hasControlDown()) {
+ ConfigObjectImpl config = ConfigManagerImpl.getInstance().getConfig();
+ if (config.setEntrySize(config.getEntrySize() + double_3 * 0.075)) {
+ ConfigManager.getInstance().saveConfig();
+ REIHelper.getInstance().getOverlay().ifPresent(REIOverlay::queueReloadOverlay);
+ return true;
+ }
+ } else {
// if (favoritePanel.mouseScrolled(double_1, double_2, double_3)) {
// return true;
// }
- scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true);
- return true;
+ scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true);
+ return true;
+ }
}
return super.mouseScrolled(double_1, double_2, double_3);
}
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java
index 27e9d44c7..517df76ba 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java
@@ -48,10 +48,7 @@ import me.shedaniel.clothconfig2.api.ModifierKeyCode;
import me.shedaniel.clothconfig2.gui.entries.KeyCodeEntry;
import me.shedaniel.clothconfig2.impl.EasingMethod;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
-import me.shedaniel.rei.api.ConfigManager;
-import me.shedaniel.rei.api.EntryRegistry;
-import me.shedaniel.rei.api.EntryStack;
-import me.shedaniel.rei.api.REIHelper;
+import me.shedaniel.rei.api.*;
import me.shedaniel.rei.api.favorites.FavoriteEntry;
import me.shedaniel.rei.gui.ContainerScreenOverlay;
import me.shedaniel.rei.gui.TransformingScreen;
@@ -82,6 +79,7 @@ import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.util.Mth;
import net.minecraft.util.Tuple;
+import net.minecraft.world.InteractionResult;
import org.apache.commons.lang3.mutable.MutableLong;
import org.jetbrains.annotations.ApiStatus;
@@ -97,11 +95,13 @@ import static me.sargunvohra.mcmods.autoconfig1u.util.Utils.setUnsafely;
@ApiStatus.Internal
@Environment(EnvType.CLIENT)
public class ConfigManagerImpl implements ConfigManager {
-
+ private static ConfigManagerImpl instance;
private boolean craftableOnly;
private final Gson gson = new GsonBuilder().create();
+ private ConfigObjectImpl object;
public ConfigManagerImpl() {
+ ConfigManagerImpl.instance = this;
this.craftableOnly = false;
Jankson jankson = Jankson.builder().build();
AutoConfig.register(ConfigObjectImpl.class, (definition, configClass) -> new JanksonConfigSerializer<>(definition, configClass, Jankson.builder().registerPrimitiveTypeAdapter(InputConstants.Key.class, it -> {
@@ -178,6 +178,10 @@ public class ConfigManagerImpl implements ConfigManager {
RoughlyEnoughItemsCore.LOGGER.info("Config loaded.");
}
+ public static ConfigManagerImpl getInstance() {
+ return instance;
+ }
+
@Override
public void saveConfig() {
if (getConfig().getFavoriteEntries() != null)
@@ -191,12 +195,19 @@ public class ConfigManagerImpl implements ConfigManager {
if (getConfig().getFilteringRules().stream().noneMatch(filteringRule -> filteringRule instanceof ManualFilteringRule)) {
getConfig().getFilteringRules().add(new ManualFilteringRule());
}
- ((me.sargunvohra.mcmods.autoconfig1u.ConfigManager<ConfigObjectImpl>) AutoConfig.getConfigHolder(ConfigObjectImpl.class)).save();
+ AutoConfig.getConfigHolder(ConfigObjectImpl.class).save();
+ AutoConfig.getConfigHolder(ConfigObjectImpl.class).registerLoadListener((configHolder, configObject) -> {
+ object = configObject;
+ return InteractionResult.PASS;
+ });
}
@Override
public ConfigObjectImpl getConfig() {
- return AutoConfig.getConfigHolder(ConfigObjectImpl.class).getConfig();
+ if (object == null) {
+ object = AutoConfig.getConfigHolder(ConfigObjectImpl.class).getConfig();
+ }
+ return object;
}
@Override
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java
index 52352366a..d6e3156dc 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java
@@ -286,6 +286,11 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
return advanced.accessibility.entrySize;
}
+ public boolean setEntrySize(double entrySize) {
+ double original = advanced.accessibility.entrySize;
+ return (advanced.accessibility.entrySize = Mth.clamp(entrySize, 0.25, 4)) != original;
+ }
+
@Override
public boolean isUsingCompactTabs() {
return advanced.accessibility.useCompactTabs;