GUIAnimFieldDisplay.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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 BansheeEngine;
  7. namespace BansheeEditor
  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].isUserCurve)
  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 = selectionBtn.Bounds.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. /// Changes the displayed value next to the element's name.
  319. /// </summary>
  320. /// <param name="value"></param>
  321. public virtual void SetValue(object value) { }
  322. /// <summary>
  323. /// Returns all child elements, if this element is complex and has children (e.g. vector).
  324. /// </summary>
  325. /// <returns>List of child elements, or null if none.</returns>
  326. public virtual GUIAnimFieldEntry[] GetChildren()
  327. {
  328. return null;
  329. }
  330. /// <summary>
  331. /// Returns the height of this element.
  332. /// </summary>
  333. /// <returns>Height of this element, in pixels.</returns>
  334. protected int GetEntryHeight()
  335. {
  336. return entryHeight;
  337. }
  338. /// <summary>
  339. /// Generates a name to display on the element's GUI based on its path.
  340. /// </summary>
  341. /// <param name="path">Path of the curve field.</param>
  342. /// <param name="shortName">True to generate a short path without scene object or component info.</param>
  343. /// <returns>Text to display on the element's GUI.</returns>
  344. protected static string GetDisplayName(string path, bool shortName)
  345. {
  346. if (string.IsNullOrEmpty(path))
  347. return "";
  348. string soName;
  349. string compName;
  350. string propertyPath;
  351. string trimmedPath = path.Trim('/');
  352. GetNames(trimmedPath, shortName, out soName, out compName, out propertyPath);
  353. if (propertyPath == null)
  354. return "";
  355. if (shortName)
  356. return propertyPath;
  357. else
  358. {
  359. string truncatedPropPath;
  360. if (propertyPath.Length > MAX_PATH_LENGTH)
  361. truncatedPropPath = "..." + propertyPath.Substring(propertyPath.Length - MAX_PATH_LENGTH);
  362. else
  363. truncatedPropPath = propertyPath;
  364. if (soName != null)
  365. {
  366. if (compName != null)
  367. return soName + "(" + compName + ") - " + truncatedPropPath;
  368. else
  369. return soName + " - " + truncatedPropPath;
  370. }
  371. else
  372. {
  373. if (compName != null)
  374. return "(" + compName + ") - " + truncatedPropPath;
  375. else
  376. return truncatedPropPath;
  377. }
  378. }
  379. }
  380. /// <summary>
  381. /// Parses a curve field path and breaks it down relevant components.
  382. /// </summary>
  383. /// <param name="path">Curve field path to parse.</param>
  384. /// <param name="shortName">If true, only the last entry of the property portion of the path will be output in
  385. /// <paramref name="propertyPath"/>. Otherwise all properties will be output.</param>
  386. /// <param name="soName">Name of the scene object the path field belongs to.</param>
  387. /// <param name="compName">Name of the component the path field belongs to, if any.</param>
  388. /// <param name="propertyPath">A list of properties relative to parent component or scene object, that determine
  389. /// which field does the path reference. If <paramref name="shortName"/> is true, only
  390. /// the last property will be output (if there are multiple).</param>
  391. protected static void GetNames(string path, bool shortName, out string soName, out string compName, out string propertyPath)
  392. {
  393. string[] entries = path.Split('/');
  394. // Find name of the last scene object in the path
  395. int pathIdx = 0;
  396. soName = null;
  397. for (; pathIdx < entries.Length; pathIdx++)
  398. {
  399. string entry = entries[pathIdx];
  400. if (string.IsNullOrEmpty(entry))
  401. continue;
  402. // Not a scene object, break
  403. if (entry[0] != '!')
  404. {
  405. if (pathIdx > 0)
  406. {
  407. string prevEntry = entries[pathIdx - 1];
  408. soName = prevEntry.Substring(1, prevEntry.Length - 1);
  409. }
  410. break;
  411. }
  412. }
  413. if (pathIdx >= entries.Length)
  414. {
  415. compName = null;
  416. propertyPath = null;
  417. return;
  418. }
  419. // If path is referencing a component, find it
  420. {
  421. string entry = entries[pathIdx];
  422. if (entry[0] == ':')
  423. compName = entry.Substring(1, entry.Length - 1);
  424. else
  425. compName = null;
  426. }
  427. // Look for a field name
  428. if (compName != null)
  429. {
  430. pathIdx++;
  431. if (pathIdx >= entries.Length)
  432. {
  433. propertyPath = null;
  434. return;
  435. }
  436. }
  437. if (shortName)
  438. {
  439. if (pathIdx < entries.Length)
  440. propertyPath = entries[entries.Length - 1];
  441. else
  442. propertyPath = null;
  443. }
  444. else
  445. {
  446. StringBuilder pathBuilder = new StringBuilder();
  447. for (; pathIdx < entries.Length - 1; pathIdx++)
  448. pathBuilder.Append(entries[pathIdx] + "/");
  449. if (pathIdx < entries.Length)
  450. pathBuilder.Append(entries[pathIdx]);
  451. propertyPath = pathBuilder.ToString();
  452. }
  453. }
  454. }
  455. /// <summary>
  456. /// Creates GUI for an element in animation field display, that contains no child elements.
  457. /// </summary>
  458. internal class GUIAnimSimpleEntry : GUIAnimFieldEntry
  459. {
  460. private GUILabel valueDisplay;
  461. private GUILayoutX underlayLayout;
  462. private GUILabel overlaySpacing;
  463. /// <summary>
  464. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  465. /// </summary>
  466. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  467. /// <param name="path">Path of the curve field.</param>
  468. /// <param name="color">Color of the path field curve, to display next to the element name.</param>
  469. /// <param name="child">Determines if the element is a root path, or a child (sub) element.</param>
  470. public GUIAnimSimpleEntry(GUIAnimFieldLayouts layouts, string path, Color color, bool child = false)
  471. : base(layouts, path, child, child ? 45 : 30)
  472. {
  473. valueDisplay = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  474. underlayLayout = layouts.underlay.AddLayoutX();
  475. underlayLayout.AddSpace(child ? 30 : 15);
  476. GUITexture colorSquare = new GUITexture(Builtin.WhiteTexture,
  477. GUIOption.FixedWidth(10), GUIOption.FixedHeight(10));
  478. colorSquare.SetTint(color);
  479. underlayLayout.AddElement(colorSquare);
  480. underlayLayout.AddFlexibleSpace();
  481. underlayLayout.AddElement(valueDisplay);
  482. underlayLayout.AddSpace(50);
  483. overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  484. layouts.overlay.AddElement(overlaySpacing);
  485. }
  486. /// <inheritdoc/>
  487. public override void Toggle(bool on)
  488. {
  489. underlayLayout.Active = on;
  490. overlaySpacing.Active = on;
  491. base.Toggle(on);
  492. }
  493. /// <inheritdoc/>
  494. public override void SetValue(object value)
  495. {
  496. if (value == null)
  497. return;
  498. string strValue = value.ToString();
  499. valueDisplay.SetContent(strValue);
  500. }
  501. }
  502. /// <summary>
  503. /// Base class for elements in animation field display, that contain other child elements.
  504. /// </summary>
  505. internal class GUIAnimComplexEntry : GUIAnimFieldEntry
  506. {
  507. private GUILayout foldoutLayout;
  508. private GUIToggle foldout;
  509. private GUILabel underlaySpacing;
  510. protected GUIAnimSimpleEntry[] children;
  511. /// <summary>
  512. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  513. /// </summary>
  514. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  515. /// <param name="path">Path of the curve field.</param>
  516. /// <param name="childEntries">Sub-path names of the child entries to display.</param>
  517. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  518. public GUIAnimComplexEntry(GUIAnimFieldLayouts layouts, string path, string[] childEntries, Color[] colors)
  519. : base(layouts, path, false, 20)
  520. {
  521. foldout = new GUIToggle("", EditorStyles.Expand);
  522. foldout.OnToggled += Toggle;
  523. GUILabel spacer = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  524. foldoutLayout = layouts.overlay.AddLayoutX();
  525. foldoutLayout.AddSpace(5);
  526. foldoutLayout.AddElement(foldout);
  527. foldoutLayout.AddElement(spacer);
  528. foldoutLayout.AddFlexibleSpace();
  529. underlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  530. layouts.underlay.AddElement(underlaySpacing);
  531. children = new GUIAnimSimpleEntry[childEntries.Length];
  532. for (int i = 0; i < childEntries.Length; i++)
  533. {
  534. Color color;
  535. if (i < colors.Length)
  536. color = colors[i];
  537. else
  538. color = Color.White;
  539. children[i] = new GUIAnimSimpleEntry(layouts, path + childEntries[i], color, true);
  540. children[i].OnEntrySelected += x => { OnEntrySelected?.Invoke(x); };
  541. }
  542. Toggle(false);
  543. }
  544. /// <inheritdoc/>
  545. public override void Toggle(bool on)
  546. {
  547. foreach(var child in children)
  548. child.Toggle(on);
  549. }
  550. /// <inheritdoc/>
  551. public override GUIAnimFieldEntry[] GetChildren()
  552. {
  553. return children;
  554. }
  555. }
  556. /// <summary>
  557. /// Creates a GUI for displaying a Vector2 curve field in the animation field display GUI element.
  558. /// </summary>
  559. internal class GUIAnimVec2Entry : GUIAnimComplexEntry
  560. {
  561. /// <summary>
  562. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  563. /// </summary>
  564. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  565. /// <param name="path">Path of the curve field.</param>
  566. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  567. public GUIAnimVec2Entry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
  568. : base(layouts, path, new[] { ".x", ".y" }, colors)
  569. { }
  570. /// <inheritdoc/>
  571. public override void SetValue(object value)
  572. {
  573. if (value == null)
  574. return;
  575. Vector2 vector = (Vector2)value;
  576. children[0].SetValue(vector.x);
  577. children[1].SetValue(vector.y);
  578. }
  579. }
  580. /// <summary>
  581. /// Creates a GUI for displaying a Vector3 curve field in the animation field display GUI element.
  582. /// </summary>
  583. internal class GUIAnimVec3Entry : GUIAnimComplexEntry
  584. {
  585. /// <summary>
  586. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  587. /// </summary>
  588. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  589. /// <param name="path">Path of the curve field.</param>
  590. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  591. public GUIAnimVec3Entry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
  592. : base(layouts, path, new[] { ".x", ".y", ".z" }, colors)
  593. { }
  594. /// <inheritdoc/>
  595. public override void SetValue(object value)
  596. {
  597. if (value == null)
  598. return;
  599. Vector3 vector = (Vector3)value;
  600. children[0].SetValue(vector.x);
  601. children[1].SetValue(vector.y);
  602. children[2].SetValue(vector.z);
  603. }
  604. }
  605. /// <summary>
  606. /// Creates a GUI for displaying a Vector4 curve field in the animation field display GUI element.
  607. /// </summary>
  608. internal class GUIAnimVec4Entry : GUIAnimComplexEntry
  609. {
  610. /// <summary>
  611. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  612. /// </summary>
  613. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  614. /// <param name="path">Path of the curve field.</param>
  615. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  616. public GUIAnimVec4Entry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
  617. : base(layouts, path, new[] { ".x", ".y", ".z", ".w" }, colors)
  618. { }
  619. /// <inheritdoc/>
  620. public override void SetValue(object value)
  621. {
  622. if (value == null)
  623. return;
  624. Vector4 vector = (Vector4)value;
  625. children[0].SetValue(vector.x);
  626. children[1].SetValue(vector.y);
  627. children[2].SetValue(vector.z);
  628. children[3].SetValue(vector.w);
  629. }
  630. }
  631. /// <summary>
  632. /// Creates a GUI for displaying a Color curve field in the animation field display GUI element.
  633. /// </summary>
  634. internal class GUIAnimColorEntry : GUIAnimComplexEntry
  635. {
  636. /// <summary>
  637. /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts.
  638. /// </summary>
  639. /// <param name="layouts">Layouts to append the GUI elements to.</param>
  640. /// <param name="path">Path of the curve field.</param>
  641. /// <param name="colors">Colors of the curves to display, for each child entry.</param>
  642. public GUIAnimColorEntry(GUIAnimFieldLayouts layouts, string path, Color[] colors)
  643. : base(layouts, path, new[] { ".r", ".g", ".b", ".a" }, colors)
  644. { }
  645. /// <inheritdoc/>
  646. public override void SetValue(object value)
  647. {
  648. if (value == null)
  649. return;
  650. Color color = (Color)value;
  651. children[0].SetValue(color.r);
  652. children[1].SetValue(color.g);
  653. children[2].SetValue(color.b);
  654. children[3].SetValue(color.a);
  655. }
  656. }
  657. /// <summary>
  658. /// Creates a GUI for displaying an entry in the animation field display GUI element that notifies the user that
  659. /// a referenced curve field path cannot be found.
  660. /// </summary>
  661. internal class GUIAnimMissingEntry : GUIAnimFieldEntry
  662. {
  663. private GUILabel missingLabel;
  664. private GUILayoutX underlayLayout;
  665. private GUILabel overlaySpacing;
  666. public GUIAnimMissingEntry(GUIAnimFieldLayouts layouts, string path)
  667. : base(layouts, path, false, 15)
  668. {
  669. missingLabel = new GUILabel("Missing property!", GUIOption.FixedHeight(GetEntryHeight()));
  670. underlayLayout = layouts.underlay.AddLayoutX();
  671. underlayLayout.AddFlexibleSpace();
  672. underlayLayout.AddElement(missingLabel);
  673. underlayLayout.AddSpace(50);
  674. overlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight()));
  675. layouts.overlay.AddElement(overlaySpacing);
  676. }
  677. /// <inheritdoc/>
  678. public override void Toggle(bool on)
  679. {
  680. underlayLayout.Active = on;
  681. overlaySpacing.Active = on;
  682. base.Toggle(on);
  683. }
  684. }
  685. /// <summary>
  686. /// Contains information required to display a single curve field entry in the animation field display GUI.
  687. /// </summary>
  688. internal struct AnimFieldInfo
  689. {
  690. public AnimFieldInfo(string path, FieldAnimCurves curveGroup, bool isUserCurve)
  691. {
  692. this.path = path;
  693. this.curveGroup = curveGroup;
  694. this.isUserCurve = isUserCurve;
  695. }
  696. public string path;
  697. public FieldAnimCurves curveGroup;
  698. public bool isUserCurve;
  699. }
  700. /** @} */
  701. }