com.badlogic.gdx.scenes.scene2d.ui.Stack Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Stack. 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: SelectBoxWidget.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public Actor getSubWidget() {
    selectBox = new SelectBox<>(TalosMain.Instance().UIStage().getSkin(), "propertyValue");
    noValueLabel = new Label("", TalosMain.Instance().UIStage().getSkin());
    noValueLabel.setAlignment(Align.right);
    stack = new Stack();
    stack.add(noValueLabel);
    stack.add(selectBox);

    noValueLabel.setVisible(false);

    listener = new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            String newValue = selectBox.getSelected();
            valueChanged(newValue);
        }
    };
    selectBox.addListener(listener);

    return stack;
}
 
Example #2
Source File: Scene2dSteeringTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
@Override
public void create () {
	lastUpdateTime = 0;
	testStack = new Stack();
	container.stage.getRoot().addActorAt(0, testStack);
	testStack.setSize(container.stageWidth, container.stageHeight);
	testStack.add(testTable = new Table() {
		@Override
		public void act (float delta) {
			float time = GdxAI.getTimepiece().getTime();
			if (lastUpdateTime != time) {
				lastUpdateTime = time;
				super.act(GdxAI.getTimepiece().getDeltaTime());
			}
		}
	});
	testStack.layout();
}
 
Example #3
Source File: MessageTestBase.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
public void create () {
	lastUpdateTime = 0;
	testStack = new Stack();
	container.stage.getRoot().addActorAt(0, testStack);
	testStack.setSize(container.stageWidth, container.stageHeight);
	testStack.add(testTable = new Table() {
		@Override
		public void act (float delta) {
			float time = GdxAI.getTimepiece().getTime();
			if (lastUpdateTime != time) {
				lastUpdateTime = time;
				super.act(GdxAI.getTimepiece().getDeltaTime());
			}
		}
	});
	testStack.layout();
}
 
Example #4
Source File: PortraitsUI.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void initializeVariables(Entity[] entities) {
	portraits = new ArrayList<PortraitUI>();
	stacks = new ArrayList<Stack>();
	hgroup = new HorizontalGroup();
	tileWidthPixel = Gdx.graphics.getWidth() / (float) TILE_TO_PIXEL_RATIO;
	tileHeightPixel = Gdx.graphics.getHeight() / (float) TILE_TO_PIXEL_RATIO;

	configureWindow();
	setFadeEffectBackground();
	configureHorizontalGroup();
	createPortraits(entities);
	updatePositionContainer();
}
 
Example #5
Source File: PortraitsUI.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void addStackPortraitBorder(PortraitUI portrait) {
	final Stack stack = new Stack();
	stack.addActor(portrait.getHeroPortrait());
	stack.addActor(portrait.getHeroPortraitBorderColored());
	stack.addActor(portrait.getHeroPortraitBorder());
	stacks.add(stack);

	final float x = portrait.getHeroPortrait().getX();
	final float y = portrait.getHeroPortrait().getY();
	stack.setBounds(x, y, PORTRAIT_WIDTH * tileWidthPixel, PORTRAIT_HEIGHT * tileHeightPixel);
	stack.addListener(new PortraitClickListener(portrait.getLinkedEntity()));
	hgroup.addActor(stack);
}
 
Example #6
Source File: CreatureQueueWindow.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override protected void initialize() {
    creaturesList.defaults().pad(2);
    creaturesList.padTop(12);

    Image left = new Image(Config.skin, "ui-creature-queue-gradient-left");
    left.setScaling(Scaling.stretchY);
    left.setAlign(Align.left);
    left.setTouchable(Touchable.disabled);

    Image right = new Image(Config.skin, "ui-creature-queue-gradient-right");
    right.setScaling(Scaling.stretchY);
    right.setAlign(Align.right);
    right.setTouchable(Touchable.disabled);

    Stack stack = new Stack();
    stack.add(new ScrollPane(creaturesList, new ScrollPane.ScrollPaneStyle()));
    stack.add(left);
    stack.add(right);

    Table content = new Table(Config.skin);
    content.setTouchable(Touchable.enabled);
    content.setBackground("ui-inventory-ability-window-background");
    content.defaults().pad(2);
    content.add(new LocLabel("ui-turns-order")).row();
    content.add(new Image(Config.skin, "ui-creature-info-line")).width(100).row();
    content.add(stack).maxWidth(table.getStage().getWidth() - 45).padRight(4).padLeft(4).row();

    table.add(content);
}
 
