Hiding and showing windows

Hi,

i have some trouble with multiple windows.

i have main menu window and settings window, lazy loaded so settings window is created only when i click on settings button

when i return from settings to main menu, then anything cannot be clicked. switchind existing windows:
[java]
/**
* Which layout to show.
* @param layout
* @return true if layout was shown, false on fail
*/
public boolean show(Class<?extends Layout> layout) {
// Create layout if not exist
if(!layouts.containsKey(layout)) {
try {
Layout instance = layout.newInstance();
instance.setGuiManager(this);
instance.setScreen(screen);
layouts.put(layout, instance.getLayout());
} catch (Exception ex) {
Main.LOG.log(Level.SEVERE, null, ex);
return false;
}
}
// Hide all layouts and show specified one
for(Map.Entry<Class<?extends Layout>, Window[]> entry : layouts.entrySet()) {
if(layout.equals(entry.getKey())) {
for(Window window : entry.getValue()) {
window.show();
window.setZOrder(1);
}
} else {
for(Window window : entry.getValue()) {
window.hide();
}
}
}
return true;
}
[/java]

i added setZOrder(1) and switching works fine, but without this line, i cannot click on anything on main menu when i return to it from settings.

if i comment window.hide() in that code snippet, settings will be opened and main menu is still visible, then if i click on “back” on settings, so window.show() is called on main menu which is not hidden and settings is not hidden, then i cannot click on main menu. but strange thing is, when i focus settings window, then i can click on anything on mainmenu window. click on mainmenu is executed and when mainmenu gets focus it is unclickable again.

if i edit code hiding part to call cleanup on window manually and remove it from layouts hashmap, so every layout is “one and only”, then this bug does not happen, so im thinking about not hiding windows, but removing them on hide

i can include my project if you want

I just use screen.removeElement on window instead of hide.

In my case, since I don’t keep a reference to the window after that, it also allows the stuff to be GCed.
Maybe in your case it’s better to keep a reference to the window… but I do find it easier and less prone to problems to rebuild the window instead, whenever you need it.

i edited my code to remove element, i can agree with you that i can destroy and recreate windows on demand.
if window is shown as modal
[java]win.showAsModal(false);[/java]
it is needed that it is hidden before removing, so my destroy code is
[java]public void destroy() {
if(null != win) {
win.hide();
win.cleanup();
screen.removeElement(win);
win = null;
}
}
[/java] it is ok? or order of commands should be changed or any command is unnecesary?

thanks ascaria

I haven’t played with those modal windows so no idea of their particularity or special needs.
I don’t use the cleanup method (haven’t checked it :D).
You might not need to specifically set win to null if the object with the destroy method is gotten rid of and is the only object with a reference to win.

Anyway, that should work fine.

Sorry for the delayed response. Just barely recovering from surgery and sort of up and down at the moment.

It’s hard to tell what the problem is without knowing what Layout does, as this isn’t an issue I have heard come up before.

The above code looks like it hides/shows elements blindly whether or not they are on screen. This shouldn’t matter (as far as I remember), but you may want to call isVisible() or do a recursive search to see if the element is part of the scene (screen.getElementById()) before calling hide/show.

And a quick explanation of the difference between hide/hideWithEffect and removeElement/removeChild:

When you call hide or hideWithEffect the geometry is removed from the rendered scene, however the parent/child relationship is still kept by both the element being hidden and the parent of that element.
** Note: When you use Effect.setDestroyOnHide(true) the hideWithEffect call works as if you were calling one of the remove methods.

When you call removeElement/removeChild both the geometry and parent/child relationship is removed.

reproduce of my strange behavior should be easy

tonegodGUI plugin says
Installed version: 0.4.6.1454
Available version: 0.4.6.1464
Date: 2.6.14

gui manager: http://pastebin.com/NczNJM7H
base layout: http://pastebin.com/ywC3K4sY
main menu layout: http://pastebin.com/8NXarQbZ
settings layout: http://pastebin.com/N0i09Yq2

in this setup, switching between mainmenu and settings should do weird things if you comment in guimanager window.setZOrder(1); but even if not commented, then if modal window is shown, hidden, shown… it’s background is on click moved under modal overlay

i changed logic to destroy and recreate windows, so this thread is not longer my issue, but i will be happy if we can identify problem :slight_smile:

@Ascaria said: reproduce of my strange behavior should be easy

