Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
mainmenustats.c
Go to the documentation of this file.
1 class MainMenuStats extends ScriptedWidgetEventHandler
2 {
3  protected Widget m_Root;
4 
5  protected Widget m_TimeSurvived;
6  protected TextWidget m_TimeSurvivedValue;
7 
8  protected Widget m_PlayersKilled;
9  protected TextWidget m_PlayersKilledValue;
10 
11  protected Widget m_InfectedKilled;
12  protected TextWidget m_InfectedKilledValue;
13 
14  protected Widget m_DistanceTraveled;
15  protected TextWidget m_DistanceTraveledValue;
16 
17  protected Widget m_LongRangeShot;
18  protected TextWidget m_LongRangeShotValue;
19 
20  private ref FullTimeData m_TimeSurvivedFull;
21 
22  void MainMenuStats(Widget root)
23  {
24  m_Root = root;
25 
26  m_TimeSurvivedFull = new FullTimeData();
27 
28  m_TimeSurvived = m_Root.FindAnyWidget("TimeSurvived");
29  m_TimeSurvivedValue = TextWidget.Cast(m_Root.FindAnyWidget("TimeSurvivedValue"));
30 
31  m_PlayersKilled = m_Root.FindAnyWidget("PlayersKilled");
32  m_PlayersKilledValue = TextWidget.Cast(m_Root.FindAnyWidget("PlayersKilledValue"));
33 
34  m_InfectedKilled = m_Root.FindAnyWidget("InfectedKilled");
35  m_InfectedKilledValue = TextWidget.Cast(m_Root.FindAnyWidget("InfectedKilledValue"));
36 
37  m_DistanceTraveled = m_Root.FindAnyWidget("DistanceTraveled");
38  m_DistanceTraveledValue = TextWidget.Cast(m_Root.FindAnyWidget("DistanceTraveledValue"));
39 
40  m_LongRangeShot = m_Root.FindAnyWidget("LongRangeShot");
41  m_LongRangeShotValue = TextWidget.Cast(m_Root.FindAnyWidget("LongRangeShotValue"));
42  }
43 
44  void ShowStats()
45  {
46  m_Root.Show(true);
47  UpdateStats();
48  }
49 
50  void HideStats()
51  {
52  m_Root.Show(false);
53  }
54 
55  void UpdateStats()
56  {
57  PlayerBase player;
58  MissionMainMenu missionMainMenu = MissionMainMenu.Cast(GetGame().GetMission());
59 
60  if (missionMainMenu && missionMainMenu.GetIntroScenePC())
61  {
62  #ifdef PLATFORM_WINDOWS
63  player = missionMainMenu.GetIntroScenePC().GetIntroCharacter().GetCharacterObj();
64  #endif
65  #ifdef PLATFORM_CONSOLE
66  player = missionMainMenu.GetIntroScenePC().GetIntroCharacter().GetCharacterObj();
67  #endif
68 
69  if (player)
70  {
71  TimeConversions.ConvertSecondsToFullTime(player.StatGet(AnalyticsManagerServer.STAT_PLAYTIME), m_TimeSurvivedFull);
72  m_TimeSurvivedValue.SetText(m_TimeSurvivedFull.FormatedNonZero());
73 
74  m_PlayersKilledValue.SetText(GetValueString(player.StatGet(AnalyticsManagerServer.STAT_PLAYERS_KILLED)));
75  m_InfectedKilledValue.SetText(GetValueString(player.StatGet(AnalyticsManagerServer.STAT_INFECTED_KILLED)));
76  m_DistanceTraveledValue.SetText(GetDistanceString(player.StatGet(AnalyticsManagerServer.STAT_DISTANCE)));
77  m_LongRangeShotValue.SetText(GetDistanceString(player.StatGet(AnalyticsManagerServer.STAT_LONGEST_SURVIVOR_HIT), true));
78  }
79  }
80  }
81 
82  protected string GetDistanceString( float total_distance, bool meters_only = false )
83  {
84  if (total_distance > 0)
85  {
86  string distanceString;
87 
88  float kilometers = total_distance * 0.001;
89  kilometers = Math.Round(kilometers);
90  if ( kilometers >= 10 && !meters_only )
91  {
92  distanceString = GetValueString(kilometers, true) + " #STR_distance_unit_abbrev_kilometer_0";
93  }
94  else
95  {
96  distanceString = GetValueString(total_distance) + " #STR_distance_unit_abbrev_meter_0";
97  }
98 
99  return distanceString;
100  }
101 
102  return "0" + " #STR_distance_unit_abbrev_meter_0";
103  }
104 
105  protected string GetValueString(float total_value, bool show_decimals = false)
106  {
107  if (total_value > 0)
108  {
109  string out_string;
110 
111  int total_value_int = total_value;
112  string number_str = total_value_int.ToString();
113 
114  //number
115  if ( total_value >= 1000 )
116  {
117  int count;
118  int first_length = number_str.Length() % 3; //calculate position of the first separator
119  if ( first_length > 0 )
120  {
121  count = 3 - first_length;
122  }
123 
124  for ( int i = 0; i < number_str.Length(); ++i )
125  {
126  out_string += number_str.Get( i );
127  count ++;
128 
129  if ( count >= 3 )
130  {
131  out_string += " "; //separator
132  count = 0;
133  }
134  }
135  }
136  else
137  {
138  out_string = number_str;
139  }
140 
141  //decimals
142  if ( show_decimals )
143  {
144  string total_value_str = total_value.ToString();
145  int decimal_idx = total_value_str.IndexOf( "." );
146 
147  if ( decimal_idx > -1 )
148  {
149  out_string.TrimInPlace();
150  out_string += total_value_str.Substring( decimal_idx, total_value_str.Length() - decimal_idx );
151  }
152  }
153 
154  return out_string;
155  }
156 
157  return "0";
158  }
159 
163  protected string GetTimeString(float total_time);
164 }
GetGame
proto native CGame GetGame()
AnalyticsManagerServer
Definition: analyticsmanagerserver.c:1
PlayerBase
Definition: playerbaseclient.c:1
TextWidget
Definition: enwidgets.c:219
FullTimeData
struct that keeps Time relevant information for future formatting
Definition: timeconversions.c:4
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650