Gamificación
This commit is contained in:
@@ -4,12 +4,14 @@ import 'package:flutter/material.dart';
|
||||
import 'package:farolero/l10n/generated/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../estado/estado_juego.dart';
|
||||
import '../modelos/gamificacion_usuario.dart';
|
||||
import '../modelos/inicio_partida_multijugador.dart';
|
||||
import '../modelos/jugador.dart';
|
||||
import '../modelos/partida.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/tema_app.dart';
|
||||
import 'pantalla_notas_online.dart';
|
||||
@@ -31,6 +33,7 @@ class _PantallaGestorHostState extends State<PantallaGestorHost> {
|
||||
int _segundosRestantes = 0;
|
||||
bool _hostListo = false;
|
||||
bool _partidaOnlineGuardada = false;
|
||||
ProgresoGamificacionUsuario? _progresoGamificacion;
|
||||
String? _primerTurnoId;
|
||||
String? _primerTurnoNombre;
|
||||
final Map<String, bool> _clientesListos = {};
|
||||
@@ -695,7 +698,7 @@ class _PantallaGestorHostState extends State<PantallaGestorHost> {
|
||||
label: Text(
|
||||
_hostYaVoto(context)
|
||||
? 'Votos del host registrados'
|
||||
: 'Votar por los jugadores de este m?vil',
|
||||
: 'Votar por los jugadores de este móvil',
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -934,12 +937,57 @@ class _PantallaGestorHostState extends State<PantallaGestorHost> {
|
||||
partida == null ? '' : l10n.theWordWas(partida.palabraSecreta),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
if (_progresoGamificacion != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
_buildProgresoGamificacion(context, _progresoGamificacion!),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProgresoGamificacion(
|
||||
BuildContext context,
|
||||
ProgresoGamificacionUsuario progreso,
|
||||
) {
|
||||
final nuevas = progreso.nuevasMedallas;
|
||||
return PanelFarolero(
|
||||
padding: const EdgeInsets.all(14),
|
||||
color: TemaApp.colorSuperficie.withValues(alpha: 0.82),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Tu progreso', style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
const Text('🔥', style: TextStyle(fontSize: 22)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: LinearProgressIndicator(
|
||||
value: progreso.despues.fuego / 100,
|
||||
minHeight: 8,
|
||||
color: TemaApp.colorNaranja,
|
||||
backgroundColor: Colors.black.withValues(alpha: 0.35),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text('${progreso.despues.fuego}%'),
|
||||
],
|
||||
),
|
||||
if (nuevas.isNotEmpty) ...[
|
||||
const SizedBox(height: 10),
|
||||
MedallasCompactasFarolero(ids: nuevas, max: nuevas.length),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _hostYaVoto(BuildContext context) {
|
||||
final estado = context.read<EstadoJuego>();
|
||||
final sala = context.read<ServicioNearby>().estadoSala;
|
||||
@@ -1182,7 +1230,28 @@ class _PantallaGestorHostState extends State<PantallaGestorHost> {
|
||||
final partida = context.read<EstadoJuego>().partida;
|
||||
if (partida?.ganador == null) return;
|
||||
_partidaOnlineGuardada = true;
|
||||
await context.read<ServicioHistorialPartidas>().guardarPartida(partida!);
|
||||
final historial = context.read<ServicioHistorialPartidas>();
|
||||
final nearby = context.read<ServicioNearby>();
|
||||
final perfil = context.read<ServicioPerfilUsuario>();
|
||||
await historial.guardarPartida(partida!);
|
||||
final jugadoresHost = _jugadoresHostControlados(
|
||||
partida,
|
||||
nearby,
|
||||
);
|
||||
final ganaronImpostores = partida.ganador == 'impostores';
|
||||
final victoria = jugadoresHost.isEmpty
|
||||
? partida.ganador == 'jugadores'
|
||||
: jugadoresHost.any(
|
||||
(jugador) =>
|
||||
jugador.esImpostor ? ganaronImpostores : !ganaronImpostores,
|
||||
);
|
||||
final progreso = await perfil.registrarPartidaCompletada(
|
||||
victoria: victoria,
|
||||
comoImpostor: jugadoresHost.any((j) => j.esImpostor),
|
||||
victoriaComoImpostor:
|
||||
ganaronImpostores && jugadoresHost.any((j) => j.esImpostor),
|
||||
);
|
||||
if (mounted) setState(() => _progresoGamificacion = progreso);
|
||||
}
|
||||
|
||||
Future<void> _iniciarAdivinanzaOnline(BuildContext context) async {
|
||||
|
||||
Reference in New Issue
Block a user