com.badlogic.gdx.scenes.scene2d.Stage Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Stage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InfoTable.java    From skin-composer with MIT License 6 votes vote down vote up
public InfoTable(final Skin skin, final Stage stage) {
    pad(10.0f);
    
    var label = new Label(Core.readAndReplace("about.txt"), skin, "small");
    label.setWrap(true);
    label.setTouchable(Touchable.disabled);
    add(label).growX().expandY().top();
    
    row();
    var textButton = new TextButton("OK", skin);
    add(textButton).growX().height(30.0f);
    textButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Core.transition(InfoTable.this, new MenuTable(skin, stage));
        }
    });
}
 
Example #2
Source File: DialogSceneComposerJavaBuilder.java    From skin-composer with MIT License 6 votes vote down vote up
public static String generateJavaFile() {
    nodeClassName = ClassName.get(rootActor.packageString + "." + rootActor.classString, "BasicNode");
    
    TypeSpec.Builder typeSpec = TypeSpec.classBuilder(rootActor.classString)
            .addModifiers(Modifier.PUBLIC)
            .superclass(ApplicationAdapter.class)
            .addField(Skin.class, "skin", javax.lang.model.element.Modifier.PRIVATE)
            .addField(Stage.class, "stage", Modifier.PRIVATE)
            .addMethod(createMethod())
            .addMethod(renderMethod())
            .addMethod(resizeMethod())
            .addMethod(disposeMethod());
    
    if (rootActor.hasChildOfTypeRecursive(SimTree.class)) {
        typeSpec.addType(basicNodeType());
    }

    JavaFile javaFile = JavaFile.builder(rootActor.packageString, typeSpec.build())
            .indent("    ")
            .build();
    
    return javaFile.toString();
}
 
Example #3
Source File: ProfilerSystem.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
protected void initialize() {
  camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  camera.setToOrtho(false);
  camera.update();
  renderer = new ShapeRenderer();
  stage = new Stage();
  stage.getBatch().setProjectionMatrix(camera.combined);
  skin = new Skin(Gdx.files.internal("profiler/uiskin.json"));

  // setup some static config like colors etc
  SystemProfilerGUI.GRAPH_H_LINE.set(Color.ORANGE);
  gui = new SystemProfilerGUI(skin, "default");
  gui.setResizeBorder(8);
  gui.show(stage);
  world.inject(gui, true);
  gui.initialize();
}
 
Example #4
Source File: AddStateDialog.java    From gdx-soundboard with MIT License 6 votes vote down vote up
public AddStateDialog(final Stage stage, final Skin skin, final MusicEventManager eventManager) {

        super("Add State", skin);
        this.stage = stage;
        this.skin = skin;
        this.eventManager = eventManager;


        Table content = this.getContentTable();
        Label label = new Label("State name", skin);
        label.setAlignment(Align.left);
        content.add(label).left().fillX().expandX().row();

        eventName = new TextField("", skin);
        content.add(eventName).right().fillX().expandX().row();

        Table buttons = this.getButtonTable();
        buttons.defaults().fillX().expandX();
        
        this.button("Ok", true);
        this.button("Cancel", false);
        

        key(Keys.ENTER, true);
        key(Keys.ESCAPE, false);
    }
 
Example #5
Source File: CreateResolutionDialog.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void ok() {

	final Stage stage = getStage();

	Message.showMsg(stage, "Creating resolution...", true);

	Timer.schedule(new Task() {
		@Override
		public void run() {
			createResolution();

			String msg = scaleImages();

			if (listener != null)
				listener.changed(new ChangeEvent(), CreateResolutionDialog.this);

			Message.hideMsg();

			if (msg != null)
				Message.showMsgDialog(stage, "Error creating resolution", msg);
		}
	}, 1);
}
 
