Skip to content

Commit

Permalink
Merge pull request #333 from bill0042/changes
Browse files Browse the repository at this point in the history
Fixes overflows, etc. on activity ranks
  • Loading branch information
joaopmarquesini authored Jan 13, 2024
2 parents 364ebc2 + 14423e7 commit 806d4ad
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions lib/modules/progress/widgets/core_activity_rank.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class CoreActivityRankItemWidget extends StatelessWidget {
final color = definition?.color?.toMaterialColor() ?? context.theme.primaryLayers;
final bgColor = color.mix(context.theme.surfaceLayers, 60);
final rankProgress = progression.currentProgress ?? 0;
final rankTotal = definition?.steps?.fold<int>(0, (v, s) => v + (s.progressTotal ?? 0)) ?? 0;
final rankProportional = rankProgress / rankTotal;
final levelCap = progression.levelCap ?? -1;
final stepsTotal = definition?.steps?.fold<int>(0, (v, s) => v + (s.progressTotal ?? 0)) ?? 0;
final rankTotal = levelCap > 0 ? stepsTotal : 0;
final rankProportional = rankTotal > 0 ? rankProgress / rankTotal : 0.0;
final stepProgress = progression.progressToNextLevel ?? 0;
final stepTotal = progression.nextLevelAt ?? 1;
final stepProportional = stepProgress / stepTotal;
Expand Down Expand Up @@ -52,7 +54,6 @@ class CoreActivityRankItemWidget extends StatelessWidget {
Widget buildIcon(BuildContext context, {double rankProgress = 0, double stepProgress = 0}) {
final definition = context.definition<DestinyProgressionDefinition>(progression.progressionHash);
final color = definition?.color?.toMaterialColor(1) ?? context.theme.primaryLayers;
final rankColor = color.mix(context.theme.onSurfaceLayers, 50);
final step = definition?.steps?.elementAtOrNull(progression.stepIndex ?? 0);
return AspectRatio(
aspectRatio: 1,
Expand All @@ -70,7 +71,7 @@ class CoreActivityRankItemWidget extends StatelessWidget {
child: buildProgress(
context,
rankProgress,
color: rankColor,
color: color.mix(context.theme.onSurfaceLayers, 50),
backgroundColor: context.theme.surfaceLayers.layer3,
),
),
Expand All @@ -81,7 +82,7 @@ class CoreActivityRankItemWidget extends StatelessWidget {
child: buildProgress(
context,
stepProgress,
color: color,
color: color.mix(context.theme.onSurfaceLayers, 25),
backgroundColor: context.theme.surfaceLayers.layer2,
),
),
Expand Down Expand Up @@ -136,29 +137,32 @@ class CoreActivityRankItemWidget extends StatelessWidget {
int stepTotal = 1,
}) {
final definition = context.definition<DestinyProgressionDefinition>(progression.progressionHash);
final color = definition?.color?.toMaterialColor(1) ?? context.theme.surfaceLayers.layer3;
final currentStep = progression.stepIndex ?? 0;
final color = definition?.color?.toMaterialColor(1) ?? context.theme.primaryLayers;
final totalSteps = definition?.steps?.length ?? 0;
final step = definition?.steps?.elementAtOrNull(progression.stepIndex ?? 0);
final currentLevel = progression.level ?? 0;
final levelCap = progression.levelCap ?? 0;
return Container(
padding: EdgeInsets.all(4),
padding: EdgeInsets.all(2),
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Container(
decoration: BoxDecoration(
color: context.theme.surfaceLayers.layer1,
borderRadius: BorderRadius.circular(4),
),
margin: EdgeInsets.only(bottom: 2),
padding: EdgeInsets.all(4),
child: Text(
"{rankName} - {currentRank}/{totalRanks}".translate(context, replace: {
"rankName": step?.stepName ?? "",
"currentRank": "${currentStep + 1}",
"totalRanks": "$totalSteps",
}).toUpperCase(),
style: context.textTheme.itemNameHighDensity,
),
),
decoration: BoxDecoration(
color: context.theme.surfaceLayers.layer1,
borderRadius: BorderRadius.circular(4),
),
margin: EdgeInsets.only(bottom: 2),
padding: EdgeInsets.all(4),
child: Row(children: [
Expanded(
child: Text(
(step?.stepName ?? "").toUpperCase(),
style: context.textTheme.itemNameHighDensity,
overflow: TextOverflow.fade,
softWrap: false,
)),
Text(" ${currentLevel + 1}" + (levelCap > 0 ? "/$totalSteps" : ""),
style: context.textTheme.itemNameHighDensity)
])),
Container(
padding: EdgeInsets.symmetric(horizontal: 4),
child: Text(
Expand All @@ -183,16 +187,27 @@ class CoreActivityRankItemWidget extends StatelessWidget {
),
progress: stepProgress,
total: stepTotal,
color: color,
color: color.mix(context.theme.onSurfaceLayers, 25),
),
Container(
padding: EdgeInsets.all(2),
margin: EdgeInsets.only(top: 4),
decoration: BoxDecoration(
color: context.theme.surfaceLayers.withOpacity(.7),
borderRadius: BorderRadius.circular(4),
),
child: Row(children: [
Expanded(child: Text("Reset count".translate(context), style: context.textTheme.caption)),
Text("${progression.currentResetCount ?? 0}", style: context.textTheme.caption)
])),
]),
);
}

Widget buildProgressBar(BuildContext context, {int progress = 0, int total = 1, String label = "", Color? color}) {
color ??= context.theme.primaryLayers;
return Container(
padding: EdgeInsets.all(4),
padding: EdgeInsets.all(2),
margin: EdgeInsets.only(top: 4),
decoration: BoxDecoration(
color: context.theme.surfaceLayers.withOpacity(.7),
Expand All @@ -201,15 +216,15 @@ class CoreActivityRankItemWidget extends StatelessWidget {
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Row(children: [
Expanded(child: Text(label, style: context.textTheme.caption)),
Text("$progress/$total", style: context.textTheme.caption)
Text(total > 0 ? "$progress/$total" : "$progress", style: context.textTheme.caption)
]),
Container(
margin: EdgeInsets.only(top: 2),
height: 8,
color: context.theme.surfaceLayers.layer3,
height: 6,
color: context.theme.surfaceLayers.layer2,
alignment: Alignment.centerLeft,
child: FractionallySizedBox(
widthFactor: progress / total,
widthFactor: (progress < total ? progress / total : 0),
child: Container(color: color),
),
),
Expand Down

0 comments on commit 806d4ad

Please sign in to comment.