From 95ffc7765f3316ad695c13ec68e03acff122bb86 Mon Sep 17 00:00:00 2001 From: dags- Date: Mon, 29 Jun 2020 18:27:02 +0100 Subject: [PATCH] improvements to transition sliders --- Engine | 2 +- .../assets/terraforged/lang/en_us.json | 106 ------------------ .../mod/biome/modifier/BeachModifier.java | 2 +- .../mod/chunk/TerraChunkGenerator.java | 2 +- .../terraforged/mod/client/gui/GuiKeys.java | 3 +- .../client/gui/element/TerraBoundSlider.java | 54 +++++++++ .../mod/client/gui/element/TerraSlider.java | 7 +- .../terraforged/mod/client/gui/page/Page.java | 7 ++ .../mod/client/gui/page/PresetsPage.java | 47 ++++---- .../mod/client/gui/page/WorldPage.java | 1 + .../mod/client/gui/preview/RenderMode.java | 40 +++---- 11 files changed, 121 insertions(+), 150 deletions(-) delete mode 100644 generated/resources/assets/terraforged/lang/en_us.json create mode 100644 src/main/java/com/terraforged/mod/client/gui/element/TerraBoundSlider.java diff --git a/Engine b/Engine index ad79d9c..37a553e 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit ad79d9cb059d512a955e99bdd9a4340e07ae34e8 +Subproject commit 37a553e45da72353eb608459b195e8f503a3fcab diff --git a/generated/resources/assets/terraforged/lang/en_us.json b/generated/resources/assets/terraforged/lang/en_us.json deleted file mode 100644 index cec6033..0000000 --- a/generated/resources/assets/terraforged/lang/en_us.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "biome.terraforged.bryce": "Bryce", - "biome.terraforged.cold_steppe": "Cold Steppe", - "biome.terraforged.fir_forest": "Fir Forest", - "biome.terraforged.flower_plains": "Flower Plains", - "biome.terraforged.frozen_lake": "Frozen Lake", - "biome.terraforged.lake": "Lake", - "biome.terraforged.marshland": "Marshland", - "biome.terraforged.savanna_scrub": "Savanna Scrub", - "biome.terraforged.shattered_savanna_scrub": "Shattered Savanna Scrub", - "biome.terraforged.snowy_fir_forest": "Snowy Fir Forest", - "biome.terraforged.snowy_taiga_scrub": "Snowy Taiga Scrub", - "biome.terraforged.steppe": "Steppe", - "biome.terraforged.stone_forest": "Stone Forest", - "biome.terraforged.taiga_scrub": "Taiga Scrub", - "biome.terraforged.warm_beach": "Warm Beach", - "display.terraforged.climate.title": "Climate Settings", - "display.terraforged.dimensions": "Dimensions", - "display.terraforged.dimensions.bedrock_layer": "Bedrock Layer", - "display.terraforged.dimensions.bedrock_layer.material": "Material", - "display.terraforged.dimensions.bedrock_layer.min_depth": "Min Depth", - "display.terraforged.dimensions.bedrock_layer.variance": "Variance", - "display.terraforged.dimensions.dimensions": "Dimensions", - "display.terraforged.dimensions.dimensions.end": "End", - "display.terraforged.dimensions.dimensions.nether": "Nether", - "display.terraforged.filters.title": "Filter Settings", - "display.terraforged.general.cancel": "Cancel", - "display.terraforged.general.done": "Done", - "display.terraforged.miscellaneous": "Miscellaneous", - "display.terraforged.miscellaneous.custom_biome_features": "Custom Biome Features", - "display.terraforged.miscellaneous.erosion_decorator": "Erosion Decorator", - "display.terraforged.miscellaneous.mountain_biome_usage": "Mountain Biome Usage", - "display.terraforged.miscellaneous.natural_snow_decorator": "Natural Snow Decorator", - "display.terraforged.miscellaneous.smooth_layer_decorator": "Smooth Layer Decorator", - "display.terraforged.miscellaneous.strata_decorator": "Strata Decorator", - "display.terraforged.miscellaneous.title": "Miscellaneous Settings", - "display.terraforged.miscellaneous.vanilla_water_features": "Vanilla Water Features", - "display.terraforged.preset.create": "Create", - "display.terraforged.preset.default": "Make Default", - "display.terraforged.preset.delete": "Delete", - "display.terraforged.preset.load": "Load", - "display.terraforged.preset.reset": "Reset", - "display.terraforged.preset.save": "Save", - "display.terraforged.presets.title": "Presets & Defaults", - "display.terraforged.preview": "Preview", - "display.terraforged.preview.area": "Area: ", - "display.terraforged.preview.biome": "Biome: ", - "display.terraforged.preview.display": "Display", - "display.terraforged.preview.seed": "New Seed", - "display.terraforged.preview.terrain": "Terrain: ", - "display.terraforged.preview.zoom": "Zoom", - "display.terraforged.river.title": "River Settings", - "display.terraforged.structures": "Structures", - "display.terraforged.structures.mansions": "Mansions", - "display.terraforged.structures.mansions.distance": "Distance", - "display.terraforged.structures.mansions.separation": "Separation", - "display.terraforged.structures.ocean_monuments": "Ocean Monuments", - "display.terraforged.structures.ocean_monuments.distance": "Distance", - "display.terraforged.structures.ocean_monuments.separation": "Separation", - "display.terraforged.structures.ocean_ruins": "Ocean Ruins", - "display.terraforged.structures.ocean_ruins.distance": "Distance", - "display.terraforged.structures.ocean_ruins.separation": "Separation", - "display.terraforged.structures.other_structures": "Other Structures", - "display.terraforged.structures.other_structures.distance": "Distance", - "display.terraforged.structures.other_structures.separation": "Separation", - "display.terraforged.structures.shipwrecks": "Shipwrecks", - "display.terraforged.structures.shipwrecks.distance": "Distance", - "display.terraforged.structures.shipwrecks.separation": "Separation", - "display.terraforged.structures.strongholds": "Strongholds", - "display.terraforged.structures.strongholds.distance": "Distance", - "display.terraforged.structures.strongholds.separation": "Separation", - "display.terraforged.structures.title": "Structure Settings", - "display.terraforged.structures.villages": "Villages", - "display.terraforged.structures.villages.distance": "Distance", - "display.terraforged.structures.villages.separation": "Separation", - "display.terraforged.terrain.title": "Terrain Settings", - "display.terraforged.world.title": "World Settings", - "generator.terraforged": "TerraForged", - "generator.terratest": "TerraTest", - "tooltip.terraforged.dimensions.bedrock_layer.material": "Controls the material that should be used in the world's base layer", - "tooltip.terraforged.dimensions.bedrock_layer.min_depth": "Controls the minimum height of the world's base layer", - "tooltip.terraforged.dimensions.bedrock_layer.variance": "Controls the amount of height randomness of the world's base layer", - "tooltip.terraforged.dimensions.dimensions.end": "Select the end generator", - "tooltip.terraforged.dimensions.dimensions.nether": "Select the nether generator", - "tooltip.terraforged.miscellaneous.custom_biome_features": "Use custom biome features in place of vanilla ones (such as trees)", - "tooltip.terraforged.miscellaneous.erosion_decorator": "Replace surface materials where erosion has occurred", - "tooltip.terraforged.miscellaneous.mountain_biome_usage": "The probability that mountainous terrain will be set to a mountain biome type.\nThis may help improve compatibility with mods that rely exclusively on mountain biomes.", - "tooltip.terraforged.miscellaneous.natural_snow_decorator": "Removes snow from the terrain where it shouldn't naturally settle", - "tooltip.terraforged.miscellaneous.smooth_layer_decorator": "Modifies layer block levels (ie snow) to fit the terrain", - "tooltip.terraforged.miscellaneous.strata_decorator": "Generates strata (rock layers) instead of just stone", - "tooltip.terraforged.miscellaneous.vanilla_water_features": "Controls whether vanilla lakes & springs should generate", - "tooltip.terraforged.structures.mansions.distance": "The maximum distance in chunks between attempts to spawn a structure", - "tooltip.terraforged.structures.mansions.separation": "The minimum distance in chunks between structure spawns", - "tooltip.terraforged.structures.ocean_monuments.distance": "The maximum distance in chunks between attempts to spawn a structure", - "tooltip.terraforged.structures.ocean_monuments.separation": "The minimum distance in chunks between structure spawns", - "tooltip.terraforged.structures.ocean_ruins.distance": "The maximum distance in chunks between attempts to spawn a structure", - "tooltip.terraforged.structures.ocean_ruins.separation": "The minimum distance in chunks between structure spawns", - "tooltip.terraforged.structures.other_structures.distance": "The maximum distance in chunks between attempts to spawn a structure", - "tooltip.terraforged.structures.other_structures.separation": "The minimum distance in chunks between structure spawns", - "tooltip.terraforged.structures.shipwrecks.distance": "The maximum distance in chunks between attempts to spawn a structure", - "tooltip.terraforged.structures.shipwrecks.separation": "The minimum distance in chunks between structure spawns", - "tooltip.terraforged.structures.strongholds.distance": "The maximum distance in chunks between attempts to spawn a structure", - "tooltip.terraforged.structures.strongholds.separation": "The minimum distance in chunks between structure spawns", - "tooltip.terraforged.structures.villages.distance": "The maximum distance in chunks between attempts to spawn a structure", - "tooltip.terraforged.structures.villages.separation": "The minimum distance in chunks between structure spawns" -} \ No newline at end of file diff --git a/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java b/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java index 5e3d30e..1c75a80 100644 --- a/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java +++ b/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java @@ -20,7 +20,7 @@ public class BeachModifier implements BiomeModifier { public BeachModifier(BiomeMap biomeMap, GeneratorContext context) { this.biomes = biomeMap; this.height = context.levels.water(6); - this.noise = Source.perlin(context.seed.next(), 10, 1).scale(context.levels.scale(5)); + this.noise = Source.perlin(context.seed.next(), 15, 1).scale(context.levels.scale(5)); } @Override diff --git a/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java b/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java index 36de966..333cb6d 100644 --- a/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java +++ b/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java @@ -140,7 +140,7 @@ public class TerraChunkGenerator extends ChunkGenerator { @Override public final void generateSurface(WorldGenRegion world, IChunk chunk) { -// surfaceGenerator.generateSurface(world, chunk); + surfaceGenerator.generateSurface(world, chunk); } @Override diff --git a/src/main/java/com/terraforged/mod/client/gui/GuiKeys.java b/src/main/java/com/terraforged/mod/client/gui/GuiKeys.java index 6bda3fa..269cc59 100644 --- a/src/main/java/com/terraforged/mod/client/gui/GuiKeys.java +++ b/src/main/java/com/terraforged/mod/client/gui/GuiKeys.java @@ -25,8 +25,9 @@ public class GuiKeys { public static final TranslationKey PRESET_LOAD = TranslationKey.gui("preset.load", "Load"); public static final TranslationKey PRESET_SAVE = TranslationKey.gui("preset.save", "Save"); public static final TranslationKey PRESET_RESET = TranslationKey.gui("preset.reset", "Reset"); - public static final TranslationKey PRESET_DEFAULT = TranslationKey.gui("preset.default", "Make Default"); public static final TranslationKey PRESET_DELETE = TranslationKey.gui("preset.delete", "Delete"); + public static final TranslationKey PRESET_SET_DEFAULTS = TranslationKey.gui("preset.default.set", "Make Defaults"); + public static final TranslationKey PRESET_CLEAR_DEFAULTS = TranslationKey.gui("preset.default.reset", "Reset Defaults"); public static void init() { diff --git a/src/main/java/com/terraforged/mod/client/gui/element/TerraBoundSlider.java b/src/main/java/com/terraforged/mod/client/gui/element/TerraBoundSlider.java new file mode 100644 index 0000000..333a9c4 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/element/TerraBoundSlider.java @@ -0,0 +1,54 @@ +package com.terraforged.mod.client.gui.element; + +import com.terraforged.n2d.util.NoiseUtil; +import net.minecraft.nbt.CompoundNBT; +import net.minecraftforge.fml.client.gui.widget.Slider; + +public class TerraBoundSlider extends TerraSlider.Float { + + private final float pad; + private final String lower; + private final String upper; + + public TerraBoundSlider(String name, CompoundNBT value) { + this(name, value, 0.01F); + } + + public TerraBoundSlider(String name, CompoundNBT value, float pad) { + super(name, value); + CompoundNBT meta = value.getCompound("#" + name); + this.pad = pad; + this.lower = meta.getString("limit_lower"); + this.upper = meta.getString("limit_upper"); + } + + @Override + protected void onChange(Slider slider, CompoundNBT value) { + int i = (int) (slider.getValue() * 1000); + + float lower = getLower(value) + pad; + float upper = getUpper(value) - pad; + float val = NoiseUtil.clamp(i / 1000F, lower, upper); + + // update setting value + value.putFloat(name, val); + + // update actual slider value + setValue(val); + updateSlider(); + } + + private float getLower(CompoundNBT value) { + if (lower == null || lower.isEmpty()) { + return 0F; + } + return value.getFloat(lower); + } + + private float getUpper(CompoundNBT value) { + if (upper == null || upper.isEmpty()) { + return 1F; + } + return value.getFloat(upper); + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/element/TerraSlider.java b/src/main/java/com/terraforged/mod/client/gui/element/TerraSlider.java index f09b6fa..b9b59d1 100644 --- a/src/main/java/com/terraforged/mod/client/gui/element/TerraSlider.java +++ b/src/main/java/com/terraforged/mod/client/gui/element/TerraSlider.java @@ -36,6 +36,7 @@ public abstract class TerraSlider extends Slider implements Slider.ISlider, Elem private final CompoundNBT value; private final List tooltip; + private boolean lock = false; private Runnable callback = () -> {}; public TerraSlider(String name, CompoundNBT value, boolean decimal) { @@ -58,7 +59,11 @@ public abstract class TerraSlider extends Slider implements Slider.ISlider, Elem @Override public void onChangeSliderValue(Slider slider) { - onChange(slider, value); + if (!lock) { + lock = true; + onChange(slider, value); + lock = false; + } } @Override diff --git a/src/main/java/com/terraforged/mod/client/gui/page/Page.java b/src/main/java/com/terraforged/mod/client/gui/page/Page.java index 91397f5..e9244b4 100644 --- a/src/main/java/com/terraforged/mod/client/gui/page/Page.java +++ b/src/main/java/com/terraforged/mod/client/gui/page/Page.java @@ -29,6 +29,7 @@ import com.terraforged.mod.client.gui.OverlayRenderer; import com.terraforged.mod.client.gui.OverlayScreen; import com.terraforged.mod.client.gui.ScrollPane; import com.terraforged.mod.client.gui.element.Element; +import com.terraforged.mod.client.gui.element.TerraBoundSlider; import com.terraforged.mod.client.gui.element.TerraLabel; import com.terraforged.mod.client.gui.element.TerraSlider; import com.terraforged.mod.client.gui.element.TerraTextInput; @@ -168,6 +169,8 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer { byte type = tag.getId(); if (type == Constants.NBT.TAG_INT) { return new TerraSlider.Int(name, value).callback(callback); + } else if (type == Constants.NBT.TAG_FLOAT && hasLimit(name, value)) { + return new TerraBoundSlider(name, value).callback(callback); } else if (type == Constants.NBT.TAG_FLOAT) { return new TerraSlider.Float(name, value).callback(callback); } else if (type == Constants.NBT.TAG_STRING && hasOptions(name, value)) { @@ -209,4 +212,8 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer { private static boolean hasOptions(String name, CompoundNBT value) { return value.getCompound("#" + name).contains("options"); } + + private static boolean hasLimit(String name, CompoundNBT value) { + return value.getCompound("#" + name).contains("limit_lower"); + } } diff --git a/src/main/java/com/terraforged/mod/client/gui/page/PresetsPage.java b/src/main/java/com/terraforged/mod/client/gui/page/PresetsPage.java index 7bb68bb..8a1c79a 100644 --- a/src/main/java/com/terraforged/mod/client/gui/page/PresetsPage.java +++ b/src/main/java/com/terraforged/mod/client/gui/page/PresetsPage.java @@ -156,25 +156,6 @@ public class PresetsPage extends BasePage { } }); - right.scrollPane.addButton(new TerraButton(GuiKeys.PRESET_DEFAULT.get()) { - - @Override - public void render(int x, int z, float ticks) { - super.active = hasSelectedPreset(); - super.render(x, z, ticks); - } - - @Override - public void onClick(double x, double y) { - super.onClick(x, y); - getSelected().ifPresent(preset -> { - TerraSettings settings = preset.getSettings(); - - SettingsHelper.exportDefaults(settings); - }); - } - }); - right.scrollPane.addButton(new TerraButton(GuiKeys.PRESET_DELETE.get()) { @Override @@ -194,6 +175,34 @@ public class PresetsPage extends BasePage { } }); + right.scrollPane.addButton(new TerraButton(GuiKeys.PRESET_SET_DEFAULTS.get()) { + + @Override + public void render(int x, int z, float ticks) { + super.active = hasSelectedPreset(); + super.render(x, z, ticks); + } + + @Override + public void onClick(double x, double y) { + super.onClick(x, y); + getSelected().ifPresent(preset -> { + TerraSettings settings = preset.getSettings(); + SettingsHelper.exportDefaults(settings); + }); + } + }); + + right.scrollPane.addButton(new TerraButton(GuiKeys.PRESET_CLEAR_DEFAULTS.get()) { + + @Override + public void onClick(double x, double y) { + super.onClick(x, y); + TerraSettings settings = new TerraSettings(); + SettingsHelper.exportDefaults(settings); + } + }); + right.scrollPane.addButton(previewWidget); // used to pad the scroll-pane out so that the preview legend scrolls on larger gui scales diff --git a/src/main/java/com/terraforged/mod/client/gui/page/WorldPage.java b/src/main/java/com/terraforged/mod/client/gui/page/WorldPage.java index 07de647..ff0ef25 100644 --- a/src/main/java/com/terraforged/mod/client/gui/page/WorldPage.java +++ b/src/main/java/com/terraforged/mod/client/gui/page/WorldPage.java @@ -70,6 +70,7 @@ public class WorldPage extends BasePage { Column left = getColumn(0); addElements(left.left, left.top, left, worldSettings, true, left.scrollPane::addButton, this::update); + addElements(left.left, left.top, left, dimSettings, true, left.scrollPane::addButton, this::update); } diff --git a/src/main/java/com/terraforged/mod/client/gui/preview/RenderMode.java b/src/main/java/com/terraforged/mod/client/gui/preview/RenderMode.java index 54761c4..89f5110 100644 --- a/src/main/java/com/terraforged/mod/client/gui/preview/RenderMode.java +++ b/src/main/java/com/terraforged/mod/client/gui/preview/RenderMode.java @@ -40,6 +40,26 @@ public enum RenderMode { return rgba(hsb[0], hsb[1], (hsb[2] * scale) + bias); } }, + TRANSITION_POINTS { + @Override + public int getColor(Cell cell, float scale, float bias) { + switch (cell.terrain.getType()) { + case DEEP_OCEAN: + return rgba(0.65F, 0.7F, 0.7F); + case SHALLOW_OCEAN: + return rgba(0.6F, 0.6F, 0.8F); + case BEACH: + return rgba(0.2F, 0.4F, 0.75F); + case COAST: + return rgba(0.35F, 0.75F, 0.65F); + default: + if (cell.terrain.isRiver() || cell.terrain.isWetland()) { + return rgba(0.6F, 0.6F, 0.8F); + } + return rgba(0.3F, 0.7F, 0.5F); + } + } + }, TEMPERATURE { @Override public int getColor(Cell cell, float scale, float bias) { @@ -80,26 +100,6 @@ public enum RenderMode { return rgba(cell.region, saturation, brightness); } }, - TRANSITION_POINTS { - @Override - public int getColor(Cell cell, float scale, float bias) { - switch (cell.terrain.getType()) { - case DEEP_OCEAN: - return rgba(0.65F, 0.7F, 0.7F); - case SHALLOW_OCEAN: - return rgba(0.6F, 0.6F, 0.8F); - case BEACH: - return rgba(0.2F, 0.4F, 0.75F); - case COAST: - return rgba(0.35F, 0.75F, 0.65F); - default: - if (cell.terrain.isRiver() || cell.terrain.isWetland()) { - return rgba(0.6F, 0.6F, 0.8F); - } - return rgba(0.3F, 0.7F, 0.5F); - } - } - } ; public int getColor(Cell cell, Levels levels) {