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

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Stage. These examples are extracted from open source projects. 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
@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 2
@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 3
Source Project: dice-heroes   Source File: SoundManager.java    License: 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 4
Source Project: uracer-kotd   Source File: Dialog.java    License: 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 5
Source Project: dice-heroes   Source File: SoundManager.java    License: 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 6
Source Project: skin-composer   Source File: InfoTable.java    License: 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 7
Source Project: skin-composer   Source File: DialogSceneComposerJavaBuilder.java    License: 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 8
Source Project: gdx-soundboard   Source File: AddStateDialog.java    License: 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 9
@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 10
Source Project: Cardshifter   Source File: UsersList.java    License: 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 Project: skin-composer   Source File: DialogFactory.java    License: 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 Project: Entitas-Java   Source File: GameSceneState.java    License: 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
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 14
Source Project: riiablo   Source File: ProfilerSystem.java    License: 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 15
Source Project: Entitas-Java   Source File: MenuState.java    License: 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 16
Source Project: Cubes   Source File: CreativeInventoryActor.java    License: MIT License 5 votes vote down vote up
@Override
protected void setStage(Stage stage) {
  Stage old = getStage();
  if (old != null) old.setScrollFocus(Cubes.getClient().renderer.guiRenderer.hotbar);
  super.setStage(stage);
  if (stage != null) stage.setScrollFocus(scrollPane);
}
 
Example 17
Source Project: gdx-ai   Source File: BehaviorTreeTests.java    License: Apache License 2.0 5 votes vote down vote up
public MainScreen() {
	Gdx.gl.glClearColor(.3f, .3f, .3f, 1);

	skin = new Skin(Gdx.files.internal("data/uiskin.json"));

	stage = new Stage(new ScreenViewport());
	stage.setDebugAll(DEBUG_STAGE);

	// Create split pane
	List<String> testList = createTestList();
	ScrollPane leftScrollPane = new ScrollPane(testList, skin);
	splitPane = new SplitPane(leftScrollPane, null, false, skin, "default-horizontal");
	splitPane.setSplitAmount(Math.min((testList.getPrefWidth() + 10) / stage.getWidth(), splitPane.getSplitAmount()));

	// Create layout
	Table t = new Table(skin);
	t.setFillParent(true);
	t.add(splitPane).colspan(3).grow();
	t.row();
	t.add(pauseButton = new PauseButton(skin)).width(90).left();
	t.add(new FpsLabel("FPS: ", skin)).left();
	t.add(testDescriptionLabel = new Label("", skin)).left();
	stage.addActor(t);

	// Set selected test
	changeTest(0);
}
 
Example 18
Source Project: RuinsOfRevenge   Source File: ScreenPause.java    License: MIT License 5 votes vote down vote up
public ScreenPause(final ResourceLoader resources, final RuinsOfRevenge game) {
	super(new Stage(), game);
	this.resources = resources;
	this.game = game;

	skin = resources.getSkin("uiskin");

	TextButton play = new TextButton("Continue Playing", skin);
	TextButton settings = new TextButton("Settings", skin);
	TextButton backToMM = new TextButton("Back to Main Menu", skin);

	play.addListener(continueListener);
	settings.addListener(settingsListener);
	backToMM.addListener(backToMMListener);

	table = new Table(skin);
	table.add(play).size(320, 64).space(8);
	table.row();
	table.add(settings).size(320, 64).space(8);
	table.row();
	table.add(backToMM).size(320, 64).space(8);
	table.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
	stage.addActor(table);
	stage.addListener(new KeyUpListener() {
		@Override
		public boolean keyUp(InputEvent event, int keycode) {
			if (keycode == Config.get().key("escape"))
				game.popScreen();
			return false;
		}
	});
}
 
Example 19
Source Project: xibalba   Source File: LoadingScreen.java    License: MIT License 5 votes vote down vote up
/**
 * Loading screen.
 *
 * @param main Instance of Main
 */
public LoadingScreen(Main main) {
  this.main = main;

  stage = new Stage(new FitViewport(960, 540));

  Table table = new Table();
  table.setFillParent(true);
  stage.addActor(table);

  label = new Label("", Main.skin);
  table.add(label);

  new Thread(() -> Gdx.app.postRunnable(this::loadAssets)).start();
}
 
Example 20
Source Project: ninja-rabbit   Source File: StatusBar.java    License: GNU General Public License v2.0 5 votes vote down vote up
public StatusBar(final Batch batch, final AssetManager assets) {
	overlay = new Stage(new ScreenViewport(), batch);

	Label.LabelStyle style = new Label.LabelStyle();
	style.fontColor = Color.WHITE;
	style.font = assets.get(Assets.HUD_FONT);
	style.font.setFixedWidthGlyphs(NUMBER_GLYPHS);

	collectiblesLabel = new Label(String.format(TWO_DIGITS, 0), style);
	livesLabel = new Label(String.format(TWO_DIGITS, 0), style);
	scoreLabel = new Label(String.format(EIGHT_DIGITS, 0), style);
	timeLabel = new Label(String.format(THREE_DIGITS, 0), style);

	TextureAtlas hudAtlas = assets.get(Assets.NINJA_RABBIT_ATLAS);

	Table table = new Table();
	table.add(new Image(hudAtlas.findRegion(SMALL_CARROT_REGION))).padRight(8.0f);
	table.add(collectiblesLabel).bottom();
	table.add(new Image(hudAtlas.findRegion(LIVES_REGION))).padLeft(15.0f);
	table.add(livesLabel).bottom();
	table.add(scoreLabel).expandX();
	table.add(new Image(hudAtlas.findRegion(TIME_REGION))).padRight(12.0f);
	table.add(timeLabel);
	table.setFillParent(true);
	table.top();
	table.pad(15.0f);

	overlay.addActor(table);
}
 
Example 21
Source Project: dice-heroes   Source File: GdxHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void showStageEvents(final Stage stage) {
    EventListener listener = new EventListener() {
        private final Vector2 tmp = new Vector2();
        private Actor actor = new Actor() {
            @Override public void draw(Batch batch, float parentAlpha) {
                if (target == null)
                    return;
                batch.end();
                Config.shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
                Config.shapeRenderer.setProjectionMatrix(stage.getCamera().combined);
                Gdx.gl.glLineWidth(6);
                Config.shapeRenderer.setColor(Color.ORANGE);
                Vector2 pos = target.localToStageCoordinates(tmp.set(0, 0));
                float x = pos.x, y = pos.y;
                Vector2 top = target.localToStageCoordinates(tmp.set(target.getWidth(), target.getHeight()));
                float maxX = top.x, maxY = top.y;
                Config.shapeRenderer.rect(x, y, maxX - x, maxY - y);

                Config.shapeRenderer.end();
                batch.begin();
            }
        };

        {
            stage.addActor(actor);
        }

        public Actor target;

        @Override public boolean handle(Event event) {
            target = event.getTarget();
            return false;
        }
    };
    stage.addListener(listener);
}
 
Example 22
Source Project: dice-heroes   Source File: LocImage.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override protected void setStage(Stage stage) {
    if (stage == null && getStage() != null) {
        //unregister
        Config.thesaurus.unregister(this);
    } else if (stage != null && getStage() == null) {
        //register
        Config.thesaurus.register(this, key);
    }
    super.setStage(stage);
}
 
Example 23
Source Project: Norii   Source File: PauseMenuUI.java    License: Apache License 2.0 5 votes vote down vote up
private void initVariables(Camera camera) {
	stage = new Stage(new ScreenViewport(camera));
	menuTable = new Table();
	menuTable.setDebug(false);
	menuTable.setFillParent(true);
	this.setVisible(false);
}
 
Example 24
Source Project: Norii   Source File: PlayerBattleHUD.java    License: Apache License 2.0 5 votes vote down vote up
private void initVariables(Camera camera, Entity[] sortedUnits) {
	statusUIs = new StatusUI[sortedUnits.length];
	actionUIs = new ActionsUI[Player.getInstance().getUnitsSortedByIni().length];
	hpBars = new HPBar[sortedUnits.length];
	stage = new Stage(new ScreenViewport(camera));
	stage.setDebugAll(false);
}
 
Example 25
Source Project: RuinsOfRevenge   Source File: ScreenMenu.java    License: 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 26
@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 27
Source Project: gdx-skineditor   Source File: SkinEditorGame.java    License: 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 28
Source Project: Unlucky   Source File: HealthBar.java    License: 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 29
Source Project: Unlucky   Source File: UI.java    License: 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();
}
 
Example 30
Source Project: Unlucky   Source File: UI.java    License: 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();
}