From 0262c8dcf9dc868d86207236fce2ced1dcdc845c Mon Sep 17 00:00:00 2001 From: dan63047 Date: Sun, 16 Jun 2024 16:25:16 +0300 Subject: [PATCH] stat_sell_num fix + tl_rating_thingy update --- lib/views/main_view.dart | 4 --- lib/widgets/stat_sell_num.dart | 12 +++++---- lib/widgets/tl_rating_thingy.dart | 42 +++++++++++++++++++++++-------- lib/widgets/tl_thingy.dart | 15 +++++------ 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/lib/views/main_view.dart b/lib/views/main_view.dart index c9187c3..dcccc09 100644 --- a/lib/views/main_view.dart +++ b/lib/views/main_view.dart @@ -953,8 +953,6 @@ class _HistoryChartThigyState extends State<_HistoryChartThigy> { series: [ if (_gamesPlayedInsteadOfDateAndTime) StepLineSeries<_HistoryChartSpot, int>( enableTooltip: true, - // splineType: SplineType.cardinal, - // cardinalSplineTension: 0.2, dataSource: widget.data, animationDuration: 0, opacity: _smooth ? 0 : 1, @@ -971,8 +969,6 @@ class _HistoryChartThigyState extends State<_HistoryChartThigy> { ) else StepLineSeries<_HistoryChartSpot, DateTime>( enableTooltip: true, - // splineType: SplineType.cardinal, - // cardinalSplineTension: 0.2, dataSource: widget.data, animationDuration: 0, opacity: _smooth ? 0 : 1, diff --git a/lib/widgets/stat_sell_num.dart b/lib/widgets/stat_sell_num.dart index 4a5ca7c..be1d940 100644 --- a/lib/widgets/stat_sell_num.dart +++ b/lib/widgets/stat_sell_num.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:tetra_stats/data_objects/tetrio.dart'; @@ -43,16 +45,16 @@ class StatCellNum extends StatelessWidget { @override Widget build(BuildContext context) { + NumberFormat f = NumberFormat.decimalPatternDigits(locale: LocaleSettings.currentLocale.languageCode, decimalDigits: fractionDigits ?? 0); NumberFormat comparef = NumberFormat("+#,###.###;-#,###.###")..maximumFractionDigits = fractionDigits ?? 0; - NumberFormat fractionf = NumberFormat.decimalPatternDigits(locale: LocaleSettings.currentLocale.languageCode, decimalDigits: fractionDigits ?? 0)..maximumIntegerDigits = 0; - num fraction = playerStat.isNegative ? 1 - (playerStat - playerStat.floor()) : playerStat - playerStat.floor(); - int integer = playerStat.isNegative ? (playerStat + fraction).toInt() : (playerStat - fraction).toInt(); + String formated = f.format(playerStat); + List splited = formated.split(f.symbols.DECIMAL_SEP); return Column( children: [ RichText( - text: TextSpan(text: intf.format(integer), + text: TextSpan(text: splited[0], children: [ - TextSpan(text: fractionf.format(fraction).substring(1), style: smallDecimal ? const TextStyle(fontSize: 16) : null) + if ((fractionDigits??0) > 0) TextSpan(text: f.symbols.DECIMAL_SEP+splited[1], style: smallDecimal ? const TextStyle(fontFamily: "Eurostile Round", fontSize: 16) : null) ], style: TextStyle( fontFamily: "Eurostile Round Extended", diff --git a/lib/widgets/tl_rating_thingy.dart b/lib/widgets/tl_rating_thingy.dart index 640de3e..5ad8a9c 100644 --- a/lib/widgets/tl_rating_thingy.dart +++ b/lib/widgets/tl_rating_thingy.dart @@ -5,7 +5,7 @@ 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("+#,###.###;-#,###.###"); +var fDiff = NumberFormat("+#,###.####;-#,###.####"); class TLRatingThingy extends StatelessWidget{ final String userID; @@ -19,7 +19,10 @@ class TLRatingThingy extends StatelessWidget{ Widget build(BuildContext context) { bool oskKagariGimmick = prefs.getBool("oskKagariGimmick")??true; bool bigScreen = MediaQuery.of(context).size.width >= 768; - int test = 0; + String decimalSeparator = f4.symbols.DECIMAL_SEP; + List formatedTR = f4.format(tlData.rating).split(decimalSeparator); + List formatedGlicko = f4.format(tlData.glicko).split(decimalSeparator); + List formatedPercentile = f4.format(tlData.percentile * 100).split(decimalSeparator); return Wrap( direction: Axis.horizontal, alignment: WrapAlignment.spaceAround, @@ -31,17 +34,34 @@ class TLRatingThingy extends StatelessWidget{ : 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) + RichText( + text: TextSpan( + style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 20, color: Colors.white), + children: switch(prefs.getInt("ratingMode")){ + 1 => [ + TextSpan(text: formatedGlicko[0], style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: bigScreen ? 42 : 28)), + if (formatedGlicko.elementAtOrNull(1) != null) TextSpan(text: decimalSeparator + formatedGlicko[1]), + TextSpan(text: " Glicko", style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: bigScreen ? 42 : 28)) + ], + 2 => [ + TextSpan(text: "Top ${formatedPercentile[0]}", style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: bigScreen ? 42 : 28)), + if (formatedPercentile.elementAtOrNull(1) != null) TextSpan(text: decimalSeparator + formatedPercentile[1]), + TextSpan(text: " %", style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: bigScreen ? 42 : 28)) + ], + _ => [ + TextSpan(text: formatedTR[0], style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: bigScreen ? 42 : 28)), + if (formatedTR.elementAtOrNull(1) != null) TextSpan(text: decimalSeparator + formatedTR[1]), + TextSpan(text: " 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", + switch(prefs.getInt("ratingMode")){ + 1 => "${fDiff.format(tlData.glicko! - oldTl!.glicko!)} Glicko", + 2 => "${fDiff.format(tlData.percentile * 100 - oldTl!.percentile * 100)} %", + _ => "${fDiff.format(tlData.rating - oldTl!.rating)} TR" + }, textAlign: TextAlign.center, style: TextStyle( color: tlData.rating - oldTl!.rating < 0 ? diff --git a/lib/widgets/tl_thingy.dart b/lib/widgets/tl_thingy.dart index 08a9ab5..dee7a3d 100644 --- a/lib/widgets/tl_thingy.dart +++ b/lib/widgets/tl_thingy.dart @@ -13,7 +13,7 @@ import 'package:tetra_stats/widgets/tl_progress_bar.dart'; import 'package:tetra_stats/widgets/tl_rating_thingy.dart'; -var intFDiff = NumberFormat("+#,###;-#,###"); +var intFDiff = NumberFormat("+#,###.000;-#,###.000"); class TLThingy extends StatefulWidget { final TetraLeagueAlpha tl; @@ -56,8 +56,9 @@ class _TLThingyState extends State { @override Widget build(BuildContext context) { final t = Translations.of(context); - NumberFormat fractionfEstTR = NumberFormat.decimalPatternDigits(locale: LocaleSettings.currentLocale.languageCode, decimalDigits: 2)..maximumIntegerDigits = 0; - NumberFormat fractionfEstTRAcc = NumberFormat.decimalPatternDigits(locale: LocaleSettings.currentLocale.languageCode, decimalDigits: 3)..maximumIntegerDigits = 0; + String decimalSeparator = f2.symbols.DECIMAL_SEP; + List estTRformated = f2.format(currentTl.estTr!.esttr).split(decimalSeparator); + List estTRaccFormated = intFDiff.format(currentTl.esttracc!).split(decimalSeparator); if (currentTl.gamesPlayed == 0) return Center(child: Text(widget.guest ? t.anonTL : widget.bot ? t.botTL : t.neverPlayedTL, style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 28), textAlign: TextAlign.center,)); return LayoutBuilder(builder: (context, constraints) { bool bigScreen = constraints.maxWidth >= 768; @@ -260,9 +261,9 @@ class _TLThingyState extends State { Text(t.statCellNum.estOfTR, style: const TextStyle(height: 0.1),), RichText( text: TextSpan( - text: intf.format(currentTl.estTr!.esttr.truncate()), + text: estTRformated[0], style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: bigScreen ? 36 : 30, fontWeight: FontWeight.w500, color: Colors.white), - children: [TextSpan(text: fractionfEstTR.format(currentTl.estTr!.esttr - currentTl.estTr!.esttr.truncate()).substring(1), style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w100))] + children: [TextSpan(text: decimalSeparator+estTRformated[1], style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w100))] ), ), RichText(text: TextSpan( @@ -289,10 +290,10 @@ class _TLThingyState extends State { Text(t.statCellNum.accOfEst, style: const TextStyle(height: 0.1),), RichText( text: TextSpan( - text: (currentTl.esttracc != null && currentTl.bestRank != "z") ? intFDiff.format(currentTl.esttracc!.truncate()) : "---", + text: (currentTl.esttracc != null && currentTl.bestRank != "z") ? estTRaccFormated[0] : "---", style: TextStyle(fontFamily: "Eurostile Round", fontSize: bigScreen ? 36 : 30, fontWeight: FontWeight.w500, color: Colors.white), children: [ - TextSpan(text: (currentTl.esttracc != null && currentTl.bestRank != "z") ? fractionfEstTRAcc.format(currentTl.esttracc!.isNegative ? 1 - (currentTl.esttracc! - currentTl.esttracc!.truncate()) : (currentTl.esttracc! - currentTl.esttracc!.truncate())).substring(1) : ".---", style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w100)) + TextSpan(text: (currentTl.esttracc != null && currentTl.bestRank != "z") ? decimalSeparator+estTRaccFormated[1] : ".---", style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w100)) ] ), ),