Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RequestToJoinSubMenu.c
Go to the documentation of this file.
2 {
3  protected const string REQUESTER_ENTRY_LAYOUT = "{B3381965FF7747CE}UI/layouts/Menus/GroupSlection/GroupRequestEntry.layout";
4  protected ref ScriptInvokerVoid m_OnJoinRequestRespond;
5  protected ref array<Widget> m_aEntryWidgets = {};
6  protected VerticalLayoutWidget m_wContent;
7 
8  //------------------------------------------------------------------------------------------------
9  override void OnTabShow()
10  {
11  super.OnTabShow();
12 
13  UpdateRequesters();
14 
15  GetOnJoinRequestRespond().Insert(UpdateRequesters);
16  }
17 
18  //------------------------------------------------------------------------------------------------
19  override void OnTabRemove()
20  {
21  super.OnTabRemove();
22 
23  GetOnJoinRequestRespond().Remove(UpdateRequesters);
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  ScriptInvokerVoid GetOnJoinRequestRespond()
28  {
29  if (!m_OnJoinRequestRespond)
30  m_OnJoinRequestRespond = new ScriptInvokerVoid();
31 
32  return m_OnJoinRequestRespond;
33  }
34 
35  //------------------------------------------------------------------------------------------------
36  void UpdateRequesters()
37  {
38  SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
39  if (!groupsManager)
40  return;
41 
42  SCR_AIGroup group = groupsManager.GetPlayerGroup(GetGame().GetPlayerController().GetPlayerId());
43  if (!group)
44  return;
45 
46  VerticalLayoutWidget content = VerticalLayoutWidget.Cast(m_wMenuRoot.FindAnyWidget("Content"));
47  if (!content)
48  return;
49 
50  for (int i = 0, count = m_aEntryWidgets.Count(); i < count ;i++)
51  {
52  content.RemoveChild(m_aEntryWidgets[i]);
53  }
54 
55  m_aEntryWidgets.Clear();
56 
57  array<int> requesterIDs = {};
58 
59  group.GetRequesterIDs(requesterIDs);
60 
61  for (int i = 0, count = requesterIDs.Count(); i < count ;i++)
62  {
63  Widget entryWidget = GetGame().GetWorkspace().CreateWidgets(REQUESTER_ENTRY_LAYOUT, content);
64  if (!entryWidget)
65  continue;
66 
67  TextWidget playerName = TextWidget.Cast(entryWidget.FindAnyWidget("PlayerName"));
68  if (!playerName)
69  continue;
70 
71  ButtonWidget refuseWidget = ButtonWidget.Cast(entryWidget.FindAnyWidget("Refuse"));
72  if (!refuseWidget)
73  continue;
74 
75  ButtonWidget acceptWidget = ButtonWidget.Cast(entryWidget.FindAnyWidget("Accept"));
76  if (!acceptWidget)
77  continue;
78 
79  SCR_ButtonComponent refuseButton = SCR_ButtonComponent.Cast(refuseWidget.FindHandler(SCR_ButtonComponent));
80  if (!refuseButton)
81  continue;
82 
83  SCR_ButtonComponent acceptButton = SCR_ButtonComponent.Cast(acceptWidget.FindHandler(SCR_ButtonComponent));
84  if (!acceptButton)
85  continue;
86 
87  SCR_JoinRequestEntry entry = SCR_JoinRequestEntry.Cast(entryWidget.FindHandler(SCR_JoinRequestEntry));
88  if (!entry)
89  continue;
90 
91  m_aEntryWidgets.Insert(entryWidget);
92 
93  entry.SetPlayerID(requesterIDs[i]);
94 
95  playerName.SetText(GetGame().GetPlayerManager().GetPlayerName(requesterIDs[i]));
96 
97  acceptButton.m_OnClicked.Insert(AcceptToJoinPrivateGroup);
98  refuseButton.m_OnClicked.Insert(RefuseJoinPrivateGroup);
99  }
100 
101  // TODO: a sub menu tab should not call a method on the menu class. This should be an invoker
102  SCR_GroupMenu groupMenu = SCR_GroupMenu.Cast(ChimeraMenuBase.GetOwnerMenu(GetRootWidget()));
103  if (!groupMenu)
104  return;
105 
106  groupMenu.UpdateTabs();
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  void AcceptToJoinPrivateGroup()
111  {
112  Widget widgetEntry = GetRootWidget().FindAnyWidget("RequesterEntry");
113  if (!widgetEntry)
114  return;
115 
116  SCR_JoinRequestEntry entry = SCR_JoinRequestEntry.Cast(widgetEntry.FindHandler(SCR_JoinRequestEntry));
117  if (!entry)
118  return;
119 
120  SCR_PlayerControllerGroupComponent playerGroupComponent = SCR_PlayerControllerGroupComponent.GetPlayerControllerComponent(GetGame().GetPlayerController().GetPlayerId());
121  if (!playerGroupComponent)
122  return;
123 
124  playerGroupComponent.AcceptJoinPrivateGroup(entry.GetPlayerID(), true);
125 
126  GetGame().GetCallqueue().CallLater(InvokeOnJoinRequestRespond, 200); //call later because requesters are updated before array is clear
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  void RefuseJoinPrivateGroup()
131  {
132  Widget widgetEntry = GetRootWidget().FindAnyWidget("RequesterEntry");
133  if (!widgetEntry)
134  return;
135 
136  SCR_JoinRequestEntry entry = SCR_JoinRequestEntry.Cast(widgetEntry.FindHandler(SCR_JoinRequestEntry));
137  if (!entry)
138  return;
139 
140  SCR_PlayerControllerGroupComponent playerGroupComponent = SCR_PlayerControllerGroupComponent.GetPlayerControllerComponent(GetGame().GetPlayerController().GetPlayerId());
141  if (!playerGroupComponent)
142  return;
143 
144  playerGroupComponent.AcceptJoinPrivateGroup(entry.GetPlayerID(), false);
145 
146  GetGame().GetCallqueue().CallLater(InvokeOnJoinRequestRespond, 200); //call later because requesters are updated before array is clear
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected void InvokeOnJoinRequestRespond()
151  {
152  if (m_OnJoinRequestRespond)
153  m_OnJoinRequestRespond.Invoke();
154  }
155 }
ChimeraMenuBase
Constant variables used in various menus.
Definition: ChimeraMenuBase.c:70
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SubMenuBase
Definition: SCR_SubMenuBase.c:6
SCR_RequestToJoinSubmenu
Definition: SCR_RequestToJoinSubMenu.c:1
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_GroupMenu
Definition: SCR_GroupMenu.c:1
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
SCR_ButtonComponent
Deprecated button component. Still used in many prefabs, so it works, it's just stripped of most of t...
Definition: SCR_ButtonComponent.c:4
SCR_JoinRequestEntry
Definition: SCR_JoinRequestEntry.c:1
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
SCR_AIGroup
Definition: SCR_AIGroup.c:68
GetPlayerId
proto external int GetPlayerId()
Definition: SCR_SpawnRequestComponent.c:39