SoundKeyUIControls.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. bool CSoundKeyUIControls::OnKeySelectionChange(const CTrackViewKeyBundle& selectedKeys)
  15. {
  16. if (!selectedKeys.AreAllKeysOfSameType())
  17. {
  18. return false;
  19. }
  20. bool bAssigned = false;
  21. if (selectedKeys.GetKeyCount() == 1)
  22. {
  23. const CTrackViewKeyHandle& keyHandle = selectedKeys.GetKey(0);
  24. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  25. if (paramType == AnimParamType::Sound)
  26. {
  27. ISoundKey soundKey;
  28. keyHandle.GetKey(&soundKey);
  29. mv_startTrigger = soundKey.sStartTrigger.c_str();
  30. mv_stopTrigger = soundKey.sStopTrigger.c_str();
  31. mv_duration = soundKey.fDuration;
  32. mv_customColor = soundKey.customColor;
  33. bAssigned = true;
  34. }
  35. }
  36. return bAssigned;
  37. }
  38. // Called when UI variable changes.
  39. void CSoundKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  40. {
  41. CTrackViewSequence* pSequence = GetIEditor()->GetAnimation()->GetSequence();
  42. if (!pSequence || !selectedKeys.AreAllKeysOfSameType())
  43. {
  44. return;
  45. }
  46. for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
  47. {
  48. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  49. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  50. if (paramType == AnimParamType::Sound)
  51. {
  52. ISoundKey soundKey;
  53. keyHandle.GetKey(&soundKey);
  54. if (pVar == mv_startTrigger.GetVar())
  55. {
  56. QString sFilename = mv_startTrigger;
  57. soundKey.sStartTrigger = sFilename.toUtf8().data();
  58. }
  59. else if (pVar == mv_stopTrigger.GetVar())
  60. {
  61. QString sFilename = mv_stopTrigger;
  62. soundKey.sStopTrigger = sFilename.toUtf8().data();
  63. }
  64. SyncValue(mv_duration, soundKey.fDuration, false, pVar);
  65. SyncValue(mv_customColor, soundKey.customColor, false, pVar);
  66. keyHandle.SetKey(&soundKey);
  67. }
  68. }
  69. }