Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FactionRequestUIComponent.c
Go to the documentation of this file.
1
6{
7 [Attribute("FactionList", desc: "Container for available factions' buttons")]
8 protected string m_sFactionList;
10
11 [Attribute("NoFactions")]
12 protected string m_sNoFactions;
14
15 [Attribute("{8A77FAE1C3B1F827}UI/layouts/Menus/DeployMenu/FactionButton.layout", desc: "Layout for faction button, has to have SCR_FactionButton attached to it.")]
17
18 protected ref array<SCR_FactionButton> m_aActiveFactionButtons = {};
19
22
24
25 //------------------------------------------------------------------------------------------------
26 override void HandlerAttached(Widget w)
27 {
28 super.HandlerAttached(w);
29
30 m_wFactionList = w.FindAnyWidget(m_sFactionList);
31 if (!m_wFactionList)
32 return;
33
34 m_wNoFactions = w.FindAnyWidget(m_sNoFactions);
35
36 m_FactionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
38 m_FactionManager.GetOnPlayerFactionCountChanged().Insert(UpdateFactionButtons);
39
40 PlayerController pc = GetGame().GetPlayerController();
41 if (pc)
43
45 }
46
47 //------------------------------------------------------------------------------------------------
50 {
52 return;
53
54 // Clear the list
55 Widget child = m_wFactionList.GetChildren();
56 while (child)
57 {
58 Widget sibling = child.GetSibling();
59 if (SCR_FactionButton.Cast(child.FindHandler(SCR_FactionButton))) // Don't clear widgets that are not SCR_FactionButton
60 child.RemoveFromHierarchy();
61 child = sibling;
62 }
63
64 m_aButtons.Clear();
66
67 // fetch factions and create their button layouts
68 array<Faction> availableFactions = {};
69 int factionCount = m_FactionManager.GetFactionsList(availableFactions);
70
71 Faction playerFaction = m_PlyFactionAffilComp.GetAffiliatedFaction();
72 bool canChangeFaction = SCR_BaseGameMode.Cast(GetGame().GetGameMode()).IsFactionChangeAllowed();
73
74 int playableFactionCount;
75 int factionPlayerLimit = -1;
76
77 for (int i = 0; i < factionCount; ++i)
78 {
79 SCR_Faction scriptedFaction = SCR_Faction.Cast(availableFactions[i]);
80 if (!scriptedFaction)
81 continue;
82
84
85 Widget btnW = GetGame().GetWorkspace().CreateWidgets(m_sFactionButton, m_wFactionList);
86
87 SCR_FactionButton btnComp;
89 btnComp = SCR_FactionButton.Cast(btnW.FindAnyWidget("Button").FindHandler(SCR_FactionButton));
90 else
91 btnComp = SCR_FactionButton.Cast(btnW.FindHandler(SCR_FactionButton));
92
93 btnComp.SetFaction(scriptedFaction);
94 btnComp.m_OnClicked.Insert(OnButtonClicked);
95 btnComp.m_OnFocus.Insert(OnButtonFocused);
96 btnComp.m_OnMouseEnter.Insert(OnButtonFocused);
97 btnComp.m_OnMouseLeave.Insert(OnMouseLeft);
98
99 if (!canChangeFaction && playerFaction)
100 {
101 btnComp.SetShouldUnlock(playerFaction == scriptedFaction);
102 btnComp.SetEnabled(playerFaction == scriptedFaction);
103 }
104
105 factionPlayerLimit = scriptedFaction.GetPlayerLimit();
106 if (factionPlayerLimit >= 0 && scriptedFaction.GetPlayerCount() >= factionPlayerLimit)
107 {
108 btnComp.SetShouldUnlock(playerFaction == scriptedFaction);
109 btnComp.SetEnabled(playerFaction == scriptedFaction);
110 }
111
112 btnComp.SetVisible(scriptedFaction.IsPlayable() && scriptedFaction.ShowInWelcomeScreenOverride() != EOverrideWelcomeScreenFactionDisplay.NEVERSHOW , false);
113
114 if (scriptedFaction.IsPlayable())
115 {
116 m_aActiveFactionButtons.Insert(btnComp);
117 playableFactionCount++;
118 }
119
120 m_aButtons.Insert(btnComp);
121 }
122
123 if (m_wNoFactions)
124 m_wNoFactions.SetVisible(playableFactionCount == 0);
125 }
126
127 //------------------------------------------------------------------------------------------------
130 {
132 {
133 if (btn)
134 return btn;
135 }
136
137 return null;
138 }
139
140 //------------------------------------------------------------------------------------------------
142 void OnPlayerFactionAssigned(Faction assignedFaction)
143 {
144 bool canChangeFaction = SCR_BaseGameMode.Cast(GetGame().GetGameMode()).IsFactionChangeAllowed();
145
146 foreach (SCR_DeployButtonBase btn : m_aButtons)
147 {
148 SCR_FactionButton factionBtn = SCR_FactionButton.Cast(btn);
149 if (factionBtn)
150 {
151 if (!canChangeFaction)
152 {
153 bool enabled = assignedFaction == factionBtn.GetFaction();
154 factionBtn.m_OnClicked.Remove(OnButtonClicked);
155 factionBtn.SetEnabled(enabled);
156 factionBtn.SetShouldUnlock(enabled);
157 }
158
159 if (assignedFaction == factionBtn.GetFaction())
160 factionBtn.HideTooltip();
161 factionBtn.SetSelected(assignedFaction == factionBtn.GetFaction());
162 }
163 }
164 }
165
166 //------------------------------------------------------------------------------------------------
168 protected void OnPlayableFactionChanged(SCR_Faction faction, bool playable)
169 {
170 int playableFactionCount = 0;
171 foreach (SCR_DeployButtonBase btn : m_aButtons)
172 {
173 SCR_FactionButton factionBtn = SCR_FactionButton.Cast(btn);
174 if (!factionBtn)
175 continue;
176 if (factionBtn.GetFaction() == faction)
177 factionBtn.SetVisible(playable, false);
178 if (factionBtn.GetFaction().IsPlayable())
179 playableFactionCount++;
180 }
181
182 if (m_wNoFactions)
183 m_wNoFactions.SetVisible(playableFactionCount == 0);
184 }
185
186 //------------------------------------------------------------------------------------------------
188 protected void UpdateFactionButtons(Faction faction, int newCount)
189 {
190 foreach (SCR_DeployButtonBase btn : m_aButtons)
191 {
192 SCR_FactionButton factionBtn = SCR_FactionButton.Cast(btn);
193 if (factionBtn)
194 factionBtn.UpdatePlayerCount();
195 }
196 }
197
198 //------------------------------------------------------------------------------------------------
200 protected void OnButtonFocused(Widget w)
201 {
202 SCR_FactionButton factionBtn = SCR_FactionButton.Cast(w.FindHandler(SCR_FactionButton));
203 if (!factionBtn)
204 return;
205
207 factionBtn.SetTooltipAvailable(m_PlyFactionAffilComp.GetAffiliatedFaction() != factionBtn.GetFaction());
208 m_OnButtonFocused.Invoke(factionBtn.GetFaction());
209 }
210
211 //------------------------------------------------------------------------------------------------
213 protected void RequestPlayerFaction(SCR_FactionButton factionBtn)
214 {
215 if (m_PlyFactionAffilComp.GetAffiliatedFaction() == factionBtn.GetFaction())
216 {
217 GetOnFactionRequested().Invoke(m_PlyFactionAffilComp, m_FactionManager.GetFactionIndex(m_PlyFactionAffilComp.GetAffiliatedFaction()), true);
218 return;
219 }
220
221 Lock(factionBtn);
222 Faction faction = factionBtn.GetFaction();
223 m_PlyFactionAffilComp.RequestFaction(faction);
224 }
225
226 //------------------------------------------------------------------------------------------------
228 protected void OnButtonClicked(SCR_FactionButton factionBtn)
229 {
230 if (SCR_BaseGameMode.Cast(GetGame().GetGameMode()).IsFactionChangeAllowed())
231 {
232 RequestPlayerFaction(factionBtn);
233 }
234 else if (m_FactionManager)
235 {
236 SCR_Faction faction = factionBtn.GetFaction();
237 int factionIndex = m_FactionManager.GetFactionIndex(faction);
239 if (SCR_GameModeCampaign.GetInstance() && faction.GetFactionLabel() == EEditableEntityLabel.FACTION_FIA)
241 else
243
244 dialog.m_OnConfirm.Insert(OnFactionDialogConfirm);
245 }
246 }
247
248 //------------------------------------------------------------------------------------------------
256
257 //------------------------------------------------------------------------------------------------
259 {
260 array<Faction> factions = {};
261 m_FactionManager.GetFactionsList(factions);
262 m_PlyFactionAffilComp.RequestFaction(factions.GetRandomElement());
263 }
264
265 //------------------------------------------------------------------------------------------------
271 {
272 Faction faction = m_FactionManager.GetFactionByIndex(factionId);
273 foreach (SCR_DeployButtonBase btn : m_aButtons)
274 {
275 SCR_FactionButton factionBtn = SCR_FactionButton.Cast(btn);
276 if (factionBtn && factionBtn.GetFaction() == faction)
277 return factionBtn;
278 }
279
280 return null;
281 }
282
290};
291
293{
294 [Attribute("FactionName")]
295 protected string m_sFactionName;
297
298 [Attribute("PlayerCountText")]
299 protected string m_sPlayerCount;
301
302 [Attribute("PlayerIcon")]
303 protected string m_sPlayerIcon;
305
306 [Attribute("Arrow")]
307 protected string m_sArrowIcon;
309
311 protected int m_iPlayerCount;
312 protected int m_iPlayerLimit;
313
314 //------------------------------------------------------------------------------------------------
315 override void HandlerAttached(Widget w)
316 {
317 super.HandlerAttached(w);
318
319 m_wFactionName = TextWidget.Cast(w.FindAnyWidget(m_sFactionName));
320 m_wPlayerCount = TextWidget.Cast(w.FindAnyWidget(m_sPlayerCount));
321 m_wPlayerIcon = ImageWidget.Cast(w.FindAnyWidget(m_sPlayerIcon));
322 m_wArrowIcon = ImageWidget.Cast(w.FindAnyWidget(m_sArrowIcon));
323 }
324
325 //------------------------------------------------------------------------------------------------
328 {
329 m_Faction = faction;
330
331 SetFactionName(faction.GetFactionName());
332 SetImage(faction.GetFactionFlag());
333
335 }
336
337 //------------------------------------------------------------------------------------------------
340 {
341 return m_Faction;
342 }
343
344 //------------------------------------------------------------------------------------------------
347 {
348 return m_iPlayerCount;
349 }
350
351 //------------------------------------------------------------------------------------------------
354 {
355 return m_iPlayerLimit;
356 }
357
358 //------------------------------------------------------------------------------------------------
361 {
363 {
364 m_iPlayerCount = m_Faction.GetPlayerCount();
365 m_iPlayerLimit = m_Faction.GetPlayerLimit();
366 if (m_iPlayerLimit >= 0)
367 m_wPlayerCount.SetTextFormat("#AR-SupportStation_ActionFormat_ItemAmount", m_iPlayerCount, m_iPlayerLimit);
368 else
369 m_wPlayerCount.SetText(m_iPlayerCount.ToString());
370 }
371 }
372
373 //------------------------------------------------------------------------------------------------
375 void SetFactionName(string name)
376 {
377 if (m_wFactionName)
378 m_wFactionName.SetText(name);
379 }
380
381 //------------------------------------------------------------------------------------------------
383 override void SetSelected(bool selected)
384 {
385 super.SetSelected(selected);
386 if (!m_wArrowIcon)
387 return;
388
389 if (selected)
390 m_wArrowIcon.SetRotation(90);
391 else
392 m_wArrowIcon.SetRotation(270);
393 }
394};
EEditableEntityLabel
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
EOverrideWelcomeScreenFactionDisplay
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ref array< SCR_DeployButtonBase > m_aButtons
void Lock(SCR_DeployButtonBase btn)
Lock this component's buttons from processing any further requests. Unlock() should be called once yo...
override void SetSelected(bool selected)
Visually set the button selected.
int GetPlayerCount()
Get the player count of the faction.
int GetPlayerLimit()
Get the player limit of the faction.
void UpdatePlayerCount()
Update faction player count of this button.
void SetFactionName(string name)
Set faction name of this button.
override void HandlerAttached(Widget w)
SCR_Faction GetFaction()
Get this button's faction.
void SetFaction(SCR_Faction faction)
Set this button's faction.
EOverrideWelcomeScreenFactionDisplay ShowInWelcomeScreenOverride()
int GetPlayerLimit()
EEditableEntityLabel GetFactionLabel()
ResourceName GetFactionFlag()
ScriptInvoker_FactionPlayableChanged GetOnFactionPlayableChanged()
bool IsPlayable()
int GetPlayerCount()
void OnButtonClicked(SCR_FactionButton factionBtn)
Callback when player clicks the faction button.
void UpdateFactionButtons(Faction faction, int newCount)
Update all available faction buttons.
SCR_FactionButton GetFactionButton(int factionId)
SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp
void OnPlayableFactionChanged(SCR_Faction faction, bool playable)
Callback when playable factions are changed.
void ShowAvailableFactions()
Display available playable factions in the list.
ref ScriptInvoker< SCR_PlayerFactionAffiliationComponent, int, bool > m_OnFactionRequested
SCR_FactionButton GetFirstValidFactionButton()
Get the first valid Faction Button from the Faction Buttons that are currently shown in the Role Sele...
void RequestPlayerFaction(SCR_FactionButton factionBtn)
Sends a request to assign a faction.
void OnButtonFocused(Widget w)
Callback when button is focused.
void OnFactionDialogConfirm(SCR_PersistentFactionDialog dialog)
Callback when player closes the persistent faction dialog.
void OnPlayerFactionAssigned(Faction assignedFaction)
Callback when local player's faction is assigned.
ref array< SCR_FactionButton > m_aActiveFactionButtons
static SCR_PersistentFactionDialog CreatePersistentFactionDialog(int factionIndex)
static SCR_PersistentFactionDialog CreatePersistentFactionCampaignFIADialog(int factionIndex)
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134