GUIAnimFieldDisplay.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using bs;
  7. namespace bs.Editor
  8. {
  9. /** @addtogroup AnimationEditor
  10. * @{
  11. */
  12. /// <summary>
  13. /// Renders a hierarchical list of animation curve fields and displays information about them. Also allows field
  14. /// selection.
  15. /// </summary>
  16. internal class GUIAnimFieldDisplay
  17. {
  18. private SceneObject root;
  19. private int width;
  20. private int height;
  21. private GUIScrollArea scrollArea;
  22. private List<AnimFieldInfo> fieldInfos = new List<AnimFieldInfo>();
  23. private GUIAnimFieldEntry[] fields;
  24. private GUIAnimFieldLayouts layouts;
  25. /// <summary>
  26. /// Triggered when the user clicks on an new entry in the field display. Curve field path of the selected entry
  27. /// is provided.
  28. /// </summary>
  29. public Action<string> OnEntrySelected;
  30. /// <summary>
  31. /// Creates a new animation field display GUI element and adds it to the provided layout.
  32. /// </summary>
  33. /// <param name="layout">Layout to add the GUI element to.</param>
  34. /// <param name="width">Width of the GUI element, in pixels.</param>
  35. /// <param name="height">Height of the GUI element, in pixels.</param>
  36. /// <param name="root">Scene object that the root curve field paths reference.</param>
  37. public GUIAnimFieldDisplay(GUILayout layout, int width, int height, SceneObject root)
  38. {
  39. this.root = root;
  40. scrollArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow);
  41. layout.AddElement(scrollArea);
  42. SetSize(width, height);
  43. }
  44. /// <summary>
  45. /// Changes the size of the GUI element.
  46. /// </summary>
  47. /// <param name="width">Width of the GUI element, in pixels.</param>
  48. /// <param name="height">Height of the GUI element, in pixels.</param>
  49. public void SetSize(int width, int height)
  50. {
  51. this.width = width;
  52. this.height = height;
  53. scrollArea.SetWidth(width);
  54. scrollArea.SetHeight(height);
  55. Rebuild();
  56. }
  57. /// <summary>
  58. /// Sets which fields to display.
  59. /// </summary>
  60. /// <param name="fields">A list of fields to display.</param>
  61. public void SetFields(AnimFieldInfo[] fields)
  62. {
  63. this.fieldInfos.Clear();
  64. this.fieldInfos.AddRange(fields);
  65. Rebuild();
  66. }
  67. /// <summary>
  68. /// Adds a new field to the existing field list, and displays it.
  69. /// </summary>
  70. /// <param name="field">Field to append to the field list, and display.</param>
  71. public void AddField(AnimFieldInfo field)
  72. {
  73. bool exists = fieldInfos.Exists(x =>
  74. {
  75. return x.path == field.path;
  76. });
  77. if (!exists)
  78. {
  79. fieldInfos.Add(field);
  80. Rebuild();
  81. }
  82. }
  83. /// <summary>
  84. /// Changes the displayed values for each field.
  85. /// </summary>
  86. /// <param name="values">Values to assign to the fields. Must match the number of displayed fields. </param>
  87. public void SetDisplayValues(GUIAnimFieldPathValue[] values)
  88. {
  89. for (int i = 0; i < fields.Length; i++)
  90. {
  91. string path = fields[i].Path;
  92. for (int j = 0; j < values.Length; j++)
  93. {
  94. if(path == values[j].path)
  95. fields[i].SetValue(values[j].value);
  96. }
  97. }
  98. }
  99. /// <summary>
  100. /// Sets which fields should be displayed as selected.
  101. /// </summary>
  102. /// <param name="paths">Curve field paths of fields to display as selected.</param>
  103. public void SetSelection(string[] paths)
  104. {
  105. Action<GUIAnimFieldEntry> updateSelection = field =>
  106. {
  107. bool foundSelected = false;
  108. for (int j = 0; j < paths.Length; j++)
  109. {
  110. if (field.Path == paths[j])
  111. {
  112. field.SetSelection(true);
  113. foundSelected = true;
  114. break;
  115. }
  116. }
  117. if (!foundSelected)
  118. field.SetSelection(false);
  119. };
  120. for (int i = 0; i < fields.Length; i++)
  121. {
  122. updateSelection(fields[i]);
  123. // Check children (only one level allowed)
  124. GUIAnimFieldEntry[] children = fields[i].GetChildren();
  125. if (children == null)
  126. continue;
  127. for (int j = 0; j < children.Length; j++)
  128. updateSelection(children[j]);
  129. }
  130. }
  131. /// <summary>
  132. /// Rebuilds the entire GUI based on the current field list and their properties.
  133. /// </summary>
  134. private void Rebuild()
  135. {
  136. scrollArea.Layout.Clear();
  137. fields = null;
  138. if (fieldInfos == null || root == null)
  139. return;
  140. GUILabel header = new GUILabel(new LocEdString("Properties"), EditorStyles.Header);
  141. scrollArea.Layout.AddElement(header);
  142. layouts = new GUIAnimFieldLayouts();
  143. GUIPanel rootPanel = scrollArea.Layout.AddPanel();
  144. GUIPanel mainPanel = rootPanel.AddPanel();
  145. GUIPanel underlayPanel = rootPanel.AddPanel(1);
  146. GUIPanel overlayPanel = rootPanel.AddPanel(-1);
  147. GUIPanel backgroundPanel = rootPanel.AddPanel(2);
  148. layouts.main = mainPanel.AddLayoutY();
  149. layouts.underlay = underlayPanel.AddLayoutY();
  150. layouts.overlay = overlayPanel.AddLayoutY();
  151. layouts.background = backgroundPanel.AddLayoutY();
  152. GUIButton catchAll = new GUIButton("", EditorStyles.Blank);
  153. catchAll.Bounds = new Rect2I(0, 0, width, height - header.Bounds.height);
  154. catchAll.OnClick += () => OnEntrySelected(null);
  155. underlayPanel.AddElement(catchAll);
  156. layouts.main.AddSpace(5);
  157. layouts.underlay.AddSpace(5);
  158. layouts.overlay.AddSpace(5);
  159. layouts.background.AddSpace(3); // Minor hack: Background starts heigher to get it to center better
  160. fields = new GUIAnimFieldEntry[fieldInfos.Count];
  161. for (int i = 0; i < fieldInfos.Count; i++)
  162. {
  163. if (string.IsNullOrEmpty(fieldInfos[i].path))
  164. continue;
  165. bool entryIsMissing;
  166. if (fieldInfos[i].curveGroup.isPropertyCurve)
  167. {
  168. string pathSuffix;
  169. SerializableProperty property = Animation.FindProperty(root, fieldInfos[i].path, out pathSuffix);
  170. entryIsMissing = property == null;
  171. }
  172. else
  173. entryIsMissing = false;
  174. if (!entryIsMissing)
  175. {
  176. Color[] colors = new Color[fieldInfos[i].curveGroup.curveInfos.Length];
  177. for (int j = 0; j < fieldInfos[i].curveGroup.curveInfos.Length; j++)
  178. colors[j] = fieldInfos[i].curveGroup.curveInfos[j].color;
  179. switch (fieldInfos[i].curveGroup.type)
  180. {
  181. case SerializableProperty.FieldType.Vector2:
  182. fields[i] = new GUIAnimVec2Entry(layouts, fieldInfos[i].path, colors);
  183. break;
  184. case SerializableProperty.FieldType.Vector3:
  185. fields[i] = new GUIAnimVec3Entry(layouts, fieldInfos[i].path, colors);
  186. break;
  187. case SerializableProperty.FieldType.Vector4:
  188. fields[i] = new GUIAnimVec4Entry(layouts, fieldInfos[i].path, colors);
  189. break;
  190. case SerializableProperty.FieldType.Color:
  191. fields[i] = new GUIAnimColorEntry(layouts, fieldInfos[i].path, colors);
  192. break;
  193. case SerializableProperty.FieldType.Bool:
  194. case SerializableProperty.FieldType.Int:
  195. case SerializableProperty.FieldType.Float:
  196. {
  197. Color color;
  198. if (colors.Length > 0)
  199. color = colors[0];
  200. else
  201. color = Color.White;
  202. fields[i] = new GUIAnimSimpleEntry(layouts, fieldInfos[i].path, color);
  203. break;
  204. }
  205. }
  206. }
  207. else
  208. {
  209. fields[i] = new GUIAnimMissingEntry(layouts, fieldInfos[i].path);
  210. }
  211. if (fields[i] != null)
  212. fields[i].OnEntrySelected += OnEntrySelected;
  213. }
  214. if (fieldInfos.Count == 0)
  215. {
  216. GUILabel warningLbl = new GUILabel(new LocEdString("No properties. Add a new property to begin animating."));
  217. GUILayoutY vertLayout = layouts.main.AddLayoutY();
  218. vertLayout.AddFlexibleSpace();
  219. GUILayoutX horzLayout = vertLayout.AddLayoutX();
  220. vertLayout.AddFlexibleSpace();
  221. horzLayout.AddFlexibleSpace();
  222. horzLayout.AddElement(warningLbl);
  223. horzLayout.AddFlexibleSpace();
  224. }
  225. layouts.main.AddSpace(5);
  226. layouts.underlay.AddSpace(5);
  227. layouts.overlay.AddSpace(5);
  228. layouts.background.AddSpace(5);
  229. layouts.main.AddFlexibleSpace();
  230. layouts.underlay.AddFlexibleSpace();
  231. layouts.overlay.AddFlexibleSpace();
  232. layouts.background.AddFlexibleSpace();
  233. }
  234. }
  235. /// <summary>
  236. /// All layouts used for placing field display GUI elements.
  237. /// </summary>
  238. internal class GUIAnimFieldLayouts
  239. {
  240. public GUILayout main;
  241. public GUILayout underlay;
  242. public GUILayout overlay;
  243. public GUILayout background;
  244. }
  245. /// <summary>
  246. /// Path/value combination used for representing the value of the currently selected frame for a specific curve path.
  247. /// </summary>
  248. internal struct GUIAnimFieldPathValue
  249. {
  250. public string path;
  251. public object value;
  252. }
  253. /// <summary>
  254. /// Base class for individual entries in a GUI animation curve field display.
  255. /// </summary>
  256. internal abstract class GUIAnimFieldEntry
  257. {
  258. private const int MAX_PATH_LENGTH = 30;
  259. protected const int INDENT_AMOUNT = 10;
  260. protected string path;
  261. private GUIButton selectionBtn;
  262. private GUITexture backgroundTexture;
  263. private int entryHeight;
  264. /// <summary>
  265. /// Triggered when the user selects this entry. Curve field path of the selected entry is provided.
  266. /// </summary>
  267. public Action<string> OnEntrySelected;
  268. /// <summary>
  269. /// Path of the curve field path this entry represents.
  270. /// </summary>
  271. public string Path { get { return path; } }
  272. /// <summary>
  273. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  274. /// </summary>
  275. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  276. /// <param name="path">Path of the curve field.</param>
  277. /// <param name="child">Determines if the element is a root path, or a child (sub) element.</param>
  278. /// <param name="indentAmount">Determines how much to horizontally indent the element, in pixels.</param>
  279. public GUIAnimFieldEntry(GUIAnimFieldLayouts layouts, string path, bool child, int indentAmount)
  280. {
  281. this.path = path;
  282. GUILayoutX toggleLayout = layouts.main.AddLayoutX();
  283. toggleLayout.AddSpace(indentAmount);
  284. selectionBtn = new GUIButton(GetDisplayName(path, child), EditorStyles.Label, GUIOption.FlexibleWidth());
  285. selectionBtn.OnClick += () =>
  286. {
  287. OnEntrySelected?.Invoke(path);
  288. };
  289. toggleLayout.AddElement(selectionBtn);
  290. entryHeight = EditorBuiltin.GUISkin.GetStyle(EditorStyles.Label).Height;
  291. backgroundTexture = new GUITexture(Builtin.WhiteTexture, GUITextureScaleMode.StretchToFit,
  292. GUIOption.FlexibleWidth());
  293. backgroundTexture.SetTint(Color.Transparent);
  294. backgroundTexture.SetHeight(entryHeight);
  295. layouts.background.AddElement(backgroundTexture);
  296. }
  297. /// <summary>
  298. /// Hides or shows the element.
  299. /// </summary>
  300. /// <param name="on">True to show the element, false otherwise.</param>
  301. public virtual void Toggle(bool on)
  302. {
  303. selectionBtn.Active = on;
  304. backgroundTexture.Active = on;
  305. }
  306. /// <summary>
  307. /// Toggles whether the entry is displayed as selected, or not selected.
  308. /// </summary>
  309. /// <param name="selected">True to display as selected, false otherwise.</param>
  310. public void SetSelection(bool selected)
  311. {
  312. if(selected)
  313. backgroundTexture.SetTint(Color.DarkCyan);
  314. else
  315. backgroundTexture.SetTint(Color.Transparent);
  316. }
  317. /// <summary>
  318. /// Displays a floating point value in the value display.
  319. /// </summary>
  320. /// <param name="value">Value to display</param>
  321. public virtual void SetValue(float value) { }
  322. /// <summary>
  323. /// Changes the displayed value next to the element's name.
  324. /// </summary>
  325. /// <param name="value"></param>
  326. public virtual void SetValue(object value) { }
  327. /// <summary>
  328. /// Returns all child elements, if this element is complex and has children (e.g. vector).
  329. /// </summary>
  330. /// <returns>List of child elements, or null if none.</returns>
  331. public virtual GUIAnimFieldEntry[] GetChildren()
  332. {
  333. return null;
  334. }
  335. /// <summary>
  336. /// Returns the height of this element.
  337. /// </summary>
  338. /// <returns>Height of this element, in pixels.</returns>
  339. protected int GetEntryHeight()
  340. {
  341. return entryHeight;
  342. }
  343. /// <summary>
  344. /// Generates a name to display on the element's GUI based on its path.
  345. /// </summary>
  346. /// <param name="path">Path of the curve field.</param>
  347. /// <param name="shortName">True to generate a short path without scene object or component info.</param>
  348. /// <returns>Text to display on the element's GUI.</returns>
  349. protected static string GetDisplayName(string path, bool shortName)
  350. {
  351. if (string.IsNullOrEmpty(path))
  352. return "";
  353. string soName;
  354. string compName;
  355. string propertyPath;
  356. string trimmedPath = path.Trim('/');
  357. GetNames(trimmedPath, shortName, out soName, out compName, out propertyPath);
  358. if (propertyPath == null)
  359. return "";
  360. if (shortName)
  361. return propertyPath;
  362. else
  363. {
  364. string truncatedPropPath;
  365. if (propertyPath.Length > MAX_PATH_LENGTH)
  366. truncatedPropPath = "..." + propertyPath.Substring(propertyPath.Length - MAX_PATH_LENGTH);
  367. else
  368. truncatedPropPath = propertyPath;
  369. if (soName != null)
  370. {
  371. if (compName != null)
  372. return soName + "(" + compName + ") - " + truncatedPropPath;
  373. else
  374. return soName + " - " + truncatedPropPath;
  375. }
  376. else
  377. {
  378. if (compName != null)
  379. return "(" + compName + ") - " + truncatedPropPath;
  380. else
  381. return truncatedPropPath;
  382. }
  383. }
  384. }
  385. /// <summary>
  386. /// Parses a curve field path and breaks it down relevant components.
  387. /// </summary>
  388. /// <param name="path">Curve field path to parse.</param>
  389. /// <param name="shortName">If true, only the last entry of the property portion of the path will be output in
  390. /// <paramref name="propertyPath"/>. Otherwise all properties will be output.</param>
  391. /// <param name="soName">Name of the scene object the path field belongs to.</param>
  392. /// <param name="compName">Name of the component the path field belongs to, if any.</param>
  393. /// <param name="propertyPath">A list of properties relative to parent component or scene object, that determine
  394. /// which field does the path reference. If <paramref name="shortName"/> is true, only
  395. /// the last property will be output (if there are multiple).</param>
  396. protected static void GetNames(string path, bool shortName, out string soName, out string compName, out string propertyPath)
  397. {
  398. string[] entries = path.Split('/');
  399. // Find name of the last scene object in the path
  400. int pathIdx = 0;
  401. soName = null;
  402. for (; pathIdx < entries.Length; pathIdx++)
  403. {
  404. string entry = entries[pathIdx];
  405. if (string.IsNullOrEmpty(entry))
  406. continue;
  407. // Not a scene object, break
  408. if (entry[0] != '!')
  409. {
  410. if (pathIdx > 0)
  411. {
  412. string prevEntry = entries[pathIdx - 1];
  413. soName = prevEntry.Substring(1, prevEntry.Length - 1);
  414. }
  415. break;
  416. }
  417. }
  418. if (pathIdx >= entries.Length)
  419. {
  420. compName = null;
  421. propertyPath = null;
  422. return;
  423. }
  424. // If path is referencing a component, find it
  425. {
  426. string entry = entries[pathIdx];
  427. if (entry[0] == ':')
  428. compName = entry.Substring(1, entry.Length - 1);
  429. else
  430. compName = null;
  431. }
  432. // Look for a field name
  433. if (compName != null)
  434. {
  435. pathIdx++;
  436. if (pathIdx >= entries.Length)
  437. {
  438. propertyPath = null;
  439. return;
  440. }
  441. }
  442. if (shortName)
  443. {
  444. if (pathIdx < entries.Length)
  445. propertyPath = entries[entries.Length - 1];
  446. else
  447. propertyPath = null;
  448. }
  449. else
  450. {
  451. StringBuilder pathBuilder = new StringBuilder();
  452. for (; pathIdx < entries.Length - 1; pathIdx++)
  453. pathBuilder.Append(entries[pathIdx] + "/");
  454. if (pathIdx < entries.Length)
  455. pathBuilder.Append(entries[pathIdx]);
  456. propertyPath = pathBuilder.ToString();
  457. }
  458. }
  459. }
  460. /// <summary>
  461. /// Creates GUI for an element in animation field display, that contains no child elements.
  462. /// </summary>
  463. internal class GUIAnimSimpleEntry : GUIAnimFieldEntry
  464. {
  465. private GUILabel valueDisplay;
  466. private GUILayoutX underlayLayout;
  467. private GUILabel overlaySpacing;
  468. /// <summary>
  469. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  470. /// </summary>
  471. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  472. /// <param name="path">Path of the curve field.</param>
  473. /// <param name="color">Color of the path field curve, to display next to the element name.</param>
  474. /// <param name="child">Determines if the element is a root path, or a child (sub) element.</param>
  475. public GUIAnimSimpleEntry(GUIAnimFieldLayouts layouts, string path, Color color, bool child = false)
  476. : base(layouts, path, child, child ? 45 : 30)
  477. {
  478. valueDisplay = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  479. underlayLayout = layouts.underlay.AddLayoutX();
  480. underlayLayout.AddSpace(child ? 30 : 15);
  481. GUITexture colorSquare = new GUITexture(Builtin.WhiteTexture,
  482. GUIOption.FixedWidth(10), GUIOption.FixedHeight(10));
  483. colorSquare.SetTint(color);
  484. underlayLayout.AddElement(colorSquare);
  485. underlayLayout.AddFlexibleSpace();
  486. underlayLayout.AddElement(valueDisplay);
  487. underlayLayout.AddSpace(10);
  488. overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  489. layouts.overlay.AddElement(overlaySpacing);
  490. }
  491. /// <inheritdoc/>
  492. public override void Toggle(bool on)
  493. {
  494. underlayLayout.Active = on;
  495. overlaySpacing.Active = on;
  496. base.Toggle(on);
  497. }
  498. /// <inheritdoc/>
  499. public override void SetValue(float value)
  500. {
  501. string strValue = value.ToString("n2");
  502. valueDisplay.SetContent(strValue);
  503. }
  504. }
  505. /// <summary>
  506. /// Base class for elements in animation field display, that contain other child elements.
  507. /// </summary>
  508. internal class GUIAnimComplexEntry : GUIAnimFieldEntry
  509. {
  510. private GUILayout foldoutLayout;
  511. private GUIToggle foldout;
  512. private GUILabel underlaySpacing;
  513. protected GUIAnimSimpleEntry[] children;
  514. /// <summary>
  515. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  516. /// </summary>
  517. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  518. /// <param name="path">Path of the curve field.</param>
  519. /// <param name="childEntries">Sub-path names of the child entries to display.</param>
  520. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  521. public GUIAnimComplexEntry(GUIAnimFieldLayouts layouts, string path, string[] childEntries, Color[] colors)
  522. : base(layouts, path, false, 20)
  523. {
  524. foldout = new GUIToggle("", EditorStyles.Expand);
  525. foldout.OnToggled += Toggle;
  526. GUILabel spacer = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  527. foldoutLayout = layouts.overlay.AddLayoutX();
  528. foldoutLayout.AddSpace(5);
  529. foldoutLayout.AddElement(foldout);
  530. foldoutLayout.AddElement(spacer);
  531. foldoutLayout.AddFlexibleSpace();
  532. underlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  533. layouts.underlay.AddElement(underlaySpacing);
  534. children = new GUIAnimSimpleEntry[childEntries.Length];
  535. for (int i = 0; i < childEntries.Length; i++)
  536. {
  537. Color color;
  538. if (i < colors.Length)
  539. color = colors[i];
  540. else
  541. color = Color.White;
  542. children[i] = new GUIAnimSimpleEntry(layouts, path + childEntries[i], color, true);
  543. children[i].OnEntrySelected += x => { OnEntrySelected?.Invoke(x); };
  544. }
  545. Toggle(false);
  546. }
  547. /// <inheritdoc/>
  548. public override void Toggle(bool on)
  549. {
  550. foreach(var child in children)
  551. child.Toggle(on);
  552. }
  553. /// <inheritdoc/>
  554. public override GUIAnimFieldEntry[] GetChildren()
  555. {
  556. return children;
  557. }
  558. }
  559. /// <summary>
  560. /// Creates a GUI for displaying a Vector2 curve field in the animation field display GUI element.
  561. /// </summary>
  562. internal class GUIAnimVec2Entry : GUIAnimComplexEntry
  563. {
  564. /// <summary>
  565. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  566. /// </summary>
  567. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  568. /// <param name="path">Path of the curve field.</param>
  569. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  570. public GUIAnimVec2Entry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
  571. : base(layouts, path, new[] { ".x", ".y" }, colors)
  572. { }
  573. /// <inheritdoc/>
  574. public override void SetValue(object value)
  575. {
  576. if (value == null)
  577. return;
  578. Vector2 vector = (Vector2)value;
  579. children[0].SetValue(vector.x);
  580. children[1].SetValue(vector.y);
  581. }
  582. }
  583. /// <summary>
  584. /// Creates a GUI for displaying a Vector3 curve field in the animation field display GUI element.
  585. /// </summary>
  586. internal class GUIAnimVec3Entry : GUIAnimComplexEntry
  587. {
  588. /// <summary>
  589. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  590. /// </summary>
  591. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  592. /// <param name="path">Path of the curve field.</param>
  593. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  594. public GUIAnimVec3Entry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
  595. : base(layouts, path, new[] { ".x", ".y", ".z" }, colors)
  596. { }
  597. /// <inheritdoc/>
  598. public override void SetValue(object value)
  599. {
  600. if (value == null)
  601. return;
  602. Vector3 vector = (Vector3)value;
  603. children[0].SetValue(vector.x);
  604. children[1].SetValue(vector.y);
  605. children[2].SetValue(vector.z);
  606. }
  607. }
  608. /// <summary>
  609. /// Creates a GUI for displaying a Vector4 curve field in the animation field display GUI element.
  610. /// </summary>
  611. internal class GUIAnimVec4Entry : GUIAnimComplexEntry
  612. {
  613. /// <summary>
  614. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  615. /// </summary>
  616. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  617. /// <param name="path">Path of the curve field.</param>
  618. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  619. public GUIAnimVec4Entry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
  620. : base(layouts, path, new[] { ".x", ".y", ".z", ".w" }, colors)
  621. { }
  622. /// <inheritdoc/>
  623. public override void SetValue(object value)
  624. {
  625. if (value == null)
  626. return;
  627. Vector4 vector = (Vector4)value;
  628. children[0].SetValue(vector.x);
  629. children[1].SetValue(vector.y);
  630. children[2].SetValue(vector.z);
  631. children[3].SetValue(vector.w);
  632. }
  633. }
  634. /// <summary>
  635. /// Creates a GUI for displaying a Color curve field in the animation field display GUI element.
  636. /// </summary>
  637. internal class GUIAnimColorEntry : GUIAnimComplexEntry
  638. {
  639. /// <summary>
  640. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  641. /// </summary>
  642. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  643. /// <param name="path">Path of the curve field.</param>
  644. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  645. public GUIAnimColorEntry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
  646. : base(layouts, path, new[] { ".r", ".g", ".b", ".a" }, colors)
  647. { }
  648. /// <inheritdoc/>
  649. public override void SetValue(object value)
  650. {
  651. if (value == null)
  652. return;
  653. Color color = (Color)value;
  654. children[0].SetValue(color.r);
  655. children[1].SetValue(color.g);
  656. children[2].SetValue(color.b);
  657. children[3].SetValue(color.a);
  658. }
  659. }
  660. /// <summary>
  661. /// Creates a GUI for displaying an entry in the animation field display GUI element that notifies the user that
  662. /// a referenced curve field path cannot be found.
  663. /// </summary>
  664. internal class GUIAnimMissingEntry : GUIAnimFieldEntry
  665. {
  666. private GUILabel missingLabel;
  667. private GUILayoutX underlayLayout;
  668. private GUILabel overlaySpacing;
  669. public GUIAnimMissingEntry(GUIAnimFieldLayouts layouts, string path)
  670. : base(layouts, path, false, 15)
  671. {
  672. missingLabel = new GUILabel("Missing!", GUIOption.FixedHeight(GetEntryHeight()));
  673. underlayLayout = layouts.underlay.AddLayoutX();
  674. underlayLayout.AddFlexibleSpace();
  675. underlayLayout.AddElement(missingLabel);
  676. underlayLayout.AddSpace(15);
  677. overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  678. layouts.overlay.AddElement(overlaySpacing);
  679. }
  680. /// <inheritdoc/>
  681. public override void Toggle(bool on)
  682. {
  683. underlayLayout.Active = on;
  684. overlaySpacing.Active = on;
  685. base.Toggle(on);
  686. }
  687. }
  688. /// <summary>
  689. /// Contains information required to display a single curve field entry in the animation field display GUI.
  690. /// </summary>
  691. internal struct AnimFieldInfo
  692. {
  693. public AnimFieldInfo(string path, FieldAnimCurves curveGroup)
  694. {
  695. this.path = path;
  696. this.curveGroup = curveGroup;
  697. }
  698. public string path;
  699. public FieldAnimCurves curveGroup;
  700. }
  701. /** @} */
  702. }