@@ -4,6 +4,7 @@ import 'package:flame/collisions.dart';
4
4
import 'package:flame/components.dart' ;
5
5
import 'package:flame/effects.dart' ;
6
6
import 'package:flame/events.dart' ;
7
+ import 'package:flame/text.dart' ;
7
8
import 'package:flame_bloc/flame_bloc.dart' ;
8
9
import 'package:flutter/material.dart' ;
9
10
import 'package:flutter_bloc/flutter_bloc.dart' ;
@@ -38,6 +39,7 @@ class GameCell extends PositionComponent
38
39
ScrollCallbacks {
39
40
late final SpriteComponent _selectionComponent;
40
41
SpriteComponent ? _cardComponent, _boardComponent;
42
+ TextElementComponent ? _waypointComponent;
41
43
late final BoardGrid grid;
42
44
List <Effect >? _effects;
43
45
@@ -61,6 +63,66 @@ class GameCell extends PositionComponent
61
63
}
62
64
}
63
65
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
+
64
126
@override
65
127
void onLoad () {
66
128
super .onLoad ();
@@ -82,7 +144,8 @@ class GameCell extends PositionComponent
82
144
previousState.table.cells[definition] !=
83
145
newState.table.cells[definition] ||
84
146
previousState.teamMembers != newState.teamMembers ||
85
- previousState.colorScheme != newState.colorScheme;
147
+ previousState.colorScheme != newState.colorScheme ||
148
+ previousState.showWaypoints != newState.showWaypoints;
86
149
}
87
150
88
151
bool get isSelected => isMounted && bloc.state.selectedCell == toDefinition ();
@@ -134,6 +197,7 @@ class GameCell extends PositionComponent
134
197
@override
135
198
void onInitialState (ClientWorldState state) {
136
199
if (state.selectedCell != toDefinition ()) _selectionComponent.opacity = 0 ;
200
+ _buildWaypointComponent (state);
137
201
}
138
202
139
203
bool isClaimed (ClientWorldState state) => state.info.teams.entries.any (
@@ -178,6 +242,7 @@ class GameCell extends PositionComponent
178
242
),
179
243
]);
180
244
}
245
+ _buildWaypointComponent (state);
181
246
}
182
247
183
248
Future <void > _updateTop () async {
0 commit comments