feat: add tournoment feature
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user