Java Code Examples for com.badlogic.gdx.scenes.scene2d.ui.Image

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Image. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: vis-ui   Source File: BasicColorPicker.java    License: Apache License 2.0 6 votes vote down vote up
private VisTable createColorsPreviewTable () {
	VisTable table = new VisTable(false);
	table.add(currentColorImg = new AlphaImage(commons, 5 * sizes.scaleFactor))
			.height(25 * sizes.scaleFactor).width(80 * sizes.scaleFactor).expandX().fillX();
	table.add(new Image(style.iconArrowRight)).pad(0, 2, 0, 2);
	table.add(newColorImg = new AlphaImage(commons, 5 * sizes.scaleFactor))
			.height(25 * sizes.scaleFactor).width(80 * sizes.scaleFactor).expandX().fillX();

	currentColorImg.setColor(color);
	newColorImg.setColor(color);

	currentColorImg.addListener(new ClickListener() {
		@Override
		public void clicked (InputEvent event, float x, float y) {
			restoreLastColor();
		}
	});

	return table;
}
 
Example 2
private Image getScreenshot(String slot) {
	String filename = slot + WorldSerialization.GAMESTATE_EXT + ".png";

	FileHandle savedFile = null;

	if (EngineAssetManager.getInstance().getUserFile(filename).exists())
		savedFile = EngineAssetManager.getInstance().getUserFile(filename);
	else if (EngineAssetManager.getInstance().assetExists("tests/" + filename))
		savedFile = EngineAssetManager.getInstance().getAsset("tests/" + filename);
	else {
		Drawable d = ui.getSkin().getDrawable("black");

		return new Image(d);
	}

	Texture t = new Texture(savedFile);

	// add to the list for proper dispose when hide the screen
	textureList.add(t);

	return new Image(t);
}
 
Example 3
Source Project: Unlucky   Source File: Item.java    License: MIT License 6 votes vote down vote up
/**
 * For all types of equips
 * Gives increased stats and can be sold for gold
 *
 * @param name
 * @param desc
 * @param type
 * @param rarity
 * @param imgIndex
 * @param mhp
 * @param dmg
 * @param acc
 * @param sell
 */
public Item(ResourceManager rm, String name, String desc, int type, int rarity, int imgIndex, int minLevel, int maxLevel,
            int mhp, int dmg, int acc, int sell) {
    this.name = name;
    this.desc = desc;
    this.type = type;
    this.rarity = rarity;
    this.imgIndex = imgIndex;
    this.minLevel = minLevel;
    this.maxLevel = maxLevel;
    this.mhp = mhp;
    this.dmg = dmg;
    this.acc = acc;
    this.sell = sell;
    actor = new Image(rm.items20x20[type][imgIndex]);
    labelName = name;
}
 
Example 4
Source Project: cocos-ui-libgdx   Source File: CCSpriteViewTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldParseSpriteView() throws Exception {
    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("animation/MainScene.json"), null, null, null, null);

    Group group = editor.createGroup();
    Image image = group.findActor("st_2");
    Array<Action> actions = image.getActions();
    assertThat(actions.size, is(1));
    RepeatAction repeatAction = (RepeatAction) actions.get(0);
    ParallelAction parallelAction = (ParallelAction) repeatAction.getAction();
    assertThat(parallelAction.getActions().size, is(3));
    assertThat(parallelAction.getActions(), (Matcher) everyItem(instanceOf(SequenceAction.class)));
    SequenceAction moveAction = (SequenceAction) parallelAction.getActions().get(0);
    SequenceAction scaleAction = (SequenceAction) parallelAction.getActions().get(1);
    assertThat(moveAction.getActions().size, is(4));
    assertThat(moveAction.getActions(), (Matcher) everyItem(instanceOf(MoveToAction.class)));
    assertThat(scaleAction.getActions().size, is(4));
    assertThat(scaleAction.getActions(), (Matcher) everyItem(instanceOf(ScaleToAction.class)));
}
 
