Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
uipopupscriptscenemanager.c
Go to the documentation of this file.
1 class UIPopupScriptSceneManager extends UIPopupScript
2 {
3  private ButtonWidget m_BtnCancel;
4  private ButtonWidget m_BtnSceneNew;
5  private ButtonWidget m_BtnSceneLoad;
6  private ButtonWidget m_BtnSceneRename;
7  private ButtonWidget m_BtnSceneDuplicate;
8  private ButtonWidget m_BtnSceneDelete;
9  private TextListboxWidget m_LstListScenes;
10 
11  private static const int m_DaysInMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
12 
13  private ButtonWidget m_BtnSave;
14 
15  private TextWidget m_TxtWeatherTime;
16 
17  private SliderWidget m_SldStartTime;
18  private TextWidget m_TxtStartTimeValue;
19  private SliderWidget m_SldStartDay;
20  private TextWidget m_TxtStartDayValue;
21  private SliderWidget m_SldOvercast;
22  private TextWidget m_TxtOvercastValue;
23  private SliderWidget m_SldRain;
24  private TextWidget m_TxtRainValue;
25  private SliderWidget m_SldFog;
26  private TextWidget m_TxtFogValue;
27  private SliderWidget m_SldWindForce;
28  private TextWidget m_TxtWindForceValue;
29 
30  private int m_OrigYear;
31  private int m_OrigMonth;
32  private int m_OrigDay;
33  private int m_OrigHour;
34  private int m_OrigMinute;
35  private float m_OrigOvercast;
36  private float m_OrigRain;
37  private float m_OrigFog;
38  private float m_OrigWindForce;
39 
40  private int m_CurrYear;
41  private int m_CurrMonth;
42  private int m_CurrDay;
43  private int m_CurrHour;
44  private int m_CurrMinute;
45  private float m_CurrOvercast;
46  private float m_CurrRain;
47  private float m_CurrFog;
48  private float m_CurrWindForce;
49 
50  //================================================
51  // UIPopupScriptSceneManager
52  //================================================
53  void UIPopupScriptSceneManager(Widget wgt)
54  {
55  m_BtnCancel = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_sm_cancel") );
56  m_BtnSceneNew = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_sm_mission_new") );
57  m_BtnSceneLoad = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_sm_mission_load") );
58  m_BtnSceneRename = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_sm_mission_rename") );
59  m_BtnSceneDelete = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_sm_mission_delete") );
60  m_BtnSceneDuplicate = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_sm_mission_duplicate") );
61 
62  m_LstListScenes = TextListboxWidget.Cast( wgt.FindAnyWidget("tls_ppp_sm_scene_list") );
63 
64  m_BtnSave = ButtonWidget.Cast( wgt.FindAnyWidget("btn_ppp_st_save") );
65 
66  m_TxtWeatherTime = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_w_time_value") );
67 
68  m_SldStartTime = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_start_time") );
69  m_TxtStartTimeValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_start_time_value") );
70 
71  m_SldStartDay = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_start_day") );
72  m_TxtStartDayValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_start_day_value") );
73 
74  m_SldOvercast = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_overcast") );
75  m_TxtOvercastValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_overcast_value") );
76 
77  m_SldRain = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_rain") );
78  m_TxtRainValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_rain_value") );
79 
80  m_SldFog = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_fog") );
81  m_TxtFogValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_fog_value") );
82 
83  m_SldWindForce = SliderWidget.Cast( wgt.FindAnyWidget("sld_ppp_st_wind_force") );
84  m_TxtWindForceValue = TextWidget.Cast( wgt.FindAnyWidget("txt_ppp_st_wind_force_value") );
85  }
86 
87  void ~UIPopupScriptSceneManager()
88  {
89  GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Remove(this.OnUpdate);
90  }
91 
92  //================================================
93  // OnClick
94  //================================================
95  override bool OnClick(Widget w, int x, int y, int button)
96  {
97  super.OnClick(w, x, y, button);
98 
99  string scene_name;
100  PluginSceneManager editor;
101 
102  if ( w == m_BtnCancel )
103  {
104  GetGame().GetWorld().SetDate( m_OrigYear, m_OrigMonth, m_OrigDay, m_OrigHour, m_OrigMinute );
105 
106  Weather weather = GetGame().GetWeather();
107  weather.GetOvercast().Set( m_OrigOvercast, 0, 1000 );
108  weather.GetRain().Set( m_OrigRain, 0, 1000 );
109  weather.GetFog().Set( m_OrigFog, 0, 1000 );
110  weather.SetWindSpeed( m_OrigWindForce );
111 
112  PopupBack();
113  return true;
114  }
115  else if ( w == m_BtnSceneNew )
116  {
117  PopupOpen(SceneEditorMenu.POPUP_ID_SCENE_NEW, NULL);
118 
119  return true;
120  }
121  else if ( w == m_BtnSceneLoad )
122  {
123  if ( m_LstListScenes.GetSelectedRow() != -1 )
124  {
125  m_LstListScenes.GetItemText( m_LstListScenes.GetSelectedRow(), 0, scene_name );
126  editor = PluginSceneManager.Cast( GetPlugin(PluginSceneManager) );
127 
128  editor.SceneLoad(scene_name);
129  PopupBack();
130 
131  return true;
132  }
133  }
134  else if ( w == m_BtnSceneRename )
135  {
136  m_LstListScenes.GetItemText( m_LstListScenes.GetSelectedRow(), 0, scene_name );
137 
138  UIPopupScriptSceneRename popup_rename = UIPopupScriptSceneRename.Cast( PopupOpen(SceneEditorMenu.POPUP_ID_SCENE_RENAME, NULL) );
139  popup_rename.SetRenameName(scene_name);
140 
141  return true;
142  }
143  else if ( w == m_BtnSceneDuplicate )
144  {
145  if ( m_LstListScenes.GetSelectedRow() != -1 )
146  {
147  m_LstListScenes.GetItemText( m_LstListScenes.GetSelectedRow(), 0, scene_name );
148  editor = PluginSceneManager.Cast( GetPlugin(PluginSceneManager) );
149 
150  editor.SceneDuplicate(scene_name);
151  UpdateSceneList();
152 
153  return true;
154  }
155  }
156  else if ( w == m_BtnSceneDelete )
157  {
158  if ( m_LstListScenes.GetSelectedRow() != -1 )
159  {
160  m_LstListScenes.GetItemText( m_LstListScenes.GetSelectedRow(), 0, scene_name );
161  editor = PluginSceneManager.Cast( GetPlugin(PluginSceneManager) );
162 
163  editor.SceneDelete(scene_name);
164 
165  if ( editor.SceneCanDelete(scene_name) )
166  {
167  UIPopupScriptSceneDelete popup_delete = UIPopupScriptSceneDelete.Cast( PopupOpen(SceneEditorMenu.POPUP_ID_SCENE_DELETE, NULL) );
168  popup_delete.SetDeleteName(scene_name);
169  }
170  else
171  {
172  UIPopupScriptNotify popup_notify = UIPopupScriptNotify.Cast( PopupOpen(SceneEditorMenu.POPUP_ID_NOTIFY, NULL) );
173  popup_notify.SetLabelText("You cant delete current loaded scene!");
174  }
175 
176  UpdateSceneList();
177  return true;
178  }
179  }
180  else if ( w == m_BtnSave )
181  {
182  m_OrigYear = m_CurrYear;
183  m_OrigMonth = m_CurrMonth;
184  m_OrigDay = m_CurrDay;
185  m_OrigHour = m_CurrHour;
186  m_OrigMinute = m_CurrMinute;
187  m_OrigOvercast = m_CurrOvercast;
188  m_OrigRain = m_CurrRain;
189  m_OrigFog = m_CurrFog;
190  m_OrigWindForce = m_CurrWindForce;
191 
192  editor = PluginSceneManager.Cast( GetPlugin(PluginSceneManager) );
193  editor.SetWeather(m_CurrOvercast, m_CurrRain, m_CurrFog, m_CurrWindForce);
194  editor.SetDate(m_CurrYear, m_CurrMonth, m_CurrDay, m_CurrHour, m_CurrMinute);
195  editor.SceneSave();
196 
197  PopupBack();
198 
199  return true;
200  }
201 
202  return false;
203  }
204 
205  override bool OnChange(Widget w, int x, int y, bool finished)
206  {
207  if ( w == m_SldStartTime )
208  {
209  float slider_value_start_time = m_SldStartTime.GetCurrent() * 0.01;
210  float start_time_f = slider_value_start_time * 1439;
211  int start_time = start_time_f;
212  m_CurrHour = start_time / 60;
213  m_CurrMinute = start_time % 60;
214 
215  UpdateSliderStartTime( m_CurrHour, m_CurrMinute );
216 
217  GetGame().GetWorld().SetDate( m_CurrYear, m_CurrMonth, m_CurrDay, m_CurrHour, m_CurrMinute );
218 
219  return true;
220  }
221  else if ( w == m_SldStartDay )
222  {
223  float slider_value_start_day = m_SldStartDay.GetCurrent();
224  float start_day_f = slider_value_start_day * 3.64 + 1;
225  int start_day = start_day_f;
226 
227  for ( int i = 0; i < 12; i++ )
228  {
229  int days = m_DaysInMonth[i];
230  if ( start_day <= days )
231  {
232  m_CurrMonth = i+1;
233  m_CurrDay = start_day;
234  break;
235  }
236  else
237  {
238  start_day -= days;
239  }
240  }
241 
242  UpdateSliderStartDay( m_CurrMonth, m_CurrDay );
243 
244  GetGame().GetWorld().SetDate( m_CurrYear, m_CurrMonth, m_CurrDay, m_CurrHour, m_CurrMinute );
245 
246  return true;
247  }
248  else if ( w == m_SldOvercast )
249  {
250  m_CurrOvercast = m_SldOvercast.GetCurrent() * 0.01;
251  GetGame().GetWeather().GetOvercast().Set( m_CurrOvercast, 0, 1000 );
252 
253  UpdateSliderOvercast();
254 
255  return true;
256  }
257  else if ( w == m_SldRain )
258  {
259  m_CurrRain = m_SldRain.GetCurrent() * 0.01;
260  GetGame().GetWeather().GetRain().Set( m_CurrRain, 0, 1000 );
261 
262  UpdateSliderRain();
263 
264  return true;
265  }
266  else if ( w == m_SldFog )
267  {
268  m_CurrFog = m_SldFog.GetCurrent() * 0.01;
269  GetGame().GetWeather().GetFog().Set( m_CurrFog, 0, 1000 );
270 
271  UpdateSliderFog();
272 
273  return true;
274  }
275  else if ( w == m_SldWindForce )
276  {
277  float wind_slider = m_SldWindForce.GetCurrent() * 0.01;
278  m_CurrWindForce = GetGame().GetWeather().GetWindMaximumSpeed() * wind_slider;
279  GetGame().GetWeather().SetWindSpeed( m_CurrWindForce );
280 
281  UpdateSliderWindForce();
282 
283  return true;
284  }
285 
286  return false;
287  }
288 
289  //================================================
290  // UpdateSceneList
291  //================================================
292  void UpdateSceneList()
293  {
294  m_LstListScenes.ClearItems();
295 
296  PluginSceneManager editor = PluginSceneManager.Cast( GetPlugin(PluginSceneManager) );
297 
298  TStringArray scene_list = editor.GetSceneList();
299  string loaded_scene_name = editor.SceneGetName();
300 
301  for ( int i = 0; i < scene_list.Count(); ++i )
302  {
303  string scene_name = scene_list.Get(i);
304 
305  m_LstListScenes.AddItem(scene_name, NULL, 0);
306 
307  if ( scene_name == loaded_scene_name )
308  {
309  m_LstListScenes.SelectRow(i);
310  }
311  }
312  }
313 
314  //================================================
315  // UpdateSceneList
316  //================================================
317  override void OnOpen(Param param)
318  {
319  //Log("Poup Scene Manager OnOpen");
320 
321  UpdateSceneList();
322  GetGame().GetWorld().GetDate( m_OrigYear, m_OrigMonth, m_OrigDay, m_OrigHour, m_OrigMinute );
323 
324  Weather weather = GetGame().GetWeather();
325  m_OrigOvercast = weather.GetOvercast().GetActual();
326  m_OrigRain = weather.GetRain().GetActual();
327  m_OrigFog = weather.GetFog().GetActual();
328  m_OrigWindForce = weather.GetWindSpeed();
329 
330  m_CurrYear = m_OrigYear;
331  m_CurrMonth = m_OrigMonth;
332  m_CurrDay = m_OrigDay;
333  m_CurrHour = m_OrigHour;
334  m_CurrMinute = m_OrigMinute;
335  m_CurrOvercast = m_OrigOvercast;
336  m_CurrRain = m_OrigRain;
337  m_CurrFog = m_OrigFog;
338  m_CurrWindForce = m_OrigWindForce;
339 
340  Print( "Year" );
341  Print( m_CurrYear );
342 
343  GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Insert(this.OnUpdate);
344 
345  ResetSliders();
346  }
347 
348  //================================================
349  // OnClose
350  //================================================
351  override void OnClose()
352  {
353  GetGame().GetUpdateQueue(CALL_CATEGORY_SYSTEM).Remove(this.OnUpdate);
354  }
355 
356  //================================================
357  // OnUpdate
358  //================================================
359  void OnUpdate()
360  {
361  m_TxtWeatherTime.SetText(GetGame().GetWeather().GetTime().ToString());
362  }
363 
364  //================================================
365  // ResetSliders
366  //================================================
367  void ResetSliders()
368  {
369  int year, month, day, hour, minute;
370  GetGame().GetWorld().GetDate( year, month, day, hour, minute );
371  m_SldStartTime.SetCurrent( ((hour * 60) + minute) / 14.39 );
372  UpdateSliderStartTime( hour, minute );
373 
374  float start_day = day;
375  int month_tmp = month;
376  while ( month_tmp > 1 )
377  {
378  month_tmp--;
379  start_day += m_DaysInMonth[month];
380  }
381  m_SldStartDay.SetCurrent( start_day / 3.64 );
382  UpdateSliderStartDay( month, day );
383 
384  Weather weather = GetGame().GetWeather();
385 
386  m_SldOvercast.SetCurrent(weather.GetOvercast().GetActual() * 100);
387  UpdateSliderOvercast();
388 
389  m_SldRain.SetCurrent(weather.GetRain().GetActual() * 100);
390  UpdateSliderRain();
391 
392  m_SldFog.SetCurrent(weather.GetFog().GetActual() * 100);
393  UpdateSliderFog();
394 
395  float wind_slider = m_SldWindForce.GetCurrent() * 0.01;
396  m_CurrWindForce = weather.GetWindMaximumSpeed() * wind_slider;
397  weather.SetWindSpeed( m_CurrWindForce );
398  UpdateSliderWindForce();
399  }
400 
401  void UpdateSliderStartTime( int hour, int minute )
402  {
403  string label_text = hour.ToStringLen(2) + ":" + minute.ToStringLen(2);
404  m_TxtStartTimeValue.SetText( label_text );
405  }
406 
407  void UpdateSliderStartDay( int month, int day )
408  {
409  string label_text = day.ToString() + "." + month.ToString() + ". " + m_CurrYear.ToString();
410  m_TxtStartDayValue.SetText( label_text );
411  }
412 
413  void UpdateSliderOvercast()
414  {
415  string label_text = m_SldOvercast.GetCurrent().ToString()+"%";
416  m_TxtOvercastValue.SetText( label_text );
417  }
418 
419  void UpdateSliderRain()
420  {
421  string label_text = m_SldRain.GetCurrent().ToString()+"%";
422  m_TxtRainValue.SetText( label_text );
423  }
424 
425  void UpdateSliderFog()
426  {
427  string label_text = m_SldFog.GetCurrent().ToString()+"%";
428  m_TxtFogValue.SetText( label_text );
429  }
430 
431  void UpdateSliderWindForce()
432  {
433  string label_text = m_CurrWindForce.ToString()+"ms";
434  m_TxtWindForceValue.SetText( label_text );
435  }
436 }
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
array< string >
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