Skip to content

Commit

Permalink
feat: Add leaderboard page scaffold (#77)
Browse files Browse the repository at this point in the history
Add leaderboard page scaffold
  • Loading branch information
luanpotter authored Jul 2, 2023
1 parent cc8d06b commit 1e36549
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 10 deletions.
Binary file added google_fonts/MajorMonoDisplay-Regular.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions lib/leaderboard/leaderboard.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'view/view.dart';
126 changes: 126 additions & 0 deletions lib/leaderboard/view/leaderboard_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:gamepads/gamepads.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:lightrunners/title/title.dart';
import 'package:lightrunners/utils/gamepad_navigator.dart';
import 'package:lightrunners/widgets/widgets.dart';

const _maxScoreDigits = 3;
const _maxCharactersScoreBoard = 32;
const _lightrunnersInfoBlob = '''
Light Runners was made with 💙 by Blue Fire and Invertase for Fluttercon 2023
''';
final _leaderboard = [
(name: 'Erick', score: 100),
(name: 'Luan', score: 90),
(name: 'Renan', score: 80),
(name: 'Spydon', score: 70),
(name: 'Wolfenrain', score: 60),
];

class LeaderboardPage extends StatefulWidget {
const LeaderboardPage({
super.key,
});

static Route<void> route() {
return MaterialPageRoute<void>(
maintainState: false,
builder: (_) => const LeaderboardPage(),
);
}

@override
State<LeaderboardPage> createState() => _LeaderboardPageState();
}

class _LeaderboardPageState extends State<LeaderboardPage> {
late StreamSubscription<GamepadEvent> _gamepadSubscription;
late GamepadNavigator _gamepadNavigator;

@override
void initState() {
super.initState();
_gamepadNavigator = GamepadNavigator(
onAny: () => Navigator.of(context).pushReplacement(TitlePage.route()),
);
_gamepadSubscription = Gamepads.events.listen(_gamepadNavigator.handle);
}

@override
void dispose() {
_gamepadSubscription.cancel();

super.dispose();
}

@override
Widget build(BuildContext context) {
final bungee = GoogleFonts.bungee().fontFamily;
final major = GoogleFonts.majorMonoDisplay().fontFamily;

return ScreenScaffold(
child: Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(64.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(child: TitleLogo(state: LogoController())),
Text(
_lightrunnersInfoBlob,
style: TextStyle(
fontFamily: bungee,
fontSize: 48,
color: Colors.white,
),
),
],
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(64.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (final entry in _leaderboard)
Text(
_toScoreboardLine(entry),
style: TextStyle(
fontFamily: major,
fontSize: 28,
color: Colors.white,
),
)
],
),
),
),
],
),
);
}

String _toScoreboardLine(({String name, int score}) entry) {
final name = entry.name.substring(
0,
min(entry.name.length, _maxCharactersScoreBoard - _maxScoreDigits - 1),
);
final maxScore = pow(10, _maxScoreDigits) - 1;
final score =
entry.score.clamp(0, maxScore).toString().padLeft(_maxScoreDigits, '0');
final dotDotDot =
'.' * (_maxCharactersScoreBoard - name.length - score.length);

return '$name$dotDotDot$score'.toLowerCase();
}
}
1 change: 1 addition & 0 deletions lib/leaderboard/view/view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'leaderboard_page.dart';
12 changes: 2 additions & 10 deletions lib/title/view/title_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:flutter/material.dart';
import 'package:lightrunners/end_game/view/end_game_page.dart';
import 'package:lightrunners/leaderboard/view/view.dart';
import 'package:lightrunners/lobby/view/lobby_page.dart';
import 'package:lightrunners/title/title.dart';
import 'package:lightrunners/ui/ui.dart';
import 'package:lightrunners/widgets/controller_menu.dart';
import 'package:lightrunners/widgets/screen_scaffold.dart';

Expand Down Expand Up @@ -40,14 +39,7 @@ class TitlePage extends StatelessWidget {
name: 'LeaderBoard',
onPressed: () {
Navigator.of(context).pushReplacement(
EndGamePage.route(
{
GamePalette.blue: 100,
GamePalette.green: 90,
GamePalette.lightBlue: 50,
GamePalette.pink: 20,
},
),
LeaderboardPage.route(),
);
},
),
Expand Down

0 comments on commit 1e36549

Please sign in to comment.