jMonkeyEngine-Contributions / Lemur

Lemur is a jMonkeyEngine-based UI toolkit.
http://jmonkeyengine-contributions.github.io/Lemur/
BSD 3-Clause "New" or "Revised" License
116 stars 32 forks source link

OptionPane don't respond to input when adding a Quad #55

Closed Pesegato closed 5 years ago

Pesegato commented 6 years ago

This code show a button that, when pressed, opens a popup that don't respond to input. To fix it, just comment line guiNode.attachChild(version);

import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.BaseAppState;
import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText;
import com.jme3.font.Rectangle;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.simsilica.lemur.ActionButton;
import com.simsilica.lemur.CallMethodAction;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.Insets3f;
import com.simsilica.lemur.OptionPanelState;
import com.simsilica.lemur.style.BaseStyles;
import org.lwjgl.opengl.Display;

public class HelloJME3 extends SimpleApplication {

    public static void main(String[] args) {
        HelloJME3 app = new HelloJME3();
        app.start(); // start the game
    }

    @Override
    public void simpleInitApp() {
        getStateManager().attachAll(
                new OptionPanelState(),
                new MainMenuAppState1());
        GuiGlobals.initialize(this);
        GuiGlobals globals = GuiGlobals.getInstance();
        BaseStyles.loadGlassStyle();
        globals.getStyles().setDefaultStyle("glass");
        BitmapText version = new BitmapText(guiFont, false);
        version.setBox(new Rectangle(0, 0, Display.getWidth(), 215));
        version.setAlignment(BitmapFont.Align.Right);
        version.setLocalTranslation(0, version.getLineHeight(), 1000);
        version.setText("this is a test for Pspeed. Enjoy!");
        //comment the next line to fix the popup
        guiNode.attachChild(version);

    }

    class MainMenuAppState1 extends BaseAppState {

        private Container mainWindow;

        public MainMenuAppState1() {
        }

        public float getStandardScale() {
            int height = getApplication().getCamera().getHeight();
            return height / 720f;
        }

        protected void showError(String title, String error) {
            getState(OptionPanelState.class).show(title, error);
        }

        @Override
        protected void initialize(Application app) {
            mainWindow = new Container();

            ActionButton play = mainWindow.addChild(new ActionButton(new CallMethodAction("Start new game", this, "newGame")));
            play.setInsets(new Insets3f(10, 10, 10, 10));

            // Calculate a standard scale and position from the app's camera
            // height
            int height = app.getCamera().getHeight();
            Vector3f pref = mainWindow.getPreferredSize().clone();

            float standardScale = getStandardScale();
            pref.multLocal(1.5f * standardScale);

            // With a slight bias toward the top        
            float y = height * 0.6f + pref.y * 0.5f;

            mainWindow.setLocalTranslation(100 * standardScale, y, 0);
            mainWindow.setLocalScale(1.5f * standardScale);
        }

        public void newGame() {
            showError("aa", "bb");
        }

        @Override
        protected void cleanup(Application app) {
        }

        @Override
        protected void onEnable() {
            Node gui = ((SimpleApplication) getApplication()).getGuiNode();
            gui.attachChild(mainWindow);
            GuiGlobals.getInstance().requestFocus(mainWindow);
        }

        @Override
        protected void onDisable() {
            mainWindow.removeFromParent();
        }
    }

}
pspeed42 commented 5 years ago

This was related to the issue that the PickEventSession was hard-coded to cast a ray from z=1000 to z=-1... this, combined with the fact that the OptionPane will dynamically pop itself above any existing things in the GUI node, meant that your z=1000 label made the popup appear above where the picking could happen.

With the above commit, the z range of the pick ray is now determined dynamically based on what's in the GUI node.

If you get a chance to try it and it fixes your issue then please let me know and we can close this issue. Thanks for reporting the problem.

pspeed42 commented 5 years ago

I'm going to go ahead and close this. If it still doesn't work in your case then feel free to reopen.