Skip to content

Commit

Permalink
Allow configurable search sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyploszaj committed Jan 9, 2025
1 parent e93a7f9 commit 70e2c88
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
4 changes: 4 additions & 0 deletions xplat/src/main/java/dev/emi/emi/config/EmiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public class EmiConfig {
public static IndexSource indexSource = IndexSource.CREATIVE;

@ConfigGroup("general.search")
@Comment("Which sidebar should be searched using the search bar.")
@ConfigValue("general.search-sidebar")
public static SidebarSide searchSidebar = SidebarSide.RIGHT;

@Comment("Whether normal search queries should include the tooltip.")
@ConfigValue("general.search-tooltip-by-default")
public static boolean searchTooltipByDefault = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.emi.emi.api.EmiApi;
import dev.emi.emi.jemi.JemiUtil;
import dev.emi.emi.screen.EmiScreenManager;
import dev.emi.emi.screen.EmiScreenManager.SidebarPanel;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.runtime.IIngredientFilter;

Expand All @@ -23,7 +24,11 @@ public String getFilterText() {

@Override
public <T> List<T> getFilteredIngredients(IIngredientType<T> ingredientType) {
return EmiScreenManager.getSearchPanel().space.getStacks().stream()
SidebarPanel search = EmiScreenManager.getSearchPanel();
if (search == null || search.space == null) {
return List.of();
}
return search.space.getStacks().stream()
.map(i -> JemiUtil.getTyped(i.getEmiStacks().get(0)))
.filter(Optional::isPresent).map(Optional::get)
.map(i -> i.getIngredient(ingredientType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public static List<Bounds> getExclusion(EmiScreenBase base) {
// EMI buttons
list.add(new Bounds(0, screen.height - 22, base.bounds().left(), 22));
// Search bar
list.add(new Bounds(EmiScreenManager.search.x - 1, EmiScreenManager.search.y - 1, EmiScreenManager.search.getWidth() + 2, EmiScreenManager.search.getHeight() + 2));
if (EmiScreenManager.search.isVisible()) {
list.add(new Bounds(EmiScreenManager.search.x - 1, EmiScreenManager.search.y - 1, EmiScreenManager.search.getWidth() + 2, EmiScreenManager.search.getHeight() + 2));
}
try {
if (fromClass.containsKey(screen.getClass())) {
for (EmiExclusionArea exclusion : fromClass.get(screen.getClass())) {
Expand Down
30 changes: 21 additions & 9 deletions xplat/src/main/java/dev/emi/emi/screen/EmiScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private static Bounds constrainBounds(List<Bounds> exclusion, Bounds bounds, Scr
for (int i = 0; i < exclusion.size(); i++) {
Bounds overlap = exclusion.get(i).overlap(bounds);
if (!overlap.empty() && !bounds.empty()) {
if (overlap.top() < bounds.top() + ENTRY_SIZE + headerOffset || overlap.width() >= bounds.width() / 2
if (overlap.top() < bounds.top() + ENTRY_SIZE + headerOffset || overlap.width() >= bounds.width() * 2 / 3
|| overlap.height() >= bounds.height() / 3) {
int widthFactor = overlap.width() * 10 / bounds.width();
int heightFactor = overlap.height() * 10 / bounds.height();
Expand Down Expand Up @@ -402,8 +402,9 @@ private static Bounds constrainBounds(List<Bounds> exclusion, Bounds bounds, Scr
}

public static void focusSearchSidebarType(SidebarType type) {
if (getSearchPanel().supportsType(type)) {
getSearchPanel().setType(type);
SidebarPanel search = getSearchPanel();
if (search != null && search.supportsType(type)) {
search.setType(type);
}
}

Expand Down Expand Up @@ -486,7 +487,7 @@ public static SidebarPanel getSearchPanel() {
return panel;
}
}
return panels.get(1);
return null;
}

public static void toggleSidebarType(SidebarType type) {
Expand All @@ -503,7 +504,11 @@ public static void toggleSidebarType(SidebarType type) {
}

public static List<? extends EmiIngredient> getSearchSource() {
return EmiSidebars.getStacks(getSearchPanel().getType());
SidebarPanel search = getSearchPanel();
if (search == null) {
return List.of();
}
return EmiSidebars.getStacks(search.getType());
}

public static EmiStackInteraction getHoveredStack(int mouseX, int mouseY, boolean notClick) {
Expand Down Expand Up @@ -885,11 +890,18 @@ public static void addWidgets(Screen screen) {
search.y = screen.height - 21;
search.setWidth(160);
} else {
search.x = panels.get(1).space.tx;
search.y = screen.height - 21;
search.setWidth(panels.get(1).space.tw * ENTRY_SIZE);
if (EmiConfig.searchSidebar == SidebarSide.RIGHT) {
search.x = panels.get(1).space.tx;
search.y = screen.height - 21;
search.setWidth(panels.get(1).space.tw * ENTRY_SIZE);
} else {
search.x = panels.get(0).space.tx;
search.y = screen.height - 21 - 21;
search.setWidth(panels.get(0).space.tw * ENTRY_SIZE);
}
}
EmiPort.focus(search, false);
search.setVisible(EmiConfig.searchSidebar != SidebarSide.NONE);

emi.x = 2;
emi.y = screen.height - 22;
Expand Down Expand Up @@ -1544,7 +1556,7 @@ private void wrapPage() {
}

public boolean isSearch() {
return side == SidebarSide.RIGHT;
return side == EmiConfig.searchSidebar;
}

public void updateWidgetPosition() {
Expand Down
1 change: 1 addition & 0 deletions xplat/src/main/resources/assets/emi/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"config.emi.general.cheat_mode": "Cheat Mode",
"config.emi.general.help_level": "Help Level",
"config.emi.general.index_source": "Index Source",
"config.emi.general.search_sidebar": "Search Sidebar",
"config.emi.general.search_tooltip_by_default": "Search Tooltip by Default",
"config.emi.general.search_mod_name_by_default": "Search Mod Name by Default",
"config.emi.general.search_tags_by_default": "Search Tags by Default",
Expand Down

0 comments on commit 70e2c88

Please sign in to comment.