From 2671c27659443fd363681bec988cc70dad24f200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Fri, 25 Jun 2021 16:45:53 +0200 Subject: [PATCH] Highlight cells with same value as currently selected one --- android/gradle.properties | 4 ++-- lib/entities/cell.dart | 12 +++++++++++- lib/layout/game.dart | 3 ++- lib/provider/data.dart | 13 +++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index 6c1d873..24add27 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.19 -app.versionCode=19 +app.versionName=0.0.20 +app.versionCode=20 diff --git a/lib/entities/cell.dart b/lib/entities/cell.dart index 4632c96..f8911de 100644 --- a/lib/entities/cell.dart +++ b/lib/entities/cell.dart @@ -35,7 +35,7 @@ class Cell { ), onTap: () { if (col != null && row != null) { - if (!this.isFixed && (col != myProvider.currentCellCol || row != myProvider.currentCellRow)) { + if (col != myProvider.currentCellCol || row != myProvider.currentCellRow) { myProvider.selectCell(col, row); } else { myProvider.selectCell(null, null); @@ -51,6 +51,8 @@ class Cell { Color editableCellColorConflict = Colors.pink[100]; Color fixedCellColor = Colors.grey[300]; Color fixedCellColorConflict = Colors.pink[200]; + Color editableSelectedValueColor = Colors.green[100]; + Color fixedSelectedValueColor = Colors.green[300]; Color backgroundColor = editableCellColor; @@ -66,6 +68,14 @@ class Cell { } } + if (myProvider.showConflicts && (this.value == myProvider.currentCellValue)) { + if (this.isFixed) { + backgroundColor = fixedSelectedValueColor; + } else { + backgroundColor = editableSelectedValueColor; + } + } + return backgroundColor; } diff --git a/lib/layout/game.dart b/lib/layout/game.dart index 6b09b41..60f7727 100644 --- a/lib/layout/game.dart +++ b/lib/layout/game.dart @@ -30,6 +30,7 @@ class Game { Color borderColor = Colors.blue; bool isCellSelected = (myProvider.currentCellCol != null && myProvider.currentCellRow != null); + bool isUpdatableCellSelected = isCellSelected ? !myProvider.cells[myProvider.currentCellRow][myProvider.currentCellCol].isFixed : false; int maxValue = myProvider.blockSizeHorizontal * myProvider.blockSizeVertical; return Container( @@ -45,7 +46,7 @@ class Game { Column( children: [ Cell( - isCellSelected ? value : 0, + isUpdatableCellSelected ? value : 0, false ).widgetUpdateValue(myProvider) ] diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 0225b29..a4adb6f 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -24,6 +24,7 @@ class Data extends ChangeNotifier { List _cells = []; int _currentCellCol = null; int _currentCellRow = null; + int _currentCellValue = null; String get level => _level; set updateLevel(String level) { @@ -104,9 +105,21 @@ class Data extends ChangeNotifier { notifyListeners(); } + int get currentCellValue => _currentCellValue; + set updateCurrentCellValue(int currentCellValue) { + _currentCellValue = currentCellValue; + notifyListeners(); + } + selectCell(int col, int row) { _currentCellCol = col; _currentCellRow = row; + _currentCellValue = null; + if (row != null && col != null) { + if (_cells[row][col].value != 0) { + _currentCellValue = _cells[row][col].value; + } + } notifyListeners(); } -- GitLab