Libgdx Dialog Bug

Anything libgdx related goes here!

Libgdx Dialog Bug

Postby denizen » Mon Mar 11, 2019 9:27 pm

On the world's most advanced Risk Client, implemented using Libgdx, I use modal dialogs that appear over the map screen seen in the image below.

My issue is that when a modal dialog is visible and there are updates performed to the map (via the networking code), the updates that overlap the dialog are drawn on the dialog instead of on the map (which is 2d table based). The dialogs are simple extensions of the libgdx Dialog class.

Could this be considered a bug in libgdx?

Anyone encountered this issue before?

I don't want to programmatically disable the map when a dialog is active and then refresh the screen when the dialog closes.

Image
http://www.denizenseven.com
Libgdx + The Board Game Risk = Grand Strategy.
denizen
 
Posts: 54
Joined: Sun May 20, 2012 6:00 pm

Re: Libgdx Dialog Bug

Postby evilentity » Mon Mar 11, 2019 11:06 pm

All the modal dialog does is fill the screen in capture all input events. If you update your map by adding new actors to the stage they will be on top of the dialog.
Perhaps a screenshot that actually shows the problem could be useful. Unless theres a dialog hiding somewhere in there.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4687
Joined: Wed Aug 24, 2011 11:37 am

Re: Libgdx Dialog Bug

Postby denizen » Tue Mar 12, 2019 4:17 pm

evilentity wrote:All the modal dialog does is fill the screen in capture all input events. If you update your map by adding new actors to the stage they will be on top of the dialog.


Yes, we do update the map by adding and removing actors.

The screenshot is somewhat self explanatory. Just imagine a dialog and the circular army actors that you see in the screenshot above draw on top of the dialog when the map is updated.

I know that dialogs in libgdx are not real windows. But windowing systems in general preserve the graphical integrity of modal dialogs.

That's why I would consider this to be a bug. Or at least a feature request. Potentially, libgdx could be modified to not draw on top of open modal dialogs.
http://www.denizenseven.com
Libgdx + The Board Game Risk = Grand Strategy.
denizen
 
Posts: 54
Joined: Sun May 20, 2012 6:00 pm

Re: Libgdx Dialog Bug

Postby evilentity » Tue Mar 12, 2019 5:25 pm

That would be far from trivial change and can easily be solved in other ways.

All you need to do is ensure what whatever you add is below the dialog in draw order. Which already should be the case, unless you stick everything into root for some reason.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4687
Joined: Wed Aug 24, 2011 11:37 am

Re: Libgdx Dialog Bug

Postby denizen » Thu Mar 14, 2019 12:42 pm

evilentity wrote:All you need to do is ensure what whatever you add is below the dialog in draw order. Which already should be the case, unless you stick everything into root for some reason.


Everything is not stuck into root.

It's just a stage with a table. The constructor for the stage does this on the main table:

this.addActor(tblMain);

The dialogs are members of the stage.

private GameOptionsDialog gameOptionsDialog;

Nothing interesting happens in the stage draw function:

this.getBatch().setColor(Color.WHITE);
this.getBatch().begin();
drawViewBackground();
this.getBatch().end();
super.draw();
http://www.denizenseven.com
Libgdx + The Board Game Risk = Grand Strategy.
denizen
 
Posts: 54
Joined: Sun May 20, 2012 6:00 pm

Re: Libgdx Dialog Bug

Postby denizen » Thu Mar 14, 2019 1:06 pm

denizen wrote:
evilentity wrote:All you need to do is ensure what whatever you add is below the dialog in draw order. Which already should be the case, unless you stick everything into root for some reason.


private GameOptionsDialog gameOptionsDialog;



In the draw method:

if (gameOptionsDialog != null)
this.gameOptionsDialog.setZIndex(this.getRoot().getChildren().size - 1);

Ahh, this seems to fix the problem.
http://www.denizenseven.com
Libgdx + The Board Game Risk = Grand Strategy.
denizen
 
Posts: 54
Joined: Sun May 20, 2012 6:00 pm

Re: Libgdx Dialog Bug

Postby evilentity » Thu Mar 14, 2019 1:14 pm

You are doing something weird if stuff is randomly drawn on top of the dialog.
This works in expected way.
https://github.com/piotr-j/libgdxplaygr ... pTest.java
What are you doing differently?
Looking for a freelancer? PM me!
evilentity
 
Posts: 4687
Joined: Wed Aug 24, 2011 11:37 am

Re: Libgdx Dialog Bug

Postby denizen » Fri Mar 15, 2019 4:44 am

evilentity wrote:You are doing something weird if stuff is randomly drawn on top of the dialog.
This works in expected way.
https://github.com/piotr-j/libgdxplaygr ... pTest.java
What are you doing differently?


Your guiRoot zindex is always greater than gameRoot zindex. So gameRoot images will never draw on top of the guiRoot.

I am adding the children to the root. The new countries are added like this from the stage:

// Remove the old country
this.getRoot().removeActor(country);
// Add the updated country
this.getRoot().addActor(newCountry);

My dialogs are also children of the root.

I found that setting the zindex of the dialogs in the draw method wouldn't work. It curiously prevented SelectBoxes on the dialogs from working.

The problem is resolved by setting the zIndex of the newly adding children to 1.

newCountry.setZIndex(1);

I suppose I could use two tables off of root like your example.
http://www.denizenseven.com
Libgdx + The Board Game Risk = Grand Strategy.
denizen
 
Posts: 54
Joined: Sun May 20, 2012 6:00 pm

Re: Libgdx Dialog Bug

Postby evilentity » Fri Mar 15, 2019 10:21 am

So the mystery is solved.
z index is basically the order in the parent, if you have two roots you dont have to play with it. Changing z index may be slowish if you have a lot of actors as it has to shift all of them if you insert new actor at the start
Looking for a freelancer? PM me!
evilentity
 
Posts: 4687
Joined: Wed Aug 24, 2011 11:37 am


Return to Libgdx

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 1 guest