c55ebd21b4
_maxDragPx was a fixed 260 *logical* pixels. On the test device (1080x2400 at 440 dpi) that is 715 physical pixels - a swipe across two thirds of the screen, which ends at the edge before full power is reached. Players could not hit 100 %. - the pull distance is now relative to the playfield: 30 % of its short edge, at least 80 logical px (~325 physical px here) - verified on the device: a 340 px swipe reaches "MAX" and fires, a 149 px swipe reaches 46 % - the HUD now prints MAX instead of 100 % and highlights it, so reaching full power is unmistakable - a tap without a real pull no longer fires: _dragged guards releaseAim, so a stray touch cannot waste a turn (verified: tap leaves the turn unchanged) - release 0.9.2 (15)
345 lines
9.8 KiB
Dart
345 lines
9.8 KiB
Dart
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: 10),
|
|
Icon(Icons.straighten,
|
|
size: 14, color: const Color(0xFFA9B4C4)),
|
|
const SizedBox(width: 3),
|
|
Text('${hud.aimAngle.round()}°',
|
|
style: const TextStyle(fontSize: 13)),
|
|
],
|
|
),
|
|
// Power is the value players fight with - show it as a number
|
|
// *and* as a bar, not only through the size of the aim dots.
|
|
const SizedBox(height: 3),
|
|
_PowerMeter(power: hud.aimPower),
|
|
],
|
|
),
|
|
),
|
|
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,
|
|
this.compact = false,
|
|
});
|
|
|
|
final MatchSession session;
|
|
final VoidCallback onOnline;
|
|
final VoidCallback onReplay;
|
|
final VoidCallback onFlush;
|
|
final VoidCallback onAd;
|
|
|
|
/// Landscape: the play area is short, so the controls lose their padding.
|
|
final bool compact;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
_Action(
|
|
icon: Icons.wifi_tethering,
|
|
label: 'Online',
|
|
onTap: onOnline,
|
|
compact: compact),
|
|
_Action(
|
|
icon: Icons.replay,
|
|
label: 'Replay',
|
|
onTap: onReplay,
|
|
compact: compact),
|
|
_Action(
|
|
icon: Icons.cloud_upload,
|
|
label: session.queued > 0 ? 'Senden (${session.queued})' : 'Senden',
|
|
onTap: onFlush,
|
|
compact: compact,
|
|
),
|
|
_Action(
|
|
icon: Icons.ondemand_video,
|
|
label: 'Ad',
|
|
onTap: onAd,
|
|
compact: compact),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Action extends StatelessWidget {
|
|
const _Action({
|
|
required this.icon,
|
|
required this.label,
|
|
required this.onTap,
|
|
this.compact = false,
|
|
});
|
|
|
|
final IconData icon;
|
|
final String label;
|
|
final VoidCallback onTap;
|
|
final bool compact;
|
|
|
|
@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: EdgeInsets.symmetric(
|
|
horizontal: compact ? 10 : 14, vertical: compact ? 6 : 12),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, size: compact ? 16 : 18),
|
|
SizedBox(width: compact ? 4 : 6),
|
|
Text(label, style: TextStyle(fontSize: compact ? 12 : 13)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Slim power bar with a percentage label, shared by the HUD.
|
|
class _PowerMeter extends StatelessWidget {
|
|
const _PowerMeter({required this.power});
|
|
|
|
final double power;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final pct = (power.clamp(0.0, 1.0) * 100).round();
|
|
final color = pct < 50
|
|
? const Color(0xFFFFB347)
|
|
: pct < 85
|
|
? const Color(0xFFFF8A3D)
|
|
: const Color(0xFFFF5A5F);
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(Icons.bolt, size: 14, color: Color(0xFFA9B4C4)),
|
|
const SizedBox(width: 3),
|
|
SizedBox(
|
|
width: 74,
|
|
height: 6,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(3),
|
|
child: LinearProgressIndicator(
|
|
value: power.clamp(0.0, 1.0),
|
|
minHeight: 6,
|
|
color: color,
|
|
backgroundColor: const Color(0xFF1B2C44),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 5),
|
|
SizedBox(
|
|
width: 38,
|
|
// „MAX" is worth a word: the bar alone made it hard to tell whether
|
|
// full power had been reached.
|
|
child: Text(pct >= 99 ? 'MAX' : '$pct %',
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: pct >= 99 ? FontWeight.w700 : FontWeight.w400,
|
|
color: pct >= 99 ? const Color(0xFFFF5A5F) : null,
|
|
)),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
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…'
|
|
: 'Zurückziehen zum Spannen · 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'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|