add stats

This commit is contained in:
Aaron Fischer 2019-08-07 14:55:33 +02:00
parent ec2a340a5d
commit 9369c5012f
7 changed files with 243 additions and 48 deletions

View file

@ -123,8 +123,11 @@ class Hero extends Unit {
@JsonKey(defaultValue: 0) @JsonKey(defaultValue: 0)
final int warbandaddition; final int warbandaddition;
@JsonKey(defaultValue: false, name: 'hiredsword')
final bool hiredSword;
Hero(this.stats, this.skilllists, this.weapons, this.armour, this.rules, Hero(this.stats, this.skilllists, this.weapons, this.armour, this.rules,
this.warbandaddition, this.header) { this.warbandaddition, this.header, this.hiredSword) {
this.name = this.header['name']; this.name = this.header['name'];
this.type = this.header['type']; this.type = this.header['type'];
this.experience = int.tryParse(this.header['experience']) ?? 0; this.experience = int.tryParse(this.header['experience']) ?? 0;

View file

@ -26,6 +26,7 @@ Hero _$HeroFromJson(Map json) {
Unit._splitListFromJson(json['rules'] as String), Unit._splitListFromJson(json['rules'] as String),
json['warbandaddition'] as int ?? 0, json['warbandaddition'] as int ?? 0,
Hero._heroHeaderFromJson(json['hero'] as String), Hero._heroHeaderFromJson(json['hero'] as String),
json['hiredsword'] as bool ?? false,
); );
} }

View file

@ -3,6 +3,7 @@ import 'package:preferences/preferences.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:toolheim/data/github_adapter.dart'; import 'package:toolheim/data/github_adapter.dart';
import 'package:toolheim/screens/settings_screen.dart'; import 'package:toolheim/screens/settings_screen.dart';
import 'package:toolheim/screens/unit_screen.dart';
import 'package:toolheim/screens/warband_roster_screen.dart'; import 'package:toolheim/screens/warband_roster_screen.dart';
void main() async { void main() async {
@ -24,7 +25,8 @@ class Toolheim extends StatelessWidget {
initialRoute: '/', initialRoute: '/',
routes: { routes: {
'/': (context) => WarbandRosterScreen(), '/': (context) => WarbandRosterScreen(),
'/settings': (context) => SettingsScreen() '/unit': (context) => UnitScreen(),
'/settings': (context) => SettingsScreen(),
}, },
), ),
); );

View file

@ -22,41 +22,14 @@ class SettingsScreen extends StatelessWidget {
PreferenceText( PreferenceText(
'Search the given GitHub repository for valid Warband files (ending with .warband.yml). This step can be done at any time.'), 'Search the given GitHub repository for valid Warband files (ending with .warband.yml). This step can be done at any time.'),
FlatButton( FlatButton(
onPressed: () { onPressed: () async {
github.search(); showSyncWaitingDialog(context);
showDialog( await github.search();
context: context,
builder: (BuildContext context) { Navigator.of(context, rootNavigator: true).pop();
return AlertDialog( if (github.syncErrors.length > 0) {
title: Text('Search Warbands ...'), showErrorDialog(context, github);
content: Column( }
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Checking the GitHub repository for suitable files. This can take a while.'),
SizedBox(
height: 50,
),
if (github.isSyncInProgress)
CircularProgressIndicator(),
if (github.syncErrors.length > 0)
buildSyncErrors(context),
]),
actions: <Widget>[
if (!github.isSyncInProgress)
FlatButton(
child: Text('Close',
style: TextStyle(color: Colors.blue)),
onPressed: () {
if (github.syncErrors.length > 0) {
Navigator.pop(context);
} else {
Navigator.popAndPushNamed(context, '/');
}
},
)
]);
});
}, },
child: child:
Text('Start search', style: TextStyle(color: Colors.blue))), Text('Start search', style: TextStyle(color: Colors.blue))),
@ -74,4 +47,48 @@ class SettingsScreen extends StatelessWidget {
Text(error, style: TextStyle(color: Colors.red)) Text(error, style: TextStyle(color: Colors.red))
]); ]);
} }
void showErrorDialog(context, github) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Errors'),
content:
Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text("We've got some errors while searching for warbands"),
SizedBox(
height: 50,
),
buildSyncErrors(context),
]),
actions: <Widget>[
FlatButton(
child: Text('Close', style: TextStyle(color: Colors.blue)),
onPressed: () {
github.syncErrors.clear();
Navigator.of(context, rootNavigator: true).pop();
},
)
]);
});
}
void showSyncWaitingDialog(context) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Search warbands ...'),
content: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(
'Checking the GitHub repository for suitable files. This can take a while ...'),
SizedBox(
height: 50,
),
CircularProgressIndicator(),
]),
);
});
}
} }

View file

@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:toolheim/data/github_adapter.dart';
import 'package:toolheim/data/warband_roster.dart' as roster;
import 'package:toolheim/widgets/stats_widget.dart';
class UnitScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
GitHubAdapter github = Provider.of<GitHubAdapter>(context);
final roster.Hero hero = ModalRoute.of(context).settings.arguments;
return Scaffold(
appBar: AppBar(
actions: <Widget>[
CircleAvatar(
child: Text(hero.experience.toString()),
backgroundColor: Colors.green,
foregroundColor: Colors.greenAccent,
),
],
title: Column(
children: <Widget>[
Text(hero.name),
Text(
hero.type,
textAlign: TextAlign.left,
style: TextStyle(fontSize: 12, fontWeight: FontWeight.normal),
)
],
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
)),
body: Column(
children: <Widget>[StatsWidget(hero.stats)],
));
}
}

View file

@ -1,7 +1,9 @@
import 'package:badges/badges.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:toolheim/data/github_adapter.dart'; import 'package:toolheim/data/github_adapter.dart';
import 'package:toolheim/widgets/stats_widget.dart';
import 'package:toolheim/widgets/warband_drawer_widget.dart'; import 'package:toolheim/widgets/warband_drawer_widget.dart';
class WarbandRosterScreen extends StatelessWidget { class WarbandRosterScreen extends StatelessWidget {
@ -47,26 +49,83 @@ class WarbandRosterScreen extends StatelessWidget {
child: Column(children: [ child: Column(children: [
for (var hero in github.activeRoster.heros) for (var hero in github.activeRoster.heros)
ListTile( ListTile(
title: Text(hero.name), title: Padding(
leading: CircleAvatar( padding: const EdgeInsets.only(bottom: 7),
child: Text(hero.experience.toString()), child: Row(children: <Widget>[
backgroundColor: Colors.green, Text(hero.name,
foregroundColor: Colors.greenAccent, style: TextStyle(
fontWeight: hero.rules.contains('Leader')
? FontWeight.bold
: FontWeight.normal)),
Text(
'(' + hero.type + ')',
style: TextStyle(fontSize: 10),
)
]),
), ),
subtitle: Text(hero.type), leading: CircleAvatar(
child: Row(children: <Widget>[
Spacer(),
Text(hero.experience.toString(),
style: TextStyle(color: Colors.white)),
Text(
'xp',
style: TextStyle(fontSize: 8),
),
Spacer()
]),
backgroundColor: hero.hiredSword ? Colors.black : Colors.green,
foregroundColor:
hero.hiredSword ? Colors.grey : Colors.greenAccent,
),
subtitle: StatsWidget(hero.stats),
isThreeLine: true,
onTap: () {
//Navigator.pushNamed(context, '/unit', arguments: hero);
},
), ),
Divider(), Divider(),
for (var henchmenGroup in github.activeRoster.henchmenGroups) for (var henchmenGroup in github.activeRoster.henchmenGroups)
ListTile( ListTile(
title: Text(henchmenGroup.name), title: Padding(
trailing: Chip(label: Text(henchmenGroup.number.toString() + 'x')), padding: const EdgeInsets.only(bottom: 7),
child: Row(children: <Widget>[
Text(henchmenGroup.name),
Text(
'(' + henchmenGroup.type + ')',
style: TextStyle(fontSize: 10),
),
Spacer(),
Badge(
badgeColor: Colors.black12,
shape: BadgeShape.square,
borderRadius: 2,
badgeContent: Text(henchmenGroup.number.toString() + 'x',
style: TextStyle(color: Colors.white)),
),
]),
),
leading: CircleAvatar( leading: CircleAvatar(
child: Text(henchmenGroup.experience.toString()), child: Row(children: <Widget>[
Spacer(),
Text(henchmenGroup.experience.toString(),
style: TextStyle(color: Colors.white)),
Text(
'xp',
style: TextStyle(fontSize: 8),
),
Spacer()
]),
backgroundColor: Colors.orange, backgroundColor: Colors.orange,
foregroundColor: Colors.white, foregroundColor: Colors.white,
), ),
subtitle: Text(henchmenGroup.type), subtitle: StatsWidget(henchmenGroup.stats),
) isThreeLine: true,
onTap: () {
//Navigator.pushNamed(context, '/unit', arguments: hero);
},
),
Divider()
])), ])),
); );
} }

View file

@ -0,0 +1,74 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:toolheim/data/warband_roster.dart';
class StatsWidget extends StatelessWidget {
Stats stats;
@override
Widget build(BuildContext context) {
return GridView.count(
crossAxisCount: 10,
crossAxisSpacing: 0.0,
//padding: const EdgeInsets.all(10),
primary: false,
shrinkWrap: true,
children: <Widget>[
statsElement('M', stats.movement,
stats.movement > 3 ? (stats.movement > 5 ? 3 : 2) : 1),
statsElement('WS', stats.weaponSkill,
stats.weaponSkill > 3 ? (stats.weaponSkill > 5 ? 3 : 2) : 1),
statsElement(
'BS',
stats.ballisticSkill,
stats.ballisticSkill > 3
? (stats.ballisticSkill > 5 ? 3 : 2)
: 1),
statsElement('S', stats.strength,
stats.strength > 3 ? (stats.strength > 5 ? 3 : 2) : 1),
statsElement('T', stats.toughtness,
stats.toughtness > 3 ? (stats.toughtness > 5 ? 3 : 2) : 1),
statsElement('W', stats.wounds,
stats.wounds > 1 ? (stats.wounds > 2 ? 3 : 2) : 1),
statsElement('I', stats.initiative,
stats.initiative > 3 ? (stats.initiative > 5 ? 3 : 2) : 1),
statsElement('A', stats.attacks,
stats.attacks > 1 ? (stats.attacks > 2 ? 3 : 2) : 1),
statsElement('Ld', stats.leadership,
stats.leadership > 7 ? (stats.leadership > 9 ? 3 : 2) : 1),
statsElement('Sv', stats.save,
stats.save > 0 ? (stats.leadership > 1 ? 3 : 2) : 0),
]);
}
StatsWidget(this.stats);
Widget statsElement(stat, value, qualityFactor) {
TextStyle styles = TextStyle(fontSize: 14, fontWeight: FontWeight.normal);
String val = value.toString();
if (qualityFactor == 0) {
styles = styles.merge(TextStyle(color: Colors.black45));
val = '-';
}
if (qualityFactor > 1) {
styles = styles
.merge(TextStyle(color: Colors.red, fontWeight: FontWeight.bold));
}
if (qualityFactor > 2) {
styles = styles.merge(TextStyle(color: Colors.purple));
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
stat,
style: TextStyle(fontSize: 9, color: Colors.grey),
),
Text(val, style: styles)
]);
}
}