7 [
Attribute(
"FactionList",
desc:
"Container for available factions' buttons")]
8 protected string m_sFactionList;
9 protected Widget m_wFactionList;
12 protected string m_sNoFactions;
13 protected Widget m_wNoFactions;
15 [
Attribute(
"{8A77FAE1C3B1F827}UI/layouts/Menus/DeployMenu/FactionButton.layout",
desc:
"Layout for faction button, has to have SCR_FactionButton attached to it.")]
16 protected ResourceName m_sFactionButton;
21 protected ref ScriptInvoker<SCR_PlayerFactionAffiliationComponent, int, bool> m_OnFactionRequested;
24 override void HandlerAttached(Widget w)
26 super.HandlerAttached(w);
28 m_wFactionList = w.FindAnyWidget(m_sFactionList);
32 m_wNoFactions = w.FindAnyWidget(m_sNoFactions);
36 m_FactionManager.GetOnPlayerFactionCountChanged().Insert(UpdateFactionButtons);
38 PlayerController pc =
GetGame().GetPlayerController();
42 ShowAvailableFactions();
46 void ShowAvailableFactions()
52 Widget child = m_wFactionList.GetChildren();
55 Widget sibling = child.GetSibling();
57 child.RemoveFromHierarchy();
64 array<Faction> availableFactions = {};
70 int playableFactionCount = 0;
72 for (
int i = 0; i < factionCount; ++i)
78 scriptedFaction.GetOnFactionPlayableChanged().Insert(OnPlayableFactionChanged);
80 Widget btnW =
GetGame().GetWorkspace().CreateWidgets(m_sFactionButton, m_wFactionList);
83 if (m_bUseListFromButton)
88 btnComp.SetFaction(scriptedFaction);
89 btnComp.m_OnClicked.Insert(OnButtonClicked);
90 btnComp.m_OnFocus.Insert(OnButtonFocused);
91 btnComp.m_OnMouseEnter.Insert(OnButtonFocused);
92 btnComp.m_OnMouseLeave.Insert(OnMouseLeft);
94 if (!canChangeFaction && playerFaction)
96 btnComp.SetShouldUnlock(playerFaction == scriptedFaction);
97 btnComp.SetEnabled(playerFaction == scriptedFaction);
100 btnComp.SetVisible(scriptedFaction.IsPlayable(),
false);
102 if (scriptedFaction.IsPlayable())
103 playableFactionCount++;
109 m_wNoFactions.SetVisible(playableFactionCount == 0);
113 void OnPlayerFactionAssigned(
Faction assignedFaction)
122 if (!canChangeFaction)
124 bool enabled = assignedFaction == factionBtn.GetFaction();
125 factionBtn.m_OnClicked.Remove(OnButtonClicked);
126 factionBtn.SetEnabled(enabled);
127 factionBtn.SetShouldUnlock(enabled);
130 if (assignedFaction == factionBtn.GetFaction())
131 factionBtn.HideTooltip();
132 factionBtn.SetSelected(assignedFaction == factionBtn.GetFaction());
138 protected void OnPlayableFactionChanged(
SCR_Faction faction,
bool playable)
140 int playableFactionCount = 0;
146 if (factionBtn.GetFaction() == faction)
147 factionBtn.SetVisible(playable,
false);
148 if (factionBtn.GetFaction().IsPlayable())
149 playableFactionCount++;
153 m_wNoFactions.SetVisible(playableFactionCount == 0);
157 protected void UpdateFactionButtons(
Faction faction,
int newCount)
163 factionBtn.UpdatePlayerCount();
168 protected void OnButtonFocused(Widget w)
174 factionBtn.SetTooltipAvailable(
m_PlyFactionAffilComp.GetAffiliatedFaction() != factionBtn.GetFaction());
175 m_OnButtonFocused.Invoke(factionBtn.GetFaction());
188 Faction faction = factionBtn.GetFaction();
197 RequestPlayerFaction(factionBtn);
201 int factionIndex =
m_FactionManager.GetFactionIndex(factionBtn.GetFaction());
203 dialog.m_OnConfirm.Insert(OnFactionDialogConfirm);
212 RequestPlayerFaction(btn);
215 void RequestRandomFaction()
217 array<Faction> factions = {};
232 if (factionBtn && factionBtn.GetFaction() == faction)
239 ScriptInvoker GetOnFactionRequested()
241 if (!m_OnFactionRequested)
242 m_OnFactionRequested =
new ScriptInvoker();
244 return m_OnFactionRequested;
252 protected string m_sFactionName;
253 protected TextWidget m_wFactionName;
256 protected string m_sPlayerCount;
257 protected TextWidget m_wPlayerCount;
260 protected string m_sPlayerIcon;
261 protected Widget m_wPlayerIcon;
264 protected string m_sArrowIcon;
265 protected ImageWidget m_wArrowIcon;
268 protected int m_iPlayerCount;
271 override void HandlerAttached(Widget w)
273 super.HandlerAttached(w);
275 m_wFactionName = TextWidget.Cast(w.FindAnyWidget(m_sFactionName));
276 m_wPlayerCount = TextWidget.Cast(w.FindAnyWidget(m_sPlayerCount));
277 m_wPlayerIcon = ImageWidget.Cast(w.FindAnyWidget(m_sPlayerIcon));
278 m_wArrowIcon = ImageWidget.Cast(w.FindAnyWidget(m_sArrowIcon));
286 SetFactionName(faction.GetFactionName());
301 return m_iPlayerCount;
305 void UpdatePlayerCount()
308 if (scrFaction && m_wPlayerCount)
310 m_iPlayerCount = scrFaction.GetPlayerCount();
311 m_wPlayerCount.SetText(m_iPlayerCount.ToString());
316 void SetFactionName(
string name)
319 m_wFactionName.SetText(name);
323 override void SetSelected(
bool selected)
325 super.SetSelected(selected);
330 m_wArrowIcon.SetRotation(90);
332 m_wArrowIcon.SetRotation(270);