LibraryDropDown.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// Drop down window that displays options used by the library window.
  8. /// </summary>
  9. internal class LibraryDropDown : DropDownWindow
  10. {
  11. private LibraryWindow parent;
  12. /// <summary>
  13. /// Constructs the drop down window.
  14. /// </summary>
  15. public LibraryDropDown()
  16. : base(150, 30)
  17. { }
  18. /// <summary>
  19. /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before
  20. /// use.
  21. /// </summary>
  22. /// <param name="parent">Libary window that this drop down window is a part of.</param>
  23. internal void Initialize(LibraryWindow parent)
  24. {
  25. this.parent = parent;
  26. GUIToggleGroup group = new GUIToggleGroup();
  27. GUIToggle list16 = new GUIToggle(new LocEdString("16"), group, EditorStyles.Button, GUIOption.FixedWidth(30));
  28. GUIToggle grid32 = new GUIToggle(new LocEdString("32"), group, EditorStyles.Button, GUIOption.FixedWidth(30));
  29. GUIToggle grid48 = new GUIToggle(new LocEdString("48"), group, EditorStyles.Button, GUIOption.FixedWidth(30));
  30. GUIToggle grid64 = new GUIToggle(new LocEdString("64"), group, EditorStyles.Button, GUIOption.FixedWidth(30));
  31. ProjectViewType activeType = parent.ViewType;
  32. switch (activeType)
  33. {
  34. case ProjectViewType.List16:
  35. list16.Value = true;
  36. break;
  37. case ProjectViewType.Grid32:
  38. grid32.Value = true;
  39. break;
  40. case ProjectViewType.Grid48:
  41. grid48.Value = true;
  42. break;
  43. case ProjectViewType.Grid64:
  44. grid64.Value = true;
  45. break;
  46. }
  47. list16.OnToggled += (active) =>
  48. {
  49. if (active)
  50. ChangeViewType(ProjectViewType.List16);
  51. };
  52. grid32.OnToggled += (active) =>
  53. {
  54. if (active)
  55. ChangeViewType(ProjectViewType.Grid32);
  56. };
  57. grid48.OnToggled += (active) =>
  58. {
  59. if (active)
  60. ChangeViewType(ProjectViewType.Grid48);
  61. };
  62. grid64.OnToggled += (active) =>
  63. {
  64. if (active)
  65. ChangeViewType(ProjectViewType.Grid64);
  66. };
  67. GUILayoutY vertLayout = GUI.AddLayoutY();
  68. vertLayout.AddFlexibleSpace();
  69. GUILayoutX contentLayout = vertLayout.AddLayoutX();
  70. contentLayout.AddFlexibleSpace();
  71. contentLayout.AddElement(list16);
  72. contentLayout.AddElement(grid32);
  73. contentLayout.AddElement(grid48);
  74. contentLayout.AddElement(grid64);
  75. contentLayout.AddFlexibleSpace();
  76. vertLayout.AddFlexibleSpace();
  77. }
  78. /// <summary>
  79. /// Changes the icon view type in the library window.
  80. /// </summary>
  81. /// <param name="viewType">Type of icons to display in the library window.</param>
  82. private void ChangeViewType(ProjectViewType viewType)
  83. {
  84. parent.ViewType = viewType;
  85. }
  86. }
  87. }