1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-29 22:45:44 +00:00
AideDeJeu/aidedejeu_flutter/lib/widgets/pceditor.dart

312 lines
8.2 KiB
Dart
Raw Normal View History

2020-02-29 02:36:15 +01:00
import 'package:aidedejeu_flutter/database.dart';
2020-03-03 16:03:31 +01:00
import 'package:aidedejeu_flutter/localization.dart';
2020-02-29 02:36:15 +01:00
import 'package:aidedejeu_flutter/models/items.dart';
2020-03-03 16:03:31 +01:00
import 'package:aidedejeu_flutter/theme.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
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
2020-03-04 23:19:51 +01:00
Widget _buildMarkdown(String markdown) {
2020-03-01 21:30:33 +01:00
return MarkdownBody(
data: markdown ?? "",
2020-03-04 23:19:51 +01:00
styleSheet: mainMarkdownStyleSheet(context),
2020-03-01 21:30:33 +01:00
onTapLink: (link) => Navigator.push(
context,
MaterialPageRoute(builder: (context) => LibraryPage(id: link)),
),
);
}
2020-03-04 23:19:51 +01:00
Widget _buildSubTitle(String title) {
return Text(title,
style: TextStyle(
fontSize: 16,
fontFamily: "Cinzel",
));
}
Widget _buildItemsWidget<T extends Item>(
2020-03-01 21:30:33 +01:00
{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
2020-03-04 23:19:51 +01:00
Widget _buildRacesWidget() {
return _buildItemsWidget<RaceItem>(
2020-03-01 21:30:33 +01:00
hintText: "Race",
items: _races,
selectedItem: _race,
onChanged: (value) {
_setRace(value);
},
);
}
2020-03-04 23:19:51 +01:00
Widget _buildSubRacesWidget() {
2020-03-01 21:30:33 +01:00
return _subRaces != null
2020-03-04 23:19:51 +01:00
? _buildItemsWidget<SubRaceItem>(
2020-03-01 21:30:33 +01:00
hintText: "Variante",
items: _subRaces,
selectedItem: _subRace,
onChanged: (value) {
_setSubRace(value);
},
)
: SizedBox.shrink();
}
2020-03-04 23:19:51 +01:00
Widget _buildRaceDetailsWidget() {
2020-03-01 19:04:48 +01:00
return _race != null
? Column(
2020-03-04 23:19:51 +01:00
crossAxisAlignment: CrossAxisAlignment.start,
2020-03-01 19:04:48 +01:00
children: [
2020-03-04 23:19:51 +01:00
_buildSubTitle("Augmentation de caractéristiques"),
_buildMarkdown(_race?.abilityScoreIncrease),
_buildMarkdown(_subRace?.abilityScoreIncrease),
2020-03-03 16:03:31 +01:00
Text(""),
2020-03-04 23:19:51 +01:00
_buildSubTitle("Âge"),
_buildMarkdown(_race?.age),
2020-03-03 16:03:31 +01:00
Text(""),
2020-03-04 23:19:51 +01:00
_buildSubTitle("Alignement"),
_buildMarkdown(_race?.alignment),
2020-03-03 16:03:31 +01:00
Text(""),
2020-03-04 23:19:51 +01:00
_buildSubTitle("Taille"),
_buildMarkdown(_race?.size),
2020-03-03 16:03:31 +01:00
Text(""),
2020-03-04 23:19:51 +01:00
_buildSubTitle("Vitesse"),
_buildMarkdown(_race?.speed),
2020-03-03 16:03:31 +01:00
Text(""),
2020-03-04 23:19:51 +01:00
_buildSubTitle("Vision dans le noir"),
_buildMarkdown(_race?.darkvision),
2020-03-03 16:03:31 +01:00
Text(""),
2020-03-04 23:19:51 +01:00
_buildSubTitle("Langues"),
_buildMarkdown(_race?.languages),
2020-03-01 19:04:48 +01:00
],
)
: SizedBox.shrink();
2020-03-01 01:44:08 +01:00
}
2020-03-04 23:19:51 +01:00
Widget _buildBackgroundsWidget() {
return _buildItemsWidget<BackgroundItem>(
2020-03-01 21:30:33 +01:00
hintText: "Historique",
items: _backgrounds,
selectedItem: _background,
onChanged: (value) {
_setBackground(value);
},
);
}
2020-03-04 23:19:51 +01:00
Widget _buildSubBackgroundsWidget() {
2020-03-01 21:30:33 +01:00
return _subBackgrounds != null
2020-03-04 23:19:51 +01:00
? _buildItemsWidget<SubBackgroundItem>(
2020-03-01 21:30:33 +01:00
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(
2020-03-03 16:03:31 +01:00
length: 5,
2020-03-01 19:04:48 +01:00
child: Scaffold(
appBar: AppBar(
2020-03-03 16:03:31 +01:00
title: Text(AppLocalizations.of(context).pceditorTitle),
2020-03-01 19:04:48 +01:00
bottom: TabBar(
2020-03-03 16:03:31 +01:00
labelColor: Colors.black,
isScrollable: true,
2020-03-04 23:19:51 +01:00
indicatorColor: Theme.of(context).accentColor,
// Colors.red,
2020-03-03 16:03:31 +01:00
indicatorSize: TabBarIndicatorSize.label,
2020-03-01 19:04:48 +01:00
tabs: <Widget>[
Text(
2020-03-03 16:03:31 +01:00
AppLocalizations.of(context).raceTitle,
2020-03-04 23:19:51 +01:00
style: TextStyle(
fontSize: 25,
fontFamily: "Cinzel",
),
2020-03-03 16:03:31 +01:00
),
Text(
AppLocalizations.of(context).backgroundTitle,
2020-03-04 23:19:51 +01:00
style: TextStyle(
fontSize: 25,
fontFamily: "Cinzel",
),
2020-03-03 16:03:31 +01:00
),
Text(
AppLocalizations.of(context).classTitle,
2020-03-04 23:19:51 +01:00
style: TextStyle(
fontSize: 25,
fontFamily: "Cinzel",
),
2020-03-01 19:04:48 +01:00
),
Text(
2020-03-03 16:03:31 +01:00
AppLocalizations.of(context).abilitiesTitle,
2020-03-04 23:19:51 +01:00
style: TextStyle(
fontSize: 25,
fontFamily: "Cinzel",
),
2020-03-01 19:04:48 +01:00
),
Text(
2020-03-03 16:03:31 +01:00
AppLocalizations.of(context).othersTitle,
2020-03-04 23:19:51 +01:00
style: TextStyle(
fontSize: 25,
fontFamily: "Cinzel",
),
2020-03-01 19:04:48 +01:00
),
],
),
),
body: TabBarView(
children: [
2020-03-04 23:19:51 +01:00
Container(
margin: EdgeInsets.all(10.0),
child: ListView(
children: <Widget>[
_buildRacesWidget(),
_buildSubRacesWidget(),
_buildRaceDetailsWidget(),
],
),
),
Container(
margin: EdgeInsets.all(10.0),
child: ListView(
children: <Widget>[
_buildBackgroundsWidget(),
_buildSubBackgroundsWidget(),
],
),
),
Container(
margin: EdgeInsets.all(10.0),
child: Text(AppLocalizations.of(context).classTitle),
),
Container(
margin: EdgeInsets.all(10.0),
child: Text(AppLocalizations.of(context).abilitiesTitle),
2020-03-01 21:30:33 +01:00
),
2020-03-04 23:19:51 +01:00
Container(
margin: EdgeInsets.all(10.0),
child: Text(AppLocalizations.of(context).othersTitle),
2020-03-01 19:04:48 +01:00
),
],
),
2020-02-29 02:36:15 +01:00
),
);
}
}