Example #7
Source File: InputFileListAdapter.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
protected Stack createView(InputFile item) {
    ViewHolder viewHolder = new ViewHolder(lmlParser.getData().getDefaultSkin(), item);
    lmlParser.createView(viewHolder, Gdx.files.internal("lml/inputFileListItem.lml"));
    viewHolder.root.setUserObject(viewHolder);
    return viewHolder.root;
}
 
Example #8
Source File: InputFileListAdapter.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
    protected void prepareViewBeforeAddingToTable(InputFile item, Stack view) {
        super.prepareViewBeforeAddingToTable(item, view);

//        // Seems like this is the only way to extract adapter's internal click listener
//        ClickListener itemClickListener = (ClickListener) view.getListeners().peek();
//        itemClickListener.setButton(0);
    }
 
Example #9
Source File: BehaviorTreeTests.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
private void changeTest (int testIndex) {
	// Dispose the previous test (if any)
	if (currentTest != null) currentTest.dispose();

	// Add the new test
	currentTest = tests[testIndex];
	Gdx.app.log("BehaviorTreeTests", "***********************************************");
	Gdx.app.log("BehaviorTreeTests", "Starting test " + currentTest.getName());
	Gdx.app.log("BehaviorTreeTests", "***********************************************");
	String description = currentTest.getDescription();
	if (description != null) {
		Gdx.app.log("BehaviorTreeTests", description);
		Gdx.app.log("BehaviorTreeTests", "***********************************************");
		testDescriptionLabel.setText(description);
	} else {
		testDescriptionLabel.setText("Run the tree, look at the log and see what happens");
	}
	Stack testStack = new Stack() {
		@Override
		public void act (float delta) {
			boolean paused = pauseButton.isChecked();
			getChildren().peek().setVisible(paused);
			if (!paused) {
				// Update AI time
				GdxAI.getTimepiece().update(delta);
				
				// Call super
				super.act(delta);
			}
		}
	};
	testStack.add(currentTest.createActor(skin));
	testStack.add(new Image(skin, "translucent"));
	splitPane.setSecondWidget(testStack);
}
 
Example #10
Source File: PathFinderTests.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void create () {
	Gdx.gl.glClearColor(.3f, .3f, .3f, 1);

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

	// Enable color markup
	BitmapFont font = skin.get("default-font", BitmapFont.class);
	font.getData().markupEnabled = true;

	stage = new Stage();
	stage.setDebugAll(DEBUG_STAGE);
	stageWidth = stage.getWidth();
	stageHeight = stage.getHeight();

	Gdx.input.setInputProcessor(new InputMultiplexer(stage));

	Stack stack = new Stack();
	stage.addActor(stack);
	stack.setSize(stageWidth, stageHeight);
	testsTable = new Table();
	stack.add(testsTable);

	// Create behavior selection window
	List<String> testList = createTestList();
	algorithmSelectionWindow = addBehaviorSelectionWindow("Path Finder Tests", testList, 0, -1);

	// Set selected test
	changeTest(0);

	stage.addActor(new FpsLabel("FPS: ", skin));
}
 
Example #11
Source File: TabbedPane.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
private void initialize () {

		setTouchable(Touchable.enabled);
		tabTitleTable = new Table();
		tabBodyStack = new Stack();
		selectedIndex = -1;

		// Create 1st row
		Cell<?> leftCell = add(new Image(style.titleBegin));
		Cell<?> midCell = add(tabTitleTable);
		Cell<?> rightCell = add(new Image(style.titleEnd));
		switch (tabTitleAlign) {
		case Align.left:
			leftCell.width(((Image)leftCell.getActor()).getWidth()).bottom();
			midCell.left();
			rightCell.expandX().fillX().bottom();
			break;
		case Align.right:
			leftCell.expandX().fillX().bottom();
			midCell.right();
			rightCell.width(((Image)rightCell.getActor()).getWidth()).bottom();
			break;
		case Align.center:
			leftCell.expandX().fillX().bottom();
			midCell.center();
			rightCell.expandX().fillX().bottom();
			break;
		default:
			throw new IllegalArgumentException("TabbedPane align must be one of left, center, right");
		}

		// Create 2nd row
		row();
		Table t = new Table();
		t.setBackground(style.bodyBackground);
		t.add(tabBodyStack);
		add(t).colspan(3).expand().fill();
	}
 
