|
|
|
@ -4,10 +4,13 @@ import android.content.Context |
|
|
|
import android.graphics.Bitmap |
|
|
|
import android.graphics.Bitmap |
|
|
|
import android.graphics.Canvas |
|
|
|
import android.graphics.Canvas |
|
|
|
import android.graphics.Paint |
|
|
|
import android.graphics.Paint |
|
|
|
|
|
|
|
import android.graphics.RectF |
|
|
|
import androidx.core.content.res.ResourcesCompat |
|
|
|
import androidx.core.content.res.ResourcesCompat |
|
|
|
|
|
|
|
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.model.handhistory.Position |
|
|
|
import net.pokeranalytics.android.model.handhistory.Position |
|
|
|
import net.pokeranalytics.android.model.handhistory.Street |
|
|
|
import net.pokeranalytics.android.model.handhistory.Street |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.Action |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.Card |
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.Card |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction |
|
|
|
import net.pokeranalytics.android.util.RANDOM_PLAYER |
|
|
|
import net.pokeranalytics.android.util.RANDOM_PLAYER |
|
|
|
@ -65,40 +68,30 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
cardTextPaint.textSize = config.cardSpecs.height * .38f |
|
|
|
cardTextPaint.textSize = config.cardSpecs.height * .38f |
|
|
|
|
|
|
|
|
|
|
|
val hh = config.handHistory |
|
|
|
val hh = config.handHistory |
|
|
|
val positions = Position.positionsPerPlayers(hh.numberOfPlayers) |
|
|
|
|
|
|
|
for (i in 0 until hh.numberOfPlayers) { |
|
|
|
for (i in 0 until hh.numberOfPlayers) { |
|
|
|
val isHero = (hh.heroIndex == i) |
|
|
|
|
|
|
|
Timber.d("Getting player $i setup ") |
|
|
|
Timber.d("Getting player $i setup ") |
|
|
|
val playerSetup = hh.playerSetupForPosition(i) |
|
|
|
val playerSetup = hh.playerSetupForPosition(i) |
|
|
|
|
|
|
|
|
|
|
|
// Stack zone |
|
|
|
drawPlayerRectangle(i, playerSetup?.stack, false, config, canvas, context) |
|
|
|
val rect = config.stackRectForPlayer(i) |
|
|
|
|
|
|
|
val radius = (rect.bottom - rect.top) / 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fillPaint.color = context.getColor(R.color.green_darker) |
|
|
|
|
|
|
|
canvas.drawRoundRect(config.stackRectForPlayer(i), radius, radius, this.fillPaint) |
|
|
|
|
|
|
|
strokePaint.color = context.getColor(R.color.green) |
|
|
|
|
|
|
|
canvas.drawRoundRect(config.stackRectForPlayer(i), radius, radius, this.strokePaint) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Player portrait zone |
|
|
|
// Player portrait zone |
|
|
|
val circle = config.circleForPlayer(i) |
|
|
|
val circle = config.circleForPlayer(i) |
|
|
|
canvas.drawCircle(circle.x, circle.y, circle.radius, this.fillPaint) |
|
|
|
val radius = circle.radius |
|
|
|
canvas.drawCircle(circle.x, circle.y, circle.radius, this.strokePaint) |
|
|
|
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 |
|
|
|
val playerInitials = playerSetup?.player?.initials ?: RANDOM_PLAYER |
|
|
|
this.textPaint.textSize = circle.radius |
|
|
|
this.textPaint.textSize = radius |
|
|
|
canvas.drawText(playerInitials, circle.x, circle.y + circle.radius * 0.4f, this.textPaint) |
|
|
|
canvas.drawText(playerInitials, circle.x, circle.y + radius * 0.4f, this.textPaint) |
|
|
|
|
|
|
|
|
|
|
|
// Player name |
|
|
|
// Player picture |
|
|
|
val name = playerSetup?.player?.name ?: positions.elementAt(i).value |
|
|
|
playerSetup?.player?.picture?.let { picturePath -> |
|
|
|
val pnPoint = config.pointForPlayerName(i) |
|
|
|
val pictureBitmap = RoundedBitmapDrawableFactory.create(context.resources, picturePath) |
|
|
|
this.textPaint.textSize = pnPoint.fontSize |
|
|
|
pictureBitmap.setAntiAlias(true) |
|
|
|
canvas.drawText(name, pnPoint.x, pnPoint.y, this.textPaint) |
|
|
|
pictureBitmap.cornerRadius = circle.radius |
|
|
|
|
|
|
|
pictureBitmap.bitmap?.let { bitmap -> |
|
|
|
// Player stack |
|
|
|
val pictureRect = RectF(circle.x - radius, circle.y - radius, circle.x + radius, circle.y + radius) |
|
|
|
playerSetup?.stack?.formatted?.let { stack -> |
|
|
|
canvas.drawBitmap(bitmap, null, pictureRect, null) |
|
|
|
val psPoint = config.pointForPlayerStack(i) |
|
|
|
} |
|
|
|
this.textPaint.textSize = psPoint.fontSize |
|
|
|
|
|
|
|
canvas.drawText(stack, psPoint.x, psPoint.y, this.textPaint) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Dealer button |
|
|
|
// Dealer button |
|
|
|
@ -107,48 +100,123 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, fillPaint) |
|
|
|
canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, fillPaint) |
|
|
|
this.strokePaint.color = context.getColor(R.color.white) |
|
|
|
this.strokePaint.color = context.getColor(R.color.white) |
|
|
|
canvas.drawCircle(dealerCircle.x, dealerCircle.y, dealerCircle.radius, strokePaint) |
|
|
|
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) |
|
|
|
canvas.drawText("D", dealerCircle.x, dealerCircle.y + this.textPaint.textSize / 3, this.textPaint) |
|
|
|
|
|
|
|
|
|
|
|
val cardRects = config.cardRects(i) |
|
|
|
drawCards(i, config, canvas, context) |
|
|
|
val cards = playerSetup?.cards |
|
|
|
|
|
|
|
cardRects.forEachIndexed { j, cardRect -> |
|
|
|
// val blinds = config.actionList.filter { it.action.type?.isBlind ?: false } |
|
|
|
|
|
|
|
// blinds.forEach { action -> |
|
|
|
if (j < cards?.size ?: 0 && (config.showVillainHands || isHero)) { // show card |
|
|
|
// drawAction(i, action, config, canvas, context) |
|
|
|
val card = cards?.get(j)!! // tested line before |
|
|
|
// } |
|
|
|
fillPaint.color = context.getColor(R.color.white) |
|
|
|
|
|
|
|
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint) |
|
|
|
val chipCircle = config.chipCircle(i) |
|
|
|
|
|
|
|
this.fillPaint.color = context.getColor(R.color.green) |
|
|
|
cardTextPaint.color = context.getColor(R.color.black) |
|
|
|
canvas.drawCircle(chipCircle.x, chipCircle.y, chipCircle.radius, this.fillPaint) |
|
|
|
val valueY = cardRect.top + config.cardSpecs.height * 0.44f |
|
|
|
|
|
|
|
canvas.drawText(card.formattedValue, cardRect.centerX(), valueY, cardTextPaint) |
|
|
|
val chipText = config.chipText(i) |
|
|
|
|
|
|
|
this.textPaint.textSize = chipText.fontSize |
|
|
|
val suit = card.suit ?: Card.Suit.UNDEFINED |
|
|
|
this.textPaint.color = context.getColor(R.color.white) |
|
|
|
cardTextPaint.color = context.getColor(suit.color) |
|
|
|
canvas.drawText("2000", chipText.x, chipText.y, this.textPaint) |
|
|
|
val suitY = cardRect.top + config.cardSpecs.height * 0.88f |
|
|
|
|
|
|
|
canvas.drawText(suit.value, cardRect.centerX(), suitY, cardTextPaint) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { // show hidden cards |
|
|
|
|
|
|
|
fillPaint.color = context.getColor(R.color.card_fill) |
|
|
|
|
|
|
|
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint) |
|
|
|
|
|
|
|
cardStrokePaint.color = context.getColor(R.color.card_border) |
|
|
|
|
|
|
|
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, cardStrokePaint) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun drawCards(playerIndex: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val playerSetup = config.handHistory.playerSetupForPosition(playerIndex) |
|
|
|
|
|
|
|
val cardRects = config.cardRects(playerIndex) |
|
|
|
|
|
|
|
val cards = playerSetup?.cards |
|
|
|
|
|
|
|
val isHero = (config.handHistory.heroIndex == playerIndex) |
|
|
|
|
|
|
|
cardRects.forEachIndexed { j, cardRect -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (j < cards?.size ?: 0 && (config.showVillainHands || isHero)) { // show card |
|
|
|
|
|
|
|
val card = cards?.get(j)!! // tested line before |
|
|
|
|
|
|
|
fillPaint.color = context.getColor(R.color.white) |
|
|
|
|
|
|
|
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cardTextPaint.color = context.getColor(R.color.black) |
|
|
|
|
|
|
|
val valueY = cardRect.top + config.cardSpecs.height * 0.44f |
|
|
|
|
|
|
|
canvas.drawText(card.formattedValue, cardRect.centerX(), valueY, cardTextPaint) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val suit = card.suit ?: Card.Suit.UNDEFINED |
|
|
|
|
|
|
|
cardTextPaint.color = context.getColor(suit.color) |
|
|
|
|
|
|
|
val suitY = cardRect.top + config.cardSpecs.height * 0.88f |
|
|
|
|
|
|
|
canvas.drawText(suit.value, cardRect.centerX(), suitY, cardTextPaint) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { // show hidden cards |
|
|
|
|
|
|
|
fillPaint.color = context.getColor(R.color.card_fill) |
|
|
|
|
|
|
|
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, fillPaint) |
|
|
|
|
|
|
|
cardStrokePaint.color = context.getColor(R.color.card_border) |
|
|
|
|
|
|
|
canvas.drawRoundRect(cardRect, config.cardRadius, config.cardRadius, cardStrokePaint) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun drawStreet(street: Street, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
fun drawAction(i: Int, action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// show that action is on the player by highlighting |
|
|
|
|
|
|
|
drawPlayerRectangle(i, null, true, config, canvas, context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// show action name : call, bet, check... |
|
|
|
|
|
|
|
drawAction(i, action.action.type!!, config, canvas, context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// show chips image + text, if applicable |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// show pot updates, if applicable |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* [i] is the player position in the hand |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun drawPlayerRectangle(i: Int, stack: Double?, 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.green_diamond_dark else R.color.green_darker |
|
|
|
|
|
|
|
fillPaint.color = context.getColor(color) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drawPositionAndStack(i, stack, config, canvas, context) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun drawAction(action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
private fun drawPositionAndStack(i: Int, stack: Double?, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val hh = config.handHistory |
|
|
|
|
|
|
|
// Player position |
|
|
|
|
|
|
|
val positions = Position.positionsPerPlayers(hh.numberOfPlayers) |
|
|
|
|
|
|
|
val name = positions.elementAt(i).value |
|
|
|
|
|
|
|
val pnPoint = config.pointForPlayerName(i) |
|
|
|
|
|
|
|
this.textPaint.textSize = pnPoint.fontSize |
|
|
|
|
|
|
|
canvas.drawText(name, pnPoint.x, pnPoint.y, this.textPaint) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Player stack |
|
|
|
|
|
|
|
val psPoint = config.pointForPlayerStack(i) |
|
|
|
|
|
|
|
this.textPaint.textSize = psPoint.fontSize |
|
|
|
|
|
|
|
val stackFormatted = stack?.formatted ?: "" |
|
|
|
|
|
|
|
canvas.drawText(stackFormatted, psPoint.x, psPoint.y, this.textPaint) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun drawAction(i: Int, type: Action.Type, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
val pnPoint = config.pointForPlayerAction(i) |
|
|
|
|
|
|
|
this.textPaint.textSize = pnPoint.fontSize |
|
|
|
|
|
|
|
canvas.drawText(type.name, pnPoint.x, pnPoint.y, this.textPaint) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun drawStreet(street: Street, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//////// |
|
|
|
//////// |
|
|
|
fun setPot(pot: Double, totalPot: Double) { |
|
|
|
fun setPot(pot: Double, totalPot: Double) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|