Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FormatHelper.c
Go to the documentation of this file.
2 {
3  //------------------------------------------------------------------------------------------------
26  static string FloatToStringNoZeroDecimalEndings(float value, int lenDec)
27  {
28  return value.ToString(lenDec: lenDec).ToFloat().ToString();
29  }
30 
31  //------------------------------------------------------------------------------------------------
33  static string FormatDateTime(int year, int month, int day, int hour, int minute, int second)
34  {
35  return string.Format("%1 %2", FormatDate(year, month, day), FormatTime(hour, minute, second));
36  }
37 
38  //------------------------------------------------------------------------------------------------
41  static string FormatDate(int year, int month, int day)
42  {
43  if (year < 100)
44  year += 2000;
45  return string.Format("%1-%2-%3", year.ToString(4), month.ToString(2), day.ToString(2));
46  }
47 
48  //------------------------------------------------------------------------------------------------
50  static string FormatTime(int totalSeconds)
51  {
52  int hour, minute, second;
53  SCR_DateTimeHelper.GetHourMinuteSecondFromSeconds(totalSeconds, hour, minute, second);
54  return FormatTime(hour, minute, second);
55  }
56 
57  //------------------------------------------------------------------------------------------------
59  static string FormatTime(int hour, int minute, int second)
60  {
61  return string.Format("%1:%2:%3", hour.ToString(2), minute.ToString(2), second.ToString(2));
62  }
63 
64  //------------------------------------------------------------------------------------------------
77  static string GetTimeFormatting(int days, int hours, int minutes, int seconds, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
78  {
79  //Todo: Display days properly rather then dd:hh:mm:ss (Though right now it is extreamly edge case if days should be shown)
80  string returnString = "";
81 
82  //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
83  //Only show days
84  //if (days > -1 && ((hideEmpty & ETimeFormatParam.DAYS) && days > 0) || !(hideEmpty & ETimeFormatParam.DAYS))
85  if (days > 0 && (hideEmpty & ETimeFormatParam.DAYS) || !(hideEmpty & ETimeFormatParam.DAYS))
86  returnString += days.ToString();
87  else
88  days = -1;
89 
90  //hours (Check if should display hours and check if should display leading zero)
91  if (hours > 0 && (hideEmpty & ETimeFormatParam.HOURS) || !(hideEmpty & ETimeFormatParam.HOURS))
92  returnString += ReturnTimeTypeString(days, hours, ((hideLeadingZeroes & ETimeFormatParam.HOURS) == 0) +1);
93  else
94  hours = -1;
95 
96  //Minutes (Check if should display Minutes and check if should display leading zero)
97  if (minutes > 0 && (hideEmpty & ETimeFormatParam.MINUTES) || !(hideEmpty & ETimeFormatParam.MINUTES))
98  returnString += ReturnTimeTypeString(hours, minutes, ((hideLeadingZeroes & ETimeFormatParam.MINUTES) == 0) +1);
99  else
100  minutes = -1;
101 
102  //Seconds (Check if should display Seconds and check if should display leading zero)
103  if (seconds > 0 && (hideEmpty & ETimeFormatParam.SECONDS) || !(hideEmpty & ETimeFormatParam.SECONDS))
104  returnString += ReturnTimeTypeString(minutes, seconds, ((hideLeadingZeroes & ETimeFormatParam.SECONDS) == 0) +1);
105 
106  return returnString;
107  }
108 
109  //------------------------------------------------------------------------------------------------
113  protected static string ReturnTimeTypeString(int prevTimeTypeAmount, int currentTimeTypeAmount, int numberLength)
114  {
115  if (prevTimeTypeAmount > -1)
116  return ":" + currentTimeTypeAmount.ToString(numberLength);
117  else
118  return currentTimeTypeAmount.ToString(numberLength);
119  }
120 
121  //------------------------------------------------------------------------------------------------
131  static string GetTimeFormatting(int totalSeconds, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
132  {
133  int days, hours, minutes, seconds;
134  SCR_DateTimeHelper.GetDayHourMinuteSecondFromSeconds(totalSeconds, days, hours, minutes, seconds);
135  return GetTimeFormatting(days, hours, minutes, seconds, hideEmpty, hideLeadingZeroes);
136  }
137 
138  //------------------------------------------------------------------------------------------------
148  static string GetTimeFormattingHideSeconds(int totalSeconds, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
149  {
150  int days, hours, minutes, seconds;
151  SCR_DateTimeHelper.GetDayHourMinuteSecondFromSeconds(totalSeconds, days, hours, minutes, seconds);
152  return GetTimeFormatting(days, hours, minutes, -1, ETimeFormatParam.SECONDS | hideEmpty, hideLeadingZeroes);
153  }
154 
155  //------------------------------------------------------------------------------------------------
164  static string GetTimeFormattingHoursMinutes(int hours, int minutes, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
165  {
166  return GetTimeFormatting(-1, hours, minutes, -1, (ETimeFormatParam.DAYS | ETimeFormatParam.SECONDS | hideEmpty), hideLeadingZeroes);
167  }
168 
169  //------------------------------------------------------------------------------------------------
178  static string GetTimeFormattingMinutesSeconds(int minutes, int seconds, ETimeFormatParam hideEmpty = 0, ETimeFormatParam hideLeadingZeroes = 0)
179  {
180  return GetTimeFormatting(-1, -1, minutes, seconds, (ETimeFormatParam.DAYS | ETimeFormatParam.HOURS | hideEmpty), hideLeadingZeroes);
181  }
182 
183  //------------------------------------------------------------------------------------------------
185  protected static string GetTimeSinceEventString(int amount, string oneUnit, string manyUnits)
186  {
187  if (amount == 1)
188  return WidgetManager.Translate(oneUnit, amount);
189  else
190  return WidgetManager.Translate(manyUnits, amount);
191  }
192 
193  //------------------------------------------------------------------------------------------------
196  static string GetTimeSinceEventImprecise(int timeDiffSeconds)
197  {
198  if (timeDiffSeconds < 0)
199  return string.Empty;
200 
201  int days, hours, minutes, remainingSeconds;
202  SCR_DateTimeHelper.GetDayHourMinuteSecondFromSeconds(timeDiffSeconds, days, hours, minutes, remainingSeconds);
203 
204  if (days > 0)
205  return GetTimeSinceEventString(days, "#AR-Date_DayAgo_LC", "#AR-Date_DaysAgo_LC"); // 23 days ago
206  else if (hours > 0)
207  return GetTimeSinceEventString(hours, "#AR-Time_HourAgo_LC", "#AR-Time_HoursAgo_LC"); // 23 hours ago
208  else
209  return GetTimeSinceEventString(minutes, "#AR-Time_MinuteAgo_LC", "#AR-Time_MinutesAgo_LC"); // 23 minutes ago
210  }
211 
212  //------------------------------------------------------------------------------------------------
218  static string FormatFrequencies(notnull set<int> frequencies, set<int> highlightFrequencies = null)
219  {
220  if (frequencies.IsEmpty())
221  return string.Empty;
222 
223  string text;
224  float accurateFrequency;
225  foreach (int i, int frequency : frequencies)
226  {
227  if (i > 0)
228  text += ", ";
229  accurateFrequency = frequency;
230  if (highlightFrequencies && highlightFrequencies.Contains(frequency))
231  text += string.Format("<color rgba='226,168,79,255'>%1</color>", accurateFrequency / 1000); //--- ToDo: Don't hardcode color
232  else
233  text += (accurateFrequency / 1000).ToString();
234  }
235  return text + " #AR-VON_FrequencyUnits_MHz";
236  }
237 };
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
SCR_DateTimeHelper
Definition: SCR_DateTimeHelper.c:1
ETimeFormatParam
ETimeFormatParam
Definition: ETimeFormatParam.c:4