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

Partially adapted MainGameScreen to use NUI #588

Merged
merged 22 commits into from
Sep 26, 2021

Conversation

BenjaminAmos
Copy link
Contributor

@BenjaminAmos BenjaminAmos commented Mar 3, 2021

Description

This pull request mostly serves as an example of how to port existing UI screens to use NUI. It partially ports one of the more significant in-game UI screens, the MainGameScreen. This screen was responsible for rendering the in-game HUD, warn-drawers and overlays. This pull request also includes a port of the ShipKbControl screen in its entirety, which is used for the touchscreen controls.

The following elements of the HUD have been ported to use NUI:

  • Side-menu Options
  • Touchscreen Controls

The following elements are still using the pre-existing UI system:

  • Player status bars (heath, shields, bullets remaining etc.)
  • Warn drawers (messages that show things like "Enemy Nearby")
  • Overlay screens (these use the pre-existing system, so they by-nature cannot be ported directly to NUI)

The code here mostly works, however some features are broken due to existing issues in NUI's LibGDX input back-end. Some of these issues could be resolved by porting MovingBlocks/TeraNUI#24 to NUI 2.0 but others will require the org.terasology.nui.backends.libgdx.NUIInputProcessor class to be re-written.

Testing

  • Run the game and either start a new game or continue an existing one

Keyboard+Mouse controls

Menu button

  • Click on the Menu button and the pause menu should be shown
  • Close the pause menu with the escape key

Map button

  • Click on the Map button and the map screen should be shown
  • Close the map screen with the escape key

Items button

  • Click on the Items button and a list of the player's current inventory items should be shown
  • Close the items screen

Talk button

  • Approach a station, if not already near one
  • Click on the Talk button and the talk screen should be shown
  • Close the talk screen

Mercs button

  • Click on the Mercs button and the mercenaries screen should be shown

Tutorial

  • Exit to the main menu and follow the tutorial

Keyboard controls

Changing key bindings

  • Due to the previously-mentioned input issues, to test this fully you might have to change the key bindings for certain actions. Both the space and tab keys appear to be fairly unreliable at the moment.
  • Run the game and enter the Options->Controls menu
  • Change the Map key to Q
  • Change the Shoot key to Left-Alt

Menu button

  • Press the escape key and the pause menu should be shown
  • Close the pause menu using the Resume button

Map button

  • Press the Q key and the map screen should be shown [this isn't currently working]
  • Close the map screen with the escape key

Items button

  • Press the i key and the items screen should be shown
  • Close the items screen

Talk button

  • Approach a station, if not already near one
  • Press the t key and the talk screen should be shown
  • Close the talk screen

Mercs button

  • Press the m key and the mercenaries screen should be shown

Tutorial

  • Exit to the main menu and follow the tutorial

Touchscreen controls

  • This may work with the emulateMobile setting set to true in debugOptions.ini but I have primarily tested this on Android

Left button

  • Hold down the Left button and the ship should turn left

Right button

  • Hold down the Right button and the ship should turn right

Forward button

  • Hold down the Fwd button and the ship should fly forwards

Gun 1 button

  • Hold down the Gun 1 button and the left gun should fire

Gun 2 button

  • Hold down the Gun 2 button and the right gun should fire

Ability button

  • Tap the Ability button and the player ship's ability should activate

Tutorial

  • Exit to the main menu and follow the tutorial. The relevant control buttons should flash when referenced.

Outstanding Work

  • Fix remaining input issues
  • Test these changes with a variety of screen resolutions
  • Stability testing, especially with the tutorial

Notes

Visual Changes

Some comparisons of the UI before and after these changes. The desktop screenshots are using a window resolution of 1024x768. The "Research" button is part of the warp module and so is not modified by these changes.

Desktop

Before

DesktopBeforeScreenshot

After

DesktopAfterScreenshot

Android

Before

AndroidBeforeUIScreenShot

After

DestSolAndroidAfterNUIUI

@Cervator
Copy link
Member

Cervator commented Sep 3, 2021

NUI conversion

…atedButton to activate buttons on a given key press. Fixed tutorial.
The controls are now accessed directly from the ShipUIControl interface instead.
Also added some extra JavaDoc to the code.
The ideal solution with NUI would be to scale the widgets with a RelativeLayout or similar widget but for now this works. Multi-touch support requires additional NUI changes that will need to be merged separately.
The "NUI UI Scale" option is now also shown on Android.
Copy link
Member

@Cervator Cervator left a comment

Choose a reason for hiding this comment

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

Have tested this fairly thoroughly - very nice job, as usual!

Looked over the code, no particular comments there other than realizing that I guess we don't have a newer NUI release available, just snapshots

After chat on Discord I know these two be pre-existing issues:

  • Mouse clicking on the in-game right side menu seems to have input consumption quirks - screens may open then immediately re-close and/or I can provoke that behavior deeper in screens if I leave a "bad click" live - just once then everything is fine
  • ESC closes the main menu and exits the game. Huh. That seems kinda severe
  • The "Shoot" binding doesn't show up if you are in mouse/keyboard mode. I figure it might be better if we do show them but keep them locked/disabled if we want to highlight that they're not changeable for the current mode
  • Zoom in/out still seems broken on the map, I know this has come up a few times but I guess we still don't have a bug report issue or a fix yet 😅

Specific to this PR (and related to subset PR #605)

  • The SolButtonsTestScreen.java may only exist in the other PR although in theory this PR covers both?
  • Rebinding controls seem to break input in-game. Gets better in some cases after restarting, but there's something off (actively being looked at as I write this yay!) - this does seem to work in develop

Overall even without the controls rebinding working I'm happy to merge this whenever, that sounds like an easy separate fix and this PR is plenty big as is. I figure high odds it isn't an architectural-level problem and an easy thing to resolve later.

Awesome!

@@ -27,7 +27,7 @@ allprojects {
appName = 'DestinationSol'
gdxVersion = '1.9.8'
roboVMVersion = '2.3.3'
nuiVersion = '3.0.0-SNAPSHOT'
nuiVersion = '3.1.0-SNAPSHOT'
Copy link
Member

Choose a reason for hiding this comment

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

I guess this is still accurate? I don't see a v3.1 release yet. Thought maybe we had gone past that by now.

@Cervator Cervator mentioned this pull request Sep 26, 2021
3 tasks
@Cervator
Copy link
Member

Can confirm the rebinding fix and have made issues for my other comments to remember - merging! :-)

@Cervator Cervator merged commit 6feafc8 into MovingBlocks:develop Sep 26, 2021
@BenjaminAmos BenjaminAmos deleted the nui-main-game-screen branch February 12, 2022 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants