Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
CareerMenuUI.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  // Widget names
5  protected const string WIDGET_NAME_EDIT = "editPlayerName";
6  protected const string WIDGET_LOADOUT_STATS = "hLoadoutPanel";
7  protected const string WIDGET_CHARACTER_PREVIEW = "CharacterPreview";
8 
9  protected const string STRING_UNKNOWN_STAT = "Unknown";
10 
11  // Resources
12  const ResourceName ENTRY_LAYOUT = "{C87F7F6734B61688}UI/layouts/Menus/Career/CareerEntry.layout";
13 
14  // Components
15  protected ref SCR_EditBoxComponent m_EditPlayerName;
16  protected ref SCR_LoadoutPreviewComponent m_LoadoutPreview;
17  protected SCR_LoadoutManager m_LoadoutManager;
18  protected ref SCR_LoadoutStatisticsComponent m_LoadoutStatistics;
19 
20  // Widgets
21  protected Widget m_wEditPlayerName;
22 
23  //private EditBoxWidget m_ProfileEditbox;
24  //private Widget m_ProfileData;
25  protected ref array<string> m_aBackendValues = new array<string>();
26 
27  // Values
28  static CareerMenuUI m_sInstance;
29  ref CareerBackendData m_BackendData;
30  protected ref CareerCallback m_Callback = new CareerCallback();
31 
32  [MenuBindAttribute()]
33  ButtonWidget Back;
34 
35  //------------------------------------------------------------------------------------------------
36  [MenuBindAttribute()]
37  void Back()
38  {
39  if (IsFocused())
40  Close();
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  protected void CreateStatEntry(Widget wParent, string sName, string sLabel, string sValue)
45  {
46  Widget entry = GetGame().GetWorkspace().CreateWidgets(ENTRY_LAYOUT, wParent);
47  entry.SetName(sName);
48 
49  // Setup label
50  string sLabelName = "txtLabel";
51  TextWidget wLabel = TextWidget.Cast(entry.FindAnyWidget(sLabelName));
52  if(wLabel)
53  wLabel.SetText(sLabel);
54 
55  ItemPreviewWidget preview;
56 
57  // set value
58  //SetStatValue(sName, sValue);
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  override bool OnChange(Widget w, int x, int y, bool finished)
63  {
64  if (!finished || !m_EditPlayerName || w != m_EditPlayerName.GetRootWidget())
65  return false;
66 
67  // TODO: Future feature of custom name
68 
69  return false;
70  }
71 
72  //------------------------------------------------------------------------------------------------\
73  protected void OnPlayerNameConfirm(string value)
74  {
75  if (value.IsEmpty())
76  return;
77 
78  string nameOld = SCR_Global.GetProfileName();
79  //string nameNew = m_ProfileEditbox.GetText();
80  string nameNew = m_EditPlayerName.GetValue();
81  nameNew = nameNew.Trim();
82  // TODO: Future feature of custom name
83  m_EditPlayerName.SetValue(nameOld);
84  }
85 
86  //------------------------------------------------------------------------------------------------
87  void UpdateCareerData()
88  {
89  if (!m_BackendData)
90  return;
91  Widget wClassList = GetGame().GetWorkspace().FindAnyWidget("vStatList");
92 
93  if (m_aBackendValues.Count() == 0)
94  {
95  // Prepare stats array
96  typename stats = ECareerStatId;
97  int count = stats.GetVariableCount();
98  for (int i = 0; i < count; i++)
99  {
100  m_aBackendValues.Insert("");
101  }
102  }
103 
104  // General
105  m_aBackendValues[ECareerStatId.KILLS] = m_BackendData.GetKills().ToString();
106  m_aBackendValues[ECareerStatId.DEATHS] = m_BackendData.GetDeaths().ToString();
107  m_aBackendValues[ECareerStatId.FRIENDLY_KILLS] = m_BackendData.GetFriendlyKills().ToString();
108 
109  // Playtime
110  m_aBackendValues[ECareerStatId.PLAYTIME_RIFFLEMAN] = STRING_UNKNOWN_STAT;
111  m_aBackendValues[ECareerStatId.PLAYIME_SHARPSHOOTER] = STRING_UNKNOWN_STAT;
112 
113  // Weapons
114  m_aBackendValues[ECareerStatId.HEADSHOTS] = STRING_UNKNOWN_STAT;
115 
116  if (m_LoadoutStatistics)
117  m_LoadoutStatistics.UpdateStats(m_LoadoutStatistics.GetCurrentLoadoutId());
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  array<string> GetBackendValues() { return m_aBackendValues; }
122 
123  //------------------------------------------------------------------------------------------------
124  protected void TestingShow()
125  {
126  Widget wEntry = GetRootWidget().FindAnyWidget("StatEntry");
127 
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  override void OnMenuUpdate(float tDelta)
132  {
133  if (!m_BackendData && GetGame().GetBackendApi().IsAuthenticated())
134  {
135  m_BackendData = new CareerBackendData;
136  BackendApi backendApi = GetGame().GetBackendApi();
137  if (backendApi)
138  backendApi.PlayerRequest(EBackendRequest.EBREQ_GAME_CharacterGet, m_Callback, m_BackendData, 0);
139  }
140 
141  super.OnMenuUpdate(tDelta);
142  }
143 
144  //------------------------------------------------------------------------------------------------
145  override void OnMenuShow()
146  {
147  // Disallow changing profile name on consoles
148  #ifndef PLATFORM_WINDOWS
149  if (m_wEditPlayerName)
150  m_wEditPlayerName.SetEnabled(false);
151  #endif
152 
153  // Player name edit
154  m_wEditPlayerName = GetRootWidget().FindAnyWidget(WIDGET_NAME_EDIT);
155  if (m_wEditPlayerName)
156  m_EditPlayerName = SCR_EditBoxComponent.Cast(m_wEditPlayerName.FindHandler(SCR_EditBoxComponent));
157 
158  if (m_EditPlayerName)
159  {
160  // Listeners
161  m_EditPlayerName.m_OnConfirm.Insert(OnPlayerNameConfirm);
162  // Setup text
163  string profileName = SCR_Global.GetProfileName();
164  m_EditPlayerName.SetValue(profileName);
165  }
166 
167  super.OnMenuShow();
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  override void OnMenuOpen()
172  {
173  Widget w = GetRootWidget();
174  m_sInstance = this;
175  InputManager inputManager = GetGame().GetInputManager();
176  inputManager.AddActionListener( "MenuBack", EActionTrigger.PRESSED, Back );
177 
178  // Preview character
179  Widget wCharacterPreview = GetRootWidget().FindAnyWidget(WIDGET_CHARACTER_PREVIEW);
180  if (wCharacterPreview)
181  m_LoadoutPreview = SCR_LoadoutPreviewComponent.Cast(wCharacterPreview.FindHandler(SCR_LoadoutPreviewComponent));
182 
183  //m_LoadoutManager = SCR_LoadoutManager.GetInstance();
184 
185  // Loadout stats
186  Widget wLoadoutStats = GetRootWidget().FindAnyWidget(WIDGET_LOADOUT_STATS);
187  if (wLoadoutStats)
188  m_LoadoutStatistics = SCR_LoadoutStatisticsComponent.Cast(wLoadoutStats.FindHandler(SCR_LoadoutStatisticsComponent));
189 
190  if (m_LoadoutStatistics)
191  {
192  m_LoadoutStatistics.SetCareerUI(this);
193  m_LoadoutStatistics.m_OnLoadoutChange.Insert(OnLoadoutChange);
194  OnLoadoutChange(m_LoadoutStatistics.GetCurrentLoadoutId());
195  }
196 
197  super.OnMenuOpen();
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  override void OnMenuClose()
202  {
203  m_sInstance = null;
204 
205  super.OnMenuClose();
206  }
207 
208  //------------------------------------------------------------------------------------------------
209  protected void OnLoadoutChange(int id)
210  {
211  if (!m_LoadoutPreview || !m_LoadoutStatistics)
212  return;
213 
214  //m_LoadoutPreview.SetPreviewedLoadout(m_LoadoutManager.m_aPlayerLoadouts[0]);
215  LoadoutStatSet statSet = m_LoadoutStatistics.GetLodoutStatSets()[id];
216  if (statSet)
217  m_LoadoutPreview.SetPreviewedLoadout(statSet.GetLoadout());
218  }
219 };
220 
221 //------------------------------------------------------------------------------------------------
223 {
224  override void OnSuccess( int code )
225  {
226  if (CareerMenuUI.m_sInstance)
227  CareerMenuUI.m_sInstance.UpdateCareerData();
228  }
229  override void OnError( int code, int restCode, int apiCode )
230  {
231  Print("[BackendCallback] OnError: "+ GetGame().GetBackendApi().GetErrorCode(code));
232  }
233  override void OnTimeout()
234  {
235  Print("[BackendCallback] OnTimeout");
236  }
237 };
238 
239 //------------------------------------------------------------------------------------------------
242 {
243  // General
247 
248  // Play times
251 
252  // Weapons
254 };
255 
ChimeraMenuBase
Constant variables used in various menus.
Definition: ChimeraMenuBase.c:70
FRIENDLY_KILLS
@ FRIENDLY_KILLS
Definition: CareerMenuUI.c:246
DEATHS
@ DEATHS
Definition: CareerMenuUI.c:245
SCR_LoadoutStatisticsComponent
Class for switching and displaying stats for different loadouts.
Definition: SCR_LoadoutStatistics.c:4
LoadoutStatSet
Definition: SCR_LoadoutStatistics.c:176
PLAYTIME_RIFFLEMAN
@ PLAYTIME_RIFFLEMAN
Definition: CareerMenuUI.c:249
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_LoadoutManager
void SCR_LoadoutManager(IEntitySource src, IEntity parent)
Definition: SCR_LoadoutManager.c:500
m_Callback
protected ref CampaignCallback m_Callback
Definition: SCR_PlayerProfileManagerComponent.c:25
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
HEADSHOTS
@ HEADSHOTS
Definition: CareerMenuUI.c:253
CareerCallback
Definition: CareerMenuUI.c:222
CareerBackendData
Definition: CareerBackend.c:43
BackendCallback
Base server browser callback.
Definition: SCR_ServerListComponent.c:4
ECareerStatId
ECareerStatId
Ids to receive all.
Definition: CareerMenuUI.c:241
SCR_Global
Definition: Functions.c:6
PLAYIME_SHARPSHOOTER
@ PLAYIME_SHARPSHOOTER
Definition: CareerMenuUI.c:250
ItemPreviewWidget
Definition: ItemPreviewWidget.c:12
SCR_EditBoxComponent
Definition: SCR_EditBoxComponent.c:8
CareerMenuUI
Definition: CareerMenuUI.c:2
SCR_LoadoutPreviewComponent
Definition: SCR_LoadoutPreviewComponent.c:1
KILLS
@ KILLS
Definition: CareerMenuUI.c:244