Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
CreateGroupSettingsDialogUI.c
Go to the documentation of this file.
2{
9
11
12 protected SCR_PlayerControllerGroupComponent m_PlayerComponent;
15
16 protected bool m_bHasPrivilege;
18
19 //------------------------------------------------------------------------------------------------
20 override void OnMenuOpen()
21 {
22 super.OnMenuOpen();
23
24 m_LocalFaction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
25
26 m_PlayerComponent = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
28 return;
29
32 SocialComponent.RequestSocialPrivilege(EUserInteraction.UserGeneratedContent, m_CallbackGetPrivilege);
33 }
34
35 //------------------------------------------------------------------------------------------------
36 protected void OnPrivilegeCallback(UserPrivilege privilege, UserPrivilegeResult result)
37 {
39 if (!m_GroupsManager)
40 return;
41
43 if (!w)
44 return;
45
46 m_RulesDescriptionSize = w.FindAnyWidget("RulesDescriptionSize");
48 return;
49
50 m_RulesDescriptionSize.SetVisible(!SCR_FactionCommanderPlayerComponent.IsLocalPlayerCommander());
51
52 m_GroupStatus = SCR_ComboBoxComponent.GetComboBoxComponent("Type", w);
53 if (!m_GroupStatus)
54 return;
55
56 m_GroupRole = SCR_ComboBoxComponent.GetComboBoxComponent("SquadRole", w);
57 if (!m_GroupRole)
58 return;
59
61 if (!m_GroupName)
62 return;
63
66 return;
67
68 m_bHasPrivilege = result == UserPrivilegeResult.ALLOWED;
69 bool canEdit = m_bHasPrivilege && !SCR_FactionCommanderPlayerComponent.IsLocalPlayerCommander();
70 string unavailable = WidgetManager.Translate("#AR-UserActionUnavailable"); // Translate is used because to change language the CreateGroupSettingsDialogUI has to be closed and then opened so it will renew.
71
72 m_GroupName.SetEnabled(canEdit);
73 m_GroupDescription.SetEnabled(canEdit);
74
75 if (canEdit)
76 {
77 m_GroupName.SetValue("");
78 m_GroupDescription.SetValue("");
79 }
80 else
81 {
82 m_GroupName.SetValue(unavailable);
83 m_GroupDescription.SetValue(unavailable);
84 }
85
89 }
90
91 //------------------------------------------------------------------------------------------------
92 override void OnMenuUpdate(float tDelta)
93 {
94 super.OnMenuUpdate(tDelta);
95
96 GetGame().GetInputManager().ActivateContext("InteractableDialogContext");
97 }
98
99 //------------------------------------------------------------------------------------------------
100 override protected void OnConfirm()
101 {
102 array<SCR_EGroupRole> availableGroupRoles = m_GroupsManager.GetAvailableGroupRoles(m_LocalFaction, SCR_PlayerController.GetLocalPlayerId());
103 if (availableGroupRoles.IsEmpty())
104 return;
105
106 SCR_PlayerControllerGroupComponent groupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
107 if (!groupController)
108 return;
109
110 if (m_bHasPrivilege)
111 {
112 bool isPrivate = m_GroupStatus.GetCurrentIndex() == SCR_EGroupPrivacy.PRIVATE;
113
114 array<SCR_EGroupRole> configuredGroupRoles = m_GroupsManager.GetConfiguredGroupRoles(m_LocalFaction, true);
115
116 int currentIndex = m_GroupRole.GetCurrentIndex();
117 if (configuredGroupRoles.IsIndexValid(currentIndex) && availableGroupRoles.Contains(configuredGroupRoles[currentIndex]))
118 {
119 bool joinGroup = !SCR_FactionCommanderPlayerComponent.IsLocalPlayerCommander();
120
121 string groupName = string.Empty;
122 if (m_GroupName.IsEnabled())
123 groupName = m_GroupName.GetValue();
124
125 string groupDescription = string.Empty;
126 if (m_GroupDescription.IsEnabled())
127 groupDescription = m_GroupDescription.GetValue();
128
129 groupController.RequestCreateGroupWithData(configuredGroupRoles[currentIndex], isPrivate, groupName, groupDescription, joinGroup, true);
130 }
131 else
132 {
133 Print("Cannot create group because is not available", LogLevel.WARNING);
134 }
135 }
136
137 Close();
138 }
139
140 //------------------------------------------------------------------------------------------------
141 protected void SetupGroupStatusCombo()
142 {
143 m_GroupStatus.AddItem("#AR-Player_Groups_Public");
144 m_GroupStatus.AddItem("#AR-Player_Groups_Private");
145
146 m_GroupStatus.SetCurrentItem(SCR_EGroupPrivacy.PUBLIC); // default value
147
148 if (SCR_FactionCommanderPlayerComponent.IsLocalPlayerCommander())
149 m_GroupStatus.SetEnabled(false);
150 }
151
152 //------------------------------------------------------------------------------------------------
153 protected void SetupGroupRoleCombo()
154 {
155 m_GroupRole.m_OnOpened.Insert(OnGroupRoleComboOpened);
156
157 // set available role to combobox
158 array<SCR_EGroupRole> availableGroupRoles = m_GroupsManager.GetAvailableGroupRoles(m_LocalFaction, SCR_PlayerController.GetLocalPlayerId());
159 bool selectAvailableGroupRole = !availableGroupRoles.IsEmpty();
160
161 array<SCR_GroupRolePresetConfig> groupRolePresetConfigs = {};
162 m_LocalFaction.GetGroupRolePresetConfigs(groupRolePresetConfigs);
163
165 string groupRoleName;
166 int count = groupRolePresetConfigs.Count();
167 for (int i = 0; i < count; i++)
168 {
169 preset = groupRolePresetConfigs[i];
170
171 if (!preset.CanBeCreatedByPlayer())
172 continue;
173
174 if (preset.GetGroupRoleName().IsEmpty())
175 groupRoleName = SCR_Enum.GetEnumName(SCR_EGroupRole, preset.GetGroupRole());
176 else
177 groupRoleName = preset.GetGroupRoleName();
178
179 m_GroupRole.AddItem(groupRoleName, i == count-1);
180
181 if (selectAvailableGroupRole && preset.GetGroupRole() == availableGroupRoles[0])
182 {
183 m_GroupRole.SetCurrentItem(i);
184 selectAvailableGroupRole = false;
185 }
186 }
187 }
188 //------------------------------------------------------------------------------------------------
189 protected void OnGroupRoleComboOpened()
190 {
191 array<SCR_EGroupRole> configuredGroupRoles = m_GroupsManager.GetConfiguredGroupRoles(m_LocalFaction, true);
192 array<SCR_EGroupRole> availableGroupRoles = m_GroupsManager.GetAvailableGroupRoles(m_LocalFaction, SCR_PlayerController.GetLocalPlayerId());
193
194 array<Widget> comboBoxWidgets = {};
195 int itemsCount = m_GroupRole.GetElementWidgets(comboBoxWidgets);
196
197 SCR_SquadRoleComboBoxElement squadRoleComboBoxElement;
198 bool isAvailable = false;
199 bool isPlayerCommander = SCR_FactionCommanderPlayerComponent.IsLocalPlayerCommander();
200
201 // set element availability in combobox
202 for (int i = 0; i < itemsCount; i++)
203 {
204 SCR_EGroupRole configuredGroupRole = configuredGroupRoles[i];
205 if (configuredGroupRoles.IsIndexValid(i))
206 isAvailable = availableGroupRoles.Contains(configuredGroupRole);
207 else
208 isAvailable = false;
209
210 m_GroupRole.SetElementWidgetEnabled(i, isAvailable, false);
211
212 squadRoleComboBoxElement = SCR_SquadRoleComboBoxElement.Cast(comboBoxWidgets[i].FindHandler(SCR_SquadRoleComboBoxElement));
213 if (!squadRoleComboBoxElement)
214 continue;
215
216 bool isRequiredRankVisible = !isPlayerCommander && !m_GroupsManager.CanCreateGroupWithLocalPlayerRank(configuredGroupRole, m_LocalFaction);
217 squadRoleComboBoxElement.SetVisibleInsufficientRank(isRequiredRankVisible);
218 if (isRequiredRankVisible)
219 {
220 SCR_ECharacterRank requiredRank = m_GroupsManager.GetRequiredRank(configuredGroupRole, m_LocalFaction);
221 squadRoleComboBoxElement.SetRankImage(m_LocalFaction.GetRanks().GetRankInsignia(requiredRank));
222 }
223
224 bool isNotEnoughFullGroupVisible = !isPlayerCommander && !m_GroupsManager.AreAllGroupsMajorityFull(configuredGroupRole, m_LocalFaction);
225 squadRoleComboBoxElement.SetVisibleNotEnoughFullGroup(isNotEnoughFullGroupVisible);
226 }
227 }
228
229 //------------------------------------------------------------------------------------------------
230 protected void UpdateConfirmButton()
231 {
232 array<SCR_EGroupRole> availableGroupRoles = m_GroupsManager.GetAvailableGroupRoles(m_LocalFaction, SCR_PlayerController.GetLocalPlayerId());
233 bool isAnyAvailable = availableGroupRoles.Count() > 0;
234 m_Confirm.SetVisible(isAnyAvailable);
235 }
236}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_EGroupPrivacy
Group privacy.
SCR_EGroupRole
Group roles.
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Widget GetRootWidget()
proto native void Close()
UserPrivilege
UserPrivilegeResult
override void OnMenuUpdate(float tDelta)
void OnPrivilegeCallback(UserPrivilege privilege, UserPrivilegeResult result)
SCR_PlayerControllerGroupComponent m_PlayerComponent
SCR_GroupsManagerComponent m_GroupsManager
ref SCR_ScriptPlatformRequestCallback m_CallbackGetPrivilege
SCR_InputButtonComponent m_Confirm
Definition DialogUI.c:8
static SCR_EditBoxComponent GetEditBoxComponent(string name, Widget parent, bool searchAllChildren=true)
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
EUserInteraction
Interaction type between two players.