Skip to content

Commit

Permalink
Fleshed out the store page so the user can buy profile pictures and t…
Browse files Browse the repository at this point in the history
…hemes.
  • Loading branch information
nrakocevic committed Dec 2, 2024
1 parent b47be22 commit da71c79
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 84 deletions.
8 changes: 8 additions & 0 deletions fightme_webapp/lib/Cosmetics/profile_pictures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@

List<String> profilePictures = [
"assets/images/dummyKnight.png",
"assets/images/knight-green.png",
"assets/images/fknight-green.png",
];

// Structure: [element in profilePictures, price]
List<List<int>> buyableProfilePictures = [
[1, 4000],
[2, 8000],
];
6 changes: 6 additions & 0 deletions fightme_webapp/lib/Cosmetics/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ List<ColorScheme> themes = [
const ColorScheme(brightness: Brightness.light, primary: Colors.tealAccent, onPrimary: Colors.black, secondary: Colors.pinkAccent, onSecondary: Colors.black, surface: Colors.deepPurple, onSurface: Colors.black, error: Colors.red, onError: Colors.black),
];

// TODO: Match the element in themes.
List<String> themeNames = [
"Default",
"Dark",
"Vaporwave",
];

// Structure: [element in themes, price]
List<List<int>> buyableThemes = [
[2, 6000],
];
302 changes: 218 additions & 84 deletions fightme_webapp/lib/gamerscore_shop.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:fightme_webapp/Models/user.dart';
import 'package:fightme_webapp/main.dart';
import 'package:flutter/material.dart';
import 'Cosmetics/profile_pictures.dart';
import 'Cosmetics/themes.dart';
import 'globals.dart' as globals;
import 'Models/httpservice.dart';

