Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
uipopupscriptscenesettings.c
Go to the documentation of this file.
1 class UIPopupScriptSceneSettings extends UIPopupScript
2 {
3  private static const int m_DaysInMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
4 
5  private ButtonWidget m_BtnSave;
6  private ButtonWidget m_BtnCancel;
7 
8  private TextWidget m_TxtWeatherTime;
9 
10  private SliderWidget m_SldStartTime;
11  private TextWidget m_TxtStartTimeValue;
12  private SliderWidget m_SldStartDay;
13  private TextWidget m_TxtStartDayValue;
14  private SliderWidget m_SldOvercast;
15  private TextWidget m_TxtOvercastValue;
16  private SliderWidget m_SldRain;
17  private TextWidget m_TxtRainValue;
18  private SliderWidget m_SldFog;
19  private TextWidget m_TxtFogValue;
20  private SliderWidget m_SldWindForce;
21  private TextWidget m_TxtWindForceValue;
22 
23  private int m_OrigYear;
24  private int m_OrigMonth;
25  private int m_OrigDay;
26  private int m_OrigHour;
27  private int m_OrigMinute;
28  private float m_OrigOvercast;
29  private float m_OrigRain;
30  private float m_OrigFog;
31  private float m_OrigWindForce;
32 
33  private int m_CurrYear;
34  private int m_CurrMonth;
35  private int m_CurrDay;
36  private int m_CurrHour;
37  private int m_CurrMinute;
38  private float m_CurrOvercast;
39  private float m_CurrRain;
40  private float m_CurrFog;
41  private float m_CurrWindForce;
42 
43  //================================================
44  // UIPopupScriptSceneSettings
45  //================================================
46  void UIPopupScriptSceneSettings(Widget wgt)
47  {
48  m_BtnSave = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_st_save") );
49  m_BtnCancel = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_st_cancel") );
50 
51  m_TxtWeatherTime = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_w_time_value") );
52 
53  m_SldStartTime = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_start_time") );
54  m_TxtStartTimeValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_start_time_value") );
55 
56  m_SldStartDay = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_start_day") );
57  m_TxtStartDayValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_start_day_value") );
58 
59  m_SldOvercast = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_overcast") );
60  m_TxtOvercastValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_overcast_value") );
61 
62  m_SldRain = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_rain") );
63  m_TxtRainValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_rain_value") );
64 
65  m_SldFog = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_fog") );
66  m_TxtFogValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_fog_value") );
67 
68  m_SldWindForce = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_wind_force") );
69  m_TxtWindForceValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_wind_force_value") );
70  }
71 
72  void ~UIPopupScriptSceneSettings()
73  {
74  GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Remove(this.OnUpdate);
75  }
76  //================================================
77  // OnClick
78  //================================================
79  override bool OnClick(Widget w, int x, int y, int button)
80  {
81  super.OnClick(w, x, y, button);
82 
83  if ( w == m_BtnSave )
84  {
85  m_OrigYear = m_CurrYear;
86  m_OrigMonth = m_CurrMonth;
87  m_OrigDay = m_CurrDay;
88  m_OrigHour = m_CurrHour;
89  m_OrigMinute = m_CurrMinute;
90  m_OrigOvercast = m_CurrOvercast;
91  m_OrigRain = m_CurrRain;
92  m_OrigFog = m_CurrFog;
93  m_OrigWindForce = m_CurrWindForce;
94 
95  PluginSceneManager editor = PluginSceneManager.Cast( GetPlugin(PluginSceneManager) );
96  editor.SetWeather(m_CurrOvercast, m_CurrRain, m_CurrFog, m_CurrWindForce);
97  editor.SetDate(m_CurrYear, m_CurrMonth, m_CurrDay, m_CurrHour, m_CurrMinute);
98 
99  PopupBack();
100 
101  return true;
102  }
103  else if ( w == m_BtnCancel )
104  {
105 
106  PopupBack();
107 
108  return true;
109  }
110 
111  return false;
112  }
113 
114 
115  override bool OnChange(Widget w, int x, int y, bool finished)
116  {
117  if ( w == m_SldStartTime )
118  {
119  float slider_value_start_time = m_SldStartTime.GetCurrent() * 0.01;
120  float start_time_f = slider_value_start_time * 1439;
121  int start_time = start_time_f;
122  m_CurrHour = start_time / 60;
123  m_CurrMinute = start_time % 60;
124 
125  UpdateSliderStartTime( m_CurrHour, m_CurrMinute );
126 
127  GetGame().GetWorld().SetDate( m_CurrYear, m_CurrMonth, m_CurrDay, m_CurrHour, m_CurrMinute );
128 
129  return true;
130  }
131  else if ( w == m_SldStartDay )
132  {
133  float slider_value_start_day = m_SldStartDay.GetCurrent();
134  float start_day_f = slider_value_start_day * 3.64 + 1;
135  int start_day = start_day_f;
136 
137  for ( int i = 0; i < 12; i++ )
138  {
139  int days = m_DaysInMonth[i];
140  if ( start_day <= days )
141  {
142  m_CurrMonth = i+1;
143  m_CurrDay = start_day;
144  break;
145  }
146  else
147  {
148  start_day -= days;
149  }
150  }
151 
152  UpdateSliderStartDay( m_CurrMonth, m_CurrDay );
153 
154  GetGame().GetWorld().SetDate( m_CurrYear, m_CurrMonth, m_CurrDay, m_CurrHour, m_CurrMinute );
155 
156  return true;
157  }
158  else if ( w == m_SldOvercast )
159  {
160  UpdateSliderOvercast();
161 
162  m_CurrOvercast = m_SldOvercast.GetCurrent() * 0.01;
163  GetGame().GetWeather().GetOvercast().Set( m_CurrOvercast, 0, 1000 );
164 
165  return true;
166  }
167  else if ( w == m_SldRain )
168  {
169  UpdateSliderRain();
170 
171  m_CurrRain = m_SldRain.GetCurrent() * 0.01;
172  GetGame().GetWeather().GetRain().Set( m_CurrRain, 0, 1000 );
173 
174  return true;
175  }
176  else if ( w == m_SldFog )
177  {
178  UpdateSliderFog();
179 
180  m_CurrFog = m_SldFog.GetCurrent() * 0.01;
181  GetGame().GetWeather().GetFog().Set( m_CurrFog, 0, 1000 );
182 
183  return true;
184  }
185  else if ( w == m_SldWindForce )
186  {
187  UpdateSliderWindForce();
188 
189  m_CurrWindForce = m_SldWindForce.GetCurrent() * 0.01;
190  //GetGame().GetWeather().SetWindSpeed( m_CurrWindForce );
191 
192  return true;
193  }
194 
195  return false;
196  }
197 
198  //================================================
199  // OnOpen
200  //================================================
201  override void OnOpen(Param param)
202  {
203  GetGame().GetWorld().GetDate( m_OrigYear, m_OrigMonth, m_OrigDay, m_OrigHour, m_OrigMinute );
204 
205  Weather weather = GetGame().GetWeather();
206 
207  m_OrigOvercast = weather.GetOvercast().GetActual();
208  m_OrigRain = weather.GetRain().GetActual();
209  m_OrigFog = weather.GetFog().GetActual();
210  m_OrigWindForce = weather.GetWindSpeed();
211 
212  m_CurrYear = m_OrigYear;
213  m_CurrMonth = m_OrigMonth;
214  m_CurrDay = m_OrigDay;
215  m_CurrHour = m_OrigHour;
216  m_CurrMinute = m_OrigMinute;
217  m_CurrOvercast = m_OrigOvercast;
218  m_CurrRain = m_OrigRain;
219  m_CurrFog = m_OrigFog;
220  m_CurrWindForce = m_OrigWindForce;
221 
222  Print( "Year" );
223  Print( m_CurrYear );
224 
225  GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Insert(this.OnUpdate);
226 
227  ResetSliders();
228  }
229 
230  //================================================
231  // OnClose
232  //================================================
233  override void OnClose()
234  {
235  Weather weather = GetGame().GetWeather();
236 
237  GetGame().GetWorld().SetDate( m_OrigYear, m_OrigMonth, m_OrigDay, m_OrigHour, m_OrigMinute );
238  weather.GetOvercast().Set( m_OrigOvercast, 0, 1000 );
239  weather.GetRain().Set( m_OrigRain, 0, 1000 );
240  weather.GetFog().Set( m_OrigFog, 0, 1000 );
241  //weather.SetWindSpeed( m_OrigWindForce );
242  }
243 
244  //================================================
245  // OnUpdate
246  //================================================
247  void OnUpdate()
248  {
249  m_TxtWeatherTime.SetText(GetGame().GetWeather().GetTime().ToString());
250  }
251 
252  //================================================
253  // ResetSliders
254  //================================================
255  void ResetSliders()
256  {
257  int year, month, day, hour, minute;
258  GetGame().GetWorld().GetDate( year, month, day, hour, minute );
259  m_SldStartTime.SetCurrent( ((hour * 60) + minute) / 14.39 );
260  UpdateSliderStartTime( hour, minute );
261 
262  float start_day = day;
263  int month_tmp = month;
264  while ( month_tmp > 1 )
265  {
266  month_tmp--;
267  start_day += m_DaysInMonth[month];
268  }
269  m_SldStartDay.SetCurrent( start_day / 3.64 );
270  UpdateSliderStartDay( month, day );
271 
272  Weather weather = GetGame().GetWeather();
273 
274  m_SldOvercast.SetCurrent(weather.GetOvercast().GetActual() * 100);
275  UpdateSliderOvercast();
276 
277  m_SldRain.SetCurrent(weather.GetRain().GetActual() * 100);
278  UpdateSliderRain();
279 
280  m_SldFog.SetCurrent(weather.GetFog().GetActual() * 100);
281  UpdateSliderFog();
282 
283  float slider_wind_value = ( weather.GetWindSpeed() / weather.GetWindMaximumSpeed() ) * 100;
284  m_SldWindForce.SetCurrent( slider_wind_value );
285  UpdateSliderWindForce();
286  }
287 
288  void UpdateSliderStartTime( int hour, int minute )
289  {
290  string label_text = hour.ToStringLen(2) + ":" + minute.ToStringLen(2);
291  m_TxtStartTimeValue.SetText( label_text );
292  }
293 
294  void UpdateSliderStartDay( int month, int day )
295  {
296  string label_text = day.ToString() + "." + month.ToString() + ". " + m_CurrYear.ToString();
297  m_TxtStartDayValue.SetText( label_text );
298  }
299 
300  void UpdateSliderOvercast()
301  {
302  string label_text = m_SldOvercast.GetCurrent().ToString()+"%";
303  m_TxtOvercastValue.SetText( label_text );
304  }
305 
306  void UpdateSliderRain()
307  {
308  string label_text = m_SldRain.GetCurrent().ToString()+"%";
309  m_TxtRainValue.SetText( label_text );
310  }
311 
312  void UpdateSliderFog()
313  {
314  string label_text = m_SldFog.GetCurrent().ToString()+"%";
315  m_TxtFogValue.SetText( label_text );
316  }
317 
318  void UpdateSliderWindForce()
319  {
320  string label_text = m_SldWindForce.GetCurrent().ToString()+"%";
321  m_TxtWindForceValue.SetText( label_text );
322  }
323 }
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
y
Icon y
Print
proto void Print(void var)
Prints content of variable to console/log.
ToString
proto string ToString()
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
TextWidget
Definition: enwidgets.c:219
OnUpdate
proto native void OnUpdate()
Definition: tools.c:349
UIPopupScript
Definition: uipopupscriptconfigs.c:1
x
Icon x
GetTime
float GetTime()
Definition: notificationsystem.c:35
OnChange
bool OnChange(Widget w, int x, int y, bool finished)
Definition: huddebug.c:336
Widget
Definition: enwidgets.c:189
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
Weather
Definition: weather.c:154