From 1dd98ad18a0a025e4c95db1f29e2f2c1584085f6 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 31 Aug 2020 11:17:36 +0200 Subject: [PATCH] Hand replayer layout improvement --- .../modules/handhistory/evaluator/Hand.java | 3 +- .../handhistory/replayer/ReplayerAnimator.kt | 45 +++++++++++++------ .../handhistory/replayer/ReplayerView.kt | 2 +- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/evaluator/Hand.java b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/evaluator/Hand.java index dfc76b01..3ffa4578 100755 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/evaluator/Hand.java +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/evaluator/Hand.java @@ -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 diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt index 00301f22..769c924f 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt @@ -208,11 +208,21 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) { private var chipTextPoints = mutableListOf() var boardCardRects = mutableListOf() + 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) } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt index 36cf474a..4072b8a7 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt @@ -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) } }