From 1672119cb383c5d333a77ade50cc2e749ae2d768 Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 2 Apr 2025 11:33:33 -0400 Subject: [PATCH] world/biome type options in world creation --- docs/src/progress/renderertodo.md | 1 + .../mainmenu/worldgen/MenuWorldSelect.java | 106 ++++++++++++++++++ .../renderer/ui/elements/StringCarousel.java | 10 ++ 3 files changed, 117 insertions(+) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index b8777eb8..b5af1d32 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1405,6 +1405,7 @@ HillsGen visuals work (04/01/2025) Falling min frames to activate increased Reorganizing world creation ui file +UI panel work diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/worldgen/MenuWorldSelect.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/worldgen/MenuWorldSelect.java index bf29534a..41fa2aaa 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/worldgen/MenuWorldSelect.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/worldgen/MenuWorldSelect.java @@ -1,6 +1,8 @@ package electrosphere.client.ui.menu.mainmenu.worldgen; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import electrosphere.auth.AuthenticationManager; import electrosphere.client.ui.menu.WindowUtils; @@ -8,11 +10,14 @@ import electrosphere.client.ui.menu.mainmenu.MenuGeneratorsTitleMenu; import electrosphere.engine.Globals; import electrosphere.engine.loadingthreads.LoadingThread; import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType; +import electrosphere.engine.signal.Signal.SignalType; import electrosphere.entity.scene.SceneGenerator; import electrosphere.renderer.ui.elements.Button; import electrosphere.renderer.ui.elements.Div; import electrosphere.renderer.ui.elements.FormElement; import electrosphere.renderer.ui.elements.Label; +import electrosphere.renderer.ui.elements.Panel; +import electrosphere.renderer.ui.elements.StringCarousel; import electrosphere.renderer.ui.elements.TextInput; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification; @@ -21,6 +26,8 @@ import electrosphere.renderer.ui.events.NavigationEvent; import electrosphere.server.saves.SaveUtils; public class MenuWorldSelect { + + private static WorldGenUIParams params; /** * Creates the world selection menu content @@ -68,6 +75,7 @@ public class MenuWorldSelect { createButtonContainer.setMarginLeft(50); //button (create) createButtonContainer.addChild(Button.createButton("Create World", () -> { + params = new WorldGenUIParams(); WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldCreationMenu()); })); @@ -119,6 +127,14 @@ public class MenuWorldSelect { worldSeedInput.setText(System.currentTimeMillis() + ""); worldSeedInputContainer.addChild(worldSeedInput); + Div worldTypeMenuButtonContainer = Div.createRow(); + { + Button worldTypeButton = Button.createButton("World Type", () -> { + WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldTypeDefinitionMenu()); + }); + worldTypeMenuButtonContainer.addChild(worldTypeButton); + } + //button (create) Div createButtonContainer = Div.createCol(); @@ -136,6 +152,91 @@ public class MenuWorldSelect { Div mainLayout = Div.createCol( worldNameInputContainer, worldSeedInputContainer, + worldTypeMenuButtonContainer, + createButtonContainer + ); + mainLayout.setMarginTop(300); + mainLayout.setAlignItems(YogaAlignment.Center); + rVal.addChild(mainLayout); + + return rVal; + } + + /** + * World type definition menu + * @return The world type definition menu element + */ + public static Element createWorldTypeDefinitionMenu(){ + FormElement rVal = new FormElement(); + + //set nav callback + WindowUtils.setMainMenuBackoutCallback((NavigationEvent event) -> { + WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldCreationMenu()); + return false; + }); + + //select world type + Div worldTypeCarousel = Div.createRow(); + { + Panel panel = Panel.createPanel(); + panel.setWidth(500); + panel.setJustifyContent(YogaJustification.Between); + worldTypeCarousel.addChild(panel); + + Label label = Label.createLabel("Type: "); + panel.addChild(label); + List options = Arrays.asList(new String[]{ + "Default", + "Homogenous", + }); + + StringCarousel typeCarousel = StringCarousel.create(options, (event) -> { + int index = options.indexOf(event.getAsString()); + params.worldType = index; + WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldTypeDefinitionMenu()); + }); + typeCarousel.setOption(params.worldType); + panel.addChild(typeCarousel); + } + + //select biome type (for homogenous worlds) + Div biomeTypeCarousel = Div.createRow(); + if(params.worldType == 1){ + Panel panel = Panel.createPanel(); + panel.setWidth(500); + panel.setJustifyContent(YogaJustification.Between); + biomeTypeCarousel.addChild(panel); + + Label label = Label.createLabel("Biome: "); + panel.addChild(label); + + + List biomes = Globals.gameConfigCurrent.getBiomeMap().getSurfaceBiomes().stream().map((biome) -> { + return biome.getDisplayName(); + }).collect(Collectors.toList()); + + StringCarousel typeCarousel = StringCarousel.create(biomes, (event) -> { + int index = biomes.indexOf(event.getAsString()); + params.biomeType = index; + Globals.signalSystem.post(SignalType.YOGA_APPLY,rVal); + }); + typeCarousel.setOption(params.biomeType); + panel.addChild(typeCarousel); + } + + + //button (create) + Div createButtonContainer = Div.createCol(); + createButtonContainer.setMarginTop(20); + createButtonContainer.addChild(Button.createButton("Return", () -> { + WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldCreationMenu()); + })); + + + //layout content + Div mainLayout = Div.createCol( + worldTypeCarousel, + biomeTypeCarousel, createButtonContainer ); mainLayout.setMarginTop(300); @@ -166,4 +267,9 @@ public class MenuWorldSelect { return rVal; } + static class WorldGenUIParams { + int worldType = 0; + int biomeType = 0; + } + } diff --git a/src/main/java/electrosphere/renderer/ui/elements/StringCarousel.java b/src/main/java/electrosphere/renderer/ui/elements/StringCarousel.java index 73003a4b..7f7eb641 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/StringCarousel.java +++ b/src/main/java/electrosphere/renderer/ui/elements/StringCarousel.java @@ -110,6 +110,15 @@ public class StringCarousel extends StandardContainerElement implements Drawable currentOption = options.size() - 1; } } + + public void setOption(int index){ + this.currentOption = index; + this.setText(this.options.get(index)); + } + + public int getCurrentOption(){ + return this.currentOption; + } void generateLetters(){ for(Element el : getChildren()){ @@ -138,6 +147,7 @@ public class StringCarousel extends StandardContainerElement implements Drawable if(focused){ setColor(new Vector3f(1,0,0)); } + Globals.signalSystem.post(SignalType.YOGA_APPLY, this); } public void setColor(Vector3f color){