245 lines
8.9 KiB
Dart
245 lines
8.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:random_avatar/random_avatar.dart';
|
|
|
|
import '../../core/theme/app_theme.dart';
|
|
import '../../core/widgets/game_ui.dart';
|
|
import '../auth/auth_cubit.dart';
|
|
import 'wallet_cubit.dart';
|
|
|
|
/// لابی اصلی: کیفپول، دکمه بازی، فروشگاه، سکه روزانه (ظاهرِ بازیگونه).
|
|
class LobbyScreen extends StatefulWidget {
|
|
const LobbyScreen({super.key});
|
|
|
|
@override
|
|
State<LobbyScreen> createState() => _LobbyScreenState();
|
|
}
|
|
|
|
class _LobbyScreenState extends State<LobbyScreen> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
context.read<WalletCubit>().load();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: GameBackground(
|
|
child: BlocBuilder<WalletCubit, WalletState>(
|
|
builder: (context, state) {
|
|
return Column(
|
|
children: [
|
|
_TopBar(walletState: state, onCoinTap: () => _openShop(context)),
|
|
Expanded(
|
|
child: Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 28),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const GlowText('سلطان حکم', size: 44),
|
|
const SizedBox(height: 44),
|
|
GameButton(
|
|
label: 'بازی',
|
|
icon: Icons.style,
|
|
width: double.infinity,
|
|
colors: const [Color(0xFFC2185B), Color(0xFF6A0D38)],
|
|
onTap: () async {
|
|
await context.push('/game/tiers');
|
|
if (context.mounted) {
|
|
context.read<WalletCubit>().load();
|
|
}
|
|
},
|
|
),
|
|
const SizedBox(height: 16),
|
|
GameButton(
|
|
label: 'دورهمی',
|
|
icon: Icons.group_add,
|
|
width: double.infinity,
|
|
colors: const [Color(0xFF1565C0), Color(0xFF0A2E57)],
|
|
onTap: () async {
|
|
await context.push('/private');
|
|
if (context.mounted) {
|
|
context.read<WalletCubit>().load();
|
|
}
|
|
},
|
|
),
|
|
const SizedBox(height: 16),
|
|
GameButton(
|
|
label: 'فروشگاه',
|
|
icon: Icons.storefront,
|
|
width: double.infinity,
|
|
colors: const [Color(0xFF7B1FA2), Color(0xFF3E0A57)],
|
|
onTap: () => _openShop(context),
|
|
),
|
|
const SizedBox(height: 16),
|
|
GameButton(
|
|
label: 'سکه روزانه',
|
|
icon: Icons.monetization_on,
|
|
width: double.infinity,
|
|
colors: const [Color(0xFF3FA34D), Color(0xFF1B5E20)],
|
|
onTap: () => _claimDaily(context),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
TextButton.icon(
|
|
onPressed: () async {
|
|
await context.read<AuthCubit>().logout();
|
|
if (context.mounted) context.go('/login');
|
|
},
|
|
icon: const Icon(Icons.logout, color: Colors.white54),
|
|
label: const Text('خروج',
|
|
style: TextStyle(color: Colors.white54)),
|
|
),
|
|
const SizedBox(height: 8),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _openShop(BuildContext context) async {
|
|
await context.push('/shop');
|
|
if (context.mounted) context.read<WalletCubit>().load();
|
|
}
|
|
|
|
Future<void> _claimDaily(BuildContext context) async {
|
|
final amount = await context.read<WalletCubit>().claimDaily();
|
|
if (!context.mounted) return;
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(amount != null
|
|
? 'سکه روزانه دریافت شد: +$amount'
|
|
: 'سکه روزانه را قبلاً امروز گرفتهاید'),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _TopBar extends StatelessWidget {
|
|
final WalletState walletState;
|
|
final VoidCallback onCoinTap;
|
|
const _TopBar({required this.walletState, required this.onCoinTap});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final w = walletState.wallet;
|
|
return Container(
|
|
margin: const EdgeInsets.all(8),
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [Color(0xFF3A0A12), Color(0xFF1A0106)],
|
|
),
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: AppColors.goldDark),
|
|
boxShadow: const [BoxShadow(color: Colors.black54, blurRadius: 8)],
|
|
),
|
|
child: Row(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () async {
|
|
await context.push('/profile');
|
|
if (context.mounted) context.read<WalletCubit>().load();
|
|
},
|
|
child: Container(
|
|
width: 48,
|
|
height: 48,
|
|
padding: const EdgeInsets.all(2),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: AppColors.panel,
|
|
border: Border.all(color: AppColors.gold, width: 2),
|
|
),
|
|
child: walletState.avatar.isEmpty
|
|
? const Icon(Icons.person, color: AppColors.gold)
|
|
: ClipOval(child: RandomAvatar(walletState.avatar)),
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Row(children: [
|
|
if (walletState.name.isNotEmpty) ...[
|
|
Text(walletState.name,
|
|
style: const TextStyle(
|
|
color: Colors.white, fontWeight: FontWeight.bold)),
|
|
const SizedBox(width: 6),
|
|
],
|
|
if (w?.vip == true) const _VipTag(),
|
|
]),
|
|
const SizedBox(height: 2),
|
|
Row(children: [
|
|
const Icon(Icons.star, color: AppColors.gold, size: 16),
|
|
const SizedBox(width: 4),
|
|
Text('سطح ${w?.level ?? '-'}',
|
|
style: const TextStyle(
|
|
color: AppColors.gold, fontWeight: FontWeight.bold)),
|
|
]),
|
|
const SizedBox(height: 4),
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(4),
|
|
child: SizedBox(
|
|
width: 96,
|
|
height: 7,
|
|
child: LinearProgressIndicator(
|
|
value: (w == null || w.xpForNext == 0)
|
|
? 0
|
|
: w.xpIntoLevel / w.xpForNext,
|
|
backgroundColor: Colors.white10,
|
|
valueColor: const AlwaysStoppedAnimation(AppColors.gold),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
GestureDetector(
|
|
onTap: onCoinTap,
|
|
child: StatChip(
|
|
icon: Icons.confirmation_number, value: '${w?.tickets ?? 0}'),
|
|
),
|
|
const SizedBox(width: 8),
|
|
GestureDetector(
|
|
onTap: onCoinTap,
|
|
child: StatChip(
|
|
icon: Icons.monetization_on, value: '${w?.coins ?? 0}'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// نشانِ کوچکِ VIP کنار نام در نوار بالا.
|
|
class _VipTag extends StatelessWidget {
|
|
const _VipTag();
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
colors: [Color(0xFFFFD54F), Color(0xFFB8860B)]),
|
|
borderRadius: BorderRadius.circular(6),
|
|
),
|
|
child: const Text('VIP',
|
|
style: TextStyle(
|
|
color: Color(0xFF3A0A12),
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 10)),
|
|
);
|
|
}
|
|
}
|