Example usage for com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener tap

List of usage examples for com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener tap

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener tap.

Prototype

public void tap(InputEvent event, float x, float y, int count, int button) 

Source Link

Usage

From source file:com.vlaaad.dice.ui.windows.PotionsPlayWindow.java

License:Open Source License

@Override
protected void doShow(Params params) {
    windowParams = params;// w  w  w  .j  a  v  a 2 s  .  c  o m
    final Table content = new Table(Config.skin);
    content.defaults().pad(2);
    content.setBackground("ui-creature-info-background");
    content.setTouchable(Touchable.enabled);
    Container container = new Container(content).top();
    table.add(container).size(162, 218);

    Array<Ability> potions = new Array<Ability>();
    for (Ability ability : params.creature.player.potions()) {
        if (params.creature.player.getPotionCount(ability) > 0)
            potions.add(ability);
    }
    potions.sort(Ability.COST_COMPARATOR);

    Table viewsList = new Table();
    Image selection = new Image(Config.skin.getDrawable("selection/turn"));
    viewsList.addActor(selection);

    LocLabel name = new LocLabel("");
    LocLabel desc = new LocLabel("");
    desc.setAlignment(Align.center /*| Align.top*/);
    desc.setWrap(true);

    Table buttons = new Table();
    buttons.top().defaults().pad(2);

    Table viewRow = new Table();
    viewsList.add(viewRow).row();
    viewRow.defaults().pad(2);
    int i = 0;
    ActorGestureListener l = null;
    for (Ability ability : potions) {
        AbilityIconCounter icon = new AbilityIconCounter(ability,
                params.creature.player.getPotionCount(ability));
        icon.image.setOrigin(icon.image.getWidth() / 2, icon.image.getHeight() / 2);
        ActorGestureListener listener = createPotionTapListener(icon, ability, selection, viewsList, name, desc,
                buttons);
        if (l == null) {
            l = listener;
        }
        icon.addListener(listener);
        i++;
        viewRow.add(icon);
        if (i % 5 == 0) {
            viewRow = new Table();
            viewRow.defaults().pad(2);
            viewsList.add(viewRow).row();
        }
    }

    content.add(viewsList).row();
    content.add(new Tile("ui-creature-info-line")).size(100, 1).row();
    content.add(name).padBottom(0).padTop(-1).row();
    //        Tile line = new Tile("ui-creature-info-line");
    //        line.setColor(1, 1, 1, 0.5f);
    //        content.add(line).padBottom(0).padTop(4).size(50, 1).row();
    content.add(desc).size(130, 44).padTop(0).row();
    //        content.add(new Tile("ui-creature-info-line")).size(100, 1).row();
    content.add(buttons)/*.height(68)*/.row();

    if (l != null) {
        table.invalidate();
        table.validate();
        l.tap(null, 0, 0, 0, 0);
    }
    getStage().addActor(new Actor() {
        float x = -1;
        float y = -1;

        @Override
        public void act(float delta) {
            if (content.getWidth() != x || content.getHeight() != y) {
                x = content.getWidth();
                y = content.getHeight();
            }
        }
    });
}

From source file:com.vlaaad.dice.ui.windows.PotionsWindow.java

License:Open Source License

@Override
protected void initialize() {
    Table content = new Table(Config.skin);
    content.setBackground("ui-creature-info-background");
    content.setTouchable(Touchable.enabled);
    content.defaults().pad(2);//  www . ja  v  a 2 s  . co m
    Array<Ability> potions = new Array<Ability>();
    for (Ability ability : Config.abilities.byType(Ability.Type.potion)) {
        potions.add(ability);
    }
    potions.sort(Ability.COST_COMPARATOR);

    potionsList = new Table();
    Image selection = new Image(Config.skin.getDrawable("selection/turn"));
    potionsList.addActor(selection);

    potionName = new LocLabel("");
    potionDescription = new LocLabel("");
    potionDescription.setAlignment(Align.center | Align.top);
    potionDescription.setWrap(true);

    ingredientsTable = new Table(Config.skin);
    ingredientsTable.defaults().pad(2);

    Table viewRow = new Table();
    potionsList.add(viewRow).row();
    viewRow.defaults().pad(2);
    int i = 0;
    ActorGestureListener l = null;
    for (Ability ability : potions) {
        AbilityIconCounter icon = new AbilityIconCounter(ability, 0);
        icon.image.setOrigin(icon.image.getWidth() / 2, icon.image.getHeight() / 2);
        potionIcons.put(ability, icon);
        ActorGestureListener listener = createPotionTapListener(icon, ability, selection, potionsList,
                potionName, potionDescription, ingredientsTable);
        if (l == null) {
            l = listener;
        }
        iconListeners.put(ability, listener);
        icon.addListener(listener);
        i++;
        viewRow.add(icon);
        if (i % 5 == 0) {
            viewRow = new Table();
            viewRow.defaults().pad(2);
            potionsList.add(viewRow).row();
        }
    }

    craftingPane = new CraftingPane(3, potions);

    Table craftTable = new Table(Config.skin);
    craftTable.setBackground("ui-craft-content");
    craftTable.defaults().pad(4);
    craftTable.add(craftingPane).row();
    craftTable.add(ingredientsContainer).row();

    content.add(potionsList).row();
    content.add(new Tile("ui-creature-info-line")).size(80, 1).row();
    content.add(potionName).row();
    content.add(ingredientsTable).padTop(5).padBottom(1).row();
    content.add(potionDescription).size(130, 48).row();
    content.add(craftTable).expandX().fillX().pad(-2).row();

    Container contentContainer = new Container(content);
    contentContainer.width(content.getPrefWidth());
    scrollPane = new ScrollPane(contentContainer);
    scrollPane.setOverscroll(false, false);
    scrollPane.setCancelTouchFocus(false);
    table.add(scrollPane).width(contentContainer.getMaxWidth());

    if (l != null) {
        table.invalidate();
        table.validate();
        l.tap(null, 0, 0, 0, 0);
    }
}