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

Use ActivityParameters widgets from flutter_custom_toolbox

parent ae2d4cd9
No related branches found
No related tags found
1 merge request!27Resolve "Use ActivityParameters widgets from flutter_custom_toolbox"
Pipeline #7050 passed
File moved
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
import 'package:snake/config/application_config.dart';
class ParameterPainterBoardSize extends CustomPainter {
const ParameterPainterBoardSize({
required this.context,
required this.value,
});
final BuildContext context;
final String value;
@override
void paint(Canvas canvas, Size size) {
// force square
final double canvasSize = min(size.width, size.height);
int gridWidth = 1;
switch (value) {
case ApplicationConfig.boardSizeValueSmall:
gridWidth = 2;
break;
case ApplicationConfig.boardSizeValueMedium:
gridWidth = 3;
break;
case ApplicationConfig.boardSizeValueLarge:
gridWidth = 4;
break;
case ApplicationConfig.boardSizeValueExtraLarge:
gridWidth = 5;
break;
default:
printlog('Wrong value for boardSize parameter value: $value');
}
final paint = Paint();
paint.strokeJoin = StrokeJoin.round;
paint.strokeWidth = 3 / 100 * canvasSize;
// Mini grid
final squareBackgroundColor = Colors.grey.shade200;
final squareBorderColor = Colors.grey.shade800;
final double cellSize = canvasSize / 7;
final double origin = (canvasSize - gridWidth * cellSize) / 2;
for (int row = 0; row < gridWidth; row++) {
for (int col = 0; col < gridWidth; col++) {
final Offset topLeft = Offset(origin + col * cellSize, origin + row * cellSize);
final Offset bottomRight = topLeft + Offset(cellSize, cellSize);
paint.color = squareBackgroundColor;
paint.style = PaintingStyle.fill;
canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint);
paint.color = squareBorderColor;
paint.style = PaintingStyle.stroke;
canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint);
}
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
import 'package:snake/config/application_config.dart';
class ParameterPainterDifficultyLevel extends CustomPainter {
const ParameterPainterDifficultyLevel({
required this.context,
required this.value,
});
final BuildContext context;
final String value;
@override
void paint(Canvas canvas, Size size) {
// force square
final double canvasSize = min(size.width, size.height);
final List<dynamic> stars = [];
switch (value) {
case ApplicationConfig.difficultyLevelValueEasy:
stars.add([0.5, 0.5]);
break;
case ApplicationConfig.difficultyLevelValueMedium:
stars.add([0.3, 0.5]);
stars.add([0.7, 0.5]);
break;
case ApplicationConfig.difficultyLevelValueHard:
stars.add([0.3, 0.3]);
stars.add([0.7, 0.3]);
stars.add([0.5, 0.7]);
break;
case ApplicationConfig.difficultyLevelValueNightmare:
stars.add([0.3, 0.3]);
stars.add([0.7, 0.3]);
stars.add([0.3, 0.7]);
stars.add([0.7, 0.7]);
break;
default:
printlog('Wrong value for level parameter value: $value');
}
final paint = Paint();
paint.strokeJoin = StrokeJoin.round;
paint.strokeWidth = 3 / 100 * canvasSize;
// Stars
final textSpan = TextSpan(
text: '⭐',
style: TextStyle(
color: Colors.black,
fontSize: canvasSize / 3,
fontWeight: FontWeight.bold,
),
);
final textPainter = TextPainter(
text: textSpan,
textDirection: TextDirection.ltr,
textAlign: TextAlign.center,
);
textPainter.layout();
for (var center in stars) {
textPainter.paint(
canvas,
Offset(
canvasSize * center[0] - textPainter.width * 0.5,
canvasSize * center[1] - textPainter.height * 0.5,
),
);
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
import 'package:snake/config/application_config.dart';
import 'package:snake/cubit/activity/activity_cubit.dart'; import 'package:snake/cubit/activity/activity_cubit.dart';
import 'package:snake/models/activity/cell.dart'; import 'package:snake/models/activity/cell.dart';
...@@ -19,7 +20,8 @@ class CellWidget extends StatelessWidget { ...@@ -19,7 +20,8 @@ class CellWidget extends StatelessWidget {
builder: (BuildContext context, ActivityState activityState) { builder: (BuildContext context, ActivityState activityState) {
final Activity currentActivity = activityState.currentActivity; final Activity currentActivity = activityState.currentActivity;
final String skin = currentActivity.globalSettings.skin; final String skin =
currentActivity.activitySettings.get(ApplicationConfig.parameterCodeSkin);
final String cellValueCode = getCellValueAsset(cellValue); final String cellValueCode = getCellValueAsset(cellValue);
final String imageAsset = 'assets/skins/${skin}_$cellValueCode.png'; final String imageAsset = 'assets/skins/${skin}_$cellValueCode.png';
......
...@@ -122,11 +122,11 @@ packages: ...@@ -122,11 +122,11 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: "0.4.0" ref: "0.5.0"
resolved-ref: eb9c090bd00d73324eab8737f74b3339cc24c9e8 resolved-ref: b8164a50489ba981ea57d9f02e2334f09cb8c6a7
url: "https://git.harrault.fr/android/flutter-toolbox.git" url: "https://git.harrault.fr/android/flutter-toolbox.git"
source: git source: git
version: "0.4.0" version: "0.5.0"
flutter_lints: flutter_lints:
dependency: "direct dev" dependency: "direct dev"
description: description:
......
...@@ -3,7 +3,7 @@ description: snake game ...@@ -3,7 +3,7 @@ description: snake game
publish_to: "none" publish_to: "none"
version: 0.5.4+24 version: 0.6.0+25
environment: environment:
sdk: "^3.0.0" sdk: "^3.0.0"
...@@ -16,7 +16,7 @@ dependencies: ...@@ -16,7 +16,7 @@ dependencies:
flutter_custom_toolbox: flutter_custom_toolbox:
git: git:
url: https://git.harrault.fr/android/flutter-toolbox.git url: https://git.harrault.fr/android/flutter-toolbox.git
ref: 0.4.0 ref: 0.5.0
# specific # specific
# (none) # (none)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment