DayZ 1.24
Loading...
Searching...
No Matches
MainMenuStats.c
Go to the documentation of this file.
1class MainMenuStats extends ScriptedWidgetEventHandler
2{
3 protected Widget m_Root;
4
7
10
13
16
19
21
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);
48 }
49
50 void HideStats()
51 {
52 m_Root.Show(false);
53 }
54
56 {
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;
90 if (kilometers >= 10 && !meters_only)
91 distanceString = GetValueString(kilometers, true) + " #STR_distance_unit_abbrev_kilometer_0";
92 else
93 distanceString = GetValueString(total_distance) + " #STR_distance_unit_abbrev_meter_0";
94
95 return distanceString;
96 }
97
98 return "0" + " #STR_distance_unit_abbrev_meter_0";
99 }
100
101 protected string GetValueString(float total_value, bool show_decimals = false)
102 {
103 if (total_value > 0)
104 {
105 string out_string;
106
108 string number_str = total_value_int.ToString();
109
110 //number
111 if (total_value >= 1000)
112 {
113 int count;
114 int first_length = number_str.Length() % 3; //calculate position of the first separator
115 if (first_length > 0)
116 count = 3 - first_length;
117
118 for (int i = 0; i < number_str.Length(); ++i)
119 {
120 out_string += number_str.Get(i);
121 count ++;
122
123 if (count >= 3)
124 {
125 out_string += " "; //separator
126 count = 0;
127 }
128 }
129 }
130 else
132
133 //decimals
134 if (show_decimals)
135 {
136 string total_value_str = total_value.ToString();
137 int decimal_idx = total_value_str.IndexOf(".");
138
139 if (decimal_idx > -1)
140 {
141 out_string.TrimInPlace();
143 }
144 }
145
146 return out_string;
147 }
148
149 return "0";
150 }
151
155 protected string GetTimeString(float total_time);
156}
Widget m_Root
Definition SizeToChild.c:85
struct that keeps Time relevant information for future formatting
Definition EnMath.c:7
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void MainMenuStats(Widget root)
string GetDistanceString(float total_distance, bool meters_only=false)
string GetValueString(float total_value, bool show_decimals=false)
string GetTimeString(float total_time)
ref FullTimeData m_TimeSurvivedFull
proto native CGame GetGame()
static proto float Round(float f)
Returns mathematical round of value.