feat: add tournoment feature

This commit is contained in:
2026-07-07 15:18:55 +03:30
parent 5b0a66bb54
commit 5424695f25
10 changed files with 1349 additions and 229 deletions
@@ -6,9 +6,12 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:random_avatar/random_avatar.dart';
import '../../../../core/locator/locator.dart';
import '../../../../core/network/ws_client.dart';
import '../../../../core/service/app_sounds.dart';
import '../../../../core/theme/app_theme.dart';
import '../../../tournament/data/data_source/remote/tournament_api_provider.dart';
import '../../../tournament/domain/entities/tournament.dart';
import '../../../wallet/presentation/bloc/wallet_bloc.dart';
import '../../../wallet/presentation/bloc/wallet_event.dart';
import '../../../wallet/presentation/bloc/wallet_state.dart';
@@ -35,6 +38,7 @@ class _GameScreenState extends State<GameScreen> {
Timer? _introTimer;
bool _introHidden = false;
int _countdown = 0; // شمارشِ معکوسِ شروعِ بازی پس از یافتنِ حریفان (۳…۲…۱)
Tournament? _tournament; // تورنومنتِ فعالِ ثبت‌نام‌شده (اگر باشد) — برای نشانِ درون‌بازی
@override
void initState() {
@@ -47,6 +51,19 @@ class _GameScreenState extends State<GameScreen> {
skin: skin.isEmpty ? 'simple' : skin,
carpet: _carpet.isEmpty ? 'classic' : _carpet,
);
_loadTournament();
}
/// بررسی می‌کند آیا کاربر در تورنومنتِ فعالی ثبت‌نام کرده تا نشانِ درون‌بازی و
/// امتیازِ پایانِ بازی نمایش داده شود (این بازیِ عمومی به تورنومنت امتیاز می‌دهد).
Future<void> _loadTournament() async {
try {
final list = await locator<TournamentApiProvider>().getTournaments();
final active = list.where((t) => t.joined && t.isActive).toList();
if (mounted && active.isNotEmpty) {
setState(() => _tournament = active.first);
}
} catch (_) {/* بی‌اهمیت */}
}
@override
@@ -128,6 +145,8 @@ class _GameScreenState extends State<GameScreen> {
onChat: () => _openChat(context),
),
if (state.connection == WsStatus.disconnected) _connBanner(),
if (_tournament != null && !_showSearch(state))
_tournamentBadge(),
if (_showSearch(state)) _searchPanel(state),
// دیالوگِ انتخابِ حکم و بنرِ نوبت فقط پس از پایانِ انیمیشنِ
// پخشِ کارت نمایش داده می‌شوند (نه وسطِ بُر زدن/پخش).
@@ -558,6 +577,44 @@ class _GameScreenState extends State<GameScreen> {
);
}
// نشانِ درون‌بازیِ تورنومنت: به کاربر می‌فهماند این بازیِ عمومی به تورنومنت
// امتیاز می‌دهد (بالای صحنه، وسط).
Widget _tournamentBadge() => Positioned(
top: 6,
left: 0,
right: 0,
child: IgnorePointer(
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFF3A2A6E), AppColors.lapisInk],
),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: AppColors.gold, width: 1.2),
boxShadow: [
BoxShadow(
color: AppColors.gold.withValues(alpha: 0.3),
blurRadius: 8),
],
),
child: Row(mainAxisSize: MainAxisSize.min, children: [
const Icon(Icons.emoji_events, color: AppColors.gold, size: 15),
const SizedBox(width: 5),
Text(
'تورنومنت: ${_tournament!.title}',
style: const TextStyle(
color: AppColors.gold,
fontSize: 12,
fontWeight: FontWeight.bold),
),
]),
),
),
),
);
Widget _gameOver(BuildContext context, GameUiState s) {
final g = s.gameOver!;
final mySeat = s.state?.yourSeat ?? 0;
@@ -581,6 +638,29 @@ class _GameScreenState extends State<GameScreen> {
'نتیجه نهایی: ${g.scores.isNotEmpty ? g.scores[0] : 0} - ${g.scores.length > 1 ? g.scores[1] : 0}',
style: const TextStyle(color: Colors.white70, fontSize: 18),
),
// امتیازِ کسب‌شده‌ی تورنومنت (برد ۱۰۰، شرکت ۲۵ — قانونِ ثابتِ سرور).
if (_tournament != null) ...[
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: BoxDecoration(
color: AppColors.gold.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: AppColors.gold),
),
child: Row(mainAxisSize: MainAxisSize.min, children: [
const Icon(Icons.emoji_events, color: AppColors.gold, size: 20),
const SizedBox(width: 8),
Text(
'+${won ? 100 : 25} امتیاز تورنومنت «${_tournament!.title}»',
style: const TextStyle(
color: AppColors.gold,
fontSize: 14,
fontWeight: FontWeight.bold),
),
]),
),
],
const SizedBox(height: 28),
SizedBox(
width: 220,
@@ -50,9 +50,36 @@ class TierListScreen extends StatelessWidget {
final tiers = state.tiers;
return ListView.separated(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 20),
itemCount: tiers.length,
itemCount: tiers.length + 1,
separatorBuilder: (_, __) => const SizedBox(height: 14),
itemBuilder: (_, i) => _TierCard(tier: tiers[i], index: i),
itemBuilder: (_, i) {
if (i == 0) {
return Container(
margin: const EdgeInsets.only(bottom: 2),
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 10),
decoration: BoxDecoration(
color: AppColors.gold.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: AppColors.goldFaint),
),
child: const Row(children: [
Icon(Icons.military_tech,
color: AppColors.gold, size: 18),
SizedBox(width: 8),
Expanded(
child: Text(
'با بردن در هر میز، امتیازِ رتبه می‌گیرید و در جدولِ قهرمانان بالا می‌روید.',
style: TextStyle(
color: Colors.white, fontSize: 12.5),
),
),
]),
);
}
final t = tiers[i - 1];
return _TierCard(tier: t, index: i - 1);
},
);
},
),
@@ -78,7 +105,6 @@ class _TierCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (tier.isRanked) return _rankedCard(context);
final colors = _palettes[index % _palettes.length];
return GestureDetector(
onTap: () => context.push('/game/${tier.id}?prize=${tier.prize}'),
@@ -137,141 +163,10 @@ class _TierCard extends StatelessWidget {
_badge(Icons.star, 'XP ${tier.xp}'),
const SizedBox(height: 6),
_badge(Icons.emoji_events, '${tier.trophy}'),
]),
],
),
),
);
}
// میزِ رتبه‌بندی: طرحِ ویژه‌ی سلطنتی (تاج، درخششِ طلایی، توضیح) تا از میزهای
// معمولی متمایز باشد و کاربر بداند این میز چه‌کاری می‌کند.
Widget _rankedCard(BuildContext context) {
return GestureDetector(
onTap: () => context.push('/game/${tier.id}?prize=${tier.prize}'),
child: Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xFF3A2A6E), Color(0xFF15193F), AppColors.lapisInk],
),
borderRadius: BorderRadius.circular(18),
border: Border.all(color: AppColors.gold, width: 2.4),
boxShadow: [
BoxShadow(
color: AppColors.gold.withValues(alpha: 0.32), blurRadius: 16),
const BoxShadow(
color: Colors.black54, blurRadius: 10, offset: Offset(0, 5)),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(9),
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [AppColors.gold, AppColors.goldDark]),
shape: BoxShape.circle,
),
child: const Icon(Icons.workspace_premium,
color: AppColors.lapisInk, size: 24),
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
Flexible(
child: Text(tier.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.gold,
fontSize: 21,
fontWeight: FontWeight.bold,
shadows: [
Shadow(color: Colors.black54, blurRadius: 3)
],
)),
),
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 7, vertical: 2),
decoration: BoxDecoration(
color: AppColors.accent,
borderRadius: BorderRadius.circular(6),
border: Border.all(
color: Colors.white.withValues(alpha: 0.3)),
),
child: const Text('ویژه',
style: TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.bold)),
),
]),
const SizedBox(height: 2),
const Text('میزِ قهرمانان',
style:
TextStyle(color: Colors.white70, fontSize: 12)),
],
),
),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: AppColors.gold.withValues(alpha: 0.14),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: AppColors.gold),
),
child: Column(children: [
Row(mainAxisSize: MainAxisSize.min, children: [
const Icon(Icons.military_tech,
color: AppColors.gold, size: 16),
const SizedBox(width: 3),
Text('+${tier.rankReward}',
style: const TextStyle(
color: AppColors.gold,
fontSize: 16,
fontWeight: FontWeight.bold)),
]),
const Text('امتیاز رتبه',
style: TextStyle(color: Colors.white70, fontSize: 10)),
]),
),
if (tier.rankReward > 0) ...[
const SizedBox(height: 6),
_badge(Icons.military_tech, '+${tier.rankReward} رتبه'),
],
),
const SizedBox(height: 12),
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
decoration: BoxDecoration(
color: Colors.black.withValues(alpha: 0.25),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: AppColors.goldFaint),
),
child: const Text(
'با هر برد در این میز امتیازِ رتبه می‌گیرید و در جدولِ قهرمانان بالا می‌روید. '
'باخت امتیاز کم می‌کند — رقابتِ واقعی برای حرفه‌ای‌ها!',
style: TextStyle(
color: Colors.white, fontSize: 12.5, height: 1.6),
),
),
const SizedBox(height: 12),
Row(children: [
_chip(Icons.style, '${tier.hands} دست'),
const SizedBox(width: 8),
_chip(Icons.login, 'ورودی ${tier.entry}'),
const SizedBox(width: 8),
_chip(Icons.star, 'XP ${tier.xp}'),
]),
],
),
@@ -279,21 +174,6 @@ class _TierCard extends StatelessWidget {
);
}
Widget _chip(IconData icon, String text) => Container(
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 5),
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.08),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.white.withValues(alpha: 0.14)),
),
child: Row(mainAxisSize: MainAxisSize.min, children: [
Icon(icon, size: 14, color: AppColors.gold),
const SizedBox(width: 5),
Text(text,
style: const TextStyle(color: Colors.white, fontSize: 12)),
]),
);
Widget _stat(IconData icon, String label, int value) => Padding(
padding: const EdgeInsets.symmetric(vertical: 2),
child: Row(mainAxisSize: MainAxisSize.min, children: [