Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
scriptconsolesoundstab.c
Go to the documentation of this file.
2 {
3  protected bool m_PlayerPosRefreshBlocked;
4  protected static float DEBUG_MAP_ZOOM = 1;
5  protected vector m_MapPos;
6  protected ButtonWidget m_CopySoundset;
7  protected ButtonWidget m_PlaySoundset;
8  protected ButtonWidget m_PlaySoundsetLooped;
9  protected ButtonWidget m_StopSoundset;
10 
11  protected EditBoxWidget m_SoundFilter;
12  protected TextListboxWidget m_SoundsTextListbox;
13 
14  protected static EffectSound m_SoundSet;
15  protected ref Timer m_RefreshFilterTimer = new Timer();
16 
17  protected MapWidget m_DebugMapWidget;
18  protected TextWidget m_MapDistWidget;
19  protected TextWidget m_MouseCurPos;
20  protected TextWidget m_MapHeadingWidget;
21 
22  void ScriptConsoleSoundsTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
23  {
24  m_MouseCurPos = TextWidget.Cast(root.FindAnyWidget("MapSoundsPos"));
25  m_MapDistWidget = TextWidget.Cast(root.FindAnyWidget("MapSoundsDistance"));
26  m_MapHeadingWidget = TextWidget.Cast(root.FindAnyWidget("MapHeadingSounds"));
27 
28  m_CopySoundset = ButtonWidget.Cast(root.FindAnyWidget("SoundsetCopy"));
29  m_PlaySoundset = ButtonWidget.Cast(root.FindAnyWidget("PlaySoundset"));
30  m_PlaySoundsetLooped = ButtonWidget.Cast(root.FindAnyWidget("PlaySoundsetLooped"));
31  m_StopSoundset = ButtonWidget.Cast(root.FindAnyWidget("StopSoundset"));
32  m_DebugMapWidget = MapWidget.Cast(root.FindAnyWidget("MapSounds"));
33 
34  m_SoundFilter = EditBoxWidget.Cast(root.FindAnyWidget("SoundsFilter"));
35  m_SoundsTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("SoundsList"));
36 
37  m_SoundFilter.SetText(m_ConfigDebugProfile.GetSoundsetFilter());
38 
39 
40  ChangeFilterSound();
41 
42  if (GetGame().GetPlayer())
43  {
44  m_DebugMapWidget.SetScale(DEBUG_MAP_ZOOM);
45  m_DebugMapWidget.SetMapPos(GetGame().GetPlayer().GetWorldPosition());
46  SetMapPos(GetGame().GetPlayer().GetWorldPosition());
47  }
48  }
49 
50  void ~ScriptConsoleSoundsTab(Widget root)
51  {
52  DEBUG_MAP_ZOOM = m_DebugMapWidget.GetScale();
53  }
54 
55  override bool OnChange(Widget w, int x, int y, bool finished)
56  {
57  super.OnChange(w, x, y, finished);
58 
59  if (w == m_SoundFilter)
60  {
61  m_RefreshFilterTimer.Run(0.85, this, "ChangeFilterSound", null, false);
62  return true;
63  }
64  return false;
65  }
66 
67  void UpdateMousePos()
68  {
69  if(!GetGame().GetPlayer())
70  return;
71  int x,y;
72  GetMousePos(x,y);
73  vector mousePos, worldPos;
74  mousePos[0] = x;
75  mousePos[1] = y;
76  worldPos = m_DebugMapWidget.ScreenToMap(mousePos);
77  vector playerPos = GetGame().GetPlayer().GetWorldPosition();
78  if (GetMapPos() != playerPos)
79  worldPos = GetMapPos();
80  worldPos[1] = GetGame().SurfaceY(worldPos[0], worldPos[2]);
81 
82  if (m_MouseCurPos)
83  {
84  m_MouseCurPos.SetText("Mouse: "+ MiscGameplayFunctions.TruncateToS(worldPos[0]) +", "+ MiscGameplayFunctions.TruncateToS(worldPos[1]) +", "+ MiscGameplayFunctions.TruncateToS(worldPos[2]));
85  }
86  if (m_MapDistWidget && GetGame().GetPlayer())
87  {
88  float dst = (worldPos - playerPos).Length();
89 
90  m_MapDistWidget.SetText("Distance: " + MiscGameplayFunctions.TruncateToS(dst));
91  }
92  if (m_MapHeadingWidget)
93  {
94  vector playerCamDir = GetGame().GetCurrentCameraDirection();
95  float heading = Math3D.AngleFromPosition(playerPos, playerCamDir, worldPos) * Math.RAD2DEG;
96  m_MapHeadingWidget.SetText("Heading:" +heading.ToString());
97  }
98  }
99 
100  protected void PrepareFilters(string filter, out TStringArray filters)
101  {
102  filter.Trim();
103  filter.ToLower();
104 
105  filters = new TStringArray;
106  TStringArray rawFilters = new TStringArray;
107  filter.Split(" ", rawFilters);
108 
109  foreach (int i, string f:rawFilters)
110  {
111  filters.Insert(f);
112 
113  }
114  }
115 
116  // this is a 95% of the code of the function of the same name inside ScriptConsole.c
117  protected void ChangeFilter(TStringArray classes, TextListboxWidget widget, EditBoxWidget filterWidget, int categoryMask = -1, bool ignoreScope = false)
118  {
119  widget.ClearItems();
120 
121  TStringArray filters;
122  PrepareFilters(filterWidget.GetText(),filters);
123 
125 
126  TStringArray itemsArray = TStringArray();
127 
128  for (int i = 0; i < classes.Count(); i++)
129  {
130  string config_path = classes.Get(i);
131 
132  int objects_count = GetGame().ConfigGetChildrenCount(config_path);
133  for (int j = 0; j < objects_count; j++)
134  {
135  string child_name;
136  bool add = false;
137  GetGame().ConfigGetChildName(config_path, j, child_name);
138 
139  if (!filters.Count())
140  {
141  add = true;
142  }
143  else
144  {
145  foreach (int indx, string filter:filters)
146  {
147  string child_name_lower = child_name;
148  child_name_lower.ToLower();
149 
150  if (child_name_lower.Contains(filter))
151  {
152  add = true;
153  break;
154  }
155  }
156  }
157  if (add)
158  itemsArray.Insert(child_name);
159  }
160  }
161 
162  if (itemsArray)
163  {
164  itemsArray.Sort();
165  foreach (string it:itemsArray)
166  {
167  widget.AddItem(it, NULL, 0);
168  }
169  }
170 
171  if (filters)
172  {
173  /*
174  if (m_FilterOrderReversed)
175  filters.Invert();
176  */
177  foreach (string f:filters)
178  {
179  TStringArray arr2 = itemsByFilters.Get(f);
180  if (arr2)
181  {
182  arr2.Sort();
183  foreach (string itm: arr2)
184  {
185  int row = widget.AddItem(itm, NULL, 0);
186  }
187  }
188  }
189  }
190 
191 
192  }
193 
194  override void Update(float timeslice)
195  {
196  super.Update(timeslice);
197 
198  HandleKeys();
199  m_DebugMapWidget.ClearUserMarks();
200 
201  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
202 
203  if (player)
204  {
205  vector playerPos = player.GetWorldPosition();
206  m_DebugMapWidget.AddUserMark(playerPos,"You", COLOR_RED,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
207 
208  if (playerPos != GetMapPos())
209  m_DebugMapWidget.AddUserMark(GetMapPos(),"Source", COLOR_GREEN,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
210  }
211  UpdateMousePos();
212  }
213 
214  protected void HandleKeys()
215  {
216  bool playRequested = KeyState(KeyCode.KC_P) != 0;
217  if (playRequested)
218  {
219  int selected_row_index = m_SoundsTextListbox.GetSelectedRow();
220 
221  if (m_SoundSet)
222  m_SoundSet.Stop();
223  if (selected_row_index != -1)
224  {
225  string soundSetName;
226  m_SoundsTextListbox.GetItemText(selected_row_index, 0, soundSetName);
227 
228  m_SoundSet = SEffectManager.PlaySoundEnviroment(soundSetName, GetMapPos());
229  m_SoundSet.SetAutodestroy(true);
230  }
231  }
232  }
233 
234  protected void SetMapPos(vector pos)
235  {
236  m_MapPos = pos;
237  }
238 
239  protected vector GetMapPos()
240  {
241  return m_MapPos;
242  }
243 
244  override bool OnMouseButtonDown(Widget w, int x, int y, int button)
245  {
246  super.OnMouseButtonDown(w,x,y,button);
247 
248  if (w == m_DebugMapWidget)
249  {
250  if (button == 0)
251  {
252  m_PlayerPosRefreshBlocked = true;
253  int mouseX, mouseY;
254  GetMousePos(mouseX,mouseY);
255  vector mousePos, worldPos;
256  mousePos[0] = mouseX;
257  mousePos[1] = mouseY;
258  worldPos = m_DebugMapWidget.ScreenToMap(mousePos);
259  worldPos[1] = GetGame().SurfaceY(worldPos[0], worldPos[2]);
260 
261  SetMapPos(worldPos);
262  }
263  else if (button == 1 && GetGame().GetPlayer())
264  {
265  SetMapPos(GetGame().GetPlayer().GetWorldPosition());
266  }
267  }
268  return true;
269  }
270 
271  override bool OnClick(Widget w, int x, int y, int button)
272  {
273  super.OnClick(w,x,y,button);
274 
275  if (w == m_CopySoundset)
276  {
277  AddItemToClipboard(m_SoundsTextListbox);
278  return true;
279  }
280  else if (w == m_PlaySoundset || w == m_PlaySoundsetLooped)
281  {
282  int selected_row_index = m_SoundsTextListbox.GetSelectedRow();
283  string soundSetName;
284  if (m_SoundSet)
285  m_SoundSet.Stop();
286  if (selected_row_index != -1)
287  {
288  m_SoundsTextListbox.GetItemText(selected_row_index, 0, soundSetName);
289 
290  bool looped = (w == m_PlaySoundsetLooped);
291  m_SoundSet = SEffectManager.PlaySoundEnviroment(soundSetName, GetMapPos(), 0, 0, looped);
292 
293  }
294  return true;
295  }
296  else if (w == m_StopSoundset)
297  {
298  if (m_SoundSet)
299  m_SoundSet.Stop();
300  return true;
301  }
302  else if (w == m_SoundFilter)
303  {
304  ChangeFilterSound();
305  return true;
306  }
307 
308  return false;
309  }
310 
311 
312  protected TStringArray GetSoundClasses()
313  {
314  return {CFG_SOUND_SETS};
315  }
316 
317  protected void ChangeFilterSound()
318  {
319  m_ConfigDebugProfile.SetSoundsetFilter(m_SoundFilter.GetText());
320  ChangeFilter(GetSoundClasses(), m_SoundsTextListbox, m_SoundFilter, 0,true);
321  }
322 
323 }
GetGame
proto native CGame GetGame()
MapWidget
Definition: gameplay.c:321
TStringArray
array< string > TStringArray
Definition: enscript.c:685
GetMousePos
proto void GetMousePos(out int x, out int y)
KeyCode
KeyCode
Definition: ensystem.c:156
EditBoxWidget
Definition: enwidgets.c:353
y
Icon y
CFG_SOUND_SETS
const string CFG_SOUND_SETS
Definition: constants.c:217
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
TextWidget
Definition: enwidgets.c:219
KeyState
proto native int KeyState(KeyCode key)
COLOR_GREEN
const int COLOR_GREEN
Definition: constants.c:65
COLOR_RED
const int COLOR_RED
Definition: constants.c:64
ScriptConsoleSoundsTab
Definition: scriptconsolesoundstab.c:1
array< string >
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
m_ConfigDebugProfile
PluginConfigDebugProfile m_ConfigDebugProfile
Definition: pluginitemdiagnostic.c:58
Timer
Definition: dayzplayerimplement.c:62
Widget
Definition: enwidgets.c:189
ScriptConsoleTabBase
Definition: scriptconsoletabbase.c:1
Math
Definition: enmath.c:6
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
Math3D
Definition: enmath3d.c:27