|
|
|
|
@ -10,6 +10,7 @@ import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.ActionList |
|
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import kotlin.math.abs |
|
|
|
|
import kotlin.math.max |
|
|
|
|
|
|
|
|
|
class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
@ -82,6 +83,15 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private val visualOccurences: Int |
|
|
|
|
get() { |
|
|
|
|
return if (this.currentStepIndex == this.steps.size - 1 && this.currentFrame == this.numberOfFramesForCurrentStep - 1) { |
|
|
|
|
FrameType.STATE.visualOccurences * 4 |
|
|
|
|
} else { |
|
|
|
|
this.frameType.visualOccurences |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns if the animator has more frame to show |
|
|
|
|
*/ |
|
|
|
|
@ -99,7 +109,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
/*** |
|
|
|
|
* The list of steps, scannable with back/forward buttons |
|
|
|
|
*/ |
|
|
|
|
private var steps: List<HandStep> |
|
|
|
|
private var steps: List<HandStep> = listOf() |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* The index of the last blind in the action list |
|
|
|
|
@ -121,9 +131,13 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
this.actionList.load(this.handHistory) |
|
|
|
|
loadHandHistory(this.handHistory) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun loadHandHistory(handHistory: HandHistory) { |
|
|
|
|
|
|
|
|
|
this.steps = HandStep.createSteps(this.handHistory) |
|
|
|
|
this.actionList.load(handHistory) |
|
|
|
|
this.steps = HandStep.createSteps(handHistory) |
|
|
|
|
|
|
|
|
|
val bi = this.steps.indexOfLast { it is ComputedAction && it.action.type?.isBlind == true } |
|
|
|
|
this.lastBlindIndex = max(bi, 0) // in case indexOfLast returns -1 |
|
|
|
|
@ -162,7 +176,8 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
get() { return this.height / 2f } |
|
|
|
|
|
|
|
|
|
var tableRect = RectF() |
|
|
|
|
var tableCornerRadius = 0f |
|
|
|
|
var tableCornerXRadius = 0f |
|
|
|
|
var tableCornerYRadius = 0f |
|
|
|
|
var cardSpecs: Size = Size(0f, 0f) |
|
|
|
|
var cardRadius = 0f |
|
|
|
|
|
|
|
|
|
@ -212,17 +227,36 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
this.height = height |
|
|
|
|
|
|
|
|
|
val maxPlayerCards = this.handHistory.maxPlayerCards |
|
|
|
|
val grid = when (this.handHistory.numberOfPlayers) { |
|
|
|
|
2, 3 -> Pair(2, 3) |
|
|
|
|
9, 10 -> Pair(4, 5) |
|
|
|
|
else -> Pair(3, 4) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val portrait = height > width |
|
|
|
|
val playerPerColumn = if (portrait) 4 else 3 |
|
|
|
|
val playerPerRow = 12 / playerPerColumn // 3 or 4 |
|
|
|
|
|
|
|
|
|
val playerPerColumn = if (portrait) grid.second else grid.first |
|
|
|
|
val playerPerRow = if (portrait) grid.first else grid.second |
|
|
|
|
|
|
|
|
|
val padding = if (portrait) 0.8f else 0.95f |
|
|
|
|
this.tableHPadding = width / playerPerRow / 2 * padding |
|
|
|
|
this.tableVPadding = height / playerPerColumn * 0.8f |
|
|
|
|
|
|
|
|
|
this.tableRect = RectF(tableHPadding, tableVPadding, width - tableHPadding, height - tableVPadding) |
|
|
|
|
this.tableCornerRadius = (if (portrait) width else height) / 8 |
|
|
|
|
|
|
|
|
|
this.tableCornerXRadius = this.tableRect.width() / 3 |
|
|
|
|
this.tableCornerYRadius = this.tableRect.height() / 3 |
|
|
|
|
|
|
|
|
|
// for (i in (0 until handHistory.numberOfPlayers)) { |
|
|
|
|
// |
|
|
|
|
// val angle = i * (2 * Math.PI / handHistory.numberOfPlayers) |
|
|
|
|
// val x = |
|
|
|
|
// val y = |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.tableCornerRadius = (if (portrait) width else height) / 8 |
|
|
|
|
|
|
|
|
|
this.tableStrokeWidth = tableHPadding / 5f |
|
|
|
|
this.playerStrokeWidth = this.tableStrokeWidth / 4f |
|
|
|
|
@ -280,8 +314,8 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
var pIndex = -1 |
|
|
|
|
repartition.forEachIndexed { index, count -> |
|
|
|
|
|
|
|
|
|
val x = width / (count + 1) |
|
|
|
|
val y = height / (count + 1) |
|
|
|
|
val xItemSpacing = width / (count + 1) |
|
|
|
|
val yItemSpacing = height / (count + 1) |
|
|
|
|
|
|
|
|
|
var rectCenterX: Float |
|
|
|
|
var rectCenterY: Float |
|
|
|
|
@ -305,7 +339,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
|
|
|
|
|
when (index) { |
|
|
|
|
0 -> { // bottom |
|
|
|
|
rectCenterX = x * i |
|
|
|
|
rectCenterX = xItemSpacing * i |
|
|
|
|
rectCenterY = height - this.tableVPadding |
|
|
|
|
circleOffset *= -1 |
|
|
|
|
chipXOffset = cornerDirection * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
@ -313,21 +347,33 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
chipTextYOffsetCoef = 1f |
|
|
|
|
} |
|
|
|
|
1 -> { // left |
|
|
|
|
rectCenterY = if (count == 4 && (i == 2 || i == 3)) { |
|
|
|
|
height - yItemSpacing - this.playerItemsHeight * 1.2f - pzHeight * (i - 2) |
|
|
|
|
} else { |
|
|
|
|
height - yItemSpacing * i |
|
|
|
|
} |
|
|
|
|
rectCenterX = this.tableHPadding |
|
|
|
|
rectCenterY = height - y * i |
|
|
|
|
// rectCenterY = height - yItemSpacing * i |
|
|
|
|
chipXOffset = 1 * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
chipYOffset = cornerDirection * -1 * chipsVerticalOffsetFromStackCenter |
|
|
|
|
chipTextYOffsetCoef = 1f * (i - 1) / count |
|
|
|
|
|
|
|
|
|
if (count == 4 && i == 1) { |
|
|
|
|
circleOffset *= -1 |
|
|
|
|
} else { |
|
|
|
|
circleOffset = abs(circleOffset) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
2 -> { // top |
|
|
|
|
rectCenterX = x * i |
|
|
|
|
rectCenterX = xItemSpacing * i |
|
|
|
|
rectCenterY = this.tableVPadding |
|
|
|
|
chipXOffset = cornerDirection * -1 * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
chipYOffset = 1 * chipsVerticalOffsetFromStackCenter |
|
|
|
|
} |
|
|
|
|
3 -> { // right |
|
|
|
|
rectCenterX = width - this.tableHPadding |
|
|
|
|
rectCenterY = y * i |
|
|
|
|
rectCenterY = yItemSpacing * i |
|
|
|
|
chipXOffset = -1 * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
chipYOffset = cornerDirection * chipsVerticalOffsetFromStackCenter |
|
|
|
|
chipTextYOffsetCoef = 1f * (count - i + 1) / count |
|
|
|
|
@ -502,7 +548,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
|
|
|
|
|
fun frames(context: Context, frameHandler: (Bitmap, Int) -> Unit) { |
|
|
|
|
|
|
|
|
|
this.steps.forEach { step -> |
|
|
|
|
this.steps.forEach { _ -> |
|
|
|
|
|
|
|
|
|
while (this.shouldShowAdditionalFrame) { |
|
|
|
|
|
|
|
|
|
@ -510,7 +556,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
val canvas = Canvas(bitmap) |
|
|
|
|
TableDrawer.drawTable(this, canvas, context) |
|
|
|
|
|
|
|
|
|
frameHandler(bitmap, this.frameType.visualOccurences) |
|
|
|
|
frameHandler(bitmap, this.visualOccurences) |
|
|
|
|
|
|
|
|
|
frameDrawn() |
|
|
|
|
} |
|
|
|
|
|