213 lines
7.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:manager_app/Components/message_notification.dart';
import 'package:manager_app/Components/multi_string_input_and_resource_container.dart';
import 'package:manager_app/Components/number_input_container.dart';
import 'package:manager_app/Components/resource_input_container.dart';
import 'package:manager_api_new/api.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Parcours/parcours_config.dart';
import 'package:manager_app/constants.dart';
class GameConfig extends StatefulWidget {
final String? color;
final String? label;
final GameDTO initialValue;
final ValueChanged<GameDTO> onChanged;
const GameConfig({
Key? key,
this.color,
this.label,
required this.initialValue,
required this.onChanged,
}) : super(key: key);
@override
_GameConfigState createState() => _GameConfigState();
}
class _GameConfigState extends State<GameConfig> {
late GameDTO gameDTO;
@override
void initState() {
gameDTO = widget.initialValue;
gameDTO.rows = gameDTO.rows ?? 3;
gameDTO.cols = gameDTO.cols ?? 3;
gameDTO.gameType = gameDTO.gameType ?? GameTypes.number0;
super.initState();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Type de Jeu : ",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
DropdownButton<GameTypes>(
value: gameDTO.gameType,
items: [
DropdownMenuItem(
value: GameTypes.number0, child: Text("Puzzle")),
DropdownMenuItem(
value: GameTypes.number1, child: Text("Puzzle Glissant")),
DropdownMenuItem(
value: GameTypes.number2, child: Text("Escape Game")),
],
onChanged: (val) {
setState(() {
gameDTO.gameType = val;
widget.onChanged(gameDTO);
});
},
),
],
),
),
if (gameDTO.gameType == GameTypes.number2) ...[
// Escape Mode: Parcours Config
Expanded(
child: ParcoursConfig(
initialValue: gameDTO.guidedPaths ?? [],
parentId: gameDTO.id!,
isEvent: false,
isEscapeMode: true,
onChanged: (paths) {
setState(() {
gameDTO.guidedPaths = paths;
widget.onChanged(gameDTO);
});
},
),
),
] else ...[
// Regular Puzzle Mode
Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ResourceInputContainer(
label: "Image du puzzle :",
initialValue: gameDTO.puzzleImageId ?? '',
onChanged: (ResourceDTO resourceDTO) {
setState(() {
if (resourceDTO.id == null) {
gameDTO.puzzleImageId = null;
gameDTO.puzzleImage = null;
} else {
gameDTO.puzzleImageId = resourceDTO.id;
gameDTO.puzzleImage = resourceDTO;
}
widget.onChanged(gameDTO);
});
},
),
Container(
height: 100,
child: MultiStringInputAndResourceContainer(
label: "Message départ :",
modalLabel: "Message départ",
fontSize: 20,
color: kPrimaryColor,
initialValue: gameDTO.messageDebut ?? [],
resourceTypes: [
ResourceType.Image,
ResourceType.ImageUrl,
ResourceType.VideoUrl,
ResourceType.Video,
ResourceType.Audio
],
onGetResult: (value) {
setState(() {
gameDTO.messageDebut = value;
widget.onChanged(gameDTO);
});
},
maxLines: 1,
isTitle: false,
),
),
Container(
height: 100,
child: MultiStringInputAndResourceContainer(
label: "Message fin :",
modalLabel: "Message fin",
fontSize: 20,
color: kPrimaryColor,
initialValue: gameDTO.messageFin ?? [],
resourceTypes: [
ResourceType.Image,
ResourceType.ImageUrl,
ResourceType.VideoUrl,
ResourceType.Video,
ResourceType.Audio
],
onGetResult: (value) {
setState(() {
gameDTO.messageFin = value;
widget.onChanged(gameDTO);
});
},
maxLines: 1,
isTitle: false,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 100,
child: NumberInputContainer(
label: "Nombre de lignes :",
initialValue: gameDTO.rows ?? 3,
isSmall: true,
maxLength: 2,
onChanged: (value) {
try {
gameDTO.rows = int.parse(value);
setState(() {
widget.onChanged(gameDTO);
});
} catch (e) {
showNotification(Colors.orange, kWhite,
'Cela doit être un chiffre', context, null);
}
},
),
),
Container(
height: 100,
child: NumberInputContainer(
label: "Nombre de colonnes :",
initialValue: gameDTO.cols ?? 3,
isSmall: true,
maxLength: 2,
onChanged: (value) {
try {
gameDTO.cols = int.parse(value);
setState(() {
widget.onChanged(gameDTO);
});
} catch (e) {
showNotification(Colors.orange, kWhite,
'Cela doit être un chiffre', context, null);
}
},
),
),
],
),
],
),
],
],
);
}
}