Add board cards

hh
Laurent 5 years ago
parent eb9f435b8b
commit 62837f2323
  1. 26
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt
  2. 45
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt

@ -22,7 +22,11 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
private val maxCards = 5 private val maxCards = 5
var width = 100f var width = 100f
val centerX: Float
get() { return this.width / 2f }
var height = 100f var height = 100f
val centerY: Float
get() { return this.height / 2f }
var tableRect = RectF() var tableRect = RectF()
var tableCornerRadius = 0f var tableCornerRadius = 0f
@ -38,6 +42,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
private var chipCircles = mutableListOf<Circle>() private var chipCircles = mutableListOf<Circle>()
private var chipTextPoints = mutableListOf<TextPoint>() private var chipTextPoints = mutableListOf<TextPoint>()
var boardCardRects = mutableListOf<RectF>()
val dealerCircle: Circle val dealerCircle: Circle
get() { get() {
@ -71,22 +76,34 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
val playerPerColumn = if (portrait) 4 else 3 val playerPerColumn = if (portrait) 4 else 3
val playerPerRow = 12 / playerPerColumn // 3 or 4 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.tableVPadding = height / playerPerColumn * 0.8f
this.tableRect = RectF(tableHPadding, tableVPadding, width - tableHPadding, height - tableVPadding) this.tableRect = RectF(tableHPadding, tableVPadding, width - tableHPadding, height - tableVPadding)
this.tableCornerRadius = (if (portrait) width else height) / 8 this.tableCornerRadius = (if (portrait) width else height) / 8
// pz for Player Zone
val pzHeight = height / playerPerColumn val pzHeight = height / playerPerColumn
val pzWidth = width / playerPerRow val pzWidth = width / playerPerRow
this.playerItemsHeight = pzHeight / 3 this.playerItemsHeight = pzHeight / 3
this.playerItemsWidth = this.tableHPadding * 2 * this.paddingPercentage 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.cardSpecs = Size(cardWidth, cardWidth * 1.75f)
this.cardRadius = cardWidth / 4 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 val playerCount = this.handHistory.numberOfPlayers
// number of players in this order: bottom / left / top / right // number of players in this order: bottom / left / top / right
val repartition = when (playerCount) { val repartition = when (playerCount) {
@ -107,7 +124,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
if (portrait && playerCount > 4) { repartition.reverse() } // adjustment for portrait vs landscape if (portrait && playerCount > 4) { repartition.reverse() } // adjustment for portrait vs landscape
val chipsVerticalOffsetFromStackCenter = this.playerItemsHeight * 0.9f val chipsVerticalOffsetFromStackCenter = this.playerItemsHeight * 0.9f
val chipsHorizontalOffsetFromStackCenter = pzWidth / 2f val chipsHorizontalOffsetFromStackCenter = this.tableHPadding * 1.2f
var pIndex = -1 var pIndex = -1
repartition.forEachIndexed { index, count -> repartition.forEachIndexed { index, count ->
@ -162,7 +179,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
rectCenterY = y * i rectCenterY = y * i
chipXOffset = -1 * chipsHorizontalOffsetFromStackCenter chipXOffset = -1 * chipsHorizontalOffsetFromStackCenter
chipYOffset = cornerDirection * chipsVerticalOffsetFromStackCenter chipYOffset = cornerDirection * chipsVerticalOffsetFromStackCenter
chipTextYOffsetCoef = 1f * (count - i - 1) / count chipTextYOffsetCoef = 1f * (count - i + 1) / count
} }
else -> throw PAIllegalStateException("can't happen") 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 cardsUsed = this.handHistory.playerSetupForPosition(pIndex)?.cards?.size ?: maxPlayerCards
val cardsRectangles = mutableListOf<RectF>() val cardsRectangles = mutableListOf<RectF>()
if (cardsUsed > 0) { if (cardsUsed > 0) {
val cardWPaddingWidth = pzWidth / maxCards
val offSet = (cardsUsed / 2 - 0.5f) * cardWPaddingWidth val offSet = (cardsUsed / 2 - 0.5f) * cardWPaddingWidth
val cardCenterY = rectCenterY - circleOffset / 2 val cardCenterY = rectCenterY - circleOffset / 2

@ -1,10 +1,7 @@
package net.pokeranalytics.android.ui.modules.handhistory.replayer package net.pokeranalytics.android.ui.modules.handhistory.replayer
import android.content.Context import android.content.Context
import android.graphics.Bitmap import android.graphics.*
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.RectF
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
@ -32,6 +29,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
private val textPaint = Paint() private val textPaint = Paint()
private val cardTextPaint = Paint() private val cardTextPaint = Paint()
private val cardStrokePaint = Paint() private val cardStrokePaint = Paint()
private val chipBorderPaint = Paint()
fun configurePaints(context: Context) { fun configurePaints(context: Context) {
tablePaint.isAntiAlias = true tablePaint.isAntiAlias = true
@ -47,6 +45,9 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
cardStrokePaint.style = Paint.Style.STROKE cardStrokePaint.style = Paint.Style.STROKE
cardStrokePaint.strokeWidth = cardStrokeWidth cardStrokePaint.strokeWidth = cardStrokeWidth
chipBorderPaint.isAntiAlias = true
chipBorderPaint.style = Paint.Style.STROKE
fillPaint.isAntiAlias = true fillPaint.isAntiAlias = true
textPaint.color = context.getColor(R.color.white) textPaint.color = context.getColor(R.color.white)
@ -113,12 +114,20 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
val chipCircle = config.chipCircle(i) val chipCircle = config.chipCircle(i)
this.fillPaint.color = context.getColor(R.color.green) this.fillPaint.color = context.getColor(R.color.green)
canvas.drawCircle(chipCircle.x, chipCircle.y, chipCircle.radius, this.fillPaint) 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) val chipText = config.chipText(i)
this.textPaint.textSize = chipText.fontSize this.textPaint.textSize = chipText.fontSize
this.textPaint.color = context.getColor(R.color.white) this.textPaint.color = context.getColor(R.color.white)
canvas.drawText("2000", chipText.x, chipText.y, this.textPaint) canvas.drawText("2000", chipText.x, chipText.y, this.textPaint)
drawStreet(Street.RIVER, config, canvas, context)
} }
} }
@ -133,6 +142,20 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
if (j < cards?.size ?: 0 && (config.showVillainHands || isHero)) { // show card if (j < cards?.size ?: 0 && (config.showVillainHands || isHero)) { // show card
val card = cards?.get(j)!! // tested line before val card = cards?.get(j)!! // tested line before
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)
cardStrokePaint.color = context.getColor(R.color.card_border)
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, cardStrokePaint)
}
}
}
private fun drawCard(card: Card, cardRect: RectF, config: ReplayerConfiguration, canvas: Canvas, context: Context) {
fillPaint.color = context.getColor(R.color.white) fillPaint.color = context.getColor(R.color.white)
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint) canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint)
@ -145,15 +168,6 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
val suitY = cardRect.top + config.cardSpecs.height * 0.88f val suitY = cardRect.top + config.cardSpecs.height * 0.88f
canvas.drawText(suit.value, cardRect.centerX(), suitY, cardTextPaint) canvas.drawText(suit.value, cardRect.centerX(), suitY, cardTextPaint)
} else { // show hidden cards
fillPaint.color = context.getColor(R.color.card_fill)
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint)
cardStrokePaint.color = context.getColor(R.color.card_border)
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, cardStrokePaint)
}
}
} }
fun drawAction(i: Int, action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { fun drawAction(i: Int, action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) {
@ -214,6 +228,11 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
fun drawStreet(street: Street, config: ReplayerConfiguration, canvas: Canvas, context: Context) { 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)
}
} }
//////// ////////

Loading…
Cancel
Save