scriptconsolesoundstab.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. class ScriptConsoleSoundsTab : ScriptConsoleTabBase
  2. {
  3. protected bool m_PlayerPosRefreshBlocked;
  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. protected ButtonWidget m_SetETSoundButton;
  10. protected ButtonWidget m_SetETSoundWeaponButton;
  11. protected ButtonWidget m_SetETSoundAttachmentButton;
  12. protected ButtonWidget m_SetETSoundVoiceButton;
  13. protected ButtonWidget m_PlaySoundEventButton;
  14. protected ButtonWidget m_CopySoundset;
  15. protected ButtonWidget m_PlaySoundset;
  16. protected ButtonWidget m_PlaySoundsetLooped;
  17. protected ButtonWidget m_StopSoundset;
  18. protected EditBoxWidget m_SoundEventIDBox;
  19. protected EditBoxWidget m_SoundFilter;
  20. protected TextListboxWidget m_SoundsTextListbox;
  21. protected static EffectSound m_SoundSet;
  22. protected ref Timer m_RefreshFilterTimer = new Timer();
  23. protected MapWidget m_DebugMapWidget;
  24. protected TextWidget m_MapDistWidget;
  25. protected TextWidget m_MouseCurPos;
  26. protected TextWidget m_MapHeadingWidget;
  27. protected ImageWidget m_BBackgroundSound;
  28. protected ImageWidget m_BBackgroundSoundWeapon;
  29. protected ImageWidget m_BBackgroundSoundAttachment;
  30. protected ImageWidget m_BBackgroundSoundVoice;
  31. protected ImageWidget m_SelectedBackground;
  32. protected CheckBoxWidget m_CheckBoxShoulderAtt;
  33. protected CheckBoxWidget m_CheckBoxBodyAtt;
  34. protected CheckBoxWidget m_CheckBoxBackAtt;
  35. void ScriptConsoleSoundsTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
  36. {
  37. m_MouseCurPos = TextWidget.Cast(root.FindAnyWidget("MapSoundsPos"));
  38. m_MapDistWidget = TextWidget.Cast(root.FindAnyWidget("MapSoundsDistance"));
  39. m_MapHeadingWidget = TextWidget.Cast(root.FindAnyWidget("MapHeadingSounds"));
  40. m_SetETSoundButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundButton"));
  41. m_SetETSoundWeaponButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundWeaponButton"));
  42. m_SetETSoundAttachmentButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundAttachmentButton"));
  43. m_SetETSoundVoiceButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundVoiceButton"));
  44. m_PlaySoundEventButton = ButtonWidget.Cast(root.FindAnyWidget("ETSoundPlayButton"));
  45. m_SoundEventIDBox = EditBoxWidget.Cast(root.FindAnyWidget("SoundIDEditBox"));
  46. m_CheckBoxShoulderAtt = CheckBoxWidget.Cast(root.FindAnyWidget("CheckBoxShoulderAtt"));
  47. m_CheckBoxBodyAtt = CheckBoxWidget.Cast(root.FindAnyWidget("CheckBoxBodyAtt"));
  48. m_CheckBoxBackAtt = CheckBoxWidget.Cast(root.FindAnyWidget("CheckBoxBackAtt"));
  49. m_BBackgroundSound = ImageWidget.Cast(root.FindAnyWidget("SoundEventType"));
  50. m_BBackgroundSoundWeapon = ImageWidget.Cast(root.FindAnyWidget("SoundEventType0"));
  51. m_BBackgroundSoundAttachment = ImageWidget.Cast(root.FindAnyWidget("SoundEventType1"));
  52. m_BBackgroundSoundVoice = ImageWidget.Cast(root.FindAnyWidget("SoundEventType2"));
  53. m_CopySoundset = ButtonWidget.Cast(root.FindAnyWidget("SoundsetCopy"));
  54. m_PlaySoundset = ButtonWidget.Cast(root.FindAnyWidget("PlaySoundset"));
  55. m_PlaySoundsetLooped = ButtonWidget.Cast(root.FindAnyWidget("PlaySoundsetLooped"));
  56. m_StopSoundset = ButtonWidget.Cast(root.FindAnyWidget("StopSoundset"));
  57. m_DebugMapWidget = MapWidget.Cast(root.FindAnyWidget("MapSounds"));
  58. m_SoundFilter = EditBoxWidget.Cast(root.FindAnyWidget("SoundsFilter"));
  59. m_SoundsTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("SoundsList"));
  60. m_SoundFilter.SetText(m_ConfigDebugProfile.GetSoundsetFilter());
  61. ChangeFilterSound();
  62. if (GetGame().GetPlayer())
  63. {
  64. m_DebugMapWidget.SetScale(DEBUG_MAP_ZOOM);
  65. m_DebugMapWidget.SetMapPos(GetGame().GetPlayer().GetWorldPosition());
  66. SetMapPos(GetGame().GetPlayer().GetWorldPosition());
  67. }
  68. // reopen update
  69. m_SoundEventIDBox.SetText(m_SelectedID.ToString());
  70. if (m_SelectedSoundEventType == "Sound")
  71. OnClick(m_SetETSoundButton,0,0,0);
  72. else if (m_SelectedSoundEventType == "SoundWeapon")
  73. OnClick(m_SetETSoundWeaponButton,0,0,0);
  74. else if (m_SelectedSoundEventType == "SoundAttachment")
  75. OnClick(m_SetETSoundAttachmentButton,0,0,0);
  76. else if (m_SelectedSoundEventType == "SoundVoice")
  77. OnClick(m_SetETSoundVoiceButton,0,0,0);
  78. string lastSelection = m_SelectedAttachments;
  79. if (lastSelection.Contains("shoulder"))
  80. m_CheckBoxShoulderAtt.SetChecked(true);
  81. if (lastSelection.Contains("body"))
  82. m_CheckBoxBodyAtt.SetChecked(true);
  83. if (lastSelection.Contains("back"))
  84. m_CheckBoxBackAtt.SetChecked(true);
  85. }
  86. void ~ScriptConsoleSoundsTab(Widget root)
  87. {
  88. DEBUG_MAP_ZOOM = m_DebugMapWidget.GetScale();
  89. }
  90. override bool OnChange(Widget w, int x, int y, bool finished)
  91. {
  92. super.OnChange(w, x, y, finished);
  93. if (w == m_SoundFilter)
  94. {
  95. m_RefreshFilterTimer.Run(0.85, this, "ChangeFilterSound", null, false);
  96. return true;
  97. }
  98. return false;
  99. }
  100. void UpdateMousePos()
  101. {
  102. if(!GetGame().GetPlayer())
  103. return;
  104. int x,y;
  105. GetMousePos(x,y);
  106. vector mousePos, worldPos;
  107. mousePos[0] = x;
  108. mousePos[1] = y;
  109. worldPos = m_DebugMapWidget.ScreenToMap(mousePos);
  110. vector playerPos = GetGame().GetPlayer().GetWorldPosition();
  111. if (GetMapPos() != playerPos)
  112. worldPos = GetMapPos();
  113. worldPos[1] = GetGame().SurfaceY(worldPos[0], worldPos[2]);
  114. if (m_MouseCurPos)
  115. {
  116. m_MouseCurPos.SetText("Mouse: "+ MiscGameplayFunctions.TruncateToS(worldPos[0]) +", "+ MiscGameplayFunctions.TruncateToS(worldPos[1]) +", "+ MiscGameplayFunctions.TruncateToS(worldPos[2]));
  117. }
  118. if (m_MapDistWidget && GetGame().GetPlayer())
  119. {
  120. float dst = (worldPos - playerPos).Length();
  121. m_MapDistWidget.SetText("Distance: " + MiscGameplayFunctions.TruncateToS(dst));
  122. }
  123. if (m_MapHeadingWidget)
  124. {
  125. vector playerCamDir = GetGame().GetCurrentCameraDirection();
  126. float heading = Math3D.AngleFromPosition(playerPos, playerCamDir, worldPos) * Math.RAD2DEG;
  127. m_MapHeadingWidget.SetText("Heading:" +heading.ToString());
  128. }
  129. }
  130. protected void PrepareFilters(string filter, out TStringArray filters)
  131. {
  132. filter.Trim();
  133. filter.ToLower();
  134. filters = new TStringArray;
  135. TStringArray rawFilters = new TStringArray;
  136. filter.Split(" ", rawFilters);
  137. foreach (int i, string f:rawFilters)
  138. {
  139. filters.Insert(f);
  140. }
  141. }
  142. // this is a 95% of the code of the function of the same name inside ScriptConsole.c
  143. protected void ChangeFilter(TStringArray classes, TextListboxWidget widget, EditBoxWidget filterWidget, int categoryMask = -1, bool ignoreScope = false)
  144. {
  145. widget.ClearItems();
  146. TStringArray filters;
  147. PrepareFilters(filterWidget.GetText(),filters);
  148. map<string,ref TStringArray> itemsByFilters = new map<string,ref TStringArray>();
  149. TStringArray itemsArray = TStringArray();
  150. for (int i = 0; i < classes.Count(); i++)
  151. {
  152. string config_path = classes.Get(i);
  153. int objects_count = GetGame().ConfigGetChildrenCount(config_path);
  154. for (int j = 0; j < objects_count; j++)
  155. {
  156. string child_name;
  157. bool add = false;
  158. GetGame().ConfigGetChildName(config_path, j, child_name);
  159. if (!filters.Count())
  160. {
  161. add = true;
  162. }
  163. else
  164. {
  165. foreach (int indx, string filter:filters)
  166. {
  167. string child_name_lower = child_name;
  168. child_name_lower.ToLower();
  169. if (child_name_lower.Contains(filter))
  170. {
  171. add = true;
  172. break;
  173. }
  174. }
  175. }
  176. if (add)
  177. itemsArray.Insert(child_name);
  178. }
  179. }
  180. if (itemsArray)
  181. {
  182. itemsArray.Sort();
  183. foreach (string it:itemsArray)
  184. {
  185. widget.AddItem(it, NULL, 0);
  186. }
  187. }
  188. if (filters)
  189. {
  190. /*
  191. if (m_FilterOrderReversed)
  192. filters.Invert();
  193. */
  194. foreach (string f:filters)
  195. {
  196. TStringArray arr2 = itemsByFilters.Get(f);
  197. if (arr2)
  198. {
  199. arr2.Sort();
  200. foreach (string itm: arr2)
  201. {
  202. int row = widget.AddItem(itm, NULL, 0);
  203. }
  204. }
  205. }
  206. }
  207. }
  208. override void Update(float timeslice)
  209. {
  210. super.Update(timeslice);
  211. HandleKeys();
  212. m_DebugMapWidget.ClearUserMarks();
  213. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  214. if (player)
  215. {
  216. vector playerPos = player.GetWorldPosition();
  217. m_DebugMapWidget.AddUserMark(playerPos,"You", COLOR_RED,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
  218. if (playerPos != GetMapPos())
  219. m_DebugMapWidget.AddUserMark(GetMapPos(),"Source", COLOR_GREEN,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
  220. }
  221. UpdateMousePos();
  222. }
  223. protected void HandleKeys()
  224. {
  225. bool playRequested = KeyState(KeyCode.KC_P) != 0;
  226. if (playRequested)
  227. {
  228. int selected_row_index = m_SoundsTextListbox.GetSelectedRow();
  229. if (m_SoundSet)
  230. m_SoundSet.Stop();
  231. if (selected_row_index != -1)
  232. {
  233. string soundSetName;
  234. m_SoundsTextListbox.GetItemText(selected_row_index, 0, soundSetName);
  235. m_SoundSet = SEffectManager.PlaySoundEnviroment(soundSetName, GetMapPos());
  236. m_SoundSet.SetAutodestroy(true);
  237. }
  238. }
  239. }
  240. protected void SetMapPos(vector pos)
  241. {
  242. m_MapPos = pos;
  243. }
  244. protected vector GetMapPos()
  245. {
  246. return m_MapPos;
  247. }
  248. protected void PlaySoundEvent()
  249. {
  250. m_SelectedID = m_SoundEventIDBox.GetText().ToInt();
  251. if (m_SelectedID == 0)
  252. return;
  253. DayZPlayerImplement player = DayZPlayerImplement.Cast(GetGame().GetPlayer());
  254. if (m_SelectedSoundEventType == "SoundAttachment")
  255. player.OnSoundEvent(m_SelectedSoundEventType, m_SelectedAttachments, m_SelectedID);
  256. else
  257. player.OnSoundEvent(m_SelectedSoundEventType, string.Empty, m_SoundEventIDBox.GetText().ToInt());
  258. }
  259. protected void UpdateAttachmentSelection()
  260. {
  261. string attachments = string.Empty;
  262. if (m_CheckBoxShoulderAtt.IsChecked())
  263. attachments += "shoulder,";
  264. if (m_CheckBoxBodyAtt.IsChecked())
  265. attachments += "body,";
  266. if (m_CheckBoxBackAtt.IsChecked())
  267. attachments += "back";
  268. m_SelectedAttachments = attachments;
  269. }
  270. protected void UpdateSelectedColor(ImageWidget buttonBackground)
  271. {
  272. if (m_SelectedBackground)
  273. m_SelectedBackground.SetColor(0xFF141414);
  274. buttonBackground.SetColor(COLOR_RED);
  275. m_SelectedBackground = buttonBackground;
  276. }
  277. override bool OnMouseButtonDown(Widget w, int x, int y, int button)
  278. {
  279. super.OnMouseButtonDown(w,x,y,button);
  280. if (w == m_DebugMapWidget)
  281. {
  282. if (button == 0)
  283. {
  284. m_PlayerPosRefreshBlocked = true;
  285. int mouseX, mouseY;
  286. GetMousePos(mouseX,mouseY);
  287. vector mousePos, worldPos;
  288. mousePos[0] = mouseX;
  289. mousePos[1] = mouseY;
  290. worldPos = m_DebugMapWidget.ScreenToMap(mousePos);
  291. worldPos[1] = GetGame().SurfaceY(worldPos[0], worldPos[2]);
  292. SetMapPos(worldPos);
  293. }
  294. else if (button == 1 && GetGame().GetPlayer())
  295. {
  296. SetMapPos(GetGame().GetPlayer().GetWorldPosition());
  297. }
  298. }
  299. return true;
  300. }
  301. override bool OnClick(Widget w, int x, int y, int button)
  302. {
  303. super.OnClick(w,x,y,button);
  304. if (w == m_CopySoundset)
  305. {
  306. AddItemToClipboard(m_SoundsTextListbox);
  307. return true;
  308. }
  309. else if (w == m_PlaySoundset || w == m_PlaySoundsetLooped)
  310. {
  311. int selected_row_index = m_SoundsTextListbox.GetSelectedRow();
  312. string soundSetName;
  313. if (m_SoundSet)
  314. m_SoundSet.Stop();
  315. if (selected_row_index != -1)
  316. {
  317. m_SoundsTextListbox.GetItemText(selected_row_index, 0, soundSetName);
  318. bool looped = (w == m_PlaySoundsetLooped);
  319. m_SoundSet = SEffectManager.PlaySoundEnviroment(soundSetName, GetMapPos(), 0, 0, looped);
  320. }
  321. return true;
  322. }
  323. else if (w == m_StopSoundset)
  324. {
  325. if (m_SoundSet)
  326. m_SoundSet.Stop();
  327. return true;
  328. }
  329. else if (w == m_SoundFilter)
  330. {
  331. ChangeFilterSound();
  332. return true;
  333. }
  334. else if (w == m_SetETSoundButton)
  335. {
  336. m_SelectedSoundEventType = "Sound";
  337. UpdateSelectedColor(m_BBackgroundSound);
  338. return true;
  339. }
  340. else if (w == m_SetETSoundWeaponButton)
  341. {
  342. m_SelectedSoundEventType = "SoundWeapon";
  343. UpdateSelectedColor(m_BBackgroundSoundWeapon);
  344. return true;
  345. }
  346. else if (w == m_SetETSoundAttachmentButton)
  347. {
  348. m_SelectedSoundEventType = "SoundAttachment";
  349. UpdateSelectedColor(m_BBackgroundSoundAttachment);
  350. return true;
  351. }
  352. else if (w == m_SetETSoundVoiceButton)
  353. {
  354. m_SelectedSoundEventType = "SoundVoice";
  355. UpdateSelectedColor(m_BBackgroundSoundVoice);
  356. return true;
  357. }
  358. else if (w == m_PlaySoundEventButton)
  359. {
  360. PlaySoundEvent();
  361. return true;
  362. }
  363. else if (w == m_CheckBoxShoulderAtt || w == m_CheckBoxBodyAtt || w == m_CheckBoxBackAtt)
  364. {
  365. UpdateAttachmentSelection();
  366. return true;
  367. }
  368. return false;
  369. }
  370. override bool OnDoubleClick(Widget w, int x, int y, int button)
  371. {
  372. super.OnDoubleClick(w, x, y, button);
  373. if (w == m_SoundEventIDBox || w == m_SoundFilter)
  374. {
  375. EditBoxWidget.Cast(w).SetText("");
  376. return true;
  377. }
  378. return false;
  379. }
  380. protected TStringArray GetSoundClasses()
  381. {
  382. return {CFG_SOUND_SETS};
  383. }
  384. protected void ChangeFilterSound()
  385. {
  386. m_ConfigDebugProfile.SetSoundsetFilter(m_SoundFilter.GetText());
  387. ChangeFilter(GetSoundClasses(), m_SoundsTextListbox, m_SoundFilter, 0,true);
  388. }
  389. }