Search in sources :

Example 1 with CollectionCard

use of com.janfic.games.computercombat.actors.CollectionCard in project computercombat by janfic.

the class OpenPackScreen method show.

@Override
public void show() {
    this.camera = new OrthographicCamera(1920 / 4, 1080 / 4);
    this.stage = ComputerCombatGame.makeNewStage(camera);
    this.skin = game.getAssetManager().get(Assets.SKIN);
    this.collections = SQLAPI.getSingleton().getCollections();
    List<Integer> collectionIDs = new ArrayList<>();
    collectionIDs.add(collection.getID());
    if (collection.getID() == 0) {
        for (Collection c : collections) {
            collectionIDs.add(c.getID());
        }
    }
    collectionIDs.remove((Integer) 0);
    this.collectionCards = SQLAPI.getSingleton().getCardsInCollection(collectionIDs, game.getCurrentProfile().getUID());
    System.out.println(collectionCards);
    this.pack = new CollectionPackActor(game, skin, collection);
    pack.setScale(1.25f);
    Gdx.input.setInputProcessor(stage);
    Table table = new Table();
    table.setFillParent(true);
    table.defaults().space(20);
    TextButton openButton = new TextButton("Open!", skin);
    openButton.setTouchable(Touchable.disabled);
    List<Card> openCards = new ArrayList<>();
    openCards.add(roll());
    openCards.add(roll());
    openCards.add(roll());
    end = new TextButton("Okay", skin);
    end.setVisible(false);
    end.setPosition(10, 10);
    end.setSize(100, 30);
    end.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            Map<Integer, Integer> added = new HashMap<>();
            for (Card openCard : openCards) {
                added.put(openCard.getID(), added.getOrDefault(openCard.getID(), 0) + 1);
            }
            SQLAPI.getSingleton().addCardsToProfile(added, game.getCurrentProfile());
            SQLAPI.getSingleton().saveProfile(game.getCurrentProfile());
            game.popScreen();
        }
    });
    table.add(pack).row();
    table.add(openButton).width(100).row();
    Action cardAction = Actions.sequence(Actions.visible(false), Actions.delay(1), Actions.moveBy(0, -stage.getHeight() * 2), Actions.visible(true), Actions.moveBy(0, stage.getHeight() * 2, 2, Interpolation.fastSlow), Actions.delay(2));
    Action buttonAction = Actions.sequence(Actions.fadeOut(0), Actions.delay(3), Actions.fadeIn(1), Actions.touchable(Touchable.enabled));
    openButton.addAction(buttonAction);
    pack.addAction(cardAction);
    cardActors = new ArrayList<>();
    openButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            pack.open();
            openButton.setVisible(false);
            Action open = Actions.sequence(Actions.moveBy(0, -200, 1), Actions.run(() -> {
                confetti();
                for (CollectionCard openCard : cardActors) {
                    openCard.setPosition(pack.getX(), pack.getY());
                    openCard.setSize(pack.getWidth() - 4, pack.getHeight());
                    openCard.addAction(Actions.parallel(Actions.moveBy(0, 200, 1, Interpolation.circleOut), Actions.moveBy((cardActors.indexOf(openCard) - 1) * 150, 0, 1, Interpolation.circleIn)));
                }
            }), Actions.run(() -> {
                end.setVisible(true);
            }));
            pack.addAction(open);
        }
    });
    for (Card openCard : openCards) {
        CollectionCard c = new CollectionCard(game, skin, openCard, 1);
        cardActors.add(c);
        stage.addActor(c);
    }
    stage.addActor(table);
    stage.addActor(end);
    table.layout();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Action(com.badlogic.gdx.scenes.scene2d.Action) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ArrayList(java.util.ArrayList) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Card(com.janfic.games.computercombat.model.Card) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) CollectionPackActor(com.janfic.games.computercombat.actors.CollectionPackActor) Collection(com.janfic.games.computercombat.model.Collection) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) HashMap(java.util.HashMap) Map(java.util.Map) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 2 with CollectionCard

use of com.janfic.games.computercombat.actors.CollectionCard in project computercombat by janfic.

the class CollectionScreen method buildCollection.

