3 [
Attribute(
"#AR-Notification_Sticky_MultiplePlayerVotes",
desc:
"When there is more then 1 vote in progress", uiwidget: UIWidgets.LocaleEditBox)]
7 protected string m_sInstantVoteLayoutName;
10 protected string m_sRemainingVotingTimeName;
12 [
Attribute(
"#AR-Voting_PlayerCountFormatting")]
13 protected string m_sCurrentVoteCountFormatting;
15 protected Widget m_InstantVoteLayout;
16 protected TextWidget m_RemainingVotingTime;
22 protected int m_eActiveSingularVoteValue;
24 protected bool m_bIsUpdatingTime;
25 protected bool m_bIsUpdatingActionContext;
28 protected void OnVotingChanged(
bool isInit =
false)
30 array<EVotingType> validActiveVotingTypes = {};
31 array<int> votingValues = {};
32 int count = m_VotingManagerComponent.GetAllVotingsWithValue(validActiveVotingTypes, votingValues,
false,
true);
34 for (
int i = count - 1; i >= 0; i--)
37 if (!m_VotingManagerComponent.IsVotingAvailable(validActiveVotingTypes[i], votingValues[i]) || m_VotingManagerComponent.HasAbstainedLocally(validActiveVotingTypes[i], votingValues[i]) || m_VotingManagerComponent.IsLocalVote(validActiveVotingTypes[i], votingValues[i]))
39 validActiveVotingTypes.RemoveOrdered(i);
40 votingValues.RemoveOrdered(i);
44 int votingCount = validActiveVotingTypes.Count();
50 SetStickyActive(
false, !isInit);
52 EnableVotingTimerUI(
false);
53 EnableContextAction(
false);
57 else if (votingCount > 1)
59 m_Text.SetTextFormat(m_sMultipleVotesText, votingCount.ToString());
61 if (m_InstantVoteLayout)
62 m_InstantVoteLayout.SetVisible(
false);
63 if (m_OptionalMessageLayout)
64 m_OptionalMessageLayout.SetVisible(
true);
66 EnableVotingTimerUI(
false);
67 EnableContextAction(
false);
72 m_eActiveSingularVoteType = validActiveVotingTypes[0];
73 m_eActiveSingularVoteValue = votingValues[0];
81 playerName = playermanager.GetPlayerName(votingValues[0]);
83 string text = WidgetManager.Translate(m_VotingManagerComponent.GetVotingInfo(m_eActiveSingularVoteType).GetStickyNotificationText(), playerName);
85 int currentVotes, VotesRequired;
86 if (m_VotingManagerComponent.GetVoteCounts(m_eActiveSingularVoteType, m_eActiveSingularVoteValue, currentVotes, VotesRequired))
87 m_Text.SetTextFormat(m_sCurrentVoteCountFormatting, text, currentVotes, VotesRequired);
89 m_Text.SetTextFormat(text);
92 if (m_InstantVoteLayout)
93 m_InstantVoteLayout.SetVisible(
true);
95 if (m_OptionalMessageLayout)
96 m_OptionalMessageLayout.SetVisible(
false);
98 EnableVotingTimerUI(
true);
99 EnableContextAction(
true);
103 SetStickyActive(
true, !isInit);
109 protected void EnableContextAction(
bool enable)
113 if (m_bIsUpdatingActionContext)
116 GetGame().GetInputManager().AddActionListener(
"InstantVote", EActionTrigger.DOWN, SCR_VoterComponent.InstantVote);
117 GetGame().GetInputManager().AddActionListener(
"InstantVoteAbstain", EActionTrigger.DOWN, SCR_VoterComponent.InstantRemoveAndAbstainVote);
118 GetGame().GetCallqueue().CallLater(InstantVotingContextUpdate, repeat:
true);
122 if (!m_bIsUpdatingActionContext)
125 GetGame().GetInputManager().RemoveActionListener(
"InstantVote", EActionTrigger.DOWN, SCR_VoterComponent.InstantVote);
126 GetGame().GetInputManager().RemoveActionListener(
"InstantVoteAbstain", EActionTrigger.DOWN, SCR_VoterComponent.InstantRemoveAndAbstainVote);
127 GetGame().GetCallqueue().Remove(InstantVotingContextUpdate);
130 m_bIsUpdatingActionContext = enable;
135 protected void InstantVotingContextUpdate()
137 GetGame().GetInputManager().ActivateContext(
"InstantVotingContext");
143 protected void EnableVotingTimerUI(
bool enable)
145 if (!m_RemainingVotingTime)
150 if (m_bIsUpdatingTime)
154 m_RemainingVotingTime.SetVisible(
true);
155 GetGame().GetCallqueue().CallLater(VotingTimeUpdate, 1000,
true);
159 if (!m_bIsUpdatingTime)
162 m_RemainingVotingTime.SetVisible(
false);
163 GetGame().GetCallqueue().Remove(VotingTimeUpdate);
166 m_bIsUpdatingTime = enable;
171 protected void VotingTimeUpdate()
180 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1:
false);
184 protected void OnVoteCountChanged(
EVotingType type,
int value,
int voteCount)
187 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1:
false);
194 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1:
false);
198 protected void OnPlayerJoinOrLeaveServer(
int playerId)
201 if (!m_bStickyNotificationActive)
205 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1:
false);
209 protected void OnPlayerFactionChanged(
Faction faction,
int newCount)
212 if (!m_bStickyNotificationActive)
216 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1:
false);
222 super.OnInit(notificationLog);
224 m_InstantVoteLayout =
m_Root.FindAnyWidget(m_sInstantVoteLayoutName);
225 if (m_InstantVoteLayout)
226 m_RemainingVotingTime = TextWidget.Cast(m_InstantVoteLayout.FindAnyWidget(m_sRemainingVotingTimeName));
229 if (m_VotingManagerComponent)
231 m_VotingManagerComponent.GetOnVotingStart().Insert(OnVoteStartOrChanged);
232 m_VotingManagerComponent.GetOnVotingEnd().Insert(OnVotingEnd);
233 m_VotingManagerComponent.GetOnVoteLocal().Insert(OnVoteStartOrChanged);
234 m_VotingManagerComponent.GetOnRemoveVoteLocal().Insert(OnVoteStartOrChanged);
235 m_VotingManagerComponent.GetOnAbstainVoteLocal().Insert(OnVoteStartOrChanged);
236 m_VotingManagerComponent.GetOnVoteCountChanged().Insert(OnVoteCountChanged);
237 OnVotingChanged(
true);
243 gameMode.GetOnPlayerRegistered().Insert(OnPlayerJoinOrLeaveServer);
244 gameMode.GetOnPlayerDisconnected().Insert(OnPlayerJoinOrLeaveServer);
249 factionManager.GetOnPlayerFactionCountChanged().Insert(OnPlayerFactionChanged);
253 protected override void OnButton()
255 MenuManager menuManager =
GetGame().GetMenuManager();
262 protected override void OnDestroy()
264 if (m_VotingManagerComponent)
266 m_VotingManagerComponent.GetOnVotingStart().Remove(OnVoteStartOrChanged);
267 m_VotingManagerComponent.GetOnVotingEnd().Remove(OnVotingEnd);
268 m_VotingManagerComponent.GetOnVoteLocal().Remove(OnVoteStartOrChanged);
269 m_VotingManagerComponent.GetOnRemoveVoteLocal().Remove(OnVoteStartOrChanged);
270 m_VotingManagerComponent.GetOnAbstainVoteLocal().Remove(OnVoteStartOrChanged);
271 m_VotingManagerComponent.GetOnVoteCountChanged().Remove(OnVoteCountChanged);
277 gameMode.GetOnPlayerRegistered().Remove(OnPlayerJoinOrLeaveServer);
278 gameMode.GetOnPlayerDisconnected().Remove(OnPlayerJoinOrLeaveServer);
283 factionManager.GetOnPlayerFactionCountChanged().Remove(OnPlayerFactionChanged);
285 if (m_bIsUpdatingActionContext)
287 InputManager inputManager =
GetGame().GetInputManager();
291 inputManager.RemoveActionListener(
"InstantVote", EActionTrigger.DOWN, SCR_VoterComponent.InstantVote);
292 inputManager.RemoveActionListener(
"InstantVoteAbstain", EActionTrigger.DOWN, SCR_VoterComponent.InstantRemoveAndAbstainVote);
295 GetGame().GetCallqueue().Remove(InstantVotingContextUpdate);
298 if (m_bIsUpdatingTime)
299 GetGame().GetCallqueue().Remove(VotingTimeUpdate);