tonegodGUI plugin says
Installed version: 0.4.6.1454
Available version: 0.4.6.1464
Date: 2.6.14

gui manager: /* * To change this template, choose Tools | Templates * and open the templa - Pastebin.com
base layout: /* * To change this template, choose Tools | Templates * and open the templa - Pastebin.com
main menu layout: /* * To change this template, choose Tools | Templates * and open the templa - Pastebin.com
settings layout: /* * To change this template, choose Tools | Templates * and open the templa - Pastebin.com

in this setup, switching between mainmenu and settings should do weird things if you comment in guimanager window.setZOrder(1); but even if not commented, then if modal window is shown, hidden, shown… it’s background is on click moved under modal overlay

i changed logic to destroy and recreate windows, so this thread is not longer my issue, but i will be happy if we can identify problem :slight_smile:

Just letting you know, I’ll be looking into this tomorrow morning and see what I can figure out.

thanks :slight_smile:

Ok… I took a quick look through this and all seems to be pretty typical usage aside from using Layout in place of using something like AbtractAppState (which would likely give you more control over presentation).

It’s the what I can’t see here that I think may be the issue. This is a client… which makes me assume there is a server =) Which also makes me assume that events are being triggered by responses from said server. Which makes me have to ask… how are these updates being sent to the gui manager?

Just a simple rundown of:

  1. Message sent from client
  2. Server process request, updates effected data
  3. Server send response to client.
    4 Client… does what with this response? More importantly… what mechanism are you using for notifying the guiManager of the changes when you receive a response from the server?

Oh… one last thing.

While looking at the guiManager, I noticed you initialize the screen if it is null… but I don’t see where you add the screen as a control to the guiNode. Where does this happen?

[java]
final public class ZoneOfUprising extends Application
{
…
@Override
public void initialize()
{
super.initialize();
…
// Gui
guiNode.addControl(guiManager.getScreen());
…
}
[/java]

i attached my sources on scene graph topic, but they are so changed now that they are useless for this topic

these things happening without server connection :slight_smile:

@Ascaria said: [java] final public class ZoneOfUprising extends Application { ... @Override public void initialize() { super.initialize(); ... // Gui guiNode.addControl(guiManager.getScreen()); ... } [/java]

i attached my sources on scene graph topic, but they are so changed now that they are useless for this topic

these things happening without server connection :slight_smile:

And you are running a completely single-threaded application? No executor, no futures or callables?

Oh out of curiosity, why are you not using SimpleApllication?

im rewriting my game from nifty and single player to tonegodgui and multiplayer, for now it is single threaded :slight_smile:

this class ZoneOfUprising is clone of SimpleApplication with removed unused things like flybycam, i like tidiness and i dont want unnecesary things to be there :slight_smile: and also i cannot get over that name “simple” :slight_smile:

1 Like
@Ascaria said: im rewriting my game from nifty and single player to tonegodgui and multiplayer, for now it is single threaded :)

this class ZoneOfUprising is clone of SimpleApplication with removed unused things like flybycam, i like tidiness and i dont want unnecesary things to be there :slight_smile: and also i cannot get over that name “simple” :slight_smile:

flyByCam is just a field. You can effectively remove the actual object just by not using the FlyCamAppState. (Remove it or just don’t include it in the first place.)

So now if we make any changes to SimpleApplication to fix stuff or whatever, you will have to merge those changes into yours… just to avoid having a null field.

@pspeed yea you are right, i can get over it :slight_smile:

@t0neg0d i would like to use effects in near future, but when i call code to open window2 and close window1 in one loop, then they will do effects at once i think… i would like to know, if there is any way that i can showwitheffect window2 immediately after hidewitheffect of window1 is completed… something like jquery do:
[java]
$( “.target” ).hide(500, function() {
$( “.target” ).show(500);
});
[/java]

@Ascaria said: @pspeed yea you are right, i can get over it :)

@t0neg0d i would like to use effects in near future, but when i call code to open window2 and close window1 in one loop, then they will do effects at once i think… i would like to know, if there is any way that i can showwitheffect window2 immediately after hidewitheffect of window1 is completed… something like jquery do:
[java]
$( “.target” ).hide(500, function() {
$( “.target” ).show(500);
});
[/java]

Have a look at EffectQueue. Or you could use the GameTimer class and fire off the event in onComplete.