|
|
|
|
@ -9,9 +9,10 @@ import net.pokeranalytics.android.model.handhistory.Street |
|
|
|
|
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 net.pokeranalytics.android.util.MathUtils |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import kotlin.math.abs |
|
|
|
|
import kotlin.math.max |
|
|
|
|
import kotlin.math.min |
|
|
|
|
|
|
|
|
|
class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
|
|
|
|
|
@ -247,14 +248,6 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
@ -290,96 +283,14 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
this.totalPotTextPoint = TextPoint(centerX, centerY - 2f * chipTextSize, chipTextSize) |
|
|
|
|
|
|
|
|
|
val playerCount = this.handHistory.numberOfPlayers |
|
|
|
|
// number of players in this order: bottom / left / top / right |
|
|
|
|
val repartition = when (playerCount) { |
|
|
|
|
2 -> mutableListOf(1, 0, 1, 0) |
|
|
|
|
3 -> mutableListOf(1, 1, 0, 1) |
|
|
|
|
4 -> mutableListOf(1, 1, 1, 1) |
|
|
|
|
5 -> mutableListOf(1, 1, 2, 1) |
|
|
|
|
6 -> mutableListOf(2, 1, 2, 1) |
|
|
|
|
7 -> mutableListOf(2, 1, 3, 1) |
|
|
|
|
8 -> mutableListOf(3, 1, 3, 1) |
|
|
|
|
9 -> mutableListOf(3, 1, 4, 1) |
|
|
|
|
10 -> mutableListOf(4, 1, 4, 1) |
|
|
|
|
else -> throw PAIllegalStateException("can't happen") |
|
|
|
|
} |
|
|
|
|
if (repartition.sum() != playerCount) { |
|
|
|
|
throw PAIllegalStateException("Problem in the $playerCount players repartition: $repartition") |
|
|
|
|
} |
|
|
|
|
if (portrait && playerCount > 4) { repartition.reverse() } // adjustment for portrait vs landscape |
|
|
|
|
|
|
|
|
|
val chipsVerticalOffsetFromStackCenter = this.playerItemsHeight * 0.9f |
|
|
|
|
val chipsHorizontalOffsetFromStackCenter = this.tableHPadding * 1.2f |
|
|
|
|
|
|
|
|
|
var pIndex = -1 |
|
|
|
|
repartition.forEachIndexed { index, count -> |
|
|
|
|
|
|
|
|
|
val xItemSpacing = width / (count + 1) |
|
|
|
|
val yItemSpacing = height / (count + 1) |
|
|
|
|
|
|
|
|
|
var rectCenterX: Float |
|
|
|
|
var rectCenterY: Float |
|
|
|
|
var chipXOffset: Float |
|
|
|
|
var chipYOffset: Float |
|
|
|
|
var chipTextYOffsetCoef = 0f |
|
|
|
|
var circleOffset = playerItemsHeight * 1.75f |
|
|
|
|
|
|
|
|
|
for (i in 1..count) { |
|
|
|
|
|
|
|
|
|
pIndex += 1 |
|
|
|
|
Timber.d("Creating dimensions for player $pIndex") |
|
|
|
|
|
|
|
|
|
// when the position is in a corner, because we have 3/4 players |
|
|
|
|
// we need an additional offset direction to display the chips |
|
|
|
|
val cornerDirection = when { |
|
|
|
|
count > 2 && i == 1 -> { 1 } |
|
|
|
|
count > 2 && i == count -> { - 1 } |
|
|
|
|
else -> { 0 } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
when (index) { |
|
|
|
|
0 -> { // bottom |
|
|
|
|
rectCenterX = xItemSpacing * i |
|
|
|
|
rectCenterY = height - this.tableVPadding |
|
|
|
|
circleOffset *= -1 |
|
|
|
|
chipXOffset = cornerDirection * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
chipYOffset = -1 * chipsVerticalOffsetFromStackCenter |
|
|
|
|
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 - 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) |
|
|
|
|
} |
|
|
|
|
val positions = MathUtils.positionsAroundRoundedRectangle(playerCount, this.tableRect, this.tableCornerXRadius, this.tableCornerYRadius) |
|
|
|
|
for (i in (0 until playerCount)) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
2 -> { // top |
|
|
|
|
rectCenterX = xItemSpacing * i |
|
|
|
|
rectCenterY = this.tableVPadding |
|
|
|
|
chipXOffset = cornerDirection * -1 * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
chipYOffset = 1 * chipsVerticalOffsetFromStackCenter |
|
|
|
|
} |
|
|
|
|
3 -> { // right |
|
|
|
|
rectCenterX = width - this.tableHPadding |
|
|
|
|
rectCenterY = yItemSpacing * i |
|
|
|
|
chipXOffset = -1 * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
chipYOffset = cornerDirection * chipsVerticalOffsetFromStackCenter |
|
|
|
|
chipTextYOffsetCoef = 1f * (count - i + 1) / count |
|
|
|
|
} |
|
|
|
|
else -> throw PAIllegalStateException("can't happen") |
|
|
|
|
} |
|
|
|
|
val point = positions[i].first |
|
|
|
|
val bottomOriented = positions[i].second |
|
|
|
|
val rectCenterX = point.x |
|
|
|
|
val rectCenterY = point.y |
|
|
|
|
|
|
|
|
|
val left = rectCenterX - this.playerItemsWidth / 2 |
|
|
|
|
val top = rectCenterY - this.playerItemsHeight / 2 |
|
|
|
|
@ -388,11 +299,14 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
this.playerStackRects.add(RectF(left, top, right, bottom)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val chipCircleY = rectCenterY + chipYOffset - chipTextYOffsetCoef * chipRadius |
|
|
|
|
// val chipCircleY = rectCenterY + chipYOffset - chipTextYOffsetCoef * chipRadius |
|
|
|
|
|
|
|
|
|
val line = MathUtils.Line(point.x, point.y, tableRect.centerX(), tableRect.centerY()) |
|
|
|
|
val chipPoint = line.pointForDistance(this.playerItemsWidth * 0.8f) |
|
|
|
|
|
|
|
|
|
this.chipCircles.add(Circle(rectCenterX + chipXOffset, chipCircleY, chipRadius)) |
|
|
|
|
this.chipCircles.add(Circle(chipPoint.x, chipPoint.y, chipRadius)) |
|
|
|
|
|
|
|
|
|
this.chipTextPoints.add(TextPoint(rectCenterX + chipXOffset, chipCircleY + 2 * chipTextSize, chipTextSize)) |
|
|
|
|
this.chipTextPoints.add(TextPoint(chipPoint.x, chipPoint.y + 2 * chipTextSize, chipTextSize)) |
|
|
|
|
|
|
|
|
|
// we give each text zone 1/3rd of the box height, leaving 1/3 for space |
|
|
|
|
// the y given is the bottom of the text rect, giving 1/18th as the offset |
|
|
|
|
@ -404,9 +318,11 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
this.playerStackPoints.add(TextPoint(rectCenterX, rectCenterY + this.playerItemsHeight / 3, fontSize)) |
|
|
|
|
this.playerActionPoints.add(TextPoint(rectCenterX, rectCenterY + this.playerItemsHeight / 9, fontSize)) |
|
|
|
|
|
|
|
|
|
val orientation = if (bottomOriented) -1 else 1 |
|
|
|
|
val circleOffset = playerItemsHeight * 1.75f * orientation |
|
|
|
|
this.playerCircles.add(Circle(rectCenterX, rectCenterY - circleOffset, this.playerItemsHeight / 2)) |
|
|
|
|
|
|
|
|
|
val cardsUsed = this.handHistory.playerSetupForPosition(pIndex)?.cards?.size ?: maxPlayerCards |
|
|
|
|
val cardsUsed = this.handHistory.playerSetupForPosition(i)?.cards?.size ?: maxPlayerCards |
|
|
|
|
val cardsRectangles = mutableListOf<RectF>() |
|
|
|
|
if (cardsUsed > 0) { |
|
|
|
|
val offSet = (cardsUsed / 2 - 0.5f) * cardWPaddingWidth |
|
|
|
|
@ -423,7 +339,142 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// number of players in this order: bottom / left / top / right |
|
|
|
|
// val repartition = when (playerCount) { |
|
|
|
|
// 2 -> mutableListOf(1, 0, 1, 0) |
|
|
|
|
// 3 -> mutableListOf(1, 1, 0, 1) |
|
|
|
|
// 4 -> mutableListOf(1, 1, 1, 1) |
|
|
|
|
// 5 -> mutableListOf(1, 1, 2, 1) |
|
|
|
|
// 6 -> mutableListOf(2, 1, 2, 1) |
|
|
|
|
// 7 -> mutableListOf(2, 1, 3, 1) |
|
|
|
|
// 8 -> mutableListOf(3, 1, 3, 1) |
|
|
|
|
// 9 -> mutableListOf(3, 1, 4, 1) |
|
|
|
|
// 10 -> mutableListOf(4, 1, 4, 1) |
|
|
|
|
// else -> throw PAIllegalStateException("can't happen") |
|
|
|
|
// } |
|
|
|
|
// if (repartition.sum() != playerCount) { |
|
|
|
|
// throw PAIllegalStateException("Problem in the $playerCount players repartition: $repartition") |
|
|
|
|
// } |
|
|
|
|
// if (portrait && playerCount > 4) { repartition.reverse() } // adjustment for portrait vs landscape |
|
|
|
|
// |
|
|
|
|
// val chipsVerticalOffsetFromStackCenter = this.playerItemsHeight * 0.9f |
|
|
|
|
// val chipsHorizontalOffsetFromStackCenter = this.tableHPadding * 1.2f |
|
|
|
|
// |
|
|
|
|
// var pIndex = -1 |
|
|
|
|
// repartition.forEachIndexed { index, count -> |
|
|
|
|
// |
|
|
|
|
// val xItemSpacing = width / (count + 1) |
|
|
|
|
// val yItemSpacing = height / (count + 1) |
|
|
|
|
// |
|
|
|
|
// var rectCenterX: Float |
|
|
|
|
// var rectCenterY: Float |
|
|
|
|
// var chipXOffset: Float |
|
|
|
|
// var chipYOffset: Float |
|
|
|
|
// var chipTextYOffsetCoef = 0f |
|
|
|
|
// var circleOffset = playerItemsHeight * 1.75f |
|
|
|
|
// |
|
|
|
|
// for (i in 1..count) { |
|
|
|
|
// |
|
|
|
|
// pIndex += 1 |
|
|
|
|
// Timber.d("Creating dimensions for player $pIndex") |
|
|
|
|
// |
|
|
|
|
// // when the position is in a corner, because we have 3/4 players |
|
|
|
|
// // we need an additional offset direction to display the chips |
|
|
|
|
// val cornerDirection = when { |
|
|
|
|
// count > 2 && i == 1 -> { 1 } |
|
|
|
|
// count > 2 && i == count -> { - 1 } |
|
|
|
|
// else -> { 0 } |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// when (index) { |
|
|
|
|
// 0 -> { // bottom |
|
|
|
|
// rectCenterX = xItemSpacing * i |
|
|
|
|
// rectCenterY = height - this.tableVPadding |
|
|
|
|
// circleOffset *= -1 |
|
|
|
|
// chipXOffset = cornerDirection * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
// chipYOffset = -1 * chipsVerticalOffsetFromStackCenter |
|
|
|
|
// 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 - 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 = xItemSpacing * i |
|
|
|
|
// rectCenterY = this.tableVPadding |
|
|
|
|
// chipXOffset = cornerDirection * -1 * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
// chipYOffset = 1 * chipsVerticalOffsetFromStackCenter |
|
|
|
|
// } |
|
|
|
|
// 3 -> { // right |
|
|
|
|
// rectCenterX = width - this.tableHPadding |
|
|
|
|
// rectCenterY = yItemSpacing * i |
|
|
|
|
// chipXOffset = -1 * chipsHorizontalOffsetFromStackCenter |
|
|
|
|
// chipYOffset = cornerDirection * chipsVerticalOffsetFromStackCenter |
|
|
|
|
// chipTextYOffsetCoef = 1f * (count - i + 1) / count |
|
|
|
|
// } |
|
|
|
|
// else -> throw PAIllegalStateException("can't happen") |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// val left = rectCenterX - this.playerItemsWidth / 2 |
|
|
|
|
// val top = rectCenterY - this.playerItemsHeight / 2 |
|
|
|
|
// val right = rectCenterX + this.playerItemsWidth / 2 |
|
|
|
|
// val bottom = rectCenterY + this.playerItemsHeight / 2 |
|
|
|
|
// this.playerStackRects.add(RectF(left, top, right, bottom)) |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// val chipCircleY = rectCenterY + chipYOffset - chipTextYOffsetCoef * chipRadius |
|
|
|
|
// |
|
|
|
|
// this.chipCircles.add(Circle(rectCenterX + chipXOffset, chipCircleY, chipRadius)) |
|
|
|
|
// |
|
|
|
|
// this.chipTextPoints.add(TextPoint(rectCenterX + chipXOffset, chipCircleY + 2 * chipTextSize, chipTextSize)) |
|
|
|
|
// |
|
|
|
|
// // we give each text zone 1/3rd of the box height, leaving 1/3 for space |
|
|
|
|
// // the y given is the bottom of the text rect, giving 1/18th as the offset |
|
|
|
|
// // 1 / (3_total_space * 3_each_space * 2_center) |
|
|
|
|
// |
|
|
|
|
// val bottomOffset = this.playerItemsHeight / (3 * 3 * 2) |
|
|
|
|
// val fontSize = this.playerItemsHeight / 3 |
|
|
|
|
// this.playerNamePoints.add(TextPoint(rectCenterX, rectCenterY - bottomOffset, fontSize)) |
|
|
|
|
// this.playerStackPoints.add(TextPoint(rectCenterX, rectCenterY + this.playerItemsHeight / 3, fontSize)) |
|
|
|
|
// this.playerActionPoints.add(TextPoint(rectCenterX, rectCenterY + this.playerItemsHeight / 9, fontSize)) |
|
|
|
|
// |
|
|
|
|
// this.playerCircles.add(Circle(rectCenterX, rectCenterY - circleOffset, this.playerItemsHeight / 2)) |
|
|
|
|
// |
|
|
|
|
// val cardsUsed = this.handHistory.playerSetupForPosition(pIndex)?.cards?.size ?: maxPlayerCards |
|
|
|
|
// val cardsRectangles = mutableListOf<RectF>() |
|
|
|
|
// if (cardsUsed > 0) { |
|
|
|
|
// val offSet = (cardsUsed / 2 - 0.5f) * cardWPaddingWidth |
|
|
|
|
// |
|
|
|
|
// val cardCenterY = rectCenterY - circleOffset / 2 |
|
|
|
|
// for (c in 0 until cardsUsed) { |
|
|
|
|
// |
|
|
|
|
// val cardCenterX = rectCenterX - offSet + c * cardWPaddingWidth |
|
|
|
|
// val cardRect = RectF(cardCenterX - cardSpecs.width / 2, cardCenterY - cardSpecs.height / 2, cardCenterX + cardSpecs.width / 2, cardCenterY + cardSpecs.height / 2) |
|
|
|
|
// cardsRectangles.add(cardRect) |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// this.playerCardRects.add(cardsRectangles) |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|