Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FormatHelper.c
Go to the documentation of this file.
2{
3 //------------------------------------------------------------------------------------------------
16 static string FloatToDecString(float value, int maxLenDec)
17 {
18 return value.ToString(lenDec: maxLenDec).ToFloat().ToString();
19 }
20
21 //------------------------------------------------------------------------------------------------
26// [Obsolete("Use FloatToDecString instead")]
27 static string FloatToStringNoZeroDecimalEndings(float value, int maxLenDec)
28 {
29 return FloatToDecString(value, maxLenDec);
30 }
31
32 //------------------------------------------------------------------------------------------------
40 static string FormatDateTime(int year, int month, int day, int hour, int minute, int second)
41 {
42 return string.Format("%1 %2", FormatDate(year, month, day), FormatTime(hour, minute, second));
43 }
44
45 //------------------------------------------------------------------------------------------------
50 static string FormatDate(int year, int month, int day)
51 {
52 if (year < 100)
53 year += 2000;
54
55 return string.Format("%1-%2-%3", year.ToString(4), month.ToString(2), day.ToString(2));
56 }
57
58 //------------------------------------------------------------------------------------------------
61 static string FormatTime(int totalSeconds)
62 {
63 int hour, minute, second;
64 SCR_DateTimeHelper.GetHourMinuteSecondFromSeconds(totalSeconds, hour, minute, second);
65 return FormatTime(hour, minute, second);
66 }
67
68 //------------------------------------------------------------------------------------------------
72 static string FormatTimeMS(float totalSeconds, int precision = 0)
73 {
74 int hour, minute, second;
75 SCR_DateTimeHelper.GetHourMinuteSecondFromSeconds(totalSeconds, hour, minute, second);
76
77 return FormatTime(hour, minute, second) + "." + GetFormattedSubSeconds(totalSeconds, precision);
78 }
79
80 //------------------------------------------------------------------------------------------------
84 static string FormatTimeMSHideZeroes(float totalSeconds, int precision = 0)
85 {
86 int hour, minute, second;
87 SCR_DateTimeHelper.GetHourMinuteSecondFromSeconds(totalSeconds, hour, minute, second);
88
89 return GetTimeFormatting(0, hour, minute, second,
92 ) + "." + GetFormattedSubSeconds(totalSeconds, precision);
93 }
94
95 //------------------------------------------------------------------------------------------------
99 static string GetFormattedSubSeconds(float totalSeconds, int precision = 0)
100 {
101 if (precision < 1)
102 precision = -1;
103
104 string formattedSubSeconds = (totalSeconds - (int)totalSeconds).ToString(lenDec: precision);
105 if (formattedSubSeconds.Contains("."))
106 {
107 if (totalSeconds < 0)
108 formattedSubSeconds = formattedSubSeconds.Substring(3, formattedSubSeconds.Length() - 3); // removing -0.
109 else
110 formattedSubSeconds = formattedSubSeconds.Substring(2, formattedSubSeconds.Length() - 2); // removing 0.
111 }
112
113 return formattedSubSeconds;
114 }
115
116 //------------------------------------------------------------------------------------------------
121 static string FormatTime(int hour, int minute, int second)
122 {
123 return string.Format("%1:%2:%3", hour.ToString(2), minute.ToString(2), second.ToString(2));
124 }
125
126 //------------------------------------------------------------------------------------------------
137 static string GetTimeFormatting(int days, int hours, int minutes, int seconds, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
138 {
139 //Todo: Display days properly rather then dd:hh:mm:ss (Though right now it is extreamly edge case if days should be shown)
140 string returnString = "";
141
142 //To do: Decide the formatting of days. Currently it is dd:hh:mm:ss and by default days are hidden if it is 0 as it would rarely be a day or more
143 //Only show days
144 //if (days > -1 && ((hideEmpty & ETimeFormatParam.DAYS) && days > 0) || !(hideEmpty & ETimeFormatParam.DAYS))
145 if (days > 0 && (hideEmpty & ETimeFormatParam.DAYS) || !(hideEmpty & ETimeFormatParam.DAYS))
146 returnString += days.ToString();
147 else
148 days = -1;
149
150 //hours (Check if should display hours and check if should display leading zero)
151 if (hours > 0 && (hideEmpty & ETimeFormatParam.HOURS) || !(hideEmpty & ETimeFormatParam.HOURS))
152 returnString += ReturnTimeTypeString(days, hours, ((hideLeadingZeroes & ETimeFormatParam.HOURS) == 0) + 1);
153 else
154 hours = -1;
155
156 //Minutes (Check if should display Minutes and check if should display leading zero)
157 if (minutes > 0 && (hideEmpty & ETimeFormatParam.MINUTES) || !(hideEmpty & ETimeFormatParam.MINUTES))
158 returnString += ReturnTimeTypeString(hours, minutes, ((hideLeadingZeroes & ETimeFormatParam.MINUTES) == 0) + 1);
159 else
160 minutes = -1;
161
162 //Seconds (Check if should display Seconds and check if should display leading zero)
163 if (seconds > 0 && (hideEmpty & ETimeFormatParam.SECONDS) || !(hideEmpty & ETimeFormatParam.SECONDS))
164 returnString += ReturnTimeTypeString(minutes, seconds, ((hideLeadingZeroes & ETimeFormatParam.SECONDS) == 0) + 1);
165
166 return returnString;
167 }
168
169 //------------------------------------------------------------------------------------------------
175 protected static string ReturnTimeTypeString(int prevTimeTypeAmount, int currentTimeTypeAmount, int numberLength)
176 {
177 if (prevTimeTypeAmount > -1)
178 return ":" + currentTimeTypeAmount.ToString(numberLength);
179 else
180 return currentTimeTypeAmount.ToString(numberLength);
181 }
182
183 //------------------------------------------------------------------------------------------------
191 static string GetTimeFormatting(int totalSeconds, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
192 {
193 int days, hours, minutes, seconds;
194 SCR_DateTimeHelper.GetDayHourMinuteSecondFromSeconds(totalSeconds, days, hours, minutes, seconds);
195 return GetTimeFormatting(days, hours, minutes, seconds, hideEmpty, hideLeadingZeroes);
196 }
197
198 //------------------------------------------------------------------------------------------------
206 static string GetTimeFormattingHideSeconds(int totalSeconds, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
207 {
208 int days, hours, minutes, seconds;
209 SCR_DateTimeHelper.GetDayHourMinuteSecondFromSeconds(totalSeconds, days, hours, minutes, seconds);
210 return GetTimeFormatting(days, hours, minutes, -1, ETimeFormatParam.SECONDS | hideEmpty, hideLeadingZeroes);
211 }
212
213 //------------------------------------------------------------------------------------------------
220 static string GetTimeFormattingHoursMinutes(int hours, int minutes, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
221 {
222 return GetTimeFormatting(-1, hours, minutes, -1, (ETimeFormatParam.DAYS | ETimeFormatParam.SECONDS | hideEmpty), hideLeadingZeroes);
223 }
224
225 //------------------------------------------------------------------------------------------------
232 static string GetTimeFormattingMinutesSeconds(int minutes, int seconds, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
233 {
234 return GetTimeFormatting(-1, -1, minutes, seconds, (ETimeFormatParam.DAYS | ETimeFormatParam.HOURS | hideEmpty), hideLeadingZeroes);
235 }
236
237 //------------------------------------------------------------------------------------------------
242 protected static string GetTimeSinceEventString(int amount, string oneUnit, string manyUnits)
243 {
244 if (amount == 1)
245 return WidgetManager.Translate(oneUnit, amount);
246 else
247 return WidgetManager.Translate(manyUnits, amount);
248 }
249
250 //------------------------------------------------------------------------------------------------
254 static string GetTimeSinceEventImprecise(int timeDiffSeconds)
255 {
256 if (timeDiffSeconds < 0)
257 return string.Empty;
258
259 int days, hours, minutes, remainingSeconds;
260 SCR_DateTimeHelper.GetDayHourMinuteSecondFromSeconds(timeDiffSeconds, days, hours, minutes, remainingSeconds);
261
262 if (days > 0)
263 return GetTimeSinceEventString(days, "#AR-Date_DayAgo_LC", "#AR-Date_DaysAgo_LC"); // 23 days ago
264 else if (hours > 0)
265 return GetTimeSinceEventString(hours, "#AR-Time_HourAgo_LC", "#AR-Time_HoursAgo_LC"); // 23 hours ago
266 else
267 return GetTimeSinceEventString(minutes, "#AR-Time_MinuteAgo_LC", "#AR-Time_MinutesAgo_LC"); // 23 minutes ago
268 }
269
270 //------------------------------------------------------------------------------------------------
274 static string FormatFrequencies(notnull set<int> frequencies, set<int> highlightFrequencies = null)
275 {
276 if (frequencies.IsEmpty())
277 return string.Empty;
278
279 string text;
280 float accurateFrequency;
281 foreach (int i, int frequency : frequencies)
282 {
283 if (i > 0)
284 text += ", ";
285
286 accurateFrequency = frequency;
287 if (highlightFrequencies && highlightFrequencies.Contains(frequency))
288 text += string.Format("<color rgba='226,168,79,255'>%1</color>", accurateFrequency * 0.001); //--- ToDo: Don't hardcode color
289 else
290 text += (accurateFrequency * 0.001).ToString();
291 }
292 return text + " #AR-VON_FrequencyUnits_MHz";
293 }
294}
ETimeFormatParam
params precision
static string GetTimeFormattingHideSeconds(int totalSeconds, ETimeFormatParam hideEmpty=0, ETimeFormatParam hideLeadingZeroes=0)
static string GetTimeSinceEventImprecise(int timeDiffSeconds)
static string GetTimeFormattingMinutesSeconds(int minutes, int seconds, ETimeFormatParam hideEmpty=0, ETimeFormatParam hideLeadingZeroes=0)
static string ReturnTimeTypeString(int prevTimeTypeAmount, int currentTimeTypeAmount, int numberLength)
static string GetTimeSinceEventString(int amount, string oneUnit, string manyUnits)
static string GetTimeFormattingHoursMinutes(int hours, int minutes, ETimeFormatParam hideEmpty=0, ETimeFormatParam hideLeadingZeroes=0)
static string FormatFrequencies(notnull set< int > frequencies, set< int > highlightFrequencies=null)
static string GetTimeFormatting(int totalSeconds, ETimeFormatParam hideEmpty=0, ETimeFormatParam hideLeadingZeroes=0)
Definition int.c:13
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.