how to show dialogue without a scene?

Anything libgdx related goes here!

how to show dialogue without a scene?

Postby TruePlayer » Tue Aug 13, 2019 2:13 am

I use my own MVC pattern in which scene2d is not involved. No stage and actors. There is only a world (not from badlogicgames, my own world). Can I show custom dialogs from libGDX?
in all examples that I saw is used scene:
Code: Select all
Skin uiSkin = new Skin(Gdx.files.internal("default_skin/uiskin.json"));
Dialog dialog = new Dialog("Warning", uiSkin, "dialog") {
    public void result(Object obj) {
        System.out.println("result "+obj);
    }
};
dialog.text("Are you sure you want to yada yada?");
dialog.button("Yes", true); //sends "true" as the result
dialog.button("No", false); //sends "false" as the result
dialog.show(stage);

should I make my world an actor and add it to the stage? or can I do it differently?
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: how to show dialogue without a scene?

Postby shatterblast » Tue Aug 13, 2019 6:24 am

Technically, Dialog is still part of Scene2D, and all its visual stuff inherits from Actor. I think you can get close to an MVC pattern, though I personally am not aware of how to in "core".
https://libgdx.badlogicgames.com/ci/nig ... ialog.html

The following is a condensed and "simplified" code snippet that can go into render(). It won't have everything, but it should cover most of the basics. The same stuff should roughly apply to Dialog. Take out Table or whatever as works for you.

Code: Select all
        //Loads only once in render().  SpriteBatch will need declaring in create().       
        if ( firstLoad == true) {

            setBattleOrthoCamera( new OrthographicCamera() );
            setBattleExtendViewport( new ExtendViewport( 800, 480, getBattleOrthoCamera() ) );

            setBattlePauseWindowStage()( new Stage(  getBattleExtendViewport(), getBackgroundAnimations_SpriteBatch() ) );

            getBattleExtendViewport().apply();

            setInputMultiplexer( new InputMultiplexer() );
            Gdx.input.setInputProcessor( getInputMultiplexer() );
            getInputMultiplexer().addProcessor( getBattleMainStage() );

            int pauseWindow_Width = 350;
            int pauseWindow_Height = 320;

            float pauseWindow_X_Position = (( getBattleExtendViewport().getWorldWidth() - pauseWindow_Width) / 2);
            float pauseWindow_Y_Position = (( getBattleExtendViewport().getWorldHeight() - pauseWindow_Height) / 2);

            pauseWindow = new Window( "Sound Test", skin );
            pauseWindow.setSize( pauseWindow_Width, pauseWindow_Height );
            pauseWindow.setModal( false );
            pauseWindow.setMovable( false );
            pauseWindow.setPosition( pauseWindow_X_Position, pauseWindow_Y_Position );
            pauseWindow.getTitleLabel().setAlignment( Align.center );

           
            narratorTest_TextButton = new TextButton( "Wes Lange's Voice Test", skin );
            narratorTest_Container = new Container( narratorTest_TextButton );

            narratorTest_TextButton.addListener(new ClickListener() {

            @Override
            public void clicked( InputEvent event, float x, float y ) {

                    narratorTest_TextButton.setDisabled( true );
                    narratorTest_TextButton.setTouchable( Touchable.disabled );
                    narratorTest_Container.addAction( Actions.fadeOut( 2f ) );
                    songStructure.play_Test();

                }

            });

            pauseWindow.add( pauseContent_Table = new Table( skin ) ).expand().fillX().fillY();
            pauseContent_Table.align( Align.center );
            pauseContent_Table.add( narratorTest_Container );

            getBattlePauseWindowStage().addActor( pauseWindow );

            firstLoad = false;       

        }


        //Back to the normal area of render() that loops each time.
        getBattlePauseWindowStage().act();
        getBattlePauseWindowStage().draw();


(Edit: Corrected the Stage code.)
shatterblast
 
Posts: 414
Joined: Sun Jul 06, 2014 1:14 pm


Return to Libgdx

Who is online

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