[SOLVED] Buttons unresponsive to input

During initialization, I construct my gui scene. When the state is enabled, I attach my gui scene to the gui view port. The scene updates and displays properly when I do this, but none of the buttons in the scene respond to input, even though all other buttons do.

Here is my code:

@Override
protected void initialize(Application app) {
    
    windowSize = new Vector2f(app.getContext().getSettings().getWidth(),
            app.getContext().getSettings().getHeight());
    
    if (app instanceof SimpleApplication) {
        vp = ((SimpleApplication)app).getGuiViewPort();
    }
    else {
        LOG.log(Level.INFO, "Unable to find the default GUI view port. Must be set manually.");
    }
    
    node.setLocalTranslation(0f, 0f, 20f);
    node.setCullHint(Spatial.CullHint.Never);
    node.setQueueBucket(RenderQueue.Bucket.Gui);
    node.attachChild(createBackgroundBlocker(-10f, new ColorRGBA(0f, 0f, 0f, .7f)));
    node.attachChild(gui);
    initGlobalButtons();
    gui.addChild(varList);
    gui.setLocalTranslation(0f, windowSize.y, 0f);
    varLayout = new BoxLayout();
    varList.setLayout(varLayout);
      
}
@Override
protected void onEnable() {
    openPopup();
    GuiGlobals.getInstance().requestCursorEnabled(this);
    GuiGlobals.getInstance().requestFocus(node);
}
private void openPopup() {
    if (popupOpen) return;
    vp.attachScene(node);
    popupOpen = true;
}
private void initGlobalButtons() {
    Container buttons = gui.addChild(new Container());
    BoxLayout layout = new BoxLayout(Axis.X, FillMode.Even);
    buttons.setLayout(layout);
    Button push = layout.addChild(new Button("Push All"));
    push.addClickCommands(new PushPullCommand(true));
    Button pull = layout.addChild(new Button("Pull All"));
    pull.addClickCommands(new PushPullCommand(false));
}

Is your background blocker maybe sorting on top of your GUI?

Wait! Are you swapping out the whole guiNode?

Lemur has automatically registered to do picking on the existing gui node. If you swap it out then you will have to remove the old registration and add your new one.

…but now I wonder what you are really trying to do because I can’t imagine a use-case where all of this is required.

Why not just use the existing gui node for your gui?

1 Like

No, guiNode is still there.

The gui is a developer tool which is supposed to able to display on top of everything at any time during the program. If the regular gui node is covered up by something (like with split-screen gui) in the game, then the dev can move this gui to another viewport to ensure it remains on top.

Plus, if the dev ever dumps all the existing gui node’s children, I don’t want my gui to get dumped too.

That dev does not deserve your time or consideration. :slight_smile: :slight_smile: :slight_smile: Seriously bad practice, though.

I see. Something more dramatic than the existing PopupState stuff would give you, I guess.

Anyway, if you add new GUI roots then you have to tell Lemur about them or it won’t know to issue picking there.

1 Like

Ok, how do I do that?

Before going down that path; why are you attaching a whole new gui node? Wouldnt it be simpler to attach something to the normal gui node? (And use z ordering to get things on top of one annother)

http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/com/simsilica/lemur/event/BasePickState.html#addCollisionRoot-com.jme3.scene.Spatial-com.jme3.renderer.ViewPort-

…for some reason I do not expose the pick state directly on GuiGlobals so you will have to getState(BasePickState.class) to grab it.

1 Like

If the user creates a post view, the existing gui (and my gui) will be covered up. My gui should always be on top, which is why I allow the user to set the viewport in which the gui is rendered.

That fixed picking for my tool’s gui, but now everything else is not responding to picks.

// in init method
root = new Node("gui-root");
root.setCullHint(Spatial.CullHint.Never);
root.setQueueBucket(RenderQueue.Bucket.Gui);
if (app instanceof SimpleApplication) {
    // vp is null
    setViewPort(((SimpleApplication)app).getGuiViewPort());
}
getState(BasePickState.class).requestEnabled(this);
public void setViewPort(ViewPort vp) {
    assert vp != null;
    BasePickState pick = getState(BasePickState.class, true);
    if (this.vp != null) {
        pick.removeCollisionRoot(root);
        this.vp.detachScene(root);
    }
    this.vp = vp;
    this.vp.attachScene(root);
    pick.addCollisionRoot(root, this.vp, PICK_LAYER);
    pick.setPickLayerOrder(PICK_LAYER, BasePickState.PICK_LAYER_GUI, BasePickState.PICK_LAYER_SCENE);
    for (String s : pick.getPickLayerOrder()) {
        System.out.println(s);
    }
}

From println:

my-pick-layer
gui
scene

I thought maybe my background blocker was eating up all the picks, but the problem did not resolve when I removed it. :thinking:

Edit: I just noticed that other gui does work when the tool’s state is enabled. After the tool’s state is disabled again, the other gui goes back to not working.

@Override
protected void onEnable() {
    // This is how the tool gets displayed. Another state
    // handles the viewport and gui root, and this state
    // simply tags on when it wants to display.
    guiRoot.getGuiRoot().attachChild(scene);
    GuiGlobals.getInstance().requestCursorEnabled(this);
    GuiGlobals.getInstance().requestFocus(scene);
}
@Override
protected void onDisable() {
    scene.removeFromParent();
    GuiGlobals.getInstance().releaseCursorEnabled(this);
    GuiGlobals.getInstance().releaseFocus(scene);
}

Why do you do this:

And then also:

Anyway, I think probably your application’s GUI never requested cursor enabled and so when you release it you are telling Lemur that nothing is using the GUI anymore and the mouse should be turned off.

Hmm, I addressed that, but it didn’t make any difference.

This is what I narrowed it down to:
When the tool scene node (with or without children) is attached to my root gui node, the other gui elements react to the mouse as expected, otherwise they don’t react as expected.

Here are the gui scenes in question:

              gui view port
            __/          \______
           /                     \
  normal gui node               my gui root
        |                            |
        |                            | 
 other gui elements             my gui scene  <--when this is attached, it works
                                     |
                                     |
                            tool buttons & gizmos

There is no reason that I can think of that it shouldn’t work.

It may require some debugging on your part to track down, unfortunately.

I figured out how to dodge the issue. If I give the tool gui its own viewport, the problem “goes away.” Thanks for your help! :hugs:

1 Like