AnimationWindow.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /** @addtogroup Windows
  7. * @{
  8. */
  9. /// <summary>
  10. /// Displays animation curve editor window.
  11. /// </summary>
  12. internal class AnimationWindow : EditorWindow
  13. {
  14. private GUITimeline timeline;
  15. private GUICurveDrawing curveDrawing;
  16. private GUIFloatField lengthField;
  17. private GUIIntField fpsField;
  18. private GUIFloatField yRangeField;
  19. /// <summary>
  20. /// Opens the animation window.
  21. /// </summary>
  22. [MenuItem("Windows/Animation", ButtonModifier.CtrlAlt, ButtonCode.A, 6000)]
  23. private static void OpenGameWindow()
  24. {
  25. OpenWindow<AnimationWindow>();
  26. }
  27. /// <inheritdoc/>
  28. protected override LocString GetDisplayName()
  29. {
  30. return new LocEdString("Animation");
  31. }
  32. private void OnInitialize()
  33. {
  34. lengthField = new GUIFloatField(new LocEdString("Length"), 50);
  35. fpsField = new GUIIntField(new LocEdString("FPS"), 50);
  36. yRangeField = new GUIFloatField(new LocEdString("Y range"), 50);
  37. lengthField.Value = 60.0f;
  38. fpsField.Value = 1;
  39. yRangeField.Value = 20.0f;
  40. lengthField.OnChanged += x =>
  41. {
  42. timeline.SetRange(lengthField.Value);
  43. curveDrawing.SetRange(lengthField.Value, yRangeField.Value * -0.5f, yRangeField.Value * 0.5f);
  44. };
  45. fpsField.OnChanged += x => timeline.SetFPS(x);
  46. yRangeField.OnChanged += x =>
  47. {
  48. curveDrawing.SetRange(lengthField.Value, x * -0.5f, x * 0.5f);
  49. };
  50. GUILayout mainLayout = GUI.AddLayoutY();
  51. GUILayout buttonLayout = mainLayout.AddLayoutX();
  52. buttonLayout.AddSpace(5);
  53. buttonLayout.AddElement(lengthField);
  54. buttonLayout.AddSpace(5);
  55. buttonLayout.AddElement(yRangeField);
  56. buttonLayout.AddSpace(5);
  57. buttonLayout.AddElement(fpsField);
  58. buttonLayout.AddSpace(5);
  59. timeline = new GUITimeline(mainLayout, Width, 20);
  60. EdAnimationCurve[] curves = CreateDummyCurves();
  61. curveDrawing = new GUICurveDrawing(mainLayout, Width, Height - 20, curves);
  62. curveDrawing.SetRange(60.0f, -10.0f, 10.0f);
  63. // TODO - Calculate min/max Y and range to set as default
  64. // - Also recalculate whenever curves change and increase as needed
  65. }
  66. private EdAnimationCurve[] CreateDummyCurves()
  67. {
  68. EdAnimationCurve[] curves = new EdAnimationCurve[1];
  69. curves[0] = new EdAnimationCurve();
  70. curves[0].AddKeyframe(0.0f, 1.0f);
  71. curves[0].AddKeyframe(10.0f, 5.0f);
  72. curves[0].AddKeyframe(15.0f, -2.0f);
  73. return curves;
  74. }
  75. protected override void WindowResized(int width, int height)
  76. {
  77. timeline.SetSize(width, 20);
  78. curveDrawing.SetSize(width, height - 20);
  79. }
  80. private void OnEditorUpdate()
  81. {
  82. //int position = (int)(MathEx.Sin(Time.RealElapsed)*50.0f + 50.0f);
  83. //canvas.SetPosition(position, 0);
  84. }
  85. }
  86. /** @} */
  87. }