Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WaypointLinesEditorUIComponent.c
Go to the documentation of this file.
1//#define WAYPOINT_LINES_DEBUG
2
4{
5 [Attribute(desc: "Show waypoint lines when a group or a waypoint has one of these states.", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(EEditableEntityState))]
7
8 [Attribute(desc: "Color of lines", defvalue: "0 0 0 1")]
9 protected ref Color m_LineColor;
10
11 [Attribute(defvalue: string.Format("%1", ShapeFlags.VISIBLE | ShapeFlags.NOZBUFFER | ShapeFlags.ONCE), desc: "Shape flags of lines.", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(ShapeFlags))]
13
14 protected ref map<SCR_EditableEntityComponent, int> m_Groups = new map<SCR_EditableEntityComponent, int>(); //--- ToDo: Save entities in an array if tokens prove to be unreliable
15 protected int m_iLineColorPacked;
16
18 protected ref array<ref CanvasWidgetCommand> m_aDrawCommands;
19
20 //------------------------------------------------------------------------------------------------
21 protected void OnMenuUpdate(float timeSlice)
22 {
23 if (m_wCanvas)
24 m_aDrawCommands.Clear();
25
26 WorkspaceWidget workspace = GetGame().GetWorkspace();
27 BaseWorld world = GetGame().GetWorld();
28 SCR_EditableEntityComponent child, prevChild;
31 LineDrawCommand line;
32
33 vector points[2];
34 vector pos1, pos2, pos3;
35 foreach (SCR_EditableEntityComponent group, int groupTokens : m_Groups)
36 {
37 if (!group)
38 continue;
39
40 for (int i = 0, count = group.GetChildrenCount(true); i < count; i++)
41 {
42 child = group.GetChild(i);
43 if (!child || child.GetEntityType() != EEditableEntityType.WAYPOINT)
44 continue;
45
46 waypoint = SCR_EditableWaypointComponent.Cast(child);
47 prevChild = waypoint.GetPrevWaypoint();
48
49 if (!waypoint.GetPos(pos1) || !prevChild.GetPos(pos2))
50 continue;
51
52 points = {pos1, pos2};
53 Shape.CreateLines(m_iLineColorPacked, m_ShapeFlags, points, 2);
54
55 if (!m_wCanvas)
56 continue;
57
58 //++ If current waypoint is the active waypoint of the AIGroup
59 //++ And cycle waypoints are enabled, draw an arrow between both
60 prevGroup = SCR_EditableGroupComponent.Cast(waypoint.GetAIGroup());
61 if (prevGroup && prevGroup.AreCycledWaypointsEnabled() && waypoint.GetAIWaypoint() == prevGroup.GetAIGroupComponent().GetCurrentWaypoint() && prevGroup.GetPos(pos3))
62 {
63 //++ Calculate screen position of points
64 vector x0 = workspace.ProjWorldToScreenNative(pos1, world);
65 vector x1 = workspace.GetWorkspace().ProjWorldToScreenNative(pos3, world);
66
67 //++ Create draw command
68 line = new LineDrawCommand();
69 line.m_iColor = m_iLineColorPacked;
70 line.m_fOutlineWidth = 0;
71 line.m_fWidth = 2;
72 line.m_Vertices = { x0[0], x0[1], x1[0], x1[1] };
73
74 //++ Insert into pool of draw commands
75 m_aDrawCommands.Insert(line);
76 }
77 }
78 }
79
80 if (m_wCanvas)
81 m_wCanvas.SetDrawCommands(m_aDrawCommands);
82
83#ifdef WAYPOINT_LINES_DEBUG
84 DbgUI.Begin("");
85 DbgUI.Text(m_Groups.Count().ToString());
86 DbgUI.End();
87#endif
88 }
89
90 //------------------------------------------------------------------------------------------------
91 protected void OnChanged(EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
92 {
93#ifdef WAYPOINT_LINES_DEBUG
94 string stateName = typename.EnumToString(EEditableEntityState, state);
95#endif
96
97 if (entitiesRemove)
98 {
100 int groupTokens;
101 foreach (SCR_EditableEntityComponent entity: entitiesRemove)
102 {
103 group = entity.GetAIGroup();
104 if (!group)
105 continue;
106
107 groupTokens = 0;
108 if (!m_Groups.Find(group, groupTokens))
109 continue;
110
111 groupTokens--;
112 if (groupTokens == 0)
113 m_Groups.Remove(group);
114 else
115 m_Groups.Set(group, groupTokens);
116
117#ifdef WAYPOINT_LINES_DEBUG
118 entity.Log(stateName + ": " + groupTokens.ToString(), true, LogLevel.WARNING);
119#endif
120 }
121 }
122
123 if (entitiesInsert)
124 {
126 int groupTokens;
127 foreach (SCR_EditableEntityComponent entity: entitiesInsert)
128 {
129 group = entity.GetAIGroup();
130 if (!group)
131 continue;
132
133 groupTokens = 0;
134 m_Groups.Find(group, groupTokens);
135
136 groupTokens++;
137 m_Groups.Set(group, groupTokens);
138
139#ifdef WAYPOINT_LINES_DEBUG
140 entity.Log(stateName + ": " + groupTokens.ToString(), true);
141#endif
142 }
143 }
144 }
145
146 //------------------------------------------------------------------------------------------------
148 {
150 if (!entitiesManager)
151 return;
152
153 m_iLineColorPacked = m_LineColor.PackToInt();
154
157 set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
158 array<int> states = {};
159 for (int i = 0, count = SCR_Enum.BitToIntArray(m_States, states); i < count; i++)
160 {
161 state = states[i];
162 filter = entitiesManager.GetFilter(state);
163 if (!filter)
164 continue;
165
166 filter.GetEntities(entities);
167 filter.GetOnChanged().Insert(OnChanged);
168 OnChanged(state, entities, null);
169 }
170
171 MenuRootBase menu = GetMenu();
172 if (menu)
173 menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
174
175 m_wCanvas = CanvasWidget.Cast(GetGame().GetWorkspace().FindAnyWidget("m_wCanvas"));
176 m_aDrawCommands = {};
177 }
178
179 //------------------------------------------------------------------------------------------------
180 override void HandlerDeattached(Widget w)
181 {
183 if (!entitiesManager)
184 return;
185
188 array<int> states = {};
189 for (int i = 0, count = SCR_Enum.BitToIntArray(m_States, states); i < count; i++)
190 {
191 state = states[i];
192 filter = entitiesManager.GetFilter(state);
193 if (!filter)
194 continue;
195
196 filter.GetOnChanged().Remove(OnChanged);
197 }
198
199 MenuRootBase menu = GetMenu();
200 if (menu)
201 menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
202 }
203}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_EditableGroupComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_EditableWaypointComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_RadialMenu GetMenu()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Color.c:13
Definition DbgUI.c:66
ScriptInvoker GetOnMenuUpdate()
ScriptInvokerBase< SCR_BaseEditableEntityFilter_OnChange > GetOnChanged()
int GetEntities(out set< SCR_EditableEntityComponent > entities, bool includeChildren=false, bool evaluate=true)
SCR_EditableEntityComponent GetChild(int index)
EEditableEntityType GetEntityType(IEntity owner=null)
int GetChildrenCount(bool onlyDirect=false)
SCR_EditableEntityComponent GetAIGroup()
SCR_BaseEditableEntityFilter GetFilter(EEditableEntityState state, bool showError=false)
void OnChanged(EEditableEntityState state, set< SCR_EditableEntityComponent > entitiesInsert, set< SCR_EditableEntityComponent > entitiesRemove)
ref array< ref CanvasWidgetCommand > m_aDrawCommands
ref map< SCR_EditableEntityComponent, int > m_Groups
Instance of created debug visualizer.
Definition Shape.c:14
Definition Types.c:486
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
ShapeFlags
Definition ShapeFlags.c:13
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
EEditableEntityState
SCR_FieldOfViewSettings Attribute