|
|
|
|
@ -6,27 +6,46 @@ import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
|
|
|
|
|
|
class ReplayerConfiguration(var handHistory: HandHistory) { |
|
|
|
|
|
|
|
|
|
data class Size(var width: Float, var height: Float) |
|
|
|
|
data class Circle(var x: Float, var y: Float, var radius: Float) |
|
|
|
|
data class TextPoint(var x: Float, var y: Float, var fontSize: Float) |
|
|
|
|
|
|
|
|
|
private val maxCards = 5 |
|
|
|
|
|
|
|
|
|
var width = 100f |
|
|
|
|
var height = 100f |
|
|
|
|
|
|
|
|
|
var tableRect = RectF() |
|
|
|
|
var playerStackRects = mutableListOf<RectF>() |
|
|
|
|
var playerCircles = mutableListOf<Circle>() |
|
|
|
|
var playerNamePoints = mutableListOf<TextPoint>() |
|
|
|
|
var playerStackPoints = mutableListOf<TextPoint>() |
|
|
|
|
var playerItemsHeight = 10f |
|
|
|
|
var playerItemsWidth = 10f |
|
|
|
|
var paddingPercentage = 0.8f |
|
|
|
|
var tableCornerRadius = 0f |
|
|
|
|
var cardSpecs: Size = Size(0f, 0f) |
|
|
|
|
var cardRadius = 0f |
|
|
|
|
|
|
|
|
|
private var playerStackRects = mutableListOf<RectF>() |
|
|
|
|
private var playerCircles = mutableListOf<Circle>() |
|
|
|
|
private var playerNamePoints = mutableListOf<TextPoint>() |
|
|
|
|
private var playerStackPoints = mutableListOf<TextPoint>() |
|
|
|
|
private var playerCardRects = mutableListOf<List<RectF>>() |
|
|
|
|
|
|
|
|
|
val dealerCircle: Circle |
|
|
|
|
get() { |
|
|
|
|
val rect = this.playerStackRects.last() |
|
|
|
|
val radius = (rect.bottom - rect.top) / 4 |
|
|
|
|
return Circle(rect.right - radius / 2, rect.top, radius) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private var playerItemsHeight = 10f |
|
|
|
|
private var playerItemsWidth = 10f |
|
|
|
|
private var paddingPercentage = 0.8f |
|
|
|
|
|
|
|
|
|
var tableHPadding = 0f |
|
|
|
|
var tableVPadding = 0f |
|
|
|
|
private var tableHPadding = 0f |
|
|
|
|
private var tableVPadding = 0f |
|
|
|
|
|
|
|
|
|
val speed: Double = 1.0 |
|
|
|
|
val showVillainHands: Boolean = true |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Calculates the position of all elements to draw |
|
|
|
|
*/ |
|
|
|
|
fun setDimension(width: Float, height: Float) { |
|
|
|
|
this.width = width |
|
|
|
|
this.height = height |
|
|
|
|
@ -39,15 +58,20 @@ class ReplayerConfiguration(var handHistory: HandHistory) { |
|
|
|
|
this.tableVPadding = height / playerPerColumn * 0.8f |
|
|
|
|
|
|
|
|
|
this.tableRect = RectF(tableHPadding, tableVPadding, width - tableHPadding, height - tableVPadding) |
|
|
|
|
this.tableCornerRadius = (if (portrait) width else height) / 8 |
|
|
|
|
|
|
|
|
|
val pzHeight = height / playerPerColumn |
|
|
|
|
val pzWidth = width / playerPerRow |
|
|
|
|
|
|
|
|
|
this.playerItemsHeight = pzHeight / 3 |
|
|
|
|
this.playerItemsWidth = pzWidth * this.paddingPercentage |
|
|
|
|
this.playerItemsWidth = pzWidth * this.paddingPercentage |
|
|
|
|
|
|
|
|
|
val cardWidth = pzWidth * paddingPercentage / maxCards |
|
|
|
|
this.cardSpecs = Size(cardWidth, cardWidth * 1.75f) |
|
|
|
|
this.cardRadius = cardWidth / 4 |
|
|
|
|
|
|
|
|
|
// number of players in this order: bottom / left / top / right |
|
|
|
|
val repartition = when (handHistory.numberOfPlayers) { |
|
|
|
|
val repartition = when (this.handHistory.numberOfPlayers) { |
|
|
|
|
2 -> mutableListOf(1, 0, 1, 0) |
|
|
|
|
3 -> mutableListOf(1, 1, 0, 1) |
|
|
|
|
4 -> mutableListOf(1, 1, 1, 1) |
|
|
|
|
@ -59,43 +83,45 @@ class ReplayerConfiguration(var handHistory: HandHistory) { |
|
|
|
|
10 -> mutableListOf(4, 1, 4, 1) |
|
|
|
|
else -> throw PAIllegalStateException("can't happen") |
|
|
|
|
} |
|
|
|
|
if (portrait && handHistory.numberOfPlayers > 4) { repartition.reverse() } |
|
|
|
|
if (portrait && this.handHistory.numberOfPlayers > 4) { repartition.reverse() } |
|
|
|
|
|
|
|
|
|
repartition.forEachIndexed { index, count -> |
|
|
|
|
|
|
|
|
|
val x = width / (count + 1) |
|
|
|
|
val y = height / (count + 1) |
|
|
|
|
|
|
|
|
|
var xOffset = x |
|
|
|
|
var yOffset = y |
|
|
|
|
var rectCenterX = x |
|
|
|
|
var rectCenterY = y |
|
|
|
|
var circleOffset = playerItemsHeight * 1.5f |
|
|
|
|
var pIndex = -1 |
|
|
|
|
for (i in 1..count) { |
|
|
|
|
pIndex++ |
|
|
|
|
|
|
|
|
|
when (index) { |
|
|
|
|
0 -> { // bottom |
|
|
|
|
xOffset = x * i |
|
|
|
|
yOffset = height - this.tableVPadding |
|
|
|
|
rectCenterX = x * i |
|
|
|
|
rectCenterY = height - this.tableVPadding |
|
|
|
|
circleOffset *= -1 |
|
|
|
|
} |
|
|
|
|
1 -> { // left |
|
|
|
|
xOffset = this.tableHPadding |
|
|
|
|
yOffset = height - y * i |
|
|
|
|
rectCenterX = this.tableHPadding |
|
|
|
|
rectCenterY = height - y * i |
|
|
|
|
} |
|
|
|
|
2 -> { // top |
|
|
|
|
xOffset = x * i |
|
|
|
|
yOffset = this.tableVPadding |
|
|
|
|
rectCenterX = x * i |
|
|
|
|
rectCenterY = this.tableVPadding |
|
|
|
|
} |
|
|
|
|
3 -> { // right |
|
|
|
|
xOffset = width - this.tableHPadding |
|
|
|
|
yOffset = y * i |
|
|
|
|
rectCenterX = width - this.tableHPadding |
|
|
|
|
rectCenterY = y * i |
|
|
|
|
} |
|
|
|
|
else -> throw PAIllegalStateException("can't happen") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val left = xOffset - this.playerItemsWidth / 2 |
|
|
|
|
val top = yOffset - this.playerItemsHeight / 2 |
|
|
|
|
val right = xOffset + this.playerItemsWidth / 2 |
|
|
|
|
val bottom = yOffset + this.playerItemsHeight / 2 |
|
|
|
|
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)) |
|
|
|
|
|
|
|
|
|
// we give each text zone 1/3rd of the box height, leaving 1/3 for space |
|
|
|
|
@ -104,10 +130,26 @@ class ReplayerConfiguration(var handHistory: HandHistory) { |
|
|
|
|
|
|
|
|
|
val bottomOffset = this.playerItemsHeight / (3 * 3 * 2) |
|
|
|
|
val fontSize = this.playerItemsHeight / 3 |
|
|
|
|
this.playerNamePoints.add(TextPoint(xOffset, yOffset - bottomOffset, fontSize)) |
|
|
|
|
this.playerStackPoints.add(TextPoint(xOffset, yOffset + this.playerItemsHeight / 3 + bottomOffset, fontSize)) |
|
|
|
|
this.playerNamePoints.add(TextPoint(rectCenterX, rectCenterY - bottomOffset, fontSize)) |
|
|
|
|
this.playerStackPoints.add(TextPoint(rectCenterX, rectCenterY + this.playerItemsHeight / 3, fontSize)) |
|
|
|
|
|
|
|
|
|
this.playerCircles.add(Circle(rectCenterX, rectCenterY - circleOffset, this.playerItemsHeight / 2)) |
|
|
|
|
|
|
|
|
|
val cardsUsed = this.handHistory.playerSetupForPosition(pIndex)?.cards?.size ?: 0 |
|
|
|
|
val cardsRectangles = mutableListOf<RectF>() |
|
|
|
|
if (cardsUsed > 0) { |
|
|
|
|
val cardWPaddingWidth = pzWidth / maxCards |
|
|
|
|
val offSet = (cardsUsed / 2 - 0.5f) * cardWPaddingWidth |
|
|
|
|
|
|
|
|
|
this.playerCircles.add(Circle(xOffset, yOffset - circleOffset, this.playerItemsHeight / 2)) |
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -134,6 +176,10 @@ class ReplayerConfiguration(var handHistory: HandHistory) { |
|
|
|
|
return this.playerStackPoints[i] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun cardRects(i: Int): List<RectF> { |
|
|
|
|
return this.playerCardRects[i] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|