Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
scriptconsolesoundstab.c
Go to the documentation of this file.
2{
4 protected static float DEBUG_MAP_ZOOM = 1;
5 protected vector m_MapPos;
6 protected static int m_SelectedID;
7 protected static string m_SelectedSoundEventType;
8 protected static string m_SelectedAttachments;
9
10 protected ButtonWidget m_SetETSoundButton;
11 protected ButtonWidget m_SetETSoundWeaponButton;
12 protected ButtonWidget m_SetETSoundAttachmentButton;
13 protected ButtonWidget m_SetETSoundVoiceButton;
14 protected ButtonWidget m_PlaySoundEventButton;
15 protected ButtonWidget m_CopySoundset;
16 protected ButtonWidget m_PlaySoundset;
17 protected ButtonWidget m_PlaySoundsetLooped;
18 protected ButtonWidget m_StopSoundset;
19
22 protected TextListboxWidget m_SoundsTextListbox;
23
24 protected static EffectSound m_SoundSet;
25 protected ref Timer m_RefreshFilterTimer = new Timer();
26
31
32 protected ImageWidget m_BBackgroundSound;
33 protected ImageWidget m_BBackgroundSoundWeapon;
34 protected ImageWidget m_BBackgroundSoundAttachment;
35 protected ImageWidget m_BBackgroundSoundVoice;
36 protected ImageWidget m_SelectedBackground;
37
38 protected CheckBoxWidget m_CheckBoxShoulderAtt;
39 protected CheckBoxWidget m_CheckBoxBodyAtt;
40 protected CheckBoxWidget m_CheckBoxBackAtt;
41
42 void ScriptConsoleSoundsTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
43 {
44 m_MouseCurPos = TextWidget.Cast(root.FindAnyWidget("MapSoundsPos"));
45 m_MapDistWidget = TextWidget.Cast(root.FindAnyWidget("MapSoundsDistance"));
46 m_MapHeadingWidget = TextWidget.Cast(root.FindAnyWidget("MapHeadingSounds"));
47
48 m_SetETSoundButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundButton"));
49 m_SetETSoundWeaponButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundWeaponButton"));
50 m_SetETSoundAttachmentButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundAttachmentButton"));
51 m_SetETSoundVoiceButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundVoiceButton"));
52 m_PlaySoundEventButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundPlayButton"));
53 m_SoundEventIDBox = EditBoxWidget.Cast(root.FindAnyWidget("SoundIDEditBox"));
54 m_CheckBoxShoulderAtt = CheckBoxWidget.Cast(root.FindAnyWidget("CheckBoxShoulderAtt"));
55 m_CheckBoxBodyAtt = CheckBoxWidget.Cast(root.FindAnyWidget("CheckBoxBodyAtt"));
56 m_CheckBoxBackAtt = CheckBoxWidget.Cast(root.FindAnyWidget("CheckBoxBackAtt"));
57 m_BBackgroundSound = ImageWidget.Cast(root.FindAnyWidget("SoundEventType"));
58 m_BBackgroundSoundWeapon = ImageWidget.Cast(root.FindAnyWidget("SoundEventType0"));
59 m_BBackgroundSoundAttachment = ImageWidget.Cast(root.FindAnyWidget("SoundEventType1"));
60 m_BBackgroundSoundVoice = ImageWidget.Cast(root.FindAnyWidget("SoundEventType2"));
61
62 m_CopySoundset = ButtonWidget.Cast(root.FindAnyWidget("SoundsetCopy"));
63 m_PlaySoundset = ButtonWidget.Cast(root.FindAnyWidget("PlaySoundset"));
64 m_PlaySoundsetLooped = ButtonWidget.Cast(root.FindAnyWidget("PlaySoundsetLooped"));
65 m_StopSoundset = ButtonWidget.Cast(root.FindAnyWidget("StopSoundset"));
66 m_DebugMapWidget = MapWidget.Cast(root.FindAnyWidget("MapSounds"));
67
68 m_SoundFilter = EditBoxWidget.Cast(root.FindAnyWidget("SoundsFilter"));
69 m_SoundsTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("SoundsList"));
70
71 m_SoundFilter.SetText(m_ConfigDebugProfile.GetSoundsetFilter());
72
73
75
76 if (g_Game.GetPlayer())
77 {
79 m_DebugMapWidget.SetMapPos(g_Game.GetPlayer().GetWorldPosition());
80 SetMapPos(g_Game.GetPlayer().GetWorldPosition());
81 }
82
83 // reopen update
84 m_SoundEventIDBox.SetText(m_SelectedID.ToString());
85
86 if (m_SelectedSoundEventType == "Sound")
88 else if (m_SelectedSoundEventType == "SoundWeapon")
90 else if (m_SelectedSoundEventType == "SoundAttachment")
92 else if (m_SelectedSoundEventType == "SoundVoice")
94
95 string lastSelection = m_SelectedAttachments;
96 if (lastSelection.Contains("shoulder"))
97 m_CheckBoxShoulderAtt.SetChecked(true);
98 if (lastSelection.Contains("body"))
99 m_CheckBoxBodyAtt.SetChecked(true);
100 if (lastSelection.Contains("back"))
101 m_CheckBoxBackAtt.SetChecked(true);
102
103 }
104
106 {
107 DEBUG_MAP_ZOOM = m_DebugMapWidget.GetScale();
108 }
109
110 override bool OnChange(Widget w, int x, int y, bool finished)
111 {
112 super.OnChange(w, x, y, finished);
113
114 if (w == m_SoundFilter)
115 {
116 m_RefreshFilterTimer.Run(0.85, this, "ChangeFilterSound", null, false);
117 return true;
118 }
119 return false;
120 }
121
123 {
124 if(!g_Game.GetPlayer())
125 return;
126 int x,y;
127 GetMousePos(x,y);
128 vector mousePos, worldPos;
129 mousePos[0] = x;
130 mousePos[1] = y;
131 worldPos = m_DebugMapWidget.ScreenToMap(mousePos);
132 vector playerPos = g_Game.GetPlayer().GetWorldPosition();
133 if (GetMapPos() != playerPos)
134 worldPos = GetMapPos();
135 worldPos[1] = g_Game.SurfaceY(worldPos[0], worldPos[2]);
136
137 if (m_MouseCurPos)
138 {
139 m_MouseCurPos.SetText("Mouse: "+ MiscGameplayFunctions.TruncateToS(worldPos[0]) +", "+ MiscGameplayFunctions.TruncateToS(worldPos[1]) +", "+ MiscGameplayFunctions.TruncateToS(worldPos[2]));
140 }
141 if (m_MapDistWidget && g_Game.GetPlayer())
142 {
143 float dst = (worldPos - playerPos).Length();
144
145 m_MapDistWidget.SetText("Distance: " + MiscGameplayFunctions.TruncateToS(dst));
146 }
148 {
149 vector playerCamDir = g_Game.GetCurrentCameraDirection();
150 float heading = Math3D.AngleFromPosition(playerPos, playerCamDir, worldPos) * Math.RAD2DEG;
151 m_MapHeadingWidget.SetText("Heading:" +heading.ToString());
152 }
153 }
154
155 protected void PrepareFilters(string filter, out TStringArray filters)
156 {
157 filter.Trim();
158 filter.ToLower();
159
160 filters = new TStringArray;
161 TStringArray rawFilters = new TStringArray;
162 filter.Split(" ", rawFilters);
163
164 foreach (int i, string f:rawFilters)
165 {
166 filters.Insert(f);
167
168 }
169 }
170
171 // this is a 95% of the code of the function of the same name inside ScriptConsole.c
172 protected void ChangeFilter(TStringArray classes, TextListboxWidget widget, EditBoxWidget filterWidget, int categoryMask = -1, bool ignoreScope = false)
173 {
174 widget.ClearItems();
175
176 TStringArray filters;
177 PrepareFilters(filterWidget.GetText(),filters);
178
180
181 TStringArray itemsArray = TStringArray();
182
183 for (int i = 0; i < classes.Count(); i++)
184 {
185 string config_path = classes.Get(i);
186
187 int objects_count = g_Game.ConfigGetChildrenCount(config_path);
188 for (int j = 0; j < objects_count; j++)
189 {
190 string child_name;
191 bool add = false;
192 g_Game.ConfigGetChildName(config_path, j, child_name);
193
194 if (!filters.Count())
195 {
196 add = true;
197 }
198 else
199 {
200 foreach (int indx, string filter:filters)
201 {
202 string child_name_lower = child_name;
203 child_name_lower.ToLower();
204
205 if (child_name_lower.Contains(filter))
206 {
207 add = true;
208 break;
209 }
210 }
211 }
212 if (add)
213 itemsArray.Insert(child_name);
214 }
215 }
216
217 if (itemsArray)
218 {
219 itemsArray.Sort();
220 foreach (string it:itemsArray)
221 {
222 widget.AddItem(it, NULL, 0);
223 }
224 }
225
226 if (filters)
227 {
228 /*
229 if (m_FilterOrderReversed)
230 filters.Invert();
231 */
232 foreach (string f:filters)
233 {
234 TStringArray arr2 = itemsByFilters.Get(f);
235 if (arr2)
236 {
237 arr2.Sort();
238 foreach (string itm: arr2)
239 {
240 int row = widget.AddItem(itm, NULL, 0);
241 }
242 }
243 }
244 }
245
246
247 }
248
249 override void Update(float timeslice)
250 {
251 super.Update(timeslice);
252
253 HandleKeys();
254 m_DebugMapWidget.ClearUserMarks();
255
256 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
257
258 if (player)
259 {
260 vector playerPos = player.GetWorldPosition();
261 m_DebugMapWidget.AddUserMark(playerPos,"You", COLOR_RED,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
262
263 if (playerPos != GetMapPos())
264 m_DebugMapWidget.AddUserMark(GetMapPos(),"Source", COLOR_GREEN,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
265 }
267 }
268
269 protected void HandleKeys()
270 {
271 bool playRequested = KeyState(KeyCode.KC_P) != 0;
272 if (playRequested)
273 {
274 int selected_row_index = m_SoundsTextListbox.GetSelectedRow();
275
276 if (m_SoundSet)
277 m_SoundSet.Stop();
278 if (selected_row_index != -1)
279 {
280 string soundSetName;
281 m_SoundsTextListbox.GetItemText(selected_row_index, 0, soundSetName);
282
284 m_SoundSet.SetAutodestroy(true);
285 }
286 }
287 }
288
289 protected void SetMapPos(vector pos)
290 {
291 m_MapPos = pos;
292 }
293
294 protected vector GetMapPos()
295 {
296 return m_MapPos;
297 }
298
299 protected void PlaySoundEvent()
300 {
301 m_SelectedID = m_SoundEventIDBox.GetText().ToInt();
302 if (m_SelectedID == 0)
303 return;
304
305 DayZPlayerImplement player = DayZPlayerImplement.Cast(g_Game.GetPlayer());
306
307 if (m_SelectedSoundEventType == "SoundAttachment")
309 else
310 player.OnSoundEvent(m_SelectedSoundEventType, string.Empty, m_SoundEventIDBox.GetText().ToInt());
311 }
312
314 {
315 string attachments = string.Empty;
316 if (m_CheckBoxShoulderAtt.IsChecked())
317 attachments += "shoulder,";
318 if (m_CheckBoxBodyAtt.IsChecked())
319 attachments += "body,";
320 if (m_CheckBoxBackAtt.IsChecked())
321 attachments += "back";
322
323 m_SelectedAttachments = attachments;
324 }
325
326 protected void UpdateSelectedColor(ImageWidget buttonBackground)
327 {
329 m_SelectedBackground.SetColor(0xFF141414);
330
331 buttonBackground.SetColor(COLOR_RED);
332
333 m_SelectedBackground = buttonBackground;
334 }
335
336 override bool OnMouseButtonDown(Widget w, int x, int y, int button)
337 {
338 super.OnMouseButtonDown(w,x,y,button);
339
340 if (w == m_DebugMapWidget)
341 {
342 if (button == 0)
343 {
345 int mouseX, mouseY;
346 GetMousePos(mouseX,mouseY);
347 vector mousePos, worldPos;
348 mousePos[0] = mouseX;
349 mousePos[1] = mouseY;
350 worldPos = m_DebugMapWidget.ScreenToMap(mousePos);
351 worldPos[1] = g_Game.SurfaceY(worldPos[0], worldPos[2]);
352
353 SetMapPos(worldPos);
354 }
355 else if (button == 1 && g_Game.GetPlayer())
356 {
357 SetMapPos(g_Game.GetPlayer().GetWorldPosition());
358 }
359 }
360 return true;
361 }
362
363 override bool OnClick(Widget w, int x, int y, int button)
364 {
365 super.OnClick(w,x,y,button);
366
367 if (w == m_CopySoundset)
368 {
370 return true;
371 }
372 else if (w == m_PlaySoundset || w == m_PlaySoundsetLooped)
373 {
374 int selected_row_index = m_SoundsTextListbox.GetSelectedRow();
375 string soundSetName;
376 if (m_SoundSet)
377 m_SoundSet.Stop();
378 if (selected_row_index != -1)
379 {
380 m_SoundsTextListbox.GetItemText(selected_row_index, 0, soundSetName);
381
382 bool looped = (w == m_PlaySoundsetLooped);
383 m_SoundSet = SEffectManager.PlaySoundEnviroment(soundSetName, GetMapPos(), 0, 0, looped);
384
385 }
386 return true;
387 }
388 else if (w == m_StopSoundset)
389 {
390 if (m_SoundSet)
391 m_SoundSet.Stop();
392 return true;
393 }
394 else if (w == m_SoundFilter)
395 {
397 return true;
398 }
399 else if (w == m_SetETSoundButton)
400 {
401 m_SelectedSoundEventType = "Sound";
403 return true;
404 }
405 else if (w == m_SetETSoundWeaponButton)
406 {
407 m_SelectedSoundEventType = "SoundWeapon";
409 return true;
410 }
411 else if (w == m_SetETSoundAttachmentButton)
412 {
413 m_SelectedSoundEventType = "SoundAttachment";
415 return true;
416 }
417 else if (w == m_SetETSoundVoiceButton)
418 {
419 m_SelectedSoundEventType = "SoundVoice";
421 return true;
422 }
423 else if (w == m_PlaySoundEventButton)
424 {
426 return true;
427 }
428 else if (w == m_CheckBoxShoulderAtt || w == m_CheckBoxBodyAtt || w == m_CheckBoxBackAtt)
429 {
431 return true;
432 }
433
434 return false;
435 }
436
437 override bool OnDoubleClick(Widget w, int x, int y, int button)
438 {
439 super.OnDoubleClick(w, x, y, button);
440
441 if (w == m_SoundEventIDBox || w == m_SoundFilter)
442 {
443 EditBoxWidget.Cast(w).SetText("");
444 return true;
445 }
446
447 return false;
448 }
449
451 {
452 return {CFG_SOUND_SETS};
453 }
454
455 protected void ChangeFilterSound()
456 {
457 m_ConfigDebugProfile.SetSoundsetFilter(m_SoundFilter.GetText());
459 }
460
461}
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
Definition enmath.c:7
Manager class for managing Effect (EffectParticle, EffectSound).
static EffectSound PlaySoundEnviroment(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound, updating environment variables.
override bool OnChange(Widget w, int x, int y, bool finished)
override void Update(float timeslice)
override bool OnDoubleClick(Widget w, int x, int y, int button)
TextListboxWidget m_SoundsTextListbox
void UpdateSelectedColor(ImageWidget buttonBackground)
void PrepareFilters(string filter, out TStringArray filters)
void ChangeFilter(TStringArray classes, TextListboxWidget widget, EditBoxWidget filterWidget, int categoryMask=-1, bool ignoreScope=false)
void ScriptConsoleSoundsTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent=null)
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
void ~ScriptConsoleSoundsTab(Widget root)
override bool OnClick(Widget w, int x, int y, int button)
PluginConfigDebugProfile m_ConfigDebugProfile
void ScriptConsoleTabBase(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent=null)
void AddItemToClipboard(TextListboxWidget text_listbox_widget)
proto string ToString(bool simple=true)
DayZGame g_Game
Definition dayzgame.c:3942
const int COLOR_RED
Definition constants.c:64
const int COLOR_GREEN
Definition constants.c:65
array< string > TStringArray
Definition enscript.c:712
KeyCode
Definition ensystem.c:157
proto native int KeyState(KeyCode key)
Gets key state.
static proto float AngleFromPosition(vector origin, vector originDir, vector target)
Angle that a target is from the direction of an origin.
static const float RAD2DEG
Definition enmath.c:16
const string CFG_SOUND_SETS
Definition constants.c:228
proto void GetMousePos(out int x, out int y)
void Split(string sample, out array< string > output)
Splits string into array of strings separated by 'sample'.
Definition enstring.c:396
bool Contains(string sample)
Returns true if sample is substring of string.
Definition enstring.c:286
proto string Trim()
Returns trimmed string with removed leading and trailing whitespaces.
proto int ToLower()
Changes string to lowercase.
Empty
Definition hand_states.c:14
Icon x
Icon y