Expand All @@ -14,22 +16,16 @@ class GamerscoreShop extends StatefulWidget {

class _GamerscoreShopState extends State<GamerscoreShop> {
final HttpService _httpService = HttpService();
Map<String, int> currentStats = {
'attackScore': curUser.attackScore,
'magicScore': curUser.magicScore,
'defenseScore': curUser.defenseScore,
};
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme
.of(context)
.colorScheme
.primary,
centerTitle: true,
title: const Text("Shop"),
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(Icons.arrow_back),
),
),
body: Center(
child: Column(
Expand All @@ -42,85 +38,223 @@ class _GamerscoreShopState extends State<GamerscoreShop> {
const Icon(Icons.monetization_on, color: Colors.yellow, size: 30,),
],
),
const SizedBox(
height: 200,
const Align(
alignment: Alignment.centerLeft,
child: Text("Profile Pictures", style: TextStyle(
fontSize: 40)),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: [
Image.asset("assets/images/attack.png", height: 80, width: 80, color: Colors.red),
const SizedBox(height: 10,),
SizedBox(
width: MediaQuery.of(context).size.width / 3 - 60.0,
child: ElevatedButton(
onPressed: () async {
if(curUser.gamerScore < 1) {
return;
}
await _httpService.updateUserGamerScore(globals.uid, curUser.gamerScore - 1);
currentStats['attackScore'] = curUser.attackScore + 1;
await _httpService.updateUserStats(globals.uid,currentStats);
setState(() {
curUser.attackScore = curUser.attackScore + 1;
curUser.gamerScore = curUser.gamerScore - 1;
});
},
child: const Text("Buy Attack"),
),
),
],
SizedBox(
height: MediaQuery.of(context).size.height / 3,
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1.25,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
),
Column(
children: [
Image.asset("assets/images/defense.png", height: 80, width: 80, color: Colors.green,),
const SizedBox(height: 10,),
SizedBox(
width: MediaQuery.of(context).size.width / 3 - 60.0,
child: ElevatedButton(
onPressed: () async {
if(curUser.gamerScore < 1) {
return;
}
await _httpService.updateUserGamerScore(globals.uid, curUser.gamerScore - 1);
currentStats['defenseScore'] = curUser.defenseScore + 1;
await _httpService.updateUserStats(globals.uid,currentStats);
setState(() {
curUser.defenseScore = curUser.defenseScore + 1;
curUser.gamerScore = curUser.gamerScore - 1;
});
},
child: const Text("Buy Defense"),
shrinkWrap: true,
itemCount: buyableProfilePictures.length,
itemBuilder: (BuildContext context, int index) {
bool bought = widget.curUser.unlockedpfps.firstWhere((element) => element == buyableProfilePictures[index][0], orElse: () => -1) != -1;
return TextButton(
onPressed: () {
if (!bought) {
if (buyableProfilePictures[index][1] > widget.curUser.gamerScore) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
duration: Duration(seconds: 3),
content: Text('You do not have enough gamer score for that.'),
)
);
}
else {
showDialog<String>(
context: context,
builder: (BuildContext context) =>
AlertDialog(
title: const Text(
'Are you sure you want to buy?'),
content: Image.asset(
profilePictures[buyableProfilePictures[index][0]],
width: 150, height: 150),
actionsAlignment: MainAxisAlignment.center,
actions: <Widget>[
TextButton(
onPressed: () =>
Navigator.pop(context, 'No'),
child: const Text('No'),
),
TextButton(
onPressed: () async {
await _httpService.updateUserGamerScore(globals.uid, widget.curUser.gamerScore - buyableProfilePictures[index][1]);
await _httpService.addUserProfilePicture(globals.uid, buyableProfilePictures[index][0]);
setState(() {
widget.curUser.unlockedpfps.add(buyableProfilePictures[index][0]);
widget.curUser.gamerScore = widget.curUser.gamerScore - buyableProfilePictures[index][1];
});
Navigator.pop(context, 'Yes');
},
child: const Text('Yes'),
),
],
),
);
}
}
},
child: GridTile(
child: Column(
children: [
Image.asset(profilePictures[buyableProfilePictures[index][0]], width: 200, height: 200),
bought ? const Text("Bought", style: TextStyle(
fontSize: 30)) :
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("${buyableProfilePictures[index][1]}", style: const TextStyle(
fontSize: 30)),
const Icon(Icons.monetization_on, color: Colors.yellow, size: 30,),
]
),
]
),
),
],
),
Column(
children: [
Image.asset("assets/images/magic.png", width: 80, height: 80, color: Colors.purple,),
const SizedBox(height: 10,),
SizedBox(
width: MediaQuery.of(context).size.width / 3 - 60.0,
child: ElevatedButton(
onPressed: () async {
if(curUser.gamerScore < 1) {
return;
);
}
),
),
const Align(
alignment: Alignment.centerLeft,
child: Text("Themes", style: TextStyle(
fontSize: 40)),
),
SizedBox(
height: MediaQuery.of(context).size.height / 3.0,
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1.25,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
),
shrinkWrap: true,
itemCount: buyableThemes.length,
itemBuilder: (BuildContext context, int index) {
bool bought = widget.curUser.unlockedThemes.firstWhere((element) => element == buyableThemes[index][0], orElse: () => -1) != -1;
return TextButton(
onPressed: () {
if (!bought) {
if (buyableThemes[index][1] > widget.curUser.gamerScore) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
duration: Duration(seconds: 3),
content: Text('You do not have enough gamer score for that.'),
)
);
}
else {
showDialog<String>(
context: context,
builder: (BuildContext context) =>
AlertDialog(
title: const Text(
'Are you sure you want to buy?'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 45.0,
decoration: BoxDecoration(
color: themes[buyableThemes[index][0]].primary,
)
),
Container(
height: 90.0,
decoration: BoxDecoration(
color: themes[buyableThemes[index][0]].surface,
),
child: Align(
child: Text(themeNames[buyableThemes[index][0]], style: TextStyle(
color: themes[buyableThemes[index][0]].onSurface)),
)
),
Container(
height: 45.0,
decoration: BoxDecoration(
color: themes[buyableThemes[index][0]].secondary,
)
),
]
),
actionsAlignment: MainAxisAlignment.center,
actions: <Widget>[
TextButton(
onPressed: () =>
Navigator.pop(context, 'No'),
child: const Text('No'),
),
TextButton(
onPressed: () async {
await _httpService.updateUserGamerScore(globals.uid, widget.curUser.gamerScore - buyableThemes[index][1]);
await _httpService.addUserTheme(globals.uid, buyableThemes[index][0]);
setState(() {
widget.curUser.unlockedThemes.add(buyableThemes[index][0]);
widget.curUser.gamerScore = widget.curUser.gamerScore - buyableThemes[index][1];
});
Navigator.pop(context, 'Yes');
},
child: const Text('Yes'),
),
],
),
);
}
await _httpService.updateUserGamerScore(globals.uid, curUser.gamerScore - 1);
currentStats['magicScore'] = curUser.magicScore + 1;
await _httpService.updateUserStats(globals.uid,currentStats);
setState(() {
curUser.magicScore = curUser.magicScore + 1;
curUser.gamerScore = curUser.gamerScore - 1;
});
},
child: const Text("Buy Magic"),
}
},
child: GridTile(
child: Column(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
color: themes[buyableThemes[index][0]].primary,
)
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: themes[buyableThemes[index][0]].surface,
),
child: Align(
child: Text(themeNames[buyableThemes[index][0]], style: TextStyle(
color: themes[buyableThemes[index][0]].onSurface)),
)
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: themes[buyableThemes[index][0]].secondary,
)
),
),
bought ? const Text("Bought", style: TextStyle(
fontSize: 30)) :
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("${buyableProfilePictures[index][1]}", style: const TextStyle(
fontSize: 30)),
const Icon(Icons.monetization_on, color: Colors.yellow, size: 30,),
]
),
]
)
),
),
],
),
],
);
}
),
),
],
),
Expand Down

0 comments on commit da71c79

Please sign in to comment.