Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Integration of NUI (Relates to #455) #536

Merged
merged 21 commits into from
Nov 28, 2020

Conversation

BenjaminAmos
Copy link
Contributor

Description

This pull request introduces the NUI UI library to Destination Sol, with the intention of eventually replacing the built-in solution. It also introduces Terasology's console UI into the game and adds a command to display NUI UI screens. This relates to #455.

I have re-created a series of themed widget graphics for Destination Sol, which are roughly based on the existing UI. You can change those or modify them as you see fit, or even replace them entirely. They were designed for testing NUI, as Terasology's UI graphics looked rather out of place in Destination Sol.

Apart from the console screen, none of the pre-existing UI screens have been ported yet. The NUI UI system and the built-in one co-exist, although they may occasionally conflict, as they use a shared SpriteBatch instance.

Testing

Configuring NUI
Testing that NUI works
  • Start Destionation Sol and create a new game (any settings should work)
  • Press the ` key to open the console
  • Ensure that the console is visible and shows the correct text
  • Enter some input into the console (e.g. "help")
  • Ensure that a valid response is produced (e.g. a list of commands)

Testing NUI's widgets

  • The MigTestScreen from Terasology has been ported as it shows the UI's alignment capabilities, as well as a variety of widgets. You can view it using the command showNUIScreen engine:migTestScreen.
  • Ensure that the widgets display correctly (you may have to use Terasology as a reference)
  • Ensure that the widgets can be interacted with correctly (you may have to use Terasology as a reference)

Testing that NUI scales

One of the major issues with the existing UI system is that it does not scale very well. UI elements often appear out of alignment when the resolution is changed. The new NUI implementation should not suffer as much from this issue.

  • Follow the instructions from the prior two sections.
  • Close the console and test screen using the Escape key.
  • Open the game menu (press Escape again) and go back to the main menu.
  • Go into the settings (options) and set change the screen resolution.
  • Continue from your previous game and follow the instructions from the Testing that NUI works and Testing NUI's widgets sections again. Ensure that the UI appears visually similar and is still functional.
Testing with non-discrete resolutions (Windowed mode only)
  • Follow the same instructions as above but instead of changing the resolution in the options menu, open the in-game pause menu and drag the window corners to change the size of the window (or however you would do so natively in your OS).
  • The console UI should still scale correctly, as well as the text within it.

Testing UI scaling

  • When the game starts, open the Options->Resolution menu and press the NUI UI Scale button to change the UI scale.
  • Start a game (either create a new one or continue an existing one)
  • Open the console using the ` key
  • The console UI should appear either larger or smaller. The NUI widgets are either being upscaled or downscaled to the target scale factor.
  • Scale factors below 1 should increase the screen size. Scale factors above 1 should decrease it. The screen is scaled from a resolution of target * scale to the target resolution.

Multi-platform testing

  • If you could test these changes on an Android device or emulator, then that would be helpful, as I have not tested these changes on Android extensively. So far as I know though they superficially work though. There may be difficulties using the UI on a touch screen though, as it is fairly desktop-oriented at the moment.
  • I haven't tested this on MacOS or Linux, although they should work with it.

Reference Renderings

I have taken the following screenshots to show how the NUI UI appears on my set-up. If the appearance differs from these then there might be a rendering bug that I was not aware of.

ConsoleScreen
MigTestScreen
AndroidConsoleScreen
AndroidMigTestScreen

Notes

  • As with Terasology, NUI operates independantly of the entity-system.
  • The only UI screens that have been ported so-far are the console UI, which I moved from Terasology, and the MigTestScreen, as it's a very good test of how the widgets render.
  • This relates to Moved NUI into a separate library Terasology#4017 (which removes the shared NUI code from Terasology) but does not depend on it.
  • The extracted NUI code used here is almost entirely the same as in Added NUI code extracted from Terasology (relates to Terasology#3819) TeraNUI#2 but contains a couple of small commits on-top to make it compatible with gestalt 7 (changes here). The branch was re-based on-top of the main nui-extraction-merge before submitting this pull request.

Known Issues

Minor Issues

  • The console UI does not properly scroll at the moment. This is due to the output history buffer being too short.
  • The console UI wraps text too early. I think this is due to the console implementation, rather than NUI itself, as it does not seem affected by UI scale.
  • The UI does not always scale to very small screens. The layout will sometimes be horizontally truncated. This is most prominent when testing the UI under very small resolutions, or on Android.

Major issues

  • Currently this pull request depends on the use of the mavenLocal repository, as the NUI library needs to be built from source for now.
  • The code is not very well documented yet. I will add some JavaDoc to the new classes/methods soon.
  • The NUI reflection work-around in gradle includes javax.servlet into the build, which should not be a compile-time dependency, however it was needed to get the code to work.
  • The textures in the engine/src/main/resources/org/destinationsol/assets/textures/ui/nui/terasology folder are taken directly from Terasology, when Destination Sol equivalents should be used instead. The UI theme should be consistent, although most of the UI graphics there are unused at the moment.

Removed overlays from NUIManager, as they served the same purpose and ui screens. Pressing the Esc key should now close NUI screens.
The files generally relate to UI file formats, which are re-used for compatibility reasons.
The UI size can now be different to the screen resolution, which is often helpful when running a very high native resolutions. The setting can be found in the Options->Resolution menu from the main menu.
@Cervator
Copy link
Member

Thank you once more for being our friendly neighborhood code Santa showing up bearing wondrous gifts at random times. While this is the first comment on the PR there have been a bunch on Discord already, not sure if you see those but there have been a lot of banter about how amazing all this is 😁

There is now a TeraNUI build in Jenkins http://jenkins.terasology.io/teraorg/job/Libraries/job/TeraNUI/ and available at 1.0.0-SNAPSHOT in Artifactory, going with MovingBlocks/Terasology#4017

I added some commits that reworked the Gradle in TeraNUI and hooked up a Jenkinsfile. You up for adding another PR with the three commits you've got on top, bumping the version there to 2.0.0-SNAPSHOT ? I figure we can keep the two version lines active - 1.x for TS, 2.x for DS (since newer Gestalt requirement - TS isn't ready for that yet). Soon as we merge a 2.0.0-SNAPSHOT we could use that with this PR.

I haven't personally tested this one although it sounds like a few of the others are. I did manage to fully test the setup for TS though, and this looks equally superb - your PR details are at a whole other level, as usual 👍

@BenjaminAmos
Copy link
Contributor Author

I've updated my nui-extraction-gestalt7 branch to use the version 2.0.0-SNAPSHOT now (in MovingBlocks/TeraNUI#4), so the latest commits changed the version number used here. If anyone had previously tested this then you might have to pull the latest changes from my branch and run gradlew publishToMavenLocal in the TeraNUI repository again to get the updated version. Nothing should have changed apart from the NUI version number.

@NicholasBatesNZ NicholasBatesNZ self-assigned this Jul 30, 2020
@Cervator
Copy link
Member

Cervator commented Aug 2, 2020

FYI for testing this PR: the TEraNUI 2.0.0-SNAPSHOT binary is now available for testing in Artifactory.

Copy link
Member

@NicholasBatesNZ NicholasBatesNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much Santa! 🎅 😄
This is excellent stuff! I'm happy to merge this very soon and we can iron out the kinks later

Also: NUI v2.0.0 is available in artifactory now

EDIT: I'm actually having a little trouble building for Android. Something about JOML not being able to be processed

* A Gson Adapter factory for supporting enums in a case-insensitive manner
* NOTE: Taken from Terasology for compatibility with NUI JSON files.
*/
public class CaseInsensitiveEnumTypeAdapterFactory implements TypeAdapterFactory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've generally put the utility stuff stolen from Terasology in the util package

engine/build.gradle Outdated Show resolved Hide resolved
Copy link
Member

@Adrijaned Adrijaned left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time has come to finally merge this thing, for if we don't now, I reckon we might not at all in the near future! (We are terrible at forcing ourselves to actually do things 😅 )

@Adrijaned Adrijaned merged commit cd7ca90 into MovingBlocks:develop Nov 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants