ConsoleKeyUIControls.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 CConsoleKeyUIControls::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::Console)
  27. {
  28. IConsoleKey consoleKey;
  29. keyHandle.GetKey(&consoleKey);
  30. mv_command = ((QString)consoleKey.command.c_str()).toUtf8().data();
  31. bAssigned = true;
  32. }
  33. }
  34. return bAssigned;
  35. }
  36. // Called when UI variable changes.
  37. void CConsoleKeyUIControls::OnUIChange(IVariable* pVar, CTrackViewKeyBundle& selectedKeys)
  38. {
  39. CTrackViewSequence* sequence = GetIEditor()->GetAnimation()->GetSequence();
  40. if (!sequence || !selectedKeys.AreAllKeysOfSameType())
  41. {
  42. return;
  43. }
  44. for (unsigned int keyIndex = 0; keyIndex < selectedKeys.GetKeyCount(); ++keyIndex)
  45. {
  46. CTrackViewKeyHandle keyHandle = selectedKeys.GetKey(keyIndex);
  47. CAnimParamType paramType = keyHandle.GetTrack()->GetParameterType();
  48. if (paramType == AnimParamType::Console)
  49. {
  50. IConsoleKey consoleKey;
  51. keyHandle.GetKey(&consoleKey);
  52. if (pVar == mv_command.GetVar())
  53. {
  54. consoleKey.command = ((QString)mv_command).toUtf8().data();
  55. }
  56. bool isDuringUndo = false;
  57. AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(isDuringUndo, &AzToolsFramework::ToolsApplicationRequests::Bus::Events::IsDuringUndoRedo);
  58. if (isDuringUndo)
  59. {
  60. keyHandle.SetKey(&consoleKey);
  61. }
  62. else
  63. {
  64. AzToolsFramework::ScopedUndoBatch undoBatch("Set Key Value");
  65. keyHandle.SetKey(&consoleKey);
  66. undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
  67. }
  68. }
  69. }
  70. }