Skip to content

Commit

Permalink
Merge pull request #29 from khari05/dev
Browse files Browse the repository at this point in the history
The blue team column hides in the match breakdown when viewing remote events
  • Loading branch information
nholo1332 authored Dec 1, 2020
2 parents 4d43402 + aa903b8 commit 81e14d8
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 37 deletions.
5 changes: 3 additions & 2 deletions lib/models/game-specifics/game-data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:toa_flutter/ui/views/match/years/match-breakdown-1718.dart';
import 'package:toa_flutter/ui/views/match/years/match-breakdown-1819.dart';
import 'package:toa_flutter/ui/views/match/years/match-breakdown-1920.dart';
import 'package:toa_flutter/ui/views/match/years/match-breakdown-2021.dart';
import 'package:toa_flutter/ui/views/match/years/remote-match-breakdown-2021.dart';

class GameData {

Expand All @@ -33,7 +34,7 @@ class GameData {
}
}

static List<Widget> getBreakdown(Match match, BuildContext context) {
static List<Widget> getBreakdown(Match match, BuildContext context, bool isRemote) {
List<Widget> noData = [NoDataWidget(MdiIcons.ballotOutline, 'No Breakdown found')];
if (match.gameData == null) {
return noData;
Expand All @@ -46,7 +47,7 @@ class GameData {
case '1920':
return MatchBreakdown1920.getRows(match, context);
case '2021':
return MatchBreakdown2021.getRows(match, context);
return isRemote ? RemoteMatchBreakdown2021.getRows(match, context) : MatchBreakdown2021.getRows(match, context); // remote events were only introduced in 2020/2021
default:
return noData;
}
Expand Down
10 changes: 9 additions & 1 deletion lib/sort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ class Sort {
int tournamentLevel2 = b.tournamentLevel;
int matchNumber1 = int.parse(a.matchKey.split("-")[3].substring(1, 4));
int matchNumber2 = int.parse(b.matchKey.split("-")[3].substring(1, 4));
int matchParticipant1 = int.parse(a.participants[0].teamKey);
int matchParticipant2 = int.parse(b.participants[0].teamKey);
bool isMatchRemote = a.participants.length == 1;

if (tournamentLevel1 == tournamentLevel2) {
/**
* if a match is remote but has already been sorted by team number, it will skip to the next condition: match number.
*/
if (tournamentLevel1 == tournamentLevel2 && isMatchRemote && matchParticipant1 != matchParticipant2) {
return matchParticipant1 < matchParticipant2 ? -1 : 1;
} else if (tournamentLevel1 == tournamentLevel2) {
return matchNumber1 < matchNumber2 ? -1 : 1;
} else if (tournamentLevel1 == MatchType.FINALS_MATCH) {
return 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/views/match/match-page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class MatchPageState extends State<MatchPage> {

// Match breakdown
column.add(!loadingBreakdown
? Column(children: GameData.getBreakdown(match, context))
? Column(children: GameData.getBreakdown(match, context, match.participants.length == 1))
: Container(
margin: EdgeInsets.only(top: 36, bottom: 24),
child: Center(child: CircularProgressIndicator())));
Expand Down
15 changes: 7 additions & 8 deletions lib/ui/views/match/years/match-breakdown-2021.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MatchBreakdown2021 {
MatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.power_shots'),
red: details.red.autoPowerShotPoints ~/ 15,
blue: details.blue.autoPowerShotPoints ~/ 15,
blue: details.blue.autoPowerShotPoints != null ? details.blue.autoPowerShotPoints ~/ 15 : 0,
points: 15),
MatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.wobble_goal_1_delivered'),
Expand Down Expand Up @@ -94,18 +94,18 @@ class MatchBreakdown2021 {
points: 5),
MatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.wobble_goal_1_end_position'),
red: getUltimateGoalWobbleString(details.red.wobbleRings1, local),
blue: getUltimateGoalWobbleString(details.blue.wobbleRings2, local),
red: getUltimateGoalWobbleString(details.red.wobbleEnd1, local),
blue: getUltimateGoalWobbleString(details.blue.wobbleEnd1, local),
text: true),
MatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.wobble_goal_2_end_position'),
red: getUltimateGoalWobbleString(details.red.wobbleRings2, local),
blue: getUltimateGoalWobbleString(details.blue.wobbleRings2, local),
red: getUltimateGoalWobbleString(details.red.wobbleEnd2, local),
blue: getUltimateGoalWobbleString(details.blue.wobbleEnd2, local),
text: true),
MatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.power_shots'),
red: details.red.endPowerShotPoints ~/ 15,
blue: details.blue.endPowerShotPoints ~/ 15,
blue: details.blue.endPowerShotPoints != null ? details.blue.endPowerShotPoints ~/ 15 : 0,
points: 15),

MatchBreakdownRow(
Expand All @@ -132,9 +132,8 @@ class MatchBreakdown2021 {
return local.get('breakdowns.ultimategoal.start_line') + ' (+5)';
case 2:
return local.get('breakdowns.ultimategoal.drop_zone') + ' (+20)';
case 0:
default:
return local.get('breakdowns.ultimategoal.not_scored');
}
return local.get('breakdowns.ultimategoal.not_scored');
}
}
115 changes: 115 additions & 0 deletions lib/ui/views/match/years/remote-match-breakdown-2021.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import 'package:flutter/material.dart';

import '../../../../internationalization/localizations.dart';
import '../../../../models/match.dart';
import '../../../widgets/remote-match-breakdown-row.dart';
import 'package:toa_flutter/models/game-specifics/ultimategoal-match-details.dart';

class RemoteMatchBreakdown2021 {
static List<Widget> getRows(
Match match, BuildContext context) {
TOALocalizations local = TOALocalizations.of(context);
UltimateGoalMatchDetails details = match.gameData;
return <Widget>[
RemoteMatchBreakdownRow(
name: local.get('breakdowns.autonomous'),
team: match.redAutoScore,
title: true),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.rings_high'),
team: details.red.autoTowerHigh,
points: 12),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.rings_middle'),
team: details.red.autoTowerMid,
points: 6),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.rings_low'),
team: details.red.autoTowerLow,
points: 3),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.power_shots'),
team: details.red.autoPowerShotPoints != null
? details.red.autoPowerShotPoints ~/ 15
: 0,
points: 15),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.wobble_goal_1_delivered'),
team: details.red.wobbleDelivered1,
points: 15),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.wobble_goal_2_delivered'),
team: details.red.wobbleDelivered2,
points: 15),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.robot_1_navigated'),
team: details.red.navigated1,
points: 5),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.teleop'),
team: match.redTeleScore,
title: true),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.rings_high'),
team: details.red.dcTowerHigh,
points: 6),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.rings_middle'),
team: details.red.dcTowerMid,
points: 4),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.rings_low'),
team: details.red.dcTowerLow,
points: 2),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.end'),
team: match.redEndScore,
title: true),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.wobble_goal_1_rings'),
team: details.red.wobbleRings1,
points: 5),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.wobble_goal_2_rings'),
team: details.red.wobbleRings2,
points: 5),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.wobble_goal_1_end_position'),
team: getUltimateGoalWobbleString(details.red.wobbleEnd1, local),
text: true),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.wobble_goal_2_end_position'),
team: getUltimateGoalWobbleString(details.red.wobbleEnd2, local),
text: true),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.ultimategoal.power_shots'),
team: details.red.endPowerShotPoints != null
? details.red.endPowerShotPoints ~/ 15
: 0,
points: 15),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.penalty'),
team: match.redPenalty,
title: true),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.minor_penalty'),
team: details.redMinPen,
points: 5),
RemoteMatchBreakdownRow(
name: local.get('breakdowns.major_penalty'),
team: details.redMajPen,
points: 20),
];
}

