Returning to previous NIfty gui screen

Is there a built in/easy way of returning to the previous shown screen, or would the best course of action be overriding the go to screen method and manually keeping track of screens?

The simplest example I can think of is the activities on android where pressing the back button returns you to the previous activity by default.

Hiya,

er… well, this post is hitting about a day’s length of time…

Yeppers, IDK about overriding the go to screen method, but yeah, that doesn’t sound like normal Nifty stuff.

If you like using new a lot you can probably just add a constructor which stores the last screen loaded (and keeps it from being destroyed by garbage collection) and then add a listener method to call the go to screen method that goes to the stored screen. edit: and unless you set up some kind of tracker to keep things tidy… your memory will go bye-bye

If you like having an appstate to control all of that kind of stuff, You could probably make a Stack< Screen > and just keep adding to that stack for a “history” type object (It will possibly eat memory up in a heartbeat if not handled correctly)

I hope this helps… I’m not too familiar with nifty, so take my advice with a big grain of salt.

Game on,
Charles

Thanks for the input, essentially I wanted to know if something like this was built into nifty its self, I tried injecting it using ASM but I couldn’t get it right :confused:

public class NiftyWrapper {

    private final Nifty nifty;
    private ArrayList<String> screenLists = new ArrayList<>();

    public Nifty getNifty() {
        return nifty;
    }

    public NiftyWrapper(Nifty nifty) {
        this.nifty = nifty;
        if(nifty.getCurrentScreen() != null) {
            screenLists.add(nifty.getCurrentScreen().getScreenId());
        }
    }

    public void closeCurrentScreen() {
        if(screenLists.size() >= 2) {
            nifty.gotoScreen(screenLists.get(screenLists.size() - 2));
            screenLists.remove(screenLists.size() - 1);
        } else {
            nifty.exit();
        }
    }

    public void gotoScreen(final String screen) {
        screenLists.add(screen);
        nifty.gotoScreen(screen);
    }
}