Skip to content

Commit

Permalink
Fix display issue regarding Fast Finishing Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Jan 4, 2024
1 parent 3078d6c commit 7518098
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
grid with the values 1..6, but altering the values between saving and loading to values 0..5 lead
to a loaded grid, demanding values 1..6, but showing the key pad values 0..5.
- Loading a saved game via directly clicking on the grid area loaded the wrong game.
- Fixed Fast Finishing Mode to display the value of the selected cell.

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ class GridCellUI(
padding: Pair<Int, Int>,
layoutDetails: GridLayoutDetails,
fastFinishMode: Boolean,
numeralSystem: NumeralSystem,
showBadMaths: Boolean,
markDuplicatedInRowOrColumn: Boolean,
) {
this.cellSize = cellSize
this.westPixel = padding.first + cellSize * cell.column + GridUI.BORDER_WIDTH
this.northPixel = padding.second + cellSize * cell.row + GridUI.BORDER_WIDTH

drawCellBackground(canvas, layoutDetails, showBadMaths, markDuplicatedInRowOrColumn)
drawCellBackground(canvas, layoutDetails, showBadMaths, markDuplicatedInRowOrColumn, fastFinishMode)

if (grid.grid.getCellAt(cell.row, cell.column + 1) != null &&
cell.cage == grid.grid.getCage(cell.row, cell.column + 1)) {
Expand All @@ -61,34 +60,34 @@ class GridCellUI(
northPixel + cellSize,
layoutDetails.innerGridPaint())
}

drawCellValue(canvas, cellSize, fastFinishMode, numeralSystem)
drawSelectionRect(canvas, layoutDetails, fastFinishMode)

if (cell.possibles.isNotEmpty()) {
possibleNumbersDrawer.drawPossibleNumbers(
canvas,
grid.grid.variant.possibleDigits,
cellSize,
layoutDetails,
fastFinishMode,
numeralSystem
)
}
}

fun onDrawForeground(
canvas: Canvas,
cellSize: Float,
grid: GridUI,
padding: Pair<Int, Int>,
layoutDetails: GridLayoutDetails,
fastFinishMode: Boolean,
numeralSystem: NumeralSystem,
) {
this.cellSize = cellSize
this.westPixel = padding.first + cellSize * cell.column + GridUI.BORDER_WIDTH
this.northPixel = padding.second + cellSize * cell.row + GridUI.BORDER_WIDTH

drawSelectionRect(canvas, layoutDetails, fastFinishMode)
drawCellValue(canvas, cellSize, fastFinishMode, numeralSystem)

if (cell.possibles.isNotEmpty()) {
possibleNumbersDrawer.drawPossibleNumbers(
canvas,
grid.grid.variant.possibleDigits,
cellSize,
layoutDetails,
fastFinishMode,
numeralSystem
)
}
}

private fun drawCellValue(
Expand Down Expand Up @@ -124,10 +123,16 @@ class GridCellUI(
)
}

private fun drawCellBackground(canvas: Canvas, layoutDetails: GridLayoutDetails, showBadMaths: Boolean, markDuplicatedInRowOrColumn: Boolean) {
private fun drawCellBackground(
canvas: Canvas,
layoutDetails: GridLayoutDetails,
showBadMaths: Boolean,
markDuplicatedInRowOrColumn: Boolean,
fastFinishMode: Boolean
) {
val badMathInCage = showBadMaths && !cell.cage!!.isUserMathCorrect()

val paint = paintHolder.cellBackgroundPaint(cell, badMathInCage, markDuplicatedInRowOrColumn) ?: return
val paint = paintHolder.cellBackgroundPaint(cell, badMathInCage, markDuplicatedInRowOrColumn, fastFinishMode) ?: return

drawCellRect(layoutDetails, paint, canvas)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,24 @@ class GridPaintHolder(gridUI: GridUI) {

fun cellValuePaint(cell: GridCell, fastFinishMode: Boolean) = when {
cell.isInvalidHighlight -> warningTextPaint
cell.isSelected && fastFinishMode -> valueSelectedFastFinishModePaint
cell.isSelected && fastFinishMode -> textOnSelectedFastFinishModePaint
cell.isSelected -> valueSelectedPaint
else -> valuePaint
}

fun cellBackgroundPaint(cell: GridCell, badMathInCage: Boolean, markDuplicatedInRowOrColumn: Boolean) = when {
fun cellBackgroundPaint(
cell: GridCell,
badMathInCage: Boolean,
markDuplicatedInRowOrColumn: Boolean,
fastFinishMode: Boolean
) = when {
cell.isSelected && fastFinishMode -> selectedFastFinishModePaint
cell.isCheated -> cheatedPaint
(markDuplicatedInRowOrColumn && cell.duplicatedInRowOrColumn) || badMathInCage || cell.isInvalidHighlight -> errorBackgroundPaint
else -> null
}

fun cellForegroundPaint(cell: GridCell, fastFinishMode: Boolean) = when {
cell.isSelected && fastFinishMode -> selectedFastFinishModePaint
cell.isSelected -> selectedPaint
cell.isLastModified -> lastModifiedPaint
else -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class GridUI : View, OnTouchListener, GridView, KoinComponent {
val markDuplicatedInRowOrColumn = gridUiInjectionStrategy.markDuplicatedInRowOrColumn()

cells.forEach {
it.onDraw(canvas, this, cellSize, padding, layoutDetails, fastFinishMode, numeralSystem, showBadMaths, markDuplicatedInRowOrColumn)
it.onDraw(canvas, this, cellSize, padding, layoutDetails, fastFinishMode, showBadMaths, markDuplicatedInRowOrColumn)
}

cages.forEach {
Expand All @@ -159,7 +159,7 @@ class GridUI : View, OnTouchListener, GridView, KoinComponent {
}

cells.forEach {
it.onDrawForeground(canvas, cellSize, padding, layoutDetails, fastFinishMode)
it.onDrawForeground(canvas, cellSize, this, padding, layoutDetails, fastFinishMode, numeralSystem)
}

if (isPreviewMode) {
Expand Down

0 comments on commit 7518098

Please sign in to comment.