import 'package:flutter/material.dart'; import '../game/iron_arc_game.dart'; import '../net/match_session.dart'; /// Score pills, turn counter and wind indicator. class Hud extends StatelessWidget { const Hud({super.key, required this.hud}); final HudState hud; @override Widget build(BuildContext context) { return Row( children: [ _Pill( label: 'P1', value: '${hud.hp0} HP', color: const Color(0xFFFF8A3D), active: hud.current == 0 && !hud.isFinished, ), const SizedBox(width: 8), Expanded( child: Column( children: [ Text('Zug ${hud.turn}', style: const TextStyle( fontSize: 13, fontWeight: FontWeight.w700)), const SizedBox(height: 2), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ const Icon(Icons.air, size: 14), const SizedBox(width: 4), Text('${hud.wind > 0 ? '+' : ''}${hud.wind}', style: const TextStyle(fontSize: 13)), ], ), ], ), ), const SizedBox(width: 8), _Pill( label: 'P2', value: '${hud.hp1} HP', color: const Color(0xFF4DD0E1), active: hud.current == 1 && !hud.isFinished, ), ], ); } } /// Connection state and pending-replay counter. class StatusBar extends StatelessWidget { const StatusBar({super.key, required this.session, required this.onSettings}); final MatchSession session; final VoidCallback onSettings; @override Widget build(BuildContext context) { final (color, icon) = switch (session.status) { SyncStatus.online => (const Color(0xFF66BB6A), Icons.cloud_done), SyncStatus.connecting => (const Color(0xFFFFC107), Icons.cloud_sync), SyncStatus.desync => (const Color(0xFFE53935), Icons.warning_amber), SyncStatus.error => (const Color(0xFFE53935), Icons.cloud_off), SyncStatus.offline => (const Color(0xFF90A4AE), Icons.cloud_off), }; return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(icon, size: 14, color: color), const SizedBox(width: 6), Flexible( child: Text( session.statusLabel, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 11, color: color), ), ), if (session.queued > 0) ...[ const SizedBox(width: 8), Text('· ${session.queued} pending', style: const TextStyle(fontSize: 11, color: Color(0xFFFFC107))), ], const SizedBox(width: 4), Semantics( button: true, label: 'Einstellungen', child: InkWell( onTap: onSettings, borderRadius: BorderRadius.circular(12), child: const Padding( padding: EdgeInsets.all(8), child: Icon(Icons.tune, size: 18, color: Color(0xFF90A4AE)), ), ), ), ], ); } } /// Online / Replay / Upload actions. class Controls extends StatelessWidget { const Controls({ super.key, required this.session, required this.onOnline, required this.onReplay, required this.onFlush, required this.onAd, }); final MatchSession session; final VoidCallback onOnline; final VoidCallback onReplay; final VoidCallback onFlush; final VoidCallback onAd; @override Widget build(BuildContext context) { return Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ _Action(icon: Icons.wifi_tethering, label: 'Online', onTap: onOnline), _Action(icon: Icons.replay, label: 'Replay', onTap: onReplay), _Action( icon: Icons.cloud_upload, label: session.queued > 0 ? 'Senden (${session.queued})' : 'Senden', onTap: onFlush, ), _Action(icon: Icons.ondemand_video, label: 'Ad', onTap: onAd), ], ); } } class _Action extends StatelessWidget { const _Action({required this.icon, required this.label, required this.onTap}); final IconData icon; final String label; final VoidCallback onTap; @override Widget build(BuildContext context) { return Material( color: const Color(0xCC0B1220), borderRadius: BorderRadius.circular(18), child: InkWell( borderRadius: BorderRadius.circular(18), onTap: onTap, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(icon, size: 18), const SizedBox(width: 6), Text(label, style: const TextStyle(fontSize: 13)), ], ), ), ), ); } } class _Pill extends StatelessWidget { const _Pill({ required this.label, required this.value, required this.color, required this.active, }); final String label; final String value; final Color color; final bool active; @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), decoration: BoxDecoration( color: color.withValues(alpha: active ? 0.28 : 0.10), borderRadius: BorderRadius.circular(10), border: Border.all( color: color.withValues(alpha: active ? 0.9 : 0.3), width: active ? 2 : 1, ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(label, style: TextStyle( fontSize: 11, color: color, fontWeight: FontWeight.w800)), Text(value, style: const TextStyle(fontSize: 15)), ], ), ); } } /// Short instruction or flight indicator. class HintBubble extends StatelessWidget { const HintBubble({super.key, required this.hud}); final HudState hud; @override Widget build(BuildContext context) { final text = hud.phase == 1 ? 'Projektil im Flug…' : 'Ziehen zum Zielen · Loslassen zum Schießen'; return Center( child: Container( padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8), decoration: BoxDecoration( color: const Color(0xCC0B1220), borderRadius: BorderRadius.circular(20), ), child: Text(text, style: const TextStyle(fontSize: 13)), ), ); } } /// Winner banner plus rematch button. class GameOver extends StatelessWidget { const GameOver({super.key, required this.hud, required this.onRestart}); final HudState hud; final VoidCallback onRestart; @override Widget build(BuildContext context) { final text = switch (hud.winner) { 0 => 'Spieler 1 gewinnt', 1 => 'Spieler 2 gewinnt', _ => 'Unentschieden', }; return Column( mainAxisSize: MainAxisSize.min, children: [ Text(text, style: const TextStyle(fontSize: 26, fontWeight: FontWeight.w800)), const SizedBox(height: 12), FilledButton.icon( onPressed: onRestart, icon: const Icon(Icons.refresh), label: const Text('Neuer Match'), ), ], ); } }