Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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
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 {
57 PlayerBase player;
58 MissionMainMenu missionMainMenu = MissionMainMenu.Cast(g_Game.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
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}
struct that keeps Time relevant information for future formatting
Definition enmath.c:7
map: item x vector(index, width, height)
Definition enwidgets.c:657
void MainMenuStats(Widget root)
ref FullTimeData m_TimeSurvivedFull
string GetValueString(float total_value, bool show_decimals=false)
string GetDistanceString(float total_distance, bool meters_only=false)
string GetTimeString(float total_time)
DEPRECATED.
proto string ToString(bool simple=true)
DayZGame g_Game
Definition dayzgame.c:3942
static proto float Round(float f)
Returns mathematical round of value.
proto string Substring(int start, int len)
Substring of 'str' from 'start' position 'len' number of characters.
proto string Get(int index)
Gets n-th character from string.
proto native int IndexOf(string sample)
Finds 'sample' in 'str'.
proto native int Length()
Returns length of string.
proto int TrimInPlace()
Removes leading and trailing whitespaces in string.
WorkspaceWidget Widget
Defined in code.
Widget m_Root
Definition sizetochild.c:91