StringKeyUIControls.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include "KeyUIControls.h"
  10. #include "TrackViewKeyPropertiesDlg.h"
  11. #include <CryCommon/Maestro/Types/AnimValueType.h>
  12. bool CStringKeyUIControls::OnKeySelectionChange(const CTrackViewKeyBundle& selectedKeys)
  13. {
  14. if (!selectedKeys.AreAllKeysOfSameType())
  15. {
  16. return false;
  17. }
  18. if (selectedKeys.GetKeyCount() == 1)
  19. {
  20. const CTrackViewKeyHandle& keyHandle = selectedKeys.GetKey(0);
  21. AnimValueType valueType = keyHandle.GetTrack()->GetValueType();
  22. if (valueType == AnimValueType::String)
  23. {
  24. IStringKey stringKey;
  25. keyHandle.GetKey(&stringKey);
  26. mv_value = QString::fromStdString(stringKey.m_strValue.c_str());
  27. return true;
  28. }
  29. }
  30. return false;
  31. }
  32. void CStringKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  33. {
  34. CTrackViewSequence* sequence = GetIEditor()->GetAnimation()->GetSequence();
  35. if (!sequence || !selectedKeys.AreAllKeysOfSameType())
  36. {
  37. return;
  38. }
  39. for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
  40. {
  41. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  42. if (keyHandle.GetTrack()->GetValueType() != AnimValueType::String)
  43. {
  44. continue;
  45. }
  46. IStringKey stringKey;
  47. keyHandle.GetKey(&stringKey);
  48. if (pVar == mv_value.GetVar())
  49. {
  50. stringKey.m_strValue = qUtf8Printable(mv_value);
  51. }
  52. bool isDuringUndo = false;
  53. AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(isDuringUndo, &AzToolsFramework::ToolsApplicationRequests::Bus::Events::IsDuringUndoRedo);
  54. if (isDuringUndo)
  55. {
  56. keyHandle.SetKey(&stringKey);
  57. }
  58. else
  59. {
  60. AzToolsFramework::ScopedUndoBatch undoBatch("Set Key Value");
  61. keyHandle.SetKey(&stringKey);
  62. undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
  63. }
  64. }
  65. }