2828import org .destinationsol .game .ship .SolShip ;
2929import org .destinationsol .ui .SolInputManager ;
3030import org .destinationsol .ui .nui .NUIScreenLayer ;
31- import org .destinationsol .ui .nui .widgets .KeyActivatedButton ;
3231import org .destinationsol .ui .nui .widgets .UIWarnButton ;
33- import org .terasology .gestalt .assets .ResourceUrn ;
3432import org .terasology .input .ButtonState ;
3533import org .terasology .input .Keyboard ;
3634import org .terasology .nui .AbstractWidget ;
37- import org .terasology .nui .BaseInteractionListener ;
38- import org .terasology .nui .Canvas ;
39- import org .terasology .nui .InteractionListener ;
4035import org .terasology .nui .UIWidget ;
41- import org .terasology .nui .asset .UIElement ;
4236import org .terasology .nui .backends .libgdx .GDXInputUtil ;
4337import org .terasology .nui .events .NUIKeyEvent ;
44- import org .terasology .nui .events .NUIMouseClickEvent ;
38+ import org .terasology .nui .events .NUIMouseButtonEvent ;
4539
4640import java .util .List ;
4741
@@ -62,18 +56,6 @@ public class MainGameScreen extends NUIScreenLayer {
6256 @ In
6357 private SolApplication solApplication ;
6458
65- private final InteractionListener interactionListener = new BaseInteractionListener () {
66- @ Override
67- public boolean onMouseClick (NUIMouseClickEvent event ) {
68- NUIScreenLayer topScreen = nuiManager .getTopScreen ();
69- if (topScreen != MainGameScreen .this && !(topScreen instanceof UIShipControlsScreen )) {
70- nuiManager .popScreen ();
71- return true ;
72- }
73- return false ;
74- }
75- };
76-
7759 @ Override
7860 public void initialise () {
7961 consoleScreen = (ConsoleScreen ) nuiManager .createScreen ("engine:console" );
@@ -174,12 +156,6 @@ public void update(float delta) {
174156 }
175157 }
176158
177- @ Override
178- public void onDraw (Canvas canvas ) {
179- canvas .addInteractionRegion (interactionListener );
180- super .onDraw (canvas );
181- }
182-
183159 @ Override
184160 protected boolean escapeCloses () {
185161 return false ;
@@ -210,6 +186,18 @@ public boolean onKeyEvent(NUIKeyEvent event) {
210186 return super .onKeyEvent (event );
211187 }
212188
189+ @ Override
190+ public void onMouseButtonEvent (NUIMouseButtonEvent event ) {
191+ if (event .getState () == ButtonState .UP ) {
192+ NUIScreenLayer topScreen = nuiManager .getTopScreen ();
193+ if (!solApplication .getInputManager ().isMouseOnUi () &&
194+ topScreen != MainGameScreen .this && !(topScreen instanceof UIShipControlsScreen )) {
195+ nuiManager .popScreen ();
196+ event .consume ();
197+ }
198+ }
199+ }
200+
213201 @ Override
214202 public void onRemoved () {
215203 menuButton .unsubscribe (this ::onMenuButtonClicked );
@@ -306,6 +294,8 @@ private void onMercsButtonClicked(UIWidget widget) {
306294 gameScreens .inventoryScreen .setOperations (gameScreens .inventoryScreen .getChooseMercenaryScreen ());
307295 nuiManager .pushScreen (gameScreens .inventoryScreen );
308296 solApplication .getGame ().getHero ().getMercs ().markAllAsSeen ();
297+ } else {
298+ nuiManager .removeScreen (gameScreens .inventoryScreen );
309299 }
310300 }
311301}
0 commit comments