Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VotingStickyNotificationUIComponent.c
Go to the documentation of this file.
2{
3 [Attribute("#AR-Notification_Sticky_MultiplePlayerVotes", desc: "When there is more then 1 vote in progress", uiwidget: UIWidgets.LocaleEditBox)]
5
6 [Attribute("VotingInstantVote")]
7 protected string m_sInstantVoteLayoutName;
8
9 [Attribute("Time")]
11
12 [Attribute("VotingInstantVoteButtons")]
14
15 [Attribute("#AR-Voting_PlayerCountFormatting")]
17
21
23
24 //~ If one vote is set then the duration left is shown
27
28 //~ If there is a voting about local player that should display the vote timer
32
33 protected bool m_bIsUpdatingTime;
35
36 protected static const float PLATFORM_ICON_SIZE = 2;
37
38 //------------------------------------------------------------------------------------------------
39 protected void OnVotingChanged(bool isInit = false)
40 {
41 array<EVotingType> validActiveVotingTypes = {};
42 array<int> votingValues = {};
43 int count = m_VotingManagerComponent.GetAllVotingsWithValue(validActiveVotingTypes, votingValues, false, true);
45
46 int value;
47 EVotingType voteType;
48 for (int i = count - 1; i >= 0; i--)
49 {
50 voteType = validActiveVotingTypes[i];
51 value = votingValues[i];
52
53 //~ Ignore any abstained, unavailible or voted votes
54 if (!m_VotingManagerComponent.IsVotingAvailable(voteType, value) || m_VotingManagerComponent.HasAbstainedLocally(voteType, value) || m_VotingManagerComponent.IsLocalVote(voteType, value))
55 {
56 if (m_VotingManagerComponent.GetVoteAlwaysDisplayVoteSubjectVotingTimer(voteType, value) && value == SCR_PlayerController.GetLocalPlayerId())
57 {
61 continue;
62 }
63
64 if (m_VotingManagerComponent.GetVoteAlwaysDisplayVoteInitiatorVotingTimer(voteType, value) && m_VotingManagerComponent.GetVoteAuthorId(voteType, value) == SCR_PlayerController.GetLocalPlayerId())
65 {
69 continue;
70 }
71
72 validActiveVotingTypes.RemoveOrdered(i);
73 votingValues.RemoveOrdered(i);
74 }
75 }
76
77 int votingCount = validActiveVotingTypes.Count();
78
80 //If no votes active
81 if (votingCount <= 0)
82 {
83 //Hide notification
84 SetStickyActive(false, !isInit);
85
88 menuInvoker.Remove(OnSettingsMenuClosed);
89 return;
90 }
91 //Multiple votes active
92 else if (votingCount > 1)
93 {
94 m_Text.SetTextFormat(m_sMultipleVotesText, votingCount.ToString());
95
97 m_OptionalMessageLayout.SetVisible(true);
98
101
103 m_VotingInstantVoteButtons.SetVisible(false);
104
107
109 EnableContextAction(false);
110 menuInvoker.Remove(OnSettingsMenuClosed);
111 }
112 //One vote active
113 else
114 {
115 m_eActiveSingularVoteType = validActiveVotingTypes[0];
116 m_eActiveSingularVoteValue = votingValues[0];
117
119 {
120 string playerName = GetPlayerName(m_eActiveSingularVoteValue);
122
124 if (!voteAuthorName.IsEmpty())
125 voteAuthorName = WidgetManager.Translate(voteUIInfo.GetAuthorText(), voteAuthorName);
126
127 string text = WidgetManager.Translate(voteUIInfo.GetStickyNotificationText(), playerName, voteAuthorName);
128
129 int currentVotes, VotesRequired;
130 if (m_VotingManagerComponent.GetVoteCounts(m_eActiveSingularVoteType, m_eActiveSingularVoteValue, currentVotes, VotesRequired))
131 m_Text.SetTextFormat(m_sCurrentVoteCountFormatting, text, currentVotes, VotesRequired);
132 else
133 m_Text.SetTextFormat(text);
134 }
135
137 m_InstantVoteLayout.SetVisible(true);
138
140 m_OptionalMessageLayout.SetVisible(false);
141
144
146 m_InstantVoteLayout.SetVisible(true);
147
150
151 menuInvoker.Insert(OnSettingsMenuClosed);
152 }
153
154 //Show Notification
155 SetStickyActive(true, !isInit);
156 }
157
158 //------------------------------------------------------------------------------------------------
162 {
163 if (SCR_SettingsSuperMenu.Cast(menu))
165 }
166
167 //------------------------------------------------------------------------------------------------
171 protected string GetPlayerName(int playerId)
172 {
173 string playerName = SCR_PlayerNamesFilterCache.GetInstance().GetPlayerDisplayName(playerId);
175 return string.Empty;
176
177 BaseContainer settings = GetGame().GetGameUserSettings().GetModule("SCR_GameplaySettings");
178 bool showIconNametag;
179 if (settings)
180 settings.Get("m_bPlatformIconNametag", showIconNametag);
181
182 PlatformKind localPlatform = GetGame().GetPlatformService().GetLocalPlatformKind();
183 if (!showIconNametag && localPlatform != PlatformKind.PSN)
184 return playerName;
185
186 PlatformKind playerPlatform = GetGame().GetPlayerManager().GetPlatformKind(playerId);
187 string iconName;
188 if (localPlatform == PlatformKind.PSN)
189 {
190 if (playerPlatform == PlatformKind.PSN)
191 iconName = UIConstants.PLATFROM_PLAYSTATION_ICON_NAME;
192 else
193 iconName = UIConstants.PLATFROM_GENERIC_ICON_NAME;
194 }
195 else
196 {
197 switch (playerPlatform)
198 {
199 case PlatformKind.STEAM:
200 iconName = UIConstants.PLATFROM_PC_ICON_NAME;
201 break;
202 case PlatformKind.XBOX:
203 iconName = UIConstants.PLATFROM_XBOX_ICON_NAME;
204 break;
205 case PlatformKind.PSN:
206 iconName = UIConstants.PLATFROM_PLAYSTATION_ICON_NAME;
207 break;
208 case PlatformKind.NONE:
209 iconName = UIConstants.PLATFROM_PC_ICON_NAME;
210 break;
211 }
212 }
213
214 return string.Format(UIConstants.NAME_WITH_PLATFORM_ICON_FORMAT, UIColors.FormatColor(GUIColors.ENABLED), UIConstants.ICONS_IMAGE_SET, iconName, PLATFORM_ICON_SIZE, playerName);
215 }
216
217 //------------------------------------------------------------------------------------------------
220 protected void EnableContextAction(bool enable)
221 {
222 if (enable)
223 {
225 return;
226
227 GetGame().GetInputManager().AddActionListener("InstantVote", EActionTrigger.DOWN, SCR_VoterComponent.InstantVote);
228 GetGame().GetInputManager().AddActionListener("InstantVoteAbstain", EActionTrigger.DOWN, SCR_VoterComponent.InstantRemoveAndAbstainVote);
229 GetGame().GetCallqueue().CallLater(InstantVotingContextUpdate, repeat: true);
230 }
231 else
232 {
234 return;
235
236 GetGame().GetInputManager().RemoveActionListener("InstantVote", EActionTrigger.DOWN, SCR_VoterComponent.InstantVote);
237 GetGame().GetInputManager().RemoveActionListener("InstantVoteAbstain", EActionTrigger.DOWN, SCR_VoterComponent.InstantRemoveAndAbstainVote);
238 GetGame().GetCallqueue().Remove(InstantVotingContextUpdate);
239 }
240
242 }
243
244 //------------------------------------------------------------------------------------------------
247 {
248 GetGame().GetInputManager().ActivateContext("InstantVotingContext");
249 }
250
251 //------------------------------------------------------------------------------------------------
254 protected void EnableVotingTimerUI(bool enable)
255 {
257 return;
258
259 if (enable)
260 {
262 return;
263
265 m_RemainingVotingTime.SetVisible(true);
266 GetGame().GetCallqueue().CallLater(VotingTimeUpdate, 1000, true);
267 }
268 else
269 {
271 return;
272
273 m_RemainingVotingTime.SetVisible(false);
274 GetGame().GetCallqueue().Remove(VotingTimeUpdate);
275 }
276
277 m_bIsUpdatingTime = enable;
278 }
279
280 //------------------------------------------------------------------------------------------------
282 protected void VotingTimeUpdate()
283 {
286 else
287 m_RemainingVotingTime.SetText(SCR_FormatHelper.GetTimeFormatting(Math.Clamp(m_VotingManagerComponent.GetRemainingDurationOfVote(m_eActiveSingularVoteType, m_eActiveSingularVoteValue), 0, float.MAX), ETimeFormatParam.DAYS | ETimeFormatParam.HOURS, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS | ETimeFormatParam.MINUTES));
288 }
289
290 //------------------------------------------------------------------------------------------------
291 protected void OnVoteStartOrChanged(EVotingType type, int value)
292 {
293 //~ One frame later to be sure that all votes were correctly counted
294 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
295 }
296
297 //------------------------------------------------------------------------------------------------
298 protected void OnVoteCountChanged(EVotingType type, int value, int voteCount)
299 {
300 //~ One frame later to be sure that all votes were correctly counted
301 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
302 }
303
304 //------------------------------------------------------------------------------------------------
305 protected void OnVotingEnd(EVotingType type, int value, int winner)
306 {
307 //~ One frame later to be sure that all votes were correctly counted
308 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
309 }
310
311 //------------------------------------------------------------------------------------------------
312 protected void OnPlayerJoinOrLeaveServer(int playerId)
313 {
314 //~ No need to do anything if sticky notification is not active
316 return;
317
318 //~ Call later to make sure everything is correctly setup
319 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
320 }
321
322 //------------------------------------------------------------------------------------------------
323 protected void OnPlayerFactionChanged(Faction faction, int newCount)
324 {
325 //~ No need to do anything if sticky notification is not active
327 return;
328
329 //~ Call later to make sure everything is correctly setup
330 GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
331 }
332
333 //------------------------------------------------------------------------------------------------
334 override void OnInit(SCR_NotificationsLogComponent notificationLog)
335 {
336 super.OnInit(notificationLog);
337
340 {
343 }
344
347 {
348 m_VotingManagerComponent.GetOnVotingStart().Insert(OnVoteStartOrChanged);
349 m_VotingManagerComponent.GetOnVotingEnd().Insert(OnVotingEnd);
350 m_VotingManagerComponent.GetOnVoteLocal().Insert(OnVoteStartOrChanged);
351 m_VotingManagerComponent.GetOnRemoveVoteLocal().Insert(OnVoteStartOrChanged);
352 m_VotingManagerComponent.GetOnAbstainVoteLocal().Insert(OnVoteStartOrChanged);
353 m_VotingManagerComponent.GetOnVoteCountChanged().Insert(OnVoteCountChanged);
354 OnVotingChanged(true);
355 }
356
358 if (gameMode)
359 {
362 }
363
364 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
365 if (factionManager)
366 factionManager.GetOnPlayerFactionCountChanged().Insert(OnPlayerFactionChanged);
367 }
368
369 //------------------------------------------------------------------------------------------------
370 protected override void OnButton()
371 {
372 MenuManager menuManager = GetGame().GetMenuManager();
373
374 if (menuManager)
375 menuManager.OpenDialog(ChimeraMenuPreset.PlayerListMenu);
376 }
377
378 //------------------------------------------------------------------------------------------------
379 protected override void OnDestroy()
380 {
382 {
383 m_VotingManagerComponent.GetOnVotingStart().Remove(OnVoteStartOrChanged);
384 m_VotingManagerComponent.GetOnVotingEnd().Remove(OnVotingEnd);
385 m_VotingManagerComponent.GetOnVoteLocal().Remove(OnVoteStartOrChanged);
386 m_VotingManagerComponent.GetOnRemoveVoteLocal().Remove(OnVoteStartOrChanged);
387 m_VotingManagerComponent.GetOnAbstainVoteLocal().Remove(OnVoteStartOrChanged);
388 m_VotingManagerComponent.GetOnVoteCountChanged().Remove(OnVoteCountChanged);
389 }
390
392 if (gameMode)
393 {
396 }
397
398 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
399 if (factionManager)
400 factionManager.GetOnPlayerFactionCountChanged().Remove(OnPlayerFactionChanged);
401
403 {
404 InputManager inputManager = GetGame().GetInputManager();
405
406 if (inputManager)
407 {
408 inputManager.RemoveActionListener("InstantVote", EActionTrigger.DOWN, SCR_VoterComponent.InstantVote);
409 inputManager.RemoveActionListener("InstantVoteAbstain", EActionTrigger.DOWN, SCR_VoterComponent.InstantRemoveAndAbstainVote);
410 }
411
412 GetGame().GetCallqueue().Remove(InstantVotingContextUpdate);
413 }
414
416 GetGame().GetCallqueue().Remove(VotingTimeUpdate);
417 }
418}
ChimeraMenuPreset
Menu presets.
ETimeFormatParam
EVotingType
Definition EVotingType.c:2
ArmaReforgerScripted GetGame()
Definition game.c:1398
PlatformKind
Definition PlatformKind.c:8
SCR_BaseGameMode GetGameMode()
EDamageType type
void SCR_FactionManager(IEntitySource src, IEntity parent)
ScriptInvokerBase< ScriptInvokerMenuMethod > ScriptInvokerMenu
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Constant variables used in various menus.
Input management system for user interactions.
Definition Math.c:13
proto external MenuBase OpenDialog(ScriptMenuPresetEnum preset, int priority=DialogPriority.INFORMATIVE, int iUserData=0, bool unique=false)
ScriptInvokerBase< SCR_BaseGameMode_OnPlayerDisconnected > GetOnPlayerDisconnected()
ScriptInvokerBase< SCR_BaseGameMode_PlayerId > GetOnPlayerRegistered()
static ScriptInvokerMenu GetOnMenuClose()
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
void SetStickyActive(bool newActive, bool fade=true)
static bool IsEmptyOrWhiteSpace(string input)
static const int DEFAULT_VALUE
void InstantVotingContextUpdate()
Updates each frame to keep InstantVotingContext active.
void OnVotingEnd(EVotingType type, int value, int winner)
void VotingTimeUpdate()
Called when only 1 vote is active or when local player is the subject of the vote and timer is displa...
override void OnInit(SCR_NotificationsLogComponent notificationLog)
void OnVoteCountChanged(EVotingType type, int value, int voteCount)
LocalizedString GetAuthorText()
string GetStickyNotificationText()
SCR_FieldOfViewSettings Attribute
EActionTrigger
Tuple param1