public InPlayView(InPlay play) { super(); mInPlayCards = play; mCardHeight = Director.instance().getAssets().get("cards", CardResource.class).getHeight(); mCardWidth = Director.instance().getAssets().get("cards", CardResource.class).getWidth(); init(); }
public void OrganizeCards() { int size = mInPlayCards.GetCards().size(); float width = Director.instance().getAssets().get("cards", CardResource.class).getWidth(); int rows = (size / cardsHorizontal) + 1; int lastCol = size % cardsHorizontal; float height = (width * overlapPercentY * (size / (cardsHorizontal + 1))); setHeight(height + mCardHeight); float startY = getHeight() - mCardHeight; int i = 0, x = 0, y = 0; int col = 0; for (y = 0; y < rows; ++y) { if (y == rows - 1) col = lastCol; else col = cardsHorizontal; if (y % 2 == 0) { // even for (x = 0; x < col; ++x) { CardView cv = CardView.getCardView(mInPlayCards.GetCards().get(i)); HandUtils.Reparent(this, cv); cv.setPosition(width * overlapPercentX * x, startY); cv.setRotation(0); cv.setSide(CardView.Side.FRONT); i++; } } else { // odd for (x = 0; x < col; ++x) { CardView cv = CardView.getCardView(mInPlayCards.GetCards().get(i)); HandUtils.Reparent(this, cv); cv.setPosition(width * overlapPercentX * (cardsHorizontal - 1 - x), startY); cv.setRotation(0); cv.setSide(CardView.Side.FRONT); i++; } } startY -= (width * overlapPercentY); } float nextX = 0.0f; float nextY = 0.0f; if (x < cardsHorizontal) { y = rows - 1; nextY = startY + (width * overlapPercentY); if (y % 2 == 0) // even nextX = width * overlapPercentX * x; else nextX = width * overlapPercentX * (cardsHorizontal - 1 - x); } else { x = 0; y = rows; nextY = startY; if (y % 2 == 0) // even nextX = width * overlapPercentX * x; else nextX = width * overlapPercentX * (cardsHorizontal - 1 - x); } mNextPosition.set(nextX, nextY); if (rows - 1 == 0) setWidth(width + (width * overlapPercentX * (lastCol - 1))); else setWidth(width + (width * overlapPercentX * (cardsHorizontal - 1))); // reposition if (mDeck == null) return; setY(mDeck.getY() - (getHeight() - mCardHeight)); }
private void createEvents() { Director.instance() .getEventSystem() .RegisterEvent( new EventSystem.EventListener(EventSystem.EventType.INPLAY_CARDS_CHANGED) { @Override public void handle(Object[] params) {} }); Director.instance() .getEventSystem() .RegisterEvent( new EventSystem.EventListener(EventSystem.EventType.BURN_CARDS) { @Override public void handle(Object[] params) { if (params == null || params.length != 1 || !(params[0] instanceof Card)) { throw new IllegalArgumentException("Invalid parameters for BURN_CARDS"); } if (!(getParent() instanceof TableView)) throw new RuntimeException("Cannot burn cards without a TableView parent"); if (!(getStage() instanceof GameScene)) throw new RuntimeException("Burning cards requires a GameScene Stage"); GameScene stage = (GameScene) getStage(); TableView table = (TableView) getParent(); Card topCard = (Card) params[0]; Play pState = (Play) Logic.get().GetMainState().getState(State.Names.PLAY); DrawPlayCard dState = (DrawPlayCard) Logic.get().GetMainState().getState(State.Names.DRAW_PLAY_CARD); if (pState == null && dState == null) { throw new RuntimeException( "Burn Animation requires Play or DrawPlayCard state to be active!"); } CardCamera.CameraSide side = CardCamera.CameraSide.BOTTOM; if (pState != null) side = HandUtils.HandSideToCamera( HandUtils.IDtoSide(table.getTable().getCurrentPlayTurn(), table)); int cardSize = mInPlayCards.GetCards().size(); for (int i = 0; i < cardSize; ++i) { Card c = mInPlayCards.GetCards().get(i); final CardView cv = CardView.getCardView(c); AnimationBuilder burnBuilder = AnimationFactory.get() .createAnimationBuilder(AnimationFactory.AnimationType.CARD); burnBuilder .setPause(true) .setDescription("Burning cards") .setTable(table) .setCard(cv) .setCamera(table.getCamera()) .setTweenCalculator(new CardAnimation.BurnCard()) .addStatusListener( new Animation.AnimationStatusListener() { @Override public void onEnd(Animation animation) { cv.remove(); // lets remove the card from the table! } }); if (i == cardSize - 1 && table.getCamera().GetSide() != side) { // this is the last card AnimationBuilder cameraBuilder = AnimationFactory.get() .createAnimationBuilder(AnimationFactory.AnimationType.CAMERA); cameraBuilder .setPause(true) .setDescription("Move Back to hand") .setTable(table) .setCamera(table.getCamera()) .setCameraSide(side) .setTweenCalculator(new CameraAnimation.MoveToSide(1.0f, 0.5f)); cameraBuilder.setEndDelay(0.5f); burnBuilder.setNextAnimation(cameraBuilder.build()); } // lets show the burn message! String message = StringMap.getString("dramatic_burn"); if (topCard != null) { if (topCard.getRank() == Card.Rank.TEN) message = StringMap.getString("burn"); else message = StringMap.getString("4_burn"); } stage.ShowMessage(message, 1.0f, Color.FIREBRICK); burnBuilder.build().Start(); } Director.instance() .getAudioManager() .QueueSound( new SoundEvent( Director.instance() .getAssets() .get("sounds", SoundMap.class) .getRandom("burn_voice"), 0.3f)); Director.instance() .getAudioManager() .QueueSound( new SoundEvent( Director.instance() .getAssets() .get("sounds", SoundMap.class) .getRandom("burn"), 0.2f)); } }); Director.instance() .getEventSystem() .RegisterEvent( new EventSystem.EventListener(EventSystem.EventType.HIGHLIGHT_PLAY) { @Override public void handle(Object params[]) { if (params == null || params.length != 1 || !(params[0] instanceof Boolean)) { throw new IllegalArgumentException("Invalid parameters for HIGHLIGHT_PLAY"); } setHighlight((Boolean) params[0]); } }); }