static getUltimateGoalWobbleString(int key, TOALocalizations local) {
switch (key) {
case 1:
return local.get('breakdowns.ultimategoal.start_line') + ' (+5)';
case 2:
return local.get('breakdowns.ultimategoal.drop_zone') + ' (+20)';
default:
return local.get('breakdowns.ultimategoal.not_scored');
}
}
}
11 changes: 7 additions & 4 deletions lib/ui/widgets/match-breakdown-row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int FALSE_VALUE = -2000;

class MatchBreakdownRow extends StatelessWidget {

MatchBreakdownRow({dynamic red, dynamic blue, this.points, this.name, this.title=false, this.text=false}) {
MatchBreakdownRow({dynamic red, dynamic blue, this.points, this.name, this.title=false, this.text=false, this.half=false}) {
if (red is bool && !text) {
this.red = red ? TRUE_VALUE : FALSE_VALUE;
} else if (red is String && text) {
Expand All @@ -37,6 +37,7 @@ class MatchBreakdownRow extends StatelessWidget {
final String name;
final bool title;
final bool text;
final bool half;

TOALocalizations local;
ThemeData theme;
Expand All @@ -51,8 +52,10 @@ class MatchBreakdownRow extends StatelessWidget {
this.text ? buildText(redText, Alliance.RED)
: buildPoints(red, points, Alliance.RED));
row.add(buildName(name));
row.add(this.text ? buildText(blueText, Alliance.BLUE)
: buildPoints(blue, points, Alliance.BLUE));
if (!half) {
row.add(this.text ? buildText(blueText, Alliance.BLUE)
: buildPoints(blue, points, Alliance.BLUE));
}

return IntrinsicHeight(
child: Row(
Expand All @@ -77,7 +80,7 @@ class MatchBreakdownRow extends StatelessWidget {
} else if (title) {
text = '$missions ${local.get('breakdowns.points')}';
} else if (missions != 0) {
int total = missions * points;
int total = missions != null ? missions * points : 0;
text = '$missions (${total > 0 ? '+' : ''}$total)';
}

Expand Down
57 changes: 36 additions & 21 deletions lib/ui/widgets/match-list-item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MatchListItem extends StatelessWidget {
List<Widget> row = [];
List<Widget> redRow = [];
List<Widget> blueRow = [];
List<Widget> orangeRow = [];

if (participants.length == 4) {
redRow.add(bulidTeam(0, participants, context));
Expand All @@ -40,10 +41,16 @@ class MatchListItem extends StatelessWidget {
blueRow.add(bulidTeam(3, participants, context));
blueRow.add(bulidTeam(4, participants, context));
blueRow.add(bulidTeam(5, participants, context));
} else if (participants.length == 1) {
orangeRow.add(bulidTeam(0, participants, context));
}

redRow.add(bulidPoints(match.redScore.toString()));
blueRow.add(bulidPoints(match.blueScore.toString()));
if (participants.length == 1) {
orangeRow.add(bulidPoints(match.redScore.toString()));
} else {
redRow.add(bulidPoints(match.redScore.toString()));
blueRow.add(bulidPoints(match.blueScore.toString()));
}

if (!justTable) {
// Match name
Expand All @@ -67,26 +74,17 @@ class MatchListItem extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: TOAColors.Colors().lighterRed,
border: points && match.redScore > match.blueScore ? Border.all(color: TOAColors.Colors().red, width: 2) : null
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: redRow
)
buildRow(
children: redRow,
color: TOAColors.Colors().lighterRed,
border: points && match.redScore > match.blueScore ? Border.all(color: TOAColors.Colors().red, width: 2) : null
),
Container(
decoration: BoxDecoration(
color: TOAColors.Colors().lighterBlue,
border: points && match.blueScore > match.redScore ? Border.all(color: TOAColors.Colors().blue, width: 2) : null
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: blueRow
)
)
buildRow(
children: blueRow,
color: TOAColors.Colors().lighterBlue,
border: points && match.blueScore > match.redScore ? Border.all(color: TOAColors.Colors().blue, width: 2) : null
),
buildRow(children: orangeRow, color: (Theme.of(context).brightness == Brightness.light) ? TOAColors.Colors().toaColors.shade100 : Colors.black.withOpacity(0.12))
]
)
));
Expand Down Expand Up @@ -157,4 +155,21 @@ class MatchListItem extends StatelessWidget {
)
);
}

Widget buildRow({@required List<Widget> children, @required Color color, BoxBorder border,}) {
if (children.isNotEmpty) {
return Container(
decoration: BoxDecoration(
color: color,
border: border
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: children
)
);
} else {
return Container();
}
}
}
Loading

0 comments on commit 81e14d8

Please sign in to comment.