Example #6
Source File: CreateProjectDialog.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void ok() {
	try {
		Ctx.project.getEditorConfig().setProperty(ANDROID_SDK_PROP, androidSdk.getText());
		Ctx.project.saveProject();
	} catch (Exception ex) {
		String msg = ex.getClass().getSimpleName()
				+ " - " + ex.getMessage();
		Message.showMsgDialog(getStage(), "Error saving project", msg);
	}
	
	final Stage stage = getStage();

	Message.showMsg(getStage(), "Creating project...", true);
	Timer.schedule(new Task() {
		@Override
		public void run() {
			createProject(stage);
		}
	},1);
}
 
Example #7
Source File: RestrictOpenWindows.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public void start(Callback callback) {
    Stage stage = resources.get("stage");
    WindowListener listener;
    listener = resources.getIfExists("restrictOpenWindowsListener");
    if (listener != null) {
        stage.removeCaptureListener(listener);
        resources.remove("restrictOpenWindowsListener");
    }
    listener = new WindowListener() {
        @Override protected void show(WindowEvent event) {
            event.cancel();
        }
    };
    stage.addCaptureListener(listener);
    resources.put("restrictOpenWindowsListener", listener);
    callback.taskEnded();
}
 
Example #8
Source File: FilteredSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public void hide() {
	if (!list.isTouchable() || !hasParent())
		return;
	list.setTouchable(Touchable.disabled);

	Stage stage = getStage();
	if (stage != null) {
		stage.removeCaptureListener(hideListener);
		if (previousScrollFocus != null && previousScrollFocus.getStage() == null)
			previousScrollFocus = null;
		Actor actor = stage.getScrollFocus();
		if (actor == null || isAscendantOf(actor))
			stage.setScrollFocus(previousScrollFocus);
	}

	clearActions();
	selectBox.onHide(this);
	filterField.remove();
}
 
Example #9
Source File: SoundManager.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
public void stopMusicBeautifully(String name, Stage stage) {
    final Music music = musics.get(name);
    if (music == null) {
        Logger.error("there is no music for " + name);
        return;
    }
    final float initialVolume = music.getVolume();
    Action action = new TemporalAction(2f, Interpolation.linear) {
        @Override protected void update(float percent) {
            music.setVolume(initialVolume - percent * initialVolume);
        }

        @Override protected void end() {
            music.stop();
            playingMusics.remove(music);
            disabledMusics.remove(music);
        }
    };
    stage.addAction(action);
    replaceAction(music, action);
}
 
Example #10
Source File: UsersList.java    From Cardshifter with Apache License 2.0 6 votes vote down vote up
public void inviteSelected(String[] availableMods, Stage stage, final CardshifterClient client) {
    if (selected == null) {
        return;
    }

    Dialog dialog = new Dialog("Invite " + selected.getName(), skin) {
        @Override
        protected void result(Object object) {
        	if (object != null) {
                client.send(new StartGameRequest(selected.getId(), (String) object));
                callback.callback((String) object);
        	}
        }
    };
    dialog.text("Which mod do you want to play?");
    for (String mod : availableMods) {
        dialog.button(mod, mod);
    }
    dialog.button("Cancel");
    dialog.show(stage);
}
 
Example #11
Source File: DialogFactory.java    From skin-composer with MIT License 6 votes vote down vote up
public void showDeleteStyleDialog(Skin skin, Stage stage) {
    StyleData styleData = main.getRootTable().getSelectedStyle();

    Dialog dialog = new Dialog("Delete Style", skin, "bg") {
        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new DeleteStyleUndoable(styleData, main), true);
            }
        }
    };
    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("Are you sure you want to delete style " + styleData.name + "?");
    dialog.getContentTable().getCells().first().pad(10.0f);

    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("Yes, delete the style", true).button("No", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());

    dialog.key(Input.Keys.ENTER, true).key(Input.Keys.ESCAPE, false);

    dialog.show(stage);
}
 
