Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditableEntityBaseSlotUIComponent.c
Go to the documentation of this file.
1 
6 class SCR_EditableEntityBaseSlotUIComponent : ScriptedWidgetComponent
7 {
8  protected Widget m_Widget;
9  protected SCR_EditableEntityComponent m_Entity;
10  protected ref map<SCR_EntitiesEditorUIRule, SCR_BaseEditableEntityUIComponent> m_EntityWidgets = new map<SCR_EntitiesEditorUIRule, SCR_BaseEditableEntityUIComponent>();
11 
12  //------------------------------------------------------------------------------------------------
15  bool IsEmpty()
16  {
17  return m_EntityWidgets.IsEmpty();
18  }
19 
20  //------------------------------------------------------------------------------------------------
23  SCR_EditableEntityComponent GetEntity()
24  {
25  return m_Entity;
26  }
27 
28  //------------------------------------------------------------------------------------------------
33  Widget CreateWidget(SCR_EditableEntityUIInfo info, SCR_EntitiesEditorUIRule rule)
34  {
35  ResourceName layout = rule.GetLayout(info.GetEntityType());
36  SCR_BaseEditableEntityUIComponent entityUI = CreateWidgetFromLayout(layout);
37  entityUI.Init(info, this);
38  return entityUI.GetWidget();
39  }
40 
41  //------------------------------------------------------------------------------------------------
47  Widget CreateWidget(SCR_EditableEntityComponent entity, SCR_EntitiesEditorUIRule rule)
48  {
49  ResourceName layout = rule.GetLayout(entity.GetEntityType());
50 
51  return CreateWidgetForEntity(entity, rule, layout);
52  }
53 
54  //------------------------------------------------------------------------------------------------
60  Widget CreateWidget(SCR_EditableEntityComponent entity, ResourceName layout)
61  {
62  return CreateWidgetForEntity(entity, null, layout);
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  protected Widget CreateWidgetForEntity(SCR_EditableEntityComponent entity, SCR_EntitiesEditorUIRule rule, ResourceName layout)
67  {
68  //--- There is already a widget for this rule, ignore
69  if (m_EntityWidgets.Contains(rule))
70  return null;
71 
72  if (!layout)
73  return null;
74 
75  SCR_BaseEditableEntityUIComponent entityUI = CreateWidgetFromLayout(layout);
76  entityUI.Init(entity, this);
77  m_EntityWidgets.Insert(rule, entityUI);
78 
79  return entityUI.GetWidget();
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  protected SCR_BaseEditableEntityUIComponent CreateWidgetFromLayout(ResourceName layout)
84  {
85  Widget entityWidget = GetGame().GetWorkspace().CreateWidgets(layout, m_Widget);
86  if (!entityWidget)
87  {
88  Debug.Error2(Type().ToString(), string.Format("Unable to create widget '%1'!\n", layout));
89  return null;
90  }
91 
92  //--- Get UI component
94  if (!entityUI)
95  {
96  Debug.Error2(Type().ToString(), string.Format("SCR_BaseEditableEntityUIComponent component is missing in the root widget of '%1'!\n", layout));
97  if (entityWidget)
98  entityWidget.RemoveFromHierarchy();
99 
100  return null;
101  }
102  return entityUI;
103  }
104 
105  //------------------------------------------------------------------------------------------------
108  void DeleteWidget(SCR_EntitiesEditorUIRule rule)
109  {
111  if (!m_EntityWidgets.Find(rule, entityUI))
112  return;
113 
114  entityUI.Exit(this);
115  m_EntityWidgets.Remove(rule);
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  protected void SetFactionColor()
120  {
121  if (!m_Entity)
122  {
123  GetWidget().SetColor(UIColors.EDITOR_ICON_COLOR_NEUTRAL);
124  return;
125  }
126 
127  Faction faction = m_Entity.GetFaction();
128  if (faction)
129  GetWidget().SetColor(faction.GetFactionColor());
130  else if (m_Entity.HasEntityState(EEditableEntityState.DESTROYED))
131  GetWidget().SetColor(UIColors.EDITOR_ICON_COLOR_DESTROYED);
132  else
133  GetWidget().SetColor(UIColors.EDITOR_ICON_COLOR_NEUTRAL);
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  protected void RefreshSlot()
138  {
139  foreach (SCR_EntitiesEditorUIRule rule, SCR_BaseEditableEntityUIComponent entityUI: m_EntityWidgets)
140  {
141  entityUI.OnRefresh(this);
142  }
143 
144  GetGame().GetCallqueue().CallLater(SetFactionColor);
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  protected void ResetSlot()
149  {
150  foreach (SCR_EntitiesEditorUIRule rule, SCR_BaseEditableEntityUIComponent entityUI: m_EntityWidgets)
151  {
152  DeleteWidget(rule);
153  CreateWidget(m_Entity, rule);
154  }
155 
156  GetGame().GetCallqueue().CallLater(SetFactionColor);
157  }
158 
159  //------------------------------------------------------------------------------------------------
166  vector UpdateSlot(int screenW, int screenH, vector posCenter, vector posCam)
167  {
168  return vector.Zero;
169  }
170 
171  //------------------------------------------------------------------------------------------------
174  void InitSlot(SCR_EditableEntityComponent entity)
175  {
176  if (!entity || !entity.GetOwner())
177  return;
178 
179  m_Entity = entity;
180 
181  //--- Initialise faction color (set on the slot, child widgets inherit from it, so they don't need to set it individually)
182  if (entity.HasEntityFlag(EEditableEntityFlag.HAS_FACTION))
183  SetFactionColor();
184 
185  if (entity.GetOnUIRefresh())
186  entity.GetOnUIRefresh().Insert(RefreshSlot);
187 
188  if (entity.GetOnUIReset())
189  entity.GetOnUIReset().Insert(ResetSlot);
190  }
191 
192  //------------------------------------------------------------------------------------------------
194  void DeleteSlot()
195  {
196  if (m_Widget)
197  {
198  m_Widget.RemoveFromHierarchy();
199  m_Widget = null;
200  }
201 
202  if (m_Entity)
203  {
204  if (m_Entity.GetOnUIRefresh())
205  m_Entity.GetOnUIRefresh().Remove(RefreshSlot);
206 
207  if (m_Entity.GetOnUIReset())
208  m_Entity.GetOnUIReset().Remove(ResetSlot);
209  }
210  }
211 
212  //------------------------------------------------------------------------------------------------
215  bool IsPreview()
216  {
217  return false;
218  }
219 
220  //------------------------------------------------------------------------------------------------
222  Widget GetWidget()
223  {
224  return m_Widget;
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  override void HandlerAttached(Widget w)
229  {
230  m_Widget = w;
231  }
232 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
EEditableEntityFlag
EEditableEntityFlag
Unique flags of the entity.
Definition: EEditableEntityFlag.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EditableEntityUIInfo
Definition: SCR_EditableEntityUIInfo.c:2
SCR_EntitiesEditorUIRule
Definition: SCR_EditableEntityUIRule.c:8
SCR_EditableEntityBaseSlotUIComponent
Definition: SCR_EditableEntityBaseSlotUIComponent.c:6
m_Entity
enum EAITargetInfoCategory m_Entity
UIColors
Definition: Constants.c:16
SCR_BaseEditableEntityUIComponent
Definition: SCR_BaseEditableEntityUIComponent.c:8
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
layout
UI layouts HUD CampaignMP CampaignMainHUD layout
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:20
Faction
Definition: Faction.c:12