Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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)]
4  protected LocalizedString m_sMultipleVotesText;
5 
6  [Attribute("VotingInstantVote")]
7  protected string m_sInstantVoteLayoutName;
8 
9  [Attribute("Time")]
10  protected string m_sRemainingVotingTimeName;
11 
12  [Attribute("#AR-Voting_PlayerCountFormatting")]
13  protected string m_sCurrentVoteCountFormatting;
14 
15  protected Widget m_InstantVoteLayout;
16  protected TextWidget m_RemainingVotingTime;
17 
18  protected SCR_VotingManagerComponent m_VotingManagerComponent;
19 
20  //~ If one vote is set then the duration left is shown
21  protected EVotingType m_eActiveSingularVoteType;
22  protected int m_eActiveSingularVoteValue;
23 
24  protected bool m_bIsUpdatingTime;
25  protected bool m_bIsUpdatingActionContext;
26 
27  //------------------------------------------------------------------------------------------------
28  protected void OnVotingChanged(bool isInit = false)
29  {
30  array<EVotingType> validActiveVotingTypes = {};
31  array<int> votingValues = {};
32  int count = m_VotingManagerComponent.GetAllVotingsWithValue(validActiveVotingTypes, votingValues, false, true);
33 
34  for (int i = count - 1; i >= 0; i--)
35  {
36  //~ Ignore any abstained, unavailible or voted votes
37  if (!m_VotingManagerComponent.IsVotingAvailable(validActiveVotingTypes[i], votingValues[i]) || m_VotingManagerComponent.HasAbstainedLocally(validActiveVotingTypes[i], votingValues[i]) || m_VotingManagerComponent.IsLocalVote(validActiveVotingTypes[i], votingValues[i]))
38  {
39  validActiveVotingTypes.RemoveOrdered(i);
40  votingValues.RemoveOrdered(i);
41  }
42  }
43 
44  int votingCount = validActiveVotingTypes.Count();
45 
46  //If no votes active
47  if (votingCount <= 0)
48  {
49  //Hide notification
50  SetStickyActive(false, !isInit);
51 
52  EnableVotingTimerUI(false);
53  EnableContextAction(false);
54  return;
55  }
56  //Multiple votes active
57  else if (votingCount > 1)
58  {
59  m_Text.SetTextFormat(m_sMultipleVotesText, votingCount.ToString());
60 
61  if (m_InstantVoteLayout)
62  m_InstantVoteLayout.SetVisible(false);
63  if (m_OptionalMessageLayout)
64  m_OptionalMessageLayout.SetVisible(true);
65 
66  EnableVotingTimerUI(false);
67  EnableContextAction(false);
68  }
69  //One vote active
70  else
71  {
72  m_eActiveSingularVoteType = validActiveVotingTypes[0];
73  m_eActiveSingularVoteValue = votingValues[0];
74 
75  if (m_eActiveSingularVoteValue != SCR_VotingBase.DEFAULT_VALUE)
76  {
77  string playerName;
78 
79  PlayerManager playermanager = GetGame().GetPlayerManager();
80  if (playermanager)
81  playerName = playermanager.GetPlayerName(votingValues[0]);
82 
83  string text = WidgetManager.Translate(m_VotingManagerComponent.GetVotingInfo(m_eActiveSingularVoteType).GetStickyNotificationText(), playerName);
84 
85  int currentVotes, VotesRequired;
86  if (m_VotingManagerComponent.GetVoteCounts(m_eActiveSingularVoteType, m_eActiveSingularVoteValue, currentVotes, VotesRequired))
87  m_Text.SetTextFormat(m_sCurrentVoteCountFormatting, text, currentVotes, VotesRequired);
88  else
89  m_Text.SetTextFormat(text);
90  }
91 
92  if (m_InstantVoteLayout)
93  m_InstantVoteLayout.SetVisible(true);
94 
95  if (m_OptionalMessageLayout)
96  m_OptionalMessageLayout.SetVisible(false);
97 
98  EnableVotingTimerUI(true);
99  EnableContextAction(true);
100  }
101 
102  //Show Notification
103  SetStickyActive(true, !isInit);
104  }
105 
106  //------------------------------------------------------------------------------------------------
109  protected void EnableContextAction(bool enable)
110  {
111  if (enable)
112  {
113  if (m_bIsUpdatingActionContext)
114  return;
115 
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);
119  }
120  else
121  {
122  if (!m_bIsUpdatingActionContext)
123  return;
124 
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);
128  }
129 
130  m_bIsUpdatingActionContext = enable;
131  }
132 
133  //------------------------------------------------------------------------------------------------
135  protected void InstantVotingContextUpdate()
136  {
137  GetGame().GetInputManager().ActivateContext("InstantVotingContext");
138  }
139 
140  //------------------------------------------------------------------------------------------------
143  protected void EnableVotingTimerUI(bool enable)
144  {
145  if (!m_RemainingVotingTime)
146  return;
147 
148  if (enable)
149  {
150  if (m_bIsUpdatingTime)
151  return;
152 
153  VotingTimeUpdate();
154  m_RemainingVotingTime.SetVisible(true);
155  GetGame().GetCallqueue().CallLater(VotingTimeUpdate, 1000, true);
156  }
157  else
158  {
159  if (!m_bIsUpdatingTime)
160  return;
161 
162  m_RemainingVotingTime.SetVisible(false);
163  GetGame().GetCallqueue().Remove(VotingTimeUpdate);
164  }
165 
166  m_bIsUpdatingTime = enable;
167  }
168 
169  //------------------------------------------------------------------------------------------------
171  protected void VotingTimeUpdate()
172  {
173  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));
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  protected void OnVoteStartOrChanged(EVotingType type, int value)
178  {
179  //~ One frame later to be sure that all votes were correctly counted
180  GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
181  }
182 
183  //------------------------------------------------------------------------------------------------
184  protected void OnVoteCountChanged(EVotingType type, int value, int voteCount)
185  {
186  //~ One frame later to be sure that all votes were correctly counted
187  GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  protected void OnVotingEnd(EVotingType type, int value, int winner)
192  {
193  //~ One frame later to be sure that all votes were correctly counted
194  GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
195  }
196 
197  //------------------------------------------------------------------------------------------------
198  protected void OnPlayerJoinOrLeaveServer(int playerId)
199  {
200  //~ No need to do anything if sticky notification is not active
201  if (!m_bStickyNotificationActive)
202  return;
203 
204  //~ Call later to make sure everything is correctly setup
205  GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
206  }
207 
208  //------------------------------------------------------------------------------------------------
209  protected void OnPlayerFactionChanged(Faction faction, int newCount)
210  {
211  //~ No need to do anything if sticky notification is not active
212  if (!m_bStickyNotificationActive)
213  return;
214 
215  //~ Call later to make sure everything is correctly setup
216  GetGame().GetCallqueue().CallLater(OnVotingChanged, param1: false);
217  }
218 
219  //------------------------------------------------------------------------------------------------
220  override void OnInit(SCR_NotificationsLogComponent notificationLog)
221  {
222  super.OnInit(notificationLog);
223 
224  m_InstantVoteLayout = m_Root.FindAnyWidget(m_sInstantVoteLayoutName);
225  if (m_InstantVoteLayout)
226  m_RemainingVotingTime = TextWidget.Cast(m_InstantVoteLayout.FindAnyWidget(m_sRemainingVotingTimeName));
227 
228  m_VotingManagerComponent = SCR_VotingManagerComponent.GetInstance();
229  if (m_VotingManagerComponent)
230  {
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);
238  }
239 
241  if (gameMode)
242  {
243  gameMode.GetOnPlayerRegistered().Insert(OnPlayerJoinOrLeaveServer);
244  gameMode.GetOnPlayerDisconnected().Insert(OnPlayerJoinOrLeaveServer);
245  }
246 
247  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
248  if (factionManager)
249  factionManager.GetOnPlayerFactionCountChanged().Insert(OnPlayerFactionChanged);
250  }
251 
252  //------------------------------------------------------------------------------------------------
253  protected override void OnButton()
254  {
255  MenuManager menuManager = GetGame().GetMenuManager();
256 
257  if (menuManager)
258  menuManager.OpenDialog(ChimeraMenuPreset.PlayerListMenu);
259  }
260 
261  //------------------------------------------------------------------------------------------------
262  protected override void OnDestroy()
263  {
264  if (m_VotingManagerComponent)
265  {
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);
272  }
273 
275  if (gameMode)
276  {
277  gameMode.GetOnPlayerRegistered().Remove(OnPlayerJoinOrLeaveServer);
278  gameMode.GetOnPlayerDisconnected().Remove(OnPlayerJoinOrLeaveServer);
279  }
280 
281  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
282  if (factionManager)
283  factionManager.GetOnPlayerFactionCountChanged().Remove(OnPlayerFactionChanged);
284 
285  if (m_bIsUpdatingActionContext)
286  {
287  InputManager inputManager = GetGame().GetInputManager();
288 
289  if (inputManager)
290  {
291  inputManager.RemoveActionListener("InstantVote", EActionTrigger.DOWN, SCR_VoterComponent.InstantVote);
292  inputManager.RemoveActionListener("InstantVoteAbstain", EActionTrigger.DOWN, SCR_VoterComponent.InstantRemoveAndAbstainVote);
293  }
294 
295  GetGame().GetCallqueue().Remove(InstantVotingContextUpdate);
296  }
297 
298  if (m_bIsUpdatingTime)
299  GetGame().GetCallqueue().Remove(VotingTimeUpdate);
300  }
301 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_VotingBase
Definition: SCR_VotingBase.c:5
m_Root
SCR_ServerHostingModSubMenu m_Root
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_NotificationsLogComponent
Definition: SCR_NotificationsLogUIComponent.c:6
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
Attribute
typedef Attribute
Post-process effect of scripted camera.
ETimeFormatParam
ETimeFormatParam
Definition: ETimeFormatParam.c:4
SCR_VotingStickyNotificationUIComponent
Definition: SCR_VotingStickyNotificationUIComponent.c:1
Faction
Definition: Faction.c:12
EVotingType
EVotingType
Definition: EVotingType.c:1
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_VotingManagerComponent
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VotingManagerComponent.c:878
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
LocalizedString
Definition: LocalizedString.c:21
PlayerManager
Definition: PlayerManager.c:12
SCR_StickyNotificationUIComponent
Definition: SCR_StickyNotificationUIComponent.c:1