mirror of
https://github.com/JonasunderscoreJones/nicer-skies.git
synced 2025-10-22 19:29:18 +02:00
change: update config screen to account for generation changes
This commit is contained in:
parent
c47e39b05c
commit
ec9bb947de
2 changed files with 54 additions and 25 deletions
|
@ -2,13 +2,11 @@ package codes.ztereohype.nicerskies.config;
|
|||
|
||||
import codes.ztereohype.nicerskies.NicerSkies;
|
||||
import com.google.gson.Gson;
|
||||
import net.fabricmc.loader.impl.util.log.LogHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
public class ConfigManager {
|
||||
public static final Config DEFAULT_CONFIG = new Config(false, true, true, NebulaType.RAINBOW.getTypeString(), 1f, 0.5f, 1f, 128, false);
|
||||
|
@ -142,16 +140,17 @@ public class ConfigManager {
|
|||
return gson.fromJson(gson.toJson(config), Config.class);
|
||||
}
|
||||
|
||||
public boolean nebulaConfigEquals(Config config) {
|
||||
return this.config.getNebulaConfig().equals(config.getNebulaConfig());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,12 @@ import net.minecraft.client.gui.components.Button;
|
|||
import net.minecraft.client.gui.components.Checkbox;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigScreen extends Screen {
|
||||
private final Screen lastScreen;
|
||||
private final ConfigManager cm = NicerSkies.config;
|
||||
|
@ -31,6 +35,7 @@ public class ConfigScreen extends Screen {
|
|||
public void onPress() {
|
||||
super.onPress();
|
||||
cm.setNebulas(!cm.getNebulas());
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -39,6 +44,7 @@ public class ConfigScreen extends Screen {
|
|||
public void onPress() {
|
||||
super.onPress();
|
||||
cm.setTwinklingStars(!cm.getTwinklingStars());
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -48,6 +54,7 @@ public class ConfigScreen extends Screen {
|
|||
super.onPress();
|
||||
cm.setLightmapTweaked(!cm.getLightmapTweaked());
|
||||
Minecraft.getInstance().gameRenderer.lightTexture().tick();
|
||||
invalidated = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -86,6 +93,7 @@ public class ConfigScreen extends Screen {
|
|||
}
|
||||
});
|
||||
|
||||
// Nebula Amount
|
||||
float noiseAmount = cm.getNebulaNoiseAmount();
|
||||
addRenderableWidget(new AbstractSliderButton(this.width / 2 + (this.width / 2 - 150) / 2, 108, 150, 20, Component.literal("Nebula Amount: " + (int) (noiseAmount * 100) + "%"), noiseAmount) {
|
||||
@Override
|
||||
|
@ -100,6 +108,7 @@ public class ConfigScreen extends Screen {
|
|||
}
|
||||
});
|
||||
|
||||
// Background Strength
|
||||
int baseColourAmount = cm.getNebulaBaseColourAmount();
|
||||
addRenderableWidget(new AbstractSliderButton(this.width / 2 + (this.width / 2 - 150) / 2, 132, 150, 20, Component.literal("Background Strength: " + baseColourAmount), baseColourAmount / 255f) {
|
||||
@Override
|
||||
|
@ -114,6 +123,7 @@ public class ConfigScreen extends Screen {
|
|||
}
|
||||
});
|
||||
|
||||
// Nebula Scale
|
||||
float nebulaNoiseScale = cm.getNebulaNoiseScale();
|
||||
addRenderableWidget(new AbstractSliderButton(this.width / 2 + (this.width / 2 - 150) / 2, 156, 150, 20, Component.literal("Nebula Scale: " + nebulaNoiseScale), Math.round((nebulaNoiseScale - 0.5f) / 1.5f * 100) / 100f) {
|
||||
@Override
|
||||
|
@ -132,20 +142,8 @@ public class ConfigScreen extends Screen {
|
|||
}
|
||||
});
|
||||
|
||||
//reload nebula button
|
||||
addRenderableWidget(new Button(this.width / 2 + (this.width / 2 - 150) / 2, 180, 74, 20, Component.literal("Apply"), (button) -> {
|
||||
NicerSkies.skyManager.generateSky(NebulaSeedManager.getSeed());
|
||||
invalidated = false;
|
||||
}, null) {
|
||||
@Override
|
||||
public void render(@NotNull PoseStack poseStack, int mouseX, int mouseY, float partialTick) {
|
||||
this.active = invalidated && NebulaSeedManager.canGetSeed();
|
||||
super.render(poseStack, mouseX, mouseY, partialTick);
|
||||
}
|
||||
});
|
||||
|
||||
//reset to default
|
||||
addRenderableWidget(new Button(this.width / 2 + (this.width / 2 - 150) / 2 + 76, 180, 74, 20, Component.literal("Reset"), (button) -> {
|
||||
// Reset
|
||||
addRenderableWidget(new Button(this.width / 2 + (this.width / 2 - 150) / 2, 184, 150, 20, Component.literal("Reset"), (button) -> {
|
||||
cm.resetNebulaSettings();
|
||||
this.clearWidgets();
|
||||
this.init();
|
||||
|
@ -158,12 +156,24 @@ public class ConfigScreen extends Screen {
|
|||
}
|
||||
});
|
||||
|
||||
// Apply
|
||||
addRenderableWidget(new Button(this.width / 2 + 4, this.height - 28, 150, 20, Component.literal("Apply"), (button) -> {
|
||||
regenerateSky();
|
||||
invalidated = false;
|
||||
}, null) {
|
||||
@Override
|
||||
public void render(@NotNull PoseStack poseStack, int mouseX, int mouseY, float partialTick) {
|
||||
this.active = invalidated;
|
||||
super.render(poseStack, mouseX, mouseY, partialTick);
|
||||
}
|
||||
});
|
||||
|
||||
// Back
|
||||
addRenderableWidget(Button.builder(Component.literal("Back"), (button) -> this.onClose())
|
||||
.pos(this.width / 2 - 100, this.height - 30)
|
||||
.size(200, 20)
|
||||
.pos(this.width / 2 - 154, this.height - 28)
|
||||
.size(150, 20)
|
||||
.build());
|
||||
super.init();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,17 +184,37 @@ public class ConfigScreen extends Screen {
|
|||
drawCenteredString(poseStack, this.font, this.title, this.width / 2, 10, 16777215);
|
||||
drawCenteredString(poseStack, this.font, "Toggle Features", this.width / 4, 36, 16777215);
|
||||
drawCenteredString(poseStack, this.font, "Nebula Settings", 3 * this.width / 4, 36, 16777215);
|
||||
|
||||
drawWrappedString(poseStack, "§lNote:§r \n\nDisable \"Twinkle Stars\" for compatibility with other mods.\n(eg. Custom Stars)", 20, 150, this.width/2 - 40, 0xFFFF00);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
if (invalidated && NebulaSeedManager.canGetSeed()) {
|
||||
NicerSkies.skyManager.generateSky(NebulaSeedManager.getSeed());
|
||||
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());
|
||||
}
|
||||
invalidated = false;
|
||||
}
|
||||
|
||||
private boolean isDefaultNebulaSettings() {
|
||||
return cm.nebulaConfigEquals(ConfigManager.DEFAULT_CONFIG);
|
||||
}
|
||||
|
||||
private void drawWrappedString(PoseStack poseStack, String string, int x, int y, int wrapWidth, int color) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
List<FormattedText> lines = mc.font.getSplitter().splitLines(Component.literal(string), wrapWidth, Style.EMPTY);
|
||||
|
||||
int amount = lines.size();
|
||||
for (int i = 0; i < amount; i++) {
|
||||
FormattedText renderable = lines.get(i);
|
||||
font.draw(poseStack, renderable.getString(), x, (float)(y + i * 9), color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue