From b5a5f60618002fe1ce774058b402b1db8621e797 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Tue, 13 Aug 2019 22:37:22 +0200 Subject: [PATCH] meta information --- mobile-app/lib/data/warband_roster.dart | 12 ++ .../lib/screens/warband_roster_screen.dart | 197 ++++++++---------- .../henchmengroup_list_tile_widget.dart | 56 +++++ .../lib/widgets/hero_list_tile_widget.dart | 50 +++++ mobile-app/lib/widgets/value_chip_widget.dart | 23 ++ 5 files changed, 228 insertions(+), 110 deletions(-) create mode 100644 mobile-app/lib/widgets/henchmengroup_list_tile_widget.dart create mode 100644 mobile-app/lib/widgets/hero_list_tile_widget.dart create mode 100644 mobile-app/lib/widgets/value_chip_widget.dart diff --git a/mobile-app/lib/data/warband_roster.dart b/mobile-app/lib/data/warband_roster.dart index 3342744..74b1f00 100644 --- a/mobile-app/lib/data/warband_roster.dart +++ b/mobile-app/lib/data/warband_roster.dart @@ -375,6 +375,18 @@ class WarbandRoster { return rating; } + int routLimit() { + var unitCount = heros.length; + henchmenGroups.forEach((group) => unitCount += group.number); + + var routLimit = (unitCount / 4).round(); + if (unitCount / 4 > routLimit) { + routLimit++; + } + + return routLimit; + } + static HashMap _warbandNameAndRaceFromJson( String nameAndRace) { HashMap nr = new HashMap(); diff --git a/mobile-app/lib/screens/warband_roster_screen.dart b/mobile-app/lib/screens/warband_roster_screen.dart index 3f35fad..d9eca7e 100644 --- a/mobile-app/lib/screens/warband_roster_screen.dart +++ b/mobile-app/lib/screens/warband_roster_screen.dart @@ -1,18 +1,18 @@ -import 'package:badges/badges.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:timeago_flutter/timeago_flutter.dart'; import 'package:toolheim/data/github_adapter.dart'; -import 'package:toolheim/widgets/stats_widget.dart'; +import 'package:toolheim/data/warband_roster.dart'; +import 'package:toolheim/widgets/henchmengroup_list_tile_widget.dart'; +import 'package:toolheim/widgets/hero_list_tile_widget.dart'; +import 'package:toolheim/widgets/value_chip_widget.dart'; import 'package:toolheim/widgets/warband_drawer_widget.dart'; class WarbandRosterScreen extends StatelessWidget { @override Widget build(BuildContext context) { - GitHubAdapter github = Provider.of(context); - - if (github.activeRoster == null) { + if (github(context).activeRoster == null) { return Scaffold( appBar: AppBar(title: const Text('Toolheim')), body: Builder(builder: (BuildContext context) { @@ -40,113 +40,90 @@ class WarbandRosterScreen extends StatelessWidget { child: SingleChildScrollView(child: WarbandDrawerWidget()))); } + WarbandRoster roster = github(context).activeRoster; + return Scaffold( - appBar: AppBar( - title: Text(github.activeRoster.name), + drawer: warbandDrawer(context), + appBar: AppBar(title: Text(roster.name)), + body: SingleChildScrollView( + child: Column(children: [ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Row( + children: [ + ValueChipWidget('CP', roster.campaignPoints.toString()), + ValueChipWidget('Rating', roster.rating().toString()), + ValueChipWidget('Rout Limit', roster.routLimit().toString()), + ], + ), + ), + Divider(), + ...units(roster), + warbandMetaInformation(roster) + ]))); + } + + Widget warbandMetaInformation(WarbandRoster roster) { + return Padding( + padding: const EdgeInsets.only(left: 40, right: 40, top: 30), + child: Table( + columnWidths: {0: FixedColumnWidth(80)}, + children: [ + metaTableRow('Alignment', roster.alignment), + metaTableRow('Objective', roster.objective), + metaTableRow('Achivements', roster.achievments), + metaTableRow('Shards', roster.shards), + metaTableRow('GC', roster.gc), + metaTableRow('Equipment', roster.equipment), + ], ), - drawer: Drawer( - child: Column(children: [ - Expanded(child: SingleChildScrollView(child: WarbandDrawerWidget())), - Container( - color: Colors.brown, - padding: EdgeInsets.all(10), - child: Align( - alignment: Alignment.bottomLeft, - child: Timeago( - date: github.lastSync, - builder: (_, value) => Text( - 'Last sync: ' + value, - style: TextStyle(color: Colors.white), - )))) - ])), - body: SingleChildScrollView( - child: Column(children: [ - for (var hero in github.activeRoster.heros) - ListTile( - title: Padding( - padding: const EdgeInsets.only(bottom: 5), - child: Row(children: [ - Padding( - padding: const EdgeInsets.only(right: 5), - child: Text(hero.name, - style: TextStyle( - fontWeight: hero.rules.contains('Leader') - ? FontWeight.bold - : FontWeight.normal)), - ), - Text( - '(' + hero.type + ')', - style: TextStyle(fontSize: 10), - ) - ]), - ), - leading: CircleAvatar( - child: Row(children: [ - 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(), - for (var henchmenGroup in github.activeRoster.henchmenGroups) - ListTile( - title: Padding( - padding: const EdgeInsets.only(bottom: 7), - child: Row(children: [ - Padding( - padding: const EdgeInsets.only(right: 5), - child: 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( - child: Row(children: [ - Spacer(), - Text(henchmenGroup.experience.toString(), - style: TextStyle(color: Colors.white)), - Text( - 'xp', - style: TextStyle(fontSize: 8), - ), - Spacer() - ]), - backgroundColor: Colors.orange, - foregroundColor: Colors.white, - ), - subtitle: StatsWidget(henchmenGroup.stats), - isThreeLine: true, - onTap: () { - //Navigator.pushNamed(context, '/unit', arguments: hero); - }, - ), - Divider() - ])), ); } + + TableRow metaTableRow(String name, dynamic value) { + return TableRow(children: [ + Text( + name.toString().trim() + ':', + style: TextStyle(fontSize: 12), + textAlign: TextAlign.right, + ), + Padding( + padding: const EdgeInsets.only(left: 10, bottom: 10), + child: Text( + value.toString().trim(), + style: TextStyle(fontWeight: FontWeight.bold), + ), + ) + ]); + } + + Drawer warbandDrawer(BuildContext context) { + return Drawer( + child: Column(children: [ + Expanded(child: SingleChildScrollView(child: WarbandDrawerWidget())), + Container( + color: Colors.brown, + padding: EdgeInsets.all(10), + child: Align( + alignment: Alignment.bottomLeft, + child: Timeago( + date: github(context).lastSync, + builder: (_, value) => Text( + 'Last sync: ' + value, + style: TextStyle(color: Colors.white), + )))) + ])); + } + + List units(WarbandRoster roster) { + return [ + for (var hero in roster.heros) HeroListTileWidget(hero), + Divider(), + for (var henchmenGroup in roster.henchmenGroups) + HenchmengroupListTileWidget(henchmenGroup), + Divider() + ]; + } + + GitHubAdapter github(context) => Provider.of(context); } diff --git a/mobile-app/lib/widgets/henchmengroup_list_tile_widget.dart b/mobile-app/lib/widgets/henchmengroup_list_tile_widget.dart new file mode 100644 index 0000000..d91464c --- /dev/null +++ b/mobile-app/lib/widgets/henchmengroup_list_tile_widget.dart @@ -0,0 +1,56 @@ +import 'package:badges/badges.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:toolheim/widgets/stats_widget.dart'; + +class HenchmengroupListTileWidget extends StatelessWidget { + final henchmenGroup; + + HenchmengroupListTileWidget(this.henchmenGroup); + + @override + Widget build(BuildContext context) { + return ListTile( + title: Padding( + padding: const EdgeInsets.only(bottom: 7), + child: Row(children: [ + Padding( + padding: const EdgeInsets.only(right: 5), + child: 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( + child: Row(children: [ + Spacer(), + Text(henchmenGroup.experience.toString(), + style: TextStyle(color: Colors.white)), + Text( + 'xp', + style: TextStyle(fontSize: 8), + ), + Spacer() + ]), + backgroundColor: Colors.orange, + foregroundColor: Colors.white, + ), + subtitle: StatsWidget(henchmenGroup.stats), + isThreeLine: true, + onTap: () { + //Navigator.pushNamed(context, '/unit', arguments: hero); + }, + ); + } +} diff --git a/mobile-app/lib/widgets/hero_list_tile_widget.dart b/mobile-app/lib/widgets/hero_list_tile_widget.dart new file mode 100644 index 0000000..55a5430 --- /dev/null +++ b/mobile-app/lib/widgets/hero_list_tile_widget.dart @@ -0,0 +1,50 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:toolheim/widgets/stats_widget.dart'; + +class HeroListTileWidget extends StatelessWidget { + final hero; + + HeroListTileWidget(this.hero); + + @override + Widget build(BuildContext context) { + return ListTile( + title: Padding( + padding: const EdgeInsets.only(bottom: 5), + child: Row(children: [ + Padding( + padding: const EdgeInsets.only(right: 5), + child: Text(hero.name, + style: TextStyle( + fontWeight: hero.rules.contains('Leader') + ? FontWeight.bold + : FontWeight.normal)), + ), + Text( + '(' + hero.type + ')', + style: TextStyle(fontSize: 10), + ) + ]), + ), + leading: CircleAvatar( + child: Row(children: [ + 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); + }); + } +} diff --git a/mobile-app/lib/widgets/value_chip_widget.dart b/mobile-app/lib/widgets/value_chip_widget.dart new file mode 100644 index 0000000..33e3648 --- /dev/null +++ b/mobile-app/lib/widgets/value_chip_widget.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +class ValueChipWidget extends StatelessWidget { + final String name; + final String value; + + ValueChipWidget(this.name, this.value); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.all(8.0), + child: Chip( + label: Row(children: [ + Text(name.toString() + ': '), + Text( + value.toString(), + style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ) + ])), + ); + } +}