SoundKeyUIControls.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorDefs.h"
  9. // CryCommon
  10. #include <CryCommon/Maestro/Types/AnimParamType.h> // for AnimParamType
  11. // Editor
  12. #include "KeyUIControls.h"
  13. #include "TrackViewKeyPropertiesDlg.h" // for CTrackViewKeyUIControls
  14. //////////////////////////////////////////////////////////////////////////
  15. bool CSoundKeyUIControls::OnKeySelectionChange(const CTrackViewKeyBundle& selectedKeys)
  16. {
  17. if (!selectedKeys.AreAllKeysOfSameType())
  18. {
  19. return false;
  20. }
  21. bool bAssigned = false;
  22. if (selectedKeys.GetKeyCount() == 1)
  23. {
  24. const CTrackViewKeyHandle& keyHandle = selectedKeys.GetKey(0);
  25. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  26. if (paramType == AnimParamType::Sound)
  27. {
  28. ISoundKey soundKey;
  29. keyHandle.GetKey(&soundKey);
  30. mv_startTrigger = soundKey.sStartTrigger.c_str();
  31. mv_stopTrigger = soundKey.sStopTrigger.c_str();
  32. mv_duration = soundKey.fDuration;
  33. mv_customColor = soundKey.customColor;
  34. bAssigned = true;
  35. }
  36. }
  37. return bAssigned;
  38. }
  39. // Called when UI variable changes.
  40. void CSoundKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  41. {
  42. CTrackViewSequence* pSequence = GetIEditor()->GetAnimation()->GetSequence();
  43. if (!pSequence || !selectedKeys.AreAllKeysOfSameType())
  44. {
  45. return;
  46. }
  47. for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
  48. {
  49. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  50. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  51. if (paramType == AnimParamType::Sound)
  52. {
  53. ISoundKey soundKey;
  54. keyHandle.GetKey(&soundKey);
  55. if (pVar == mv_startTrigger.GetVar())
  56. {
  57. QString sFilename = mv_startTrigger;
  58. soundKey.sStartTrigger = sFilename.toUtf8().data();
  59. }
  60. else if (pVar == mv_stopTrigger.GetVar())
  61. {
  62. QString sFilename = mv_stopTrigger;
  63. soundKey.sStopTrigger = sFilename.toUtf8().data();
  64. }
  65. SyncValue(mv_duration, soundKey.fDuration, false, pVar);
  66. SyncValue(mv_customColor, soundKey.customColor, false, pVar);
  67. keyHandle.SetKey(&soundKey);
  68. }
  69. }
  70. }