diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index ed52f30d..fb1682aa 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1344,7 +1344,8 @@ Fix audio engine not cleaning up audio sources More accurate block test types Block meshgen work Delete deprecated foliage manager - +Title menu navigation work +Fix UI Testing debug menu # TODO diff --git a/src/main/java/electrosphere/client/ui/menu/MenuGenerators.java b/src/main/java/electrosphere/client/ui/menu/MenuGenerators.java index 11262009..fcee9f11 100644 --- a/src/main/java/electrosphere/client/ui/menu/MenuGenerators.java +++ b/src/main/java/electrosphere/client/ui/menu/MenuGenerators.java @@ -1,18 +1,6 @@ package electrosphere.client.ui.menu; -import electrosphere.auth.AuthenticationManager; -import electrosphere.client.ui.components.InputMacros; -import electrosphere.client.ui.menu.mainmenu.MenuGeneratorsKeybind; -import electrosphere.client.ui.menu.mainmenu.MenuGeneratorsTitleMenu; -import electrosphere.engine.Globals; -import electrosphere.engine.loadingthreads.LoadingThread; -import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType; -import electrosphere.net.NetUtils; -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.TextInput; import electrosphere.renderer.ui.elementtypes.Element; /** @@ -28,158 +16,6 @@ public class MenuGenerators { Div rVal = Div.createDiv(); return rVal; } - - - public static Element createCharacterCreationMenu(){ - FormElement rVal = new FormElement(); - - //TODO: add text input to name world - - //button (create) - rVal.addChild(Button.createButton("Create World", () -> { - throw new UnsupportedOperationException("Unimplemented"); - })); - - - return rVal; - } - - public static Element createFinalizeSaveCreationMenu(){ - FormElement rVal = new FormElement(); - - //TODO: add text input to name world - - //button (create) - rVal.addChild(Button.createButton("Create World", () -> { - throw new UnsupportedOperationException("Unimplemented"); - })); - - return rVal; - } - - public static Element createMultiplayerMenu(){ - FormElement rVal = new FormElement(); - - //button (host) - rVal.addChild(Button.createButton("Host", () -> { - LoadingThread clientThread = new LoadingThread(LoadingThreadType.CHARACTER_SERVER); - LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME); - Globals.RUN_CLIENT = true; - Globals.RUN_SERVER = true; - Globals.threadManager.start(serverThread); - Globals.threadManager.start(clientThread); - })); - - //button (join) - rVal.addChild(Button.createButton("Join", () -> { - WindowUtils.replaceMainMenuContents(MenuGenerators.createIPMenu()); - })); - - - //button (back) - rVal.addChild(Button.createButton("Back", () -> { - WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu()); - })); - - return rVal; - } - - public static Element createIPMenu(){ - FormElement rVal = new FormElement(); - - // - //Address input - // - String ipAddress = ""; - if(Globals.netConfig != null && Globals.netConfig.getAddress() != null){ - ipAddress = Globals.netConfig.getAddress(); - } else { - ipAddress = NetUtils.getAddress(); - } - Div addressControl = InputMacros.createTextInputVertical("IP Address", ipAddress); - TextInput addressInput = (TextInput)addressControl.getChildren().get(1); - rVal.addChild(addressControl); - - // - //Port input - // - String port = ""; - if(Globals.netConfig != null && Globals.netConfig.getPort() != null){ - port = Globals.netConfig.getPort(); - } else { - port = NetUtils.getPort() + ""; - } - Div portControl = InputMacros.createTextInputVertical("Port", port); - TextInput portInput = (TextInput)portControl.getChildren().get(1); - rVal.addChild(portControl); - - // - //Username input - // - String username = ""; - if(Globals.netConfig != null && Globals.netConfig.getPort() != null){ - username = Globals.netConfig.getUsername(); - } else { - username = ""; - } - Div usernameControl = InputMacros.createTextInputVertical("Username", username); - TextInput usernameInput = (TextInput)usernameControl.getChildren().get(1); - rVal.addChild(usernameControl); - - - // - //Password input - // - String password = ""; - if(Globals.netConfig != null && Globals.netConfig.getPort() != null){ - password = Globals.netConfig.getPassword(); - } else { - password = ""; - } - Div passwordControl = InputMacros.createTextInputVertical("Password", password); - TextInput passwordInput = (TextInput)passwordControl.getChildren().get(1); - rVal.addChild(passwordControl); - - //button (connect) - rVal.addChild(Button.createButton("Connect", () -> { - NetUtils.setAddress(addressInput.getText()); - NetUtils.setPort(Integer.parseInt(portInput.getText())); - Globals.clientUsername = usernameInput.getText(); - Globals.clientPassword = AuthenticationManager.getHashedString(passwordInput.getText()); - LoadingThread clientThread = new LoadingThread(LoadingThreadType.CHARACTER_SERVER); - Globals.RUN_CLIENT = true; - Globals.RUN_SERVER = false; - Globals.threadManager.start(clientThread); - })); - - //button (back) - rVal.addChild(Button.createButton("Back", () -> { - WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu()); - })); - - return rVal; - } - - public static Element createOptionsMainMenu(){ - FormElement rVal = new FormElement(); - - //label (options) - Label optionsLabel = Label.createLabel("Options"); - rVal.addChild(optionsLabel); - - //button (back) - rVal.addChild(Button.createButton("Back", () -> { - WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu()); - })); - - //button to open rebind controls window - Button rebindControlsButton = Button.createButton("Controls", () -> { - WindowUtils.replaceMainMenuContents(MenuGeneratorsKeybind.createControlsRebindMenu()); - }); - rVal.addChild(rebindControlsButton); - - return rVal; - } diff --git a/src/main/java/electrosphere/client/ui/menu/WindowUtils.java b/src/main/java/electrosphere/client/ui/menu/WindowUtils.java index 4caafdc1..b2ecce00 100644 --- a/src/main/java/electrosphere/client/ui/menu/WindowUtils.java +++ b/src/main/java/electrosphere/client/ui/menu/WindowUtils.java @@ -14,6 +14,7 @@ import electrosphere.renderer.ui.elements.Window; import electrosphere.renderer.ui.elementtypes.ContainerElement; import electrosphere.renderer.ui.elementtypes.DrawableElement; import electrosphere.renderer.ui.elementtypes.Element; +import electrosphere.renderer.ui.elementtypes.NavigableElement.NavigationEventCallback; /** * Utils for native windowing framework @@ -151,6 +152,15 @@ public class WindowUtils { Globals.elementService.focusFirstElement(); } + /** + * Sets the backout callback for the main menu window + * @param onNav The callback + */ + public static void setMainMenuBackoutCallback(NavigationEventCallback onNav){ + Window mainMenu = (Window)Globals.elementService.getWindow(WindowStrings.WINDOW_MENU_MAIN); + mainMenu.setOnNavigationCallback(onNav); + } + /** * Cleans up a window visually and removes it from the element manager * @param window the window to clean up diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsLevelEditor.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsLevelEditor.java index 0d07196d..d6931c55 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsLevelEditor.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsLevelEditor.java @@ -20,6 +20,7 @@ import electrosphere.renderer.ui.elements.Label; import electrosphere.renderer.ui.elementtypes.Element; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification; +import electrosphere.renderer.ui.events.NavigationEvent; import electrosphere.renderer.ui.events.ValueChangeEvent; import electrosphere.server.datacell.GriddedDataCellManager; import electrosphere.server.saves.SaveUtils; @@ -50,6 +51,12 @@ public class MenuGeneratorsLevelEditor { //left-right rVal.setAlignItems(YogaAlignment.Center); rVal.setAlignContent(YogaAlignment.Center); + + //set nav callback + WindowUtils.setMainMenuBackoutCallback((NavigationEvent event) -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu()); + return false; + }); // @@ -135,6 +142,13 @@ public class MenuGeneratorsLevelEditor { */ public static Element createLevelEditorCreationMenu(){ + //set nav callback + WindowUtils.setMainMenuBackoutCallback((NavigationEvent event) -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsLevelEditor.createLevelEditorTopMenu()); + return false; + }); + + //values to creat the level with LevelDescription inFlightLevel = new LevelDescription(); SceneFile sceneFile = SceneFile.createSceneFile(); diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsMultiplayer.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsMultiplayer.java index b1d30e31..77ab2b12 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsMultiplayer.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsMultiplayer.java @@ -1,18 +1,26 @@ package electrosphere.client.ui.menu.mainmenu; +import electrosphere.auth.AuthenticationManager; import electrosphere.client.ui.components.CharacterCustomizer; +import electrosphere.client.ui.components.InputMacros; import electrosphere.client.ui.menu.WindowUtils; import electrosphere.engine.Globals; +import electrosphere.engine.loadingthreads.LoadingThread; +import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType; import electrosphere.entity.types.creature.CreatureTemplate; +import electrosphere.net.NetUtils; import electrosphere.net.parser.net.message.CharacterMessage; 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.StringCarousel; +import electrosphere.renderer.ui.elements.TextInput; import electrosphere.renderer.ui.elementtypes.ClickableElement; import electrosphere.renderer.ui.elementtypes.Element; import electrosphere.renderer.ui.elementtypes.ValueElement.ValueChangeEventCallback; import electrosphere.renderer.ui.events.ClickEvent; +import electrosphere.renderer.ui.events.NavigationEvent; import electrosphere.renderer.ui.events.ValueChangeEvent; import electrosphere.util.Utilities; @@ -63,4 +71,127 @@ public class MenuGeneratorsMultiplayer { return rVal; } + /** + * The multiplayer mode selection menu + * @return The element containing the menu + */ + public static Element createMultiplayerMenu(){ + FormElement rVal = new FormElement(); + + //set nav callback + WindowUtils.setMainMenuBackoutCallback((NavigationEvent event) -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu()); + return false; + }); + + //button (host) + rVal.addChild(Button.createButton("Host", () -> { + LoadingThread clientThread = new LoadingThread(LoadingThreadType.CHARACTER_SERVER); + LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME); + Globals.RUN_CLIENT = true; + Globals.RUN_SERVER = true; + Globals.threadManager.start(serverThread); + Globals.threadManager.start(clientThread); + })); + + //button (join) + rVal.addChild(Button.createButton("Join", () -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsMultiplayer.createIPMenu()); + })); + + + //button (back) + rVal.addChild(Button.createButton("Back", () -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu()); + })); + + return rVal; + } + + /** + * The ip input menu + * @return The element containing the menu + */ + public static Element createIPMenu(){ + FormElement rVal = new FormElement(); + + //set nav callback + WindowUtils.setMainMenuBackoutCallback((NavigationEvent event) -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsMultiplayer.createMultiplayerMenu()); + return false; + }); + + // + //Address input + // + String ipAddress = ""; + if(Globals.netConfig != null && Globals.netConfig.getAddress() != null){ + ipAddress = Globals.netConfig.getAddress(); + } else { + ipAddress = NetUtils.getAddress(); + } + Div addressControl = InputMacros.createTextInputVertical("IP Address", ipAddress); + TextInput addressInput = (TextInput)addressControl.getChildren().get(1); + rVal.addChild(addressControl); + + // + //Port input + // + String port = ""; + if(Globals.netConfig != null && Globals.netConfig.getPort() != null){ + port = Globals.netConfig.getPort(); + } else { + port = NetUtils.getPort() + ""; + } + Div portControl = InputMacros.createTextInputVertical("Port", port); + TextInput portInput = (TextInput)portControl.getChildren().get(1); + rVal.addChild(portControl); + + // + //Username input + // + String username = ""; + if(Globals.netConfig != null && Globals.netConfig.getPort() != null){ + username = Globals.netConfig.getUsername(); + } else { + username = ""; + } + Div usernameControl = InputMacros.createTextInputVertical("Username", username); + TextInput usernameInput = (TextInput)usernameControl.getChildren().get(1); + rVal.addChild(usernameControl); + + + // + //Password input + // + String password = ""; + if(Globals.netConfig != null && Globals.netConfig.getPort() != null){ + password = Globals.netConfig.getPassword(); + } else { + password = ""; + } + Div passwordControl = InputMacros.createTextInputVertical("Password", password); + TextInput passwordInput = (TextInput)passwordControl.getChildren().get(1); + rVal.addChild(passwordControl); + + //button (connect) + rVal.addChild(Button.createButton("Connect", () -> { + NetUtils.setAddress(addressInput.getText()); + NetUtils.setPort(Integer.parseInt(portInput.getText())); + Globals.clientUsername = usernameInput.getText(); + Globals.clientPassword = AuthenticationManager.getHashedString(passwordInput.getText()); + LoadingThread clientThread = new LoadingThread(LoadingThreadType.CHARACTER_SERVER); + Globals.RUN_CLIENT = true; + Globals.RUN_SERVER = false; + Globals.threadManager.start(clientThread); + })); + + //button (back) + rVal.addChild(Button.createButton("Back", () -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsMultiplayer.createMultiplayerMenu()); + })); + + return rVal; + } + } diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsTitleMenu.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsTitleMenu.java index 5fdc519b..11f0e262 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsTitleMenu.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsTitleMenu.java @@ -1,6 +1,5 @@ package electrosphere.client.ui.menu.mainmenu; -import electrosphere.client.ui.menu.MenuGenerators; import electrosphere.client.ui.menu.WindowUtils; import electrosphere.engine.Globals; import electrosphere.engine.assetmanager.AssetDataStrings; @@ -14,6 +13,7 @@ import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaFlexDirection; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification; import electrosphere.renderer.ui.elementtypes.Element; +import electrosphere.renderer.ui.events.NavigationEvent; /** * Menu generators for the title menu @@ -25,6 +25,12 @@ public class MenuGeneratorsTitleMenu { * @return The menu element */ public static Element createTitleMenu(){ + + //set nav callback + WindowUtils.setMainMenuBackoutCallback((NavigationEvent event) -> { + return false; + }); + Div rVal = Div.createDiv(); //top-bottom rVal.setJustifyContent(YogaJustification.Between); @@ -53,7 +59,7 @@ public class MenuGeneratorsTitleMenu { //button (multiplayer) optionPanel.addChild(Button.createButtonCentered("Multiplayer", 1.0f, () -> { - WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu()); + WindowUtils.replaceMainMenuContents(MenuGeneratorsMultiplayer.createMultiplayerMenu()); }).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE)); //button (static level) @@ -63,7 +69,7 @@ public class MenuGeneratorsTitleMenu { //button (options) optionPanel.addChild(Button.createButtonCentered("Options", 1.0f, () -> { - WindowUtils.replaceMainMenuContents(MenuGenerators.createOptionsMainMenu()); + WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleOptions.createOptionsMainMenu()); }).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE)); //button (sp debug) diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsTitleOptions.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsTitleOptions.java new file mode 100644 index 00000000..12d98fe9 --- /dev/null +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsTitleOptions.java @@ -0,0 +1,46 @@ +package electrosphere.client.ui.menu.mainmenu; + +import electrosphere.client.ui.menu.WindowUtils; +import electrosphere.renderer.ui.elements.Button; +import electrosphere.renderer.ui.elements.FormElement; +import electrosphere.renderer.ui.elements.Label; +import electrosphere.renderer.ui.elementtypes.Element; +import electrosphere.renderer.ui.events.NavigationEvent; + +/** + * Functions for generating the options menu ui + */ +public class MenuGeneratorsTitleOptions { + + /** + * Generates the main options page + * @return The element containing the main options page + */ + public static Element createOptionsMainMenu(){ + FormElement rVal = new FormElement(); + + //set nav callback + WindowUtils.setMainMenuBackoutCallback((NavigationEvent event) -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu()); + return false; + }); + + //label (options) + Label optionsLabel = Label.createLabel("Options"); + rVal.addChild(optionsLabel); + + //button (back) + rVal.addChild(Button.createButton("Back", () -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu()); + })); + + //button to open rebind controls window + Button rebindControlsButton = Button.createButton("Controls", () -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsKeybind.createControlsRebindMenu()); + }); + rVal.addChild(rebindControlsButton); + + return rVal; + } + +} diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java index e5d196b6..286241db 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java @@ -97,10 +97,10 @@ public class MenuGeneratorsUITesting { formEl.addChild(InputMacros.createToggle("Test Toggle", false, null)); //actor panel - ActorPanel actorPanel = ActorPanel.create(ActorUtils.createActorFromModelPath(AssetDataStrings.UNITCUBE)); if(Globals.playerCamera == null){ Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3d(0,0,0), new Vector3d(-1,0,0)); } + ActorPanel actorPanel = ActorPanel.create(ActorUtils.createActorFromModelPath(AssetDataStrings.UNITCUBE)); formEl.addChild(actorPanel); diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuWorldSelect.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuWorldSelect.java index 04b08526..7c473ff5 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuWorldSelect.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuWorldSelect.java @@ -15,6 +15,7 @@ import electrosphere.renderer.ui.elements.TextInput; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification; import electrosphere.renderer.ui.elementtypes.Element; +import electrosphere.renderer.ui.events.NavigationEvent; import electrosphere.server.saves.SaveUtils; public class MenuWorldSelect { @@ -26,6 +27,12 @@ public class MenuWorldSelect { public static Element createWorldSelectMenu(){ FormElement rVal = new FormElement(); + //set nav callback + WindowUtils.setMainMenuBackoutCallback((NavigationEvent event) -> { + WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu()); + return false; + }); + //create save button column Div saveButtonContainer = Div.createCol(); saveButtonContainer.setMarginRight(50);