diff --git a/android/gradle.properties b/android/gradle.properties index 6c1d873456149a8611e43a05ae56e4f50c73274f..24add27a90a4accaf6a1ee28ec651d0d6bda4f8e 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/fastlane/metadata/android/en-US/changelogs/20.txt b/fastlane/metadata/android/en-US/changelogs/20.txt new file mode 100644 index 0000000000000000000000000000000000000000..367712de164cb634658a65d22bb978e5ca0418cc --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/20.txt @@ -0,0 +1 @@ +Add colors theme selector in parameters. diff --git a/fastlane/metadata/android/fr-FR/changelogs/20.txt b/fastlane/metadata/android/fr-FR/changelogs/20.txt new file mode 100644 index 0000000000000000000000000000000000000000..30739ca1dc40779feb7e985d117e2894679ee86c --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/20.txt @@ -0,0 +1 @@ +Ajout de la sélection du thème de couleurs. diff --git a/lib/config/default_game_settings.dart b/lib/config/default_game_settings.dart index f57c9587708d3692fb9f1b27d0efbec02c8b749b..64fd2221a23fa55d4a65d082fbe5ee1d1aadd322 100644 --- a/lib/config/default_game_settings.dart +++ b/lib/config/default_game_settings.dart @@ -2,6 +2,7 @@ class DefaultGameSettings { static const List<String> availableParameters = [ 'boardSize', 'colorsCount', + 'colorsTheme', ]; static const int boardSizeValueSmall = 6; @@ -30,12 +31,28 @@ class DefaultGameSettings { colorsCountValueVeryHigh, ]; + static const int defaultColorsThemeValue = 1; + static const List<int> allowedColorsThemeValues = [ + // 0, // 0x9D9D9D,0xFFFFFF,0xBE2633,0xE06F8B,0x493C2B,0xA46422,0xEB8931,0xF7E26B,0x2F484E,0x44891A,0xA3CE27,0x1B2632,0x005784,0x31A2F2,0xB2DCEF,// legacy + 1, // 0x0e0e12,0x1a1a24,0x333346,0x535373,0x8080a4,0xa6a6bf,0xc1c1d2,0xe6e6ec, // https://lospec.com/palette-list/gothic-bit + 2, // 0x615e85,0x9c8dc2,0xd9a3cd,0xebc3a7,0xe0e0dc,0xa3d1af,0x90b4de,0x717fb0, // https://lospec.com/palette-list/sweethope + 3, // 0xd9af80,0xb07972,0x524352,0x686887,0x7f9bb0,0xbfd4b0,0x90b870,0x628c70, // https://lospec.com/palette-list/nostalgic-dreams + 4, // 0x8bc7bf,0x5796a1,0x524bb3,0x471b6e,0x702782,0xb0455a,0xde8b6f,0xebd694, // https://lospec.com/palette-list/arjibi8 + // 5, // 0x40263e,0x5979a6,0x84c2a3,0xefe8c3,0xefefef,0xcbc7d6,0xd06060,0x773971, // https://lospec.com/palette-list/kotomasho-8 + // 6, // 0xf0f0eb,0xffff8f,0x7be098,0x849ad8,0xe8b382,0xd8828e,0xa776c1,0x545155, // https://lospec.com/palette-list/desatur8 + // 7, // 0x211d38,0x2e2a4f,0x3b405e,0x60556e,0x9a6278,0xc7786f,0xcfa98a,0xcdd4a5, // https://lospec.com/palette-list/purplemorning8 + // 8, // 0x332422,0xc95b40,0xff9b5e,0xfcdf76,0x4c2f7f,0x3a66ad,0x39cec2,0xfafff9, // https://lospec.com/palette-list/cold-war-8 + // 9, // 0x111323,0x374566,0x50785d,0x8497b3,0xe8dcd8,0xcfb463,0xb35447,0x692e4b, // https://lospec.com/palette-list/low-8 + ]; + static List<int> getAvailableValues(String parameterCode) { switch (parameterCode) { case 'boardSize': return DefaultGameSettings.allowedBoardSizeValues; case 'colorsCount': return DefaultGameSettings.allowedColorsCountValues; + case 'colorsTheme': + return DefaultGameSettings.allowedColorsThemeValues; } return []; diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart index 4bcda5b9930a719134b215118f20fe31432f21b3..f7570750b42a30464ba3298a57b4704521931fc4 100644 --- a/lib/cubit/game_cubit.dart +++ b/lib/cubit/game_cubit.dart @@ -67,8 +67,8 @@ class GameCubit extends HydratedCubit<GameState> { refresh(); } - void shuffleColors() { - this.state.currentGame.shuffleColorsAgain(); + void shuffleColors(final int colorsTheme) { + this.state.currentGame.shuffleColorsAgain(colorsTheme); } moveCellsDown() { diff --git a/lib/cubit/settings_cubit.dart b/lib/cubit/settings_cubit.dart index 76b785030f8488d7e61c0486acfaa6ece2b99acf..99a2ac2d5b3c7d265fbc2683039727d35caa6ae0 100644 --- a/lib/cubit/settings_cubit.dart +++ b/lib/cubit/settings_cubit.dart @@ -12,12 +12,14 @@ class SettingsCubit extends HydratedCubit<SettingsState> { void setValues({ int? boardSize, int? colorsCount, + int? colorsTheme, }) { emit( SettingsState( settings: GameSettings( boardSize: boardSize ?? state.settings.boardSize, colorsCount: colorsCount ?? state.settings.colorsCount, + colorsTheme: colorsTheme ?? state.settings.colorsTheme, ), ), ); @@ -29,6 +31,8 @@ class SettingsCubit extends HydratedCubit<SettingsState> { return GameSettings.getBoardSizeValueFromUnsafe(state.settings.boardSize); case 'colorsCount': return GameSettings.getColorsCountValueFromUnsafe(state.settings.colorsCount); + case 'colorsTheme': + return GameSettings.getColorsThemeValueFromUnsafe(state.settings.colorsTheme); } return 0; } @@ -39,10 +43,12 @@ class SettingsCubit extends HydratedCubit<SettingsState> { int boardSize = code == 'boardSize' ? value : getParameterValue('boardSize'); int colorsCount = code == 'colorsCount' ? value : getParameterValue('colorsCount'); + int colorsTheme = code == 'colorsTheme' ? value : getParameterValue('colorsTheme'); setValues( boardSize: boardSize, colorsCount: colorsCount, + colorsTheme: colorsTheme, ); } @@ -50,11 +56,13 @@ class SettingsCubit extends HydratedCubit<SettingsState> { SettingsState? fromJson(Map<String, dynamic> json) { int boardSize = json['boardSize'] as int; int colorsCount = json['colorsCount'] as int; + int colorsTheme = json['colorsTheme'] as int; return SettingsState( settings: GameSettings( boardSize: boardSize, colorsCount: colorsCount, + colorsTheme: colorsTheme, ), ); } @@ -64,6 +72,7 @@ class SettingsCubit extends HydratedCubit<SettingsState> { return <String, dynamic>{ 'boardSize': state.settings.boardSize, 'colorsCount': state.settings.colorsCount, + 'colorsTheme': state.settings.colorsTheme, }; } } diff --git a/lib/models/game.dart b/lib/models/game.dart index 423654aa88be4d6e0a10e7a285af9868ee7f71b0..4ba3fe74e7c06e6b7cb2964310a4a8fd75deda42 100644 --- a/lib/models/game.dart +++ b/lib/models/game.dart @@ -1,5 +1,6 @@ import 'dart:math'; +import 'package:jeweled/config/default_game_settings.dart'; import 'package:jeweled/models/game_board.dart'; import 'package:jeweled/models/game_cell.dart'; import 'package:jeweled/models/cell_location.dart'; @@ -31,7 +32,7 @@ class Game { return Game( board: GameBoard.createNull(), settings: GameSettings.createDefault(), - shuffledColors: shuffleColors(), + shuffledColors: shuffleColors(DefaultGameSettings.defaultColorsThemeValue), ); } @@ -41,20 +42,21 @@ class Game { return Game( board: GameBoard.createRandom(settings), settings: settings, - shuffledColors: shuffleColors(), + shuffledColors: shuffleColors(settings.colorsTheme), isRunning: true, ); } - static List<int> shuffleColors() { - List<int> values = new List<int>.generate(ColorTheme.getColorsCount(), (i) => i + 1); + static List<int> shuffleColors(final int colorsTheme) { + List<int> values = + new List<int>.generate(ColorTheme.getColorsCount(colorsTheme), (i) => i + 1); values.shuffle(); return values; } - void shuffleColorsAgain() { - this.shuffledColors = shuffleColors(); + void shuffleColorsAgain(final int colorsTheme) { + this.shuffledColors = shuffleColors(colorsTheme); } GameCell getCell(CellLocation cellLocation) { diff --git a/lib/models/game_settings.dart b/lib/models/game_settings.dart index 6e2cb12098401e1187ff7d5afc89928d9cf8a4be..7e636dc4818d1bf6b583c13a234a3553f10fa5ee 100644 --- a/lib/models/game_settings.dart +++ b/lib/models/game_settings.dart @@ -3,10 +3,12 @@ import 'package:jeweled/config/default_game_settings.dart'; class GameSettings { final int boardSize; final int colorsCount; + final int colorsTheme; GameSettings({ required this.boardSize, required this.colorsCount, + required this.colorsTheme, }); static int getBoardSizeValueFromUnsafe(int size) { @@ -25,10 +27,19 @@ class GameSettings { return DefaultGameSettings.defaultColorsCountValue; } + static int getColorsThemeValueFromUnsafe(int colorsTheme) { + if (DefaultGameSettings.allowedColorsThemeValues.contains(colorsTheme)) { + return colorsTheme; + } + + return DefaultGameSettings.defaultColorsThemeValue; + } + factory GameSettings.createDefault() { return GameSettings( boardSize: DefaultGameSettings.defaultBoardSizeValue, colorsCount: DefaultGameSettings.defaultColorsCountValue, + colorsTheme: DefaultGameSettings.defaultColorsThemeValue, ); } @@ -36,6 +47,7 @@ class GameSettings { print('Settings: '); print(' boardSize: ' + boardSize.toString()); print(' colorsCount: ' + colorsCount.toString()); + print(' colorsTheme: ' + colorsTheme.toString()); } String toString() { @@ -46,6 +58,7 @@ class GameSettings { return <String, dynamic>{ 'boardSize': this.boardSize, 'colorsCount': this.colorsCount, + 'colorsTheme': this.colorsTheme, }; } } diff --git a/lib/ui/painters/game_board_painter.dart b/lib/ui/painters/game_board_painter.dart index 28000faf7062d5d8999ba39c3dbf92a55adc2965..1d72bad22e55662a10202bd32d95321aa32f26ed 100644 --- a/lib/ui/painters/game_board_painter.dart +++ b/lib/ui/painters/game_board_painter.dart @@ -33,7 +33,7 @@ class GameBoardPainter extends CustomPainter { final CellLocation cellLocation = CellLocation.go(row, col); final int? cellValue = game.getCellValueShuffled(cellLocation); if (cellValue != null) { - final int colorCode = ColorTheme.getColorCode(cellValue); + final int colorCode = ColorTheme.getColorCode(cellValue, game.settings.colorsTheme); final Animation<double>? translation = this.animations[row][col]; final double y = yOrigin + (translation?.value ?? 0) * cellSize; diff --git a/lib/ui/painters/parameter_painter.dart b/lib/ui/painters/parameter_painter.dart index 35ff29acaf991469a073e76e47878bdaf2ef00e5..dcfdf5948b5f32433d3379061e407827fb3c6283 100644 --- a/lib/ui/painters/parameter_painter.dart +++ b/lib/ui/painters/parameter_painter.dart @@ -3,6 +3,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:jeweled/config/default_game_settings.dart'; +import 'package:jeweled/models/game_settings.dart'; import 'package:jeweled/utils/color_extensions.dart'; import 'package:jeweled/utils/color_theme.dart'; @@ -11,11 +12,13 @@ class ParameterPainter extends CustomPainter { required this.code, required this.value, required this.isSelected, + required this.gameSettings, }); final String code; final int value; final bool isSelected; + final GameSettings gameSettings; @override void paint(Canvas canvas, Size size) { @@ -41,6 +44,9 @@ class ParameterPainter extends CustomPainter { case 'boardSize': paintBoardSizeParameterItem(value, canvas, canvasSize); break; + case 'colorsTheme': + paintColorsThemeParameterItem(value, canvas, canvasSize); + break; default: print('Unknown parameter: ' + code + '/' + value.toString()); paintUnknownParameterItem(value, canvas, canvasSize); @@ -121,7 +127,8 @@ class ParameterPainter extends CustomPainter { final Offset topLeft = Offset(origin + col * cellSize, origin + row * cellSize); final Offset bottomRight = topLeft + Offset(cellSize, cellSize); - final squareColor = Color(ColorTheme.getColorCode(col + row * gridWidth)); + final squareColor = + Color(ColorTheme.getColorCode(col + row * gridWidth, gameSettings.colorsTheme)); paint.color = squareColor; paint.style = PaintingStyle.fill; @@ -187,7 +194,7 @@ class ParameterPainter extends CustomPainter { final Offset bottomRight = topLeft + Offset(width, width); - final squareColor = Color(ColorTheme.getColorCode(colorIndex)); + final squareColor = Color(ColorTheme.getColorCode(colorIndex, gameSettings.colorsTheme)); paint.color = squareColor; paint.style = PaintingStyle.fill; canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint); @@ -220,4 +227,41 @@ class ParameterPainter extends CustomPainter { ), ); } + + void paintColorsThemeParameterItem(final int value, final Canvas canvas, final double size) { + Color backgroundColor = Colors.grey; + const int gridWidth = 4; + + final paint = Paint(); + paint.strokeJoin = StrokeJoin.round; + paint.strokeWidth = 3 / 100 * size; + + // Colored background + paint.color = backgroundColor; + paint.style = PaintingStyle.fill; + canvas.drawRect(Rect.fromPoints(Offset(0, 0), Offset(size, size)), paint); + + // Mini grid + final borderColor = Colors.grey.shade800; + + final double cellSize = size / gridWidth; + final double origin = (size - 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); + + final squareColor = Color(ColorTheme.getColorCode(col + row * gridWidth, value)); + + paint.color = squareColor; + paint.style = PaintingStyle.fill; + canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint); + + paint.color = borderColor; + paint.style = PaintingStyle.stroke; + canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint); + } + } + } } diff --git a/lib/ui/widgets/game_top_indicator.dart b/lib/ui/widgets/game_top_indicator.dart index 1e692b3b36a1f49ebcd67b6e969f57d7cfc79bac..6b583b2a9511f49b8703c4e2c982be06f334f6e6 100644 --- a/lib/ui/widgets/game_top_indicator.dart +++ b/lib/ui/widgets/game_top_indicator.dart @@ -60,7 +60,7 @@ class GameTopIndicatorWidget extends StatelessWidget { child: Icon(UniconsSolid.refresh), onPressed: () { final GameCubit gameCubit = BlocProvider.of<GameCubit>(context); - gameCubit.shuffleColors(); + gameCubit.shuffleColors(currentGame.settings.colorsTheme); }, ) ], diff --git a/lib/ui/widgets/parameters.dart b/lib/ui/widgets/parameters.dart index 15d1ccca2695420e26d7b027308a591e0103b60d..f756fadf14c34b3a4f882c77a4b5075e4e1245db 100644 --- a/lib/ui/widgets/parameters.dart +++ b/lib/ui/widgets/parameters.dart @@ -49,6 +49,7 @@ class Parameters extends StatelessWidget { code: code, value: value, isSelected: isActive, + gameSettings: settingsState.settings, ), isComplex: true, ), diff --git a/lib/utils/color_theme.dart b/lib/utils/color_theme.dart index 9152f0d809e176885e22022b58ea75c10c0c4275..8579cbda7f81765b26eb99ba150f0a6e162ed2bb 100644 --- a/lib/utils/color_theme.dart +++ b/lib/utils/color_theme.dart @@ -1,31 +1,77 @@ import 'package:flutter/material.dart'; class ColorTheme { - static Map<String, List<int>> itemColors = { - 'default': [ - 0x000000, - 0x9D9D9D, - 0xFFFFFF, - 0xBE2633, - 0xE06F8B, - 0x493C2B, - 0xA46422, - 0xEB8931, - 0xF7E26B, - 0x2F484E, - 0x44891A, - 0xA3CE27, - 0x1B2632, - 0x005784, - 0x31A2F2, - 0xB2DCEF, + static Map<int, List<int>> itemColors = { + // legacy + // 0:[0x9D9D9D,0xFFFFFF,0xBE2633,0xE06F8B,0x493C2B,0xA46422,0xEB8931,0xF7E26B,0x2F484E,0x44891A,0xA3CE27,0x1B2632,0x005784,0x31A2F2,0xB2DCEF,], + + // https://lospec.com/palette-list/gothic-bit + 1: [ + 0x0e0e12, + 0x1a1a24, + 0x333346, + 0x535373, + 0x8080a4, + 0xa6a6bf, + 0xc1c1d2, + 0xe6e6ec, + ], + + // https://lospec.com/palette-list/sweethope + 2: [ + 0x615e85, + 0x9c8dc2, + 0xd9a3cd, + 0xebc3a7, + 0xe0e0dc, + 0xa3d1af, + 0x90b4de, + 0x717fb0, + ], + + // https://lospec.com/palette-list/nostalgic-dreams + 3: [ + 0xd9af80, + 0xb07972, + 0x524352, + 0x686887, + 0x7f9bb0, + 0xbfd4b0, + 0x90b870, + 0x628c70, + ], + + // https://lospec.com/palette-list/arjibi8 + 4: [ + 0x8bc7bf, + 0x5796a1, + 0x524bb3, + 0x471b6e, + 0x702782, + 0xb0455a, + 0xde8b6f, + 0xebd694, ], + + // https://lospec.com/palette-list/kotomasho-8 + // 5:[0x40263e,0x5979a6,0x84c2a3,0xefe8c3,0xefefef,0xcbc7d6,0xd06060,0x773971,], + + // https://lospec.com/palette-list/desatur8 + // 6:[0xf0f0eb,0xffff8f,0x7be098,0x849ad8,0xe8b382,0xd8828e,0xa776c1,0x545155,], + + // https://lospec.com/palette-list/purplemorning8 + // 7:[0x211d38,0x2e2a4f,0x3b405e,0x60556e,0x9a6278,0xc7786f,0xcfa98a,0xcdd4a5,], + + // https://lospec.com/palette-list/cold-war-8 + // 8:[0x332422,0xc95b40,0xff9b5e,0xfcdf76,0x4c2f7f,0x3a66ad,0x39cec2,0xfafff9,], + + // https://lospec.com/palette-list/low-8 + // 9:[0x111323,0x374566,0x50785d,0x8497b3,0xe8dcd8,0xcfb463,0xb35447,0x692e4b,], }; - static int defaultItemColor = 0x808080; - static int getColorsCount() { - const skin = 'default'; + static int defaultItemColor = 0x808080; + static int getColorsCount(final int skin) { if (itemColors.containsKey(skin) && null != itemColors[skin]) { List<int> skinColors = itemColors[skin] ?? []; @@ -35,12 +81,10 @@ class ColorTheme { return 0; } - static int getColorCode(int? value) { - const skin = 'default'; - + static int getColorCode(int? value, final int skin) { if (value != null && itemColors.containsKey(skin) && null != itemColors[skin]) { List<int> skinColors = itemColors[skin] ?? []; - return (skinColors[value % getColorsCount()]) | 0xFF000000; + return (skinColors[value % getColorsCount(skin)]) | 0xFF000000; } return defaultItemColor | 0xFF000000; } diff --git a/pubspec.yaml b/pubspec.yaml index c32d629f5bc5d8afbc6a28e3b030b1662752b701..2e61b6f8493d6139990716000eebeb0c5b2b56f9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Jeweled Game publish_to: 'none' -version: 0.0.19+19 +version: 0.0.20+20 environment: sdk: '^3.0.0'