Example #12
Source File: InputFileListAdapter.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
@Override
protected void selectView(Stack view) {
    ViewHolder viewHolder = (ViewHolder) view.getUserObject();
    viewHolder.setSelected(true);
}
 
Example #13
Source File: ResumeVsJoinTest.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public TestScreen (final ResumeVsJoinTest test, Skin skin) {
	this.test = test;
	this.skin = skin;
	lastUpdateTime = 0;
	gameOver = false;

	greenFishTextureRegion = new TextureRegion(new Texture("data/green_fish.png"));
	badlogicTextureRegion = new TextureRegion(new Texture("data/badlogicsmall.jpg"));
	targetTextureRegion = new TextureRegion(new Texture("data/target.png"));

	shapeRenderer = new ShapeRenderer();

	stage = new Stage();

	Stack testStack = new Stack();
	stage.addActor(testStack);

	// Add translucent panel (it's only visible when AI is paused)
	final Image translucentPanel = new Image(skin, "translucent");
	translucentPanel.setSize(stage.getWidth(), stage.getHeight());
	translucentPanel.setVisible(false);
	stage.addActor(translucentPanel);

	// Create status bar
	Table statusBar = new Table(skin);
	statusBar.left().bottom();
	statusBar.row().height(26);
	statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left();
	statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15);
	statusBar.add(new IntValueLabel("Resume (Fish): ", 0, skin) {
		@Override
		public int getValue () {
			return resumePredator.score;
		}
	}).padLeft(15);
	statusBar.add(new IntValueLabel("Join (Badlogics): ", 0, skin) {
		@Override
		public int getValue () {
			return joinPredator.score;
		}
	}).padLeft(15);
	stage.addActor(statusBar);

	// Add test table
	testStack.setSize(stage.getWidth(), stage.getHeight());
	testStack.add(testTable = new Table() {
		@Override
		public void act (float delta) {
			float time = GdxAI.getTimepiece().getTime();
			if (lastUpdateTime != time) {
				lastUpdateTime = time;
				super.act(GdxAI.getTimepiece().getDeltaTime());
			}
		}
	});
	testStack.layout();

	this.sheeps = new Array<Sheep>();

	for (int i = 0; i < 30; i++) {
		Sheep sheep = new Sheep(targetTextureRegion);
		sheep.setMaxLinearAcceleration(50);
		sheep.setMaxLinearSpeed(80);
		sheep.setMaxAngularAcceleration(10); // greater than 0 because independent facing is enabled
		sheep.setMaxAngularSpeed(5);

		Wander<Vector2> wanderSB = new Wander<Vector2>(sheep) //
			.setFaceEnabled(true) // We want to use Face internally (independent facing is on)
			.setAlignTolerance(0.001f) // Used by Face
			.setDecelerationRadius(5) // Used by Face
			.setTimeToTarget(0.1f) // Used by Face
			.setWanderOffset(90) //
			.setWanderOrientation(10) //
			.setWanderRadius(40) //
			.setWanderRate(MathUtils.PI2 * 4);
		sheep.setSteeringBehavior(wanderSB);

		setRandomNonOverlappingPosition(sheep, sheeps, 5);
		setRandomOrientation(sheep);

		testTable.addActor(sheep);

		sheeps.add(sheep);
	}

	resumePredator = createPredator(false);
	joinPredator = createPredator(true);

	// Create GameOver panel
	gameOverButton = new TextButton("Game Over", skin);
	gameOverButton.setVisible(false);
	gameOverButton.addListener(new ChangeListener() {
		@Override
		public void changed (ChangeEvent event, Actor actor) {
			test.backToPreviousScreen();
		}
	});
	testTable.add(gameOverButton);
}
 
Example #14
Source File: ParallelVsSequenceTest.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public TestScreen (final ParallelVsSequenceTest test, Skin skin) {
	this.test = test;
	this.skin = skin;
	lastUpdateTime = 0;
	gameOver = false;

	greenFishTextureRegion = new TextureRegion(new Texture("data/green_fish.png"));
	badlogicTextureRegion = new TextureRegion(new Texture("data/badlogicsmall.jpg"));
	targetTextureRegion = new TextureRegion(new Texture("data/target.png"));

	shapeRenderer = new ShapeRenderer();

	stage = new Stage();

	Stack testStack = new Stack();
	stage.addActor(testStack);

	// Add translucent panel (it's only visible when AI is paused)
	final Image translucentPanel = new Image(skin, "translucent");
	translucentPanel.setSize(stage.getWidth(), stage.getHeight());
	translucentPanel.setVisible(false);
	stage.addActor(translucentPanel);

	// Create status bar
	Table statusBar = new Table(skin);
	statusBar.left().bottom();
	statusBar.row().height(26);
	statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left();
	statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15);
	statusBar.add(new IntValueLabel("Sequence (Fish): ", 0, skin) {
		@Override
		public int getValue () {
			return sequencePredator.score;
		}
	}).padLeft(15);
	statusBar.add(new IntValueLabel("Parallel (Badlogics): ", 0, skin) {
		@Override
		public int getValue () {
			return parallelPredator.score;
		}
	}).padLeft(15);
	stage.addActor(statusBar);

	// Add test table
	testStack.setSize(stage.getWidth(), stage.getHeight());
	testStack.add(testTable = new Table() {
		@Override
		public void act (float delta) {
			float time = GdxAI.getTimepiece().getTime();
			if (lastUpdateTime != time) {
				lastUpdateTime = time;
				super.act(GdxAI.getTimepiece().getDeltaTime());
			}
		}
	});
	testStack.layout();

	this.sheeps = new Array<Sheep>();

	for (int i = 0; i < 30; i++) {
		Sheep sheep = new Sheep(targetTextureRegion);
		sheep.setMaxLinearAcceleration(50);
		sheep.setMaxLinearSpeed(80);
		sheep.setMaxAngularAcceleration(10); // greater than 0 because independent facing is enabled
		sheep.setMaxAngularSpeed(5);

		Wander<Vector2> wanderSB = new Wander<Vector2>(sheep) //
			.setFaceEnabled(true) // We want to use Face internally (independent facing is on)
			.setAlignTolerance(0.001f) // Used by Face
			.setDecelerationRadius(5) // Used by Face
			.setTimeToTarget(0.1f) // Used by Face
			.setWanderOffset(90) //
			.setWanderOrientation(10) //
			.setWanderRadius(40) //
			.setWanderRate(MathUtils.PI2 * 4);
		sheep.setSteeringBehavior(wanderSB);

		setRandomNonOverlappingPosition(sheep, sheeps, 5);
		setRandomOrientation(sheep);

		testTable.addActor(sheep);

		sheeps.add(sheep);
	}

	sequencePredator = createPredator(false);
	parallelPredator = createPredator(true);

	// Create GameOver panel
	gameOverButton = new TextButton("Game Over", skin);
	gameOverButton.setVisible(false);
	gameOverButton.addListener(new ChangeListener() {
		@Override
		public void changed (ChangeEvent event, Actor actor) {
			test.backToPreviousScreen();
		}
	});
	testTable.add(gameOverButton);
}
 
Example #15
Source File: InputFileListAdapter.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
@Override
protected void deselectView(Stack view) {
    ViewHolder viewHolder = (ViewHolder) view.getUserObject();
    viewHolder.setSelected(false);
}
 
Example #16
Source File: PortraitsUI.java    From Norii with Apache License 2.0 4 votes vote down vote up
private void updateStacks() {
	for (final Stack stack : stacks) {
		stack.setSize(PORTRAIT_WIDTH * tileWidthPixel, portraitsHeight);
	}
}
 
Example #17
Source File: TextureDropWidget.java    From talos with Apache License 2.0 3 votes vote down vote up
public void init(TextureRegion region, Skin skin, float width) {

        Stack stack = new Stack();

        image = new Image(region);
        Image border = new Image(skin.getDrawable("border"));

        stack.add(image);
        stack.add(border);

        add(stack).size(width);

    }