@@ -4,6 +4,7 @@ import 'package:flame/collisions.dart';
44import 'package:flame/components.dart' ;
55import 'package:flame/effects.dart' ;
66import 'package:flame/events.dart' ;
7+ import 'package:flame/text.dart' ;
78import 'package:flame_bloc/flame_bloc.dart' ;
89import 'package:flutter/material.dart' ;
910import 'package:flutter_bloc/flutter_bloc.dart' ;
@@ -38,6 +39,7 @@ class GameCell extends PositionComponent
3839 ScrollCallbacks {
3940 late final SpriteComponent _selectionComponent;
4041 SpriteComponent ? _cardComponent, _boardComponent;
42+ TextElementComponent ? _waypointComponent;
4143 late final BoardGrid grid;
4244 List <Effect >? _effects;
4345
@@ -61,6 +63,66 @@ class GameCell extends PositionComponent
6163 }
6264 }
6365
66+ void _buildWaypointComponent (ClientWorldState state) {
67+ final visible = state.showWaypoints;
68+ _waypointComponent? .removeFromParent ();
69+ _waypointComponent = null ;
70+ if (! visible) {
71+ return ;
72+ }
73+ final global = toGlobalDefinition (state);
74+ final globalWaypoints = state.info.waypoints
75+ .where ((waypoint) => waypoint.position == global)
76+ .map <InlineTextNode >((e) => PlainTextNode (e.name))
77+ .toList ();
78+ final teamWaypoints = state.world.getTeams ().expand ((name) {
79+ final team = state.info.teams[name];
80+ if (team == null ) return Iterable <InlineTextNode >.empty ();
81+ return team.waypoints
82+ .where ((waypoint) => waypoint.position == global)
83+ .map <InlineTextNode >(
84+ (e) => CustomInlineTextNode (
85+ PlainTextNode (e.name),
86+ styleName: 'team-$name ' ,
87+ ),
88+ );
89+ }).toList ();
90+ if (globalWaypoints.isEmpty && teamWaypoints.isEmpty) {
91+ return ;
92+ }
93+ final blocks = < BlockNode > [
94+ ParagraphNode .group (globalWaypoints),
95+ ParagraphNode .group (teamWaypoints),
96+ ];
97+ final document = DocumentRoot (blocks);
98+ final component = _waypointComponent = TextElementComponent .fromDocument (
99+ document: document,
100+ size: size,
101+ priority: 2 ,
102+ style: DocumentStyle (
103+ paragraph: BlockStyle (textAlign: TextAlign .center),
104+ customStyles: {
105+ for (final entry in state.world.getTeams ())
106+ 'team-$entry ' : InlineTextStyle (
107+ color:
108+ state.info.teams[entry]? .color? .color ??
109+ state.colorScheme.primary,
110+ ),
111+ },
112+ text: InlineTextStyle (
113+ shadows: [
114+ Shadow (
115+ color: Colors .black,
116+ offset: const Offset (0 , 0 ),
117+ blurRadius: 2 ,
118+ ),
119+ ],
120+ ),
121+ ),
122+ );
123+ add (component);
124+ }
125+
64126 @override
65127 void onLoad () {
66128 super .onLoad ();
@@ -82,7 +144,8 @@ class GameCell extends PositionComponent
82144 previousState.table.cells[definition] !=
83145 newState.table.cells[definition] ||
84146 previousState.teamMembers != newState.teamMembers ||
85- previousState.colorScheme != newState.colorScheme;
147+ previousState.colorScheme != newState.colorScheme ||
148+ previousState.showWaypoints != newState.showWaypoints;
86149 }
87150
88151 bool get isSelected => isMounted && bloc.state.selectedCell == toDefinition ();
@@ -134,6 +197,7 @@ class GameCell extends PositionComponent
134197 @override
135198 void onInitialState (ClientWorldState state) {
136199 if (state.selectedCell != toDefinition ()) _selectionComponent.opacity = 0 ;
200+ _buildWaypointComponent (state);
137201 }
138202
139203 bool isClaimed (ClientWorldState state) => state.info.teams.entries.any (
@@ -178,6 +242,7 @@ class GameCell extends PositionComponent
178242 ),
179243 ]);
180244 }
245+ _buildWaypointComponent (state);
181246 }
182247
183248 Future <void > _updateTop () async {
0 commit comments