mirror of
https://github.com/JonasunderscoreJones/nicer-skies.git
synced 2025-10-22 19:29:18 +02:00
refactor config screen and system to be much more robust
This commit is contained in:
parent
c8f8622546
commit
29f30fb53a
3 changed files with 190 additions and 233 deletions
|
@ -1,39 +1,142 @@
|
|||
package codes.ztereohype.nicerskies.config;
|
||||
|
||||
import codes.ztereohype.nicerskies.NicerSkies;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
public class Config {
|
||||
private boolean tweakedLigthmap;
|
||||
private boolean twinklingStars;
|
||||
private boolean nebulas;
|
||||
public static final ConfigData DEFAULT_CONFIG = new ConfigData(false,
|
||||
true,
|
||||
true,
|
||||
NebulaType.RAINBOW.getTypeString(),
|
||||
1f,
|
||||
0.5f,
|
||||
1f,
|
||||
128,
|
||||
false);
|
||||
|
||||
private final NebulaConfig nebulaConfig;
|
||||
private static final Gson gson = new Gson();
|
||||
private final File file;
|
||||
|
||||
public Config(boolean tweakedLigthmap, boolean twinklingStars, boolean nebulas, String nebulaType, float nebulaStrength, float nebulaNoiseAmount, float nebulaNoiseScale, int baseColourAmount, boolean renderDuringDay) {
|
||||
this.tweakedLigthmap = tweakedLigthmap;
|
||||
this.twinklingStars = twinklingStars;
|
||||
this.nebulas = nebulas;
|
||||
@Getter
|
||||
private ConfigData configData;
|
||||
|
||||
this.nebulaConfig = new NebulaConfig(nebulaType, nebulaStrength, nebulaNoiseAmount, nebulaNoiseScale, baseColourAmount, renderDuringDay);
|
||||
public static Config fromFile(File file) {
|
||||
ConfigData config;
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
|
||||
config = DEFAULT_CONFIG.toBuilder().build();
|
||||
|
||||
gson.toJson(config, new FileWriter(file));
|
||||
} else {
|
||||
config = gson.fromJson(new FileReader(file), ConfigData.class);
|
||||
|
||||
if (config == null) {
|
||||
throw new IOException("Failed to read config file");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
NicerSkies.LOGGER.warning("Failed to read config file, falling back to default config.");
|
||||
e.printStackTrace();
|
||||
config = DEFAULT_CONFIG.toBuilder().build();
|
||||
}
|
||||
|
||||
return new Config(config, file);
|
||||
}
|
||||
|
||||
private Config(ConfigData configData, File file) {
|
||||
this.configData = configData;
|
||||
this.file = file;
|
||||
save(file);
|
||||
}
|
||||
|
||||
public boolean getLightmapTweaked() {
|
||||
return configData.isLightmapTweaked();
|
||||
}
|
||||
|
||||
public boolean areTwinlkingStarsEnabled() {
|
||||
return configData.isTwinklingStars();
|
||||
}
|
||||
|
||||
public boolean areNebulasEnabled() {
|
||||
return configData.isRenderNebulas();
|
||||
}
|
||||
|
||||
public float getNebulaStrength() {
|
||||
return configData.getNebulaConfig().getNebulaStrength();
|
||||
}
|
||||
|
||||
public float getNebulaNoiseAmount() {
|
||||
return configData.getNebulaConfig().getNebulaNoiseAmount();
|
||||
}
|
||||
|
||||
public float getNebulaNoiseScale() {
|
||||
return configData.getNebulaConfig().getNebulaNoiseScale();
|
||||
}
|
||||
|
||||
public int getNebulaBaseColourAmount() {
|
||||
return configData.getNebulaConfig().getBaseColourAmount();
|
||||
}
|
||||
|
||||
public boolean getRenderDuringDay() {
|
||||
return configData.getNebulaConfig().isRenderDuringDay();
|
||||
}
|
||||
|
||||
public void updateConfig(ConfigData configData) {
|
||||
this.configData = configData.toBuilder().build();
|
||||
this.configData.setNebulaConfig(configData.getNebulaConfig().toBuilder().build());
|
||||
save(file);
|
||||
}
|
||||
|
||||
public void save(File file) {
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
writer.write(gson.toJson(configData));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
NicerSkies.LOGGER.warning("Failed to save config file!");
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class NebulaConfig {
|
||||
public NebulaConfig(String nebulaType, float nebulaStrength, float nebulaNoiseAmount, float nebulaNoiseScale, int baseColourAmount, boolean renderDuringDay) {
|
||||
this.nebulaType = nebulaType;
|
||||
this.nebulaStrength = nebulaStrength;
|
||||
this.nebulaNoiseAmount = nebulaNoiseAmount;
|
||||
this.nebulaNoiseScale = nebulaNoiseScale;
|
||||
this.baseColourAmount = baseColourAmount;
|
||||
this.renderDuringDay = renderDuringDay;
|
||||
@AllArgsConstructor
|
||||
@Builder(toBuilder=true)
|
||||
public final static class ConfigData {
|
||||
private boolean lightmapTweaked;
|
||||
private boolean twinklingStars;
|
||||
private boolean renderNebulas;
|
||||
private boolean nebulasInOtherDimensions;
|
||||
|
||||
private NebulaConfigData nebulaConfig;
|
||||
|
||||
private ConfigData(boolean tweakedLigthmap, boolean twinklingStars, boolean nebulas, String nebulaType, float nebulaStrength, float nebulaNoiseAmount, float nebulaNoiseScale, int baseColourAmount, boolean renderDuringDay) {
|
||||
this.lightmapTweaked = tweakedLigthmap;
|
||||
this.twinklingStars = twinklingStars;
|
||||
this.renderNebulas = nebulas;
|
||||
|
||||
this.nebulaConfig = new NebulaConfigData(nebulaType, nebulaStrength, nebulaNoiseAmount, nebulaNoiseScale, baseColourAmount, renderDuringDay);
|
||||
}
|
||||
|
||||
private String nebulaType;
|
||||
private float nebulaStrength;
|
||||
private float nebulaNoiseAmount;
|
||||
private float nebulaNoiseScale;
|
||||
private int baseColourAmount;
|
||||
private boolean renderDuringDay;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder(toBuilder=true)
|
||||
public static final class NebulaConfigData {
|
||||
private String nebulaType;
|
||||
private float nebulaStrength;
|
||||
private float nebulaNoiseAmount;
|
||||
private float nebulaNoiseScale;
|
||||
private int baseColourAmount;
|
||||
private boolean renderDuringDay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,156 +0,0 @@
|
|||
package codes.ztereohype.nicerskies.config;
|
||||
|
||||
import codes.ztereohype.nicerskies.NicerSkies;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ConfigManager {
|
||||
public static final Config DEFAULT_CONFIG = new Config(false, true, true, NebulaType.RAINBOW.getTypeString(), 1f, 0.5f, 1f, 128, false);
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
private final Config config;
|
||||
private final File file;
|
||||
|
||||
public static ConfigManager fromFile(File file) {
|
||||
Config config;
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
|
||||
config = cloneConfig(DEFAULT_CONFIG);
|
||||
|
||||
gson.toJson(config, new FileWriter(file));
|
||||
} else {
|
||||
config = gson.fromJson(new FileReader(file), Config.class);
|
||||
|
||||
if (config == null) {
|
||||
throw new IOException("Failed to read config file");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
NicerSkies.LOGGER.warning("Failed to read config file, falling back to default config");
|
||||
e.printStackTrace();
|
||||
config = cloneConfig(DEFAULT_CONFIG);
|
||||
}
|
||||
|
||||
return new ConfigManager(config, file);
|
||||
}
|
||||
|
||||
private ConfigManager(Config config, File file) {
|
||||
this.config = config;
|
||||
this.file = file;
|
||||
save(file);
|
||||
}
|
||||
|
||||
public boolean getLightmapTweaked() {
|
||||
return config.isTweakedLigthmap();
|
||||
}
|
||||
|
||||
public boolean getTwinklingStars() {
|
||||
return config.isTwinklingStars();
|
||||
}
|
||||
|
||||
public boolean getNebulas() {
|
||||
return config.isNebulas();
|
||||
}
|
||||
|
||||
public NebulaType getNebulaType() {
|
||||
return NebulaType.valueOf(config.getNebulaConfig().getNebulaType().toUpperCase());
|
||||
}
|
||||
|
||||
public float getNebulaStrength() {
|
||||
return config.getNebulaConfig().getNebulaStrength();
|
||||
}
|
||||
|
||||
public float getNebulaNoiseAmount() {
|
||||
return config.getNebulaConfig().getNebulaNoiseAmount();
|
||||
}
|
||||
|
||||
public float getNebulaNoiseScale() {
|
||||
return config.getNebulaConfig().getNebulaNoiseScale();
|
||||
}
|
||||
|
||||
public int getNebulaBaseColourAmount() {
|
||||
return config.getNebulaConfig().getBaseColourAmount();
|
||||
}
|
||||
|
||||
public boolean getRenderDuringDay() {
|
||||
return config.getNebulaConfig().isRenderDuringDay();
|
||||
}
|
||||
|
||||
public void setLightmapTweaked(boolean tweaked) {
|
||||
config.setTweakedLigthmap(tweaked);
|
||||
save(file);
|
||||
}
|
||||
|
||||
public void setTwinklingStars(boolean twinkling) {
|
||||
config.setTwinklingStars(twinkling);
|
||||
save(file);
|
||||
}
|
||||
|
||||
public void setNebulas(boolean nebulas) {
|
||||
config.setNebulas(nebulas);
|
||||
save(file);
|
||||
}
|
||||
|
||||
public void setNebulaType(NebulaType type) {
|
||||
config.getNebulaConfig().setNebulaType(type.getTypeString());
|
||||
save(file);
|
||||
}
|
||||
|
||||
public void setNebulaStrength(float strength) {
|
||||
config.getNebulaConfig().setNebulaStrength(strength);
|
||||
save(file);
|
||||
}
|
||||
|
||||
public void setNebulaNoiseAmount(float amount) {
|
||||
config.getNebulaConfig().setNebulaNoiseAmount(amount);
|
||||
save(file);
|
||||
}
|
||||
|
||||
public void setNebulaNoiseScale(float scale) {
|
||||
config.getNebulaConfig().setNebulaNoiseScale(scale);
|
||||
save(file);
|
||||
}
|
||||
|
||||
public void setNebulaBaseColourAmount(int amount) {
|
||||
config.getNebulaConfig().setBaseColourAmount(amount);
|
||||
save(file);
|
||||
}
|
||||
public void setRenderDuringDay(boolean bl) {
|
||||
config.getNebulaConfig().setRenderDuringDay(bl);
|
||||
save(file);
|
||||
}
|
||||
|
||||
public void save(File file) {
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
writer.write(gson.toJson(config));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
NicerSkies.LOGGER.warning("Failed to save config file!");
|
||||
}
|
||||
}
|
||||
|
||||
private static Config cloneConfig(Config config) {
|
||||
return gson.fromJson(gson.toJson(config), Config.class);
|
||||
}
|
||||
|
||||
public void resetNebulaSettings() {
|
||||
config.getNebulaConfig().setNebulaType(DEFAULT_CONFIG.getNebulaConfig().getNebulaType());
|
||||
config.getNebulaConfig().setNebulaStrength(DEFAULT_CONFIG.getNebulaConfig().getNebulaStrength());
|
||||
config.getNebulaConfig().setNebulaNoiseAmount(DEFAULT_CONFIG.getNebulaConfig().getNebulaNoiseAmount());
|
||||
config.getNebulaConfig().setNebulaNoiseScale(DEFAULT_CONFIG.getNebulaConfig().getNebulaNoiseScale());
|
||||
config.getNebulaConfig().setBaseColourAmount(DEFAULT_CONFIG.getNebulaConfig().getBaseColourAmount());
|
||||
|
||||
save(file);
|
||||
}
|
||||
|
||||
public boolean nebulaConfigEquals(Config config) {
|
||||
return this.config.getNebulaConfig().equals(config.getNebulaConfig());
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package codes.ztereohype.nicerskies.gui;
|
||||
|
||||
import codes.ztereohype.nicerskies.NicerSkies;
|
||||
import codes.ztereohype.nicerskies.config.ConfigManager;
|
||||
import codes.ztereohype.nicerskies.config.Config;
|
||||
import codes.ztereohype.nicerskies.core.NebulaSeedManager;
|
||||
import codes.ztereohype.nicerskies.gui.widget.Separator;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -15,73 +15,82 @@ import net.minecraft.network.chat.FormattedText;
|
|||
import net.minecraft.network.chat.Style;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public class ConfigScreen extends Screen {
|
||||
private final Screen lastScreen;
|
||||
private final ConfigManager cm = NicerSkies.config;
|
||||
private final Config config;
|
||||
private final Config.ConfigData newConfig;
|
||||
|
||||
private boolean invalidated = false;
|
||||
|
||||
protected ConfigScreen(Screen lastScreen) {
|
||||
super(Component.translatable("nicer_skies.menu.settings"));
|
||||
this.lastScreen = lastScreen;
|
||||
|
||||
this.config = NicerSkies.getInstance().getConfig();
|
||||
this.newConfig = config.getConfigData().toBuilder().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addRenderableWidget(new Checkbox(20, 60, 20, 20, Component.translatable("nicer_skies.option.render_nebulas"), cm.getNebulas()) {
|
||||
int btnDst = 24;
|
||||
int nebulaOptMargin = this.width / 2 + (this.width / 2 - 150) / 2;
|
||||
|
||||
// initial values
|
||||
boolean renderNebulas = newConfig.isRenderNebulas();
|
||||
boolean twinkleStars = newConfig.isTwinklingStars();
|
||||
boolean lightmapTweaked = newConfig.isLightmapTweaked();
|
||||
|
||||
boolean renderDuringDay = newConfig.getNebulaConfig().isRenderDuringDay();
|
||||
float nebulaStrength = newConfig.getNebulaConfig().getNebulaStrength();
|
||||
float nebulaNoiseAmount = newConfig.getNebulaConfig().getNebulaNoiseAmount();
|
||||
int nebulaBaseColourAmount = newConfig.getNebulaConfig().getBaseColourAmount();
|
||||
float nebulaNoiseScale = newConfig.getNebulaConfig().getNebulaNoiseScale();
|
||||
|
||||
int Y = 60;
|
||||
addRenderableWidget(new Checkbox(20, Y, 20, 20, Component.translatable("nicer_skies.option.render_nebulas"), renderNebulas) {
|
||||
@Override
|
||||
public void onPress() {
|
||||
super.onPress();
|
||||
cm.setNebulas(!cm.getNebulas());
|
||||
newConfig.setRenderNebulas(this.selected());
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
addRenderableWidget(new Checkbox(20, 84, 20, 20, Component.translatable("nicer_skies.option.twinkle_stars"), cm.getTwinklingStars()) {
|
||||
addRenderableWidget(new Checkbox(20, (Y += btnDst), 20, 20, Component.translatable("nicer_skies.option.twinkle_stars"), twinkleStars) {
|
||||
@Override
|
||||
public void onPress() {
|
||||
super.onPress();
|
||||
cm.setTwinklingStars(!cm.getTwinklingStars());
|
||||
newConfig.setTwinklingStars(this.selected());
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
addRenderableWidget(new Checkbox(20, 108, 20, 20, Component.translatable("nicer_skies.option.custom_lightmap"), cm.getLightmapTweaked()) {
|
||||
addRenderableWidget(new Checkbox(20, (Y += btnDst), 20, 20, Component.translatable("nicer_skies.option.custom_lightmap"), lightmapTweaked) {
|
||||
@Override
|
||||
public void onPress() {
|
||||
super.onPress();
|
||||
cm.setLightmapTweaked(!cm.getLightmapTweaked());
|
||||
newConfig.setLightmapTweaked(this.selected());
|
||||
Minecraft.getInstance().gameRenderer.lightTexture().tick();
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
addRenderableOnly(new Separator(this.width / 2, 30, this.height - 70));
|
||||
Y = 60;
|
||||
|
||||
// CycleButton<NebulaType> nebulaType = CycleButton.builder((NebulaType value) -> Component.literal(value.getTypeString()))
|
||||
// .withValues(NebulaType.values())
|
||||
// .create(this.width / 2 + (this.width / 2 - 150) / 2, 60, 150, 20, Component.literal("Nebula Type"), (button, value) -> {
|
||||
// invalidated = true;
|
||||
// NicerSkies.config.setNebulaType(value);
|
||||
// });
|
||||
//
|
||||
// if (NebulaType.values().length < 2)
|
||||
// nebulaType.active = false; // deactivate while theres only one!
|
||||
//
|
||||
// addRenderableWidget(nebulaType);
|
||||
|
||||
addRenderableWidget(new Checkbox(this.width / 2 + (this.width / 2 - 150) / 2, 60, 20, 20, Component.literal("Render During Day"), cm.getRenderDuringDay()) {
|
||||
addRenderableWidget(new Checkbox(nebulaOptMargin, Y, 20, 20, Component.literal("Render During Day"), renderDuringDay) {
|
||||
@Override
|
||||
public void onPress() {
|
||||
super.onPress();
|
||||
cm.setRenderDuringDay(!cm.getRenderDuringDay());
|
||||
newConfig.getNebulaConfig().setRenderDuringDay(this.selected());
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
float strength = cm.getNebulaStrength();
|
||||
addRenderableWidget(new AbstractSliderButton(this.width / 2 + (this.width / 2 - 150) / 2, 84, 150, 20, Component.translatable("nicer_skies.option.nebula_transparency", (int) (strength * 100) + "%"), strength) {
|
||||
addRenderableWidget(new AbstractSliderButton(nebulaOptMargin, (Y += btnDst), 150, 20, Component.translatable("nicer_skies.option.nebula_transparency", (int) (nebulaStrength * 100) + "%"), nebulaStrength) {
|
||||
@Override
|
||||
protected void updateMessage() {
|
||||
this.setMessage(Component.translatable("nicer_skies.option.nebula_transparency", (int) (this.value * 100) + "%"));
|
||||
|
@ -89,66 +98,60 @@ public class ConfigScreen extends Screen {
|
|||
|
||||
@Override
|
||||
protected void applyValue() {
|
||||
NicerSkies.config.setNebulaStrength((float) this.value);
|
||||
newConfig.getNebulaConfig().setNebulaStrength((float) this.value);
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Nebula Amount
|
||||
float noiseAmount = cm.getNebulaNoiseAmount();
|
||||
addRenderableWidget(new AbstractSliderButton(this.width / 2 + (this.width / 2 - 150) / 2, 108, 150, 20, Component.translatable("nicer_skies.option.nebula_amount", (int) (noiseAmount * 100) + "%"), noiseAmount) {
|
||||
addRenderableWidget(new AbstractSliderButton(nebulaOptMargin, (Y += btnDst), 150, 20, Component.translatable("nicer_skies.option.nebula_amount", (int) (nebulaNoiseAmount * 100) + "%"), nebulaNoiseAmount) {
|
||||
@Override
|
||||
protected void updateMessage() {
|
||||
invalidated = true;
|
||||
this.setMessage(Component.translatable("nicer_skies.option.nebula_amount", (int) (this.value * 100) + "%"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyValue() {
|
||||
NicerSkies.config.setNebulaNoiseAmount((float) this.value);
|
||||
newConfig.getNebulaConfig().setNebulaNoiseAmount((float) this.value);
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Background Strength
|
||||
int baseColourAmount = cm.getNebulaBaseColourAmount();
|
||||
addRenderableWidget(new AbstractSliderButton(this.width / 2 + (this.width / 2 - 150) / 2, 132, 150, 20, Component.translatable("nicer_skies.option.background_strength", baseColourAmount), baseColourAmount / 255f) {
|
||||
addRenderableWidget(new AbstractSliderButton(nebulaOptMargin, (Y += btnDst), 150, 20, Component.translatable("nicer_skies.option.background_strength", nebulaBaseColourAmount), nebulaBaseColourAmount / 255f) {
|
||||
@Override
|
||||
protected void updateMessage() {
|
||||
invalidated = true;
|
||||
this.setMessage(Component.translatable("nicer_skies.option.background_strength", (int) (this.value * 255)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyValue() {
|
||||
NicerSkies.config.setNebulaBaseColourAmount((int) (this.value * 255));
|
||||
newConfig.getNebulaConfig().setBaseColourAmount((int) (this.value * 255));
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Nebula Scale
|
||||
float nebulaNoiseScale = cm.getNebulaNoiseScale();
|
||||
addRenderableWidget(new AbstractSliderButton(this.width / 2 + (this.width / 2 - 150) / 2, 156, 150, 20, Component.translatable("nicer_skies.option.nebula_scale", nebulaNoiseScale), Math.round(1f / (nebulaNoiseScale * 1.5f + 0.5f) * 100) / 100f) {
|
||||
addRenderableWidget(new AbstractSliderButton(nebulaOptMargin, (Y += btnDst), 150, 20, Component.translatable("nicer_skies.option.nebula_scale", nebulaNoiseScale), mapValueToScale(nebulaNoiseScale)) {
|
||||
@Override
|
||||
protected void updateMessage() {
|
||||
invalidated = true;
|
||||
this.setMessage(Component.translatable("nicer_skies.option.nebula_scale", getNebulaNoiseScale()));
|
||||
this.setMessage(Component.translatable("nicer_skies.option.nebula_scale", mapScaleToValue((float) this.value)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyValue() {
|
||||
NicerSkies.config.setNebulaNoiseScale(getNebulaNoiseScale());
|
||||
}
|
||||
|
||||
private float getNebulaNoiseScale() {
|
||||
return (float) Math.round(1f / (this.value * 1.5f + 0.5f) * 100) / 100f;
|
||||
newConfig.getNebulaConfig().setNebulaNoiseScale(mapScaleToValue((float) this.value));
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Reset
|
||||
addRenderableWidget(new Button(this.width / 2 + (this.width / 2 - 150) / 2, 184, 150, 20, Component.translatable("nicer_skies.menu.reset"), (button) -> {
|
||||
cm.resetNebulaSettings();
|
||||
this.clearWidgets();
|
||||
this.init();
|
||||
addRenderableWidget(new Button(nebulaOptMargin, (Y += btnDst), 150, 20, Component.translatable("nicer_skies.menu.reset"), (button) -> {
|
||||
newConfig.setNebulaConfig(Config.DEFAULT_CONFIG.getNebulaConfig().toBuilder().build());
|
||||
this.rebuildWidgets();
|
||||
invalidated = true;
|
||||
}, null) {
|
||||
}, Supplier::get) {
|
||||
@Override
|
||||
public void render(GuiGraphics g, int mouseX, int mouseY, float partialTick) {
|
||||
this.active = !isDefaultNebulaSettings();
|
||||
|
@ -158,9 +161,10 @@ public class ConfigScreen extends Screen {
|
|||
|
||||
// Apply
|
||||
addRenderableWidget(new Button(this.width / 2 + 4, this.height - 28, 150, 20, Component.translatable("nicer_skies.menu.apply"), (button) -> {
|
||||
config.updateConfig(newConfig);
|
||||
regenerateSky();
|
||||
invalidated = false;
|
||||
}, null) {
|
||||
}, Supplier::get) {
|
||||
@Override
|
||||
public void render(GuiGraphics g, int mouseX, int mouseY, float partialTick) {
|
||||
this.active = invalidated;
|
||||
|
@ -190,21 +194,18 @@ public class ConfigScreen extends Screen {
|
|||
|
||||
@Override
|
||||
public void onClose() {
|
||||
if (invalidated && NebulaSeedManager.canGenerateSky()) {
|
||||
regenerateSky();
|
||||
}
|
||||
minecraft.setScreen(lastScreen);
|
||||
}
|
||||
|
||||
private void regenerateSky() {
|
||||
if (NebulaSeedManager.canGenerateSky()) {
|
||||
NicerSkies.skyManager.generateSky(NebulaSeedManager.getSeed(), NicerSkies.config.getTwinklingStars(), NicerSkies.config.getNebulas());
|
||||
NicerSkies.getInstance().getSkyManager().generateSky(NebulaSeedManager.getSeed());
|
||||
}
|
||||
invalidated = false;
|
||||
}
|
||||
|
||||
private boolean isDefaultNebulaSettings() {
|
||||
return cm.nebulaConfigEquals(ConfigManager.DEFAULT_CONFIG);
|
||||
return newConfig.getNebulaConfig().equals(Config.DEFAULT_CONFIG.getNebulaConfig());
|
||||
}
|
||||
|
||||
private void drawWrappedComponent(GuiGraphics g, FormattedText component, int x, int y, int wrapWidth, int color) {
|
||||
|
@ -217,4 +218,13 @@ public class ConfigScreen extends Screen {
|
|||
g.drawString(font, renderable.getString(), x, y + i * 9, color);
|
||||
}
|
||||
}
|
||||
|
||||
private float mapScaleToValue(float value) {
|
||||
return (float) Math.round(1f / (value * 1.5f + 0.5f) * 100) / 100f;
|
||||
}
|
||||
|
||||
// inverse of above
|
||||
private float mapValueToScale(float value) {
|
||||
return ((1f / value) - 0.5f) / 1.5f;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue