clear logic

hh
Laurent 5 years ago
parent 3ab853c693
commit c32d0cf402
  1. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  3. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  4. 14
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt
  5. 152
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt

@ -581,6 +581,12 @@ class ActionList(var listener: ActionListListener? = null) : ArrayList<ComputedA
} }
} }
fun potSizeForStreet(street: Street): Double {
val firstIndexOfStreet = this.firstOrNull { it.street == street }?.action?.index
?: this.size
return this.totalPotSize(firstIndexOfStreet)
}
override fun totalPotSize(index: Int): Double { override fun totalPotSize(index: Int): Double {
return this.handHistory.anteSum + this.take(index).sumByDouble { it.action.effectiveAmount } return this.handHistory.anteSum + this.take(index).sumByDouble { it.action.effectiveAmount }
} }

@ -309,7 +309,7 @@ class ComputedAction(var manager: ActionManager,
get() { return this.action.position } get() { return this.action.position }
override fun draw(configuration: ReplayerConfiguration, canvas: Canvas, context: Context) { override fun draw(configuration: ReplayerConfiguration, canvas: Canvas, context: Context) {
TableDrawer.drawAction(this.positionIndex, this, configuration, canvas, context) TableDrawer.drawAction(this, true, configuration, canvas, context)
} }
override fun frames( override fun frames(

@ -406,9 +406,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
* Returns the formatted pot size at the given [street] * Returns the formatted pot size at the given [street]
*/ */
private fun formattedPotSizeForStreet(street: Street): String { private fun formattedPotSizeForStreet(street: Street): String {
val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index val potSize = this.sortedActions.potSizeForStreet(street)
?: this.sortedActions.size
val potSize = this.sortedActions.totalPotSize(firstIndexOfStreet)
return if (potSize > 0) potSize.formatted else "" // "" required otherwise random values come up return if (potSize > 0) potSize.formatted else "" // "" required otherwise random values come up
} }

@ -16,8 +16,16 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
} }
data class Size(var width: Float, var height: Float) data class Size(var width: Float, var height: Float)
data class Circle(var x: Float, var y: Float, var radius: 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) fun toRect(): RectF {
return RectF(x - radius, y - radius, x + radius, y + radius)
}
}
data class TextPoint(var x: Float, var y: Float, var fontSize: Float) {
fun toRect(): RectF {
return RectF(x - 2 * fontSize, y - fontSize, x + 2 * fontSize, y)
}
}
private val maxCards = 5 private val maxCards = 5
@ -49,7 +57,7 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
get() { get() {
val rect = this.playerStackRects.last() val rect = this.playerStackRects.last()
val radius = (rect.bottom - rect.top) / 4 val radius = (rect.bottom - rect.top) / 4
return Circle(rect.right - radius / 2, rect.top, radius) return Circle(rect.left, rect.bottom, radius)
} }
private var playerItemsHeight = 10f private var playerItemsHeight = 10f

