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 24841535..33b71a0f 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 @@ -6,27 +6,46 @@ import net.pokeranalytics.android.model.realm.handhistory.HandHistory class ReplayerConfiguration(var handHistory: HandHistory) { + data class Size(var width: Float, var height: Float) data class Circle(var x: Float, var y: Float, var radius: Float) data class TextPoint(var x: Float, var y: Float, var fontSize: Float) + private val maxCards = 5 + var width = 100f var height = 100f var tableRect = RectF() - var playerStackRects = mutableListOf() - var playerCircles = mutableListOf() - var playerNamePoints = mutableListOf() - var playerStackPoints = mutableListOf() - var playerItemsHeight = 10f - var playerItemsWidth = 10f - var paddingPercentage = 0.8f + var tableCornerRadius = 0f + var cardSpecs: Size = Size(0f, 0f) + var cardRadius = 0f + + private var playerStackRects = mutableListOf() + private var playerCircles = mutableListOf() + private var playerNamePoints = mutableListOf() + private var playerStackPoints = mutableListOf() + private var playerCardRects = mutableListOf>() + + val dealerCircle: Circle + get() { + val rect = this.playerStackRects.last() + val radius = (rect.bottom - rect.top) / 4 + return Circle(rect.right - radius / 2, rect.top, radius) + } + + private var playerItemsHeight = 10f + private var playerItemsWidth = 10f + private var paddingPercentage = 0.8f - var tableHPadding = 0f - var tableVPadding = 0f + private var tableHPadding = 0f + private var tableVPadding = 0f val speed: Double = 1.0 val showVillainHands: Boolean = true + /*** + * Calculates the position of all elements to draw + */ fun setDimension(width: Float, height: Float) { this.width = width this.height = height @@ -39,15 +58,20 @@ class ReplayerConfiguration(var handHistory: HandHistory) { this.tableVPadding = height / playerPerColumn * 0.8f this.tableRect = RectF(tableHPadding, tableVPadding, width - tableHPadding, height - tableVPadding) + this.tableCornerRadius = (if (portrait) width else height) / 8 val pzHeight = height / playerPerColumn val pzWidth = width / playerPerRow this.playerItemsHeight = pzHeight / 3 - this.playerItemsWidth = pzWidth * this.paddingPercentage + this.playerItemsWidth = pzWidth * this.paddingPercentage + + val cardWidth = pzWidth * paddingPercentage / maxCards + this.cardSpecs = Size(cardWidth, cardWidth * 1.75f) + this.cardRadius = cardWidth / 4 // number of players in this order: bottom / left / top / right - val repartition = when (handHistory.numberOfPlayers) { + val repartition = when (this.handHistory.numberOfPlayers) { 2 -> mutableListOf(1, 0, 1, 0) 3 -> mutableListOf(1, 1, 0, 1) 4 -> mutableListOf(1, 1, 1, 1) @@ -59,43 +83,45 @@ class ReplayerConfiguration(var handHistory: HandHistory) { 10 -> mutableListOf(4, 1, 4, 1) else -> throw PAIllegalStateException("can't happen") } - if (portrait && handHistory.numberOfPlayers > 4) { repartition.reverse() } + if (portrait && this.handHistory.numberOfPlayers > 4) { repartition.reverse() } repartition.forEachIndexed { index, count -> val x = width / (count + 1) val y = height / (count + 1) - var xOffset = x - var yOffset = y + var rectCenterX = x + var rectCenterY = y var circleOffset = playerItemsHeight * 1.5f + var pIndex = -1 for (i in 1..count) { + pIndex++ when (index) { 0 -> { // bottom - xOffset = x * i - yOffset = height - this.tableVPadding + rectCenterX = x * i + rectCenterY = height - this.tableVPadding circleOffset *= -1 } 1 -> { // left - xOffset = this.tableHPadding - yOffset = height - y * i + rectCenterX = this.tableHPadding + rectCenterY = height - y * i } 2 -> { // top - xOffset = x * i - yOffset = this.tableVPadding + rectCenterX = x * i + rectCenterY = this.tableVPadding } 3 -> { // right - xOffset = width - this.tableHPadding - yOffset = y * i + rectCenterX = width - this.tableHPadding + rectCenterY = y * i } else -> throw PAIllegalStateException("can't happen") } - val left = xOffset - this.playerItemsWidth / 2 - val top = yOffset - this.playerItemsHeight / 2 - val right = xOffset + this.playerItemsWidth / 2 - val bottom = yOffset + this.playerItemsHeight / 2 + val left = rectCenterX - this.playerItemsWidth / 2 + val top = rectCenterY - this.playerItemsHeight / 2 + val right = rectCenterX + this.playerItemsWidth / 2 + val bottom = rectCenterY + this.playerItemsHeight / 2 this.playerStackRects.add(RectF(left, top, right, bottom)) // we give each text zone 1/3rd of the box height, leaving 1/3 for space @@ -104,10 +130,26 @@ class ReplayerConfiguration(var handHistory: HandHistory) { val bottomOffset = this.playerItemsHeight / (3 * 3 * 2) val fontSize = this.playerItemsHeight / 3 - this.playerNamePoints.add(TextPoint(xOffset, yOffset - bottomOffset, fontSize)) - this.playerStackPoints.add(TextPoint(xOffset, yOffset + this.playerItemsHeight / 3 + bottomOffset, fontSize)) + this.playerNamePoints.add(TextPoint(rectCenterX, rectCenterY - bottomOffset, fontSize)) + this.playerStackPoints.add(TextPoint(rectCenterX, rectCenterY + this.playerItemsHeight / 3, fontSize)) + + this.playerCircles.add(Circle(rectCenterX, rectCenterY - circleOffset, this.playerItemsHeight / 2)) + + val cardsUsed = this.handHistory.playerSetupForPosition(pIndex)?.cards?.size ?: 0 + val cardsRectangles = mutableListOf() + if (cardsUsed > 0) { + val cardWPaddingWidth = pzWidth / maxCards + val offSet = (cardsUsed / 2 - 0.5f) * cardWPaddingWidth - this.playerCircles.add(Circle(xOffset, yOffset - circleOffset, this.playerItemsHeight / 2)) + val cardCenterY = rectCenterY - circleOffset / 2 + for (c in 0 until cardsUsed) { + + val cardCenterX = rectCenterX - offSet + c * cardWPaddingWidth + val cardRect = RectF(cardCenterX - cardSpecs.width / 2, cardCenterY - cardSpecs.height / 2, cardCenterX + cardSpecs.width / 2, cardCenterY + cardSpecs.height / 2) + cardsRectangles.add(cardRect) + } + } + this.playerCardRects.add(cardsRectangles) } @@ -134,6 +176,10 @@ class ReplayerConfiguration(var handHistory: HandHistory) { return this.playerStackPoints[i] } + fun cardRects(i: Int): List { + return this.playerCardRects[i] + } + } 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 531491b8..154c37ff 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 @@ -16,12 +16,11 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { const val tableStrokeWidth = 30f const val playerStrokeWidth = 8f - const val tableCornerRadius = 100f -// const val stackRectRadius = 25f - private val tablePaint = Paint() - private val playerPaint = Paint() + private val strokePaint = Paint() private val fillPaint = Paint() + + private val tablePaint = Paint() private val textPaint = Paint() fun configurePaints(context: Context) { @@ -30,17 +29,16 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { tablePaint.strokeWidth = tableStrokeWidth tablePaint.color = context.getColor(R.color.green) - playerPaint.isAntiAlias = true - playerPaint.style = Paint.Style.STROKE - playerPaint.strokeWidth = playerStrokeWidth - playerPaint.color = context.getColor(R.color.green) + strokePaint.isAntiAlias = true + strokePaint.style = Paint.Style.STROKE + strokePaint.strokeWidth = playerStrokeWidth - fillPaint.color = context.getColor(R.color.green_darker) fillPaint.isAntiAlias = true textPaint.color = context.getColor(R.color.white) textPaint.textAlign = Paint.Align.CENTER textPaint.isAntiAlias = true + } /*** @@ -48,7 +46,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { */ fun initializeTable(config: ReplayerConfiguration, canvas: Canvas, context: Context) { - canvas.drawRoundRect(config.tableRect, this.tableCornerRadius, this.tableCornerRadius, this.tablePaint) + canvas.drawRoundRect(config.tableRect, config.tableCornerRadius, config.tableCornerRadius, this.tablePaint) val hh = config.handHistory val positions = Position.positionsPerPlayers(hh.numberOfPlayers) @@ -58,25 +56,46 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { // Stack zone val rect = config.stackRectForPlayer(i) val radius = (rect.bottom - rect.top) / 4 + + fillPaint.color = context.getColor(R.color.green_darker) canvas.drawRoundRect(config.stackRectForPlayer(i), radius, radius, this.fillPaint) - canvas.drawRoundRect(config.stackRectForPlayer(i), radius, radius, this.playerPaint) + strokePaint.color = context.getColor(R.color.green) + canvas.drawRoundRect(config.stackRectForPlayer(i), radius, radius, this.strokePaint) // Player portrait zone val circle = config.circleForPlayer(i) canvas.drawCircle(circle.x, circle.y, circle.radius, this.fillPaint) - canvas.drawCircle(circle.x, circle.y, circle.radius, this.playerPaint) + canvas.drawCircle(circle.x, circle.y, circle.radius, this.strokePaint) + // Player name val name = playerSetup?.player?.name ?: positions.elementAt(i).value val pnPoint = config.pointForPlayerName(i) this.textPaint.textSize = pnPoint.fontSize canvas.drawText(name, pnPoint.x, pnPoint.y, this.textPaint) + // Player stack playerSetup?.stack?.formatted?.let { stack -> val psPoint = config.pointForPlayerStack(i) this.textPaint.textSize = psPoint.fontSize canvas.drawText(stack, psPoint.x, psPoint.y, this.textPaint) } + // Dealer button + val dealerCircle = config.dealerCircle + fillPaint.color = context.getColor(R.color.red) + canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, fillPaint) + strokePaint.color = context.getColor(R.color.white) + canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, strokePaint) + canvas.drawText("D", dealerCircle.x, dealerCircle.y + this.textPaint.textSize / 3, this.textPaint) + + playerSetup?.cards?.let { cards -> + val cardRects = config.cardRects(i) + for (cardRect in cardRects) { + fillPaint.color = context.getColor(R.color.white) + canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint) + } + } + } } diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 4475753c..92c60918 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -34,6 +34,8 @@ #1E231E #FF5F57 + #FF7F79 + #C64943 #1b8ec8