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

Add colors theme selector

parent 36641f0a
Branches
Tags
1 merge request!22Resolve "Add colors theme selector"
Pipeline #4970 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.19 app.versionName=0.0.20
app.versionCode=19 app.versionCode=20
Add colors theme selector in parameters.
Ajout de la sélection du thème de couleurs.
...@@ -2,6 +2,7 @@ class DefaultGameSettings { ...@@ -2,6 +2,7 @@ class DefaultGameSettings {
static const List<String> availableParameters = [ static const List<String> availableParameters = [
'boardSize', 'boardSize',
'colorsCount', 'colorsCount',
'colorsTheme',
]; ];
static const int boardSizeValueSmall = 6; static const int boardSizeValueSmall = 6;
...@@ -30,12 +31,28 @@ class DefaultGameSettings { ...@@ -30,12 +31,28 @@ class DefaultGameSettings {
colorsCountValueVeryHigh, 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) { static List<int> getAvailableValues(String parameterCode) {
switch (parameterCode) { switch (parameterCode) {
case 'boardSize': case 'boardSize':
return DefaultGameSettings.allowedBoardSizeValues; return DefaultGameSettings.allowedBoardSizeValues;
case 'colorsCount': case 'colorsCount':
return DefaultGameSettings.allowedColorsCountValues; return DefaultGameSettings.allowedColorsCountValues;
case 'colorsTheme':
return DefaultGameSettings.allowedColorsThemeValues;
} }
return []; return [];
......
...@@ -67,8 +67,8 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -67,8 +67,8 @@ class GameCubit extends HydratedCubit<GameState> {
refresh(); refresh();
} }
void shuffleColors() { void shuffleColors(final int colorsTheme) {
this.state.currentGame.shuffleColorsAgain(); this.state.currentGame.shuffleColorsAgain(colorsTheme);
} }
moveCellsDown() { moveCellsDown() {
......
...@@ -12,12 +12,14 @@ class SettingsCubit extends HydratedCubit<SettingsState> { ...@@ -12,12 +12,14 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
void setValues({ void setValues({
int? boardSize, int? boardSize,
int? colorsCount, int? colorsCount,
int? colorsTheme,
}) { }) {
emit( emit(
SettingsState( SettingsState(
settings: GameSettings( settings: GameSettings(
boardSize: boardSize ?? state.settings.boardSize, boardSize: boardSize ?? state.settings.boardSize,
colorsCount: colorsCount ?? state.settings.colorsCount, colorsCount: colorsCount ?? state.settings.colorsCount,
colorsTheme: colorsTheme ?? state.settings.colorsTheme,
), ),
), ),
); );
...@@ -29,6 +31,8 @@ class SettingsCubit extends HydratedCubit<SettingsState> { ...@@ -29,6 +31,8 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
return GameSettings.getBoardSizeValueFromUnsafe(state.settings.boardSize); return GameSettings.getBoardSizeValueFromUnsafe(state.settings.boardSize);
case 'colorsCount': case 'colorsCount':
return GameSettings.getColorsCountValueFromUnsafe(state.settings.colorsCount); return GameSettings.getColorsCountValueFromUnsafe(state.settings.colorsCount);
case 'colorsTheme':
return GameSettings.getColorsThemeValueFromUnsafe(state.settings.colorsTheme);
} }
return 0; return 0;
} }
...@@ -39,10 +43,12 @@ class SettingsCubit extends HydratedCubit<SettingsState> { ...@@ -39,10 +43,12 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
int boardSize = code == 'boardSize' ? value : getParameterValue('boardSize'); int boardSize = code == 'boardSize' ? value : getParameterValue('boardSize');
int colorsCount = code == 'colorsCount' ? value : getParameterValue('colorsCount'); int colorsCount = code == 'colorsCount' ? value : getParameterValue('colorsCount');
int colorsTheme = code == 'colorsTheme' ? value : getParameterValue('colorsTheme');
setValues( setValues(
boardSize: boardSize, boardSize: boardSize,
colorsCount: colorsCount, colorsCount: colorsCount,
colorsTheme: colorsTheme,
); );
} }
...@@ -50,11 +56,13 @@ class SettingsCubit extends HydratedCubit<SettingsState> { ...@@ -50,11 +56,13 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
SettingsState? fromJson(Map<String, dynamic> json) { SettingsState? fromJson(Map<String, dynamic> json) {
int boardSize = json['boardSize'] as int; int boardSize = json['boardSize'] as int;
int colorsCount = json['colorsCount'] as int; int colorsCount = json['colorsCount'] as int;
int colorsTheme = json['colorsTheme'] as int;
return SettingsState( return SettingsState(
settings: GameSettings( settings: GameSettings(
boardSize: boardSize, boardSize: boardSize,
colorsCount: colorsCount, colorsCount: colorsCount,
colorsTheme: colorsTheme,
), ),
); );
} }
...@@ -64,6 +72,7 @@ class SettingsCubit extends HydratedCubit<SettingsState> { ...@@ -64,6 +72,7 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
return <String, dynamic>{ return <String, dynamic>{
'boardSize': state.settings.boardSize, 'boardSize': state.settings.boardSize,
'colorsCount': state.settings.colorsCount, 'colorsCount': state.settings.colorsCount,
'colorsTheme': state.settings.colorsTheme,
}; };
} }
} }
import 'dart:math'; import 'dart:math';
import 'package:jeweled/config/default_game_settings.dart';
import 'package:jeweled/models/game_board.dart'; import 'package:jeweled/models/game_board.dart';
import 'package:jeweled/models/game_cell.dart'; import 'package:jeweled/models/game_cell.dart';
import 'package:jeweled/models/cell_location.dart'; import 'package:jeweled/models/cell_location.dart';
...@@ -31,7 +32,7 @@ class Game { ...@@ -31,7 +32,7 @@ class Game {
return Game( return Game(
board: GameBoard.createNull(), board: GameBoard.createNull(),
settings: GameSettings.createDefault(), settings: GameSettings.createDefault(),
shuffledColors: shuffleColors(), shuffledColors: shuffleColors(DefaultGameSettings.defaultColorsThemeValue),
); );
} }
...@@ -41,20 +42,21 @@ class Game { ...@@ -41,20 +42,21 @@ class Game {
return Game( return Game(
board: GameBoard.createRandom(settings), board: GameBoard.createRandom(settings),
settings: settings, settings: settings,
shuffledColors: shuffleColors(), shuffledColors: shuffleColors(settings.colorsTheme),
isRunning: true, isRunning: true,
); );
} }
static List<int> shuffleColors() { static List<int> shuffleColors(final int colorsTheme) {
List<int> values = new List<int>.generate(ColorTheme.getColorsCount(), (i) => i + 1); List<int> values =
new List<int>.generate(ColorTheme.getColorsCount(colorsTheme), (i) => i + 1);
values.shuffle(); values.shuffle();
return values; return values;
} }
void shuffleColorsAgain() { void shuffleColorsAgain(final int colorsTheme) {
this.shuffledColors = shuffleColors(); this.shuffledColors = shuffleColors(colorsTheme);
} }
GameCell getCell(CellLocation cellLocation) { GameCell getCell(CellLocation cellLocation) {
......
...@@ -3,10 +3,12 @@ import 'package:jeweled/config/default_game_settings.dart'; ...@@ -3,10 +3,12 @@ import 'package:jeweled/config/default_game_settings.dart';
class GameSettings { class GameSettings {
final int boardSize; final int boardSize;
final int colorsCount; final int colorsCount;
final int colorsTheme;
GameSettings({ GameSettings({
required this.boardSize, required this.boardSize,
required this.colorsCount, required this.colorsCount,
required this.colorsTheme,
}); });
static int getBoardSizeValueFromUnsafe(int size) { static int getBoardSizeValueFromUnsafe(int size) {
...@@ -25,10 +27,19 @@ class GameSettings { ...@@ -25,10 +27,19 @@ class GameSettings {
return DefaultGameSettings.defaultColorsCountValue; return DefaultGameSettings.defaultColorsCountValue;
} }
static int getColorsThemeValueFromUnsafe(int colorsTheme) {
if (DefaultGameSettings.allowedColorsThemeValues.contains(colorsTheme)) {
return colorsTheme;
}
return DefaultGameSettings.defaultColorsThemeValue;
}
factory GameSettings.createDefault() { factory GameSettings.createDefault() {
return GameSettings( return GameSettings(
boardSize: DefaultGameSettings.defaultBoardSizeValue, boardSize: DefaultGameSettings.defaultBoardSizeValue,
colorsCount: DefaultGameSettings.defaultColorsCountValue, colorsCount: DefaultGameSettings.defaultColorsCountValue,
colorsTheme: DefaultGameSettings.defaultColorsThemeValue,
); );
} }
...@@ -36,6 +47,7 @@ class GameSettings { ...@@ -36,6 +47,7 @@ class GameSettings {
print('Settings: '); print('Settings: ');
print(' boardSize: ' + boardSize.toString()); print(' boardSize: ' + boardSize.toString());
print(' colorsCount: ' + colorsCount.toString()); print(' colorsCount: ' + colorsCount.toString());
print(' colorsTheme: ' + colorsTheme.toString());
} }
String toString() { String toString() {
...@@ -46,6 +58,7 @@ class GameSettings { ...@@ -46,6 +58,7 @@ class GameSettings {
return <String, dynamic>{ return <String, dynamic>{
'boardSize': this.boardSize, 'boardSize': this.boardSize,
'colorsCount': this.colorsCount, 'colorsCount': this.colorsCount,
'colorsTheme': this.colorsTheme,
}; };
} }
} }
...@@ -33,7 +33,7 @@ class GameBoardPainter extends CustomPainter { ...@@ -33,7 +33,7 @@ class GameBoardPainter extends CustomPainter {
final CellLocation cellLocation = CellLocation.go(row, col); final CellLocation cellLocation = CellLocation.go(row, col);
final int? cellValue = game.getCellValueShuffled(cellLocation); final int? cellValue = game.getCellValueShuffled(cellLocation);
if (cellValue != null) { 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 Animation<double>? translation = this.animations[row][col];
final double y = yOrigin + (translation?.value ?? 0) * cellSize; final double y = yOrigin + (translation?.value ?? 0) * cellSize;
......
...@@ -3,6 +3,7 @@ import 'dart:math'; ...@@ -3,6 +3,7 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:jeweled/config/default_game_settings.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_extensions.dart';
import 'package:jeweled/utils/color_theme.dart'; import 'package:jeweled/utils/color_theme.dart';
...@@ -11,11 +12,13 @@ class ParameterPainter extends CustomPainter { ...@@ -11,11 +12,13 @@ class ParameterPainter extends CustomPainter {
required this.code, required this.code,
required this.value, required this.value,
required this.isSelected, required this.isSelected,
required this.gameSettings,
}); });
final String code; final String code;
final int value; final int value;
final bool isSelected; final bool isSelected;
final GameSettings gameSettings;
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
...@@ -41,6 +44,9 @@ class ParameterPainter extends CustomPainter { ...@@ -41,6 +44,9 @@ class ParameterPainter extends CustomPainter {
case 'boardSize': case 'boardSize':
paintBoardSizeParameterItem(value, canvas, canvasSize); paintBoardSizeParameterItem(value, canvas, canvasSize);
break; break;
case 'colorsTheme':
paintColorsThemeParameterItem(value, canvas, canvasSize);
break;
default: default:
print('Unknown parameter: ' + code + '/' + value.toString()); print('Unknown parameter: ' + code + '/' + value.toString());
paintUnknownParameterItem(value, canvas, canvasSize); paintUnknownParameterItem(value, canvas, canvasSize);
...@@ -121,7 +127,8 @@ class ParameterPainter extends CustomPainter { ...@@ -121,7 +127,8 @@ class ParameterPainter extends CustomPainter {
final Offset topLeft = Offset(origin + col * cellSize, origin + row * cellSize); final Offset topLeft = Offset(origin + col * cellSize, origin + row * cellSize);
final Offset bottomRight = topLeft + Offset(cellSize, 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.color = squareColor;
paint.style = PaintingStyle.fill; paint.style = PaintingStyle.fill;
...@@ -187,7 +194,7 @@ class ParameterPainter extends CustomPainter { ...@@ -187,7 +194,7 @@ class ParameterPainter extends CustomPainter {
final Offset bottomRight = topLeft + Offset(width, width); 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.color = squareColor;
paint.style = PaintingStyle.fill; paint.style = PaintingStyle.fill;
canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint); canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint);
...@@ -220,4 +227,41 @@ class ParameterPainter extends CustomPainter { ...@@ -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);
}
}
}
} }
...@@ -60,7 +60,7 @@ class GameTopIndicatorWidget extends StatelessWidget { ...@@ -60,7 +60,7 @@ class GameTopIndicatorWidget extends StatelessWidget {
child: Icon(UniconsSolid.refresh), child: Icon(UniconsSolid.refresh),
onPressed: () { onPressed: () {
final GameCubit gameCubit = BlocProvider.of<GameCubit>(context); final GameCubit gameCubit = BlocProvider.of<GameCubit>(context);
gameCubit.shuffleColors(); gameCubit.shuffleColors(currentGame.settings.colorsTheme);
}, },
) )
], ],
......
...@@ -49,6 +49,7 @@ class Parameters extends StatelessWidget { ...@@ -49,6 +49,7 @@ class Parameters extends StatelessWidget {
code: code, code: code,
value: value, value: value,
isSelected: isActive, isSelected: isActive,
gameSettings: settingsState.settings,
), ),
isComplex: true, isComplex: true,
), ),
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ColorTheme { class ColorTheme {
static Map<String, List<int>> itemColors = { static Map<int, List<int>> itemColors = {
'default': [ // legacy
0x000000, // 0:[0x9D9D9D,0xFFFFFF,0xBE2633,0xE06F8B,0x493C2B,0xA46422,0xEB8931,0xF7E26B,0x2F484E,0x44891A,0xA3CE27,0x1B2632,0x005784,0x31A2F2,0xB2DCEF,],
0x9D9D9D,
0xFFFFFF, // https://lospec.com/palette-list/gothic-bit
0xBE2633, 1: [
0xE06F8B, 0x0e0e12,
0x493C2B, 0x1a1a24,
0xA46422, 0x333346,
0xEB8931, 0x535373,
0xF7E26B, 0x8080a4,
0x2F484E, 0xa6a6bf,
0x44891A, 0xc1c1d2,
0xA3CE27, 0xe6e6ec,
0x1B2632, ],
0x005784,
0x31A2F2, // https://lospec.com/palette-list/sweethope
0xB2DCEF, 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() { static int defaultItemColor = 0x808080;
const skin = 'default';
static int getColorsCount(final int skin) {
if (itemColors.containsKey(skin) && null != itemColors[skin]) { if (itemColors.containsKey(skin) && null != itemColors[skin]) {
List<int> skinColors = itemColors[skin] ?? []; List<int> skinColors = itemColors[skin] ?? [];
...@@ -35,12 +81,10 @@ class ColorTheme { ...@@ -35,12 +81,10 @@ class ColorTheme {
return 0; return 0;
} }
static int getColorCode(int? value) { static int getColorCode(int? value, final int skin) {
const skin = 'default';
if (value != null && itemColors.containsKey(skin) && null != itemColors[skin]) { if (value != null && itemColors.containsKey(skin) && null != itemColors[skin]) {
List<int> skinColors = itemColors[skin] ?? []; List<int> skinColors = itemColors[skin] ?? [];
return (skinColors[value % getColorsCount()]) | 0xFF000000; return (skinColors[value % getColorsCount(skin)]) | 0xFF000000;
} }
return defaultItemColor | 0xFF000000; return defaultItemColor | 0xFF000000;
} }
......
...@@ -3,7 +3,7 @@ description: Jeweled Game ...@@ -3,7 +3,7 @@ description: Jeweled Game
publish_to: 'none' publish_to: 'none'
version: 0.0.19+19 version: 0.0.20+20
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.
Please register or to comment