Example 5
Source Project: Cubes   Source File: SlotActor.java    License: MIT License 6 votes vote down vote up
public SlotActor(Inventory inventory, int num) {
  super(new ButtonStyle());

  Image image = new Image();
  image.setScaling(Scaling.fit);
  image.setDrawable(new SlotDrawable());
  image.setTouchable(Touchable.disabled);
  add(image);
  setSize(getPrefWidth(), getPrefHeight());

  this.inventory = inventory;
  this.num = num;

  InventoryManager.newSlot(this);
  addListener(new SlotTooltipListener(this));
}
 
Example 6
private void blink(final Image arrow, final ArrowDirection direction) {
if (direction == ArrowDirection.fromTop || direction == ArrowDirection.fromBottom) {
    arrow.addAction(Actions.sequence(
        Actions.moveBy(0, moveOffset(), periodTime() * 0.25f),
        Actions.moveBy(0, -moveOffset() * 2f, periodTime() * 0.5f),
        Actions.moveBy(0, moveOffset(), periodTime() * 0.25f),
        Actions.run(new Runnable() {
            @Override public void run() {
                blink(arrow, direction);
            }
        })
    ));
} else {
    arrow.addAction(Actions.sequence(
        Actions.moveBy(moveOffset(), 0, periodTime() * 0.25f),
        Actions.moveBy(-moveOffset() * 2f, 0 * 2f, periodTime() * 0.5f),
        Actions.moveBy(moveOffset(), 0, periodTime() * 0.25f),
        Actions.run(new Runnable() {
 
Example 7
Source Project: dice-heroes   Source File: ArrowMessageNet.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override protected Table getMessageTable() {

        LocLabel label = new LocLabel(locKey);
        label.setWrap(true);
        label.setAlignment(Align.center);

        Label tapToContinue = new LocLabel("tap-to-continue", ShowTutorialMessage.Message.TAP_TO_CONTINUE);
        tapToContinue.setWrap(true);
        tapToContinue.setAlignment(Align.center);

        Table result = new Table();
        result.align(Align.top);
        result.add(label).width(stage.getWidth() / 1.5f).row();
        result.add(new Image(Config.skin, "ui-creature-info-line")).width(120).padTop(4).row();
        result.add(tapToContinue);
        return result;
    }
 
Example 8
Source Project: cocos-ui-libgdx   Source File: CCLoadingBar.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {

    if (widget.getImageFileData() == null) {
        return new Image();
    }

    TextureRegion textureRegion = editor.findTextureRegion(widget, widget.getImageFileData()
            .getPath());
    if (textureRegion == null) {
        return new Image();
    }
    TLoadingBar loadingBar = new TLoadingBar(textureRegion);
    loadingBar.setValue(widget.getProgressInfo());

    return loadingBar;
}
 
Example 9
private ClickListener createListener(final Group group, final Image selection, final LocLabel label, final CreatureEffect effect, final Creature creature) {
    return new ClickListener() {
        @Override public void clicked(InputEvent event, float x, float y) {
            group.addActor(selection);
            final int turnCount = effect.getTurnCount();
            if (turnCount > 1000) {
                //forever effect
                label.setKey("ui-creature-info-window-forever-effect-description");
                label.setParams(Thesaurus.params()
                        .with("desc", effect.locDescKey())
                        .with("die", creature.description.nameLocKey())
                );
            } else {
                label.setKey("ui-creature-info-window-effect-description");
                label.setParams(Thesaurus.params()
                        .with("desc", effect.locDescKey())
                        .with("turn-count", String.valueOf(turnCount))
                        .with("die", creature.description.nameLocKey())
                );
            }
        }
    };
}
 
Example 10
Source Project: dice-heroes   Source File: CraftingPane.java    License: GNU General Public License v3.0 6 votes vote down vote up
public CraftingPane(int elementsCount, Array<Ability> recipes) {
        super(Config.skin);
        this.inputs = new ObjectMap<Actor, ItemIcon>(elementsCount);
        this.count = elementsCount;
        this.recipes = recipes;
//        defaults().pad(2);
        for (int i = 0; i < elementsCount; i++) {
            Image image = new Image(Config.skin, "ui-crafting-slot");
            image.setName("slot#" + i);
            inputs.put(image, null);
            add(image).size(26);
            if (i != elementsCount - 1) {
                add(new Tile("ui-plus")).pad(1);
            } else {
                add(new Tile("ui-equals")).pad(1);
            }
        }
        add(output).size(26);
        setTouchable(Touchable.enabled);
    }
 
Example 11
public AbilityIconCounter(Ability ability, int value) {
    if (ability == null) {
        ability = Config.abilities.get("skip-turn");
    }
    image = new Image(Config.skin.getDrawable("ability/" + ability.name + "-icon"));
    if (ability.cost <0) image.setColor(AbilityIcon.unique);
    image.setScaling(Scaling.none);
    image.setAlign(Align.left | Align.top);
    image.moveBy(0, 1);

    counter = new Label("", Config.skin, "default", "inventory-counter");
    counter.setAlignment(Align.right | Align.bottom);
    setCount(value);

    addActor(image);
    addActor(counter);

    setSize(image.getPrefWidth(), image.getPrefHeight());
}
 
Example 12
Source Project: gdx-vfx   Source File: ImageDrawableLmlAttribute.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void process(LmlParser parser, LmlTag tag, Image image, String rawAttributeData) {
    ActorConsumer<Drawable, Image> action = (ActorConsumer<Drawable, Image>) parser.parseAction(rawAttributeData, image);
    if (action == null) {
        parser.throwError("Cannot find action: " + rawAttributeData);
        return;
    }

    Drawable drawable = action.consume(image);
    image.setDrawable(drawable);
}
 
Example 13
Source Project: talos   Source File: NodeStage.java    License: Apache License 2.0 5 votes vote down vote up
private void initActors() {
    GridRenderer gridRenderer = new GridRenderer(stage);
    stage.addActor(gridRenderer);

    moduleBoardWidget = new ModuleBoardWidget(this);

    stage.addActor(moduleBoardWidget);

    selectionRect = new Image(skin.getDrawable("orange_row"));
    selectionRect.setSize(0, 0);
    selectionRect.setVisible(false);
    stage.addActor(selectionRect);
}
 
Example 14
Source Project: gdx-gltf   Source File: GLTFDemoUI.java    License: Apache License 2.0 5 votes vote down vote up
private void addMaterialTextureSwitch(String name, final Material material, long type){
	final PBRTextureAttribute attribute = material.get(PBRTextureAttribute.class, type);
	if(attribute != null){
		final TextButton bt = new TextButton(name, getSkin(), "toggle");
		bt.setChecked(true);
		materialTable.add(bt);
		
		Image pict = new Image(attribute.textureDescription.texture);
		
		pict.setScaling(Scaling.fit);
		
		materialTable.add(pict).size(64);
		
		materialTable.row();
		
		bt.addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				if(bt.isChecked()){
					material.set(attribute);
				}else{
					material.remove(attribute.type);
				}
			}
		});
	}
	
}
 
Example 15
Source Project: gdx-gltf   Source File: GLTFDemoUI.java    License: Apache License 2.0 5 votes vote down vote up
public void setImage(Texture texture){
	if(texture != null){
		Image img = new Image(texture);
		img.setScaling(Scaling.fit);
		screenshotsTable.add(img).height(100);
	}
}
 
Example 16
Source Project: Norii   Source File: StatusUI.java    License: Apache License 2.0 5 votes vote down vote up
private void createDynamicHpBar() {
	final TextureAtlas skinAtlas = Utility.getUITextureAtlas();
	final NinePatch hpBarBackgroundPatch = new NinePatch(skinAtlas.findRegion("default-round"), 5, 5, 4, 4);
	final NinePatch hpBarPatch = new NinePatch(skinAtlas.findRegion("default-round-down"), 5, 5, 4, 4);
	hpBar = new Image(hpBarPatch);
	hpBarBackground = new Image(hpBarBackgroundPatch);

	hpBar.setWidth(BAR_WIDTH * tileWidthPixel);
	hpBarBackground.setWidth(BAR_WIDTH * tileWidthPixel);
}
 
Example 17
Source Project: Norii   Source File: StatusUI.java    License: Apache License 2.0 5 votes vote down vote up
private void createDynamicXpBar() {
	final TextureAtlas skinAtlas = Utility.getUITextureAtlas();
	final NinePatch xpBarBackgroundPatch = new NinePatch(skinAtlas.findRegion("default-round"), 5, 5, 4, 4);
	final NinePatch xpBarPatch = new NinePatch(skinAtlas.findRegion("default-round-down"), 5, 5, 4, 4);
	xpBarPatch.setColor(Color.BLACK);
	xpBar = new Image(xpBarPatch);
	xpBarBackground = new Image(xpBarBackgroundPatch);
}
 
Example 18
Source Project: Norii   Source File: HPBar.java    License: Apache License 2.0 5 votes vote down vote up
private void createDynamicHpBar() {
	final TextureAtlas skinAtlas = Utility.getUITextureAtlas();
	final NinePatch hpBarBackgroundPatch = new NinePatch(skinAtlas.findRegion("default-round"), 5, 5, 4, 4);
	final NinePatch hpBarPatch = new NinePatch(skinAtlas.findRegion("default-round-down"), 5, 5, 4, 4);
	hpBarImage = new Image(hpBarPatch);
	hpBarBackgroundImage = new Image(hpBarBackgroundPatch);
}
 
Example 19
private void initializeAssets() {
    skin = manager.get("skin.json", Skin.class);
    atlas = manager.get("skin.atlas", TextureAtlas.class);

    // layout
    Table table = new Table();
    table.pad(10);
    table.defaults().space(10);
    table.setFillParent(true);

    // header
    table.row();
    table.add(new Label("LibGDX Card Deck", skin, "cantarell")).colspan(RANKS.length);

    // deck
    for (String suit : SUITS) {
        table.row();
        for (String rank : RANKS) {
            table.add(
                    new Image(
                            new SpriteDrawable(atlas.createSprite(String.format("card1_suit_%s_rank_%s", suit, rank))),
                            Scaling.fit));
        }
    }

    stage.addActor(table);
}
 
Example 20
Source Project: Unlucky   Source File: SpecialMove.java    License: MIT License 5 votes vote down vote up
public SpecialMove(int id, String name, String desc, int levelUnlocked, Image icon) {
    this.id = id;
    this.name = name;
    this.desc = desc;
    this.levelUnlocked = levelUnlocked;
    this.icon = icon;
}
 
Example 21
Source Project: Unlucky   Source File: Item.java    License: MIT License 5 votes vote down vote up
/**
 * For potions
 * Only can be consumed for hp or sold for gold
 *
 * @param name
 * @param desc
 * @param rarity
 * @param imgIndex for textureregion in spritesheet
 * @param hp
 * @param sell
 */
public Item(ResourceManager rm, String name, String desc, int rarity, int imgIndex, int minLevel, int maxLevel, int hp, int exp, int sell) {
    this.name = name;
    this.desc = desc;
    this.rarity = rarity;
    this.imgIndex = imgIndex;
    this.minLevel = minLevel;
    this.maxLevel = maxLevel;
    this.hp = hp;
    this.exp = exp;
    this.sell = sell;
    type = 0;
    actor = new Image(rm.items20x20[0][imgIndex]);
    labelName = name;
}
 
Example 22
Source Project: vis-ui   Source File: GridSubImage.java    License: Apache License 2.0 5 votes vote down vote up
public void draw (Batch batch, Image parent) {
	ShaderProgram originalShader = batch.getShader();
	batch.setShader(gridShader);
	gridShader.setUniformf("u_width", parent.getWidth());
	gridShader.setUniformf("u_height", parent.getHeight());
	gridShader.setUniformf("u_gridSize", gridSize);
	batch.draw(whiteTexture, parent.getX() + parent.getImageX(), parent.getY() + parent.getImageY(),
			parent.getImageWidth() * parent.getScaleX(), parent.getImageHeight() * parent.getScaleY());
	batch.setShader(originalShader);
}
 
Example 23
Source Project: Mundus   Source File: ImageChooserField.java    License: Apache License 2.0 5 votes vote down vote up
public ImageChooserField(int width) {
    super();
    this.width = width;
    fcBtn = new VisTextButton("Select");
    img = new Image(PLACEHOLDER_IMG);

    setupUI();
    setupListeners();
}
 
Example 24
private void updateImage() {
    Image toUse;
    Image toRemove;
    if (currentIndex % 2 == 0) { // even
        toUse = dia;
        toRemove = orto;
    } else {
        toUse = orto;
        toRemove = dia;
    }
    toRemove.remove();
    group.addActor(toUse);
    toUse.setRotation(getRotation(currentIndex));
}
 
Example 25
Source Project: dice-heroes   Source File: BeamVisualizer.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override public IFuture<Void> visualize(ITargetOwner result) {
    final Future<Void> future = new Future<Void>();
    SoundManager.instance.playSoundIfExists(soundName);
    Image image = new Image(Config.skin, "effect-luck-image");
    image.setColor(color);
    image.setScale(0, 0);
    image.setOrigin(image.getWidth() / 2, image.getHeight() / 2);
    image.setPosition(
        result.getTarget().getX() * ViewController.CELL_SIZE + (ViewController.CELL_SIZE - image.getWidth()) * 0.5f,
        result.getTarget().getY() * ViewController.CELL_SIZE + (ViewController.CELL_SIZE - image.getHeight()) * 0.5f + 6
    );
    visualizer.viewController.effectLayer.addActor(image);
    image.addAction(
        Actions.sequence(
            Actions.parallel(
                Actions.scaleTo(0.75f, 0.75f, 0.5f, Interpolation.sine),
                Actions.rotateBy(135, 0.5f)
            ),
            Actions.parallel(
                Actions.scaleTo(0, 0, 0.5f, Interpolation.sine),
                Actions.rotateBy(135, 0.5f)
            ),
            Actions.run(future),
            Actions.removeActor()
        )
    );
    return future;
}
 
Example 26
Source Project: riiablo   Source File: TabbedPane.java    License: Apache License 2.0 5 votes vote down vote up
public TabbedPane() {
  clickListener = new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y) {
      Button button = (Button) event.getListenerActor();
      contentPanel.setActor(map.get(button.getName()));
      notifyTabSwitched(buttons.getChecked().getName(), button.getName());
    }
  };

  add(tabs = new VisTable()).growX().row();
  add(new Image(VisUI.getSkin().getDrawable("list-selection"))).growX().row();
  add(contentPanel = new Container<>()).align(Align.top).row();
}
 
Example 27
Source Project: dice-heroes   Source File: ViewController.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void addBackgroundObject(boolean anywhere) {
    final Image image = new Image(backgroundDrawables.random());
    backgroundLayer.addActor(image);


    float scale = 0.5f * MathUtils.random(1, 2);
    image.setSize(image.getPrefWidth() * scale, image.getPrefHeight() * scale);
    image.setRotation(MathUtils.random(0, 1) * 180);
    image.getColor().a = MathUtils.random(0.1f, 0.3f);

    float w = Math.max(world.stage.getWidth(), root.getWidth() + ViewScroller.LEFT + ViewScroller.RIGHT);
    float h = Math.max(world.stage.getHeight(), root.getHeight() + ViewScroller.TOP + ViewScroller.BOTTOM);

    if (anywhere)
        image.setPosition(-root.getX() + w * MathUtils.random(), -root.getY() + h * MathUtils.random());
    else
        image.setPosition(-root.getX() - image.getWidth(), -root.getY() + h * MathUtils.random());

    image.addAction(Actions.sequence(
        Actions.moveBy(w + image.getWidth() - image.getX(), 0, 15 + MathUtils.random(6)),
        Actions.run(new Runnable() {
            @Override public void run() {
                image.remove();
                addBackgroundObject(false);
            }
        })
    ));
}
 
Example 28
Source Project: dice-heroes   Source File: ViewController.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static Image addTopLeftCornerTransition(String name, int x, int y, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("transitions/" + name + "-corner").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE, y * CELL_SIZE);
    return image;
}
 
Example 29
Source Project: dice-heroes   Source File: ViewController.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static Image addTopRightCornerTransition(String name, int x, int y, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("transitions/" + name + "-corner").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    layer.addActor(image);
    image.setRotation(-90);
    image.setPosition(x * CELL_SIZE, (y + 1) * CELL_SIZE);
    return image;
}
 
Example 30
Source Project: gdx-ai   Source File: BehaviorTreeTests.java    License: 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);
}