Skip to content
Snippets Groups Projects
Commit 733cfb65 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '43-add-a-delay-after-use-help-button-to-reactivate' into 'master'

Resolve "Add a delay after use help button to reactivate"

Closes #43

See merge request !45
parents 8bedd559 b2f230af
No related branches found
No related tags found
1 merge request!45Resolve "Add a delay after use help button to reactivate"
Pipeline #5591 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.1.17 app.versionName=0.1.18
app.versionCode=66 app.versionCode=67
Add a timer after use of "help" button.
Ajout d'une temporisation pour réactiver le bouton "aide" après usage.
import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -54,6 +55,7 @@ class Data extends ChangeNotifier { ...@@ -54,6 +55,7 @@ class Data extends ChangeNotifier {
int? _selectedCellValue; int? _selectedCellValue;
bool _showConflicts = false; bool _showConflicts = false;
int _givenTipsCount = 0; int _givenTipsCount = 0;
int _givenTipsCountEnableCountdown = 0;
String _currentSavedState = ''; String _currentSavedState = '';
void updateParameterLevel(String parameterLevel) { void updateParameterLevel(String parameterLevel) {
...@@ -246,23 +248,45 @@ class Data extends ChangeNotifier { ...@@ -246,23 +248,45 @@ class Data extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
int get givenTipsCountEnableCountdown => _givenTipsCountEnableCountdown;
int get givenTipsCount => _givenTipsCount; int get givenTipsCount => _givenTipsCount;
increaseGivenTipsCount() { void increaseGivenTipsCount() {
_givenTipsCount = _givenTipsCount + 1; _givenTipsCount = _givenTipsCount + 1;
_givenTipsCountEnableCountdown = 60;
const Duration interval = Duration(milliseconds: 500);
Timer.periodic(
interval,
(Timer timer) {
if (_givenTipsCountEnableCountdown == 0) {
timer.cancel();
notifyListeners();
} else {
_givenTipsCountEnableCountdown--;
notifyListeners();
}
},
);
saveCurrentGameState(); saveCurrentGameState();
notifyListeners(); notifyListeners();
} }
setGivenTipsCount(int value) { void setGivenTipsCount(int value) {
_givenTipsCount = value; _givenTipsCount = value;
_givenTipsCountEnableCountdown = 0;
notifyListeners(); notifyListeners();
} }
resetGivenTipsCount() { bool canGiveTip() {
return (_givenTipsCountEnableCountdown == 0);
}
void resetGivenTipsCount() {
setGivenTipsCount(0); setGivenTipsCount(0);
} }
selectCell(int? col, int? row) { void selectCell(int? col, int? row) {
_selectedCellCol = col; _selectedCellCol = col;
_selectedCellRow = row; _selectedCellRow = row;
_selectedCellValue = null; _selectedCellValue = null;
...@@ -291,7 +315,7 @@ class Data extends ChangeNotifier { ...@@ -291,7 +315,7 @@ class Data extends ChangeNotifier {
_boardConflicts = conflictsCount; _boardConflicts = conflictsCount;
} }
updateCellValue(int? col, int? row, int value) { void updateCellValue(int? col, int? row, int value) {
if ((col != null) && (row != null)) { if ((col != null) && (row != null)) {
if (!_board[row][col].isFixed) { if (!_board[row][col].isFixed) {
_board[row][col] = Cell( _board[row][col] = Cell(
......
...@@ -117,13 +117,16 @@ class HomeState extends State<Home> { ...@@ -117,13 +117,16 @@ class HomeState extends State<Home> {
myProvider.givenTipsCount == 0 ? '' : myProvider.givenTipsCount.toString(), myProvider.givenTipsCount == 0 ? '' : myProvider.givenTipsCount.toString(),
style: const TextStyle(color: Colors.white), style: const TextStyle(color: Colors.white),
), ),
child: const Image( child: Container(
image: AssetImage('assets/icons/button_help.png'), padding: EdgeInsets.all(myProvider.givenTipsCountEnableCountdown / 4),
fit: BoxFit.fill, child: const Image(
image: AssetImage('assets/icons/button_help.png'),
fit: BoxFit.fill,
),
), ),
), ),
), ),
onPressed: () => GameUtils.showTip(myProvider), onPressed: () => myProvider.canGiveTip() ? GameUtils.showTip(myProvider) : null,
)); ));
menuActions.add(const Spacer()); menuActions.add(const Spacer());
menuActions.add(TextButton( menuActions.add(TextButton(
......
name: sudoku name: sudoku
description: A sudoku game application. description: A sudoku game application.
publish_to: 'none' publish_to: 'none'
version: 0.1.17+66 version: 0.1.18+67
environment: environment:
sdk: '^3.0.0' sdk: '^3.0.0'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment