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 bb276f5f..084b8098 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 @@ -13,7 +13,6 @@ 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 class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { @@ -93,39 +92,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { val hh = config.handHistory for (i in 0 until hh.numberOfPlayers) { - Timber.d("Getting player $i setup ") - - // draw player rectangles with action or name + stack - val actionType = computedAction?.action?.type - if (computedAction?.positionIndex == i && actionType != null) { - drawPlayerRectangle(i, true, config, canvas, context) - drawAction(i, actionType, config, canvas, context) - } else { - val remainingStack = config.playerRemainingStack(i) - drawPlayerRectangle(i, false, config, canvas, context) - drawPositionAndStack(i, remainingStack, config, canvas, context) - } - - // draw chips - // when does a chip appears ? - // when the player has put some money during the current street - config.lastSignificantActionOfPlayer(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 -> {} - } - } - + drawPlayerShapes(i, computedAction, config, canvas, context) } // show player cards @@ -135,6 +102,46 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } + private fun drawPlayerShapes(i: Int, computedAction: ComputedAction?, config: ReplayerConfiguration, canvas: Canvas, context: Context) { + + // draw player rectangles with action or name + stack + val actionType = computedAction?.action?.type + if (computedAction?.positionIndex == i && actionType != null) { + drawPlayerRectangle(i, true, config, canvas, context) + drawAction(i, actionType, config, canvas, context) + } else { + val remainingStack = config.playerRemainingStack(i) + drawPlayerRectangle(i, false, config, canvas, context) + drawPositionAndStack(i, remainingStack, config, canvas) + } + + drawPlayerChips(i, config, canvas, context) + + } + + /*** + * Draw chips + * A chip should appears when the player has put some money during the current street + */ + private fun drawPlayerChips(i: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { + + config.lastSignificantActionOfPlayer(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 -> {} + } + } + } + /*** * WARNING: Avoid instancing objects here, as it's called from onDraw method */ @@ -147,28 +154,13 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { val hh = config.handHistory for (i in 0 until hh.numberOfPlayers) { - Timber.d("Getting player $i setup ") - val playerSetup = hh.playerSetupForPosition(i) - -// drawCards(i, config, canvas, context) drawPlayerRectangle(i,false, config, canvas, context) -// drawPositionAndStack(i, playerSetup?.stack, config, canvas, context) - drawPlayerCircle(i, config, canvas, context) - drawDealerButton(config, canvas, context) - } } - fun drawCards(indexes: List, config: ReplayerConfiguration, canvas: Canvas, context: Context) { -// val hh = config.handHistory - for (i in indexes) { - drawCards(i, config, canvas, context) - } - } - private fun drawDealerButton(config: ReplayerConfiguration, canvas: Canvas, context: Context) { // Dealer button @@ -190,9 +182,6 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { 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) canvas.drawCircle(chipCircle.x, chipCircle.y, chipCircle.radius, this.fillPaint) this.chipBorderPaint.color = context.getColor(R.color.white) @@ -208,18 +197,6 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } -// private fun clearText(textPoint: ReplayerConfiguration.TextPoint, canvas: Canvas) { -// this.clearRect(textPoint.toRect(), canvas) -// } -// -// private fun clearCircle(circle: ReplayerConfiguration.Circle, canvas: Canvas) { -// this.clearRect(circle.toRect(), canvas) -// } -// -// private fun clearRect(rect: RectF, canvas: Canvas) { -// canvas.drawRect(rect, this.backgroundPaint) -// } - private fun drawCards(playerIndex: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { val playerSetup = config.handHistory.playerSetupForPosition(playerIndex) @@ -242,12 +219,6 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } -// private fun clearCards(playerIndex: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { -// config.cardRects(playerIndex).forEach { -// clearRect(it, canvas) -// } -// } - private fun drawCard(card: Card, cardRect: RectF, config: ReplayerConfiguration, canvas: Canvas, context: Context) { fillPaint.color = context.getColor(R.color.white) @@ -264,44 +235,10 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } - private fun drawPlayerPositionAndStack(action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { - drawPlayerRectangle(action.positionIndex,false, config, canvas, context) - drawPositionAndStack(action.positionIndex, action.stackAfterActing, config, canvas, context) - } - - private fun drawAction(action: ComputedAction, highlighted: Boolean = true, config: ReplayerConfiguration, canvas: Canvas, context: Context) { - - // show that action is on the player by highlighting - drawPlayerRectangle(action.positionIndex, highlighted, config, canvas, context) - - // redraw previous player rectangle - action.previousAction?.let { previousAction -> - drawPlayerPositionAndStack(previousAction, config, canvas, context) - } - - // show action name : call, bet, check... - drawAction(action.positionIndex, action.action.type!!, config, canvas, context) - - // show chips image + text, if applicable - when { - action.action.type?.isSignificant == true -> { - action.action.amount?.let { amount -> - drawChip(amount, action.positionIndex, config, canvas, context) - drawPot(action, config, canvas, context) - } - } - action.action.type?.isCall == true -> { - action.getStreetLastSignificantAction()?.action?.amount?.let { amount -> - drawChip(amount, action.positionIndex, config, canvas, context) - drawPot(action, config, canvas, context) - } - } -// action.action.type == Action.Type.FOLD -> { -// clearCards(action.positionIndex, config, canvas, context) -// } - } - - } +// private fun drawPlayerPositionAndStack(action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { +// drawPlayerRectangle(action.positionIndex,false, config, canvas, context) +// drawPositionAndStack(action.positionIndex, action.stackAfterActing, config, canvas, context) +// } private fun drawPlayerCircle(i: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { @@ -331,26 +268,36 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { } - /*** + /*** * [i] is the player position in the hand */ - private fun drawPlayerRectangle(i: Int, 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 rectRadius = (rect.bottom - rect.top) / 4 val color = if (highlighted) R.color.kaki else R.color.green_darker fillPaint.color = context.getColor(color) - canvas.drawRoundRect(config.stackRectForPlayer(i), rectRadius, rectRadius, this.fillPaint) + canvas.drawRoundRect( + config.stackRectForPlayer(i), + rectRadius, + rectRadius, + this.fillPaint + ) 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 + ) 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) { val hh = config.handHistory // Player position @@ -382,20 +329,6 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { drawCard(cards[index], rectF, config, canvas, context) } - // Clear all chips -// val hh = config.handHistory -// for (i in 0 until hh.numberOfPlayers) { -// val pc = config.chipCircle(i) -// clearCircle(pc, canvas) -// val pct = config.chipText(i) -// clearText(pct, canvas) -// } - - // Clear last action before street -// config.lastActionBeforeStreet(street)?.let { action -> -// drawPlayerPositionAndStack(action, config, canvas, context) -// } - } private fun drawPot(action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { @@ -408,7 +341,6 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { this.textPaint.textSize = tpTextPoint.fontSize this.textPaint.color = context.getColor(R.color.white) -// clearText(config.totalPotTextPoint, canvas) canvas.drawText(totalPot.formatted, config.totalPotTextPoint.x, config.totalPotTextPoint.y, this.textPaint) }