From 62837f2323d2d2da13a4fbbdd78b65df84a2e7ec Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 9 Jun 2020 12:12:14 +0200 Subject: [PATCH] Add board cards --- .../replayer/ReplayerConfiguration.kt | 26 ++++++++-- .../handhistory/replayer/TableDrawer.kt | 51 +++++++++++++------ 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt index 6b7b5f75..390ae17d 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt @@ -22,7 +22,11 @@ class ReplayerConfiguration(var handHistory: HandHistory) { private val maxCards = 5 var width = 100f + val centerX: Float + get() { return this.width / 2f } var height = 100f + val centerY: Float + get() { return this.height / 2f } var tableRect = RectF() var tableCornerRadius = 0f @@ -38,6 +42,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) { private var chipCircles = mutableListOf() private var chipTextPoints = mutableListOf() + var boardCardRects = mutableListOf() val dealerCircle: Circle get() { @@ -71,22 +76,34 @@ class ReplayerConfiguration(var handHistory: HandHistory) { val playerPerColumn = if (portrait) 4 else 3 val playerPerRow = 12 / playerPerColumn // 3 or 4 - this.tableHPadding = width / playerPerRow / 2 * 0.9f + this.tableHPadding = width / playerPerRow / 2 * 0.8f this.tableVPadding = height / playerPerColumn * 0.8f this.tableRect = RectF(tableHPadding, tableVPadding, width - tableHPadding, height - tableVPadding) this.tableCornerRadius = (if (portrait) width else height) / 8 + // pz for Player Zone val pzHeight = height / playerPerColumn val pzWidth = width / playerPerRow this.playerItemsHeight = pzHeight / 3 this.playerItemsWidth = this.tableHPadding * 2 * this.paddingPercentage - val cardWidth = pzWidth * this.cardsPaddingPercentage / this.maxCards + val cardWPaddingWidth = this.playerItemsWidth * 1.2f / this.maxCards + val cardWidth = cardWPaddingWidth * this.cardsPaddingPercentage this.cardSpecs = Size(cardWidth, cardWidth * 1.75f) this.cardRadius = cardWidth / 4 + // Board cards rectangles + val bcTop = centerY - cardSpecs.height / 2 + val bcBottom = centerY + cardSpecs.height / 2 + val boardCards = 5 + for (i in 0 until boardCards) { + val bcLeft = centerX - (boardCards / 2f - i) * cardWPaddingWidth + val bcRight = centerX - (boardCards / 2f - i) * cardWPaddingWidth + cardWidth + this.boardCardRects.add(RectF(bcLeft, bcTop, bcRight, bcBottom)) + } + val playerCount = this.handHistory.numberOfPlayers // number of players in this order: bottom / left / top / right val repartition = when (playerCount) { @@ -107,7 +124,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) { if (portrait && playerCount > 4) { repartition.reverse() } // adjustment for portrait vs landscape val chipsVerticalOffsetFromStackCenter = this.playerItemsHeight * 0.9f - val chipsHorizontalOffsetFromStackCenter = pzWidth / 2f + val chipsHorizontalOffsetFromStackCenter = this.tableHPadding * 1.2f var pIndex = -1 repartition.forEachIndexed { index, count -> @@ -162,7 +179,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) { rectCenterY = y * i chipXOffset = -1 * chipsHorizontalOffsetFromStackCenter chipYOffset = cornerDirection * chipsVerticalOffsetFromStackCenter - chipTextYOffsetCoef = 1f * (count - i - 1) / count + chipTextYOffsetCoef = 1f * (count - i + 1) / count } else -> throw PAIllegalStateException("can't happen") } @@ -197,7 +214,6 @@ class ReplayerConfiguration(var handHistory: HandHistory) { val cardsUsed = this.handHistory.playerSetupForPosition(pIndex)?.cards?.size ?: maxPlayerCards val cardsRectangles = mutableListOf() if (cardsUsed > 0) { - val cardWPaddingWidth = pzWidth / maxCards val offSet = (cardsUsed / 2 - 0.5f) * cardWPaddingWidth val cardCenterY = rectCenterY - circleOffset / 2 diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt index bc5555ef..49b6f872 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt @@ -1,10 +1,7 @@ package net.pokeranalytics.android.ui.modules.handhistory.replayer import android.content.Context -import android.graphics.Bitmap -import android.graphics.Canvas -import android.graphics.Paint -import android.graphics.RectF +import android.graphics.* import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory import net.pokeranalytics.android.R @@ -32,6 +29,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { private val textPaint = Paint() private val cardTextPaint = Paint() private val cardStrokePaint = Paint() + private val chipBorderPaint = Paint() fun configurePaints(context: Context) { tablePaint.isAntiAlias = true @@ -47,6 +45,9 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { cardStrokePaint.style = Paint.Style.STROKE cardStrokePaint.strokeWidth = cardStrokeWidth + chipBorderPaint.isAntiAlias = true + chipBorderPaint.style = Paint.Style.STROKE + fillPaint.isAntiAlias = true textPaint.color = context.getColor(R.color.white) @@ -113,12 +114,20 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { val chipCircle = config.chipCircle(i) this.fillPaint.color = context.getColor(R.color.green) canvas.drawCircle(chipCircle.x, chipCircle.y, chipCircle.radius, this.fillPaint) + this.chipBorderPaint.color = context.getColor(R.color.white) + val chipBorderStrokeWidth = chipCircle.radius / 3f + this.chipBorderPaint.strokeWidth = chipBorderStrokeWidth + + chipBorderPaint.pathEffect = DashPathEffect(floatArrayOf(chipCircle.radius * 0.6f, chipCircle.radius * 0.44f), 0f) + canvas.drawCircle(chipCircle.x, chipCircle.y, chipCircle.radius - chipBorderStrokeWidth / 2, this.chipBorderPaint) val chipText = config.chipText(i) this.textPaint.textSize = chipText.fontSize this.textPaint.color = context.getColor(R.color.white) canvas.drawText("2000", chipText.x, chipText.y, this.textPaint) + drawStreet(Street.RIVER, config, canvas, context) + } } @@ -133,18 +142,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { if (j < cards?.size ?: 0 && (config.showVillainHands || isHero)) { // show card val card = cards?.get(j)!! // tested line before - fillPaint.color = context.getColor(R.color.white) - canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint) - - cardTextPaint.color = context.getColor(R.color.black) - val valueY = cardRect.top + config.cardSpecs.height * 0.44f - canvas.drawText(card.formattedValue, cardRect.centerX(), valueY, cardTextPaint) - - val suit = card.suit ?: Card.Suit.UNDEFINED - cardTextPaint.color = context.getColor(suit.color) - val suitY = cardRect.top + config.cardSpecs.height * 0.88f - canvas.drawText(suit.value, cardRect.centerX(), suitY, cardTextPaint) - + drawCard(card, cardRect, config, canvas, context) } else { // show hidden cards fillPaint.color = context.getColor(R.color.card_fill) canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint) @@ -156,6 +154,22 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } + private fun drawCard(card: Card, cardRect: RectF, config: ReplayerConfiguration, canvas: Canvas, context: Context) { + + fillPaint.color = context.getColor(R.color.white) + canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint) + + cardTextPaint.color = context.getColor(R.color.black) + val valueY = cardRect.top + config.cardSpecs.height * 0.44f + canvas.drawText(card.formattedValue, cardRect.centerX(), valueY, cardTextPaint) + + val suit = card.suit ?: Card.Suit.UNDEFINED + cardTextPaint.color = context.getColor(suit.color) + val suitY = cardRect.top + config.cardSpecs.height * 0.88f + canvas.drawText(suit.value, cardRect.centerX(), suitY, cardTextPaint) + + } + fun drawAction(i: Int, action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { // show that action is on the player by highlighting @@ -214,6 +228,11 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { fun drawStreet(street: Street, config: ReplayerConfiguration, canvas: Canvas, context: Context) { + val cards = config.handHistory.cardsForStreet(street) + config.boardCardRects.take(street.totalBoardCards).forEachIndexed { index, rectF -> + drawCard(cards[index], rectF, config, canvas, context) + } + } ////////