Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions common/src/main/java/net/irisshaders/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,7 @@ private static boolean loadExternalShaderpack(String name) {
try {
currentPack = new ShaderPack(shaderPackPath, changedConfigs, StandardMacros.createStandardEnvironmentDefines(), isZip);

MutableOptionValues changedConfigsValues = currentPack.getShaderPackOptions().getOptionValues().mutableCopy();

// Store changed values from those currently in use by the shader pack
Properties configsToSave = new Properties();
changedConfigsValues.getBooleanValues().forEach((k, v) -> configsToSave.setProperty(k, Boolean.toString(v)));
changedConfigsValues.getStringValues().forEach(configsToSave::setProperty);

tryUpdateConfigPropertiesFile(shaderPackConfigTxt, configsToSave);
saveShaderPackConfig(currentPack, shaderPackConfigTxt);
} catch (Exception e) {
logger.error("Failed to load the shaderpack \"{}\"!", name);
logger.error("", e);
Expand All @@ -364,6 +357,23 @@ private static boolean loadExternalShaderpack(String name) {
return true;
}

public static void saveShaderPackConfig() {
if (currentPack != null) {
saveShaderPackConfig(currentPack, getShaderpacksDirectory().resolve(currentPackName + ".txt"));
}
}

private static void saveShaderPackConfig(ShaderPack pack, Path configTxt) {
MutableOptionValues changedConfigsValues = pack.getShaderPackOptions().getOptionValues().mutableCopy();

// Store changed values from those currently in use by the shader pack
Properties configsToSave = new Properties();
changedConfigsValues.getBooleanValues().forEach((k, v) -> configsToSave.setProperty(k, Boolean.toString(v)));
changedConfigsValues.getStringValues().forEach(configsToSave::setProperty);

tryUpdateConfigPropertiesFile(configTxt, configsToSave);
}

private static void handleException(Exception e) {
if (irisConfig.areDebugOptionsEnabled()) {
Minecraft.getInstance().gui.setScreen(new DebugLoadFailedGridScreen(Minecraft.getInstance().gui.screen(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public SliderElementWidget(OptionMenuStringOptionElement element) {
public void render(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float tickDelta, boolean hovered) {
this.updateRenderParams(35);


if (!hovered && !isFocused()) {
if (!hovered && !isFocused() && !isDragging()) {
if (usedKeyboard) {
usedKeyboard = false;
mouseDown = false;
Expand Down Expand Up @@ -59,16 +58,15 @@ public void render(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, flo
}
}

if (this.mouseDown && !usedKeyboard) {
// Release if the mouse went off the slider
if (!hovered) {
this.onReleased();
}

if (isDragging()) {
whileDragging(mouseX);
}
}

private boolean isDragging() {
return this.mouseDown && !usedKeyboard;
}

private void renderSlider(GuiGraphicsExtractor guiGraphics) {
GuiUtil.bindIrisWidgetsTexture();

Expand Down Expand Up @@ -101,6 +99,7 @@ private void whileDragging(int mouseX) {
this.valueIndex = newValueIndex;

this.updateLabels();
this.applyRealtime(false);
}
}

Expand All @@ -126,6 +125,14 @@ public boolean mouseClicked(MouseButtonEvent event, boolean bl2) {
}

mouseDown = true;
if (isRealtime()) {
this.screen.setdraggedButton(this);
}
this.screen.runOnNextMouseRelease(() -> {
if (isDragging()) {
this.onReleased();
}
});
GuiUtil.playButtonClickSound();

return true;
Expand Down Expand Up @@ -158,10 +165,12 @@ public boolean keyPressed(KeyEvent event) {
if (event.isLeft()) {
valueIndex = Math.max(0, valueIndex - 1);
this.updateLabels();
this.applyRealtime(false);
return true;
} else if (event.isRight()) {
valueIndex = Math.min(valueCount - 1, valueIndex + 1);
this.updateLabels();
this.applyRealtime(false);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.irisshaders.iris.gui.GuiUtil;
import net.irisshaders.iris.gui.NavigationController;
import net.irisshaders.iris.gui.screen.ShaderPackScreen;
import net.irisshaders.iris.shaderpack.option.RealtimeSettings;
import net.irisshaders.iris.shaderpack.option.StringOption;
import net.irisshaders.iris.shaderpack.option.menu.OptionMenuStringOptionElement;
import net.minecraft.client.gui.GuiGraphicsExtractor;
Expand Down Expand Up @@ -91,7 +92,40 @@ public String getValue() {
}

protected void queue() {
// Realtime options take effect immediately
if (this.applyRealtime(true)) {
return;
}

Iris.getShaderPackOptionQueue().put(this.option.getName(), this.getValue());

if (isRealtime() && isValueModified()) {
this.screen.applyChanges();
}
}

private RealtimeSettings getRealtimeSettings() {
return Iris.getCurrentPack().map(pack -> pack.getShaderPackOptions().getRealtimeSettings()).orElse(RealtimeSettings.NONE);
}

protected boolean isRealtime() {
return getRealtimeSettings().isRealtime(this.option.getName());
}

protected boolean applyRealtime(boolean save) {
if (!getRealtimeSettings().canApplyLive(this.option.getName(), this.getValue())) {
return false;
}

if (getRealtimeSettings().set(this.option.getName(), this.getValue())) {
this.appliedValue = this.getValue();

if (save) {
Iris.saveShaderPackConfig();
}
}

return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public class ShaderPackScreen extends Screen implements HudHideable {
private int hoveredElementCommentTimer = 0;
private boolean optionMenuOpen = false;
private boolean dropChanges = false;
private @Nullable Runnable mouseReleaseAction = null;
private @Nullable AbstractElementWidget<?> draggedButton = null;
private MutableComponent developmentComponent;
private MutableComponent updateComponent;
private float guiButtonHoverTimer = 0.0f;
Expand Down Expand Up @@ -164,7 +166,10 @@ public void extractRenderState(GuiGraphicsExtractor guiGraphics, int mouseX, int
Component.literal("Enable"), Component.literal("Disable")));
}

if (!this.guiHidden) {
if (this.draggedButton != null) {
// only render dragged button from realtime settings, everything else is hidden
this.draggedButton.render(guiGraphics, mouseX, mouseY, delta, false);
} else if (!this.guiHidden) {
super.extractRenderState(guiGraphics, mouseX, mouseY, delta);
} else {
this.showHideButton.extractRenderState(guiGraphics, mouseX, mouseY, delta);
Expand All @@ -175,7 +180,7 @@ public void extractRenderState(GuiGraphicsExtractor guiGraphics, int mouseX, int
this.guiButtonHoverTimer = 0.0f;
}

if (!this.guiHidden) {
if (!this.guiHidden && this.draggedButton == null) {
guiGraphics.centeredText(this.font, this.title, (int) (this.width * 0.5), 8, 0xFFFFFFFF);

if (notificationDialog != null && notificationDialogTimer > 0) {
Expand Down Expand Up @@ -221,6 +226,14 @@ public void extractRenderState(GuiGraphicsExtractor guiGraphics, int mouseX, int
}
}


@Override // remove the darkening background
public void extractBackground(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float delta) {
if (this.draggedButton == null) {
super.extractBackground(guiGraphics, mouseX, mouseY, delta);
}
}

@Override
public boolean mouseClicked(MouseButtonEvent event, boolean bl2) {
int widthValue = this.font.width("New update available!");
Expand All @@ -237,6 +250,29 @@ public boolean mouseClicked(MouseButtonEvent event, boolean bl2) {
return super.mouseClicked(event, bl2);
}

public void setdraggedButton(@Nullable AbstractElementWidget<?> widget) {
this.draggedButton = widget;
}

// The iris buttons only hear about mouse stuff directly above them, this tells them about any release
public void runOnNextMouseRelease(Runnable action) {
this.mouseReleaseAction = action;
}

@Override
public boolean mouseReleased(MouseButtonEvent event) {
boolean released = super.mouseReleased(event);
this.draggedButton = null;

if (this.mouseReleaseAction != null) {
Runnable action = this.mouseReleaseAction;
this.mouseReleaseAction = null;
action.run();
}

return released;
}

@Override
protected void init() {
super.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ public IrisRenderingPipeline(ProgramSet programSet) {
this.updateNotifier);
BuiltinReplacementUniforms.addBuiltinReplacementUniforms(holder);
VanillaUniforms.addVanillaUniforms(holder);
programSet.getPack().getShaderPackOptions().getRealtimeSettings().registerUniforms(holder);
});

this.frameUniforms = new FrameUniforms(this.customUniforms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.irisshaders.iris.shaderpack.materialmap.NamespacedId;
import net.irisshaders.iris.shaderpack.option.OrderBackedProperties;
import net.irisshaders.iris.shaderpack.option.ProfileSet;
import net.irisshaders.iris.shaderpack.option.RealtimeSettings;
import net.irisshaders.iris.shaderpack.option.ShaderPackOptions;
import net.irisshaders.iris.shaderpack.option.menu.OptionMenuContainer;
import net.irisshaders.iris.shaderpack.option.values.MutableOptionValues;
Expand Down Expand Up @@ -165,7 +166,9 @@ public ShaderPack(Path root, Map<String, String> changedConfigs, ImmutableList<S
this.languageMap = new LanguageMap(root.resolve("lang"));

// Discover, merge, and apply shader pack options
this.shaderPackOptions = new ShaderPackOptions(graph, changedConfigs);
Properties realtimeProperties = loadProperties(root, RealtimeSettings.FILE_NAME, environmentDefines).orElseGet(Properties::new);
Optional<String> shadersPropertiesSource = loadProperties(root, "shaders.properties");
this.shaderPackOptions = new ShaderPackOptions(graph, changedConfigs, realtimeProperties, shadersPropertiesSource.orElse(""));
graph = this.shaderPackOptions.getIncludes();

List<StringPair> finalEnvironmentDefines = new ArrayList<>(List.copyOf(environmentDefines));
Expand All @@ -174,7 +177,7 @@ public ShaderPack(Path root, Map<String, String> changedConfigs, ImmutableList<S
finalEnvironmentDefines.add(new StringPair("IRIS_FEATURE_" + flag.name(), ""));
}
}
this.shaderProperties = loadProperties(root, "shaders.properties").map(
this.shaderProperties = shadersPropertiesSource.map(
source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines)).orElseGet(ShaderProperties::empty);

for (Int2ObjectMap.Entry<ShaderStorageInfo> shaderStorageInfoEntry : shaderProperties.getBufferObjects().int2ObjectEntrySet()) {
Expand Down Expand Up @@ -326,7 +329,7 @@ public ShaderPack(Path root, Map<String, String> changedConfigs, ImmutableList<S
// directly. This removes one obstacle to accurate reporting of line numbers for errors,
// though there exist many more (such as relocating all #extension directives and similar things)
String source = builder.toString();
source = JcppProcessor.glslPreprocessSource(source, finalEnvironmentDefines1);
source = JcppProcessor.glslPreprocessSource(source, finalEnvironmentDefines1, shaderPackOptions.getRealtimeSettings());

return source;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -450,22 +451,22 @@ public OptionSet getOptionSet(AbsolutePackPath filePath, Set<String> booleanDefi
return builder.build();
}

public LineTransform asTransform(OptionValues values) {
return (index, line) -> edit(values, index, line);
public LineTransform asTransform(OptionValues values, RealtimeSettings realtime) {
return (index, line) -> edit(values, realtime, index, line);
}

public String apply(OptionValues values) {
StringBuilder source = new StringBuilder();

for (int index = 0; index < lines.size(); index++) {
source.append(edit(values, index, lines.get(index)));
source.append(edit(values, RealtimeSettings.NONE, index, lines.get(index)));
source.append('\n');
}

return source.toString();
}

private String edit(OptionValues values, int index, String existing) {
private String edit(OptionValues values, RealtimeSettings realtime, int index, String existing) {
// See if it's a boolean option
BooleanOption booleanOption = booleanOptions.get(index);

Expand All @@ -489,7 +490,11 @@ private String edit(OptionValues values, int index, String existing) {
StringOption stringOption = stringOptions.get(index);

if (stringOption != null) {
return values.getStringValue(stringOption.getName()).map(value -> {
// Realtime options read their value from a uniform, so the source does not depend on the chosen value
Optional<String> currentValue = Optional.ofNullable(realtime.sourceValue(stringOption.getName()))
.or(() -> values.getStringValue(stringOption.getName()));

return currentValue.map(value -> {
if (stringOption.getType() == OptionType.DEFINE) {
return "#define " + stringOption.getName() + " " + value + " // OptionAnnotatedSource: Changed option";
} else if (stringOption.getType() == OptionType.CONST) {
Expand Down
Loading
Loading