@ -22,6 +22,8 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
private const val playerStrokeWidth = 8f private const val playerStrokeWidth = 8f
private const val cardStrokeWidth = 8f private const val cardStrokeWidth = 8f
private val backgroundColor = R.color.green_darker
private val backgroundPaint = Paint()
private val strokePaint = Paint() private val strokePaint = Paint()
private val fillPaint = Paint() private val fillPaint = Paint()
@ -32,6 +34,9 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
private val chipBorderPaint = Paint() private val chipBorderPaint = Paint()
fun configurePaints(context: Context) { fun configurePaints(context: Context) {
backgroundPaint.color = context.getColor(backgroundColor)
tablePaint.isAntiAlias = true tablePaint.isAntiAlias = true
tablePaint.style = Paint.Style.STROKE tablePaint.style = Paint.Style.STROKE
tablePaint.strokeWidth = tableStrokeWidth tablePaint.strokeWidth = tableStrokeWidth
@ -65,66 +70,76 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
*/ */
fun initializeTable(config: ReplayerConfiguration, canvas: Canvas, context: Context) { fun initializeTable(config: ReplayerConfiguration, canvas: Canvas, context: Context) {
canvas.drawColor(context.getColor(backgroundColor))
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 this.cardTextPaint.textSize = config.cardSpecs.height * .38f
val hh = config.handHistory val hh = config.handHistory
for (i in 0 until hh.numberOfPlayers) { for (i in 0 until hh.numberOfPlayers) {
Timber.d("Getting player $i setup ") Timber.d("Getting player $i setup ")
val playerSetup = hh.playerSetupForPosition(i) val playerSetup = hh.playerSetupForPosition(i)
drawPlayerRectangle(i, playerSetup?.stack, false, config, canvas, context) drawPlayerRectangle(i,false, config, canvas, context)
drawPositionAndStack(i, playerSetup?.stack, config, canvas, context)
// Player portrait zone
val circle = config.circleForPlayer(i)
val radius = circle.radius
canvas.drawCircle(circle.x, circle.y, radius, this.fillPaint)
canvas.drawCircle(circle.x, circle.y, radius, this.strokePaint)
val playerInitials = playerSetup?.player?.initials ?: RANDOM_PLAYER
this.textPaint.textSize = radius
canvas.drawText(playerInitials, circle.x, circle.y + radius * 0.4f, this.textPaint)
// Player picture
playerSetup?.player?.picture?.let { picturePath ->
val pictureBitmap = RoundedBitmapDrawableFactory.create(context.resources, picturePath)
pictureBitmap.setAntiAlias(true)
pictureBitmap.cornerRadius = circle.radius
pictureBitmap.bitmap?.let { bitmap ->
val pictureRect = RectF(circle.x - radius, circle.y - radius, circle.x + radius, circle.y + radius)
canvas.drawBitmap(bitmap, null, pictureRect, null)
}
}
// Dealer button drawPlayerCircle(i, config, canvas, context)
val dealerCircle = config.dealerCircle
this.fillPaint.color = context.getColor(R.color.red)
canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, fillPaint)
this.strokePaint.color = context.getColor(R.color.white)
canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, strokePaint)
this.textPaint.textSize = dealerCircle.radius
canvas.drawText("D", dealerCircle.x, dealerCircle.y + this.textPaint.textSize / 3, this.textPaint)
drawCards(i, config, canvas, context) drawDealerButton(config, canvas, context)
// val blinds = config.actionList.filter { it.action.type?.isBlind ?: false } drawCards(i, config, canvas, context)
// blinds.forEach { action ->
// drawAction(i, action, config, canvas, context)
// }
val chipCircle = config.chipCircle(i) // val chipCircle = config.chipCircle(i)
val chipText = config.chipText(i) // val chipText = config.chipText(i)
drawChip(2000.0, chipText, chipCircle, canvas, context) // drawChip(2000.0, chipText, chipCircle, canvas, context)
drawStreet(Street.RIVER, config, canvas, context) drawStreet(Street.RIVER, config, canvas, context)
drawPot(100.0, 200.0, config, canvas, context) // drawPot(100.0, 200.0, config, canvas, context)
}
val blinds = config.actionList.filter { it.action.type?.isBlind ?: false }
blinds.forEach { action ->
action.action.amount?.let { amount ->
drawChip(amount, action.positionIndex, config, canvas, context)
}
val pot = config.actionList.potSizeForStreet(action.street)
val totalPot = config.actionList.totalPotSize(action.action.index + 1)
drawPot(pot, totalPot, config, canvas, context)
// drawAction(action, false, config, canvas, context)
} }
} }
private fun drawDealerButton(config: ReplayerConfiguration, canvas: Canvas, context: Context) {
// Dealer button
val dealerCircle = config.dealerCircle
this.fillPaint.color = context.getColor(R.color.red)
canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, fillPaint)
this.strokePaint.color = context.getColor(R.color.white)
canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, strokePaint)
this.textPaint.textSize = dealerCircle.radius
canvas.drawText("D", dealerCircle.x, dealerCircle.y + this.textPaint.textSize / 3, this.textPaint)
}
private fun drawChip(amount: Double, playerIndex: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) {
val circle = config.chipCircle(playerIndex)
val text = config.chipText(playerIndex)
drawChip(amount, text, circle, canvas, context)
}
private fun drawChip(amount: Double, chipText: ReplayerConfiguration.TextPoint, chipCircle: ReplayerConfiguration.Circle, canvas: Canvas, context: Context) { private fun drawChip(amount: Double, chipText: ReplayerConfiguration.TextPoint, chipCircle: ReplayerConfiguration.Circle, canvas: Canvas, context: Context) {
clearText(chipText, canvas)
clearCircle(chipCircle, canvas)
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) this.chipBorderPaint.color = context.getColor(R.color.white)
@ -140,6 +155,18 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
private fun clearText(textPoint: ReplayerConfiguration.TextPoint, canvas: Canvas) {
this.clearZone(textPoint.toRect(), canvas)
}
private fun clearCircle(circle: ReplayerConfiguration.Circle, canvas: Canvas) {
this.clearZone(circle.toRect(), canvas)
}
private fun clearZone(rect: RectF, canvas: Canvas) {
canvas.drawRect(rect, this.backgroundPaint)
}
private fun drawCards(playerIndex: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { private fun drawCards(playerIndex: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) {
val playerSetup = config.handHistory.playerSetupForPosition(playerIndex) val playerSetup = config.handHistory.playerSetupForPosition(playerIndex)
@ -178,13 +205,13 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
fun drawAction(i: Int, action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { fun drawAction(action: ComputedAction, highlighted: Boolean = true, config: ReplayerConfiguration, canvas: Canvas, context: Context) {
// show that action is on the player by highlighting // show that action is on the player by highlighting
drawPlayerRectangle(i, null, true, config, canvas, context) drawPlayerRectangle(action.positionIndex, highlighted, config, canvas, context)
// show action name : call, bet, check... // show action name : call, bet, check...
drawAction(i, action.action.type!!, config, canvas, context) drawAction(action.positionIndex, action.action.type!!, config, canvas, context)
// show chips image + text, if applicable // show chips image + text, if applicable
@ -192,10 +219,38 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
/*** private fun drawPlayerCircle(i: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) {
val playerSetup = config.handHistory.playerSetupForPosition(i)
// Player portrait zone
val circle = config.circleForPlayer(i)
val radius = circle.radius
this.fillPaint.color = context.getColor(R.color.green_darker)
canvas.drawCircle(circle.x, circle.y, radius, this.fillPaint)
this.strokePaint.color = context.getColor(R.color.green)
canvas.drawCircle(circle.x, circle.y, radius, this.strokePaint)
val playerInitials = playerSetup?.player?.initials ?: RANDOM_PLAYER
this.textPaint.textSize = radius
canvas.drawText(playerInitials, circle.x, circle.y + radius * 0.4f, this.textPaint)
// Player picture
playerSetup?.player?.picture?.let { picturePath ->
val pictureBitmap = RoundedBitmapDrawableFactory.create(context.resources, picturePath)
pictureBitmap.setAntiAlias(true)
pictureBitmap.cornerRadius = circle.radius
pictureBitmap.bitmap?.let { bitmap ->
val pictureRect = RectF(circle.x - radius, circle.y - radius, circle.x + radius, circle.y + radius)
canvas.drawBitmap(bitmap, null, pictureRect, null)
}
}
}
/***
* [i] is the player position in the hand * [i] is the player position in the hand
*/ */
private fun drawPlayerRectangle(i: Int, stack: Double?, highlighted: Boolean, config: ReplayerConfiguration, canvas: Canvas, context: Context) { private fun drawPlayerRectangle(i: Int, highlighted: Boolean, config: ReplayerConfiguration, canvas: Canvas, context: Context) {
val rect = config.stackRectForPlayer(i) val rect = config.stackRectForPlayer(i)
val rectRadius = (rect.bottom - rect.top) / 4 val rectRadius = (rect.bottom - rect.top) / 4
@ -206,8 +261,9 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
strokePaint.color = context.getColor(R.color.green) strokePaint.color = context.getColor(R.color.green)
canvas.drawRoundRect(config.stackRectForPlayer(i), rectRadius, rectRadius, this.strokePaint) canvas.drawRoundRect(config.stackRectForPlayer(i), rectRadius, rectRadius, this.strokePaint)
drawPositionAndStack(i, stack, config, canvas, context) if (i == config.handHistory.heroIndex) { // refresh dealer button
drawDealerButton(config, canvas, context)
}
} }
private fun drawPositionAndStack(i: Int, stack: Double?, config: ReplayerConfiguration, canvas: Canvas, context: Context) { private fun drawPositionAndStack(i: Int, stack: Double?, config: ReplayerConfiguration, canvas: Canvas, context: Context) {
@ -243,12 +299,14 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
fun drawPot(pot: Double, totalPot: Double, config: ReplayerConfiguration, canvas: Canvas, context: Context) { private fun drawPot(pot: Double, totalPot: Double, config: ReplayerConfiguration, canvas: Canvas, context: Context) {
drawChip(pot, config.potTextPoint, config.potChipCircle, canvas, context) drawChip(pot, config.potTextPoint, config.potChipCircle, canvas, context)
val tpTextPoint = config.totalPotTextPoint val tpTextPoint = config.totalPotTextPoint
this.textPaint.textSize = tpTextPoint.fontSize this.textPaint.textSize = tpTextPoint.fontSize
this.textPaint.color = context.getColor(R.color.white) this.textPaint.color = context.getColor(R.color.white)
clearText(config.totalPotTextPoint, canvas)
canvas.drawText(totalPot.formatted, config.totalPotTextPoint.x, config.totalPotTextPoint.y, this.textPaint) canvas.drawText(totalPot.formatted, config.totalPotTextPoint.x, config.totalPotTextPoint.y, this.textPaint)
} }

Loading…
Cancel
Save