mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-22 05:12:16 +00:00
Better video settings search (#1254)
This commit is contained in:
1 parent
e9257b8739
commit
d2730ccca8
10 files changed
+311
-160
No files matched your search
-12
@@ -5,19 +5,7 @@ import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
|
||||
public interface OptionExtended<T> extends Option<T> {
|
||||
|
||||
boolean isHighlight();
|
||||
|
||||
void setHighlight(boolean highlight);
|
||||
|
||||
Dim2i getDim2i();
|
||||
|
||||
void setDim2i(Dim2i dim2i);
|
||||
|
||||
Dim2i getParentDimension();
|
||||
|
||||
void setParentDimension(Dim2i dim2i);
|
||||
|
||||
boolean isSelected();
|
||||
|
||||
void setSelected(boolean selected);
|
||||
}
|
||||
+86
-38
@@ -14,6 +14,7 @@ import me.jellysquid.mods.sodium.client.gui.SodiumGameOptionPages;
|
||||
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.Option;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionFlag;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionGroup;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget;
|
||||
@@ -28,6 +29,7 @@ import org.lwjgl.input.Keyboard;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ReeseSodiumVideoOptionsScreen extends SodiumOptionsGUI {
|
||||
@@ -39,7 +41,6 @@ public class ReeseSodiumVideoOptionsScreen extends SodiumOptionsGUI {
|
||||
private static final AtomicReference<Integer> optionPageScrollBarOffset = new AtomicReference<>(0);
|
||||
|
||||
private static final AtomicReference<String> lastSearch = new AtomicReference<>("");
|
||||
private static final AtomicReference<Integer> lastSearchIndex = new AtomicReference<>(0);
|
||||
|
||||
private AbstractFrame frame;
|
||||
private SearchTextFieldComponent searchTextField;
|
||||
@@ -51,8 +52,14 @@ public class ReeseSodiumVideoOptionsScreen extends SodiumOptionsGUI {
|
||||
// Hackalicious! Rebuild UI
|
||||
@Override
|
||||
public void rebuildGUI() {
|
||||
// Preserve search focus state across rebuilds
|
||||
boolean wasSearchFocused = this.searchTextField != null && this.searchTextField.isFocused();
|
||||
this.children.clear();
|
||||
this.initGui();
|
||||
if (wasSearchFocused && this.searchTextField != null) {
|
||||
this.searchTextField.setFocused(true);
|
||||
this.setFocused(this.searchTextField);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,62 +105,85 @@ public class ReeseSodiumVideoOptionsScreen extends SodiumOptionsGUI {
|
||||
this.applyButton = new FlatButtonWidget(applyButtonDim, "Apply", this::applyChanges);
|
||||
this.closeButton = new FlatButtonWidget(closeButtonDim, "Close", this::onClose);
|
||||
|
||||
// Pre-compute button text and widths to avoid duplicate calculations
|
||||
final String irisText = Iris.enabled ? I18n.format(IrisApi.getInstance().getMainScreenLanguageKey()) : null;
|
||||
final int irisWidth = irisText != null ? this.mc.fontRenderer.getStringWidth(irisText) : 0;
|
||||
final String fontConfigText = AngelicaConfig.enableFontRenderer ? I18n.format("options.angelica.fontconfig") : null;
|
||||
final int fontConfigWidth = fontConfigText != null ? this.mc.fontRenderer.getStringWidth(fontConfigText) : 0;
|
||||
|
||||
// Total width reserved for buttons (used for search field sizing)
|
||||
int buttonsWidth = 0;
|
||||
if (irisText != null) buttonsWidth += irisWidth + 12;
|
||||
if (fontConfigText != null) buttonsWidth += fontConfigWidth + 14;
|
||||
|
||||
// Create search field before parentBasicFrameBuilder (which needs the predicate)
|
||||
Dim2i searchTextFieldDim = new Dim2i(tabFrameDim.getOriginX(), tabFrameDim.getOriginY() - 26, tabFrameDim.getWidth() - buttonsWidth, 20);
|
||||
this.searchTextField = new SearchTextFieldComponent(searchTextFieldDim, this.pages, tabFrameSelectedTab,
|
||||
tabFrameScrollBarOffset, optionPageScrollBarOffset, tabFrameDim.getHeight(), this, lastSearch);
|
||||
|
||||
basicFrameBuilder = this.parentBasicFrameBuilder(basicFrameDim, tabFrameDim);
|
||||
|
||||
int cumulativeXShift = 0;
|
||||
|
||||
if (Iris.enabled) {
|
||||
//int size = this.client.textRenderer.getWidth(new TranslatableText(IrisApi.getInstance().getMainScreenLanguageKey()));
|
||||
final String irisText = I18n.format(IrisApi.getInstance().getMainScreenLanguageKey());
|
||||
final int size = this.mc.fontRenderer.getStringWidth(irisText);
|
||||
final Dim2i shaderPackButtonDim = new Dim2i(tabFrameDim.getLimitX() - size - 10, tabFrameDim.getOriginY() - 26, 10 + size, 20);
|
||||
cumulativeXShift += size + 12;
|
||||
|
||||
// Add buttons after basicFrameBuilder is created
|
||||
int buttonX = tabFrameDim.getLimitX();
|
||||
if (irisText != null) {
|
||||
buttonX -= irisWidth + 10;
|
||||
final Dim2i shaderPackButtonDim = new Dim2i(buttonX, tabFrameDim.getOriginY() - 26, irisWidth + 10, 20);
|
||||
final FlatButtonWidget shaderPackButton = new FlatButtonWidget(shaderPackButtonDim, irisText, () -> mc.displayGuiScreen(new ShaderPackScreen(this)));
|
||||
basicFrameBuilder.addChild(dim -> shaderPackButton);
|
||||
buttonX -= 2; // gap between buttons
|
||||
}
|
||||
|
||||
if (AngelicaConfig.enableFontRenderer) {
|
||||
final String fontConfigText = I18n.format("options.angelica.fontconfig");
|
||||
final int size = this.mc.fontRenderer.getStringWidth(fontConfigText);
|
||||
final Dim2i fontConfigButtonDim = new Dim2i(tabFrameDim.getLimitX() - size - 12 - cumulativeXShift, tabFrameDim.getOriginY() - 26, 12 + size, 20);
|
||||
cumulativeXShift += size + 14;
|
||||
|
||||
if (fontConfigText != null) {
|
||||
buttonX -= fontConfigWidth + 12;
|
||||
final Dim2i fontConfigButtonDim = new Dim2i(buttonX, tabFrameDim.getOriginY() - 26, fontConfigWidth + 12, 20);
|
||||
final FlatButtonWidget fontConfigButton = new FlatButtonWidget(fontConfigButtonDim, fontConfigText, () -> mc.displayGuiScreen(new FontConfigScreen(this)));
|
||||
basicFrameBuilder.addChild(dim -> fontConfigButton);
|
||||
}
|
||||
|
||||
Dim2i searchTextFieldDim = new Dim2i(tabFrameDim.getOriginX(), tabFrameDim.getOriginY() - 26, tabFrameDim.getWidth() - cumulativeXShift, 20);
|
||||
this.searchTextField = new SearchTextFieldComponent(searchTextFieldDim, this.pages, tabFrameSelectedTab,
|
||||
tabFrameScrollBarOffset, optionPageScrollBarOffset, tabFrameDim.getHeight(), this, lastSearch, lastSearchIndex);
|
||||
|
||||
basicFrameBuilder.addChild(dim -> this.searchTextField);
|
||||
|
||||
return basicFrameBuilder;
|
||||
}
|
||||
|
||||
public BasicFrame.Builder parentBasicFrameBuilder(Dim2i parentBasicFrameDim, Dim2i tabFrameDim) {
|
||||
return BasicFrame.createBuilder()
|
||||
final Predicate<Option<?>> optionPredicate = searchTextField.getOptionPredicate();
|
||||
final boolean noResults = searchTextField.hasNoResults();
|
||||
|
||||
BasicFrame.Builder builder = BasicFrame.createBuilder()
|
||||
.setDimension(parentBasicFrameDim)
|
||||
.shouldRenderOutline(false)
|
||||
.addChild(parentDim -> TabFrame.createBuilder()
|
||||
.setDimension(tabFrameDim)
|
||||
.shouldRenderOutline(false)
|
||||
.setTabSectionScrollBarOffset(tabFrameScrollBarOffset)
|
||||
.setTabSectionSelectedTab(tabFrameSelectedTab)
|
||||
.addTabs(tabs -> this.pages
|
||||
.stream()
|
||||
.filter(page -> !page.getGroups().isEmpty())
|
||||
.forEach(page -> tabs.add(Tab.createBuilder().from(page, optionPageScrollBarOffset)))
|
||||
)
|
||||
.onSetTab(() -> {
|
||||
optionPageScrollBarOffset.set(0);
|
||||
})
|
||||
.build()
|
||||
)
|
||||
.shouldRenderOutline(false);
|
||||
|
||||
if (noResults) {
|
||||
// Show "No matching options" message centered in the tab area
|
||||
final String noResultsText = I18n.format("options.angelica.search.no_results");
|
||||
builder.addChild(dim -> new me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget() {
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
int textWidth = mc.fontRenderer.getStringWidth(noResultsText);
|
||||
int x = tabFrameDim.getCenterX() - textWidth / 2;
|
||||
int y = tabFrameDim.getCenterY();
|
||||
drawString(noResultsText, x, y, 0x808080);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
builder.addChild(parentDim -> TabFrame.createBuilder()
|
||||
.setDimension(tabFrameDim)
|
||||
.shouldRenderOutline(false)
|
||||
.setTabSectionScrollBarOffset(tabFrameScrollBarOffset)
|
||||
.setTabSectionSelectedTab(tabFrameSelectedTab)
|
||||
.addTabs(tabs -> this.pages
|
||||
.stream()
|
||||
.filter(this::canShowPage)
|
||||
.forEach(page -> tabs.add(Tab.createBuilder().from(page, optionPredicate, optionPageScrollBarOffset)))
|
||||
)
|
||||
.onSetTab(() -> {
|
||||
optionPageScrollBarOffset.set(0);
|
||||
})
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
return builder
|
||||
.addChild(dim -> this.undoButton)
|
||||
.addChild(dim -> this.applyButton)
|
||||
.addChild(dim -> this.closeButton);
|
||||
@@ -224,6 +254,25 @@ public class ReeseSodiumVideoOptionsScreen extends SodiumOptionsGUI {
|
||||
this.getAllOptions().forEach(Option::reset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a page has any options that match the current search filter.
|
||||
*/
|
||||
private boolean canShowPage(OptionPage page) {
|
||||
if (page.getGroups().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Predicate<Option<?>> predicate = searchTextField.getOptionPredicate();
|
||||
for (OptionGroup group : page.getGroups()) {
|
||||
for (Option<?> option : group.getOptions()) {
|
||||
if (predicate.test(option)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
if(keyCode == Keyboard.KEY_ESCAPE && !shouldCloseOnEsc()) {
|
||||
@@ -253,7 +302,6 @@ public class ReeseSodiumVideoOptionsScreen extends SodiumOptionsGUI {
|
||||
@Override
|
||||
public void onClose() {
|
||||
lastSearch.set("");
|
||||
lastSearchIndex.set(0);
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
+29
-9
@@ -18,18 +18,21 @@ import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class OptionPageFrame extends AbstractFrame {
|
||||
protected static final SodiumControlElementFactory elementFactory = new SodiumControlElementFactory();
|
||||
protected final Dim2i originalDim;
|
||||
protected final OptionPage page;
|
||||
protected final Predicate<Option<?>> optionFilter;
|
||||
private long lastTime = 0;
|
||||
private ControlElement<?> lastHoveredElement = null;
|
||||
|
||||
public OptionPageFrame(Dim2i dim, boolean renderOutline, OptionPage page) {
|
||||
public OptionPageFrame(Dim2i dim, boolean renderOutline, OptionPage page, Predicate<Option<?>> optionFilter) {
|
||||
super(dim, renderOutline);
|
||||
this.originalDim = new Dim2i(dim.getOriginX(), dim.getOriginY(), dim.getWidth(), dim.getHeight());
|
||||
this.page = page;
|
||||
this.optionFilter = optionFilter;
|
||||
this.setupFrame();
|
||||
this.buildFrame();
|
||||
}
|
||||
@@ -48,9 +51,12 @@ public class OptionPageFrame extends AbstractFrame {
|
||||
OptionGroup lastGroup = this.page.getGroups().get(this.page.getGroups().size() - 1);
|
||||
|
||||
for (OptionGroup group : this.page.getGroups()) {
|
||||
y += group.getOptions().size() * 18;
|
||||
if (group != lastGroup) {
|
||||
y += 4;
|
||||
int visibleCount = (int) group.getOptions().stream() .filter(optionFilter::test) .count();
|
||||
if (visibleCount > 0) {
|
||||
y += visibleCount * 18;
|
||||
if (group != lastGroup) {
|
||||
y += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,19 +79,27 @@ public class OptionPageFrame extends AbstractFrame {
|
||||
|
||||
int y = 0;
|
||||
for (OptionGroup group : this.page.getGroups()) {
|
||||
// Add each option's control element
|
||||
boolean hasVisibleOptions = false;
|
||||
|
||||
// Add each option's control element (if it passes the filter)
|
||||
for (Option<?> option : group.getOptions()) {
|
||||
if (!optionFilter.test(option)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hasVisibleOptions = true;
|
||||
final Control<?> control = option.getControl();
|
||||
final ControlElement<?> element = control.createElement(new Dim2i(this.dim.getOriginX(), this.dim.getOriginY() + y, this.dim.getWidth(), 18), elementFactory);
|
||||
// This is probably not safe
|
||||
this.children.add((AbstractWidget) element);
|
||||
|
||||
// Move down to the next option
|
||||
y += 18;
|
||||
}
|
||||
|
||||
// Add padding beneath each option group
|
||||
y += 4;
|
||||
// Add padding beneath each option group (only if it had visible options)
|
||||
if (hasVisibleOptions) {
|
||||
y += 4;
|
||||
}
|
||||
}
|
||||
|
||||
super.buildFrame();
|
||||
@@ -160,6 +174,7 @@ public class OptionPageFrame extends AbstractFrame {
|
||||
private Dim2i dim;
|
||||
private boolean renderOutline;
|
||||
private OptionPage page;
|
||||
private Predicate<Option<?>> optionFilter = opt -> true;
|
||||
|
||||
public Builder setDimension(Dim2i dim) {
|
||||
this.dim = dim;
|
||||
@@ -176,11 +191,16 @@ public class OptionPageFrame extends AbstractFrame {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOptionFilter(Predicate<Option<?>> optionFilter) {
|
||||
this.optionFilter = optionFilter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OptionPageFrame build() {
|
||||
Validate.notNull(this.dim, "Dimension must be specified");
|
||||
Validate.notNull(this.page, "Option Page must be specified");
|
||||
|
||||
return new OptionPageFrame(this.dim, this.renderOutline, this.page);
|
||||
return new OptionPageFrame(this.dim, this.renderOutline, this.page, this.optionFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
-71
@@ -2,7 +2,6 @@ package me.flashyreese.mods.reeses_sodium_options.client.gui.frame.components;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.OptionExtended;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.ReeseSodiumVideoOptionsScreen;
|
||||
import me.flashyreese.mods.reeses_sodium_options.util.StringUtils;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.Option;
|
||||
@@ -18,8 +17,10 @@ import net.minecraft.util.MathHelper;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -34,7 +35,6 @@ public class SearchTextFieldComponent extends AbstractWidget {
|
||||
private final int tabDimHeight;
|
||||
private final ReeseSodiumVideoOptionsScreen sodiumVideoOptionsScreen;
|
||||
private final AtomicReference<String> lastSearch;
|
||||
private final AtomicReference<Integer> lastSearchIndex;
|
||||
protected boolean selecting;
|
||||
protected String text = "";
|
||||
protected int maxLength = 100;
|
||||
@@ -50,7 +50,10 @@ public class SearchTextFieldComponent extends AbstractWidget {
|
||||
private boolean focused;
|
||||
private int lastCursorPosition = this.getCursor();
|
||||
|
||||
public SearchTextFieldComponent(Dim2i dim, List<OptionPage> pages, AtomicReference<String> tabFrameSelectedTab, AtomicReference<Integer> tabFrameScrollBarOffset, AtomicReference<Integer> optionPageScrollBarOffset, int tabDimHeight, ReeseSodiumVideoOptionsScreen sodiumVideoOptionsScreen, AtomicReference<String> lastSearch, AtomicReference<Integer> lastSearchIndex) {
|
||||
// Set of options matching the current search query (null = show all)
|
||||
private Set<Option<?>> matchingOptions = null;
|
||||
|
||||
public SearchTextFieldComponent(Dim2i dim, List<OptionPage> pages, AtomicReference<String> tabFrameSelectedTab, AtomicReference<Integer> tabFrameScrollBarOffset, AtomicReference<Integer> optionPageScrollBarOffset, int tabDimHeight, ReeseSodiumVideoOptionsScreen sodiumVideoOptionsScreen, AtomicReference<String> lastSearch) {
|
||||
this.dim = dim;
|
||||
this.pages = pages;
|
||||
this.tabFrameSelectedTab = tabFrameSelectedTab;
|
||||
@@ -59,12 +62,30 @@ public class SearchTextFieldComponent extends AbstractWidget {
|
||||
this.tabDimHeight = tabDimHeight;
|
||||
this.sodiumVideoOptionsScreen = sodiumVideoOptionsScreen;
|
||||
this.lastSearch = lastSearch;
|
||||
this.lastSearchIndex = lastSearchIndex;
|
||||
if (!lastSearch.get().trim().isEmpty()) {
|
||||
this.write(lastSearch.get());
|
||||
|
||||
// Initialize text from lastSearch without triggering rebuild
|
||||
String initialSearch = lastSearch.get().trim();
|
||||
if (!initialSearch.isEmpty()) {
|
||||
this.text = initialSearch;
|
||||
this.selectionStart = initialSearch.length();
|
||||
this.selectionEnd = initialSearch.length();
|
||||
// Initialize matching options for the restored search
|
||||
this.matchingOptions = new HashSet<>(StringUtils.fuzzySearch(this.pages, initialSearch, 2));
|
||||
}
|
||||
}
|
||||
|
||||
public Predicate<Option<?>> getOptionPredicate() {
|
||||
return matchingOptions == null ? opt -> true : matchingOptions::contains;
|
||||
}
|
||||
|
||||
public boolean hasSearchQuery() {
|
||||
return !this.text.trim().isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasNoResults() {
|
||||
return hasSearchQuery() && matchingOptions != null && matchingOptions.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
if (!this.isVisible()) {
|
||||
@@ -118,17 +139,22 @@ public class SearchTextFieldComponent extends AbstractWidget {
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
// Right-click to clear search
|
||||
if (button == 1 && this.dim.containsCursor(mouseX, mouseY)) {
|
||||
this.text = "";
|
||||
this.selectionStart = 0;
|
||||
this.selectionEnd = 0;
|
||||
this.firstCharacterIndex = 0;
|
||||
this.onChanged("");
|
||||
this.setFocused(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
final int i = MathHelper.floor_double(mouseX) - this.dim.getOriginX() - 6;
|
||||
final String string = this.textRenderer.trimStringToWidth(this.text.substring(this.firstCharacterIndex), this.getInnerWidth());
|
||||
this.setCursor(this.textRenderer.trimStringToWidth(string, i).length() + this.firstCharacterIndex);
|
||||
|
||||
this.setFocused(this.dim.containsCursor(mouseX, mouseY));
|
||||
this.pages.forEach(page -> page
|
||||
.getOptions()
|
||||
.stream()
|
||||
.filter(OptionExtended.class::isInstance)
|
||||
.map(OptionExtended.class::cast)
|
||||
.forEach(optionExtended -> optionExtended.setSelected(false)));
|
||||
return this.isFocused();
|
||||
}
|
||||
|
||||
@@ -192,22 +218,16 @@ public class SearchTextFieldComponent extends AbstractWidget {
|
||||
}
|
||||
|
||||
private void onChanged(String newText) {
|
||||
this.pages.forEach(page -> page
|
||||
.getOptions()
|
||||
.stream()
|
||||
.filter(OptionExtended.class::isInstance)
|
||||
.map(OptionExtended.class::cast)
|
||||
.forEach(optionExtended -> optionExtended.setHighlight(false)));
|
||||
|
||||
this.lastSearch.set(newText.trim());
|
||||
if (this.editable && (!newText.trim().isEmpty())) {
|
||||
final List<Option<?>> fuzzy = StringUtils.fuzzySearch(this.pages, newText, 2);
|
||||
fuzzy.stream()
|
||||
.filter(OptionExtended.class::isInstance)
|
||||
.map(OptionExtended.class::cast)
|
||||
.forEach(optionExtended -> optionExtended.setHighlight(true));
|
||||
|
||||
if (this.editable && !newText.trim().isEmpty()) {
|
||||
final List<Option<?>> fuzzy = StringUtils.fuzzySearch(this.pages, newText, 2);
|
||||
this.matchingOptions = new HashSet<>(fuzzy);
|
||||
} else {
|
||||
this.matchingOptions = null;
|
||||
}
|
||||
|
||||
this.sodiumVideoOptionsScreen.rebuildGUI();
|
||||
}
|
||||
|
||||
private void erase(int offset) {
|
||||
@@ -296,8 +316,6 @@ public class SearchTextFieldComponent extends AbstractWidget {
|
||||
if (!this.selecting) {
|
||||
this.setSelectionEnd(this.selectionStart);
|
||||
}
|
||||
|
||||
this.onChanged(this.text);
|
||||
}
|
||||
|
||||
public void moveCursor(int offset) {
|
||||
@@ -368,12 +386,6 @@ public class SearchTextFieldComponent extends AbstractWidget {
|
||||
//
|
||||
@Override
|
||||
public boolean keyTyped(char typedChar, int keyCode) {
|
||||
this.pages.forEach(page2 -> page2
|
||||
.getOptions()
|
||||
.stream()
|
||||
.filter(OptionExtended.class::isInstance)
|
||||
.map(OptionExtended.class::cast)
|
||||
.forEach(optionExtended2 -> optionExtended2.setSelected(false)));
|
||||
if (!this.isActive()) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -404,42 +416,6 @@ public class SearchTextFieldComponent extends AbstractWidget {
|
||||
return true;
|
||||
} else {
|
||||
switch (keyCode) {
|
||||
case Keyboard.KEY_RETURN: // GLFW.GLFW_KEY_ENTER
|
||||
if (this.editable) {
|
||||
int count = 0;
|
||||
for (OptionPage page : this.pages) {
|
||||
for (Option<?> option : page.getOptions()) {
|
||||
if(option instanceof OptionExtended<?> optionExtended) {
|
||||
if (optionExtended.isHighlight() && optionExtended.getParentDimension() != null) {
|
||||
if (count == this.lastSearchIndex.get()) {
|
||||
final Dim2i optionDim = optionExtended.getDim2i();
|
||||
final Dim2i parentDim = optionExtended.getParentDimension();
|
||||
final int maxOffset = parentDim.getHeight() - this.tabDimHeight;
|
||||
final int input = optionDim.getOriginY() - parentDim.getOriginY();
|
||||
final int inputOffset = input + optionDim.getHeight() == parentDim.getHeight() ? parentDim.getHeight() : input;
|
||||
final int offset = inputOffset * maxOffset / parentDim.getHeight();
|
||||
|
||||
int total = this.pages.stream().mapToInt(page2 -> Math.toIntExact(page2.getOptions().stream().filter(OptionExtended.class::isInstance).map(OptionExtended.class::cast).filter(OptionExtended::isHighlight).count())).sum();
|
||||
|
||||
final int value = total == this.lastSearchIndex.get() + 1 ? 0 : this.lastSearchIndex.get() + 1;
|
||||
optionExtended.setSelected(true);
|
||||
this.lastSearchIndex.set(value);
|
||||
this.tabFrameSelectedTab.set(page.getName());
|
||||
// todo: calculate tab frame scroll bar offset
|
||||
this.tabFrameScrollBarOffset.set(0);
|
||||
|
||||
this.optionPageScrollBarOffset.set(offset);
|
||||
this.setFocused(false);
|
||||
this.sodiumVideoOptionsScreen.rebuildGUI();
|
||||
return true;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case Keyboard.KEY_BACK: // GLFW.GLFW_KEY_BACKSPACE
|
||||
if (this.editable) {
|
||||
this.selecting = false;
|
||||
@@ -481,9 +457,7 @@ public class SearchTextFieldComponent extends AbstractWidget {
|
||||
default:
|
||||
if (ChatAllowedCharacters.isAllowedCharacter(typedChar)) {
|
||||
if (this.editable) {
|
||||
this.lastSearch.set(this.text.trim());
|
||||
this.write(Character.toString(typedChar));
|
||||
this.lastSearchIndex.set(0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package me.flashyreese.mods.reeses_sodium_options.client.gui.frame.tab;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.AbstractFrame;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.OptionPageFrame;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.ScrollableFrame;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.Option;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class Tab<T extends AbstractFrame> {
|
||||
private final String title;
|
||||
@@ -49,6 +51,10 @@ public class Tab<T extends AbstractFrame> {
|
||||
}
|
||||
|
||||
public Tab<ScrollableFrame> from(OptionPage page, AtomicReference<Integer> verticalScrollBarOffset) {
|
||||
return from(page, opt -> true, verticalScrollBarOffset);
|
||||
}
|
||||
|
||||
public Tab<ScrollableFrame> from(OptionPage page, Predicate<Option<?>> optionFilter, AtomicReference<Integer> verticalScrollBarOffset) {
|
||||
return new Tab<>(page.getName(), dim2i -> ScrollableFrame
|
||||
.createBuilder()
|
||||
.setDimension(dim2i)
|
||||
@@ -56,6 +62,7 @@ public class Tab<T extends AbstractFrame> {
|
||||
.createBuilder()
|
||||
.setDimension(new Dim2i(dim2i.getOriginX(), dim2i.getOriginY(), dim2i.getWidth(), dim2i.getHeight()))
|
||||
.setOptionPage(page)
|
||||
.setOptionFilter(optionFilter)
|
||||
.build())
|
||||
.setVerticalScrollBarOffset(verticalScrollBarOffset)
|
||||
.build());
|
||||
|
||||
@@ -38,27 +38,29 @@ public class StringUtils {
|
||||
|
||||
for (OptionPage page : pages) {
|
||||
for (Option<?> option : page.getOptions()) {
|
||||
String sentence = (option.getName()/* +
|
||||
" " +
|
||||
option.getTooltip().getString()+
|
||||
" " +
|
||||
option.getImpact().toString()*/).toLowerCase();
|
||||
String name = option.getName().toLowerCase();
|
||||
String tooltip = option.getTooltip().toLowerCase();
|
||||
|
||||
boolean containsAllWords = true;
|
||||
for (String word : targetWords) {
|
||||
boolean containsWord = false;
|
||||
for (String sentenceWord : sentence.toLowerCase().split("\\s+")) {
|
||||
int distance = levenshteinDistance(word, sentenceWord);
|
||||
if (distance <= maxDistance) {
|
||||
containsWord = true;
|
||||
break;
|
||||
}
|
||||
// Starts with match
|
||||
if (sentenceWord.startsWith(word)) {
|
||||
|
||||
// Fuzzy match on name (handles typos)
|
||||
// Use stricter matching for short words to avoid false positives (e.g., "fps" matching "fog")
|
||||
int effectiveMaxDistance = word.length() < 4 ? Math.min(1, maxDistance) : maxDistance;
|
||||
for (String nameWord : name.split("\\s+")) {
|
||||
int distance = levenshteinDistance(word, nameWord);
|
||||
if (distance <= effectiveMaxDistance || nameWord.startsWith(word)) {
|
||||
containsWord = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Substring match on tooltip (for discoverability like "fps" -> "frames per second")
|
||||
if (!containsWord && tooltip.contains(word)) {
|
||||
containsWord = true;
|
||||
}
|
||||
|
||||
if (!containsWord) {
|
||||
containsAllWords = false;
|
||||
break;
|
||||
|
||||
@@ -214,8 +214,5 @@ public class OptionImpl<S, T> implements OptionExtended<T> {
|
||||
|
||||
|
||||
@Setter @Getter private Dim2i parentDimension;
|
||||
@Setter @Getter private Dim2i dim2i;
|
||||
@Setter @Getter private boolean highlight;
|
||||
@Setter @Getter private boolean selected;
|
||||
|
||||
}
|
||||
-13
@@ -1,6 +1,5 @@
|
||||
package me.jellysquid.mods.sodium.client.gui.options.control.element;
|
||||
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.OptionExtended;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.Option;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
|
||||
@@ -15,9 +14,6 @@ public class SodiumControlElement<T> extends AbstractWidget implements ControlEl
|
||||
public SodiumControlElement(Option<T> option, Dim2i dim) {
|
||||
this.option = option;
|
||||
this.dim = dim;
|
||||
if(option instanceof OptionExtended<?> optionExtended) {
|
||||
optionExtended.setDim2i(dim);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,16 +37,7 @@ public class SodiumControlElement<T> extends AbstractWidget implements ControlEl
|
||||
|
||||
this.hovered = this.dim.containsCursor(mouseX, mouseY);
|
||||
|
||||
|
||||
this.drawRect(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getLimitX(), this.dim.getLimitY(), this.hovered ? 0xE0000000 : 0x90000000);
|
||||
if(option instanceof OptionExtended<?> optionExtended && (optionExtended.isHighlight())) {
|
||||
final String replacement = optionExtended.isSelected() ? EnumChatFormatting.DARK_GREEN.toString() : EnumChatFormatting.YELLOW.toString();
|
||||
|
||||
label = label.replace(EnumChatFormatting.WHITE.toString(), EnumChatFormatting.WHITE + replacement);
|
||||
label = label.replace(EnumChatFormatting.STRIKETHROUGH.toString(), EnumChatFormatting.STRIKETHROUGH + replacement);
|
||||
label = label.replace(EnumChatFormatting.ITALIC.toString(), EnumChatFormatting.ITALIC + replacement);
|
||||
|
||||
}
|
||||
this.drawString(label, this.dim.getOriginX() + 6, this.dim.getCenterY() - 4, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user