Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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))]
6  protected EEditableEntityState m_States;
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))]
12  protected ShapeFlags m_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 
17  //------------------------------------------------------------------------------------------------
18  protected void OnMenuUpdate(float timeSlice)
19  {
20  SCR_EditableEntityComponent child, prevWaypoint;
21  SCR_EditableWaypointComponent waypoint;
22  vector points[2];
23  vector pos1, pos2;
24  foreach (SCR_EditableEntityComponent group, int groupTokens : m_Groups)
25  {
26  if (!group)
27  continue;
28 
29  for (int i = 0, count = group.GetChildrenCount(true); i < count; i++)
30  {
31  child = group.GetChild(i);
32  if (child.GetEntityType() != EEditableEntityType.WAYPOINT)
33  continue;
34 
35  waypoint = SCR_EditableWaypointComponent.Cast(child);
36  prevWaypoint = waypoint.GetPrevWaypoint();
37 
38  if (!waypoint.GetPos(pos1) || !prevWaypoint.GetPos(pos2))
39  continue;
40 
41  points = {pos1, pos2};
42  Shape.CreateLines(m_iLineColorPacked, m_ShapeFlags, points, 2);
43  }
44 
45  }
46 
47 #ifdef WAYPOINT_LINES_DEBUG
48  DbgUI.Begin("");
49  DbgUI.Text(m_Groups.Count().ToString());
50  DbgUI.End();
51 #endif
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  protected void OnChanged(EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
56  {
57 #ifdef WAYPOINT_LINES_DEBUG
58  string stateName = typename.EnumToString(EEditableEntityState, state);
59 #endif
60 
61  if (entitiesRemove)
62  {
64  int groupTokens;
65  foreach (SCR_EditableEntityComponent entity: entitiesRemove)
66  {
67  group = entity.GetAIGroup();
68  if (!group)
69  continue;
70 
71  groupTokens = 0;
72  if (!m_Groups.Find(group, groupTokens))
73  continue;
74 
75  groupTokens--;
76  if (groupTokens == 0)
77  m_Groups.Remove(group);
78  else
79  m_Groups.Set(group, groupTokens);
80 
81 #ifdef WAYPOINT_LINES_DEBUG
82  entity.Log(stateName + ": " + groupTokens.ToString(), true, LogLevel.WARNING);
83 #endif
84  }
85  }
86 
87  if (entitiesInsert)
88  {
90  int groupTokens;
91  foreach (SCR_EditableEntityComponent entity: entitiesInsert)
92  {
93  group = entity.GetAIGroup();
94  if (!group)
95  continue;
96 
97  groupTokens = 0;
98  m_Groups.Find(group, groupTokens);
99 
100  groupTokens++;
101  m_Groups.Set(group, groupTokens);
102 
103 #ifdef WAYPOINT_LINES_DEBUG
104  entity.Log(stateName + ": " + groupTokens.ToString(), true);
105 #endif
106  }
107  }
108  }
109 
110  //------------------------------------------------------------------------------------------------
111  override void HandlerAttachedScripted(Widget w)
112  {
114  if (!entitiesManager)
115  return;
116 
117  m_iLineColorPacked = m_LineColor.PackToInt();
118 
119  EEditableEntityState state;
121  set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
122  array<int> states = {};
123  for (int i = 0, count = SCR_Enum.BitToIntArray(m_States, states); i < count; i++)
124  {
125  state = states[i];
126  filter = entitiesManager.GetFilter(state);
127  if (!filter)
128  continue;
129 
130  filter.GetEntities(entities);
131  filter.GetOnChanged().Insert(OnChanged);
132  OnChanged(state, entities, null);
133  }
134 
135  MenuRootBase menu = GetMenu();
136  if (menu)
137  menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  override void HandlerDeattached(Widget w)
142  {
144  if (!entitiesManager)
145  return;
146 
147  EEditableEntityState state;
149  array<int> states = {};
150  for (int i = 0, count = SCR_Enum.BitToIntArray(m_States, states); i < count; i++)
151  {
152  state = states[i];
153  filter = entitiesManager.GetFilter(state);
154  if (!filter)
155  continue;
156 
157  filter.GetOnChanged().Remove(OnChanged);
158  }
159 
160  MenuRootBase menu = GetMenu();
161  if (menu)
162  menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
163  }
164 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
SCR_Enum
Definition: SCR_Enum.c:1
SCR_WaypointLinesEditorUIComponent
Definition: SCR_WaypointLinesEditorUIComponent.c:3
SCR_EntitiesManagerEditorComponent
Definition: SCR_EntitiesManagerEditorComponent.c:13
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
Attribute
typedef Attribute
Post-process effect of scripted camera.
MenuRootBase
Definition: MenuRootBase.c:6
EEditableEntityType
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
Definition: EEditableEntityType.c:5
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3