From cedb304c1a51935352e156988dccce7f969ecae8 Mon Sep 17 00:00:00 2001 From: dan63047 Date: Tue, 11 Jun 2024 01:35:07 +0300 Subject: [PATCH] Customization -> Main representation of rating --- lib/views/customization_view.dart | 30 ++++++++++++ lib/widgets/tl_rating_thingy.dart | 77 +++++++++++++++++++++++++++++++ lib/widgets/tl_thingy.dart | 53 ++------------------- 3 files changed, 111 insertions(+), 49 deletions(-) create mode 100644 lib/widgets/tl_rating_thingy.dart diff --git a/lib/views/customization_view.dart b/lib/views/customization_view.dart index 3449d8a..533b128 100644 --- a/lib/views/customization_view.dart +++ b/lib/views/customization_view.dart @@ -21,6 +21,7 @@ class CustomizationState extends State { late SharedPreferences prefs; late bool oskKagariGimmick; late bool sheetbotRadarGraphs; + late int ratingMode; void changeColor(Color color) { setState(() => pickerColor = color); @@ -54,6 +55,11 @@ class CustomizationState extends State { } else { sheetbotRadarGraphs = false; } + if (prefs.getInt("ratingMode") != null) { + ratingMode = prefs.getInt("ratingMode")!; + } else { + ratingMode = 0; + } } ThemeData getTheme(BuildContext context, Color color){ @@ -119,6 +125,30 @@ class CustomizationState extends State { oskKagariGimmick = value; }); }),), + ListTile(title: Text("Main representation of rating"), + subtitle: Text(t.oskKagariDescription, style: subtitleStyle), + trailing: DropdownButton( + value: ratingMode, + items: [ + DropdownMenuItem(value: 0, child: Text("TR")), + DropdownMenuItem(value: 1, child: Text("Glicko")), + DropdownMenuItem(value: 2, child: Text("LB position")) + ], + onChanged: (dynamic value){ + prefs.setInt("ratingMode", value); + setState(() { + ratingMode = value; + }); + }, + ), + // trailing: Switch(value: sheetbotRadarGraphs, onChanged: (bool value){ + // prefs.setBool("sheetbotRadarGraphs", value); + // setState(() { + // sheetbotRadarGraphs = value; + // }); + // } + // ), + ), ListTile(title: Text("Sheetbot-like behavior for radar graphs"), subtitle: Text(t.oskKagariDescription, style: subtitleStyle), trailing: Switch(value: sheetbotRadarGraphs, onChanged: (bool value){ diff --git a/lib/widgets/tl_rating_thingy.dart b/lib/widgets/tl_rating_thingy.dart new file mode 100644 index 0000000..640de3e --- /dev/null +++ b/lib/widgets/tl_rating_thingy.dart @@ -0,0 +1,77 @@ +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:tetra_stats/data_objects/tetrio.dart'; +import 'package:tetra_stats/gen/strings.g.dart'; +import 'package:tetra_stats/main.dart' show prefs; +import 'package:tetra_stats/utils/numers_formats.dart'; + +var fDiff = NumberFormat("+#,###.###;-#,###.###"); + +class TLRatingThingy extends StatelessWidget{ + final String userID; + final TetraLeagueAlpha tlData; + final TetraLeagueAlpha? oldTl; + final double? topTR; + + const TLRatingThingy({required this.userID, required this.tlData, this.oldTl, this.topTR}); + + @override + Widget build(BuildContext context) { + bool oskKagariGimmick = prefs.getBool("oskKagariGimmick")??true; + bool bigScreen = MediaQuery.of(context).size.width >= 768; + int test = 0; + return Wrap( + direction: Axis.horizontal, + alignment: WrapAlignment.spaceAround, + crossAxisAlignment: WrapCrossAlignment.center, + clipBehavior: Clip.hardEdge, + children: [ + (userID == "5e32fc85ab319c2ab1beb07c" && oskKagariGimmick) // he love her so much, you can't even imagine + ? Image.asset("res/icons/kagari.png", height: 128) // Btw why she wearing Kazamatsuri high school uniform? + : Image.asset("res/tetrio_tl_alpha_ranks/${tlData.rank}.png", height: 128), + Column( + children: [ + Text( + switch(prefs.getInt("ratingMode")){ + 1 => "${f2.format(tlData.glicko)} Glicko", + 2 => "Top ${tlData.percentile < 0.1 ? f3.format(tlData.percentile * 100) : f2.format(tlData.percentile * 100)}%", + _ => "${(tlData.rating >= 24999 || tlData.rating < 100) ? f4.format(tlData.rating) : f2.format(tlData.rating)} TR", + }, + style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: bigScreen ? 42 : 28) + ), + // Text("${f4.format(25000.0 - tlData.rating)} TR", style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: bigScreen ? 42 : 28)), + if (oldTl != null) Text( + "${fDiff.format(tlData.rating - oldTl!.rating)} TR", + textAlign: TextAlign.center, + style: TextStyle( + color: tlData.rating - oldTl!.rating < 0 ? + Colors.red : + Colors.green + ), + ), + Column( + children: [ + RichText( + textAlign: TextAlign.center, + softWrap: true, + text: TextSpan( + style: DefaultTextStyle.of(context).style, + children: [ + TextSpan(text: prefs.getInt("ratingMode") == 2 ? "${f2.format(tlData.rating)} TR • % rank: ${tlData.percentileRank.toUpperCase()}" : "${t.top} ${f2.format(tlData.percentile * 100)}% (${tlData.percentileRank.toUpperCase()})"), + if (tlData.bestRank != "z") const TextSpan(text: " • "), + if (tlData.bestRank != "z") TextSpan(text: "${t.topRank}: ${tlData.bestRank.toUpperCase()}"), + if (topTR != null) TextSpan(text: " (${f2.format(topTR)} TR)"), + TextSpan(text: " • ${prefs.getInt("ratingMode") == 1 ? "${f2.format(tlData.rating)} TR • RD: " : "Glicko: ${f2.format(tlData.glicko!)}±"}"), + TextSpan(text: f2.format(tlData.rd!), style: tlData.decaying ? TextStyle(color: tlData.rd! > 98 ? Colors.red : Colors.yellow) : null), + if (tlData.decaying) WidgetSpan(child: Icon(Icons.trending_up, color: tlData.rd! > 98 ? Colors.red : Colors.yellow,), alignment: PlaceholderAlignment.middle, baseline: TextBaseline.alphabetic) + ], + ), + ), + ], + ), + ], + ), + ], + ); + } +} \ No newline at end of file diff --git a/lib/widgets/tl_thingy.dart b/lib/widgets/tl_thingy.dart index bec9f10..9571cf6 100644 --- a/lib/widgets/tl_thingy.dart +++ b/lib/widgets/tl_thingy.dart @@ -3,15 +3,16 @@ import 'package:intl/intl.dart'; import 'package:tetra_stats/data_objects/tetrio.dart'; import 'package:syncfusion_flutter_gauges/gauges.dart'; import 'package:tetra_stats/gen/strings.g.dart'; -import 'package:tetra_stats/main.dart' show prefs; + import 'package:tetra_stats/utils/colors_functions.dart'; import 'package:tetra_stats/utils/numers_formats.dart'; import 'package:tetra_stats/widgets/gauget_num.dart'; import 'package:tetra_stats/widgets/graphs.dart'; import 'package:tetra_stats/widgets/stat_sell_num.dart'; import 'package:tetra_stats/widgets/tl_progress_bar.dart'; +import 'package:tetra_stats/widgets/tl_rating_thingy.dart'; + -var fDiff = NumberFormat("+#,###.###;-#,###.###"); var intFDiff = NumberFormat("+#,###;-#,###"); final DateFormat dateFormat = DateFormat.yMMMd(LocaleSettings.currentLocale.languageCode).add_Hms(); @@ -48,7 +49,6 @@ class _TLThingyState extends State { void initState() { _currentRangeValues = const RangeValues(0, 1); sortedStates = widget.states.reversed.toList(); - oskKagariGimmick = prefs.getBool("oskKagariGimmick")??true; oldTl = sortedStates.elementAtOrNull(1)?.tlSeason1; currentTl = widget.tl; super.initState(); @@ -92,52 +92,7 @@ class _TLThingyState extends State { }); }, ), - if (currentTl.gamesPlayed >= 10) - Wrap( - direction: Axis.horizontal, - alignment: WrapAlignment.spaceAround, - crossAxisAlignment: WrapCrossAlignment.center, - clipBehavior: Clip.hardEdge, - children: [ - (widget.userID == "5e32fc85ab319c2ab1beb07c" && oskKagariGimmick) // he love her so much, you can't even imagine - ? Image.asset("res/icons/kagari.png", height: 128) // Btw why she wearing Kazamatsuri high school uniform? - : Image.asset("res/tetrio_tl_alpha_ranks/${currentTl.rank}.png", height: 128), - Column( - children: [ - Text("${f2.format(currentTl.rating)} TR", style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: bigScreen ? 42 : 28)), - if (oldTl != null) Text( - "${fDiff.format(currentTl.rating - oldTl!.rating)} TR", - textAlign: TextAlign.center, - style: TextStyle( - color: currentTl.rating - oldTl!.rating < 0 ? - Colors.red : - Colors.green - ), - ), - Column( - children: [ - RichText( - textAlign: TextAlign.center, - softWrap: true, - text: TextSpan( - style: DefaultTextStyle.of(context).style, - children: [ - TextSpan(text: "${t.top} ${f2.format(currentTl.percentile * 100)}% (${currentTl.percentileRank.toUpperCase()})"), - if (currentTl.bestRank != "z") const TextSpan(text: " • "), - if (currentTl.bestRank != "z") TextSpan(text: "${t.topRank}: ${currentTl.bestRank.toUpperCase()}"), - if (widget.topTR != null) TextSpan(text: " (${f2.format(widget.topTR)} TR)"), - TextSpan(text: " • Glicko: ${f2.format(currentTl.glicko!)}±"), - TextSpan(text: f2.format(currentTl.rd!), style: currentTl.decaying ? TextStyle(color: currentTl.rd! > 98 ? Colors.red : Colors.yellow) : null), - if (currentTl.decaying) WidgetSpan(child: Icon(Icons.trending_up, color: currentTl.rd! > 98 ? Colors.red : Colors.yellow,), alignment: PlaceholderAlignment.middle, baseline: TextBaseline.alphabetic) - ], - ), - ), - ], - ), - ], - ), - ], - ), + if (currentTl.gamesPlayed >= 10) TLRatingThingy(userID: widget.userID, tlData: currentTl, oldTl: oldTl, topTR: widget.topTR), if (currentTl.gamesPlayed > 9) TLProgress( tlData: currentTl, previousRankTRcutoff: widget.thatRankCutoff,