literales y unificación de resultados en los dos modos de juego

This commit is contained in:
2026-05-11 21:57:46 +02:00
parent 8ecd1ead32
commit 3c5d98d6dd
42 changed files with 1815 additions and 786 deletions
+6 -5
View File
@@ -384,6 +384,7 @@ class _TarjetaProgresoGamificacion extends StatelessWidget {
final nuevas = progreso.nuevasMedallas;
final antes = progreso.antes.fuego.clamp(0, 100);
final despues = progreso.despues.fuego.clamp(0, 100);
final l10n = AppLocalizations.of(context)!;
return _PanelRecompensa(
child: Column(
@@ -420,7 +421,7 @@ class _TarjetaProgresoGamificacion extends StatelessWidget {
const SizedBox(width: 14),
Expanded(
child: Text(
'RECOMPENSAS DE PARTIDA',
l10n.matchRewards.toUpperCase(),
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: TemaApp.colorDorado,
fontSize: 20,
@@ -438,7 +439,7 @@ class _TarjetaProgresoGamificacion extends StatelessWidget {
const SizedBox(height: 20),
if (nuevas.isEmpty)
Text(
'Sin medallas nuevas esta vez. Seguí acumulando fuego.',
l10n.noNewMedalsKeepFire,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: TemaApp.colorTextoSecundario,
height: 1.35,
@@ -446,7 +447,7 @@ class _TarjetaProgresoGamificacion extends StatelessWidget {
)
else ...[
Text(
'NUEVAS MEDALLAS',
l10n.newMedals.toUpperCase(),
style: Theme.of(context).textTheme.labelLarge?.copyWith(
color: TemaApp.colorDorado,
fontWeight: FontWeight.w800,
@@ -486,7 +487,7 @@ class _TarjetaRecompensaCargando extends StatelessWidget {
const SizedBox(width: 12),
Expanded(
child: Text(
'Calculando recompensas...',
AppLocalizations.of(context)!.calculatingRewards,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: TemaApp.colorDorado,
),
@@ -617,7 +618,7 @@ class _BarraFuegoPremium extends StatelessWidget {
Row(
children: [
Text(
'Fuego',
AppLocalizations.of(context)!.fireLabel,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w700,
),
+185 -314
View File
@@ -1,15 +1,18 @@
import 'package:confetti/confetti.dart';
import 'package:farolero/l10n/generated/app_localizations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:provider/provider.dart';
import '../modelos/inicio_partida_multijugador.dart';
import '../modelos/gamificacion_usuario.dart';
import '../modelos/inicio_partida_multijugador.dart';
import '../modelos/jugador.dart';
import '../modelos/palabra.dart';
import '../modelos/snapshot_partida_online.dart';
import '../servicios/servicio_historial_partidas.dart';
import '../servicios/servicio_nearby.dart';
import '../servicios/servicio_perfil_usuario.dart';
import '../tema/componentes_farolero.dart';
import '../tema/componentes_resultado_farolero.dart';
import '../tema/tema_app.dart';
import 'pantalla_notas_online.dart';
import 'pantalla_principal.dart';
@@ -35,202 +38,216 @@ class PantallaFinPartidaOnline extends StatefulWidget {
class _PantallaFinPartidaOnlineState extends State<PantallaFinPartidaOnline> {
bool _guardada = false;
ProgresoGamificacionUsuario? _progreso;
late final ConfettiController _confetti;
@override
void initState() {
super.initState();
_confetti = ConfettiController(duration: const Duration(seconds: 5));
Future.delayed(const Duration(milliseconds: 450), () {
if (mounted) _confetti.play();
});
}
@override
void dispose() {
_confetti.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final snapshot = widget.snapshot;
final jugadoresControlados = widget.jugadoresControlados;
final pistaCategoria = widget.pistaCategoria;
final ganaronJugadores = snapshot.ganador == 'jugadores';
final color = ganaronJugadores ? TemaApp.colorVerde : TemaApp.colorAcento;
if (!_guardada && snapshot.ganador != null) {
_guardada = true;
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (mounted) {
final historial = context.read<ServicioHistorialPartidas>();
final perfil = context.read<ServicioPerfilUsuario>();
await historial.guardarSnapshotOnline(snapshot);
final progreso = await perfil.registrarPartidaCompletada(
victoria: _perfilLocalGano(snapshot, jugadoresControlados),
comoImpostor: jugadoresControlados.any((j) => j.esImpostor),
victoriaComoImpostor: snapshot.ganador == 'impostores' &&
jugadoresControlados.any((j) => j.esImpostor),
);
if (mounted) setState(() => _progreso = progreso);
}
});
}
_registrarResultadoSiHaceFalta(context, snapshot);
return Scaffold(
extendBodyBehindAppBar: true,
backgroundColor: const Color(0xFF05070D),
appBar: AppBar(
title: Text(l10n.gameOver),
automaticallyImplyLeading: false,
actions: [
IconButton(
tooltip: l10n.seeYourWord,
icon: const Icon(Icons.visibility),
onPressed: jugadoresControlados.isEmpty
? null
: () => mostrarRevisionPalabraOnline(
context: context,
jugadoresControlados: jugadoresControlados,
pistaCategoria: pistaCategoria,
),
),
IconButton(
tooltip: l10n.notesTitle,
icon: const Icon(Icons.edit_note),
onPressed: snapshot.roomId == null || jugadoresControlados.isEmpty
? null
: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => PantallaNotasOnline(
partidaId: snapshot.roomId!,
jugadores: snapshot.jugadores,
autoresControlados: jugadoresControlados,
),
),
),
),
],
backgroundColor: Colors.transparent,
elevation: 0,
actions: _acciones(context, l10n, snapshot),
),
body: FondoFarolero(
intenso: true,
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
child: Stack(
children: [
_ResultadoOnlineHero(
ganaronJugadores: ganaronJugadores,
titulo: ganaronJugadores ? l10n.playersWin : l10n.impostorsWin,
Positioned.fill(
child: IgnorePointer(
child: CustomPaint(
painter: EscenarioFinPartidaFaroleroPainter(color: color),
),
),
),
const SizedBox(height: 24),
if (_progreso != null) ...[
_TarjetaProgresoGamificacion(progreso: _progreso!),
const SizedBox(height: 16),
],
Card(
child: Padding(
padding: const EdgeInsets.all(20),
Align(
alignment: Alignment.topCenter,
child: ConfettiWidget(
confettiController: _confetti,
blastDirectionality: BlastDirectionality.explosive,
emissionFrequency: 0.09,
numberOfParticles: 28,
gravity: 0.18,
colors: const [
TemaApp.colorDorado,
TemaApp.colorNaranja,
TemaApp.colorAcento,
Color(0xFFFFECBE),
],
),
),
Positioned.fill(
child: IgnorePointer(
child: DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.transparent,
Colors.black.withValues(alpha: 0.10),
Colors.black.withValues(alpha: 0.52),
],
stops: const [0.0, 0.54, 1.0],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
),
),
SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(20, 72, 20, 28),
child: Column(
children: [
Text(
l10n.theSecretWordWas,
style: Theme.of(context).textTheme.titleMedium,
HeroFinalPartidaFarolero(
encabezado: l10n.gameOver,
titulo:
ganaronJugadores ? l10n.playersWin : l10n.impostorsWin,
icono: ganaronJugadores
? Icons.emoji_events
: Icons.theater_comedy,
color: color,
),
const SizedBox(height: 8),
Text(
snapshot.palabraSecreta ?? '?',
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
color: TemaApp.colorNaranja,
fontSize: 32,
),
),
const SizedBox(height: 4),
Text(
l10n.categoryLabel(
BancoPalabras.nombreBonitoCategoria(
const SizedBox(height: 12),
if (_progreso == null)
const TarjetaRecompensaCargandoPremium()
else
TarjetaProgresoGamificacionPremium(progreso: _progreso!),
const SizedBox(height: 18),
if (snapshot.palabraSecreta != null)
TarjetaSecretoPremium(
palabra: snapshot.palabraSecreta!,
categoria: BancoPalabras.nombreBonitoCategoria(
snapshot.categoria,
l10n,
),
),
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
),
),
const SizedBox(height: 16),
Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
children: [
Text(
snapshot.impostores.length == 1
const SizedBox(height: 18),
TarjetaImpostoresPremium(
titulo: snapshot.impostores.length == 1
? l10n.theImpostorWas
: l10n.theImpostorsWere,
style: Theme.of(context).textTheme.titleMedium,
impostores: _impostores(snapshot),
),
const SizedBox(height: 8),
...snapshot.impostores.map(
(nombre) => Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Text(
'🎭 $nombre',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: TemaApp.colorAcento,
),
),
const SizedBox(height: 18),
if (snapshot.historialVotaciones.isNotEmpty)
TarjetaHistorialVotosPremium(
historial: snapshot.historialVotaciones,
jugadores: snapshot.jugadores,
),
const SizedBox(height: 24),
BotonFarolero.oscuro(
texto: l10n.mainMenu,
icono: Icons.home,
onPressed: () async {
await context.read<ServicioNearby>().desconectar();
if (!context.mounted) return;
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (_) => const PantallaPrincipal(),
),
(route) => false,
);
},
),
const SizedBox(height: 16),
],
),
),
),
const SizedBox(height: 16),
if (snapshot.historialVotaciones.isNotEmpty)
Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
l10n.votingHistory,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 12),
...snapshot.historialVotaciones.asMap().entries.map(
(entrada) {
final ronda = entrada.key + 1;
final resultado = entrada.value;
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Text(
l10n.roundElimination(
ronda,
resultado.eliminadoNombre,
),
style: TextStyle(
fontWeight: FontWeight.bold,
color: resultado.eraImpostor
? TemaApp.colorVerde
: TemaApp.colorAcento,
),
),
);
},
),
],
),
),
),
const SizedBox(height: 24),
BotonFarolero.oscuro(
texto: l10n.mainMenu,
icono: Icons.home,
onPressed: () async {
await context.read<ServicioNearby>().desconectar();
if (!context.mounted) return;
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (_) => const PantallaPrincipal(),
),
(route) => false,
);
},
),
],
),
),
),
);
}
List<Widget> _acciones(
BuildContext context,
AppLocalizations l10n,
SnapshotPartidaOnline snapshot,
) {
return [
IconButton(
tooltip: l10n.seeYourWord,
icon: const Icon(Icons.visibility),
onPressed: widget.jugadoresControlados.isEmpty
? null
: () => mostrarRevisionPalabraOnline(
context: context,
jugadoresControlados: widget.jugadoresControlados,
pistaCategoria: widget.pistaCategoria,
),
),
IconButton(
tooltip: l10n.notesTitle,
icon: const Icon(Icons.edit_note),
onPressed: snapshot.roomId == null || widget.jugadoresControlados.isEmpty
? null
: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => PantallaNotasOnline(
partidaId: snapshot.roomId!,
jugadores: snapshot.jugadores,
autoresControlados: widget.jugadoresControlados,
),
),
),
),
];
}
void _registrarResultadoSiHaceFalta(
BuildContext context,
SnapshotPartidaOnline snapshot,
) {
if (_guardada || snapshot.ganador == null) return;
_guardada = true;
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (!mounted) return;
final historial = context.read<ServicioHistorialPartidas>();
final perfil = context.read<ServicioPerfilUsuario>();
await historial.guardarSnapshotOnline(snapshot);
final progreso = await perfil.registrarPartidaCompletada(
victoria: _perfilLocalGano(snapshot, widget.jugadoresControlados),
comoImpostor: widget.jugadoresControlados.any((j) => j.esImpostor),
victoriaComoImpostor: snapshot.ganador == 'impostores' &&
widget.jugadoresControlados.any((j) => j.esImpostor),
);
if (!mounted) return;
setState(() => _progreso = progreso);
if (progreso.nuevasMedallas.isNotEmpty || progreso.incrementoFuego > 0) {
_confetti.play();
}
});
}
bool _perfilLocalGano(
SnapshotPartidaOnline snapshot,
List<JugadorInicioPartida> jugadoresControlados,
@@ -241,161 +258,15 @@ class _PantallaFinPartidaOnlineState extends State<PantallaFinPartidaOnline> {
(jugador) => jugador.esImpostor ? ganaronImpostores : !ganaronImpostores,
);
}
}
class _ResultadoOnlineHero extends StatelessWidget {
final bool ganaronJugadores;
final String titulo;
const _ResultadoOnlineHero({
required this.ganaronJugadores,
required this.titulo,
});
@override
Widget build(BuildContext context) {
final color = ganaronJugadores ? TemaApp.colorVerde : TemaApp.colorAcento;
return Container(
width: double.infinity,
padding: const EdgeInsets.fromLTRB(20, 18, 20, 24),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
color.withValues(alpha: 0.20),
const Color(0xFF101827).withValues(alpha: 0.68),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
borderRadius: BorderRadius.circular(28),
border: Border.all(color: color.withValues(alpha: 0.65)),
),
child: Column(
children: [
Image.asset(
'assets/ui/generated/final_rewards/cinematic_burst.webp',
height: 250,
fit: BoxFit.contain,
opacity: const AlwaysStoppedAnimation(0.95),
),
const SizedBox(height: 8),
Text(
titulo,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: color,
fontWeight: FontWeight.w900,
shadows: [
Shadow(color: color.withValues(alpha: 0.75), blurRadius: 18),
],
),
textAlign: TextAlign.center,
),
],
),
).animate().fadeIn(duration: 320.ms).slideY(begin: -0.08);
}
}
class _TarjetaProgresoGamificacion extends StatelessWidget {
final ProgresoGamificacionUsuario progreso;
const _TarjetaProgresoGamificacion({required this.progreso});
@override
Widget build(BuildContext context) {
final nuevas = progreso.nuevasMedallas;
return Container(
width: double.infinity,
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
const Color(0xFF111B28).withValues(alpha: 0.96),
const Color(0xFF180D22).withValues(alpha: 0.94),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(22),
border: Border.all(color: TemaApp.colorDorado.withValues(alpha: 0.52)),
boxShadow: [
BoxShadow(
color: TemaApp.colorNaranja.withValues(alpha: 0.18),
blurRadius: 32,
offset: const Offset(0, 16),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.local_fire_department,
color: TemaApp.colorNaranja),
const SizedBox(width: 8),
Expanded(
child: Text(
'RECOMPENSAS DE PARTIDA',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: TemaApp.colorDorado,
fontWeight: FontWeight.w900,
letterSpacing: 1,
),
),
),
Text(
progreso.incrementoFuego >= 0
? '+${progreso.incrementoFuego}'
: '${progreso.incrementoFuego}',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: TemaApp.colorDorado,
fontWeight: FontWeight.w900,
),
),
],
),
const SizedBox(height: 12),
TweenAnimationBuilder<double>(
tween: Tween(
begin: progreso.antes.fuego.clamp(0, 100) / 100,
end: progreso.despues.fuego.clamp(0, 100) / 100,
),
duration: const Duration(milliseconds: 1300),
curve: Curves.easeOutCubic,
builder: (context, value, _) => ClipRRect(
borderRadius: BorderRadius.circular(999),
child: LinearProgressIndicator(
value: value.clamp(0.0, 1.0).toDouble(),
minHeight: 18,
backgroundColor: Colors.black.withValues(alpha: 0.35),
valueColor: const AlwaysStoppedAnimation(TemaApp.colorNaranja),
),
),
),
const SizedBox(height: 8),
Text(
'${progreso.despues.fuego}% de fuego',
style: Theme.of(context).textTheme.bodySmall,
),
if (nuevas.isNotEmpty) ...[
const SizedBox(height: 12),
Text(
'NUEVAS MEDALLAS',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: TemaApp.colorDorado,
fontWeight: FontWeight.w800,
),
),
const SizedBox(height: 6),
MedallasCompactasFarolero(ids: nuevas, max: nuevas.length),
],
],
),
)
.animate()
.fadeIn(duration: 360.ms)
.slideY(begin: 0.12)
.shimmer(delay: 700.ms, duration: 1200.ms);
List<Jugador> _impostores(SnapshotPartidaOnline snapshot) {
final porNombre = {for (final jugador in snapshot.jugadores) jugador.nombre: jugador};
return snapshot.impostores
.map(
(nombre) =>
porNombre[nombre] ??
Jugador(id: nombre, nombre: nombre, esImpostor: true),
)
.toList();
}
}
+4 -181
View File
@@ -84,56 +84,12 @@ class _PantallaResultadoState extends State<PantallaResultado>
],
if (_revelado) ...[
// Resultado revelado
FadeTransition(
opacity: _animOpacidad,
child: Column(
children: [
const ArteGameplayFarolero.resultado(height: 164),
const SizedBox(height: 16),
Text(
widget.resultado.eliminadoNombre,
style: Theme.of(context)
.textTheme
.headlineLarge
?.copyWith(fontSize: 32),
),
const SizedBox(height: 12),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 24, vertical: 12),
decoration: BoxDecoration(
color: widget.resultado.eraImpostor
? TemaApp.colorVerde.withValues(alpha: 0.3)
: TemaApp.colorAcento.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(30),
border: Border.all(
color: widget.resultado.eraImpostor
? TemaApp.colorVerde
: TemaApp.colorAcento,
),
),
child: Text(
widget.resultado.eraImpostor
? l10n.wasImpostor
: l10n.wasInnocent,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: widget.resultado.eraImpostor
? TemaApp.colorVerde
: TemaApp.colorAcento,
),
),
),
const SizedBox(height: 24),
_buildDetalleVotos(context, partida, l10n),
const SizedBox(height: 24),
// Acciones
_construirBotones(context, estado),
],
child: ResultadoRondaFarolero(
resultado: widget.resultado,
jugadores: partida?.jugadores ?? const [],
acciones: _construirBotones(context, estado),
),
),
],
@@ -145,139 +101,6 @@ class _PantallaResultadoState extends State<PantallaResultado>
);
}
Widget _buildDetalleVotos(
BuildContext context,
Partida? partida,
AppLocalizations l10n,
) {
final jugadores = {
for (final jugador in partida?.jugadores ?? []) jugador.id: jugador,
};
final conteo = <String, int>{};
for (final votadoId in widget.resultado.votos.values) {
conteo[votadoId] = (conteo[votadoId] ?? 0) + 1;
}
final maxVotos = conteo.values.isEmpty
? 1
: conteo.values.reduce((a, b) => a > b ? a : b);
final ranking = conteo.entries.toList()
..sort((a, b) => b.value.compareTo(a.value));
return Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.bar_chart, color: TemaApp.colorNaranja),
const SizedBox(width: 8),
Text(
l10n.votesThisRound,
style: Theme.of(context).textTheme.titleMedium,
),
],
),
const SizedBox(height: 12),
...ranking.map((entry) {
final jugador = jugadores[entry.key];
final eliminado = entry.key == widget.resultado.eliminadoId;
return _buildBarraVotos(
context,
nombre: jugador?.nombre ?? '?',
votos: entry.value,
total: maxVotos,
destacado: eliminado,
);
}),
const Divider(height: 24),
...widget.resultado.votos.entries.map((entry) {
final votante = jugadores[entry.key]?.nombre ?? '?';
final votado = jugadores[entry.value]?.nombre ?? '?';
final fueAlEliminado =
entry.value == widget.resultado.eliminadoId;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
Icon(
fueAlEliminado
? Icons.how_to_vote
: Icons.arrow_forward,
size: 18,
color: fueAlEliminado
? TemaApp.colorAcento
: TemaApp.colorTextoSecundario,
),
const SizedBox(width: 8),
Expanded(
child: Text(
'$votante$votado',
style: TextStyle(
color: fueAlEliminado
? TemaApp.colorTexto
: TemaApp.colorTextoSecundario,
fontWeight: fueAlEliminado
? FontWeight.bold
: FontWeight.normal,
),
),
),
],
),
);
}),
],
),
),
);
}
Widget _buildBarraVotos(
BuildContext context, {
required String nombre,
required int votos,
required int total,
required bool destacado,
}) {
final color = destacado ? TemaApp.colorAcento : TemaApp.colorNaranja;
final proporcion = total == 0 ? 0.0 : votos / total;
return Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
nombre,
style: TextStyle(
fontWeight: destacado ? FontWeight.bold : FontWeight.w600,
),
),
),
Text(
'$votos',
style: TextStyle(color: color, fontWeight: FontWeight.bold),
),
],
),
const SizedBox(height: 6),
ClipRRect(
borderRadius: BorderRadius.circular(999),
child: LinearProgressIndicator(
value: proporcion.clamp(0.0, 1.0).toDouble(),
minHeight: 10,
backgroundColor: TemaApp.colorSuperficie,
valueColor: AlwaysStoppedAnimation(color),
),
),
],
),
);
}
Widget _construirBotones(BuildContext context, EstadoJuego estado) {
final l10n = AppLocalizations.of(context)!;
final partida = estado.partida;
+13 -117
View File
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:farolero/l10n/generated/app_localizations.dart';
import '../modelos/inicio_partida_multijugador.dart';
import '../modelos/partida.dart';
import '../modelos/snapshot_partida_online.dart';
import '../servicios/servicio_nearby.dart';
import '../tema/componentes_farolero.dart';
import '../tema/componentes_resultado_farolero.dart';
import '../tema/tema_app.dart';
import 'pantalla_debate_cliente.dart';
import 'pantalla_fin_partida_online.dart';
@@ -171,11 +171,18 @@ class _PantallaResultadoOnlineState extends State<PantallaResultadoOnline> {
),
body: FondoFarolero(
intenso: true,
child: Padding(
padding: const EdgeInsets.all(24),
child: resultado == null
? _buildEsperaAdivinanza(context, l10n)
: _buildResultado(context, l10n, resultado),
child: SafeArea(
top: false,
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: resultado == null
? _buildEsperaAdivinanza(context, l10n)
: ResultadoRondaFarolero(
resultado: resultado,
jugadores: _snapshot.jugadores,
mensaje: _snapshot.mensaje,
),
),
),
),
);
@@ -242,116 +249,5 @@ class _PantallaResultadoOnlineState extends State<PantallaResultadoOnline> {
);
}
Widget _buildResultado(
BuildContext context,
AppLocalizations l10n,
ResultadoVotacion resultado,
) {
final conteo = <String, int>{};
for (final votadoId in resultado.votos.values) {
conteo[votadoId] = (conteo[votadoId] ?? 0) + 1;
}
final maxVotos = conteo.values.isEmpty
? 1
: conteo.values.reduce((a, b) => a > b ? a : b);
final ranking = conteo.entries.toList()
..sort((a, b) => b.value.compareTo(a.value));
final jugadores = {for (final jugador in _snapshot.jugadores) jugador.id: jugador};
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const ArteGameplayFarolero.resultado(height: 132),
const SizedBox(height: 12),
Container(
width: double.infinity,
padding: const EdgeInsets.all(20),
decoration: TemaApp.decoracionPanel(
color: resultado.eraImpostor
? TemaApp.colorVerde.withValues(alpha: 0.18)
: TemaApp.colorAcento.withValues(alpha: 0.18),
borderColor:
resultado.eraImpostor ? TemaApp.colorVerde : TemaApp.colorAcento,
),
child: Column(
children: [
Text(
resultado.eliminadoNombre,
style: Theme.of(context).textTheme.headlineMedium,
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
resultado.eraImpostor ? l10n.wasImpostor : l10n.wasInnocent,
style: TextStyle(
color: resultado.eraImpostor
? TemaApp.colorVerde
: TemaApp.colorAcento,
fontWeight: FontWeight.bold,
),
),
if (_snapshot.mensaje != null) ...[
const SizedBox(height: 12),
Text(_snapshot.mensaje!, textAlign: TextAlign.center),
],
],
),
),
const SizedBox(height: 20),
Text(l10n.votesThisRound, style: Theme.of(context).textTheme.titleLarge),
const SizedBox(height: 12),
Expanded(
child: ListView(
children: [
...ranking.map((entry) {
final jugador = jugadores[entry.key];
final destacado = entry.key == resultado.eliminadoId;
final color = destacado ? TemaApp.colorAcento : TemaApp.colorNaranja;
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(child: Text(jugador?.nombre ?? '?')),
Text(
'${entry.value}',
style: TextStyle(
color: color,
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 6),
ClipRRect(
borderRadius: BorderRadius.circular(999),
child: LinearProgressIndicator(
value: (entry.value / maxVotos).clamp(0.0, 1.0).toDouble(),
minHeight: 10,
backgroundColor: TemaApp.colorSuperficie,
valueColor: AlwaysStoppedAnimation(color),
),
),
],
),
);
}),
const Divider(height: 24),
...resultado.votos.entries.map((entry) {
final votante = jugadores[entry.key]?.nombre ?? '?';
final votado = jugadores[entry.value]?.nombre ?? '?';
return ListTile(
dense: true,
leading: const Icon(Icons.how_to_vote),
title: Text('$votante$votado'),
);
}),
],
),
),
],
);
}
}
+26 -169
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:farolero/l10n/generated/app_localizations.dart';
import 'package:farolero/modelos/inicio_partida_multijugador.dart';
import 'package:farolero/modelos/jugador.dart';
import 'package:farolero/modelos/partida.dart';
import 'package:farolero/modelos/snapshot_partida_online.dart';
import 'package:farolero/pantallas/pantalla_notas_online.dart';
import 'package:farolero/pantallas/pantalla_revision_palabra.dart';
@@ -36,7 +37,6 @@ class PantallaVotacionCliente extends StatefulWidget {
class _PantallaVotacionClienteState extends State<PantallaVotacionCliente> {
final Map<String, String> _votosPorVotante = {};
Map<String, dynamic>? _resultado;
OnMensajeCallback? _listener;
ServicioNearby? _nearby;
@@ -63,7 +63,31 @@ class _PantallaVotacionClienteState extends State<PantallaVotacionCliente> {
),
);
} else {
setState(() => _resultado = mensaje.datos);
final votosRaw = mensaje.datos['votos'] as Map<dynamic, dynamic>? ?? {};
final snapshot = SnapshotPartidaOnline(
roomId: widget.partidaId,
fase: 'resultado',
ronda: 1,
categoria: '',
jugadores: widget.jugadores,
resultadoActual: ResultadoVotacion(
eliminadoId: mensaje.datos['eliminadoId'] as String? ?? '',
eliminadoNombre: mensaje.datos['eliminadoNombre'] as String? ?? '?',
eraImpostor: mensaje.datos['eraImpostor'] as bool? ?? false,
votos: votosRaw.map(
(key, value) => MapEntry(key.toString(), value.toString()),
),
),
);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (_) => PantallaResultadoOnline(
snapshot: snapshot,
jugadoresControlados: widget.jugadoresControlados,
pistaCategoria: widget.pistaCategoria,
),
),
);
}
};
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -87,7 +111,6 @@ class _PantallaVotacionClienteState extends State<PantallaVotacionCliente> {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
if (_resultado != null) return _buildResultado(context, _resultado!);
return Scaffold(
backgroundColor: TemaApp.colorFondo,
@@ -189,172 +212,6 @@ class _PantallaVotacionClienteState extends State<PantallaVotacionCliente> {
widget.jugadoresControlados.isNotEmpty;
}
Widget _buildResultado(BuildContext context, Map<String, dynamic> resultado) {
final l10n = AppLocalizations.of(context)!;
final eliminadoId = resultado['eliminadoId'] as String?;
final eliminadoNombre = resultado['eliminadoNombre'] as String? ?? '?';
final eraImpostor = resultado['eraImpostor'] as bool? ?? false;
final votosRaw = resultado['votos'] as Map<dynamic, dynamic>? ?? {};
final votos = votosRaw.map(
(key, value) => MapEntry(key.toString(), value.toString()),
);
final jugadores = {for (final jugador in widget.jugadores) jugador.id: jugador};
final conteo = <String, int>{};
for (final votadoId in votos.values) {
conteo[votadoId] = (conteo[votadoId] ?? 0) + 1;
}
final maxVotos = conteo.values.isEmpty
? 1
: conteo.values.reduce((a, b) => a > b ? a : b);
final ranking = conteo.entries.toList()
..sort((a, b) => b.value.compareTo(a.value));
return Scaffold(
backgroundColor: TemaApp.colorFondo,
appBar: AppBar(
title: Text(l10n.result),
automaticallyImplyLeading: false,
backgroundColor: Colors.transparent,
elevation: 0,
actions: [
IconButton(
tooltip: l10n.seeYourWord,
icon: const Icon(Icons.visibility),
onPressed: widget.jugadoresControlados.isEmpty
? null
: () => mostrarRevisionPalabraOnline(
context: context,
jugadoresControlados: widget.jugadoresControlados,
pistaCategoria: widget.pistaCategoria,
),
),
IconButton(
tooltip: l10n.notesTitle,
icon: const Icon(Icons.edit_note),
onPressed: _puedeAbrirNotas
? () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => PantallaNotasOnline(
partidaId: widget.partidaId!,
jugadores: widget.jugadores,
autoresControlados: widget.jugadoresControlados,
),
),
)
: null,
),
],
),
body: FondoFarolero(
intenso: true,
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const ArteGameplayFarolero.fase(height: 118),
const SizedBox(height: 10),
Container(
width: double.infinity,
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: eraImpostor
? TemaApp.colorVerde.withValues(alpha: 0.18)
: TemaApp.colorAcento.withValues(alpha: 0.18),
borderRadius: BorderRadius.circular(18),
border: Border.all(
color: eraImpostor ? TemaApp.colorVerde : TemaApp.colorAcento,
),
),
child: Column(
children: [
Text(
eliminadoNombre,
style: Theme.of(context).textTheme.headlineMedium,
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
eraImpostor ? l10n.wasImpostor : l10n.wasInnocent,
style: TextStyle(
color: eraImpostor
? TemaApp.colorVerde
: TemaApp.colorAcento,
fontWeight: FontWeight.bold,
),
),
],
),
),
const SizedBox(height: 20),
Text(
'Detalle de votos',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 12),
Expanded(
child: ListView(
children: [
...ranking.map((entry) {
final jugador = jugadores[entry.key];
final destacado = entry.key == eliminadoId;
final color = destacado
? TemaApp.colorAcento
: TemaApp.colorNaranja;
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(child: Text(jugador?.nombre ?? '?')),
Text(
'${entry.value}',
style: TextStyle(
color: color,
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 6),
ClipRRect(
borderRadius: BorderRadius.circular(999),
child: LinearProgressIndicator(
value: (entry.value / maxVotos)
.clamp(0.0, 1.0)
.toDouble(),
minHeight: 10,
backgroundColor: TemaApp.colorSuperficie,
valueColor: AlwaysStoppedAnimation(color),
),
),
],
),
);
}),
const Divider(height: 24),
...votos.entries.map((entry) {
final votante = jugadores[entry.key]?.nombre ?? '?';
final votado = jugadores[entry.value]?.nombre ?? '?';
return ListTile(
dense: true,
leading: const Icon(Icons.how_to_vote),
title: Text('$votante$votado'),
);
}),
],
),
),
],
),
),
),
);
}
Widget _buildSelectorLegacy() {
return ListView.builder(
itemCount: widget.jugadores.length,