-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
333 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 35 additions & 4 deletions
39
...main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/SearchFieldWidgetProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,56 @@ | ||
package me.shedaniel.rei.impl.client.gui.overlay.widgets; | ||
|
||
import me.shedaniel.rei.api.client.gui.widgets.TextField; | ||
import com.mojang.blaze3d.platform.Window; | ||
import me.shedaniel.math.Rectangle; | ||
import me.shedaniel.rei.api.client.REIRuntime; | ||
import me.shedaniel.rei.api.client.config.ConfigObject; | ||
import me.shedaniel.rei.api.client.gui.widgets.Widget; | ||
import me.shedaniel.rei.api.client.overlay.ScreenOverlay; | ||
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; | ||
import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; | ||
import me.shedaniel.rei.impl.client.gui.overlay.widgets.search.OverlaySearchField; | ||
import net.minecraft.client.Minecraft; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.function.UnaryOperator; | ||
|
||
public class SearchFieldWidgetProvider implements OverlayWidgetProvider { | ||
private OverlaySearchField searchField; | ||
|
||
@Override | ||
public List<Widget> provide(ScreenOverlay overlay, MenuAccess access, Consumer<TextField> textFieldSink, UnaryOperator<Widget> lateRenderable) { | ||
public List<Widget> provide(ScreenOverlay overlay, MenuAccess access, TextFieldSink textFieldSink, UnaryOperator<Widget> lateRenderable) { | ||
if (searchField == null) { | ||
searchField = new OverlaySearchField(access); | ||
} | ||
|
||
textFieldSink.accept(searchField); | ||
searchField.getBounds().setBounds(getSearchFieldArea(overlay)); | ||
textFieldSink.accept(searchField, searchField::isHighlighting); | ||
return List.of(lateRenderable.apply(searchField)); | ||
} | ||
|
||
private Rectangle getSearchFieldArea(ScreenOverlay overlay) { | ||
int widthRemoved = 1; | ||
if (ConfigObject.getInstance().isCraftableFilterEnabled()) widthRemoved += 22; | ||
if (ConfigObject.getInstance().isLowerConfigButton()) widthRemoved += 22; | ||
return switch (REIRuntime.getInstance().getContextualSearchFieldLocation()) { | ||
case TOP_SIDE -> getTopSideSearchFieldArea(overlay, widthRemoved); | ||
case BOTTOM_SIDE -> getBottomSideSearchFieldArea(overlay, widthRemoved); | ||
case CENTER -> getCenterSearchFieldArea(overlay, widthRemoved); | ||
}; | ||
} | ||
|
||
private Rectangle getTopSideSearchFieldArea(ScreenOverlay overlay, int widthRemoved) { | ||
return new Rectangle(overlay.getBounds().x + 2, 4, overlay.getBounds().width - 6 - widthRemoved, 18); | ||
} | ||
|
||
private Rectangle getBottomSideSearchFieldArea(ScreenOverlay overlay, int widthRemoved) { | ||
Window window = Minecraft.getInstance().getWindow(); | ||
return new Rectangle(overlay.getBounds().x + 2, window.getGuiScaledHeight() - 22, overlay.getBounds().width - 6 - widthRemoved, 18); | ||
} | ||
|
||
private Rectangle getCenterSearchFieldArea(ScreenOverlay overlay, int widthRemoved) { | ||
Window window = Minecraft.getInstance().getWindow(); | ||
Rectangle screenBounds = ScreenRegistry.getInstance().getScreenBounds(Minecraft.getInstance().screen); | ||
return new Rectangle(screenBounds.x, window.getGuiScaledHeight() - 22, screenBounds.width - widthRemoved, 18); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.