Hand replayer layout improvement

bs
Laurent 5 years ago
parent 6cf42dadd2
commit 1dd98ad18a
  1. 3
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/evaluator/Hand.java
  2. 45
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt

@ -20,7 +20,8 @@ public abstract class Hand {
public static int evaluate(Card[] cards) {
// Only 5-card hands are supported
if (cards == null || cards.length != 5) {
throw new IllegalArgumentException("Exactly 5 cards are required.");
String message = "Exactly 5 cards are required, " + cards.length + " passed.";
throw new IllegalArgumentException(message);
}
// Binary representations of each card

@ -208,11 +208,21 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
private var chipTextPoints = mutableListOf<TextPoint>()
var boardCardRects = mutableListOf<RectF>()
var dealerBottomOriented = true
val dealerCircle: Circle
get() {
val rect = this.playerStackRects.last()
val radius = (rect.bottom - rect.top) / 4
return Circle(rect.left, rect.bottom, radius)
val width = rect.right - rect.left
val x: Float; val y: Float
if (this.dealerBottomOriented) {
x = rect.left
y = (rect.top + rect.bottom) / 2f
} else {
x = rect.left + width / 6.0f
y = rect.bottom
}
return Circle(x, y, radius)
}
private var playerItemsHeight = 10f
@ -250,15 +260,21 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
this.height = height
val maxPlayerCards = this.handHistory.maxPlayerCards
val hwRatio = 1.3f
val portrait = height > width
val base = 3.3f + this.handHistory.numberOfPlayers / 20.0f
val playerPerColumn = if (portrait) base * hwRatio else base
val playerPerRow = if (portrait) base else base * hwRatio
val grid = when (this.handHistory.numberOfPlayers) {
9, 10 -> Pair(4f, 5f)
else -> Pair(3.7f, 4.7f)
}
val portrait = height > width
val playerPerColumn = if (portrait) grid.second else grid.first
val playerPerRow = if (portrait) grid.first else grid.second
Timber.d("playerPerRow = $playerPerRow, playerPerColumn = $playerPerColumn")
// 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
@ -280,14 +296,15 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
this.playerItemsWidth = this.tableHPadding * 2 * this.paddingPercentage
this.chipRadius = this.playerItemsHeight / 4
val cardWPaddingWidth = this.playerItemsWidth * 1.5f / this.maxCards
val cardWPaddingWidth = this.playerItemsWidth * 1.4f / this.maxCards
val cardWidth = cardWPaddingWidth * this.cardsPaddingPercentage
this.cardSpecs = Size(cardWidth, cardWidth * 1.75f)
this.cardRadius = cardWidth / 4
// Board cards rectangles
val bcTop = centerY - cardSpecs.height / 2
val bcBottom = centerY + cardSpecs.height / 2
val bcCenterY = centerY + cardSpecs.height / 2
val bcTop = bcCenterY - cardSpecs.height / 2
val bcBottom = bcCenterY + cardSpecs.height / 2
val boardCards = 5
for (i in 0 until boardCards) {
val bcLeft = centerX - (boardCards / 2f - i) * cardWPaddingWidth
@ -296,9 +313,9 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
}
val chipTextSize = this.chipRadius
this.potChipCircle = Circle(centerX, centerY - 5.2f * chipTextSize, this.chipRadius)
this.potTextPoint = TextPoint(centerX, centerY - 3.2f * chipTextSize, chipTextSize)
this.totalPotTextPoint = TextPoint(centerX, centerY - 2.2f * chipTextSize, chipTextSize)
this.potChipCircle = Circle(centerX, bcTop - 3.7f * chipTextSize, this.chipRadius)
this.potTextPoint = TextPoint(centerX, bcTop - 1.6f * chipTextSize, chipTextSize)
this.totalPotTextPoint = TextPoint(centerX, bcTop - 0.5f * chipTextSize, chipTextSize)
val playerCount = this.handHistory.numberOfPlayers
@ -307,6 +324,8 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
val point = positions[i].first
val bottomOriented = positions[i].second
if (i == positions.size - 1) { dealerBottomOriented = bottomOriented }
val rectCenterX = point.x
val rectCenterY = point.y
@ -321,7 +340,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
val prp = line.intersects(pRect) ?: throw PAIllegalStateException("should not happen")
val boxToCenterLine = MathUtils.Line(prp.x, prp.y, tableRect.centerX(), tableRect.centerY())
val boxToChipDistance = if (bottomOriented) 3.3f * chipRadius else 2 * chipRadius // because the chip text needs space
val boxToChipDistance = if (bottomOriented) 3f * chipRadius else 2f * chipRadius // because the chip text needs space
val chipPoint = boxToCenterLine.pointForDistance(boxToChipDistance)
this.chipCircles.add(Circle(chipPoint.x, chipPoint.y, chipRadius))
@ -356,10 +375,10 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
}
}
this.playerCardRects.add(cardsRectangles)
}
}
fun drawTable(canvas: Canvas, context: Context) {
this.drawer.drawTable(canvas, context)
}

@ -19,7 +19,7 @@ class ReplayerView(context: Context, attrs: AttributeSet) : View(context, attrs)
init {
this.viewTreeObserver.addOnGlobalLayoutListener {
this.animator.configure(width.toFloat(), width.toFloat(), context)
this.animator.configure(width.toFloat(), height.toFloat(), context)
}
}

Loading…
Cancel
Save