Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
FeedbackDialogUI.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class FeedbackData extends JsonApiStruct
3 {
5  protected string m_sTypeTag;
6  protected string m_sTypeName;
8  protected string m_sCategoryTag;
9  protected string m_sCategoryName;
10 
12  protected string m_sContent;
13 
15  protected string m_sUserName;
16 
19  protected string m_sBuildTime;
21  protected string m_sBuildVersion;
22 
25  protected string m_sWorldFile;
28  protected string m_sSubmitTime;
29 
31  protected vector m_vWorldPosition;
33  protected vector m_vWorldRotation;
34 
36  protected string m_sMessage;
37 
38  //------------------------------------------------------------------------------------------------
39  string FormatMessage()
40  {
41  const string altsep = "-----------------------------\n";
42  string res = "\n";
43 
44  res += string.Format("Type: %1\n", GetFeedbackType());
45  res += string.Format("Category: %1\n", GetFeedbackCategory());
46  res += string.Format("User: %1\n", GetUserName());
47 
48  // assembly link to WE
49  res += string.Format("<enfusion://WorldEditor/%1;%2,%3,%4;%5,%6,%7|Enfusion Link>\n",
50  GetWorldFile(),
51  m_vWorldPosition[0].ToString(),
52  m_vWorldPosition[1].ToString(),
53  m_vWorldPosition[2].ToString(),
54  m_vWorldRotation[1].ToString(),
55  m_vWorldRotation[2].ToString(),
56  m_vWorldRotation[0].ToString());
57 
58  res += string.Format("Build Version: %1\n", GetBuildVersion());
59  res += string.Format("Submit Time: %1\n", GetFeedbackSubmitTime());
60  res += string.Format("Build Time: %1\n", GetBuildTime());
61  res += string.Format("World File: %1\n", GetWorldFile());
62 
63  // position && message
64  res += string.Format("Position: %1\n", m_vWorldPosition.ToString());
65  res += string.Format("Rotation: %1\n", m_vWorldRotation.ToString());
66 
67  res += altsep;
68  res += "FEEDBACK USER DATA:\n";
69  res += m_sContent;
70 
71 
72  m_sMessage = res;
73 
74  return m_sMessage;
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  string GetWorldFile()
79  {
80  return m_sWorldFile;
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  string GetUserName()
85  {
86  return m_sUserName;
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  string GetBuildTime()
91  {
92  return m_sBuildTime;
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  string GetBuildVersion()
97  {
98  return m_sBuildVersion;
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  string GetFeedbackSubmitTime()
103  {
104  return m_sSubmitTime;
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  string GetFeedbackType()
109  {
110  return m_sTypeName;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  string GetFeedbackCategory()
115  {
116  return m_sCategoryName;
117  }
118 
119  //------------------------------------------------------------------------------------------------
120  string GetFeedbackContent()
121  {
122  return m_sContent;
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  protected string GetCurrentTimestamp()
127  {
128  int year, month, day, hour, minute, sec;
129  System.GetYearMonthDay(year, month, day);
130  System.GetHourMinuteSecond(hour, minute, sec);
131  string smonth, sday, shour, sminute, ssec;
132  if(month < 10)
133  smonth = string.Format("0%1", month);
134  else
135  smonth = string.Format("%1", month);
136 
137  if(day < 10)
138  sday = string.Format("0%1", day);
139  else
140  sday = string.Format("%1", day);
141 
142  if (hour < 10)
143  shour = string.Format("0%1", hour);
144  else
145  shour = string.Format("%1", hour);
146 
147  if (minute < 10)
148  sminute = string.Format("0%1", minute);
149  else
150  sminute = string.Format("%1", minute);
151 
152  if (sec < 10)
153  ssec = string.Format("0%1", sec);
154  else
155  ssec = string.Format("%1", sec);
156 
157  return string.Format("%1-%2-%3 %4:%5:%6", year, smonth, sday, shour, sminute, ssec);
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  protected bool FetchCoords()
162  {
163  ArmaReforgerScripted game = GetGame();
164  if(game)
165  {
166  BaseWorld world = game.GetWorld();
167  if (world)
168  {
169  int cameraId = world.GetCurrentCameraId();
170  // get current engine camera transformation
171  vector mat[4];
172  world.GetCamera(cameraId, mat);
173  vector yawPitchRoll = Math3D.MatrixToAngles(mat);
174  m_vWorldPosition = mat[3];
175 
176  // yawpitchroll->pitchyawroll
177  m_vWorldRotation[0] = yawPitchRoll[1];
178  m_vWorldRotation[1] = yawPitchRoll[0];
179  m_vWorldRotation[2] = yawPitchRoll[2];
180  return true;
181  }
182  }
183 
184  // Plausible defaults
185  m_vWorldPosition = Vector(0,0,0);
186  m_vWorldRotation = Vector(0,0,0);
187  return false;
188  }
189 
190  //------------------------------------------------------------------------------------------------
192  void FeedbackData( string typeTag, string typeName, string catTag, string catName, string content)
193  {
194  // ...
195  // data below are structured, send as JSON!
196  RegV("m_sTypeName");
197  RegV("m_sCategoryName");
198  RegV("m_sContent");
199  RegV("m_sUserName");
200 
201  RegV("m_sBuildTime");
202  RegV("m_sBuildVersion");
203 
204  RegV("m_sWorldFile");
205  RegV("m_sSubmitTime");
206 
207  RegV("m_vWorldPosition");
208  RegV("m_vWorldRotation");
209  // ...
210 
211 
212  m_sTypeTag = typeTag;
213  m_sCategoryTag = catTag;
214 
215  m_sTypeName = typeName;
216  m_sCategoryName = catName;
217 
218  m_sContent = content;
219 
220  ArmaReforgerScripted game = GetGame();
221  if (!game)
222  return;
223 
224  // TODO: Not sure if the user name should be directly sent. Same goes for platform specific UID
225  m_sUserName = SCR_Global.GetProfileName();
226  m_sBuildTime = game.GetBuildTime();
227  m_sBuildVersion = game.GetBuildVersion();
228 
229  m_sWorldFile = game.GetWorldFile();
230  m_sSubmitTime = GetCurrentTimestamp();
231 
232  // Fetch coords data
233  FetchCoords();
234  }
235 
236 };
237 
238 //------------------------------------------------------------------------------------------------
240 {
242  static const int TYPE_NAMES_COUNT = 2;
243  static const string TYPE_TAGS[TYPE_NAMES_COUNT] =
244  {
245  "feedback",
246  "issue"
247  };
248  static const LocalizedString TYPE_NAMES[TYPE_NAMES_COUNT] =
249  {
250  "#AR-MainMenu_Feedback_Name",
251  "#AR-Feedback_Issue"
252  };
253 
255  static const int CATEGORY_NAMES_COUNT = 8;
256  static const string CATEGORY_TAGS[CATEGORY_NAMES_COUNT] =
257  {
258  "general",
259  "ui",
260  "editor",
261  "character",
262  "vehicles",
263  "weapons",
264  "multiplayer",
265  "conflict"
266  };
267  static const LocalizedString CATEGORY_NAMES[CATEGORY_NAMES_COUNT] =
268  {
269  "#AR-Feedback_General",
270  "#AR-Feedback_UI",
271  "#AR-MainMenu_Editor_Name",
272  "#AR-Feedback_Character",
273  "#AR-Feedback_Vehicles",
274  "#AR-Feedback_Weapons",
275  "#AR-MainMenu_Multiplayer_Name",
276  "#AR-MainMenu_Conflict_Name"
277  };
278 
279  protected SCR_EditBoxComponent m_EditBox;
280  protected SCR_ComboBoxComponent m_Type;
281  protected SCR_ComboBoxComponent m_Category;
282 
283  protected static ref FeedbackData m_LastFeedback;
284  protected static float m_fLastFeedbackTime = -float.MAX;
285  protected static const float FEEDBACK_SEND_TIMEOUT = 5000; // ms
286 
287  SCR_InputButtonComponent m_CreateAccount;
288  protected bool m_bShouldEnableConfirmButton;
289 
290  //------------------------------------------------------------------------------------------------
291  override protected void OnConfirm()
292  {
293  if (!m_Type || !m_Category || !m_EditBox)
294  return;
295 
296  // Fetch feedback data
297  int type = m_Type.GetCurrentIndex();
298  int category = m_Category.GetCurrentIndex();
299  string content = m_EditBox.GetValue();
300  SendFeedback(content, type, category);
301 
302  super.OnConfirm();
303  }
304 
305  //------------------------------------------------------------------------------------------------
306  override void OnMenuShow()
307  {
308  if (m_Type)
309  GetGame().GetWorkspace().SetFocusedWidget(m_Type.GetRootWidget());
310  }
311 
312  //------------------------------------------------------------------------------------------------
313  override void OnMenuUpdate(float tDelta)
314  {
315  super.OnMenuUpdate(tDelta);
316 
317  GetGame().GetInputManager().ActivateContext("InteractableDialogContext");
318  }
319 
320  //------------------------------------------------------------------------------------------------
321  static FeedbackDialogUI OpenFeedbackDialog()
322  {
323  ArmaReforgerScripted game = GetGame();
324  if (!game)
325  return null;
326 
327  MenuManager menuManager = game.GetMenuManager();
328  if (!menuManager)
329  return null;
330 
331  MenuBase dialog = menuManager.FindMenuByPreset(ChimeraMenuPreset.FeedbackDialog);
332  if (!dialog)
333  dialog = menuManager.OpenDialog(ChimeraMenuPreset.FeedbackDialog, DialogPriority.INFORMATIVE, 0, true);
334 
335  return FeedbackDialogUI.Cast(dialog);
336  }
337 
338  //------------------------------------------------------------------------------------------------
339  static bool CanSendFeedback()
340  {
341  BaseWorld world = GetGame().GetWorld();
342  if (!world)
343  return false;
344 
345  float timeSinceLast = world.GetWorldTime() - m_fLastFeedbackTime;
346  return timeSinceLast > FEEDBACK_SEND_TIMEOUT;
347  }
348 
349  //------------------------------------------------------------------------------------------------
350  static void SendFeedback(string content, int type, int category)
351  {
352  // Create container for our feedback
353  m_LastFeedback = NULL;
354  m_LastFeedback = new FeedbackData(TYPE_TAGS[type], TYPE_NAMES[type], CATEGORY_TAGS[category], CATEGORY_NAMES[category], content);
355  string summary = m_LastFeedback.FormatMessage();
356 
357  GetGame().GetBackendApi().FeedbackMessage(null,m_LastFeedback,summary);
358  m_fLastFeedbackTime = GetGame().GetWorld().GetWorldTime();
359  }
360 
361  //------------------------------------------------------------------------------------------------
362  static void ClearFeedback()
363  {
364  m_LastFeedback = null;
365  }
366 
367  //------------------------------------------------------------------------------------------------
368  private void OnCreateAccount()
369  {
370  GetGame().GetPlatformService().OpenBrowser(GetGame().GetBackendApi().GetLinkItem("Link_PrivacyPolicy"));
371  }
372 
373  //------------------------------------------------------------------------------------------------
374  override void OnMenuOpen()
375  {
376  super.OnMenuOpen();
377  m_Confirm.SetEnabled(false, false);
378  Widget w = GetRootWidget();
379  m_EditBox = SCR_EditBoxComponent.GetEditBoxComponent("EditBox", w);
380 
381  m_Type = SCR_ComboBoxComponent.GetComboBoxComponent("FeedbackType", w);
382  if (m_Type)
383  {
384  for (int i = 0; i < TYPE_NAMES_COUNT; i++)
385  {
386  m_Type.AddItem(TYPE_NAMES[i]);
387  }
388  m_Type.SetCurrentItem(0);
389  }
390 
391  m_Category = SCR_ComboBoxComponent.GetComboBoxComponent("FeedbackCategory", w);
392  if (m_Category)
393  {
394  for (int i = 0; i < CATEGORY_NAMES_COUNT; i++)
395  {
396  m_Category.AddItem(CATEGORY_NAMES[i]);
397  }
398  m_Category.SetCurrentItem(0);
399  }
400 
401  m_CreateAccount = SCR_InputButtonComponent.GetInputButtonComponent("CreateAccount", w);
402  if (m_CreateAccount)
403  m_CreateAccount.m_OnActivated.Insert(OnCreateAccount);
404 
405  if(m_EditBox)
406  {
407  m_EditBox.m_OnWriteModeLeave.Insert(OnWriteModeLeave);
408  m_EditBox.m_OnTextChange.Insert(OnTextChange);
409  }
410  }
411 
412  //------------------------------------------------------------------------------------------------
413  protected void OnWriteModeLeave(string text)
414  {
415  OnTextChange(text);
416  }
417 
418  //------------------------------------------------------------------------------------------------
419  protected void OnTextChange(string text)
420  {
421  if (!m_Confirm)
422  return;
423 
424  m_bShouldEnableConfirmButton = m_EditBox.GetValue() != string.Empty && FeedbackDialogUI.CanSendFeedback();
425 
426  m_Confirm.SetEnabled(m_bShouldEnableConfirmButton);
427  }
428 };
SCR_ComboBoxComponent
Definition: SCR_ComboBoxComponent.c:1
FeedbackDialogUI
Definition: FeedbackDialogUI.c:239
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
JsonApiStruct
Parameters for joining server.
Definition: FeedbackDialogUI.c:2
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
NULL
PauseMenuUI NULL
m_Type
protected EEditableEntityType m_Type
Definition: SCR_EntitiesToolbarEditorUIComponent.c:3
DialogUI
Definition: DialogUI.c:1
SCR_Global
Definition: Functions.c:6
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_EditBoxComponent
Definition: SCR_EditBoxComponent.c:8
LocalizedString
Definition: LocalizedString.c:21
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180