GUIDictionaryField.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. /// <summary>
  8. /// Base class for objects that display GUI for a modifyable dictionary of elements. Elements can be added, modified or
  9. /// removed.
  10. /// </summary>
  11. public abstract class GUIDictionaryFieldBase
  12. {
  13. private const int IndentAmount = 5;
  14. protected Dictionary<int, GUIDictionaryFieldRow> rows = new Dictionary<int, GUIDictionaryFieldRow>();
  15. protected GUIDictionaryFieldRow editRow;
  16. protected GUILayoutY guiLayout;
  17. protected GUILayoutX guiChildLayout;
  18. protected GUILayoutX guiTitleLayout;
  19. protected GUILayoutX guiInternalTitleLayout;
  20. protected GUILayoutY guiContentLayout;
  21. protected bool isExpanded;
  22. protected int depth;
  23. protected LocString title;
  24. private int editRowIdx = -1;
  25. private object editKey;
  26. private object editValue;
  27. private object editOriginalKey;
  28. private State state;
  29. private bool isModified;
  30. /// <summary>
  31. /// Constructs a new GUI dictionary.
  32. /// </summary>
  33. /// <param name="title">Label to display on the dictionary GUI title.</param>
  34. /// <param name="layout">Layout to which to append the list GUI elements to.</param>
  35. /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
  36. /// nested containers whose backgrounds are overlaping. Also determines background style,
  37. /// depths divisible by two will use an alternate style.</param>
  38. protected GUIDictionaryFieldBase(LocString title, GUILayout layout, int depth = 0)
  39. {
  40. this.title = title;
  41. this.depth = depth;
  42. guiLayout = layout.AddLayoutY();
  43. guiTitleLayout = guiLayout.AddLayoutX();
  44. }
  45. /// <summary>
  46. /// Completely rebuilds the dictionary GUI elements.
  47. /// </summary>
  48. public void BuildGUI()
  49. {
  50. editKey = CreateKey();
  51. editValue = CreateValue();
  52. UpdateHeaderGUI();
  53. foreach (var KVP in rows)
  54. KVP.Value.Destroy();
  55. rows.Clear();
  56. if (editRow != null)
  57. {
  58. editRow.Destroy();
  59. editRow = null;
  60. }
  61. if (!IsNull())
  62. {
  63. // Hidden dependency: BuildGUI must be called after all elements are
  64. // in the dictionary so we do it in two steps
  65. int numRows = GetNumRows();
  66. for (int i = 0; i < numRows; i++)
  67. {
  68. GUIDictionaryFieldRow newRow = CreateRow();
  69. rows.Add(i, newRow);
  70. }
  71. editRow = CreateRow();
  72. editRow.Initialize(this, guiContentLayout, numRows, depth + 1);
  73. editRow.Enabled = false;
  74. for (int i = 0; i < numRows; i++)
  75. rows[i].Initialize(this, guiContentLayout, i, depth + 1);
  76. }
  77. }
  78. /// <summary>
  79. /// Rebuilds the GUI dictionary header if needed.
  80. /// </summary>
  81. protected void UpdateHeaderGUI()
  82. {
  83. Action BuildEmptyGUI = () =>
  84. {
  85. guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);
  86. guiInternalTitleLayout.AddElement(new GUILabel(title));
  87. guiInternalTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100)));
  88. GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create));
  89. GUIButton createBtn = new GUIButton(createIcon, GUIOption.FixedWidth(30));
  90. createBtn.OnClick += OnCreateButtonClicked;
  91. guiInternalTitleLayout.AddElement(createBtn);
  92. };
  93. Action BuildFilledGUI = () =>
  94. {
  95. guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);
  96. GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
  97. guiFoldout.Value = isExpanded;
  98. guiFoldout.OnToggled += ToggleFoldout;
  99. GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear));
  100. GUIButton guiClearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(30));
  101. guiClearBtn.OnClick += OnClearButtonClicked;
  102. GUIContent addIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Add));
  103. GUIButton guiAddBtn = new GUIButton(addIcon, GUIOption.FixedWidth(30));
  104. guiAddBtn.OnClick += OnAddButtonClicked;
  105. guiInternalTitleLayout.AddElement(guiFoldout);
  106. guiInternalTitleLayout.AddElement(guiAddBtn);
  107. guiInternalTitleLayout.AddElement(guiClearBtn);
  108. guiChildLayout = guiLayout.AddLayoutX();
  109. guiChildLayout.AddSpace(IndentAmount);
  110. GUIPanel guiContentPanel = guiChildLayout.AddPanel();
  111. GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
  112. guiIndentLayoutX.AddSpace(IndentAmount);
  113. GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
  114. guiIndentLayoutY.AddSpace(IndentAmount);
  115. guiContentLayout = guiIndentLayoutY.AddLayoutY();
  116. guiIndentLayoutY.AddSpace(IndentAmount);
  117. guiIndentLayoutX.AddSpace(IndentAmount);
  118. guiChildLayout.AddSpace(IndentAmount);
  119. short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
  120. string bgPanelStyle = depth % 2 == 0
  121. ? EditorStyles.InspectorContentBgAlternate
  122. : EditorStyles.InspectorContentBg;
  123. GUIPanel backgroundPanel = guiContentPanel.AddPanel(backgroundDepth);
  124. GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
  125. backgroundPanel.AddElement(inspectorContentBg);
  126. ToggleFoldout(isExpanded);
  127. };
  128. if (state == State.None)
  129. {
  130. if (!IsNull())
  131. {
  132. BuildFilledGUI();
  133. state = State.Filled;
  134. }
  135. else
  136. {
  137. BuildEmptyGUI();
  138. state = State.Empty;
  139. }
  140. }
  141. else if (state == State.Empty)
  142. {
  143. if (!IsNull())
  144. {
  145. guiInternalTitleLayout.Destroy();
  146. BuildFilledGUI();
  147. state = State.Filled;
  148. }
  149. }
  150. else if (state == State.Filled)
  151. {
  152. if (IsNull())
  153. {
  154. guiInternalTitleLayout.Destroy();
  155. guiChildLayout.Destroy();
  156. BuildEmptyGUI();
  157. state = State.Empty;
  158. }
  159. }
  160. }
  161. /// <summary>
  162. /// Destroys all rows and clears the row list.
  163. /// </summary>
  164. private void ClearRows()
  165. {
  166. foreach (var KVP in rows)
  167. KVP.Value.Destroy();
  168. editRow.Destroy();
  169. rows.Clear();
  170. }
  171. /// <summary>
  172. /// Returns the layout that is used for positioning the elements in the title bar.
  173. /// </summary>
  174. /// <returns>Horizontal layout for positioning the title bar elements.</returns>
  175. public GUILayoutX GetTitleLayout()
  176. {
  177. return guiTitleLayout;
  178. }
  179. /// <summary>
  180. /// Refreshes contents of all dictionary rows and checks if anything was modified.
  181. /// </summary>
  182. /// <returns>State representing was anything modified between two last calls to <see cref="Refresh"/>.</returns>
  183. public virtual InspectableState Refresh()
  184. {
  185. InspectableState state = InspectableState.NotModified;
  186. for (int i = 0; i < rows.Count; i++)
  187. state |= rows[i].Refresh();
  188. if (editRow != null && editRow.Enabled)
  189. state |= editRow.Refresh();
  190. if (isModified)
  191. {
  192. state |= InspectableState.Modified;
  193. isModified = false;
  194. }
  195. return state;
  196. }
  197. /// <summary>
  198. /// Destroys the GUI elements.
  199. /// </summary>
  200. public void Destroy()
  201. {
  202. if (guiLayout != null)
  203. {
  204. guiLayout.Destroy();
  205. guiLayout = null;
  206. }
  207. guiLayout = null;
  208. guiTitleLayout = null;
  209. guiChildLayout = null;
  210. for (int i = 0; i < rows.Count; i++)
  211. rows[i].Destroy();
  212. rows.Clear();
  213. if (editRow != null)
  214. editRow.Destroy();
  215. editRow = null;
  216. }
  217. /// <summary>
  218. /// Checks is the specified row index the temporary edit row.
  219. /// </summary>
  220. /// <param name="rowIdx">Sequential index of the row to check.</param>
  221. /// <returns>True if the index is of an edit row.</returns>
  222. private bool IsTemporaryRow(int rowIdx)
  223. {
  224. return rowIdx == rows.Count;
  225. }
  226. /// <summary>
  227. /// Checks is any row being currently edited.
  228. /// </summary>
  229. /// <returns>True if a row is being edited, false otherwise.</returns>
  230. private bool IsEditInProgress()
  231. {
  232. return editRowIdx != -1;
  233. }
  234. /// <summary>
  235. /// Returns the number of rows in the dictionary.
  236. /// </summary>
  237. /// <returns>Number of rows in the dictionary.</returns>
  238. protected abstract int GetNumRows();
  239. /// <summary>
  240. /// Checks is the dictionary instance not assigned.
  241. /// </summary>
  242. /// <returns>True if there is not a dictionary instance.</returns>
  243. protected abstract bool IsNull();
  244. /// <summary>
  245. /// Gets a value of an element at the specified index in the list. Also handles temporary edit fields.
  246. /// </summary>
  247. /// <param name="rowIdx">Sequential index of the row to set the value for.</param>
  248. /// <returns>Value of the list element at the specified key.</returns>
  249. protected internal virtual object GetValueInternal(int rowIdx)
  250. {
  251. if (rowIdx == editRowIdx || IsTemporaryRow(rowIdx))
  252. return editValue;
  253. else
  254. return GetValue(GetKey(rowIdx));
  255. }
  256. /// <summary>
  257. /// Sets a value of an element at the specified index in the list. Also handles temporary edit fields.
  258. /// </summary>
  259. /// <param name="rowIdx">Sequential index of the row to set the value for.</param>
  260. /// <param name="value">Value to assign to the element. Caller must ensure it is of valid type.</param>
  261. protected internal virtual void SetValueInternal(int rowIdx, object value)
  262. {
  263. if (rowIdx == editRowIdx || IsTemporaryRow(rowIdx))
  264. editValue = value;
  265. else
  266. SetValue(GetKey(rowIdx), value);
  267. }
  268. /// <summary>
  269. /// Changes the value of the key of the specified row.
  270. /// </summary>
  271. /// <param name="rowIdx">Sequential index of the row to set the key for.</param>
  272. /// <param name="key">Key to assign to the specified row.</param>
  273. protected internal void SetKey(int rowIdx, object key)
  274. {
  275. if (editRowIdx != rowIdx)
  276. {
  277. Debug.LogError("Cannot change a dictionary row that is not in edit state.");
  278. return;
  279. }
  280. editKey = key;
  281. }
  282. /// <summary>
  283. /// Gets a key for a row at the specified index. Handles the special case for the currently edited row.
  284. /// </summary>
  285. /// <param name="rowIdx">Sequential index of the row for which to retrieve the key.</param>
  286. /// <returns>Key for a row at the specified index.</returns>
  287. protected internal object GetKeyInternal(int rowIdx)
  288. {
  289. if (editRowIdx == rowIdx || IsTemporaryRow(rowIdx))
  290. return editKey;
  291. return GetKey(rowIdx);
  292. }
  293. /// <summary>
  294. /// Creates a new dictionary row GUI.
  295. /// </summary>
  296. /// <returns>Object containing the dictionary row GUI.</returns>
  297. protected abstract GUIDictionaryFieldRow CreateRow();
  298. /// <summary>
  299. /// Gets a key for a row at the specified index.
  300. /// </summary>
  301. /// <param name="rowIdx">Sequential index of the row for which to retrieve the key.</param>
  302. /// <returns>Key for a row at the specified index.</returns>
  303. protected internal abstract object GetKey(int rowIdx);
  304. /// <summary>
  305. /// Gets a value of an element at the specified index in the list.
  306. /// </summary>
  307. /// <param name="key">Key of the element whose value to retrieve.</param>
  308. /// <returns>Value of the dictionary entry for the specified key.</returns>
  309. protected internal abstract object GetValue(object key);
  310. /// <summary>
  311. /// Sets a value of an element at the specified index in the list.
  312. /// </summary>
  313. /// <param name="key">Key of the element whose value to set.</param>
  314. /// <param name="value">Value to assign to the element. Caller must ensure it is of valid type.</param>
  315. protected internal abstract void SetValue(object key, object value);
  316. /// <summary>
  317. /// Updates both key and value of an existing entry.
  318. /// </summary>
  319. /// <param name="oldKey">Original key of the entry.</param>
  320. /// <param name="newKey">New key of the entry.</param>
  321. /// <param name="value">New value of the entry.</param>
  322. protected internal abstract void EditEntry(object oldKey, object newKey, object value);
  323. /// <summary>
  324. /// Adds a new entry to the dictionary.
  325. /// </summary>
  326. /// <param name="key">Key of the entry to add.</param>
  327. /// <param name="value">Value of the entry to add.</param>
  328. protected internal abstract void AddEntry(object key, object value);
  329. /// <summary>
  330. /// Removes the specified entry from the dictionary.
  331. /// </summary>
  332. /// <param name="key">Key of the entry to remove.</param>
  333. protected internal abstract void RemoveEntry(object key);
  334. /// <summary>
  335. /// Creates a new empty key object of a valid type that can be used in the dictionary.
  336. /// </summary>
  337. /// <returns>New empty key object.</returns>
  338. protected internal abstract object CreateKey();
  339. /// <summary>
  340. /// Creates a new empty value object of a valid type that can be used in the dictionary.
  341. /// </summary>
  342. /// <returns>New empty value object.</returns>
  343. protected internal abstract object CreateValue();
  344. /// <summary>
  345. /// Checks does the element with the specified key exist in the dictionary.
  346. /// </summary>
  347. /// <param name="key">Key of the element to check for existence.</param>
  348. /// <returns>True if the key exists in the dictionary, false otherwise.</returns>
  349. protected internal abstract bool Contains(object key);
  350. /// <summary>
  351. /// Clones the specified dictionary element.
  352. /// </summary>
  353. /// <param name="index">Sequential index of the element in the dictionary to clone.</param>
  354. protected internal abstract KeyValuePair<object, object> CloneElement(int index);
  355. /// <summary>
  356. /// Creates a brand new dictionary with zero elements in the place of the current dictionary.
  357. /// </summary>
  358. protected abstract void CreateDictionary();
  359. /// <summary>
  360. /// Deletes the current dictionary object.
  361. /// </summary>
  362. protected abstract void DeleteDictionary();
  363. /// <summary>
  364. /// Hides or shows the dictionary rows.
  365. /// </summary>
  366. /// <param name="expanded">True if the rows should be displayed, false otherwise.</param>
  367. private void ToggleFoldout(bool expanded)
  368. {
  369. isExpanded = expanded;
  370. if (guiChildLayout != null)
  371. guiChildLayout.Active = isExpanded && (rows.Count > 0 || IsEditInProgress());
  372. }
  373. /// <summary>
  374. /// Triggered when the user clicks on the create button on the title bar. Creates a brand new dictionary with zero
  375. /// elements in the place of the current dictionary.
  376. /// </summary>
  377. protected void OnCreateButtonClicked()
  378. {
  379. CreateDictionary();
  380. UpdateHeaderGUI();
  381. editRow.Initialize(this, guiContentLayout, 0, depth + 1);
  382. editRow.Enabled = false;
  383. isModified = true;
  384. }
  385. /// <summary>
  386. /// Triggered when the user clicks on the add button on the title bar. Adds a new empty element to the dictionary.
  387. /// </summary>
  388. protected virtual void OnAddButtonClicked()
  389. {
  390. if (IsEditInProgress())
  391. {
  392. DialogBox.Open(
  393. new LocEdString("Edit in progress."),
  394. new LocEdString("You are editing the entry with key \"" + editKey + "\". You cannot add a row " +
  395. "before applying or discarding those changes. Do you wish to apply those changes first?"),
  396. DialogBox.Type.YesNoCancel,
  397. x =>
  398. {
  399. switch (x)
  400. {
  401. case DialogBox.ResultType.Yes:
  402. if (ApplyChanges())
  403. StartAdd();
  404. break;
  405. case DialogBox.ResultType.No:
  406. DiscardChanges();
  407. StartAdd();
  408. break;
  409. }
  410. });
  411. }
  412. else
  413. {
  414. if (!isExpanded)
  415. ToggleFoldout(true);
  416. StartAdd();
  417. }
  418. }
  419. /// <summary>
  420. /// Triggered when the user clicks on the clear button on the title bar. Deletes the current dictionary object.
  421. /// </summary>
  422. protected void OnClearButtonClicked()
  423. {
  424. DeleteDictionary();
  425. UpdateHeaderGUI();
  426. ClearRows();
  427. isModified = true;
  428. }
  429. /// <summary>
  430. /// Triggered when the user clicks on the delete button next to a dictionary entry. Deletes an element in the
  431. /// dictionary.
  432. /// </summary>
  433. /// <param name="rowIdx">Sequential row index of the entry that was clicked.</param>
  434. protected internal virtual void OnDeleteButtonClicked(int rowIdx)
  435. {
  436. if (IsEditInProgress())
  437. DiscardChanges();
  438. else
  439. {
  440. // Remove the entry, but ensure the rows keep referencing the original keys (dictionaries have undefined
  441. // order so we need to compare old vs. new elements to determine if any changed).
  442. int oldNumRows = GetNumRows();
  443. Dictionary<object, int> oldKeys = new Dictionary<object, int>();
  444. for (int i = 0; i < oldNumRows; i++)
  445. {
  446. Debug.Log("OLD KEYS: " + i + " - " + ((SerializableProperty)GetKey(i)).GetValue<object>() + " -- " +
  447. ((SerializableProperty)GetValue(GetKey(i))).GetValue<object>());
  448. oldKeys.Add(GetKey(i), i);
  449. }
  450. RemoveEntry(GetKey(rowIdx));
  451. int newNumRows = GetNumRows();
  452. Dictionary<object, int> newKeys = new Dictionary<object, int>();
  453. for (int i = 0; i < newNumRows; i++)
  454. {
  455. Debug.Log("NEW KEYS: " + i + " - " + ((SerializableProperty)GetKey(i)).GetValue<object>());
  456. newKeys.Add(GetKey(i), i);
  457. }
  458. foreach (var KVP in oldKeys)
  459. {
  460. int newRowIdx;
  461. if (newKeys.TryGetValue(KVP.Key, out newRowIdx))
  462. {
  463. if (KVP.Value != newRowIdx)
  464. {
  465. GUIDictionaryFieldRow temp = rows[KVP.Value];
  466. Debug.Log("Swapping: " + KVP.Value + " - " + newRowIdx);
  467. temp.SetIndex(newRowIdx);
  468. rows[newRowIdx].SetIndex(KVP.Value);
  469. rows[KVP.Value] = rows[newRowIdx];
  470. rows[newRowIdx] = temp;
  471. }
  472. }
  473. }
  474. for (int i = 0; i < newNumRows; i++)
  475. Debug.Log("NEW VALUES: " + i + " - " + ((SerializableProperty)GetKey(i)).GetValue<object>() + " -- "
  476. + ((SerializableProperty)GetValue(GetKey(i))).GetValue<object>());
  477. for (int i = oldNumRows - 1; i >= newNumRows; i--)
  478. {
  479. rows[i].Destroy();
  480. rows.Remove(i);
  481. }
  482. editRow.SetIndex(newNumRows);
  483. isModified = true;
  484. }
  485. }
  486. /// <summary>
  487. /// Triggered when the user clicks on the clone button next to a dictionary entry. Clones an element and
  488. /// adds the clone to the dictionary.
  489. /// </summary>
  490. /// <param name="rowIdx">Sequential row index of the entry that was clicked.</param>
  491. protected internal virtual void OnCloneButtonClicked(int rowIdx)
  492. {
  493. if (IsEditInProgress())
  494. {
  495. DialogBox.Open(
  496. new LocEdString("Edit in progress."),
  497. new LocEdString("You are editing the entry with key \"" + editKey + "\". You cannot clone a row " +
  498. "before applying or discarding those changes. Do you wish to apply those changes first?"),
  499. DialogBox.Type.YesNoCancel,
  500. x =>
  501. {
  502. switch (x)
  503. {
  504. case DialogBox.ResultType.Yes:
  505. if (ApplyChanges())
  506. StartClone(rowIdx);
  507. break;
  508. case DialogBox.ResultType.No:
  509. DiscardChanges();
  510. StartClone(rowIdx);
  511. break;
  512. }
  513. });
  514. }
  515. else
  516. StartClone(rowIdx);
  517. }
  518. /// <summary>
  519. /// Triggered when user clicks the edit or apply (depending on state) button next to the dictionary entry. Starts
  520. /// edit mode for the element, if not already in edit mode. Applies edit mode changes if already in edit mode.
  521. /// </summary>
  522. /// <param name="rowIdx">Sequential row index of the entry that was clicked.</param>
  523. protected internal virtual void OnEditButtonClicked(int rowIdx)
  524. {
  525. if (editRowIdx == rowIdx)
  526. ApplyChanges();
  527. else
  528. {
  529. if (IsEditInProgress())
  530. {
  531. DialogBox.Open(
  532. new LocEdString("Edit in progress."),
  533. new LocEdString("You are already editing the entry with key \"" + editKey + "\". You cannot edit " +
  534. "another row before applying or discarding those changes. Do you wish to apply those changes first?"),
  535. DialogBox.Type.YesNoCancel,
  536. x =>
  537. {
  538. switch (x)
  539. {
  540. case DialogBox.ResultType.Yes:
  541. if (ApplyChanges())
  542. StartEdit(rowIdx);
  543. break;
  544. case DialogBox.ResultType.No:
  545. DiscardChanges();
  546. StartEdit(rowIdx);
  547. break;
  548. }
  549. });
  550. }
  551. else
  552. StartEdit(rowIdx);
  553. }
  554. }
  555. /// <summary>
  556. /// Starts an edit operation on a row with the specified key. Allows the user to change the key of the specified row.
  557. /// Caller must ensure no edit operation is already in progress.
  558. /// </summary>
  559. /// <param name="rowIdx">Sequential row index of the entry to edit.</param>
  560. private void StartEdit(int rowIdx)
  561. {
  562. object key = GetKey(rowIdx);
  563. KeyValuePair<object, object> clone = CloneElement(rowIdx);
  564. editKey = clone.Key;
  565. editValue = clone.Value;
  566. editOriginalKey = key;
  567. editRowIdx = rowIdx;
  568. rows[rowIdx].EditMode = true;
  569. guiChildLayout.Active = rows.Count > 0 && isExpanded;
  570. }
  571. /// <summary>
  572. /// Starts an add operation. Adds a new key/value pair and allows the user to set them up in a temporary row
  573. /// before inserting them into the dictionary. Caller must ensure no edit operation is already in progress.
  574. /// </summary>
  575. private void StartAdd()
  576. {
  577. editKey = CreateKey();
  578. editValue = CreateValue();
  579. editOriginalKey = null;
  580. editRowIdx = rows.Count;
  581. editRow.BuildGUI();
  582. editRow.Enabled = true;
  583. editRow.EditMode = true;
  584. ToggleFoldout(isExpanded);
  585. }
  586. /// <summary>
  587. /// Starts a clone operation. Adds a new key/value pair by cloning an existing one. Allows the user to modify the
  588. /// new pair in a temporary row before inserting them into the dictionary. Caller must ensure no edit operation is
  589. /// already in progress.
  590. /// </summary>
  591. /// <param name="rowIdx">Sequential row index of the entry to clone.</param>
  592. private void StartClone(int rowIdx)
  593. {
  594. KeyValuePair<object, object> clone = CloneElement(rowIdx);
  595. editKey = clone.Key;
  596. editValue = clone.Value;
  597. editOriginalKey = null;
  598. editRowIdx = rows.Count;
  599. editRow.BuildGUI();
  600. editRow.Enabled = true;
  601. editRow.EditMode = true;
  602. ToggleFoldout(isExpanded);
  603. }
  604. /// <summary>
  605. /// Attempts to apply any changes made to the currently edited row.
  606. /// </summary>
  607. /// <returns>True if the changes were successfully applied, false if the new key already exists in the dictionary.
  608. /// </returns>
  609. private bool ApplyChanges()
  610. {
  611. if (!IsEditInProgress())
  612. return true;
  613. if (Contains(editKey) && (editOriginalKey == null || !editOriginalKey.Equals(editKey)))
  614. {
  615. DialogBox.Open(
  616. new LocEdString("Key already exists."),
  617. new LocEdString("Cannot add a key \"" + editKey + "\" to dictionary. Key already exists"),
  618. DialogBox.Type.OK);
  619. return false;
  620. }
  621. else
  622. {
  623. if (IsTemporaryRow(editRowIdx))
  624. {
  625. editRow.EditMode = false;
  626. editRow.Enabled = false;
  627. }
  628. else
  629. {
  630. rows[editRowIdx].EditMode = false;
  631. }
  632. // Add/remove the entry, but ensure the rows keep referencing the original keys (dictionaries have undefined
  633. // order so we need to compare old vs. new elements to determine if any changed).
  634. int oldNumRows = GetNumRows();
  635. Dictionary<object, int> oldKeys = new Dictionary<object, int>();
  636. for (int i = 0; i < oldNumRows; i++)
  637. oldKeys.Add(GetKey(i), i);
  638. if (editOriginalKey != null) // Editing
  639. EditEntry(editOriginalKey, editKey, editValue);
  640. else // Adding/Cloning
  641. AddEntry(editKey, editValue);
  642. int newNumRows = GetNumRows();
  643. Dictionary<object, int> newKeys = new Dictionary<object, int>();
  644. for (int i = 0; i < newNumRows; i++)
  645. newKeys.Add(GetKey(i), i);
  646. // Hidden dependency: Initialize must be called after all elements are
  647. // in the dictionary so we do it in two steps
  648. for (int i = oldNumRows; i < newNumRows; i++)
  649. rows[i] = CreateRow();
  650. for (int i = oldNumRows; i < newNumRows; i++)
  651. rows[i].Initialize(this, guiContentLayout, i, depth + 1);
  652. foreach (var KVP in oldKeys)
  653. {
  654. int newRowIdx;
  655. if (newKeys.TryGetValue(KVP.Key, out newRowIdx))
  656. {
  657. if (KVP.Value != newRowIdx)
  658. {
  659. GUIDictionaryFieldRow temp = rows[KVP.Value];
  660. temp.SetIndex(newRowIdx);
  661. rows[newRowIdx].SetIndex(KVP.Value);
  662. rows[KVP.Value] = rows[newRowIdx];
  663. rows[newRowIdx] = temp;
  664. }
  665. }
  666. }
  667. for (int i = oldNumRows - 1; i >= newNumRows; i--)
  668. {
  669. rows[i].Destroy();
  670. rows.Remove(i);
  671. }
  672. editRow.SetIndex(newNumRows);
  673. editKey = CreateKey();
  674. editValue = CreateValue();
  675. editOriginalKey = null;
  676. editRowIdx = -1;
  677. ToggleFoldout(isExpanded);
  678. isModified = true;
  679. return true;
  680. }
  681. }
  682. /// <summary>
  683. /// Cancels any changes made on the currently edited row.
  684. /// </summary>
  685. private void DiscardChanges()
  686. {
  687. if (IsEditInProgress())
  688. {
  689. if (IsTemporaryRow(editRowIdx))
  690. {
  691. editRow.EditMode = false;
  692. editRow.Enabled = false;
  693. }
  694. else
  695. {
  696. rows[editRowIdx].EditMode = false;
  697. }
  698. editKey = CreateKey();
  699. editValue = CreateValue();
  700. editOriginalKey = null;
  701. editRow.Enabled = false;
  702. editRowIdx = -1;
  703. ToggleFoldout(isExpanded);
  704. }
  705. }
  706. /// <summary>
  707. /// Possible states dictionary GUI can be in.
  708. /// </summary>
  709. private enum State
  710. {
  711. None,
  712. Empty,
  713. Filled
  714. }
  715. }
  716. /// <summary>
  717. /// Creates GUI elements that allow viewing and manipulation of a <see cref="Dictionary{TKey,TValue}"/>. When constructing the
  718. /// object user can provide a custom type that manages GUI for individual dictionary elements.
  719. /// </summary>
  720. /// <typeparam name="Key">Type of key used by the dictionary.</typeparam>
  721. /// <typeparam name="Value">Type of value stored in the dictionary.</typeparam>
  722. /// <typeparam name="RowType">Type of rows that are used to handle GUI for individual dictionary elements.</typeparam>
  723. public class GUIDictionaryField<Key, Value, RowType> : GUIDictionaryFieldBase where RowType : GUIDictionaryFieldRow, new()
  724. {
  725. public delegate int SortDictionaryDelegate(Key a, Key b);
  726. /// <summary>
  727. /// Triggered when the reference array has been changed. This does not include changes that only happen to its
  728. /// internal elements.
  729. /// </summary>
  730. public Action<Dictionary<Key, Value>> OnChanged;
  731. /// <summary>
  732. /// Triggered when an element in the list has been added or changed.
  733. /// </summary>
  734. public Action<Key> OnValueChanged;
  735. /// <summary>
  736. /// Triggered when an element in the dictionary has been removed.
  737. /// </summary>
  738. public Action<Key> OnValueRemoved;
  739. /// <summary>
  740. /// Optional method that will be used for sorting the elements in the dictionary.
  741. /// </summary>
  742. public SortDictionaryDelegate SortMethod;
  743. /// <summary>
  744. /// Array object whose contents are displayed.
  745. /// </summary>
  746. public Dictionary<Key, Value> Dictionary { get { return dictionary; } }
  747. protected Dictionary<Key, Value> dictionary;
  748. private List<Key> orderedKeys = new List<Key>();
  749. /// <summary>
  750. /// Constructs a new dictionary GUI field.
  751. /// </summary>
  752. /// <param name="title">Label to display on the dictionary GUI title.</param>
  753. /// <param name="dictionary">Object containing the data. Can be null.</param>
  754. /// <param name="layout">Layout to which to append the list GUI elements to.</param>
  755. /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
  756. /// nested containers whose backgrounds are overlaping. Also determines background style,
  757. /// depths divisible by two will use an alternate style.</param>
  758. protected GUIDictionaryField(LocString title, Dictionary<Key, Value> dictionary, GUILayout layout, int depth = 0)
  759. : base(title, layout, depth)
  760. {
  761. this.dictionary = dictionary;
  762. UpdateKeys();
  763. }
  764. /// <summary>
  765. /// Creates a dictionary GUI field containing GUI elements required for displaying the provided dictionary.
  766. /// </summary>
  767. /// <typeparam name="RowType">Type of rows that are used to handle GUI for individual dictionary elements.</typeparam>
  768. /// <param name="title">Label to display on the list GUI title.</param>
  769. /// <param name="dictionary">Object containing the data. Can be null.</param>
  770. /// <param name="layout">Layout to which to append the list GUI elements to.</param>
  771. /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
  772. /// nested containers whose backgrounds are overlaping. Also determines background style,
  773. /// depths divisible by two will use an alternate style.</param>
  774. /// <returns>New instance of dictionary GUI field.</returns>
  775. public static GUIDictionaryField<Key, Value, RowType> Create(LocString title, Dictionary<Key, Value> dictionary,
  776. GUILayout layout, int depth = 0)
  777. {
  778. GUIDictionaryField<Key, Value, RowType> guiDictionary = new GUIDictionaryField<Key, Value, RowType>(
  779. title, dictionary, layout, depth);
  780. guiDictionary.BuildGUI();
  781. return guiDictionary;
  782. }
  783. /// <summary>
  784. /// Updates the ordered set of keys used for mapping sequential indexes to keys. Should be called whenever a
  785. /// dictionary key changes.
  786. /// </summary>
  787. private void UpdateKeys()
  788. {
  789. orderedKeys.Clear();
  790. if (dictionary != null)
  791. {
  792. foreach (var KVP in dictionary)
  793. orderedKeys.Add(KVP.Key);
  794. if (SortMethod != null)
  795. orderedKeys.Sort((x,y) => SortMethod(x, y));
  796. else
  797. orderedKeys.Sort();
  798. }
  799. }
  800. /// <inheritdoc/>
  801. protected override GUIDictionaryFieldRow CreateRow()
  802. {
  803. return new RowType();
  804. }
  805. /// <inheritdoc/>
  806. protected override int GetNumRows()
  807. {
  808. if (dictionary != null)
  809. return dictionary.Count;
  810. return 0;
  811. }
  812. /// <inheritdoc/>
  813. protected override bool IsNull()
  814. {
  815. return dictionary == null;
  816. }
  817. /// <inheritdoc/>
  818. protected internal override object GetKey(int rowIdx)
  819. {
  820. return orderedKeys[rowIdx];
  821. }
  822. /// <inheritdoc/>
  823. protected internal override object GetValue(object key)
  824. {
  825. return dictionary[(Key)key];
  826. }
  827. /// <inheritdoc/>
  828. protected internal override void SetValue(object key, object value)
  829. {
  830. dictionary[(Key)key] = (Value)value;
  831. if (OnValueChanged != null)
  832. OnValueChanged((Key)key);
  833. }
  834. /// <inheritdoc/>
  835. protected internal override bool Contains(object key)
  836. {
  837. return dictionary.ContainsKey((Key)key); ;
  838. }
  839. /// <inheritdoc/>
  840. protected internal override void EditEntry(object oldKey, object newKey, object value)
  841. {
  842. dictionary.Remove((Key)oldKey);
  843. dictionary[(Key)newKey] = (Value)value;
  844. if (OnValueRemoved != null)
  845. OnValueRemoved((Key)oldKey);
  846. if (OnValueChanged != null)
  847. OnValueChanged((Key)newKey);
  848. UpdateKeys();
  849. }
  850. /// <inheritdoc/>
  851. protected internal override void AddEntry(object key, object value)
  852. {
  853. dictionary[(Key)key] = (Value)value;
  854. if (OnValueChanged != null)
  855. OnValueChanged((Key)key);
  856. UpdateKeys();
  857. }
  858. /// <inheritdoc/>
  859. protected internal override void RemoveEntry(object key)
  860. {
  861. dictionary.Remove((Key) key);
  862. if (OnValueRemoved != null)
  863. OnValueRemoved((Key)key);
  864. UpdateKeys();
  865. }
  866. /// <inheritdoc/>
  867. protected internal override object CreateKey()
  868. {
  869. return SerializableUtility.Create<Key>();
  870. }
  871. /// <inheritdoc/>
  872. protected internal override object CreateValue()
  873. {
  874. return SerializableUtility.Create<Value>();
  875. }
  876. /// <inheritdoc/>
  877. protected internal override KeyValuePair<object, object> CloneElement(int index)
  878. {
  879. object key = GetKey(index);
  880. object value = GetValue(key);
  881. KeyValuePair<object, object> clone = new KeyValuePair<object, object>(
  882. SerializableUtility.Clone(key), SerializableUtility.Clone(value));
  883. return clone;
  884. }
  885. /// <inheritdoc/>
  886. protected override void CreateDictionary()
  887. {
  888. dictionary = new Dictionary<Key, Value>();
  889. if (OnChanged != null)
  890. OnChanged(dictionary);
  891. UpdateKeys();
  892. }
  893. /// <inheritdoc/>
  894. protected override void DeleteDictionary()
  895. {
  896. dictionary = null;
  897. if (OnChanged != null)
  898. OnChanged(dictionary);
  899. UpdateKeys();
  900. }
  901. }
  902. /// <summary>
  903. /// Contains GUI elements for a single entry in a dictionary.
  904. /// </summary>
  905. public abstract class GUIDictionaryFieldRow
  906. {
  907. private GUILayoutY rowLayout;
  908. private GUILayoutX keyRowLayout;
  909. private GUILayoutY keyLayout;
  910. private GUILayoutY valueLayout;
  911. private GUILayoutX titleLayout;
  912. private GUIButton cloneBtn;
  913. private GUIButton deleteBtn;
  914. private GUIButton editBtn;
  915. private bool localTitleLayout;
  916. private bool enabled = true;
  917. private bool editMode = false;
  918. private GUIDictionaryFieldBase parent;
  919. private int rowIdx;
  920. private int depth;
  921. private InspectableState modifiedState;
  922. /// <summary>
  923. /// Returns the depth at which the row is rendered.
  924. /// </summary>
  925. protected int Depth { get { return depth; } }
  926. /// <summary>
  927. /// Determines is the row currently being displayed.
  928. /// </summary>
  929. internal bool Enabled
  930. {
  931. get { return enabled; }
  932. set { enabled = value; rowLayout.Active = value; }
  933. }
  934. /// <summary>
  935. /// Enables or disables the row's edit mode. This determines what type of buttons are shown on the row title bar.
  936. /// </summary>
  937. internal bool EditMode
  938. {
  939. set
  940. {
  941. if (value)
  942. {
  943. GUIContent cancelIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Cancel));
  944. GUIContent applyIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Apply));
  945. deleteBtn.SetContent(cancelIcon);
  946. editBtn.SetContent(applyIcon);
  947. }
  948. else
  949. {
  950. GUIContent deleteIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Delete));
  951. GUIContent editIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Edit));
  952. deleteBtn.SetContent(deleteIcon);
  953. editBtn.SetContent(editIcon);
  954. }
  955. editMode = value;
  956. OnEditModeChanged(value);
  957. }
  958. }
  959. /// <summary>
  960. /// Constructs a new dictionary row object.
  961. /// </summary>
  962. protected GUIDictionaryFieldRow()
  963. {
  964. }
  965. /// <summary>
  966. /// Initializes the row and creates row GUI elements.
  967. /// </summary>
  968. /// <param name="parent">Parent array GUI object that the entry is contained in.</param>
  969. /// <param name="parentLayout">Parent layout that row GUI elements will be added to.</param>
  970. /// <param name="rowIdx">Sequential index of the row.</param>
  971. /// <param name="depth">Determines the depth at which the element is rendered.</param>
  972. internal void Initialize(GUIDictionaryFieldBase parent, GUILayout parentLayout, int rowIdx, int depth)
  973. {
  974. this.parent = parent;
  975. this.rowIdx = rowIdx;
  976. this.depth = depth;
  977. rowLayout = parentLayout.AddLayoutY();
  978. keyRowLayout = rowLayout.AddLayoutX();
  979. keyLayout = keyRowLayout.AddLayoutY();
  980. valueLayout = rowLayout.AddLayoutY();
  981. BuildGUI();
  982. }
  983. /// <summary>
  984. /// Changes the index of the dictionary element this row represents.
  985. /// </summary>
  986. /// <param name="seqIndex">Sequential index of the dictionary entry.</param>
  987. internal void SetIndex(int seqIndex)
  988. {
  989. this.rowIdx = seqIndex;
  990. }
  991. /// <summary>
  992. /// (Re)creates all row GUI elements.
  993. /// </summary>
  994. internal protected void BuildGUI()
  995. {
  996. keyLayout.Clear();
  997. valueLayout.Clear();
  998. GUILayoutX externalTitleLayout = CreateKeyGUI(keyLayout);
  999. CreateValueGUI(valueLayout);
  1000. if (localTitleLayout || (titleLayout != null && titleLayout == externalTitleLayout))
  1001. return;
  1002. if (externalTitleLayout != null)
  1003. {
  1004. localTitleLayout = false;
  1005. titleLayout = externalTitleLayout;
  1006. }
  1007. else
  1008. {
  1009. GUILayoutY buttonCenter = keyRowLayout.AddLayoutY();
  1010. buttonCenter.AddFlexibleSpace();
  1011. titleLayout = buttonCenter.AddLayoutX();
  1012. buttonCenter.AddFlexibleSpace();
  1013. localTitleLayout = true;
  1014. }
  1015. GUIContent cloneIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clone));
  1016. GUIContent deleteIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Delete));
  1017. GUIContent editIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Edit));
  1018. cloneBtn = new GUIButton(cloneIcon, GUIOption.FixedWidth(30));
  1019. deleteBtn = new GUIButton(deleteIcon, GUIOption.FixedWidth(30));
  1020. editBtn = new GUIButton(editIcon, GUIOption.FixedWidth(30));
  1021. cloneBtn.OnClick += () => parent.OnCloneButtonClicked(rowIdx);
  1022. deleteBtn.OnClick += () => parent.OnDeleteButtonClicked(rowIdx);
  1023. editBtn.OnClick += () => parent.OnEditButtonClicked(rowIdx);
  1024. titleLayout.AddElement(cloneBtn);
  1025. titleLayout.AddElement(deleteBtn);
  1026. titleLayout.AddSpace(10);
  1027. titleLayout.AddElement(editBtn);
  1028. EditMode = editMode;
  1029. }
  1030. /// <summary>
  1031. /// Creates GUI elements specific to type in the key portion of a dictionary entry.
  1032. /// </summary>
  1033. /// <param name="layout">Layout to insert the row GUI elements to.</param>
  1034. /// <returns>An optional title bar layout that the standard dictionary buttons will be appended to.</returns>
  1035. protected abstract GUILayoutX CreateKeyGUI(GUILayoutY layout);
  1036. /// <summary>
  1037. /// Creates GUI elements specific to type in the key portion of a dictionary entry.
  1038. /// </summary>
  1039. /// <param name="layout">Layout to insert the row GUI elements to.</param>
  1040. protected abstract void CreateValueGUI(GUILayoutY layout);
  1041. /// <summary>
  1042. /// Triggered when a GUI rows enters or leaves edit mode. Allows the row GUI to be updated accordingly.
  1043. /// </summary>
  1044. /// <param name="editMode">True if the edit mode is being enabled, false otherwise.</param>
  1045. protected virtual void OnEditModeChanged(bool editMode) { }
  1046. /// <summary>
  1047. /// Refreshes the GUI for the dictionary row and checks if anything was modified.
  1048. /// </summary>
  1049. /// <returns>State representing was anything modified between two last calls to <see cref="Refresh"/>.</returns>
  1050. internal protected virtual InspectableState Refresh()
  1051. {
  1052. InspectableState oldState = modifiedState;
  1053. if (modifiedState.HasFlag(InspectableState.Modified))
  1054. modifiedState = InspectableState.NotModified;
  1055. return oldState;
  1056. }
  1057. /// <summary>
  1058. /// Marks the contents of the row as modified.
  1059. /// </summary>
  1060. protected void MarkAsModified()
  1061. {
  1062. modifiedState |= InspectableState.ModifyInProgress;
  1063. }
  1064. /// <summary>
  1065. /// Confirms any queued modifications, signaling parent elements.
  1066. /// </summary>
  1067. protected void ConfirmModify()
  1068. {
  1069. if (modifiedState.HasFlag(InspectableState.ModifyInProgress))
  1070. modifiedState |= InspectableState.Modified;
  1071. }
  1072. /// <summary>
  1073. /// Gets the key contained in this dictionary's row.
  1074. /// </summary>
  1075. /// <typeparam name="T">Type of the key. Must match the dictionary's element type.</typeparam>
  1076. /// <returns>Key in this dictionary's row.</returns>
  1077. protected T GetKey<T>()
  1078. {
  1079. return (T)parent.GetKeyInternal(rowIdx);
  1080. }
  1081. /// <summary>
  1082. /// Sets the key for in this dictionary's row.
  1083. /// </summary>
  1084. /// <typeparam name="T">Type of the key. Must match the dictionary's element type.</typeparam>
  1085. /// <param name="key">Key to assign to this row.</param>
  1086. protected void SetKey<T>(T key)
  1087. {
  1088. parent.SetKey(rowIdx, key);
  1089. }
  1090. /// <summary>
  1091. /// Gets the value contained in this dictionary's row.
  1092. /// </summary>
  1093. /// <typeparam name="T">Type of the value. Must match the dictionary's element type.</typeparam>
  1094. /// <returns>Value in this dictionary's row.</returns>
  1095. protected T GetValue<T>()
  1096. {
  1097. return (T)parent.GetValueInternal(rowIdx);
  1098. }
  1099. /// <summary>
  1100. /// Sets the value contained in this dictionary's row.
  1101. /// </summary>
  1102. /// <typeparam name="T">Type of the value. Must match the dictionary's element type.</typeparam>
  1103. /// <param name="value">Value to set.</param>
  1104. protected void SetValue<T>(T value)
  1105. {
  1106. parent.SetValueInternal(rowIdx, value);
  1107. }
  1108. /// <summary>
  1109. /// Destroys all row GUI elements.
  1110. /// </summary>
  1111. public void Destroy()
  1112. {
  1113. if (rowLayout != null)
  1114. {
  1115. rowLayout.Destroy();
  1116. rowLayout = null;
  1117. }
  1118. keyRowLayout = null;
  1119. keyLayout = null;
  1120. valueLayout = null;
  1121. titleLayout = null;
  1122. cloneBtn = null;
  1123. deleteBtn = null;
  1124. editBtn = null;
  1125. localTitleLayout = false;
  1126. }
  1127. }
  1128. }