|
|
|
|
@ -5,6 +5,7 @@ import android.graphics.* |
|
|
|
|
import androidx.core.content.res.ResourcesCompat |
|
|
|
|
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
import net.pokeranalytics.android.model.handhistory.Position |
|
|
|
|
import net.pokeranalytics.android.model.handhistory.Street |
|
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.Action |
|
|
|
|
@ -66,10 +67,78 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
cardTextPaint.isAntiAlias = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun drawTable(config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
// base |
|
|
|
|
initializeTable(config, canvas, context) |
|
|
|
|
|
|
|
|
|
val step = config.currentStep |
|
|
|
|
val street: Street |
|
|
|
|
var computedAction: ComputedAction? = null |
|
|
|
|
when (step) { |
|
|
|
|
is Street -> { |
|
|
|
|
street = step |
|
|
|
|
config.lastActionBeforeStreet(street)?.let { |
|
|
|
|
drawPot(it, config, canvas, context) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
is ComputedAction -> { |
|
|
|
|
street = step.street |
|
|
|
|
computedAction = step |
|
|
|
|
drawPot(step, config, canvas, context) |
|
|
|
|
} |
|
|
|
|
else -> throw PAIllegalStateException("Step unmanaged: $step") |
|
|
|
|
} |
|
|
|
|
drawBoardCards(street, config, canvas, context) |
|
|
|
|
|
|
|
|
|
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 -> {} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// show player cards |
|
|
|
|
config.activePositions.forEach { |
|
|
|
|
drawCards(it, config, canvas, context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* WARNING: Avoid instancing objects here, as it's called from onDraw method |
|
|
|
|
*/ |
|
|
|
|
fun initializeTable(config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
private fun initializeTable(config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
canvas.drawColor(context.getColor(backgroundColor)) |
|
|
|
|
|
|
|
|
|
@ -83,7 +152,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
|
|
|
|
|
// drawCards(i, config, canvas, context) |
|
|
|
|
drawPlayerRectangle(i,false, config, canvas, context) |
|
|
|
|
drawPositionAndStack(i, playerSetup?.stack, config, canvas, context) |
|
|
|
|
// drawPositionAndStack(i, playerSetup?.stack, config, canvas, context) |
|
|
|
|
|
|
|
|
|
drawPlayerCircle(i, config, canvas, context) |
|
|
|
|
|
|
|
|
|
@ -121,8 +190,8 @@ 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) |
|
|
|
|
// clearText(chipText, canvas) |
|
|
|
|
// clearCircle(chipCircle, canvas) |
|
|
|
|
|
|
|
|
|
this.fillPaint.color = context.getColor(R.color.green) |
|
|
|
|
canvas.drawCircle(chipCircle.x, chipCircle.y, chipCircle.radius, this.fillPaint) |
|
|
|
|
@ -139,19 +208,19 @@ 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 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) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
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 cardRects = config.cardRects(playerIndex) |
|
|
|
|
@ -195,12 +264,12 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun drawPlayerPositionAndStack(action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: 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) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun drawAction(action: ComputedAction, highlighted: Boolean = true, config: ReplayerConfiguration, canvas: Canvas, context: 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) |
|
|
|
|
@ -306,7 +375,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
canvas.drawText(actionName, pnPoint.x, pnPoint.y, this.textPaint) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun drawStreet(street: Street, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
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 -> |
|
|
|
|
@ -314,18 +383,18 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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) |
|
|
|
|
} |
|
|
|
|
// 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) |
|
|
|
|
} |
|
|
|
|
// config.lastActionBeforeStreet(street)?.let { action -> |
|
|
|
|
// drawPlayerPositionAndStack(action, config, canvas, context) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -339,7 +408,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
this.textPaint.textSize = tpTextPoint.fontSize |
|
|
|
|
this.textPaint.color = context.getColor(R.color.white) |
|
|
|
|
|
|
|
|
|
clearText(config.totalPotTextPoint, canvas) |
|
|
|
|
// clearText(config.totalPotTextPoint, canvas) |
|
|
|
|
canvas.drawText(totalPot.formatted, config.totalPotTextPoint.x, config.totalPotTextPoint.y, this.textPaint) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|