Same control in different screen (Nifty-Gui + Slick2d)

First of all, my intention is to get a console in a popup persisten through screens. In other words I want to have a console at any time in the game shown by pressing [ESC].



I begin by loading the XML file in the “mainScreen”. At this point I can perfectly use the console, which I toogle(add and close) using the [ESC] key. I have already created a “loginPopup”. When I login to the server and I receive the player information I gotoScreen(“gameScreen”). Now I can toogle the “consolePopup” element stored before and it shows and hides fine, keeping it’s previous state, but it doesn’t get any input from the keyboard.



My guess is that the console gets binded to the “mainScreen” input, and this is no longer receiving any events.

I’ve already tried everything I’ve seen all over the web(bind, layout, setParent…) and nothing did the trick…



I am trying to achieve this the wrong way? I am not experienced with nifty-gui…

  • I also tried using the same screenController in both screens.



    Any help would be sincerely appreciated.



    An extract from the main XML:

    16

    17

    18

    19

    20

    21

    22

    23

    24 <panel childLayout=“absolute” x=“8” y=“10” width=“554” height=“92”

    25 visibleToMouse=“true”>

    26 <control x=“5” y=“0” width=“540” height=“92” id=“gameLog”

    27 name=“listBox” vertical=“optional” horizontal=“optional”

    28 displayItems=“6” wrap=“true” selectionMode=“Disabled” />

    29

    30 <panel childLayout=“absolute” x=“18” y=“108” width=“535”

    31 height=“18”>

    32 <control x=“0” y=“0” width=“535” height=“18” id=“gameConsole”

    33 name=“textfield” text="" />

    34

    35

    36

    73

    74

    75 <panel align=“center” childLayout=“center” valign=“center”

    76 width=“95%”>

    77 <control id=“console” name=“nifty-console” align=“center”

    78 lines=“40” valign=“center”>

    79

    80 <onCustom name=“move” alternateEnable=“show” direction=“top”

    81 inherit=“true” length=“200” mode=“in” startDelay=“0” />

    82

    83 <onCustom name=“move” alternateEnable=“hide” direction=“top”

    84 inherit=“true” length=“200” mode=“out” startDelay=“0” />

    85

    86

    87

    88



    Thank you all very much!!!

Popups and changing screens can get pretty messy in nifty. You may be better off not using popups at all and just add a new layer/panel/whatever. When you change screen if you want it still open you will need to re-add it of course… or if you want it closed you will need to close it.

1 Like

So how can I keep the console state from one screen to another? Because, right now, if I keep it I can’t get the input to work, even though, everything else looks great…



Thanks again @zarch.

Hmm, @void256 might have a suggestion but I don’t think you can do that while using screens.



However if you instead used one screen with different layers representing each “screen” then you could turn on and off those layers and achieve the same effect without disturbing your console layer.

1 Like

I guess that’s possible but I was trying to avoid having the whole game in the same screen.

In order to take this path, is it possible to “not load/show or hide” a layer in a screen when using gotoScreen or fromXml the first time?



Thank you again.

Yes, just put an onStartScreen that hides the layers you don’t want to see.

1 Like

you can’t have popups stay open when you use gotoScreen(). currently popups live in a special layer that is above all other “regular” layers … but still it belongs to the current screen. sorry.

1 Like

@void256 I understand that, is just that as far as I know, the popup is just a “special” layer. And I wanted to someway, attach the old layer to the new screen(current). But, event thought I can see the popup, it just doesn’t get any key events or input…



Thank you.