Adds various chip colors + fix pot display

hh
Laurent 5 years ago
parent d60dcbb69f
commit aea0a48674
  1. 3
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt
  2. 122
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt
  3. 12
      app/src/main/res/values/colors.xml

@ -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

@ -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<ChipColor> 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<Double, ChipColor>()
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

@ -38,8 +38,6 @@
<color name="card_fill">#53775C</color>
<color name="red">#FF5F57</color>
<color name="light_red">#FF7F79</color>
<color name="dark_red">#C64943</color>
<color name="blue">#1b8ec8</color>
@ -61,7 +59,15 @@
<color name="player_color_8">#ff573d</color>
<color name="player_color_9">#ff971e</color>
<color name="diamond">#ff971e</color>
<color name="clover">#479E5D</color>
<color name="chip_dash_color_2">#938647</color>
<color name="chip_dash_color_3">#4A9759</color>
<color name="chip_dash_color_4">#528C81</color>
<color name="chip_dash_color_5">#1D6598</color>
<color name="chip_dash_color_6">#36315C</color>
<color name="chip_dash_color_7">#9C449C</color>
<color name="chip_dash_color_8">#9E483B</color>
<color name="chip_dash_color_9">#7C572D</color>
</resources>

Loading…
Cancel
Save