Example #12
Source File: GameSceneState.java    From Entitas-Java with MIT License 6 votes vote down vote up
@Override
public void loadResources() {
    this.skinManager = engine.getManager(SMGUIManager.class);
    this.assetsManager = engine.getManager(BaseAssetsManager.class);
    guiFactory = new GuiFactory(assetsManager, skin);
    bodyBuilder =  new BodyBuilder();
    this.stage = new Stage();
    stage.clear();
    stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
    Gdx.input.setInputProcessor(stage);
    Gdx.app.log("Menu", "LoadResources");

    assetsManager.loadTextureAtlas(SPRITE_ATLAS);
    assetsManager.finishLoading();

}
 
Example #13
Source File: Dialog.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
/** {@link #pack() Packs} the dialog and adds it to the stage, centered. */
public Dialog show (Stage stage) {
	clearActions();
	removeCaptureListener(ignoreTouchDown);

	previousKeyboardFocus = null;
	Actor actor = stage.getKeyboardFocus();
	if (actor != null && !actor.isDescendantOf(this)) previousKeyboardFocus = actor;

	previousScrollFocus = null;
	actor = stage.getScrollFocus();
	if (actor != null && !actor.isDescendantOf(this)) previousScrollFocus = actor;

	// pack();
	setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2));
	stage.addActor(this);
	stage.setKeyboardFocus(this);
	stage.setScrollFocus(this);
	if (fadeDuration > 0) {
		getColor().a = 0;
		addAction(Actions.fadeIn(fadeDuration, Interpolation.fade));
	}
	return this;
}
 
Example #14
Source File: SoundManager.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
public void playMusicBeautifully(String name, Stage stage) {
    final Music music = musics.get(name);
    if (music == null) {
        Logger.error("there is no music for " + name);
        return;
    }
    music.setVolume(0);
    if (!usesMusic) {
        disabledMusics.add(music);
    } else {
        music.play();
    }
    music.setLooping(true);
    playingMusics.add(music);
    Action action = new TemporalAction(5f, Interpolation.linear) {
        @Override protected void update(float percent) {
            music.setVolume(percent * volume);
        }
    };
    stage.addAction(action);
    replaceAction(music, action);
}
 
Example #15
Source File: DialogFactory.java    From skin-composer with MIT License 5 votes vote down vote up
public Dialog yesNoCancelDialog(String title, String text,
        ConfirmationListener listener, DialogListener dialogListener) {
    Dialog dialog = new Dialog(title, main.getSkin(), "bg") {
        @Override
        public Dialog show(Stage stage, Action action) {
            fire(new DialogEvent(DialogEvent.Type.OPEN));
            return super.show(stage, action);
        }
        @Override
        protected void result(Object object) {
            listener.selected((int) object);
            fire(new DialogEvent(DialogEvent.Type.CLOSE));
        }
    };
    
    if (dialogListener != null) {
        dialog.addListener(dialogListener);
    }


    dialog.getTitleTable().getCells().first().padLeft(5.0f);
    Label label = new Label(text, main.getSkin());
    label.setAlignment(Align.center);
    dialog.text(label);
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("Yes", 0);
    dialog.button("No", 1);
    dialog.button("Cancel", 2);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(2).getActor().addListener(main.getHandListener());
    dialog.key(Input.Keys.ESCAPE, 2);
    dialog.key(Keys.ENTER, 0);
    dialog.key(Keys.SPACE, 0);
    dialog.show(main.getStage());
    return dialog;
}
 
Example #16
Source File: PvpPlayState.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override protected void dispose(boolean isStateChange, Stage stage) {
    Config.mobileApi.keepScreenOn(false);
    if (stage != null)
        SoundManager.instance.stopMusicBeautifully("ambient-battle", stage);
    else
        SoundManager.instance.stopMusic("ambient-battle");
    Gdx.app.postRunnable(new Runnable() {
        @Override public void run() {
            Logger.debug("disconnect because disposing");
            session.disconnect(false);
            PvpPlayState.this.stage.dispose();
        }
    });
}
 
