mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-19 11:59:40 +00:00
Add Reese's Sodium Options (#219)
* Add Reese's Sodium Options Co-authored-by: makamys <[email protected]>
This commit is contained in:
1 parent
806bcf2d6b
commit
aff05e1812
35 files changed
+2199
-110
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package com.gtnewhorizons.angelica.client.gui;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Element;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ScrollableGuiScreen extends GuiScreen {
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
handleMouseScroll(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
public abstract List<? extends Element> children();
|
||||
|
||||
protected void handleMouseScroll(int mouseX, int mouseY, float partialTicks) {
|
||||
for (; !this.mc.gameSettings.touchscreen && Mouse.next(); this.mc.currentScreen.handleMouseInput()) {
|
||||
int dWheel = Mouse.getEventDWheel();
|
||||
|
||||
if (dWheel != 0) {
|
||||
for(Element child : children()) {
|
||||
child.mouseScrolled(mouseX, mouseY, dWheel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.gtnewhorizons.angelica.compat.mojang;
|
||||
|
||||
public interface Drawable {
|
||||
default void render(int mouseX, int mouseY, float delta) {}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.gtnewhorizons.angelica.compat.mojang;
|
||||
|
||||
public interface Element {
|
||||
default boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean mouseDragged(double mouseX, double mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean mouseScrolled(double mouseX, double mouseY, double amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean keyTyped(char typedChar, int keyCode) { return false; }
|
||||
|
||||
default boolean isMouseOver(double mouseX, double mouseY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean changeFocus(boolean lookForwards) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.gtnewhorizons.angelica.compat.mojang;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface ParentElement extends Element {
|
||||
List<? extends Element> children();
|
||||
|
||||
default Optional<Element> hoveredElement(double mouseX, double mouseY) {
|
||||
for(Element element : this.children()) {
|
||||
if (element.isMouseOver(mouseX, mouseY)) {
|
||||
return Optional.of(element);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
default boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
for(Element element : this.children()) {
|
||||
if (element.mouseClicked(mouseX, mouseY, button)) {
|
||||
this.setFocused(element);
|
||||
if (button == 0) {
|
||||
this.setDragging(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
this.setDragging(false);
|
||||
return this.hoveredElement(mouseX, mouseY).filter((element) -> element.mouseReleased(mouseX, mouseY, button)).isPresent();
|
||||
}
|
||||
|
||||
default boolean mouseDragged(double mouseX, double mouseY, int button) {
|
||||
return this.getFocused() != null && this.isDragging() && button == 0 && this.getFocused().mouseDragged(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
boolean isDragging();
|
||||
|
||||
void setDragging(boolean dragging);
|
||||
|
||||
default boolean mouseScrolled(double mouseX, double mouseY, double amount) {
|
||||
return this.hoveredElement(mouseX, mouseY).filter((element) -> element.mouseScrolled(mouseX, mouseY, amount)).isPresent();
|
||||
}
|
||||
|
||||
default boolean keyTyped(char typedChar, int keyCode) {
|
||||
return this.getFocused() != null && this.getFocused().keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Element getFocused();
|
||||
|
||||
void setFocused(@Nullable Element focused);
|
||||
|
||||
default boolean changeFocus(boolean lookForwards) {
|
||||
final Element element = this.getFocused();
|
||||
if (element != null && element.changeFocus(lookForwards)) {
|
||||
return true;
|
||||
} else {
|
||||
final List<? extends Element> list = this.children();
|
||||
final int i = list.indexOf(element);
|
||||
final int j;
|
||||
if (element != null && i >= 0) {
|
||||
j = i + (lookForwards ? 1 : 0);
|
||||
} else if (lookForwards) {
|
||||
j = 0;
|
||||
} else {
|
||||
j = list.size();
|
||||
}
|
||||
|
||||
|
||||
final ListIterator<? extends Element> listIterator = list.listIterator(j);
|
||||
final BooleanSupplier booleanSupplier = lookForwards ? listIterator::hasNext : listIterator::hasPrevious;
|
||||
final Supplier<? extends Element> supplier = lookForwards ? listIterator::next : listIterator::previous;
|
||||
|
||||
Element element2;
|
||||
do {
|
||||
if (!booleanSupplier.getAsBoolean()) {
|
||||
this.setFocused(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
element2 = supplier.get();
|
||||
} while(!element2.changeFocus(lookForwards));
|
||||
|
||||
this.setFocused(element2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,10 @@ public class AngelicaConfig {
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableSodium;
|
||||
|
||||
@Config.Comment("Enable Reese's Sodium Options")
|
||||
@Config.DefaultBoolean(true)
|
||||
public static boolean enableReesesSodiumOptions;
|
||||
|
||||
@Config.Comment("Enable Sodium fluid rendering")
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
|
||||
@@ -79,6 +79,7 @@ public class GLStateManager {
|
||||
@Getter protected static final TextureUnitArray textures = new TextureUnitArray();
|
||||
@Getter protected static final BlendStateStack blendState = new BlendStateStack();
|
||||
@Getter protected static final BooleanStateStack blendMode = new BooleanStateStack(GL11.GL_BLEND);
|
||||
@Getter protected static final BooleanStateStack scissorTest = new BooleanStateStack(GL11.GL_SCISSOR_TEST);
|
||||
@Getter protected static final DepthStateStack depthState = new DepthStateStack();
|
||||
@Getter protected static final BooleanStateStack depthTest = new BooleanStateStack(GL11.GL_DEPTH_TEST);
|
||||
|
||||
@@ -156,6 +157,7 @@ public class GLStateManager {
|
||||
case GL12.GL_RESCALE_NORMAL -> enableRescaleNormal();
|
||||
case GL11.GL_TEXTURE_2D -> enableTexture();
|
||||
case GL11.GL_FOG -> enableFog();
|
||||
case GL11.GL_SCISSOR_TEST -> enableScissorTest();
|
||||
default -> GL11.glEnable(cap);
|
||||
}
|
||||
}
|
||||
@@ -170,6 +172,7 @@ public class GLStateManager {
|
||||
case GL12.GL_RESCALE_NORMAL -> disableRescaleNormal();
|
||||
case GL11.GL_TEXTURE_2D -> disableTexture();
|
||||
case GL11.GL_FOG -> disableFog();
|
||||
case GL11.GL_SCISSOR_TEST -> disableScissorTest();
|
||||
default -> GL11.glDisable(cap);
|
||||
}
|
||||
}
|
||||
@@ -216,6 +219,14 @@ public class GLStateManager {
|
||||
blendMode.disable();
|
||||
}
|
||||
|
||||
public static void enableScissorTest() {
|
||||
scissorTest.enable();
|
||||
}
|
||||
|
||||
public static void disableScissorTest() {
|
||||
scissorTest.disable();
|
||||
}
|
||||
|
||||
public static void glBlendFunc(int srcFactor, int dstFactor) {
|
||||
if (AngelicaConfig.enableIris) {
|
||||
if (BlendModeStorage.isBlendLocked()) {
|
||||
|
||||
@@ -236,10 +236,15 @@ public enum Mixins {
|
||||
,"notfine.settings.MixinGameSettings"
|
||||
//,"notfine.toggle.MixinGuiIngame"
|
||||
//,"notfine.toggle.MixinEntityRenderer"
|
||||
,"notfine.toggle.MixinRender"
|
||||
//,"notfine.toggle.MixinRender" --> No Sodium below
|
||||
//,"notfine.toggle.MixinRenderItem"
|
||||
)),
|
||||
|
||||
NOTFINE_FEATURES_NO_SODIUM(new Builder("NotFine Features").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT)
|
||||
.setPhase(Phase.EARLY).setApplyIf(() -> AngelicaConfig.enableNotFineFeatures && !AngelicaConfig.enableSodium).addMixinClasses(
|
||||
"notfine.toggle.MixinRender"
|
||||
)),
|
||||
|
||||
NOTFINE_FEATURES_NO_MCPF_CIT(new Builder("NotFine Features which clash with mcpf cit (compat handled in MCPF_NF mixin)").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT)
|
||||
.setPhase(Phase.EARLY).setApplyIf(() -> AngelicaConfig.enableNotFineFeatures &&
|
||||
!(AngelicaConfig.enableMCPatcherForgeFeatures && MCPatcherForgeConfig.instance().customItemTexturesEnabled)
|
||||
|
||||
@@ -61,7 +61,6 @@ public class ClientProxy extends CommonProxy {
|
||||
Iris.INSTANCE.fmlInitEvent();
|
||||
FMLCommonHandler.instance().bus().register(Iris.INSTANCE);
|
||||
MinecraftForge.EVENT_BUS.register(Iris.INSTANCE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.gtnewhorizons.angelica.transform.BlockTransformer.*;
|
||||
import static com.gtnewhorizons.angelica.transform.BlockTransformer.BlockBoundsFields;
|
||||
import static com.gtnewhorizons.angelica.transform.BlockTransformer.BlockClass;
|
||||
|
||||
/**
|
||||
* This transformer redirects all Tessellator.instance field accesses to go through our TessellatorManager.
|
||||
@@ -88,6 +89,7 @@ public class RedirectorTransformer implements IClassTransformer {
|
||||
glCapRedirects.put(org.lwjgl.opengl.GL11.GL_TEXTURE_2D, "Texture");
|
||||
glCapRedirects.put(org.lwjgl.opengl.GL11.GL_FOG, "Fog");
|
||||
glCapRedirects.put(org.lwjgl.opengl.GL12.GL_RESCALE_NORMAL, "RescaleNormal");
|
||||
glCapRedirects.put(org.lwjgl.opengl.GL11.GL_SCISSOR_TEST, "ScissorTest");
|
||||
methodRedirects.put(GL11, RedirectMap.newMap()
|
||||
.add("glGetFloat")
|
||||
.add("glAlphaFunc")
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package me.flashyreese.mods.reeses_sodium_options.client.gui;
|
||||
|
||||
import me.jellysquid.mods.sodium.client.gui.options.Option;
|
||||
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);
|
||||
}
|
||||
+300
@@ -0,0 +1,300 @@
|
||||
package me.flashyreese.mods.reeses_sodium_options.client.gui;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Element;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import jss.notfine.gui.GuiCustomMenu;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.AbstractFrame;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.BasicFrame;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.components.SearchTextFieldComponent;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.tab.Tab;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.tab.TabFrame;
|
||||
import me.jellysquid.mods.sodium.client.SodiumClientMod;
|
||||
import me.jellysquid.mods.sodium.client.gui.SodiumGameOptionPages;
|
||||
import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions;
|
||||
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.OptionPage;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
|
||||
import me.jellysquid.mods.sodium.client.gui.utils.URLUtils;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
import net.coderbot.iris.gui.screen.ShaderPackScreen;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ReeseSodiumVideoOptionsScreen extends SodiumOptionsGUI {
|
||||
@Nullable
|
||||
private Element focused;
|
||||
|
||||
private static final AtomicReference<String> tabFrameSelectedTab = new AtomicReference<>(null);
|
||||
private static final AtomicReference<Integer> tabFrameScrollBarOffset = new AtomicReference<>(0);
|
||||
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;
|
||||
|
||||
public ReeseSodiumVideoOptionsScreen(GuiScreen prevScreen) {
|
||||
super(prevScreen);
|
||||
}
|
||||
|
||||
// Hackalicious! Rebuild UI
|
||||
@Override
|
||||
public void rebuildGUI() {
|
||||
this.children.clear();
|
||||
this.initGui();
|
||||
}
|
||||
|
||||
|
||||
public void setFocused(@Nullable Element focused) {
|
||||
this.focused = focused;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Element getFocused() {
|
||||
return this.focused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
this.frame = this.parentFrameBuilder().build();
|
||||
this.children.add(this.frame);
|
||||
|
||||
this.searchTextField.setFocused(!lastSearch.get().trim().isEmpty());
|
||||
if (this.searchTextField.isFocused()) {
|
||||
this.setFocused(this.searchTextField);
|
||||
} else {
|
||||
this.setFocused(this.frame);
|
||||
}
|
||||
}
|
||||
|
||||
protected BasicFrame.Builder parentFrameBuilder() {
|
||||
final BasicFrame.Builder basicFrameBuilder;
|
||||
|
||||
// Calculates if resolution exceeds 16:9 ratio, force 16:9
|
||||
int newWidth = this.width;
|
||||
if ((float) this.width / (float) this.height > 1.77777777778) {
|
||||
newWidth = (int) (this.height * 1.77777777778);
|
||||
}
|
||||
|
||||
final Dim2i basicFrameDim = new Dim2i((this.width - newWidth) / 2, 0, newWidth, this.height);
|
||||
final Dim2i tabFrameDim = new Dim2i(basicFrameDim.getOriginX() + basicFrameDim.getWidth() / 20 / 2, basicFrameDim.getOriginY() + basicFrameDim.getHeight() / 4 / 2, basicFrameDim.getWidth() - (basicFrameDim.getWidth() / 20), basicFrameDim.getHeight() / 4 * 3);
|
||||
|
||||
final Dim2i undoButtonDim = new Dim2i(tabFrameDim.getLimitX() - 203, tabFrameDim.getLimitY() + 5, 65, 20);
|
||||
final Dim2i applyButtonDim = new Dim2i(tabFrameDim.getLimitX() - 134, tabFrameDim.getLimitY() + 5, 65, 20);
|
||||
final Dim2i closeButtonDim = new Dim2i(tabFrameDim.getLimitX() - 65, tabFrameDim.getLimitY() + 5, 65, 20);
|
||||
|
||||
final String donationText = "Buy us a coffee!";
|
||||
final int donationTextWidth = this.mc.fontRenderer.getStringWidth(donationText);
|
||||
|
||||
final Dim2i donateButtonDim = new Dim2i(tabFrameDim.getLimitX() - 32 - donationTextWidth, tabFrameDim.getOriginY() - 26, 10 + donationTextWidth, 20);
|
||||
final Dim2i hideDonateButtonDim = new Dim2i(tabFrameDim.getLimitX() - 20, tabFrameDim.getOriginY() - 26, 20, 20);
|
||||
|
||||
this.undoButton = new FlatButtonWidget(undoButtonDim, "Undo", this::undoChanges);
|
||||
this.applyButton = new FlatButtonWidget(applyButtonDim, "Apply", this::applyChanges);
|
||||
this.closeButton = new FlatButtonWidget(closeButtonDim, "Close", this::onClose);
|
||||
|
||||
this.donateButton = new FlatButtonWidget(donateButtonDim, donationText, this::openDonationPage);
|
||||
this.hideDonateButton = new FlatButtonWidget(hideDonateButtonDim, "x", this::hideDonationButton);
|
||||
|
||||
if (SodiumClientMod.options().notifications.hideDonationButton) {
|
||||
this.setDonationButtonVisibility(false);
|
||||
}
|
||||
|
||||
|
||||
Dim2i searchTextFieldDim;
|
||||
if (SodiumClientMod.options().notifications.hideDonationButton) {
|
||||
searchTextFieldDim = new Dim2i(tabFrameDim.getOriginX(), tabFrameDim.getOriginY() - 26, tabFrameDim.getWidth(), 20);
|
||||
} else {
|
||||
searchTextFieldDim = new Dim2i(tabFrameDim.getOriginX(), tabFrameDim.getOriginY() - 26, tabFrameDim.getWidth() - (tabFrameDim.getLimitX() - donateButtonDim.getOriginX()) - 2, 20);
|
||||
}
|
||||
|
||||
|
||||
basicFrameBuilder = this.parentBasicFrameBuilder(basicFrameDim, tabFrameDim);
|
||||
|
||||
if(AngelicaConfig.enableIris) {
|
||||
//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;
|
||||
if (!SodiumClientMod.options().notifications.hideDonationButton) {
|
||||
shaderPackButtonDim = new Dim2i(donateButtonDim.getOriginX() - 12 - size, tabFrameDim.getOriginY() - 26, 10 + size, 20);
|
||||
} else {
|
||||
shaderPackButtonDim = new Dim2i(tabFrameDim.getLimitX() - size - 10, tabFrameDim.getOriginY() - 26, 10 + size, 20);
|
||||
}
|
||||
searchTextFieldDim = new Dim2i(tabFrameDim.getOriginX(), tabFrameDim.getOriginY() - 26, tabFrameDim.getWidth() - (tabFrameDim.getLimitX() - shaderPackButtonDim.getOriginX()) - 2, 20);
|
||||
|
||||
//FlatButtonWidget shaderPackButton = new FlatButtonWidget(shaderPackButtonDim, new TranslatableText(IrisApi.getInstance().getMainScreenLanguageKey()), () -> this.client.setScreen((Screen) IrisApi.getInstance().openMainIrisScreenObj(this)));
|
||||
final FlatButtonWidget shaderPackButton = new FlatButtonWidget(shaderPackButtonDim, irisText, () -> mc.displayGuiScreen(new ShaderPackScreen(this)));
|
||||
basicFrameBuilder.addChild(dim -> shaderPackButton);
|
||||
}
|
||||
|
||||
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()
|
||||
.setDimension(parentBasicFrameDim)
|
||||
.shouldRenderOutline(false)
|
||||
.addChild(dim -> this.donateButton)
|
||||
.addChild(dim -> this.hideDonateButton)
|
||||
.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()
|
||||
)
|
||||
.addChild(dim -> this.undoButton)
|
||||
.addChild(dim -> this.applyButton)
|
||||
.addChild(dim -> this.closeButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawDefaultBackground();
|
||||
handleMouseScroll(mouseX, mouseY, partialTicks);
|
||||
this.updateControls();
|
||||
this.frame.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
private void updateControls() {
|
||||
boolean hasChanges = this.getAllOptions()
|
||||
.anyMatch(Option::hasChanged);
|
||||
|
||||
for (OptionPage page : this.pages) {
|
||||
for (Option<?> option : page.getOptions()) {
|
||||
if (option.hasChanged()) {
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.applyButton.setEnabled(hasChanges);
|
||||
this.undoButton.setVisible(hasChanges);
|
||||
this.closeButton.setEnabled(!hasChanges);
|
||||
|
||||
this.hasPendingChanges = hasChanges;
|
||||
}
|
||||
|
||||
private void setDonationButtonVisibility(boolean value) {
|
||||
this.donateButton.setVisible(value);
|
||||
this.hideDonateButton.setVisible(value);
|
||||
}
|
||||
|
||||
private void hideDonationButton() {
|
||||
SodiumGameOptions options = SodiumClientMod.options();
|
||||
options.notifications.hideDonationButton = true;
|
||||
|
||||
try {
|
||||
options.writeChanges();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to save configuration", e);
|
||||
}
|
||||
|
||||
this.setDonationButtonVisibility(false);
|
||||
|
||||
|
||||
this.rebuildGUI();
|
||||
}
|
||||
|
||||
private void openDonationPage() {
|
||||
URLUtils.open("https://caffeinemc.net/donate");
|
||||
}
|
||||
|
||||
private Stream<Option<?>> getAllOptions() {
|
||||
return this.pages.stream().flatMap(s -> s.getOptions().stream());
|
||||
}
|
||||
|
||||
private void applyChanges() {
|
||||
final HashSet<OptionStorage<?>> dirtyStorages = new HashSet<>();
|
||||
final EnumSet<OptionFlag> flags = EnumSet.noneOf(OptionFlag.class);
|
||||
|
||||
this.getAllOptions().forEach((option -> {
|
||||
if (!option.hasChanged()) {
|
||||
return;
|
||||
}
|
||||
|
||||
option.applyChanges();
|
||||
|
||||
flags.addAll(option.getFlags());
|
||||
dirtyStorages.add(option.getStorage());
|
||||
}));
|
||||
|
||||
|
||||
if (flags.contains(OptionFlag.REQUIRES_RENDERER_RELOAD)) {
|
||||
this.mc.renderGlobal.loadRenderers();
|
||||
}
|
||||
|
||||
if (flags.contains(OptionFlag.REQUIRES_ASSET_RELOAD)) {
|
||||
this.mc.getTextureMapBlocks().setMipmapLevels(this.mc.gameSettings.mipmapLevels);
|
||||
this.mc.refreshResources();
|
||||
}
|
||||
|
||||
for (OptionStorage<?> storage : dirtyStorages) {
|
||||
storage.save();
|
||||
}
|
||||
}
|
||||
|
||||
private void undoChanges() {
|
||||
this.getAllOptions().forEach(Option::reset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
if(keyCode == Keyboard.KEY_ESCAPE && !shouldCloseOnEsc()) {
|
||||
return;
|
||||
} else if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
if (keyCode == Keyboard.KEY_P) {
|
||||
if(isShiftKeyDown()){
|
||||
this.mc.displayGuiScreen(new GuiCustomMenu(this.prevScreen, SodiumGameOptionPages.general(), SodiumGameOptionPages.quality(), SodiumGameOptionPages.advanced(), SodiumGameOptionPages.performance()));
|
||||
} else if (isCtrlKeyDown()) {
|
||||
this.mc.displayGuiScreen(new SodiumOptionsGUI(this.prevScreen));
|
||||
}
|
||||
}
|
||||
|
||||
if(focused != null) {
|
||||
focused.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCloseOnEsc() {
|
||||
return !this.hasPendingChanges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
lastSearch.set("");
|
||||
lastSearchIndex.set(0);
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package me.flashyreese.mods.reeses_sodium_options.client.gui.frame;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Drawable;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Element;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ParentElement;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractFrame extends AbstractWidget implements ParentElement {
|
||||
protected final Dim2i dim;
|
||||
protected final List<AbstractWidget> children = new ArrayList<>();
|
||||
protected final List<Drawable> drawable = new ArrayList<>();
|
||||
protected final List<ControlElement<?>> controlElements = new ArrayList<>();
|
||||
protected boolean renderOutline;
|
||||
private Element focused;
|
||||
private boolean dragging;
|
||||
|
||||
public AbstractFrame(Dim2i dim, boolean renderOutline) {
|
||||
this.dim = dim;
|
||||
this.renderOutline = renderOutline;
|
||||
}
|
||||
|
||||
public void buildFrame() {
|
||||
for (Element element : this.children) {
|
||||
if (element instanceof AbstractFrame abstractFrame) {
|
||||
this.controlElements.addAll(abstractFrame.controlElements);
|
||||
}
|
||||
if (element instanceof ControlElement<?> controlElement) {
|
||||
this.controlElements.add(controlElement);
|
||||
}
|
||||
if (element instanceof Drawable drawable) {
|
||||
this.drawable.add(drawable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
if (this.renderOutline) {
|
||||
this.drawRectOutline(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA);
|
||||
}
|
||||
for (Drawable drawable : this.drawable) {
|
||||
drawable.render(mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
||||
public void applyScissor(int x, int y, int width, int height, Runnable action) {
|
||||
final double scale = new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight).getScaleFactor();
|
||||
GLStateManager.enableScissorTest();
|
||||
GL11.glScissor((int) (x * scale), (int) (Minecraft.getMinecraft().getFramebuffer().framebufferHeight - (y + height) * scale), (int) (width * scale), (int) (height * scale));
|
||||
action.run();
|
||||
GLStateManager.disableScissorTest();
|
||||
}
|
||||
|
||||
protected void drawRectOutline(double x, double y, double w, double h, int color) {
|
||||
final float a = (float) (color >> 24 & 255) / 255.0F;
|
||||
final float r = (float) (color >> 16 & 255) / 255.0F;
|
||||
final float g = (float) (color >> 8 & 255) / 255.0F;
|
||||
final float b = (float) (color & 255) / 255.0F;
|
||||
|
||||
this.drawQuads(vertices -> {
|
||||
addQuad(vertices, x, y, w, y + 1, a, r, g, b);
|
||||
addQuad(vertices, x, h - 1, w, h, a, r, g, b);
|
||||
addQuad(vertices, x, y, x + 1, h, a, r, g, b);
|
||||
addQuad(vertices, w - 1, y, w, h, a, r, g, b);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDragging() {
|
||||
return this.dragging;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDragging(boolean dragging) {
|
||||
this.dragging = dragging;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Element getFocused() {
|
||||
return this.focused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocused(@Nullable Element focused) {
|
||||
this.focused = focused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Element> children() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(double mouseX, double mouseY) {
|
||||
return this.dim.containsCursor(mouseX, mouseY);
|
||||
}
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package me.flashyreese.mods.reeses_sodium_options.client.gui.frame;
|
||||
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BasicFrame extends AbstractFrame {
|
||||
|
||||
protected List<Function<Dim2i, AbstractWidget>> functions;
|
||||
|
||||
public BasicFrame(Dim2i dim, boolean renderOutline, List<Function<Dim2i, AbstractWidget>> functions) {
|
||||
super(dim, renderOutline);
|
||||
this.functions = functions;
|
||||
this.buildFrame();
|
||||
}
|
||||
|
||||
public static Builder createBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildFrame() {
|
||||
this.children.clear();
|
||||
this.drawable.clear();
|
||||
this.controlElements.clear();
|
||||
|
||||
this.functions.forEach(function -> this.children.add(function.apply(dim)));
|
||||
|
||||
super.buildFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
super.render(mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final List<Function<Dim2i, AbstractWidget>> functions = new ArrayList<>();
|
||||
private Dim2i dim;
|
||||
private boolean renderOutline;
|
||||
|
||||
public Builder setDimension(Dim2i dim) {
|
||||
this.dim = dim;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder shouldRenderOutline(boolean renderOutline) {
|
||||
this.renderOutline = renderOutline;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addChild(Function<Dim2i, AbstractWidget> function) {
|
||||
this.functions.add(function);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BasicFrame build() {
|
||||
Validate.notNull(this.dim, "Dimension must be specified");
|
||||
|
||||
return new BasicFrame(this.dim, this.renderOutline, this.functions);
|
||||
}
|
||||
}
|
||||
}
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
package me.flashyreese.mods.reeses_sodium_options.client.gui.frame;
|
||||
|
||||
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.OptionGroup;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionImpact;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.control.Control;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.control.element.SodiumControlElementFactory;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OptionPageFrame extends AbstractFrame {
|
||||
protected static final SodiumControlElementFactory elementFactory = new SodiumControlElementFactory();
|
||||
protected final Dim2i originalDim;
|
||||
protected final OptionPage page;
|
||||
private long lastTime = 0;
|
||||
private ControlElement<?> lastHoveredElement = null;
|
||||
|
||||
public OptionPageFrame(Dim2i dim, boolean renderOutline, OptionPage page) {
|
||||
super(dim, renderOutline);
|
||||
this.originalDim = new Dim2i(dim.getOriginX(), dim.getOriginY(), dim.getWidth(), dim.getHeight());
|
||||
this.page = page;
|
||||
this.setupFrame();
|
||||
this.buildFrame();
|
||||
}
|
||||
|
||||
public static Builder createBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public void setupFrame() {
|
||||
this.children.clear();
|
||||
this.drawable.clear();
|
||||
this.controlElements.clear();
|
||||
|
||||
int y = 0;
|
||||
if (!this.page.getGroups().isEmpty()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.dim.setHeight(y);
|
||||
this.page.getGroups().forEach(group -> group.getOptions().forEach(option -> {
|
||||
if (option instanceof OptionExtended<?> optionExtended) {
|
||||
optionExtended.setParentDimension(this.dim);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildFrame() {
|
||||
if (this.page == null) return;
|
||||
|
||||
this.children.clear();
|
||||
this.drawable.clear();
|
||||
this.controlElements.clear();
|
||||
|
||||
int y = 0;
|
||||
for (OptionGroup group : this.page.getGroups()) {
|
||||
// Add each option's control element
|
||||
for (Option<?> option : group.getOptions()) {
|
||||
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;
|
||||
}
|
||||
|
||||
super.buildFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
final ControlElement<?> hoveredElement = this.controlElements.stream()
|
||||
.filter(controlElement -> controlElement.getDimensions().overlapWith(this.originalDim))
|
||||
.filter(ControlElement::isHovered)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
super.render(mouseX, mouseY, delta);
|
||||
if (hoveredElement != null && this.lastHoveredElement == hoveredElement &&
|
||||
(this.originalDim.containsCursor(mouseX, mouseY) && hoveredElement.isHovered()/* && isMouseOver(mouseX, mouseY)*/)) {
|
||||
if (this.lastTime == 0) {
|
||||
this.lastTime = System.currentTimeMillis();
|
||||
}
|
||||
this.renderOptionTooltip(hoveredElement);
|
||||
} else {
|
||||
this.lastTime = 0;
|
||||
this.lastHoveredElement = hoveredElement;
|
||||
}
|
||||
}
|
||||
|
||||
private void renderOptionTooltip(ControlElement<?> element) {
|
||||
final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
if (this.lastTime + 500 > System.currentTimeMillis()) return;
|
||||
|
||||
final Dim2i dim = element.getDimensions();
|
||||
|
||||
final int textPadding = 3;
|
||||
final int boxPadding = 3;
|
||||
|
||||
final int boxWidth = dim.getWidth();
|
||||
|
||||
//Offset based on mouse position, width and height of content and width and height of the window
|
||||
int boxY = dim.getLimitY();
|
||||
final int boxX = dim.getOriginX();
|
||||
|
||||
final Option<?> option = element.getOption();
|
||||
final List<String> tooltip = new ArrayList<>(fontRenderer.listFormattedStringToWidth(option.getTooltip(), boxWidth - (textPadding * 2)));
|
||||
|
||||
final OptionImpact impact = option.getImpact();
|
||||
|
||||
if (impact != null) {
|
||||
tooltip.add(EnumChatFormatting.GRAY + I18n.format("sodium.options.performance_impact_string", impact.toDisplayString()));
|
||||
}
|
||||
|
||||
final int boxHeight = (tooltip.size() * 12) + boxPadding;
|
||||
final int boxYLimit = boxY + boxHeight;
|
||||
final int boxYCutoff = this.originalDim.getLimitY();
|
||||
|
||||
// If the box is going to be cutoff on the Y-axis, move it back up the difference
|
||||
if (boxYLimit > boxYCutoff) {
|
||||
boxY -= boxHeight + dim.getHeight();
|
||||
}
|
||||
|
||||
if (boxY < 0) {
|
||||
boxY = dim.getLimitY();
|
||||
}
|
||||
|
||||
this.drawRect(boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0xE0000000);
|
||||
this.drawRectOutline(boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0xFF94E4D3);
|
||||
|
||||
for (int i = 0; i < tooltip.size(); i++) {
|
||||
fontRenderer.drawString(tooltip.get(i), boxX + textPadding, boxY + textPadding + (i * 12), 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Dim2i dim;
|
||||
private boolean renderOutline;
|
||||
private OptionPage page;
|
||||
|
||||
public Builder setDimension(Dim2i dim) {
|
||||
this.dim = dim;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder shouldRenderOutline(boolean renderOutline) {
|
||||
this.renderOutline = renderOutline;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOptionPage(OptionPage page) {
|
||||
this.page = page;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
package me.flashyreese.mods.reeses_sodium_options.client.gui.frame;
|
||||
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.components.ScrollBarComponent;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class ScrollableFrame extends AbstractFrame {
|
||||
|
||||
protected final Dim2i frameOrigin;
|
||||
protected final AbstractFrame frame;
|
||||
|
||||
private boolean canScrollHorizontal;
|
||||
private boolean canScrollVertical;
|
||||
private Dim2i viewPortDimension = null;
|
||||
private ScrollBarComponent verticalScrollBar = null;
|
||||
private ScrollBarComponent horizontalScrollBar = null;
|
||||
|
||||
public ScrollableFrame(Dim2i dim, AbstractFrame frame, boolean renderOutline, AtomicReference<Integer> verticalScrollBarOffset, AtomicReference<Integer> horizontalScrollBarOffset) {
|
||||
super(dim, renderOutline);
|
||||
this.frame = frame;
|
||||
this.frameOrigin = new Dim2i(frame.dim.getOriginX(), frame.dim.getOriginY(), 0, 0);
|
||||
this.setupFrame(verticalScrollBarOffset, horizontalScrollBarOffset);
|
||||
this.buildFrame();
|
||||
}
|
||||
|
||||
public static Builder createBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public void setupFrame(AtomicReference<Integer> verticalScrollBarOffset, AtomicReference<Integer> horizontalScrollBarOffset) {
|
||||
int maxWidth = 0;
|
||||
int maxHeight = 0;
|
||||
if (!this.dim.canFitDimension(this.frame.dim)) {
|
||||
if (this.dim.getLimitX() < this.frame.dim.getLimitX()) {
|
||||
int value = this.frame.dim.getOriginX() - this.dim.getOriginX() + this.frame.dim.getWidth();
|
||||
if (maxWidth < value) {
|
||||
maxWidth = value;
|
||||
}
|
||||
}
|
||||
if (this.dim.getLimitY() < this.frame.dim.getLimitY()) {
|
||||
int value = this.frame.dim.getOriginY() - this.dim.getOriginY() + this.frame.dim.getHeight();
|
||||
if (maxHeight < value) {
|
||||
maxHeight = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (maxWidth > 0) {
|
||||
this.canScrollHorizontal = true;
|
||||
}
|
||||
if (maxHeight > 0) {
|
||||
this.canScrollVertical = true;
|
||||
}
|
||||
|
||||
if (this.canScrollHorizontal && this.canScrollVertical) {
|
||||
this.viewPortDimension = new Dim2i(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getWidth() - 11, this.dim.getHeight() - 11);
|
||||
} else if (this.canScrollHorizontal) {
|
||||
this.viewPortDimension = new Dim2i(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getWidth(), this.dim.getHeight() - 11);
|
||||
this.frame.dim.setHeight(this.frame.dim.getHeight() - 11); // fixme: don't mutate rather
|
||||
} else if (this.canScrollVertical) {
|
||||
this.viewPortDimension = new Dim2i(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getWidth() - 11, this.dim.getHeight());
|
||||
this.frame.dim.setWidth(this.frame.dim.getWidth() - 11); // fixme: don't mutate rather
|
||||
}
|
||||
|
||||
if (this.canScrollHorizontal) {
|
||||
this.horizontalScrollBar = new ScrollBarComponent(new Dim2i(this.viewPortDimension.getOriginX(), this.viewPortDimension.getLimitY() + 1, this.viewPortDimension.getWidth(), 10), ScrollBarComponent.Mode.HORIZONTAL, this.frame.dim.getWidth(), this.viewPortDimension.getWidth(), offset -> {
|
||||
this.buildFrame();
|
||||
horizontalScrollBarOffset.set(offset);
|
||||
});
|
||||
this.horizontalScrollBar.setOffset(horizontalScrollBarOffset.get());
|
||||
}
|
||||
if (this.canScrollVertical) {
|
||||
this.verticalScrollBar = new ScrollBarComponent(new Dim2i(this.viewPortDimension.getLimitX() + 1, this.viewPortDimension.getOriginY(), 10, this.viewPortDimension.getHeight()), ScrollBarComponent.Mode.VERTICAL, this.frame.dim.getHeight(), this.viewPortDimension.getHeight(), offset -> {
|
||||
this.buildFrame();
|
||||
verticalScrollBarOffset.set(offset);
|
||||
}, this.viewPortDimension);
|
||||
this.verticalScrollBar.setOffset(verticalScrollBarOffset.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildFrame() {
|
||||
this.children.clear();
|
||||
this.drawable.clear();
|
||||
this.controlElements.clear();
|
||||
|
||||
if (this.canScrollHorizontal) {
|
||||
this.horizontalScrollBar.updateThumbPosition();
|
||||
}
|
||||
|
||||
if (this.canScrollVertical) {
|
||||
this.verticalScrollBar.updateThumbPosition();
|
||||
}
|
||||
|
||||
if (this.canScrollHorizontal) {
|
||||
this.frame.dim.setX(this.frameOrigin.getOriginX() - this.horizontalScrollBar.getOffset());
|
||||
}
|
||||
|
||||
if (this.canScrollVertical) {
|
||||
this.frame.dim.setY(this.frameOrigin.getOriginY() - this.verticalScrollBar.getOffset());
|
||||
}
|
||||
|
||||
this.frame.buildFrame();
|
||||
this.children.add(this.frame);
|
||||
super.buildFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
if (this.canScrollHorizontal || this.canScrollVertical) {
|
||||
if (this.renderOutline) {
|
||||
this.drawRectOutline(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA);
|
||||
}
|
||||
this.applyScissor(this.viewPortDimension.getOriginX(), this.viewPortDimension.getOriginY(), this.viewPortDimension.getWidth(), this.viewPortDimension.getHeight(), () -> super.render(mouseX, mouseY, delta));
|
||||
} else {
|
||||
super.render(mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
if (this.canScrollHorizontal) {
|
||||
this.horizontalScrollBar.render(mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
if (this.canScrollVertical) {
|
||||
this.verticalScrollBar.render(mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
return super.mouseClicked(mouseX, mouseY, button) || (this.canScrollHorizontal && this.horizontalScrollBar.mouseClicked(mouseX, mouseY, button)) || (this.canScrollVertical && this.verticalScrollBar.mouseClicked(mouseX, mouseY, button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button) {
|
||||
return super.mouseDragged(mouseX, mouseY, button) || (this.canScrollHorizontal && this.horizontalScrollBar.mouseDragged(mouseX, mouseY, button)) || (this.canScrollVertical && this.verticalScrollBar.mouseDragged(mouseX, mouseY, button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
return super.mouseReleased(mouseX, mouseY, button) || (this.canScrollHorizontal && this.horizontalScrollBar.mouseReleased(mouseX, mouseY, button)) || (this.canScrollVertical && this.verticalScrollBar.mouseReleased(mouseX, mouseY, button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
|
||||
return super.mouseScrolled(mouseX, mouseY, amount) || (this.canScrollHorizontal && this.horizontalScrollBar.mouseScrolled(mouseX, mouseY, amount)) || (this.canScrollVertical && this.verticalScrollBar.mouseScrolled(mouseX, mouseY, amount));
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private boolean renderOutline = false;
|
||||
private Dim2i dim = null;
|
||||
private AbstractFrame frame = null;
|
||||
private AtomicReference<Integer> verticalScrollBarOffset = new AtomicReference<>(0);
|
||||
private AtomicReference<Integer> horizontalScrollBarOffset = new AtomicReference<>(0);
|
||||
|
||||
public Builder setDimension(Dim2i dim) {
|
||||
this.dim = dim;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder shouldRenderOutline(boolean state) {
|
||||
this.renderOutline = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setVerticalScrollBarOffset(AtomicReference<Integer> verticalScrollBarOffset) {
|
||||
this.verticalScrollBarOffset = verticalScrollBarOffset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setHorizontalScrollBarOffset(AtomicReference<Integer> horizontalScrollBarOffset) {
|
||||
this.horizontalScrollBarOffset = horizontalScrollBarOffset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setFrame(AbstractFrame frame) {
|
||||
this.frame = frame;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScrollableFrame build() {
|
||||
return new ScrollableFrame(this.dim, this.frame, this.renderOutline, this.verticalScrollBarOffset, this.horizontalScrollBarOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package me.flashyreese.mods.reeses_sodium_options.client.gui.frame.components;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ScrollBarComponent extends AbstractWidget {
|
||||
|
||||
protected static final int SCROLL_OFFSET = 6;
|
||||
|
||||
protected final Dim2i dim;
|
||||
|
||||
private final Mode mode;
|
||||
private final int frameLength;
|
||||
private final int viewPortLength;
|
||||
private final int maxScrollBarOffset;
|
||||
private final Consumer<Integer> onSetOffset;
|
||||
@Getter
|
||||
private int offset = 0;
|
||||
private boolean isDragging;
|
||||
|
||||
private Dim2i scrollThumb = null;
|
||||
private int scrollThumbClickOffset;
|
||||
|
||||
private Dim2i extendedScrollArea = null;
|
||||
|
||||
public ScrollBarComponent(Dim2i trackArea, Mode mode, int frameLength, int viewPortLength, Consumer<Integer> onSetOffset) {
|
||||
this.dim = trackArea;
|
||||
this.mode = mode;
|
||||
this.frameLength = frameLength;
|
||||
this.viewPortLength = viewPortLength;
|
||||
this.onSetOffset = onSetOffset;
|
||||
this.maxScrollBarOffset = this.frameLength - this.viewPortLength;
|
||||
}
|
||||
|
||||
public ScrollBarComponent(Dim2i scrollBarArea, Mode mode, int frameLength, int viewPortLength, Consumer<Integer> onSetOffset, Dim2i extendedTrackArea) {
|
||||
this(scrollBarArea, mode, frameLength, viewPortLength, onSetOffset);
|
||||
this.extendedScrollArea = extendedTrackArea;
|
||||
}
|
||||
|
||||
public void updateThumbPosition() {
|
||||
int scrollThumbLength = (this.viewPortLength * (this.mode == Mode.VERTICAL ? this.dim.getHeight() : this.dim.getWidth() - 6)) / this.frameLength;
|
||||
int maximumScrollThumbOffset = this.viewPortLength - scrollThumbLength;
|
||||
int scrollThumbOffset = this.offset * maximumScrollThumbOffset / this.maxScrollBarOffset;
|
||||
this.scrollThumb = new Dim2i(this.dim.getOriginX() + 2 + (this.mode == Mode.HORIZONTAL ? scrollThumbOffset : 0), this.dim.getOriginY() + 2 + (this.mode == Mode.VERTICAL ? scrollThumbOffset : 0), (this.mode == Mode.VERTICAL ? this.dim.getWidth() : scrollThumbLength) - 4, (this.mode == Mode.VERTICAL ? scrollThumbLength : this.dim.getHeight()) - 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
this.drawRectOutline(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA);
|
||||
this.drawRect(this.scrollThumb.getOriginX(), this.scrollThumb.getOriginY(), this.scrollThumb.getLimitX(), this.scrollThumb.getLimitY(), 0xFFAAAAAA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (this.dim.containsCursor(mouseX, mouseY)) {
|
||||
if (this.scrollThumb.containsCursor(mouseX, mouseY)) {
|
||||
if (this.mode == Mode.VERTICAL) {
|
||||
this.scrollThumbClickOffset = (int) (mouseY - this.scrollThumb.getCenterY());
|
||||
} else {
|
||||
this.scrollThumbClickOffset = (int) (mouseX - this.scrollThumb.getCenterX());
|
||||
}
|
||||
this.isDragging = true;
|
||||
} else {
|
||||
int value;
|
||||
if (this.mode == Mode.VERTICAL) {
|
||||
value = (int) ((mouseY - this.dim.getOriginY() - (this.scrollThumb.getHeight() / 2)) / (this.dim.getHeight() - this.scrollThumb.getHeight()) * this.maxScrollBarOffset);
|
||||
} else {
|
||||
value = (int) ((mouseX - this.dim.getOriginX() - (this.scrollThumb.getWidth() / 2)) / (this.dim.getWidth() - this.scrollThumb.getWidth()) * this.maxScrollBarOffset);
|
||||
}
|
||||
this.setOffset(value);
|
||||
this.isDragging = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
this.isDragging = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
if (button == 0) {
|
||||
this.isDragging = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button) {
|
||||
if (this.isDragging) {
|
||||
final int value;
|
||||
if (this.mode == Mode.VERTICAL) {
|
||||
value = (int) ((mouseY - this.scrollThumbClickOffset - this.dim.getOriginY() - (this.scrollThumb.getHeight() / 2)) / (this.dim.getHeight() - this.scrollThumb.getHeight()) * this.maxScrollBarOffset);
|
||||
} else {
|
||||
value = (int) ((mouseX - this.scrollThumbClickOffset - this.dim.getOriginX() - (this.scrollThumb.getWidth() / 2)) / (this.dim.getWidth() - this.scrollThumb.getWidth()) * this.maxScrollBarOffset);
|
||||
}
|
||||
this.setOffset(value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
|
||||
if (this.dim.containsCursor(mouseX, mouseY) || this.extendedScrollArea != null && this.extendedScrollArea.containsCursor(mouseX, mouseY)) {
|
||||
if (this.offset <= this.maxScrollBarOffset && this.offset >= 0) {
|
||||
int value = (int) (this.offset - amount * SCROLL_OFFSET);
|
||||
this.setOffset(value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setOffset(int value) {
|
||||
this.offset = MathHelper.clamp_int(value, 0, this.maxScrollBarOffset);
|
||||
this.updateThumbPosition();
|
||||
this.onSetOffset.accept(this.offset);
|
||||
}
|
||||
|
||||
|
||||
protected void drawRectOutline(double x, double y, double w, double h, int color) {
|
||||
final float a = (float) (color >> 24 & 255) / 255.0F;
|
||||
final float r = (float) (color >> 16 & 255) / 255.0F;
|
||||
final float g = (float) (color >> 8 & 255) / 255.0F;
|
||||
final float b = (float) (color & 255) / 255.0F;
|
||||
|
||||
this.drawQuads(vertices -> {
|
||||
addQuad(vertices, x, y, w, y + 1, a, r, g, b);
|
||||
addQuad(vertices, x, h - 1, w, h, a, r, g, b);
|
||||
addQuad(vertices, x, y, x + 1, h, a, r, g, b);
|
||||
addQuad(vertices, w - 1, y, w, h, a, r, g, b);
|
||||
});
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
HORIZONTAL,
|
||||
VERTICAL
|
||||
}
|
||||
}
|
||||
+499
@@ -0,0 +1,499 @@
|
||||
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;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.ChatAllowedCharacters;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class SearchTextFieldComponent extends AbstractWidget {
|
||||
protected final Dim2i dim;
|
||||
protected final List<OptionPage> pages;
|
||||
private final FontRenderer textRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
private final Predicate<String> textPredicate = Objects::nonNull;
|
||||
private final AtomicReference<String> tabFrameSelectedTab;
|
||||
private final AtomicReference<Integer> tabFrameScrollBarOffset;
|
||||
private final AtomicReference<Integer> optionPageScrollBarOffset;
|
||||
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;
|
||||
@Getter
|
||||
protected boolean visible = true;
|
||||
@Getter
|
||||
protected boolean editable = true;
|
||||
private int firstCharacterIndex;
|
||||
private int selectionStart;
|
||||
private int selectionEnd;
|
||||
@Setter
|
||||
@Getter
|
||||
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) {
|
||||
this.dim = dim;
|
||||
this.pages = pages;
|
||||
this.tabFrameSelectedTab = tabFrameSelectedTab;
|
||||
this.tabFrameScrollBarOffset = tabFrameScrollBarOffset;
|
||||
this.optionPageScrollBarOffset = optionPageScrollBarOffset;
|
||||
this.tabDimHeight = tabDimHeight;
|
||||
this.sodiumVideoOptionsScreen = sodiumVideoOptionsScreen;
|
||||
this.lastSearch = lastSearch;
|
||||
this.lastSearchIndex = lastSearchIndex;
|
||||
if (!lastSearch.get().trim().isEmpty()) {
|
||||
this.write(lastSearch.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
if (!this.isVisible()) {
|
||||
return;
|
||||
}
|
||||
if (!this.isFocused() && this.text.isEmpty()) {
|
||||
final String key = "rso.search_bar_empty";
|
||||
String text = I18n.format(key);
|
||||
if (text.equals(key))
|
||||
text = "Search options...";
|
||||
this.textRenderer.drawString(text, this.dim.getOriginX() + 6, this.dim.getOriginY() + 6, 0xFFAAAAAA);
|
||||
}
|
||||
|
||||
drawRect(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getLimitX(), this.dim.getLimitY(), this.isFocused() ? 0xE0000000 : 0x90000000);
|
||||
final int j = this.selectionStart - this.firstCharacterIndex;
|
||||
int k = this.selectionEnd - this.firstCharacterIndex;
|
||||
final String string = this.textRenderer.trimStringToWidth(this.text.substring(this.firstCharacterIndex), this.getInnerWidth());
|
||||
final boolean bl = j >= 0 && j <= string.length();
|
||||
final int l = this.dim.getOriginX() + 6;
|
||||
final int m = this.dim.getOriginY() + 6;
|
||||
int n = l;
|
||||
if (k > string.length()) {
|
||||
k = string.length();
|
||||
}
|
||||
if (!string.isEmpty()) {
|
||||
final String string2 = bl ? string.substring(0, j) : string;
|
||||
n = this.textRenderer.drawStringWithShadow(string2, n, m, 0xE0E0E0);
|
||||
}
|
||||
final boolean bl3 = this.selectionStart < this.text.length() || this.text.length() >= this.getMaxLength();
|
||||
int o = n;
|
||||
if (!bl) {
|
||||
o = j > 0 ? l + this.dim.getWidth() - 12 : l;
|
||||
} else if (bl3) {
|
||||
--o;
|
||||
--n;
|
||||
}
|
||||
if (!string.isEmpty() && bl && j < string.length()) {
|
||||
this.textRenderer.drawStringWithShadow(string.substring(j), n, m, 0xE0E0E0);
|
||||
}
|
||||
// Cursor
|
||||
if (this.isFocused()) {
|
||||
drawRect(o, m - 1, o + 1, m + 1 + this.textRenderer.FONT_HEIGHT, -0x2F2F30);
|
||||
}
|
||||
// Highlighted text
|
||||
if (k != j) {
|
||||
final int p = l + this.textRenderer.getStringWidth(string.substring(0, k));
|
||||
this.drawSelectionHighlight(o, m - 1, p - 1, m + 1 + this.textRenderer.FONT_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
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();
|
||||
}
|
||||
|
||||
private void drawSelectionHighlight(int x1, int y1, int x2, int y2) {
|
||||
int i;
|
||||
if (x1 < x2) {
|
||||
i = x1;
|
||||
x1 = x2;
|
||||
x2 = i;
|
||||
}
|
||||
if (y1 < y2) {
|
||||
i = y1;
|
||||
y1 = y2;
|
||||
y2 = i;
|
||||
}
|
||||
if (x2 > this.dim.getOriginX() + this.dim.getWidth()) {
|
||||
x2 = this.dim.getOriginX() + this.dim.getWidth();
|
||||
}
|
||||
if (x1 > this.dim.getOriginX() + this.dim.getWidth()) {
|
||||
x1 = this.dim.getOriginX() + this.dim.getWidth();
|
||||
}
|
||||
GL11.glEnable(GL11.GL_COLOR_LOGIC_OP);
|
||||
GL11.glLogicOp(GL11.GL_OR_REVERSE);
|
||||
|
||||
drawRect(x1, y1, x2, y2, -0xFFFF01);
|
||||
|
||||
GL11.glDisable(GL11.GL_COLOR_LOGIC_OP);
|
||||
|
||||
}
|
||||
|
||||
private int getMaxLength() {
|
||||
return this.maxLength;
|
||||
}
|
||||
|
||||
public String getSelectedText() {
|
||||
final int i = Math.min(this.selectionStart, this.selectionEnd);
|
||||
final int j = Math.max(this.selectionStart, this.selectionEnd);
|
||||
return this.text.substring(i, j);
|
||||
}
|
||||
|
||||
public void write(String text) {
|
||||
|
||||
|
||||
final int i = Math.min(this.selectionStart, this.selectionEnd);
|
||||
final int j = Math.max(this.selectionStart, this.selectionEnd);
|
||||
final int k = this.maxLength - this.text.length() - (i - j);
|
||||
String string = text; //SharedConstants.stripInvalidChars(text);
|
||||
int l = string.length();
|
||||
if (k < l) {
|
||||
string = string.substring(0, k);
|
||||
l = k;
|
||||
}
|
||||
|
||||
final String string2 = (new StringBuilder(this.text)).replace(i, j, string).toString();
|
||||
if (this.textPredicate.test(string2)) {
|
||||
this.text = string2;
|
||||
this.setSelectionStart(i + l);
|
||||
this.setSelectionEnd(this.selectionStart);
|
||||
this.onChanged(this.text);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void erase(int offset) {
|
||||
if (GuiScreen.isCtrlKeyDown()) {
|
||||
this.eraseWords(offset);
|
||||
} else {
|
||||
this.eraseCharacters(offset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void eraseWords(int wordOffset) {
|
||||
if (!this.text.isEmpty()) {
|
||||
if (this.selectionEnd != this.selectionStart) {
|
||||
this.write("");
|
||||
} else {
|
||||
this.eraseCharacters(this.getWordSkipPosition(wordOffset) - this.selectionStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void eraseCharacters(int characterOffset) {
|
||||
if (!this.text.isEmpty()) {
|
||||
if (this.selectionEnd != this.selectionStart) {
|
||||
this.write("");
|
||||
} else {
|
||||
final int i = this.getCursorPosWithOffset(characterOffset);
|
||||
final int j = Math.min(i, this.selectionStart);
|
||||
final int k = Math.max(i, this.selectionStart);
|
||||
if (j != k) {
|
||||
final String string = (new StringBuilder(this.text)).delete(j, k).toString();
|
||||
if (this.textPredicate.test(string)) {
|
||||
this.text = string;
|
||||
this.setCursor(j);
|
||||
this.onChanged(this.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getWordSkipPosition(int wordOffset) {
|
||||
return this.getWordSkipPosition(wordOffset, this.getCursor());
|
||||
}
|
||||
|
||||
private int getWordSkipPosition(int wordOffset, int cursorPosition) {
|
||||
return this.getWordSkipPosition(wordOffset, cursorPosition, true);
|
||||
}
|
||||
|
||||
private int getWordSkipPosition(int wordOffset, int cursorPosition, boolean skipOverSpaces) {
|
||||
int i = cursorPosition;
|
||||
final boolean bl = wordOffset < 0;
|
||||
final int j = Math.abs(wordOffset);
|
||||
|
||||
for (int k = 0; k < j; ++k) {
|
||||
if (!bl) {
|
||||
final int l = this.text.length();
|
||||
i = this.text.indexOf(32, i);
|
||||
if (i == -1) {
|
||||
i = l;
|
||||
} else {
|
||||
while (skipOverSpaces && i < l && this.text.charAt(i) == ' ') {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (skipOverSpaces && i > 0 && this.text.charAt(i - 1) == ' ') {
|
||||
--i;
|
||||
}
|
||||
|
||||
while (i > 0 && this.text.charAt(i - 1) != ' ') {
|
||||
--i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public int getCursor() {
|
||||
return this.selectionStart;
|
||||
}
|
||||
|
||||
public void setCursor(int cursor) {
|
||||
this.setSelectionStart(cursor);
|
||||
if (!this.selecting) {
|
||||
this.setSelectionEnd(this.selectionStart);
|
||||
}
|
||||
|
||||
this.onChanged(this.text);
|
||||
}
|
||||
|
||||
public void moveCursor(int offset) {
|
||||
this.setCursor(this.getCursorPosWithOffset(offset));
|
||||
}
|
||||
|
||||
private int getCursorPosWithOffset(int offset) {
|
||||
//return Util.moveCursor(this.text, this.selectionStart, offset);
|
||||
return this.selectionStart + offset;
|
||||
}
|
||||
|
||||
public void setSelectionStart(int cursor) {
|
||||
this.selectionStart = MathHelper.clamp_int(cursor, 0, this.text.length());
|
||||
}
|
||||
|
||||
public void setCursorToStart() {
|
||||
this.setCursor(0);
|
||||
}
|
||||
|
||||
public void setCursorToEnd() {
|
||||
this.setCursor(this.text.length());
|
||||
}
|
||||
|
||||
public void setSelectionEnd(int index) {
|
||||
final int i = this.text.length();
|
||||
this.selectionEnd = MathHelper.clamp_int(index, 0, i);
|
||||
if (this.textRenderer != null) {
|
||||
if (this.firstCharacterIndex > i) {
|
||||
this.firstCharacterIndex = i;
|
||||
}
|
||||
|
||||
final int j = this.getInnerWidth();
|
||||
final String string = this.textRenderer.trimStringToWidth(this.text.substring(this.firstCharacterIndex), j);
|
||||
final int k = string.length() + this.firstCharacterIndex;
|
||||
if (this.selectionEnd == this.firstCharacterIndex) {
|
||||
this.firstCharacterIndex -= this.textRenderer.trimStringToWidth(this.text, j, true).length();
|
||||
}
|
||||
|
||||
if (this.selectionEnd > k) {
|
||||
this.firstCharacterIndex += this.selectionEnd - k;
|
||||
} else if (this.selectionEnd <= this.firstCharacterIndex) {
|
||||
this.firstCharacterIndex -= this.firstCharacterIndex - this.selectionEnd;
|
||||
}
|
||||
|
||||
this.firstCharacterIndex = MathHelper.clamp_int(this.firstCharacterIndex, 0, i);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return this.isVisible() && this.isFocused() && this.isEditable();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean charTyped(char chr, int modifiers) {
|
||||
// if (!this.isActive()) {
|
||||
// return false;
|
||||
// }
|
||||
// if (SharedConstants.isValidChar(chr)) {
|
||||
// if (this.editable) {
|
||||
// this.lastSearch.set(this.text.trim());
|
||||
// this.write(Character.toString(chr));
|
||||
// this.lastSearchIndex.set(0);
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
@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 {
|
||||
this.selecting = GuiScreen.isShiftKeyDown();
|
||||
if (keyCode == Keyboard.KEY_A && GuiScreen.isCtrlKeyDown() && !GuiScreen.isShiftKeyDown() ) {
|
||||
// Select all
|
||||
this.setCursorToEnd();
|
||||
this.setSelectionEnd(0);
|
||||
return true;
|
||||
} else if (keyCode == Keyboard.KEY_C && GuiScreen.isCtrlKeyDown() && !GuiScreen.isShiftKeyDown() ) {
|
||||
// Copy
|
||||
GuiScreen.setClipboardString(this.getSelectedText());
|
||||
return true;
|
||||
} else if (keyCode == Keyboard.KEY_V && GuiScreen.isCtrlKeyDown() && !GuiScreen.isShiftKeyDown() ) {
|
||||
// Paste
|
||||
if (this.editable) {
|
||||
this.write(GuiScreen.getClipboardString());
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (keyCode == Keyboard.KEY_X && GuiScreen.isCtrlKeyDown() && !GuiScreen.isShiftKeyDown() ) {
|
||||
// Cut
|
||||
GuiScreen.setClipboardString(this.getSelectedText());
|
||||
if (this.editable) {
|
||||
this.write("");
|
||||
}
|
||||
|
||||
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;
|
||||
this.erase(-1);
|
||||
this.selecting = GuiScreen.isShiftKeyDown();
|
||||
}
|
||||
return true;
|
||||
case Keyboard.KEY_DELETE: // GLFW.GLFW_KEY_DELETE
|
||||
if (this.editable) {
|
||||
this.selecting = false;
|
||||
this.erase(1);
|
||||
this.selecting = GuiScreen.isShiftKeyDown();
|
||||
}
|
||||
return true;
|
||||
case Keyboard.KEY_RIGHT: // GLFW.GLFW_KEY_RIGHT
|
||||
if (GuiScreen.isCtrlKeyDown()) {
|
||||
this.setCursor(this.getWordSkipPosition(1));
|
||||
} else {
|
||||
this.moveCursor(1);
|
||||
}
|
||||
final boolean state = this.getCursor() != this.lastCursorPosition && this.getCursor() != this.text.length() + 1;
|
||||
this.lastCursorPosition = this.getCursor();
|
||||
return state;
|
||||
case Keyboard.KEY_LEFT: // GLFW.GLFW_KEY_LEFT
|
||||
if (GuiScreen.isCtrlKeyDown()) {
|
||||
this.setCursor(this.getWordSkipPosition(-1));
|
||||
} else {
|
||||
this.moveCursor(-1);
|
||||
}
|
||||
final boolean state2 = this.getCursor() != this.lastCursorPosition && this.getCursor() != 0;
|
||||
this.lastCursorPosition = this.getCursor();
|
||||
return state2;
|
||||
case Keyboard.KEY_HOME: // GLFW.GLFW_KEY_HOME
|
||||
this.setCursorToStart();
|
||||
return true;
|
||||
case Keyboard.KEY_END: // GLFW.GLFW_KEY_END
|
||||
this.setCursorToEnd();
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getInnerWidth() {
|
||||
return this.dim.getWidth() - 12;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
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.OptionPage;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Tab<T extends AbstractFrame> {
|
||||
private final String title;
|
||||
private final Function<Dim2i, T> frameFunction;
|
||||
|
||||
public Tab(String title, Function<Dim2i, T> frameFunction) {
|
||||
this.title = title;
|
||||
this.frameFunction = frameFunction;
|
||||
}
|
||||
|
||||
public static Builder<?> createBuilder() {
|
||||
return new Builder<>();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public Function<Dim2i, T> getFrameFunction() {
|
||||
return this.frameFunction;
|
||||
}
|
||||
|
||||
public static class Builder<T extends AbstractFrame> {
|
||||
private String title;
|
||||
private Function<Dim2i, T> frameFunction;
|
||||
|
||||
public Builder<T> setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> setFrameFunction(Function<Dim2i, T> frameFunction) {
|
||||
this.frameFunction = frameFunction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Tab<T> build() {
|
||||
return new Tab<>(this.title, this.frameFunction);
|
||||
}
|
||||
|
||||
public Tab<ScrollableFrame> from(OptionPage page, AtomicReference<Integer> verticalScrollBarOffset) {
|
||||
return new Tab<>(page.getName(), dim2i -> ScrollableFrame
|
||||
.createBuilder()
|
||||
.setDimension(dim2i)
|
||||
.setFrame(OptionPageFrame
|
||||
.createBuilder()
|
||||
.setDimension(new Dim2i(dim2i.getOriginX(), dim2i.getOriginY(), dim2i.getWidth(), dim2i.getHeight()))
|
||||
.setOptionPage(page)
|
||||
.build())
|
||||
.setVerticalScrollBarOffset(verticalScrollBarOffset)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
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.components.ScrollBarComponent;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TabFrame extends AbstractFrame {
|
||||
|
||||
private final boolean tabSectionCanScroll;
|
||||
private final Dim2i tabSection;
|
||||
private final Dim2i frameSection;
|
||||
private final List<Tab<?>> tabs = new ArrayList<>();
|
||||
private final Runnable onSetTab;
|
||||
private final AtomicReference<String> tabSectionSelectedTab;
|
||||
private ScrollBarComponent tabSectionScrollBar = null;
|
||||
private Tab<?> selectedTab;
|
||||
private AbstractFrame selectedFrame;
|
||||
|
||||
public TabFrame(Dim2i dim, boolean renderOutline, List<Tab<?>> tabs, Runnable onSetTab, AtomicReference<String> tabSectionSelectedTab, AtomicReference<Integer> tabSectionScrollBarOffset) {
|
||||
super(dim, renderOutline);
|
||||
this.tabs.addAll(tabs);
|
||||
final int tabSectionY = this.tabs.size() * 18;
|
||||
this.tabSectionCanScroll = tabSectionY > this.dim.getHeight();
|
||||
|
||||
final Optional<Integer> result = tabs.stream().map(tab -> this.getTextWidth(tab.getTitle())).max(Integer::compareTo);
|
||||
|
||||
this.tabSection = new Dim2i(this.dim.getOriginX(), this.dim.getOriginY(), result.map(integer -> integer + (this.tabSectionCanScroll ? 32 : 24)).orElseGet(() -> (int) (this.dim.getWidth() * 0.35D)), this.dim.getHeight());
|
||||
this.frameSection = new Dim2i(this.tabSection.getLimitX(), this.dim.getOriginY(), this.dim.getWidth() - this.tabSection.getWidth(), this.dim.getHeight());
|
||||
|
||||
this.onSetTab = onSetTab;
|
||||
if (this.tabSectionCanScroll) {
|
||||
this.tabSectionScrollBar = new ScrollBarComponent(new Dim2i(this.tabSection.getLimitX() - 11, this.tabSection.getOriginY(), 10, this.tabSection.getHeight()), ScrollBarComponent.Mode.VERTICAL, tabSectionY, this.dim.getHeight(), offset -> {
|
||||
this.buildFrame();
|
||||
tabSectionScrollBarOffset.set(offset);
|
||||
}, this.dim);
|
||||
this.tabSectionScrollBar.setOffset(tabSectionScrollBarOffset.get());
|
||||
}
|
||||
this.tabSectionSelectedTab = tabSectionSelectedTab;
|
||||
|
||||
if (this.tabSectionSelectedTab.get() != null) {
|
||||
this.selectedTab = this.tabs.stream().filter(tab -> tab.getTitle().equals(this.tabSectionSelectedTab.get())).findAny().get();
|
||||
}
|
||||
|
||||
this.buildFrame();
|
||||
|
||||
// Let's build each frame, future note for anyone: do not move this line.
|
||||
this.tabs.stream().filter(tab -> this.selectedTab != tab).forEach(tab -> tab.getFrameFunction().apply(this.frameSection));
|
||||
}
|
||||
|
||||
public static Builder createBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public void setTab(Tab<?> tab) {
|
||||
this.selectedTab = tab;
|
||||
this.tabSectionSelectedTab.set(this.selectedTab.getTitle());
|
||||
if (this.onSetTab != null) {
|
||||
this.onSetTab.run();
|
||||
}
|
||||
this.buildFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildFrame() {
|
||||
this.children.clear();
|
||||
this.drawable.clear();
|
||||
this.controlElements.clear();
|
||||
|
||||
if (this.selectedTab == null) {
|
||||
if (!this.tabs.isEmpty()) {
|
||||
// Just use the first tab for now
|
||||
this.selectedTab = this.tabs.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
this.rebuildTabs();
|
||||
this.rebuildTabFrame();
|
||||
|
||||
if (this.tabSectionCanScroll) {
|
||||
this.tabSectionScrollBar.updateThumbPosition();
|
||||
}
|
||||
|
||||
super.buildFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float delta) {
|
||||
this.applyScissor(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getWidth(), this.dim.getHeight(), () -> {
|
||||
for (AbstractWidget widget: this.children) {
|
||||
if (widget != this.selectedFrame){
|
||||
widget.render(mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.selectedFrame.render(mouseX, mouseY, delta);
|
||||
if (this.tabSectionCanScroll) {
|
||||
this.tabSectionScrollBar.render(mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
return (this.dim.containsCursor(mouseX, mouseY) && super.mouseClicked(mouseX, mouseY, button)) || (this.tabSectionCanScroll && this.tabSectionScrollBar.mouseClicked(mouseX, mouseY, button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button) {
|
||||
return super.mouseDragged(mouseX, mouseY, button) || (this.tabSectionCanScroll && this.tabSectionScrollBar.mouseDragged(mouseX, mouseY, button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
return super.mouseReleased(mouseX, mouseY, button) || (this.tabSectionCanScroll && this.tabSectionScrollBar.mouseReleased(mouseX, mouseY, button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
|
||||
return super.mouseScrolled(mouseX, mouseY, amount) || (this.tabSectionCanScroll && this.tabSectionScrollBar.mouseScrolled(mouseX, mouseY, amount));
|
||||
}
|
||||
|
||||
private void rebuildTabs() {
|
||||
int offsetY = 0;
|
||||
for (Tab<?> tab : this.tabs) {
|
||||
final int x = this.tabSection.getOriginX();
|
||||
final int y = this.tabSection.getOriginY() + offsetY - (this.tabSectionCanScroll ? this.tabSectionScrollBar.getOffset() : 0);
|
||||
final int width = this.tabSection.getWidth() - (this.tabSectionCanScroll ? 12 : 4);
|
||||
final int height = 18;
|
||||
final Dim2i tabDim = new Dim2i(x, y, width, height);
|
||||
|
||||
FlatButtonWidget button = new FlatButtonWidget(tabDim, tab.getTitle(), () -> this.setTab(tab));
|
||||
button.setSelected(this.selectedTab == tab);
|
||||
button.setLeftAligned(true);
|
||||
this.children.add(button);
|
||||
|
||||
offsetY += 18;
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildTabFrame() {
|
||||
if (this.selectedTab == null) return;
|
||||
AbstractFrame frame = this.selectedTab.getFrameFunction().apply(this.frameSection);
|
||||
if (frame != null) {
|
||||
this.selectedFrame = frame;
|
||||
frame.buildFrame();
|
||||
this.children.add(frame);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final List<Tab<?>> functions = new ArrayList<>();
|
||||
private Dim2i dim;
|
||||
private boolean renderOutline;
|
||||
private Runnable onSetTab;
|
||||
private AtomicReference<String> tabSectionSelectedTab = new AtomicReference<>(null);
|
||||
private AtomicReference<Integer> tabSectionScrollBarOffset = new AtomicReference<>(0);
|
||||
|
||||
public Builder setDimension(Dim2i dim) {
|
||||
this.dim = dim;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder shouldRenderOutline(boolean renderOutline) {
|
||||
this.renderOutline = renderOutline;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addTabs(Consumer<List<Tab<?>>> tabs) {
|
||||
tabs.accept(this.functions);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder onSetTab(Runnable onSetTab) {
|
||||
this.onSetTab = onSetTab;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTabSectionSelectedTab(AtomicReference<String> tabSectionSelectedTab) {
|
||||
this.tabSectionSelectedTab = tabSectionSelectedTab;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTabSectionScrollBarOffset(AtomicReference<Integer> tabSectionScrollBarOffset) {
|
||||
this.tabSectionScrollBarOffset = tabSectionScrollBarOffset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TabFrame build() {
|
||||
Validate.notNull(this.dim, "Dimension must be specified");
|
||||
|
||||
return new TabFrame(this.dim, this.renderOutline, this.functions, this.onSetTab, this.tabSectionSelectedTab, this.tabSectionScrollBarOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package me.flashyreese.mods.reeses_sodium_options.util;
|
||||
|
||||
import me.jellysquid.mods.sodium.client.gui.options.Option;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StringUtils {
|
||||
// Levenshtein distance: Calculates the number of edits (insertion, deletion, substitution) needed to transform one string into another.
|
||||
public static int levenshteinDistance(String s1, String s2) {
|
||||
int m = s1.length();
|
||||
int n = s2.length();
|
||||
|
||||
int[][] dp = new int[m + 1][n + 1];
|
||||
|
||||
for (int i = 0; i <= m; i++) {
|
||||
dp[i][0] = i;
|
||||
}
|
||||
|
||||
for (int j = 0; j <= n; j++) {
|
||||
dp[0][j] = j;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
int cost = s1.charAt(i - 1) == s2.charAt(j - 1) ? 0 : 1;
|
||||
dp[i][j] = Math.min(dp[i - 1][j] + 1, Math.min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost));
|
||||
}
|
||||
}
|
||||
|
||||
return dp[m][n];
|
||||
}
|
||||
|
||||
public static List<Option<?>> fuzzySearch(List<OptionPage> pages, String userInput, int maxDistance) {
|
||||
List<Option<?>> result = new ArrayList<>();
|
||||
String[] targetWords = userInput.toLowerCase().split("\\s+");
|
||||
|
||||
for (OptionPage page : pages) {
|
||||
for (Option<?> option : page.getOptions()) {
|
||||
String sentence = (option.getName()/* +
|
||||
" " +
|
||||
option.getTooltip().getString()+
|
||||
" " +
|
||||
option.getImpact().toString()*/).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)) {
|
||||
containsWord = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!containsWord) {
|
||||
containsAllWords = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (containsAllWords) {
|
||||
result.add(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package me.jellysquid.mods.sodium.client.gui;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import jss.notfine.core.Settings;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.ReeseSodiumVideoOptionsScreen;
|
||||
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.OptionImpact;
|
||||
@@ -96,7 +97,10 @@ public class SodiumGameOptionPages {
|
||||
.setBinding((opts, value) -> {
|
||||
opts.guiScale = value;
|
||||
// Resizing our window
|
||||
if(Minecraft.getMinecraft().currentScreen instanceof SodiumOptionsGUI oldGui) {
|
||||
if(Minecraft.getMinecraft().currentScreen instanceof ReeseSodiumVideoOptionsScreen oldGui) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new ReeseSodiumVideoOptionsScreen(oldGui.prevScreen));
|
||||
}
|
||||
else if(Minecraft.getMinecraft().currentScreen instanceof SodiumOptionsGUI oldGui) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SodiumOptionsGUI(oldGui.prevScreen));
|
||||
}
|
||||
}, opts -> opts.guiScale)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package me.jellysquid.mods.sodium.client.gui;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.gtnewhorizons.angelica.client.gui.ScrollableGuiScreen;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Drawable;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Element;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import jss.notfine.gui.GuiCustomMenu;
|
||||
import me.jellysquid.mods.sodium.client.SodiumClientMod;
|
||||
@@ -13,8 +16,6 @@ import me.jellysquid.mods.sodium.client.gui.options.control.Control;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.control.element.SodiumControlElementFactory;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
|
||||
import me.jellysquid.mods.sodium.client.gui.utils.Drawable;
|
||||
import me.jellysquid.mods.sodium.client.gui.utils.Element;
|
||||
import me.jellysquid.mods.sodium.client.gui.utils.URLUtils;
|
||||
import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
@@ -32,28 +33,29 @@ import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SodiumOptionsGUI extends GuiScreen {
|
||||
public class SodiumOptionsGUI extends ScrollableGuiScreen {
|
||||
|
||||
private static final SodiumControlElementFactory elementFactory = new SodiumControlElementFactory();
|
||||
protected static final SodiumControlElementFactory elementFactory = new SodiumControlElementFactory();
|
||||
|
||||
private final List<Element> children = new CopyOnWriteArrayList<>();
|
||||
protected final List<Element> children = new CopyOnWriteArrayList<>();
|
||||
|
||||
private final List<OptionPage> pages = new ArrayList<>();
|
||||
protected final List<OptionPage> pages = new ArrayList<>();
|
||||
|
||||
private final List<ControlElement<?>> controls = new ArrayList<>();
|
||||
private final List<Drawable> drawable = new ArrayList<>();
|
||||
protected final List<ControlElement<?>> controls = new ArrayList<>();
|
||||
protected final List<Drawable> drawable = new ArrayList<>();
|
||||
|
||||
public final GuiScreen prevScreen;
|
||||
|
||||
private OptionPage currentPage;
|
||||
protected OptionPage currentPage;
|
||||
|
||||
private FlatButtonWidget applyButton, closeButton, undoButton;
|
||||
private FlatButtonWidget donateButton, hideDonateButton;
|
||||
protected FlatButtonWidget applyButton, closeButton, undoButton;
|
||||
protected FlatButtonWidget donateButton, hideDonateButton;
|
||||
|
||||
private boolean hasPendingChanges;
|
||||
private ControlElement<?> hoveredElement;
|
||||
protected boolean hasPendingChanges;
|
||||
protected ControlElement<?> hoveredElement;
|
||||
|
||||
protected OptionPage shaderPacks;
|
||||
|
||||
private OptionPage shaderPacks;
|
||||
|
||||
public SodiumOptionsGUI(GuiScreen prevScreen) {
|
||||
this.prevScreen = prevScreen;
|
||||
@@ -63,7 +65,7 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
this.pages.add(SodiumGameOptionPages.advanced());
|
||||
this.pages.add(SodiumGameOptionPages.performance());
|
||||
|
||||
if(AngelicaConfig.enableIris) {
|
||||
if (AngelicaConfig.enableIris) {
|
||||
shaderPacks = new OptionPage(I18n.format("options.iris.shaderPackSelection"), ImmutableList.of());
|
||||
this.pages.add(shaderPacks);
|
||||
}
|
||||
@@ -85,7 +87,7 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
this.rebuildGUI();
|
||||
}
|
||||
|
||||
private void rebuildGUI() {
|
||||
protected void rebuildGUI() {
|
||||
this.controls.clear();
|
||||
this.children.clear();
|
||||
this.drawable.clear();
|
||||
@@ -105,8 +107,8 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
this.undoButton = new FlatButtonWidget(new Dim2i(this.width - 211, this.height - 26, 65, 20), I18n.format("sodium.options.buttons.undo"), this::undoChanges);
|
||||
this.applyButton = new FlatButtonWidget(new Dim2i(this.width - 142, this.height - 26, 65, 20), I18n.format("sodium.options.buttons.apply"), this::applyChanges);
|
||||
this.closeButton = new FlatButtonWidget(new Dim2i(this.width - 73, this.height - 26, 65, 20), I18n.format("gui.done"), this::onClose);
|
||||
String donateToJelly = I18n.format("sodium.options.buttons.donate");
|
||||
int width = 12 + this.fontRendererObj.getStringWidth(donateToJelly);
|
||||
final String donateToJelly = I18n.format("sodium.options.buttons.donate");
|
||||
final int width = 12 + this.fontRendererObj.getStringWidth(donateToJelly);
|
||||
this.donateButton = new FlatButtonWidget(new Dim2i(this.width - width - 32, 6, width, 20), donateToJelly, () -> openDonationPage("https://caffeinemc.net/donate"));
|
||||
this.hideDonateButton = new FlatButtonWidget(new Dim2i(this.width - 26, 6, 20, 20), "x", this::hideDonationButton);
|
||||
|
||||
@@ -133,7 +135,7 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
}
|
||||
|
||||
private void hideDonationButton() {
|
||||
SodiumGameOptions options = SodiumClientMod.options();
|
||||
final SodiumGameOptions options = SodiumClientMod.options();
|
||||
options.notifications.hideDonationButton = true;
|
||||
|
||||
try {
|
||||
@@ -147,12 +149,12 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
|
||||
private void rebuildGUIPages() {
|
||||
int x = 6;
|
||||
int y = 6;
|
||||
final int y = 6;
|
||||
|
||||
for (OptionPage page : this.pages) {
|
||||
int width = 12 + this.fontRendererObj.getStringWidth(page.getName());
|
||||
final int width = 12 + this.fontRendererObj.getStringWidth(page.getName());
|
||||
|
||||
FlatButtonWidget button = new FlatButtonWidget(new Dim2i(x, y, width, 18), page.getName(), () -> this.setPage(page));
|
||||
final FlatButtonWidget button = new FlatButtonWidget(new Dim2i(x, y, width, 18), page.getName(), () -> this.setPage(page));
|
||||
button.setSelected(this.currentPage == page);
|
||||
|
||||
x += width + 6;
|
||||
@@ -162,14 +164,14 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
}
|
||||
|
||||
private void rebuildGUIOptions() {
|
||||
int x = 6;
|
||||
final int x = 6;
|
||||
int y = 28;
|
||||
|
||||
for (OptionGroup group : this.currentPage.getGroups()) {
|
||||
// Add each option's control element
|
||||
for (Option<?> option : group.getOptions()) {
|
||||
Control<?> control = option.getControl();
|
||||
ControlElement<?> element = control.createElement(new Dim2i(x, y, 200, 18), elementFactory);
|
||||
final Control<?> control = option.getControl();
|
||||
final ControlElement<?> element = control.createElement(new Dim2i(x, y, 200, 18), elementFactory);
|
||||
|
||||
this.controls.add(element);
|
||||
//Safe if SodiumControlElementFactory or a compatible ControlElementFactory is used to create element.
|
||||
@@ -186,6 +188,7 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float delta) {
|
||||
super.drawScreen(mouseX, mouseY, delta);
|
||||
super.drawDefaultBackground();
|
||||
|
||||
this.updateControls();
|
||||
@@ -199,14 +202,18 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Element> children() {
|
||||
return children;
|
||||
}
|
||||
|
||||
private void updateControls() {
|
||||
ControlElement<?> hovered = this.getActiveControls()
|
||||
.filter(ControlElement::isHovered)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
boolean hasChanges = this.getAllOptions()
|
||||
.anyMatch(Option::hasChanged);
|
||||
boolean hasChanges = this.getAllOptions().anyMatch(Option::hasChanged);
|
||||
|
||||
for (OptionPage page : this.pages) {
|
||||
for (Option<?> option : page.getOptions()) {
|
||||
@@ -234,28 +241,28 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
}
|
||||
|
||||
private void renderOptionTooltip(ControlElement<?> element) {
|
||||
Dim2i dim = element.getDimensions();
|
||||
final Dim2i dim = element.getDimensions();
|
||||
|
||||
int textPadding = 3;
|
||||
int boxPadding = 3;
|
||||
final int textPadding = 3;
|
||||
final int boxPadding = 3;
|
||||
|
||||
int boxWidth = 200;
|
||||
final int boxWidth = 200;
|
||||
|
||||
int boxY = dim.getOriginY();
|
||||
int boxX = dim.getLimitX() + boxPadding;
|
||||
final int boxX = dim.getLimitX() + boxPadding;
|
||||
|
||||
Option<?> option = element.getOption();
|
||||
List<String> tooltip = new ArrayList<>(this.fontRendererObj.listFormattedStringToWidth(option.getTooltip(), boxWidth - (textPadding * 2)));
|
||||
final Option<?> option = element.getOption();
|
||||
final List<String> tooltip = new ArrayList<>(this.fontRendererObj.listFormattedStringToWidth(option.getTooltip(), boxWidth - (textPadding * 2)));
|
||||
|
||||
OptionImpact impact = option.getImpact();
|
||||
final OptionImpact impact = option.getImpact();
|
||||
|
||||
if (impact != null) {
|
||||
tooltip.add(EnumChatFormatting.GRAY + I18n.format("sodium.options.performance_impact_string", impact.toDisplayString()));
|
||||
}
|
||||
|
||||
int boxHeight = (tooltip.size() * 12) + boxPadding;
|
||||
int boxYLimit = boxY + boxHeight;
|
||||
int boxYCutoff = this.height - 40;
|
||||
final int boxHeight = (tooltip.size() * 12) + boxPadding;
|
||||
final int boxYLimit = boxY + boxHeight;
|
||||
final int boxYCutoff = this.height - 40;
|
||||
|
||||
// If the box is going to be cutoff on the Y-axis, move it back up the difference
|
||||
if (boxYLimit > boxYCutoff) {
|
||||
@@ -299,8 +306,7 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
}
|
||||
|
||||
private void undoChanges() {
|
||||
this.getAllOptions()
|
||||
.forEach(Option::reset);
|
||||
this.getAllOptions().forEach(Option::reset);
|
||||
}
|
||||
|
||||
private void openDonationPage(String url) {
|
||||
@@ -340,9 +346,10 @@ public class SodiumOptionsGUI extends GuiScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
protected void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
|
||||
super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
|
||||
|
||||
this.children.forEach(element -> element.mouseDragged(mouseX, mouseY));
|
||||
this.children.forEach(element -> element.mouseDragged(mouseX, mouseY, mouseButton));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,4 +29,5 @@ public interface Option<T> {
|
||||
void applyChanges();
|
||||
|
||||
Collection<OptionFlag> getFlags();
|
||||
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package me.jellysquid.mods.sodium.client.gui.options;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.OptionExtended;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.binding.GenericBinding;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.binding.OptionBinding;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.control.Control;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -13,7 +17,7 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class OptionImpl<S, T> implements Option<T> {
|
||||
public class OptionImpl<S, T> implements OptionExtended<T> {
|
||||
private final OptionStorage<S> storage;
|
||||
|
||||
private final OptionBinding<S, T> binding;
|
||||
@@ -207,4 +211,11 @@ public class OptionImpl<S, T> implements Option<T> {
|
||||
return new OptionImpl<>(this.storage, this.name, this.tooltip, this.binding, this.control, this.flags, this.impact, this.enabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Setter @Getter private Dim2i parentDimension;
|
||||
@Setter @Getter private Dim2i dim2i;
|
||||
@Setter @Getter private boolean highlight;
|
||||
@Setter @Getter private boolean selected;
|
||||
|
||||
}
|
||||
+3
-3
@@ -4,8 +4,8 @@ import me.jellysquid.mods.sodium.client.gui.options.Option;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
|
||||
public interface ControlElement<T> {
|
||||
public boolean isHovered();
|
||||
public Option<T> getOption();
|
||||
public Dim2i getDimensions();
|
||||
boolean isHovered();
|
||||
Option<T> getOption();
|
||||
Dim2i getDimensions();
|
||||
|
||||
}
|
||||
+4
-4
@@ -17,7 +17,7 @@ public class CyclingControl<T extends Enum<T>> implements Control<T> {
|
||||
}
|
||||
|
||||
public CyclingControl(Option<T> option, Class<T> enumType, String[] names) {
|
||||
T[] universe = enumType.getEnumConstants();
|
||||
final T[] universe = enumType.getEnumConstants();
|
||||
|
||||
Validate.isTrue(universe.length == names.length, "Mismatch between universe length and names array length");
|
||||
Validate.notEmpty(universe, "The enum universe must contain at least one item");
|
||||
@@ -28,15 +28,15 @@ public class CyclingControl<T extends Enum<T>> implements Control<T> {
|
||||
}
|
||||
|
||||
public CyclingControl(Option<T> option, Class<T> enumType, T[] allowedValues) {
|
||||
T[] universe = enumType.getEnumConstants();
|
||||
final T[] universe = enumType.getEnumConstants();
|
||||
|
||||
this.option = option;
|
||||
this.allowedValues = allowedValues;
|
||||
this.names = new String[universe.length];
|
||||
|
||||
for (int i = 0; i < this.names.length; i++) {
|
||||
String name;
|
||||
T value = universe[i];
|
||||
final String name;
|
||||
final T value = universe[i];
|
||||
|
||||
name = I18n.format(value instanceof NamedState namedState ? namedState.getKey() : value.name());
|
||||
|
||||
|
||||
+12
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -14,6 +15,9 @@ 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
|
||||
@@ -39,6 +43,14 @@ public class SodiumControlElement<T> extends AbstractWidget implements ControlEl
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
+17
-6
@@ -1,5 +1,6 @@
|
||||
package me.jellysquid.mods.sodium.client.gui.options.control.element;
|
||||
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
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.options.control.ControlValueFormatter;
|
||||
@@ -56,12 +57,22 @@ public class SodiumControlElementFactory implements ControlElementFactory {
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (this.option.isAvailable() && button == 0 && this.dim.containsCursor(mouseX, mouseY)) {
|
||||
this.currentIndex = (this.option.getValue().ordinal() + 1) % this.allowedValues.length;
|
||||
this.option.setValue(this.allowedValues[this.currentIndex]);
|
||||
this.playClickSound();
|
||||
if(AngelicaConfig.enableReesesSodiumOptions) {
|
||||
if (this.option.isAvailable() && this.dim.containsCursor(mouseX, mouseY) && (button == 0 || button == 1)) {
|
||||
this.currentIndex = Math.floorMod(this.option.getValue().ordinal() + (button == 0 ? 1 : -1), this.allowedValues.length);
|
||||
this.option.setValue(this.allowedValues[this.currentIndex]);
|
||||
this.playClickSound();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (this.option.isAvailable() && button == 0 && this.dim.containsCursor(mouseX, mouseY)) {
|
||||
this.currentIndex = (this.option.getValue().ordinal() + 1) % this.allowedValues.length;
|
||||
this.option.setValue(this.allowedValues[this.currentIndex]);
|
||||
this.playClickSound();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -176,7 +187,7 @@ public class SodiumControlElementFactory implements ControlElementFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY) {
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button) {
|
||||
if (this.option.isAvailable() && this.sliderBounds.contains((int) mouseX, (int) mouseY)) {
|
||||
this.setValueFromMouse(mouseX);
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package me.jellysquid.mods.sodium.client.gui.utils;
|
||||
|
||||
public interface Drawable {
|
||||
void render(int mouseX, int mouseY, float delta);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package me.jellysquid.mods.sodium.client.gui.utils;
|
||||
|
||||
public interface Element {
|
||||
default boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean mouseDragged(double mouseX, double mouseY) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package me.jellysquid.mods.sodium.client.gui.widgets;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Drawable;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Element;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import me.jellysquid.mods.sodium.client.gui.utils.Drawable;
|
||||
import me.jellysquid.mods.sodium.client.gui.utils.Element;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -24,10 +24,10 @@ public abstract class AbstractWidget implements Drawable, Element {
|
||||
}
|
||||
|
||||
protected void drawRect(double x1, double y1, double x2, double y2, int color) {
|
||||
float a = (float) (color >> 24 & 255) / 255.0F;
|
||||
float r = (float) (color >> 16 & 255) / 255.0F;
|
||||
float g = (float) (color >> 8 & 255) / 255.0F;
|
||||
float b = (float) (color & 255) / 255.0F;
|
||||
final float a = (float) (color >> 24 & 255) / 255.0F;
|
||||
final float r = (float) (color >> 16 & 255) / 255.0F;
|
||||
final float g = (float) (color >> 8 & 255) / 255.0F;
|
||||
final float b = (float) (color & 255) / 255.0F;
|
||||
|
||||
this.drawQuads(vertices -> addQuad(vertices, x1, y1, x2, y2, a, r, g, b));
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public abstract class AbstractWidget implements Drawable, Element {
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GLStateManager.defaultBlendFunc();
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
consumer.accept(tessellator);
|
||||
tessellator.draw();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.jellysquid.mods.sodium.client.gui.widgets;
|
||||
|
||||
import me.jellysquid.mods.sodium.client.gui.utils.Drawable;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Drawable;
|
||||
import lombok.Setter;
|
||||
import me.jellysquid.mods.sodium.client.util.Dim2i;
|
||||
|
||||
public class FlatButtonWidget extends AbstractWidget implements Drawable {
|
||||
@@ -8,9 +9,10 @@ public class FlatButtonWidget extends AbstractWidget implements Drawable {
|
||||
private final String label;
|
||||
private final Runnable action;
|
||||
|
||||
private boolean selected;
|
||||
private boolean enabled = true;
|
||||
private boolean visible = true;
|
||||
@Setter private boolean selected;
|
||||
@Setter private boolean enabled = true;
|
||||
@Setter private boolean visible = true;
|
||||
@Setter private boolean leftAligned;
|
||||
|
||||
public FlatButtonWidget(Dim2i dim, String label, Runnable action) {
|
||||
this.dim = dim;
|
||||
@@ -24,25 +26,23 @@ public class FlatButtonWidget extends AbstractWidget implements Drawable {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean hovered = this.dim.containsCursor(mouseX, mouseY);
|
||||
final boolean hovered = this.dim.containsCursor(mouseX, mouseY);
|
||||
|
||||
int backgroundColor = this.enabled ? (hovered ? 0xE0000000 : 0x90000000) : 0x60000000;
|
||||
int textColor = this.enabled ? 0xFFFFFFFF : 0x90FFFFFF;
|
||||
final int backgroundColor = this.enabled ? (hovered ? 0xE0000000 : 0x90000000) : 0x60000000;
|
||||
final int textColor = this.enabled ? 0xFFFFFFFF : 0x90FFFFFF;
|
||||
|
||||
int strWidth = this.font.getStringWidth(this.label);
|
||||
final int strWidth = this.font.getStringWidth(this.label);
|
||||
|
||||
this.drawRect(this.dim.getOriginX(), this.dim.getOriginY(), this.dim.getLimitX(), this.dim.getLimitY(), backgroundColor);
|
||||
this.drawString(this.label, this.dim.getCenterX() - (strWidth / 2), this.dim.getCenterY() - 4, textColor);
|
||||
final int x = leftAligned ? this.dim.getOriginX() + 10 : this.dim.getCenterX() - (strWidth / 2);
|
||||
this.drawString(this.label, x, this.dim.getCenterY() - 4, textColor);
|
||||
|
||||
if (this.enabled && this.selected) {
|
||||
this.drawRect(this.dim.getOriginX(), this.dim.getLimitY() - 1, this.dim.getLimitX(), this.dim.getLimitY(), 0xFF94E4D3);
|
||||
this.drawRect(this.dim.getOriginX(), leftAligned ? this.dim.getOriginY() : (this.dim.getLimitY() - 1),
|
||||
this.leftAligned ? (this.dim.getOriginX() + 1) : this.dim.getLimitX(), this.dim.getLimitY(), 0xFF94E4D3);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (!this.enabled || !this.visible) {
|
||||
@@ -59,11 +59,4 @@ public class FlatButtonWidget extends AbstractWidget implements Drawable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package me.jellysquid.mods.sodium.client.util;
|
||||
|
||||
public class Dim2i {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private int x;
|
||||
private int y;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public Dim2i(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
@@ -48,4 +48,28 @@ public class Dim2i {
|
||||
public int getCenterY() {
|
||||
return this.y + (this.height / 2);
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public boolean canFitDimension(Dim2i anotherDim) {
|
||||
return this.x <= anotherDim.getOriginX() && this.y <= anotherDim.getOriginY() && this.getLimitX() >= anotherDim.getLimitX() && this.getLimitY() >= anotherDim.getLimitY();
|
||||
}
|
||||
|
||||
public boolean overlapWith(Dim2i other) {
|
||||
return this.x < other.getLimitX() && this.getLimitX() > other.getOriginX() && this.y < other.getLimitY() && this.getLimitY() > other.getOriginY();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package me.jellysquid.mods.sodium.proxy;
|
||||
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import jss.notfine.gui.GuiCustomMenu;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.ReeseSodiumVideoOptionsScreen;
|
||||
import me.jellysquid.mods.sodium.client.gui.SodiumGameOptionPages;
|
||||
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -28,8 +30,10 @@ public class ClientProxy extends CommonProxy {
|
||||
if(GuiScreen.isShiftKeyDown()) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiCustomMenu(eventGui.parentGuiScreen, SodiumGameOptionPages.general(),
|
||||
SodiumGameOptionPages.quality(), SodiumGameOptionPages.advanced(), SodiumGameOptionPages.performance()));
|
||||
} else {
|
||||
} else if(!AngelicaConfig.enableReesesSodiumOptions || GuiScreen.isCtrlKeyDown()) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SodiumOptionsGUI(eventGui.parentGuiScreen));
|
||||
} else {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new ReeseSodiumVideoOptionsScreen(eventGui.parentGuiScreen));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user