Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScenarioPanelEditorUIComponent .c
Go to the documentation of this file.
1 class SCR_ScenarioPanelEditorUIComponent : ScriptedWidgetComponent
2 {
3  [Attribute("ToolbarBackgroundOverlay")]
4  protected string m_sFullWindowName;
5 
6  [Attribute("ConfigureScenarioButton")]
7  protected string m_sButtonOnlyName;
8 
9  protected Widget m_wRoot;
10 
11  protected bool m_bListeningToEvents;
12 
13  //------------------------------------------------------------------------------------------------
14  //Show/hide full UI
15  protected void ShowButtonOrFullWindow(bool showFullWindow)
16  {
17  Widget fullWindow = m_wRoot.FindAnyWidget(m_sFullWindowName);
18  Widget buttonOnly = m_wRoot.FindAnyWidget(m_sButtonOnlyName);
19 
20  if (!fullWindow || !buttonOnly)
21  return;
22 
23  fullWindow.SetVisible(showFullWindow);
24  buttonOnly.SetVisible(!showFullWindow);
25  }
26 
27  //------------------------------------------------------------------------------------------------
28  //When an attribute has been changed
29  protected void OnAttributeChanges()
30  {
31  StopListeningToEvents();
32  ShowButtonOrFullWindow(true);
33  }
34 
35  //------------------------------------------------------------------------------------------------
36  protected void OnPlayerSpawned(int playerID, SCR_EditableEntityComponent entity, SCR_EditableEntityComponent prevEntity)
37  {
39  if (!editorPlayerManager || !editorPlayerManager.HasLocalPlayerSpawnedOnce())
40  return;
41 
42  StopListeningToEvents();
43  ShowButtonOrFullWindow(true);
44  }
45 
46  //------------------------------------------------------------------------------------------------
47  //When faction is set playable
48  protected void OnFactionSetPlayable(SCR_Faction faction, bool playable)
49  {
50  if (!playable)
51  return;
52 
53  StopListeningToEvents();
54  ShowButtonOrFullWindow(true);
55  }
56 
57  //------------------------------------------------------------------------------------------------
58  //Remove all event listeners
59  protected void StopListeningToEvents()
60  {
61  if (!m_bListeningToEvents)
62  return;
63 
64  m_bListeningToEvents = false;
65 
66  //Remove on faction set playable listener
67  SCR_DelegateFactionManagerComponent delegateFactionManager = SCR_DelegateFactionManagerComponent.GetInstance();
68  if (delegateFactionManager)
69  {
70  map<Faction, SCR_EditableFactionComponent> delegates = new map<Faction, SCR_EditableFactionComponent>();
71  delegateFactionManager.GetFactionDelegates(delegates);
72  SCR_Faction scrFaction;
73 
74  foreach (Faction f, SCR_EditableFactionComponent d : delegates)
75  {
76  scrFaction = SCR_Faction.Cast(f);
77 
78  if (!scrFaction)
79  continue;
80 
81  scrFaction.GetOnFactionPlayableChanged().Remove(OnFactionSetPlayable);
82  }
83  }
84 
85  //Remove on attribute changes listener
86  SCR_AttributesManagerEditorComponent attributeManager = SCR_AttributesManagerEditorComponent.Cast(SCR_AttributesManagerEditorComponent.GetInstance(SCR_AttributesManagerEditorComponent));
87  if (attributeManager)
88  attributeManager.GetOnAttributeChangesApplied().Remove(OnAttributeChanges);
89 
90  //Remove on local player spawned listener
92  if (editorPlayerManager)
93  editorPlayerManager.GetOnSpawn().Remove(OnPlayerSpawned);
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  override void HandlerAttached(Widget w)
98  {
99  //Are there any playable factions
100  SCR_DelegateFactionManagerComponent delegateFactionManager = SCR_DelegateFactionManagerComponent.GetInstance();
101  if (!delegateFactionManager|| delegateFactionManager.GetPlayableFactionDelegateCount() > 0)
102  return;
103 
104  //Has attribute been changed yet
105  SCR_AttributesManagerEditorComponent attributeManager = SCR_AttributesManagerEditorComponent.Cast(SCR_AttributesManagerEditorComponent.GetInstance(SCR_AttributesManagerEditorComponent, true));
106  if (!attributeManager || attributeManager.GetChangedAttributesOnce())
107  return;
108 
109  //Local player has spawned yet
111  if (!editorPlayerManager || editorPlayerManager.HasLocalPlayerSpawnedOnce())
112  return;
113 
114  m_wRoot = w;
115 
116  //Show button only
117  ShowButtonOrFullWindow(false);
118 
119  //Listen to events
120  m_bListeningToEvents = true;
121 
122  //On faction set playable listener
123  map<Faction, SCR_EditableFactionComponent> delegates = new map<Faction, SCR_EditableFactionComponent>();
124  delegateFactionManager.GetFactionDelegates(delegates);
125  SCR_Faction scrFaction;
126 
127  foreach (Faction f, SCR_EditableFactionComponent d : delegates)
128  {
129  scrFaction = SCR_Faction.Cast(f);
130 
131  if (!scrFaction)
132  continue;
133 
134  scrFaction.GetOnFactionPlayableChanged().Insert(OnFactionSetPlayable);
135  }
136 
137  //On attribute changes listener
138  attributeManager.GetOnAttributeChangesApplied().Insert(OnAttributeChanges);
139 
140  //On local player spawned listener
141  if (editorPlayerManager)
142  editorPlayerManager.GetOnSpawn().Insert(OnPlayerSpawned);
143  }
144 
145  //------------------------------------------------------------------------------------------------
146  override void HandlerDeattached(Widget w)
147  {
148  StopListeningToEvents();
149  }
150 }
SCR_PlayersManagerEditorComponent
Definition: SCR_PlayersManagerEditorComponent.c:9
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_ScenarioPanelEditorUIComponent
Definition: SCR_ScenarioPanelEditorUIComponent .c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
Faction
Definition: Faction.c:12
SCR_DelegateFactionManagerComponent
Definition: SCR_DelegateFactionManagerComponent.c:15
SCR_Faction
Definition: SCR_Faction.c:6