Example #17
Source File: HideTutorialMessage.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void start(Callback callback) {
    ShowTutorialMessage.Message message = resources.getIfExists("tutorialMessage");
    if (message == null) {
        callback.taskEnded();
        return;
    }
    resources.remove("tutorialMessage");
    if (immediately) {
        message.remove();
        callback.taskEnded();
        return;
    }

    Stage stage = resources.get("stage");

    if (message.getStage() != stage) {
        message.remove();
        callback.taskEnded();
    }

    message.clearActions();
    message.addAction(Actions.sequence(
        Actions.moveTo(0, message.onTop ? message.child.getPrefHeight() : -message.child.getPrefHeight(), 0.2f),
        Actions.removeActor()
    ));

    callback.taskEnded();
}
 
Example #18
Source File: DirsSuggestionPopup.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
public void showRecentDirectories (Stage stage, Array<FileHandle> recentDirectories, float width) {
	int suggestions = createRecentDirSuggestions(recentDirectories, width);
	if (suggestions == 0) {
		remove();
		return;
	}
	showMenu(stage, pathField);
	setWidth(width);
	layout();
}
 
Example #19
Source File: ScreenError.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
public ScreenError(final ResourceLoader resources, final RuinsOfRevenge game, String message, final Exception e) {
	super(new Stage(), game);
	this.resources = resources;
	this.game = game;

	skin = resources.getSkin("uiskin");

	final Dialog dialog = new Dialog("Error", skin);

	TextButton back = new TextButton("Back", skin);
	TextButton submit = new TextButton("Sumbit", skin);

	back.addListener(backListener);
	submit.addListener(submitListener);

	dialog.getContentTable().pad(8);
	dialog.getButtonTable().pad(8);

	dialog.getContentTable().add(message).space(8);
	dialog.getContentTable().row();
	dialog.getContentTable().add("Details: ").space(8);
	dialog.getContentTable().row();
	if (e != null) {
		Label excText = new Label(ExceptionUtils.stackTraceToString(e), skin);
		ScrollPane pane = new ScrollPane(excText, skin);
		pane.setFadeScrollBars(false);
		pane.setOverscroll(false, true);
		dialog.getContentTable().add(pane).height(100).space(8);
		dialog.getContentTable().row();
	}
	dialog.getButtonTable().add(back).size(160, 32).space(8);
	dialog.getButtonTable().add(submit).size(160, 32).space(8);

	dialog.setKeepWithinStage(true);
	dialog.show(stage);

	dialog.getContentTable().debug();
}
 
Example #20
Source File: ShowTutorialMessage.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void start(Callback callback) {
    Message message = resources.getIfExists("tutorialMessage");
    if (message != null) {
        new Tutorial(resources, Tutorial.tasks().with(new HideTutorialMessage())).start();
    }
    Stage stage = resources.get("stage");
    message = new Message(addTapToContinueText);
    stage.addActor(message);
    resources.put("tutorialMessage", message);
    if (message.getStage() != stage) {
        stage.addActor(message);
    }
    message.setTop(onTop);
    message.label.setKey(locKey);
    if (paramsProvider != null) {
        message.label.setParams(paramsProvider.apply(resources));
    }
    if (onTop) {
        message.setY(message.child.getPrefHeight());
    } else {
        message.setY(-message.child.getPrefHeight());
    }
    message.addAction(Actions.moveTo(
        0, 0, 0.3f
    ));
    callback.taskEnded();
}
 
Example #21
Source File: ScreenMenu.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
public ScreenMenu(final ResourceLoader resources, final RuinsOfRevenge game) {
	super(new Stage(), game);
	this.resources = resources;
	this.game = game;
	this.background = resources.getRegion("background");
	background.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
	this.ruinsOfRevengeText = resources.getRegion("RuinsOfRevenge");

	skin = resources.getSkin("uiskin");

	Image rorLogo = new Image(ruinsOfRevengeText);
	TextButton play = new TextButton("Play", skin);
	TextButton settings = new TextButton("Settings", skin);
	TextButton exit = new TextButton("Exit", skin);

	play.addListener(playListener);
	settings.addListener(settingsListener);
	exit.addListener(exitListener);

	table = new Table(skin);
	table.add(rorLogo).size(600, 200).space(32);
	table.row();
	table.add(play).size(320, 64).space(8);
	table.row();
	table.add(settings).size(320, 64).space(8);
	table.row();
	table.add(exit).size(320, 64).space(8);
	table.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
	stage.addActor(table);
}
 
