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 97dc9bb5..2e73c8e6 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 @@ -30,6 +30,9 @@ class ReplayerConfiguration(var handHistory: HandHistory) { private var currentFrame = 0 + val isLastFrame: Boolean + get() { return this.currentFrame == numberOfFramesForCurrentStep - 1 } + val shouldShowAdditionalFrame: Boolean get() { return this.currentFrame < this.numberOfFramesForCurrentStep 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 e1411f3a..7cddc98a 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 @@ -12,6 +12,29 @@ import net.pokeranalytics.android.model.realm.handhistory.Card import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction import net.pokeranalytics.android.util.RANDOM_PLAYER import net.pokeranalytics.android.util.extensions.formatted +import timber.log.Timber + +data class ChipColor(val fillColor: Int, val borderColor: Int) { + companion object { + val all: List by lazy { + listOf( + ChipColor(R.color.white, R.color.grey), + ChipColor(R.color.green, R.color.white), + ChipColor(R.color.player_color_2, R.color.chip_dash_color_2), + ChipColor(R.color.player_color_3, R.color.chip_dash_color_3), + ChipColor(R.color.player_color_4, R.color.chip_dash_color_4), + ChipColor(R.color.player_color_5, R.color.chip_dash_color_5), + ChipColor(R.color.player_color_6, R.color.chip_dash_color_6), + ChipColor(R.color.player_color_7, R.color.chip_dash_color_7), + ChipColor(R.color.player_color_8, R.color.chip_dash_color_8), + ChipColor(R.color.player_color_9, R.color.chip_dash_color_9), + ChipColor(R.color.chip_dash_color_7, R.color.player_color_2), + ChipColor(R.color.player_color_6, R.color.player_color_9) + ) + } + + } +} class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { @@ -32,8 +55,12 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { private val cardStrokePaint = Paint() private val chipBorderPaint = Paint() + private val colorsByAmount = hashMapOf() + fun configurePaints(context: Context) { + this.colorsByAmount.clear() + backgroundPaint.color = context.getColor(backgroundColor) tablePaint.isAntiAlias = true @@ -87,8 +114,9 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } // draw pot - val potAction = computedAction ?: config.lastActionBeforeStreet(street) - potAction?.let { drawPot(potAction, config, canvas, context) } + drawPot(street, computedAction, config, canvas, context) +// val potAction = computedAction ?: config.lastActionBeforeStreet(street) +// potAction?.let { drawPot(potAction, config, canvas, context) } // draw board drawBoardCards(street, config, canvas, context) @@ -129,9 +157,12 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { when (config.currentStep) { is Street -> { // animate chips - if (config.lastChipCommittingActionOfPlayer(i) != null) { - val circle = config.animatedChipCircle(i) - drawChipCircle(circle, canvas, context) + if (!config.isLastFrame) { + lastCommitedAmount(i, config)?.let { amount -> + val color = colorForAmount(amount) + val circle = config.animatedChipCircle(i) + drawChipCircle(circle, color, canvas, context) + } } } is ComputedAction -> { @@ -142,22 +173,33 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } private fun drawChipForAction(i: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { + lastCommitedAmount(i, config)?.let { amount -> + drawChip(amount, i, config, canvas, context) + } - config.lastChipCommittingActionOfPlayer(i)?.let { action -> - when { - action.action.type?.isSignificant == true -> { - action.action.amount?.let { amount -> - drawChip(amount, action.positionIndex, config, canvas, context) - } - } - action.action.type?.isCall == true -> { - action.getStreetLastSignificantAction()?.action?.amount?.let { amount -> - drawChip(amount, action.positionIndex, config, canvas, context) - } - } - else -> {} - } +// config.lastChipCommittingActionOfPlayer(i)?.let { action -> +// when { +// action.action.type?.isSignificant == true -> { +// action.action.amount?.let { amount -> +// drawChip(amount, action.positionIndex, config, canvas, context) +// } +// } +// action.action.type?.isCall == true -> { +// action.getStreetLastSignificantAction()?.action?.amount?.let { amount -> +// drawChip(amount, action.positionIndex, config, canvas, context) +// } +// } +// else -> {} +// } +// } + } + + private fun lastCommitedAmount(i: Int, config: ReplayerConfiguration): Double? { + var committingAction = config.lastChipCommittingActionOfPlayer(i) + if (committingAction?.action?.type?.isCall == true) { + committingAction = committingAction.getStreetLastSignificantAction() } + return committingAction?.action?.amount } /*** @@ -200,7 +242,8 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { private fun drawChip(amount: Double, chipText: ReplayerConfiguration.TextPoint, chipCircle: ReplayerConfiguration.Circle, canvas: Canvas, context: Context) { - drawChipCircle(chipCircle, canvas, context) + val color = colorForAmount(amount) + drawChipCircle(chipCircle, color, canvas, context) this.textPaint.textSize = chipText.fontSize this.textPaint.color = context.getColor(R.color.white) @@ -208,11 +251,21 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } - private fun drawChipCircle(chipCircle: ReplayerConfiguration.Circle, canvas: Canvas, context: Context) { + private fun colorForAmount(amount: Double): ChipColor { + + this.colorsByAmount[amount]?.let { return it } + + val index = this.colorsByAmount.size % ChipColor.all.size + val color = ChipColor.all[index] + this.colorsByAmount[amount] = color + return color + } - this.fillPaint.color = context.getColor(R.color.green) + private fun drawChipCircle(chipCircle: ReplayerConfiguration.Circle, chipColor: ChipColor, canvas: Canvas, context: Context) { + + this.fillPaint.color = context.getColor(chipColor.fillColor) canvas.drawCircle(chipCircle.x, chipCircle.y, chipCircle.radius, this.fillPaint) - this.chipBorderPaint.color = context.getColor(R.color.white) + this.chipBorderPaint.color = context.getColor(chipColor.borderColor) val chipBorderStrokeWidth = chipCircle.radius / 3f this.chipBorderPaint.strokeWidth = chipBorderStrokeWidth @@ -363,17 +416,28 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { private fun drawBoardCards(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) + // when the step is the street, we wait for the last frame to display the board + if ((config.currentStep == street && config.isLastFrame) || config.currentStep != street) { + + val cards = config.handHistory.cardsForStreet(street) + config.boardCardRects.take(street.totalBoardCards).forEachIndexed { index, rectF -> + drawCard(cards[index], rectF, config, canvas, context) + } + } } - private fun drawPot(action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { + private fun drawPot(street: Street, computedAction: ComputedAction?, config: ReplayerConfiguration, canvas: Canvas, context: Context) { + + val pot = config.actionList.potSizeForStreet(street) - val pot = config.actionList.potSizeForStreet(action.street) - val totalPot = config.actionList.totalPotSize(action.action.index + 1) + val action = computedAction ?: config.lastActionBeforeStreet(street) + val totalPot = action?.let { + config.actionList.totalPotSize(it.action.index + 1) + } ?: run { + pot + } drawChip(pot, config.potTextPoint, config.potChipCircle, canvas, context) val tpTextPoint = config.totalPotTextPoint diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ec778a17..313d7062 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -38,8 +38,6 @@ #53775C #FF5F57 - #FF7F79 - #C64943 #1b8ec8 @@ -61,7 +59,15 @@ #ff573d #ff971e - #ff971e #479E5D + #938647 + #4A9759 + #528C81 + #1D6598 + #36315C + #9C449C + #9E483B + #7C572D +