public void buildCollection() {
    Profile profile = game.getCurrentProfile();
    Map<Card, Integer> playerCards = new HashMap<>();
    Map<Card, Integer> allCards = new HashMap<>();
    List<Card> ac = SQLAPI.getSingleton().getCardsInfo(null, null);
    playerCards = SQLAPI.getSingleton().getPlayerOwnedCards(profile.getUID());
    for (Card card : ac) {
        for (Card c : playerCards.keySet()) {
            if (card.getID() == c.getID()) {
                card.setOwnerUID(profile.getUID());
                break;
            }
        }
    }
    for (Card card : ac) {
        allCards.put(card, 0);
    }
    for (Card card : playerCards.keySet()) {
        allCards.put(card, playerCards.get(card));
    }
    collection.clearChildren();
    int row = 0;
    for (Card card : allCards.keySet()) {
        CollectionCard cc = new CollectionCard(game, skin, card, allCards.get(card));
        if (allCards.get(card) == 0) {
            cc.setColor(1, 1, 1, 0.5f);
        }
        if (filterWindow.getFilter().filter(card, null, null)) {
            cards.add(cc);
            collection.add(cc);
            row++;
            if (row % 4 == 0) {
                collection.row();
                row = 0;
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Profile(com.janfic.games.computercombat.model.Profile) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Card(com.janfic.games.computercombat.model.Card)

Example 3 with CollectionCard

use of com.janfic.games.computercombat.actors.CollectionCard in project computercombat by janfic.

the class DrawAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    Table leftPanel = screen.getLeftPanel();
    Table rightPanel = screen.getRightPanel();
    Table panel;
    if (playerUID.equals(currentPlayerUID)) {
        panel = leftPanel;
    } else {
        panel = rightPanel;
    }
    List<List<Action>> animations = new ArrayList<>();
    ComputerCombatGame game = (ComputerCombatGame) Gdx.app.getApplicationListener();
    if (newSoftware.size() > 0) {
        List<Action> cardAnimation = new ArrayList<>();
        Table t = new Table();
        t.setFillParent(true);
        Card loadNewCard = SQLAPI.getSingleton().getCardById(newSoftware.get(0).getID(), newSoftware.get(0).getOwnerUID());
        loadNewCard.setMatchID(newSoftware.get(0).getMatchID());
        CollectionCard card = new CollectionCard(game, screen.getSkin(), loadNewCard, 1);
        card.setTouchable(Touchable.disabled);
        Stage stage = screen.getMainStage();
        stage.addActor(t);
        card.setVisible(false);
        card.setPosition(stage.getWidth() / 2, -300);
        t.add(card).expand().center();
        Action cardAction = Actions.sequence(Actions.moveBy(0, -400), Actions.visible(true), Actions.moveBy(0, 400, 1 * animationSpeed, Interpolation.fastSlow), Actions.delay(1 * animationSpeed), Actions.moveBy(0, -400, 1 * animationSpeed, Interpolation.slowFast));
        cardAction.setActor(card);
        cardAnimation.add(cardAction);
        animations.add(cardAnimation);
        List<SoftwareActor> softwareActors = screen.getSoftwareActors().get(currentPlayerUID);
        ComputerActor computerActor = screen.getComputerActors().get(currentPlayerUID);
        List<Action> softwareAnimation = new ArrayList<>();
        SoftwareActor softwareActor = new SoftwareActor(screen.getSkin(), !playerUID.equals(currentPlayerUID), loadNewCard, game);
        panel.clear();
        for (SoftwareActor s : softwareActors) {
            panel.add(s).row();
        }
        panel.add(softwareActor).row();
        panel.add(computerActor).expandY().growX().bottom();
        softwareActor.setVisible(false);
        softwareActors.add(softwareActor);
        Action softwareActorAction = Actions.sequence(Actions.moveBy(0, -400), Actions.visible(true), Actions.moveBy(0, 400, 1 * animationSpeed, Interpolation.fastSlow));
        softwareActorAction.setActor(softwareActor);
        softwareAnimation.add(softwareActorAction);
        animations.add(softwareAnimation);
    }
    return animations;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ArrayList(java.util.ArrayList) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) ComputerCombatGame(com.janfic.games.computercombat.ComputerCombatGame) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Card(com.janfic.games.computercombat.model.Card) ComputerActor(com.janfic.games.computercombat.actors.ComputerActor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CollectionCard (com.janfic.games.computercombat.actors.CollectionCard)3 Card (com.janfic.games.computercombat.model.Card)3 Action (com.badlogic.gdx.scenes.scene2d.Action)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 ComputerCombatGame (com.janfic.games.computercombat.ComputerCombatGame)1 CollectionPackActor (com.janfic.games.computercombat.actors.CollectionPackActor)1 ComputerActor (com.janfic.games.computercombat.actors.ComputerActor)1 SoftwareActor (com.janfic.games.computercombat.actors.SoftwareActor)1 Collection (com.janfic.games.computercombat.model.Collection)1 Profile (com.janfic.games.computercombat.model.Profile)1 List (java.util.List)1 Map (java.util.Map)1