2-way JEI sync on search boxes (#2707)
* 2-way JEI sync on search boxes * Push two-way JEI sync into separate search option
This commit is contained in:
@@ -36,6 +36,8 @@ public interface IGrid {
|
|||||||
int SEARCH_BOX_MODE_NORMAL_AUTOSELECTED = 1;
|
int SEARCH_BOX_MODE_NORMAL_AUTOSELECTED = 1;
|
||||||
int SEARCH_BOX_MODE_JEI_SYNCHRONIZED = 2;
|
int SEARCH_BOX_MODE_JEI_SYNCHRONIZED = 2;
|
||||||
int SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED = 3;
|
int SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED = 3;
|
||||||
|
int SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY = 4;
|
||||||
|
int SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY_AUTOSELECTED = 5;
|
||||||
|
|
||||||
int VIEW_TYPE_NORMAL = 0;
|
int VIEW_TYPE_NORMAL = 0;
|
||||||
int VIEW_TYPE_NON_CRAFTABLES = 1;
|
int VIEW_TYPE_NON_CRAFTABLES = 1;
|
||||||
@@ -255,11 +257,22 @@ public interface IGrid {
|
|||||||
return mode == SEARCH_BOX_MODE_NORMAL ||
|
return mode == SEARCH_BOX_MODE_NORMAL ||
|
||||||
mode == SEARCH_BOX_MODE_NORMAL_AUTOSELECTED ||
|
mode == SEARCH_BOX_MODE_NORMAL_AUTOSELECTED ||
|
||||||
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED ||
|
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED ||
|
||||||
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED;
|
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED ||
|
||||||
|
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY ||
|
||||||
|
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY_AUTOSELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isSearchBoxModeWithAutoselection(int mode) {
|
static boolean isSearchBoxModeWithAutoselection(int mode) {
|
||||||
return mode == SEARCH_BOX_MODE_NORMAL_AUTOSELECTED || mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED;
|
return mode == SEARCH_BOX_MODE_NORMAL_AUTOSELECTED ||
|
||||||
|
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED ||
|
||||||
|
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY_AUTOSELECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean doesSearchBoxModeUseJEI(int mode) {
|
||||||
|
return mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED ||
|
||||||
|
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED ||
|
||||||
|
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY ||
|
||||||
|
mode == SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY_AUTOSELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isValidSortingType(int type) {
|
static boolean isValidSortingType(int type) {
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.refinedmods.refinedstorage.screen.widget;
|
package com.refinedmods.refinedstorage.screen.widget;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.refinedmods.refinedstorage.RSKeyBindings;
|
import com.refinedmods.refinedstorage.RSKeyBindings;
|
||||||
import com.refinedmods.refinedstorage.api.network.grid.IGrid;
|
import com.refinedmods.refinedstorage.api.network.grid.IGrid;
|
||||||
import com.refinedmods.refinedstorage.integration.jei.JeiIntegration;
|
import com.refinedmods.refinedstorage.integration.jei.JeiIntegration;
|
||||||
@@ -29,11 +30,21 @@ public class SearchWidget extends TextFieldWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateJei() {
|
public void updateJei() {
|
||||||
if (JeiIntegration.isLoaded() && (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED || mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED)) {
|
if (canSyncToJEINow()) {
|
||||||
RSJeiPlugin.getRuntime().getIngredientFilter().setFilterText(getText());
|
RSJeiPlugin.getRuntime().getIngredientFilter().setFilterText(getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean canSyncToJEINow() {
|
||||||
|
return IGrid.doesSearchBoxModeUseJEI(this.mode) && JeiIntegration.isLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canSyncFromJEINow() {
|
||||||
|
return (this.mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY ||
|
||||||
|
this.mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY_AUTOSELECTED)
|
||||||
|
&& JeiIntegration.isLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
|
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
|
||||||
boolean wasFocused = isFocused();
|
boolean wasFocused = isFocused();
|
||||||
@@ -148,5 +159,24 @@ public class SearchWidget extends TextFieldWidget {
|
|||||||
|
|
||||||
this.setCanLoseFocus(!IGrid.isSearchBoxModeWithAutoselection(mode));
|
this.setCanLoseFocus(!IGrid.isSearchBoxModeWithAutoselection(mode));
|
||||||
this.setFocused(IGrid.isSearchBoxModeWithAutoselection(mode));
|
this.setFocused(IGrid.isSearchBoxModeWithAutoselection(mode));
|
||||||
|
|
||||||
|
if (canSyncFromJEINow()) {
|
||||||
|
setTextFromJEI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTextFromJEI() {
|
||||||
|
final String filterText = RSJeiPlugin.getRuntime().getIngredientFilter().getFilterText();
|
||||||
|
if (!getText().equals(filterText)) {
|
||||||
|
setText(filterText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderButton(MatrixStack p_230431_1_, int p_230431_2_, int p_230431_3_, float p_230431_4_) {
|
||||||
|
if (canSyncFromJEINow() && RSJeiPlugin.getRuntime().getIngredientListOverlay().hasKeyboardFocus()) {
|
||||||
|
setTextFromJEI();
|
||||||
|
}
|
||||||
|
super.renderButton(p_230431_1_, p_230431_2_, p_230431_3_, p_230431_4_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,49 +1,21 @@
|
|||||||
package com.refinedmods.refinedstorage.screen.widget.sidebutton;
|
package com.refinedmods.refinedstorage.screen.widget.sidebutton;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.refinedmods.refinedstorage.api.network.grid.IGrid;
|
|
||||||
import com.refinedmods.refinedstorage.integration.jei.JeiIntegration;
|
|
||||||
import com.refinedmods.refinedstorage.screen.CrafterManagerScreen;
|
import com.refinedmods.refinedstorage.screen.CrafterManagerScreen;
|
||||||
import com.refinedmods.refinedstorage.tile.CrafterManagerTile;
|
import com.refinedmods.refinedstorage.tile.CrafterManagerTile;
|
||||||
import com.refinedmods.refinedstorage.tile.data.TileDataManager;
|
import com.refinedmods.refinedstorage.tile.data.TileDataManager;
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
|
|
||||||
public class CrafterManagerSearchBoxModeSideButton extends SideButton {
|
public class CrafterManagerSearchBoxModeSideButton extends SearchBoxModeSideButton {
|
||||||
public CrafterManagerSearchBoxModeSideButton(CrafterManagerScreen screen) {
|
public CrafterManagerSearchBoxModeSideButton(CrafterManagerScreen screen) {
|
||||||
super(screen);
|
super(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTooltip() {
|
protected int getSearchBoxMode() {
|
||||||
return I18n.format("sidebutton.refinedstorage.grid.search_box_mode") + "\n" + TextFormatting.GRAY + I18n.format("sidebutton.refinedstorage.grid.search_box_mode." + ((CrafterManagerScreen) screen).getCrafterManager().getSearchBoxMode());
|
return ((CrafterManagerScreen) screen).getCrafterManager().getSearchBoxMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderButtonIcon(MatrixStack matrixStack, int x, int y) {
|
protected void setSearchBoxMode(int mode) {
|
||||||
int mode = ((CrafterManagerScreen) screen).getCrafterManager().getSearchBoxMode();
|
|
||||||
|
|
||||||
screen.blit(matrixStack, x, y, mode == IGrid.SEARCH_BOX_MODE_NORMAL_AUTOSELECTED || mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED ? 16 : 0, 96, 16, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPress() {
|
|
||||||
int mode = ((CrafterManagerScreen) screen).getCrafterManager().getSearchBoxMode();
|
|
||||||
|
|
||||||
if (mode == IGrid.SEARCH_BOX_MODE_NORMAL) {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_NORMAL_AUTOSELECTED;
|
|
||||||
} else if (mode == IGrid.SEARCH_BOX_MODE_NORMAL_AUTOSELECTED) {
|
|
||||||
if (JeiIntegration.isLoaded()) {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED;
|
|
||||||
} else {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_NORMAL;
|
|
||||||
}
|
|
||||||
} else if (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED) {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED;
|
|
||||||
} else if (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED) {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
TileDataManager.setParameter(CrafterManagerTile.SEARCH_BOX_MODE, mode);
|
TileDataManager.setParameter(CrafterManagerTile.SEARCH_BOX_MODE, mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,49 +1,20 @@
|
|||||||
package com.refinedmods.refinedstorage.screen.widget.sidebutton;
|
package com.refinedmods.refinedstorage.screen.widget.sidebutton;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.refinedmods.refinedstorage.api.network.grid.IGrid;
|
|
||||||
import com.refinedmods.refinedstorage.integration.jei.JeiIntegration;
|
|
||||||
import com.refinedmods.refinedstorage.screen.grid.GridScreen;
|
import com.refinedmods.refinedstorage.screen.grid.GridScreen;
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
|
|
||||||
public class GridSearchBoxModeSideButton extends SideButton {
|
public class GridSearchBoxModeSideButton extends SearchBoxModeSideButton {
|
||||||
public GridSearchBoxModeSideButton(GridScreen screen) {
|
public GridSearchBoxModeSideButton(GridScreen screen) {
|
||||||
super(screen);
|
super(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTooltip() {
|
protected int getSearchBoxMode() {
|
||||||
return I18n.format("sidebutton.refinedstorage.grid.search_box_mode") + "\n" + TextFormatting.GRAY + I18n.format("sidebutton.refinedstorage.grid.search_box_mode." + ((GridScreen) screen).getGrid().getSearchBoxMode());
|
return ((GridScreen) screen).getGrid().getSearchBoxMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderButtonIcon(MatrixStack matrixStack, int x, int y) {
|
protected void setSearchBoxMode(int mode) {
|
||||||
int mode = ((GridScreen) screen).getGrid().getSearchBoxMode();
|
|
||||||
|
|
||||||
screen.blit(matrixStack, x, y, mode == IGrid.SEARCH_BOX_MODE_NORMAL_AUTOSELECTED || mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED ? 16 : 0, 96, 16, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPress() {
|
|
||||||
int mode = ((GridScreen) screen).getGrid().getSearchBoxMode();
|
|
||||||
|
|
||||||
if (mode == IGrid.SEARCH_BOX_MODE_NORMAL) {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_NORMAL_AUTOSELECTED;
|
|
||||||
} else if (mode == IGrid.SEARCH_BOX_MODE_NORMAL_AUTOSELECTED) {
|
|
||||||
if (JeiIntegration.isLoaded()) {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED;
|
|
||||||
} else {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_NORMAL;
|
|
||||||
}
|
|
||||||
} else if (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED) {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED;
|
|
||||||
} else if (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED) {
|
|
||||||
mode = IGrid.SEARCH_BOX_MODE_NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
((GridScreen) screen).getGrid().onSearchBoxModeChanged(mode);
|
((GridScreen) screen).getGrid().onSearchBoxModeChanged(mode);
|
||||||
|
|
||||||
((GridScreen) screen).getSearchField().setMode(mode);
|
((GridScreen) screen).getSearchField().setMode(mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,58 @@
|
|||||||
|
package com.refinedmods.refinedstorage.screen.widget.sidebutton;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
|
import com.refinedmods.refinedstorage.api.network.grid.IGrid;
|
||||||
|
import com.refinedmods.refinedstorage.integration.jei.JeiIntegration;
|
||||||
|
import com.refinedmods.refinedstorage.screen.BaseScreen;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class SearchBoxModeSideButton extends SideButton {
|
||||||
|
private static final List<Integer> MODE_ROTATION = Arrays.asList(
|
||||||
|
IGrid.SEARCH_BOX_MODE_NORMAL,
|
||||||
|
IGrid.SEARCH_BOX_MODE_NORMAL_AUTOSELECTED,
|
||||||
|
IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED,
|
||||||
|
IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED,
|
||||||
|
IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY,
|
||||||
|
IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_2WAY_AUTOSELECTED,
|
||||||
|
IGrid.SEARCH_BOX_MODE_NORMAL
|
||||||
|
);
|
||||||
|
|
||||||
|
private static int nextMode(int oldMode) {
|
||||||
|
return MODE_ROTATION.get(MODE_ROTATION.indexOf(oldMode) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SearchBoxModeSideButton(BaseScreen<?> screen) {
|
||||||
|
super(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTooltip() {
|
||||||
|
return I18n.format("sidebutton.refinedstorage.grid.search_box_mode") + "\n" + TextFormatting.GRAY + I18n.format("sidebutton.refinedstorage.grid.search_box_mode." + getSearchBoxMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderButtonIcon(MatrixStack matrixStack, int x, int y) {
|
||||||
|
int mode = getSearchBoxMode();
|
||||||
|
|
||||||
|
screen.blit(matrixStack, x, y, IGrid.isSearchBoxModeWithAutoselection(mode) ? 16 : 0, 96, 16, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPress() {
|
||||||
|
int mode = nextMode(getSearchBoxMode());
|
||||||
|
|
||||||
|
if (IGrid.doesSearchBoxModeUseJEI(mode) && !JeiIntegration.isLoaded()) {
|
||||||
|
mode = IGrid.SEARCH_BOX_MODE_NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSearchBoxMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract int getSearchBoxMode();
|
||||||
|
|
||||||
|
protected abstract void setSearchBoxMode(int mode);
|
||||||
|
}
|
@@ -178,6 +178,8 @@
|
|||||||
"sidebutton.refinedstorage.grid.search_box_mode.1": "Normal (autoselected)",
|
"sidebutton.refinedstorage.grid.search_box_mode.1": "Normal (autoselected)",
|
||||||
"sidebutton.refinedstorage.grid.search_box_mode.2": "JEI synchronized",
|
"sidebutton.refinedstorage.grid.search_box_mode.2": "JEI synchronized",
|
||||||
"sidebutton.refinedstorage.grid.search_box_mode.3": "JEI synchronized (autoselected)",
|
"sidebutton.refinedstorage.grid.search_box_mode.3": "JEI synchronized (autoselected)",
|
||||||
|
"sidebutton.refinedstorage.grid.search_box_mode.4": "JEI synchronized (two-way)",
|
||||||
|
"sidebutton.refinedstorage.grid.search_box_mode.5": "JEI synchronized (two-way autoselected)",
|
||||||
"sidebutton.refinedstorage.grid.size": "Size",
|
"sidebutton.refinedstorage.grid.size": "Size",
|
||||||
"sidebutton.refinedstorage.grid.size.0": "Stretch",
|
"sidebutton.refinedstorage.grid.size.0": "Stretch",
|
||||||
"sidebutton.refinedstorage.grid.size.1": "Small",
|
"sidebutton.refinedstorage.grid.size.1": "Small",
|
||||||
|
Reference in New Issue
Block a user