Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VotingEditor.c
Go to the documentation of this file.
3 {
4  [Attribute(SCR_Enum.GetDefault(EEditorMode.EDIT), uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(EEditorMode))]
5  protected EEditorMode m_EditorModes;
6 
7  protected SCR_EditorManagerEntity m_EditorManager;
8 
9  //------------------------------------------------------------------------------------------------
10  protected bool EvaluateEditor(out EVotingOutcome outcome)
11  {
12  if (!m_EditorManager || !m_EditorManager.IsLimited())
13  {
14  outcome = EVotingOutcome.FORCE_FAIL;
15  return true;
16  }
17  return false;
18  }
19 
20  //------------------------------------------------------------------------------------------------
21  override bool Evaluate(out EVotingOutcome outcome)
22  {
23  if (!m_EditorManager)
24  {
26  m_EditorManager = core.GetEditorManager(GetValue());
27  }
28 
29  if (EvaluateEditor(outcome))
30  return true;
31  else
32  return super.Evaluate(outcome);
33  }
34 
35  //------------------------------------------------------------------------------------------------
36  override bool IsAvailable(int value, bool isOngoing)
37  {
38  //--- Only local player can nominate themselves, but everyone else can vote for them afterwards
39  if (isOngoing || SCR_PlayerController.GetLocalPlayerId() == value)
40  {
42  if (editorDelegateManager)
43  {
44  //--- Cannot vote for existing GMs
45  SCR_EditablePlayerDelegateComponent playerEditorDelegate = editorDelegateManager.GetDelegate(value);
46  return playerEditorDelegate && playerEditorDelegate.HasLimitedEditor();
47  }
48  }
49  return false;
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  override bool CanSendNotification(int value)
54  {
55  if (!Replication.IsRunning())
56  return false;
57 
58  SCR_VotingManagerComponent votingManager = SCR_VotingManagerComponent.GetInstance();
60  return (votingManager && votingManager.GetHostPlayerID() != value) || (gameMode && gameMode.GetGameMasterTarget() != EGameModeEditorTarget.EVERYBODY);
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  override void OnVotingEnd(int value = DEFAULT_VALUE, int winner = DEFAULT_VALUE)
65  {
66  if (winner == DEFAULT_VALUE)
67  return;
68 
70  SCR_EditorManagerEntity editorManager = core.GetEditorManager(winner);
71  editorManager.AddEditorModes(EEditorModeAccess.BASE, m_EditorModes, false);
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  override void InitFromTemplate(SCR_VotingBase template, int value, float remainingDuration)
76  {
77  super.InitFromTemplate(template, value, remainingDuration);
78 
79  SCR_VotingEditorIn templateEditor = SCR_VotingEditorIn.Cast(template);
80  m_EditorModes = templateEditor.m_EditorModes;
81  }
82 }
83 
85 class SCR_VotingEditorOut: SCR_VotingEditorIn
86 {
87  //------------------------------------------------------------------------------------------------
88  override protected bool EvaluateEditor(out EVotingOutcome outcome)
89  {
90  if (!m_EditorManager || m_EditorManager.IsLimited())
91  {
92  outcome = EVotingOutcome.FORCE_FAIL;
93  return true;
94  }
95  return false;
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  override protected int GetPlayerCount()
100  {
101  return Math.Max(super.GetPlayerCount() - 1, 2); //--- Ignore target player. 2 is a limit to prevent instant completion in a session with just 2 people.
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  override bool IsAvailable(int value, bool isOngoing)
106  {
107  //--- Cannot vote for self
108  if (SCR_PlayerController.GetLocalPlayerId() == value)
109  return false;
110 
111  //--- Cannot vote host or admin out
112  SCR_VotingManagerComponent votingManager = SCR_VotingManagerComponent.GetInstance();
113  if (!votingManager || votingManager.GetHostPlayerID() == value || GetGame().GetPlayerManager().HasPlayerRole(value, EPlayerRole.ADMINISTRATOR))
114  return false;
115 
116  //--- Cannot vote for players who are not GMs
118  if (!editorDelegateManager)
119  return false;
120 
121  SCR_EditablePlayerDelegateComponent playerEditorDelegate = editorDelegateManager.GetDelegate(value);
122  return playerEditorDelegate && !playerEditorDelegate.HasLimitedEditor();
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  override bool CanSendNotification(int value)
127  {
129  return gameMode && gameMode.GetGameMasterTarget() != EGameModeEditorTarget.EVERYBODY;
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  override void OnVotingEnd(int value = DEFAULT_VALUE, int winner = DEFAULT_VALUE)
134  {
135  if (winner == DEFAULT_VALUE)
136  return;
137 
139  SCR_EditorManagerEntity editorManager = core.GetEditorManager(winner);
140  editorManager.RemoveEditorModes(EEditorModeAccess.BASE, m_EditorModes);
141  }
142 }
143 
146 {
147  //------------------------------------------------------------------------------------------------
148  override bool Evaluate(out EVotingOutcome outcome)
149  {
150  return true;
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  override bool IsAvailable(int value, bool isOngoing)
155  {
156  //--- Can apply only for self
157  if (SCR_PlayerController.GetLocalPlayerId() != value)
158  return false;
159 
160  //--- Cannot apply when a host or an admin
161  SCR_VotingManagerComponent votingManager = SCR_VotingManagerComponent.GetInstance();
162  if (!votingManager || votingManager.GetHostPlayerID() == value || GetGame().GetPlayerManager().HasPlayerRole(value, EPlayerRole.ADMINISTRATOR))
163  return false;
164 
165  //--- Cannot vote for players who are not GMs
167  if (!editorDelegateManager)
168  return false;
169 
170  SCR_EditablePlayerDelegateComponent playerEditorDelegate = editorDelegateManager.GetDelegate(value);
171  return playerEditorDelegate && !playerEditorDelegate.HasLimitedEditor();
172  }
173 
174  //------------------------------------------------------------------------------------------------
175  override void OnVotingEnd(int value = DEFAULT_VALUE, int winner = DEFAULT_VALUE)
176  {
177  if (winner == DEFAULT_VALUE)
178  return;
179 
181  SCR_EditorManagerEntity editorManager = core.GetEditorManager(winner);
182  editorManager.RemoveEditorModes(EEditorModeAccess.BASE, m_EditorModes);
183  }
184 }
SCR_VotingBase
Definition: SCR_VotingBase.c:5
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_Enum
Definition: SCR_Enum.c:1
EPlayerRole
EPlayerRole
Definition: EPlayerRole.c:7
BaseContainerProps
SCR_VotingEditorIn SCR_VotingReferendum BaseContainerProps()
EEditorModeAccess
EEditorModeAccess
Definition: EEditorModeAccess.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_VotingEditorIn
Definition: SCR_VotingEditor.c:2
SCR_PlayerDelegateEditorComponent
Definition: SCR_PlayerDelegateEditorComponent.c:9
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_VotingReferendum
Definition: SCR_VotingBase.c:345
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
EvaluateEditor
protected bool EvaluateEditor(out EVotingOutcome outcome)
Definition: SCR_VotingEditor.c:8
CanSendNotification
override bool CanSendNotification(int value)
Definition: SCR_VotingEditor.c:51
GetValue
override int GetValue()
Definition: SCR_VotingBase.c:69
m_EditorManager
protected SCR_EditorManagerEntity m_EditorManager
Definition: SCR_VotingEditor.c:5
EEditorMode
EEditorMode
Editor mode that defines overall functionality.
Definition: EEditorMode.c:5
m_EditorModes
protected EEditorMode m_EditorModes
Definition: SCR_VotingEditor.c:3
EVotingType
EVotingType
Definition: EVotingType.c:1
OnVotingEnd
override void OnVotingEnd(int value=DEFAULT_VALUE, int winner=DEFAULT_VALUE)
Definition: SCR_VotingEditor.c:62
SCR_VotingManagerComponent
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VotingManagerComponent.c:878
IsAvailable
override bool IsAvailable(int value, bool isOngoing)
Definition: SCR_VotingEditor.c:34
GetPlayerCount
int GetPlayerCount()
Definition: SCR_Faction.c:365
EGameModeEditorTarget
EGameModeEditorTarget
Definition: SCR_GameModeEditor.c:150
SCR_VotingEditorWithdraw
Definition: SCR_VotingEditor.c:145
SCR_BaseContainerCustomTitleEnum
SCR_VotingEditorIn SCR_VotingReferendum SCR_BaseContainerCustomTitleEnum(EVotingType, "m_Type")
Definition: SCR_VotingEditor.c:84
EVotingOutcome
EVotingOutcome
Definition: EVotingOutcome.c:1
SCR_GameModeEditor
Definition: SCR_GameModeEditor.c:7
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26