Example #22
Source File: IntroState.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override protected void dispose(boolean isStateChange, Stage stage) {
    textureImage.dispose();
    textureText.dispose();
    Gdx.app.postRunnable(new Runnable() {
        @Override public void run() {
            IntroState.this.stage.dispose();
        }
    });
}
 
Example #23
Source File: ControllerMenuDialog.java    From gdx-controllerutils with Apache License 2.0 5 votes vote down vote up
@Override
protected void setStage(Stage stage) {
    if (stage == null && getStage() != null && getStage() instanceof ControllerMenuStage) {
        ((ControllerMenuStage) getStage()).removeFocusableActors(buttonsToAdd);
    }

    super.setStage(stage);

    if (stage != null && stage instanceof ControllerMenuStage) {
        ((ControllerMenuStage) stage).addFocusableActors(buttonsToAdd);
    }
}
 
Example #24
Source File: LoadGameResourcesState.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void dispose(boolean isStateChange, Stage stage) {
    texture.dispose();
    Gdx.app.postRunnable(new Runnable() {
        @Override public void run() {
            LoadGameResourcesState.this.stage.dispose();
        }
    });
}
 
Example #25
Source File: UI.java    From Unlucky with MIT License 5 votes vote down vote up
public UI(GameScreen gameScreen, TileMap tileMap, Player player, ResourceManager rm) {
    this.game = gameScreen.getGame();
    this.gameScreen = gameScreen;
    this.tileMap = tileMap;
    this.player = player;
    this.rm = rm;

    viewport = new StretchViewport(Unlucky.V_WIDTH, Unlucky.V_HEIGHT, new OrthographicCamera());
    stage = new Stage(viewport, gameScreen.getBatch());

    shapeRenderer = new ShapeRenderer();
}
 
Example #26
Source File: MenuState.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public void loadResources() {
    assetsManager = engine.getManager(BaseAssetsManager.class);
    this.stage = new Stage();
    mainTable = new Table();
    mainTable.setFillParent(true);
    stage.clear();
    stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
    this.stage.addActor(mainTable);
    Gdx.input.setInputProcessor(stage);
    Gdx.app.log("Menu", "LoadResources");
}
 
Example #27
Source File: HealthBar.java    From Unlucky with MIT License 5 votes vote down vote up
public HealthBar(Entity entity, Stage stage, ShapeRenderer shapeRenderer, int max, int hpBarHeight, Vector2 position, Color color) {
    this.entity = entity;
    this.stage = stage;
    this.shapeRenderer = shapeRenderer;
    this.maxHpBarWidth = max;
    this.hpBarHeight = hpBarHeight;
    this.position = position;
    this.color = color;
}
 
Example #28
Source File: SkinEditorGame.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * Display a dialog with a notice
 */
public void showNotice(String title, String message, Stage stage) {
	Dialog dlg = new Dialog(title, skin);
	dlg.pad(20);
	dlg.getContentTable().add(message).pad(20);
	dlg.button("OK", true);
	dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
	dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
	dlg.show(stage);
}
 
Example #29
Source File: CardDeckApplication.java    From androidsvgdrawable-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void create () {
    manager = new AssetManager();
    manager.load("skin.json", Skin.class);
    manager.load("skin.atlas", TextureAtlas.class);
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);
}
 
Example #30
Source File: UI.java    From Unlucky with MIT License 5 votes vote down vote up
public UI(final Unlucky game, Player player, ResourceManager rm) {
    this.game = game;
    this.player = player;
    this.rm = rm;

    viewport = new StretchViewport(Unlucky.V_WIDTH, Unlucky.V_HEIGHT, new OrthographicCamera());
    stage = new Stage(viewport, game.batch);

    shapeRenderer = new ShapeRenderer();
}