1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-31 07:26:09 +00:00
AideDeJeu/aidedejeu_flutter/lib/widgets/pceditor.dart

258 lines
6.2 KiB
Dart
Raw Normal View History

2020-02-29 02:36:15 +01:00
import 'package:aidedejeu_flutter/database.dart';
import 'package:aidedejeu_flutter/models/items.dart';
2020-03-01 01:44:08 +01:00
import 'package:aidedejeu_flutter/widgets/library.dart';
2020-02-29 02:36:15 +01:00
import 'package:flutter/material.dart';
2020-03-01 01:44:08 +01:00
import 'package:flutter_markdown/flutter_markdown.dart';
2020-02-29 02:36:15 +01:00
class PCEditorPage extends StatefulWidget {
PCEditorPage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Personnage"),
),
body: Column());
}
@override
State<StatefulWidget> createState() => _PCEditorPageState();
}
class _PCEditorPageState extends State<PCEditorPage> {
2020-03-01 00:27:51 +01:00
RaceItem _race;
SubRaceItem _subRace;
List<RaceItem> _races;
List<SubRaceItem> _subRaces;
2020-03-01 21:30:33 +01:00
BackgroundItem _background;
SubBackgroundItem _subBackground;
List<BackgroundItem> _backgrounds;
List<SubBackgroundItem> _subBackgrounds;
// inits
2020-03-01 00:27:51 +01:00
@override
void initState() {
super.initState();
2020-03-01 01:44:08 +01:00
_initRaces();
2020-03-01 21:30:33 +01:00
_initBackgrounds();
2020-03-01 01:44:08 +01:00
}
void _initRaces() async {
var races = await loadRaces();
setState(() {
_races = races.map((e) => e as RaceItem).toList();
});
}
void _initSubRaces(RaceItem race) async {
var subRaces = await loadSubRaces(race);
setState(() {
_subRaces = subRaces.map((e) => e as SubRaceItem).toList();
});
2020-03-01 00:27:51 +01:00
}
2020-03-01 21:30:33 +01:00
void _initBackgrounds() async {
var backgrounds = await loadBackgrounds();
setState(() {
_backgrounds = backgrounds.map((e) => e as BackgroundItem).toList();
});
}
void _initSubBackgrounds(BackgroundItem background) async {
var subBackgrounds = await loadSubBackgrounds(background);
setState(() {
_subBackgrounds =
subBackgrounds.map((e) => e as SubBackgroundItem).toList();
});
}
// setters
2020-03-01 00:27:51 +01:00
void _setRace(RaceItem race) {
setState(() {
this._race = race;
this._subRace = null;
this._subRaces = null;
});
2020-03-01 01:44:08 +01:00
_initSubRaces(race);
2020-03-01 00:27:51 +01:00
}
void _setSubRace(SubRaceItem subRace) {
setState(() {
this._subRace = subRace;
});
}
2020-03-01 21:30:33 +01:00
void _setBackground(BackgroundItem background) {
setState(() {
this._background = background;
this._subBackground = null;
this._subBackgrounds = null;
});
_initSubBackgrounds(background);
}
void _setSubBackground(SubBackgroundItem subBackground) {
setState(() {
this._subBackground = subBackground;
});
}
// widgets generics
Widget _loadMarkdown(String markdown) {
return MarkdownBody(
data: markdown ?? "",
onTapLink: (link) => Navigator.push(
context,
MaterialPageRoute(builder: (context) => LibraryPage(id: link)),
),
);
}
Widget _loadItemsWidget<T extends Item>(
{String hintText,
List<T> items,
T selectedItem,
ValueChanged<T> onChanged}) {
2020-03-01 00:27:51 +01:00
return DropdownButton(
2020-03-01 21:30:33 +01:00
hint: Text(hintText),
value: items != null ? selectedItem : "",
2020-03-01 00:27:51 +01:00
onChanged: (value) {
2020-03-01 21:30:33 +01:00
onChanged(value);
2020-03-01 00:27:51 +01:00
},
2020-03-01 21:30:33 +01:00
items: items != null
? items
2020-03-01 00:27:51 +01:00
.map((e) => DropdownMenuItem(
value: e,
child: Text(e.name),
))
.toList()
: null,
);
}
2020-03-01 21:30:33 +01:00
// widgets specifics
Widget _loadRacesWidget() {
return _loadItemsWidget<RaceItem>(
hintText: "Race",
items: _races,
selectedItem: _race,
onChanged: (value) {
_setRace(value);
},
);
}
Widget _loadSubRacesWidget() {
return _subRaces != null
? _loadItemsWidget<SubRaceItem>(
hintText: "Variante",
items: _subRaces,
selectedItem: _subRace,
onChanged: (value) {
_setSubRace(value);
},
)
: SizedBox.shrink();
}
Widget _loadRaceDetailsWidget() {
2020-03-01 19:04:48 +01:00
return _race != null
? Column(
children: [
Text("Augmentation de caractéristiques"),
2020-03-01 21:30:33 +01:00
_loadMarkdown(_race?.abilityScoreIncrease),
_loadMarkdown(_subRace?.abilityScoreIncrease),
2020-03-01 19:04:48 +01:00
Text("Âge"),
2020-03-01 21:30:33 +01:00
_loadMarkdown(_race?.age),
2020-03-01 19:04:48 +01:00
Text("Alignement"),
2020-03-01 21:30:33 +01:00
_loadMarkdown(_race?.alignment),
2020-03-01 19:04:48 +01:00
Text("Taille"),
2020-03-01 21:30:33 +01:00
_loadMarkdown(_race?.size),
2020-03-01 19:04:48 +01:00
Text("Vitesse"),
2020-03-01 21:30:33 +01:00
_loadMarkdown(_race?.speed),
2020-03-01 19:04:48 +01:00
Text("Vision dans le noir"),
2020-03-01 21:30:33 +01:00
_loadMarkdown(_race?.darkvision),
2020-03-01 19:04:48 +01:00
Text("Langues"),
2020-03-01 21:30:33 +01:00
_loadMarkdown(_race?.languages),
2020-03-01 19:04:48 +01:00
],
)
: SizedBox.shrink();
2020-03-01 01:44:08 +01:00
}
2020-03-01 21:30:33 +01:00
Widget _loadBackgroundsWidget() {
return _loadItemsWidget<BackgroundItem>(
hintText: "Historique",
items: _backgrounds,
selectedItem: _background,
onChanged: (value) {
_setBackground(value);
},
);
}
Widget _loadSubBackgroundsWidget() {
return _subBackgrounds != null
? _loadItemsWidget<SubBackgroundItem>(
hintText: "Variante",
items: _subBackgrounds,
selectedItem: _subBackground,
2020-03-01 00:27:51 +01:00
onChanged: (value) {
2020-03-01 21:30:33 +01:00
_setSubBackground(value);
2020-03-01 00:27:51 +01:00
},
)
: SizedBox.shrink();
}
2020-02-29 02:36:15 +01:00
@override
Widget build(BuildContext context) {
2020-03-01 19:04:48 +01:00
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: Text("Personnage"),
bottom: TabBar(
tabs: <Widget>[
Text(
"Race",
style: TextStyle(color: Colors.black),
),
Text(
"Historique",
style: TextStyle(color: Colors.black),
),
Text(
"Classe",
style: TextStyle(color: Colors.black),
),
],
),
),
body: TabBarView(
children: [
ListView(
children: <Widget>[
_loadRacesWidget(),
_loadSubRacesWidget(),
2020-03-01 21:30:33 +01:00
_loadRaceDetailsWidget(),
],
),
ListView(
children: <Widget>[
_loadBackgroundsWidget(),
_loadSubBackgroundsWidget(),
2020-03-01 19:04:48 +01:00
],
),
Text(""),
],
),
2020-02-29 02:36:15 +01:00
),
);
}
}