Fixes cards display

hh
Laurent 6 years ago
parent 3ae8cb22c4
commit 1d9d301ae0
  1. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt
  2. 21
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt
  3. 28
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt

@ -157,7 +157,7 @@ open class Card : RealmObject() {
/*** /***
* Returns the formatted value of the card * Returns the formatted value of the card
*/ */
private val formattedValue: String val formattedValue: String
get() { return Value.format(this.value) } get() { return Value.format(this.value) }
/*** /***

@ -3,6 +3,7 @@ package net.pokeranalytics.android.ui.modules.handhistory.replayer
import android.graphics.RectF import android.graphics.RectF
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import timber.log.Timber
class ReplayerConfiguration(var handHistory: HandHistory) { class ReplayerConfiguration(var handHistory: HandHistory) {
@ -36,6 +37,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
private var playerItemsHeight = 10f private var playerItemsHeight = 10f
private var playerItemsWidth = 10f private var playerItemsWidth = 10f
private var paddingPercentage = 0.8f private var paddingPercentage = 0.8f
private var cardsPaddingPercentage = 0.9f
private var tableHPadding = 0f private var tableHPadding = 0f
private var tableVPadding = 0f private var tableVPadding = 0f
@ -47,6 +49,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
* Calculates the position of all elements to draw * Calculates the position of all elements to draw
*/ */
fun setDimension(width: Float, height: Float) { fun setDimension(width: Float, height: Float) {
Timber.d("Setting dimensions...")
this.width = width this.width = width
this.height = height this.height = height
@ -66,12 +69,13 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
this.playerItemsHeight = pzHeight / 3 this.playerItemsHeight = pzHeight / 3
this.playerItemsWidth = pzWidth * this.paddingPercentage this.playerItemsWidth = pzWidth * this.paddingPercentage
val cardWidth = pzWidth * paddingPercentage / maxCards val cardWidth = pzWidth * this.cardsPaddingPercentage / this.maxCards
this.cardSpecs = Size(cardWidth, cardWidth * 1.75f) this.cardSpecs = Size(cardWidth, cardWidth * 1.75f)
this.cardRadius = cardWidth / 4 this.cardRadius = cardWidth / 4
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 (this.handHistory.numberOfPlayers) { val repartition = when (playerCount) {
2 -> mutableListOf(1, 0, 1, 0) 2 -> mutableListOf(1, 0, 1, 0)
3 -> mutableListOf(1, 1, 0, 1) 3 -> mutableListOf(1, 1, 0, 1)
4 -> mutableListOf(1, 1, 1, 1) 4 -> mutableListOf(1, 1, 1, 1)
@ -83,8 +87,12 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
10 -> mutableListOf(4, 1, 4, 1) 10 -> mutableListOf(4, 1, 4, 1)
else -> throw PAIllegalStateException("can't happen") else -> throw PAIllegalStateException("can't happen")
} }
if (portrait && this.handHistory.numberOfPlayers > 4) { repartition.reverse() } if (repartition.sum() != playerCount) {
throw PAIllegalStateException("Problem in the $playerCount players repartition: $repartition")
}
if (portrait && playerCount > 4) { repartition.reverse() } // adjustment for portrait vs landscape
var pIndex = -1
repartition.forEachIndexed { index, count -> repartition.forEachIndexed { index, count ->
val x = width / (count + 1) val x = width / (count + 1)
@ -92,10 +100,11 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
var rectCenterX = x var rectCenterX = x
var rectCenterY = y var rectCenterY = y
var circleOffset = playerItemsHeight * 1.5f var circleOffset = playerItemsHeight * 1.75f
var pIndex = -1
for (i in 1..count) { for (i in 1..count) {
pIndex++
pIndex += 1
Timber.d("Creating dimensions for player $pIndex")
when (index) { when (index) {
0 -> { // bottom 0 -> { // bottom

@ -4,24 +4,28 @@ import android.content.Context
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Paint import android.graphics.Paint
import androidx.core.content.res.ResourcesCompat
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.handhistory.Street import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction
import net.pokeranalytics.android.util.extensions.formatted import net.pokeranalytics.android.util.extensions.formatted
import timber.log.Timber
class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
companion object { companion object {
const val tableStrokeWidth = 30f private const val tableStrokeWidth = 30f
const val playerStrokeWidth = 8f private const val playerStrokeWidth = 8f
private val strokePaint = Paint() private val strokePaint = Paint()
private val fillPaint = Paint() private val fillPaint = Paint()
private val tablePaint = Paint() private val tablePaint = Paint()
private val textPaint = Paint() private val textPaint = Paint()
private val cardTextPaint = Paint()
fun configurePaints(context: Context) { fun configurePaints(context: Context) {
tablePaint.isAntiAlias = true tablePaint.isAntiAlias = true
@ -39,6 +43,10 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
textPaint.textAlign = Paint.Align.CENTER textPaint.textAlign = Paint.Align.CENTER
textPaint.isAntiAlias = true textPaint.isAntiAlias = true
cardTextPaint.color = context.getColor(R.color.black)
cardTextPaint.typeface = ResourcesCompat.getFont(context, R.font.roboto_bold)
cardTextPaint.textAlign = Paint.Align.CENTER
cardTextPaint.isAntiAlias = true
} }
/*** /***
@ -47,10 +55,12 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
fun initializeTable(config: ReplayerConfiguration, canvas: Canvas, context: Context) { fun initializeTable(config: ReplayerConfiguration, canvas: Canvas, context: Context) {
canvas.drawRoundRect(config.tableRect, config.tableCornerRadius, config.tableCornerRadius, this.tablePaint) canvas.drawRoundRect(config.tableRect, config.tableCornerRadius, config.tableCornerRadius, this.tablePaint)
cardTextPaint.textSize = config.cardSpecs.height * .38f
val hh = config.handHistory val hh = config.handHistory
val positions = Position.positionsPerPlayers(hh.numberOfPlayers) val positions = Position.positionsPerPlayers(hh.numberOfPlayers)
for (i in 0 until hh.numberOfPlayers) { for (i in 0 until hh.numberOfPlayers) {
Timber.d("Getting player $i setup ")
val playerSetup = hh.playerSetupForPosition(i) val playerSetup = hh.playerSetupForPosition(i)
// Stack zone // Stack zone
@ -88,12 +98,20 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, strokePaint) canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, strokePaint)
canvas.drawText("D", dealerCircle.x, dealerCircle.y + this.textPaint.textSize / 3, this.textPaint) canvas.drawText("D", dealerCircle.x, dealerCircle.y + this.textPaint.textSize / 3, this.textPaint)
playerSetup?.cards?.let { cards ->
val cardRects = config.cardRects(i) val cardRects = config.cardRects(i)
for (cardRect in cardRects) { playerSetup?.cards?.forEachIndexed { j, card ->
val cardRect = cardRects[j]
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)
}
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)
} }
} }

Loading…
Cancel
Save