ProjectWindow.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. internal enum ProjectViewType
  8. {
  9. Grid64, Grid48, Grid32, List16
  10. }
  11. internal sealed class ProjectWindow : EditorWindow
  12. {
  13. private class ContentInfo
  14. {
  15. public ContentInfo(ProjectWindow window, ProjectViewType viewType, int numEntries)
  16. {
  17. GUIPanel parentPanel = window.scrollAreaPanel;
  18. GUIPanel contentPanel = parentPanel.AddPanel(1);
  19. overlay = parentPanel.AddPanel(0);
  20. underlay = parentPanel.AddPanel(2);
  21. main = contentPanel.AddLayoutY();
  22. if (viewType == ProjectViewType.List16)
  23. {
  24. tileSize = 16;
  25. gridLayout = false;
  26. elementsPerRow = 1;
  27. }
  28. else
  29. {
  30. switch (viewType)
  31. {
  32. case ProjectViewType.Grid64:
  33. tileSize = 64;
  34. break;
  35. case ProjectViewType.Grid48:
  36. tileSize = 48;
  37. break;
  38. case ProjectViewType.Grid32:
  39. tileSize = 32;
  40. break;
  41. }
  42. gridLayout = true;
  43. Rect2I scrollBounds = window.contentScrollArea.Bounds;
  44. int availableWidth = scrollBounds.width;
  45. int elemSize = tileSize + GRID_ENTRY_SPACING;
  46. elementsPerRow = (availableWidth - GRID_ENTRY_SPACING * 2) / elemSize;
  47. int numRows = MathEx.CeilToInt(numEntries / (float)elementsPerRow);
  48. int neededHeight = numRows * (elemSize);
  49. bool requiresScrollbar = neededHeight > scrollBounds.height;
  50. if (requiresScrollbar)
  51. {
  52. availableWidth -= window.contentScrollArea.ScrollBarWidth;
  53. elementsPerRow = (availableWidth - GRID_ENTRY_SPACING * 2) / elemSize;
  54. }
  55. labelWidth = availableWidth / elementsPerRow;
  56. labelWidth -= (elementsPerRow + 1)*MIN_HORZ_SPACING;
  57. }
  58. this.window = window;
  59. }
  60. public GUILayout main;
  61. public GUIPanel overlay;
  62. public GUIPanel underlay;
  63. public ProjectWindow window;
  64. public int tileSize;
  65. public bool gridLayout;
  66. public int elementsPerRow;
  67. public int labelWidth;
  68. }
  69. private class ElementEntry
  70. {
  71. // Note: Order of these is relevant
  72. enum UnderlayState
  73. {
  74. None, Hovered, Selected, Pinged
  75. }
  76. public int index;
  77. public string path;
  78. public GUITexture icon;
  79. public GUILabel label;
  80. public Rect2I bounds;
  81. private GUITexture underlay;
  82. private ContentInfo info;
  83. private UnderlayState underlayState;
  84. public ElementEntry(ContentInfo info, GUILayout parent, LibraryEntry entry, int index)
  85. {
  86. GUILayout entryLayout;
  87. if (info.gridLayout)
  88. entryLayout = parent.AddLayoutY();
  89. else
  90. entryLayout = parent.AddLayoutX();
  91. SpriteTexture iconTexture = GetIcon(entry);
  92. icon = new GUITexture(iconTexture, GUIImageScaleMode.ScaleToFit,
  93. true, GUIOption.FixedHeight(info.tileSize), GUIOption.FixedWidth(info.tileSize));
  94. label = null;
  95. if (info.gridLayout)
  96. {
  97. label = new GUILabel(entry.Name, EditorStyles.MultiLineLabel,
  98. GUIOption.FixedWidth(info.labelWidth), GUIOption.FlexibleHeight(0, MAX_LABEL_HEIGHT));
  99. }
  100. else
  101. {
  102. label = new GUILabel(entry.Name);
  103. }
  104. entryLayout.AddElement(icon);
  105. entryLayout.AddElement(label);
  106. this.info = info;
  107. this.index = index;
  108. this.path = entry.Path;
  109. this.bounds = new Rect2I();
  110. this.underlay = null;
  111. }
  112. public void Initialize()
  113. {
  114. bounds = icon.Bounds;
  115. Rect2I labelBounds = label.Bounds;
  116. bounds.x = MathEx.Min(bounds.x, labelBounds.x);
  117. bounds.y = MathEx.Min(bounds.y, labelBounds.y) - 5; // 5 - Just padding for better look
  118. bounds.width = MathEx.Max(bounds.x + bounds.width,
  119. labelBounds.x + labelBounds.width) - bounds.x;
  120. bounds.height = MathEx.Max(bounds.y + bounds.height,
  121. labelBounds.y + labelBounds.height) - bounds.y;
  122. ProjectWindow hoistedWindow = info.window;
  123. string hoistedPath = path;
  124. GUIButton overlayBtn = new GUIButton("", EditorStyles.Blank);
  125. overlayBtn.Bounds = bounds;
  126. overlayBtn.OnClick += () => hoistedWindow.OnEntryClicked(hoistedPath);
  127. overlayBtn.OnDoubleClick += () => hoistedWindow.OnEntryDoubleClicked(hoistedPath);
  128. overlayBtn.SetContextMenu(info.window.entryContextMenu);
  129. info.overlay.AddElement(overlayBtn);
  130. }
  131. public Rect2I Bounds
  132. {
  133. get { return bounds; }
  134. }
  135. public void MarkAsCut(bool enable)
  136. {
  137. if (enable)
  138. icon.SetTint(CUT_COLOR);
  139. else
  140. icon.SetTint(Color.White);
  141. }
  142. public void MarkAsSelected(bool enable)
  143. {
  144. if ((int)underlayState > (int) UnderlayState.Selected)
  145. return;
  146. if (enable)
  147. {
  148. CreateUnderlay();
  149. underlay.SetTint(SELECTION_COLOR);
  150. }
  151. else
  152. ClearUnderlay();
  153. underlayState = UnderlayState.Selected;
  154. }
  155. public void MarkAsPinged(bool enable)
  156. {
  157. if ((int)underlayState > (int)UnderlayState.Pinged)
  158. return;
  159. if (enable)
  160. {
  161. CreateUnderlay();
  162. underlay.SetTint(PING_COLOR);
  163. }
  164. else
  165. ClearUnderlay();
  166. underlayState = UnderlayState.Pinged;
  167. }
  168. public void MarkAsHovered(bool enable)
  169. {
  170. if ((int)underlayState > (int)UnderlayState.Hovered)
  171. return;
  172. if (enable)
  173. {
  174. CreateUnderlay();
  175. underlay.SetTint(HOVER_COLOR);
  176. }
  177. else
  178. ClearUnderlay();
  179. underlayState = UnderlayState.Hovered;
  180. }
  181. private void ClearUnderlay()
  182. {
  183. if (underlay != null)
  184. {
  185. underlay.Destroy();
  186. underlay = null;
  187. }
  188. underlayState = UnderlayState.None;
  189. }
  190. private void CreateUnderlay()
  191. {
  192. if (underlay == null)
  193. {
  194. underlay = new GUITexture(Builtin.WhiteTexture);
  195. underlay.Bounds = Bounds;
  196. info.underlay.AddElement(underlay);
  197. }
  198. }
  199. private static SpriteTexture GetIcon(LibraryEntry entry)
  200. {
  201. if (entry.Type == LibraryEntryType.Directory)
  202. {
  203. return EditorBuiltin.FolderIcon;
  204. }
  205. else
  206. {
  207. FileEntry fileEntry = (FileEntry)entry;
  208. switch (fileEntry.ResType)
  209. {
  210. case ResourceType.Font:
  211. return EditorBuiltin.FontIcon;
  212. case ResourceType.Mesh:
  213. return EditorBuiltin.MeshIcon;
  214. case ResourceType.Texture:
  215. return EditorBuiltin.TextureIcon;
  216. case ResourceType.PlainText:
  217. return EditorBuiltin.PlainTextIcon;
  218. case ResourceType.ScriptCode:
  219. return EditorBuiltin.ScriptCodeIcon;
  220. case ResourceType.SpriteTexture:
  221. return EditorBuiltin.SpriteTextureIcon;
  222. case ResourceType.Shader:
  223. return EditorBuiltin.ShaderIcon;
  224. case ResourceType.Material:
  225. return EditorBuiltin.MaterialIcon;
  226. }
  227. }
  228. return null;
  229. }
  230. }
  231. enum MoveDirection
  232. {
  233. Up, Down, Left, Right
  234. }
  235. private const int GRID_ENTRY_SPACING = 15;
  236. private const int LIST_ENTRY_SPACING = 7;
  237. private const int MAX_LABEL_HEIGHT = 50;
  238. private const int MIN_HORZ_SPACING = 5;
  239. private const int DRAG_SCROLL_HEIGHT = 20;
  240. private const int DRAG_SCROLL_AMOUNT_PER_SECOND = 100;
  241. private const int FOLDER_BUTTON_WIDTH = 20;
  242. private const int FOLDER_SEPARATOR_WIDTH = 7;
  243. private static readonly Color PING_COLOR = Color.BansheeOrange;
  244. private static readonly Color SELECTION_COLOR = Color.DarkCyan;
  245. private static readonly Color HOVER_COLOR = new Color(Color.DarkCyan.r, Color.DarkCyan.g, Color.DarkCyan.b, 0.5f);
  246. private static readonly Color CUT_COLOR = new Color(1.0f, 1.0f, 1.0f, 0.5f);
  247. private bool hasContentFocus = false;
  248. private bool HasContentFocus { get { return HasFocus && hasContentFocus; } }
  249. private string searchQuery;
  250. private bool IsSearchActive { get { return !string.IsNullOrEmpty(searchQuery); } }
  251. private ProjectViewType viewType = ProjectViewType.Grid32;
  252. private string currentDirectory = "";
  253. private List<string> selectionPaths = new List<string>();
  254. private int selectionAnchorStart = -1;
  255. private int selectionAnchorEnd = -1;
  256. private string pingPath = "";
  257. private string hoverHighlightPath = "";
  258. private ContentInfo contentInfo;
  259. private GUIScrollArea contentScrollArea;
  260. private GUIPanel scrollAreaPanel;
  261. private GUILayoutX searchBarLayout;
  262. private GUIButton optionsButton;
  263. private GUILayout folderBarLayout;
  264. private GUILayout folderListLayout;
  265. private GUITextField searchField;
  266. private GUITexture dragSelection;
  267. private ContextMenu entryContextMenu;
  268. private ProjectDropTarget dropTarget;
  269. private List<ElementEntry> entries = new List<ElementEntry>();
  270. private Dictionary<string, ElementEntry> entryLookup = new Dictionary<string, ElementEntry>();
  271. private int autoScrollAmount;
  272. private bool isDraggingSelection;
  273. private Vector2I dragSelectionStart;
  274. private Vector2I dragSelectionEnd;
  275. // Cut/Copy/Paste
  276. private List<string> copyPaths = new List<string>();
  277. private List<string> cutPaths = new List<string>();
  278. internal ProjectViewType ViewType
  279. {
  280. get { return viewType; }
  281. set { viewType = value; Refresh(); }
  282. }
  283. [MenuItem("Windows/Project", ButtonModifier.Ctrl, ButtonCode.P)]
  284. private static void OpenProjectWindow()
  285. {
  286. OpenWindow<ProjectWindow>();
  287. }
  288. private void OnInitialize()
  289. {
  290. ProjectLibrary.OnEntryAdded += OnEntryChanged;
  291. ProjectLibrary.OnEntryRemoved += OnEntryChanged;
  292. GUILayoutY contentLayout = GUI.AddLayoutY();
  293. searchBarLayout = contentLayout.AddLayoutX();
  294. searchField = new GUITextField();
  295. searchField.OnChanged += OnSearchChanged;
  296. GUIButton clearSearchBtn = new GUIButton("C");
  297. clearSearchBtn.OnClick += ClearSearch;
  298. clearSearchBtn.SetWidth(40);
  299. optionsButton = new GUIButton("O");
  300. optionsButton.OnClick += OpenOptionsWindow;
  301. optionsButton.SetWidth(40);
  302. searchBarLayout.AddElement(searchField);
  303. searchBarLayout.AddElement(clearSearchBtn);
  304. searchBarLayout.AddElement(optionsButton);
  305. folderBarLayout = contentLayout.AddLayoutX();
  306. GUIButton homeButton = new GUIButton("H", GUIOption.FixedWidth(FOLDER_BUTTON_WIDTH));
  307. homeButton.OnClick += OnHomeClicked;
  308. GUIButton upButton = new GUIButton("U", GUIOption.FixedWidth(FOLDER_BUTTON_WIDTH));
  309. upButton.OnClick += OnUpClicked;
  310. folderBarLayout.AddElement(homeButton);
  311. folderBarLayout.AddElement(upButton);
  312. folderBarLayout.AddSpace(10);
  313. contentScrollArea = new GUIScrollArea(GUIOption.FlexibleWidth(), GUIOption.FlexibleHeight());
  314. contentLayout.AddElement(contentScrollArea);
  315. contentLayout.AddFlexibleSpace();
  316. entryContextMenu = new ContextMenu();
  317. entryContextMenu.AddItem("Cut", CutSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.X));
  318. entryContextMenu.AddItem("Copy", CopySelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.C));
  319. entryContextMenu.AddItem("Duplicate", DuplicateSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.D));
  320. entryContextMenu.AddItem("Paste", PasteToSelection, new ShortcutKey(ButtonModifier.Ctrl, ButtonCode.V));
  321. Reset();
  322. dropTarget = new ProjectDropTarget(this);
  323. dropTarget.Bounds = contentScrollArea.Bounds;
  324. dropTarget.OnStart += DoOnDragStart;
  325. dropTarget.OnDrag += DoOnDragMove;
  326. dropTarget.OnLeave += DoOnDragLeave;
  327. dropTarget.OnDrop += DoOnDragDropped;
  328. dropTarget.OnEnd += DoOnDragEnd;
  329. }
  330. private ElementEntry FindElementAt(Vector2I windowPos)
  331. {
  332. Vector2I scrollPos = WindowToScrollAreaCoords(windowPos);
  333. foreach (var element in entries)
  334. {
  335. if (element.bounds.Contains(scrollPos))
  336. return element;
  337. }
  338. return null;
  339. }
  340. private ElementEntry[] FindElementsOverlapping(Rect2I scrollBounds)
  341. {
  342. List<ElementEntry> elements = new List<ElementEntry>();
  343. foreach (var element in entries)
  344. {
  345. if(element.Bounds.Overlaps(scrollBounds))
  346. elements.Add(element);
  347. }
  348. return elements.ToArray();
  349. }
  350. private void DoOnDragStart(Vector2I windowPos)
  351. {
  352. ElementEntry underCursorElem = FindElementAt(windowPos);
  353. if (underCursorElem == null || !selectionPaths.Contains(underCursorElem.path))
  354. {
  355. StartDragSelection(windowPos);
  356. return;
  357. }
  358. ResourceDragDropData dragDropData = new ResourceDragDropData(selectionPaths.ToArray());
  359. DragDrop.StartDrag(dragDropData);
  360. }
  361. private void DoOnDragMove(Vector2I windowPos)
  362. {
  363. // Auto-scroll
  364. Rect2I scrollAreaBounds = contentScrollArea.Bounds;
  365. int scrollAreaTop = scrollAreaBounds.y;
  366. int scrollAreaBottom = scrollAreaBounds.y + scrollAreaBounds.height;
  367. if (windowPos.y > scrollAreaTop && windowPos.y <= (scrollAreaTop + DRAG_SCROLL_HEIGHT))
  368. autoScrollAmount = -DRAG_SCROLL_AMOUNT_PER_SECOND;
  369. else if (windowPos.y >= (scrollAreaBottom - DRAG_SCROLL_HEIGHT) && windowPos.y < scrollAreaBottom)
  370. autoScrollAmount = DRAG_SCROLL_AMOUNT_PER_SECOND;
  371. else
  372. autoScrollAmount = 0;
  373. // Selection box
  374. if (UpdateDragSelection(windowPos))
  375. return;
  376. // Drag and drop (hover element under cursor)
  377. ElementEntry underCursorElem = FindElementAt(windowPos);
  378. if (underCursorElem == null)
  379. {
  380. ClearHoverHighlight();
  381. }
  382. else
  383. {
  384. if (underCursorElem.path != hoverHighlightPath)
  385. {
  386. ClearHoverHighlight();
  387. hoverHighlightPath = underCursorElem.path;
  388. underCursorElem.MarkAsHovered(true);
  389. }
  390. }
  391. }
  392. private void DoOnDragLeave()
  393. {
  394. ClearHoverHighlight();
  395. autoScrollAmount = 0;
  396. }
  397. private void DoOnDragDropped(Vector2I windowPos, string[] paths)
  398. {
  399. ClearHoverHighlight();
  400. autoScrollAmount = 0;
  401. if (EndDragSelection())
  402. return;
  403. string resourceDir = ProjectLibrary.ResourceFolder;
  404. string destinationFolder = Path.Combine(resourceDir, currentDirectory);
  405. ElementEntry underCursorElement = FindElementAt(windowPos);
  406. if (underCursorElement != null)
  407. {
  408. LibraryEntry entry = ProjectLibrary.GetEntry(underCursorElement.path);
  409. if (entry != null && entry.Type == LibraryEntryType.Directory)
  410. destinationFolder = Path.Combine(resourceDir, entry.Path);
  411. }
  412. if (paths != null)
  413. {
  414. foreach (var path in paths)
  415. {
  416. if (path == null)
  417. continue;
  418. string absolutePath = path;
  419. if (!Path.IsPathRooted(absolutePath))
  420. absolutePath = Path.Combine(resourceDir, path);
  421. if (string.IsNullOrEmpty(absolutePath))
  422. continue;
  423. if (PathEx.IsPartOf(destinationFolder, absolutePath) || PathEx.Compare(absolutePath, destinationFolder))
  424. continue;
  425. string destination = Path.Combine(destinationFolder, Path.GetFileName(absolutePath));
  426. if (ProjectLibrary.Exists(path))
  427. ProjectLibrary.Move(path, destination, true);
  428. else
  429. ProjectLibrary.Copy(path, destination, true);
  430. }
  431. }
  432. }
  433. private void DoOnDragEnd(Vector2I windowPos)
  434. {
  435. EndDragSelection();
  436. }
  437. private void ClearHoverHighlight()
  438. {
  439. if (!string.IsNullOrEmpty(hoverHighlightPath))
  440. {
  441. ElementEntry previousUnderCursorElem;
  442. if (entryLookup.TryGetValue(hoverHighlightPath, out previousUnderCursorElem))
  443. previousUnderCursorElem.MarkAsHovered(false);
  444. }
  445. hoverHighlightPath = "";
  446. }
  447. public void Ping(Resource resource)
  448. {
  449. if (!string.IsNullOrEmpty(pingPath))
  450. {
  451. ElementEntry entry;
  452. if (entryLookup.TryGetValue(pingPath, out entry))
  453. entry.MarkAsPinged(false);
  454. }
  455. if (resource != null)
  456. pingPath = ProjectLibrary.GetPath(resource);
  457. else
  458. pingPath = "";
  459. if (!string.IsNullOrEmpty(pingPath))
  460. {
  461. ElementEntry entry;
  462. if (entryLookup.TryGetValue(pingPath, out entry))
  463. entry.MarkAsPinged(true);
  464. ScrollToEntry(pingPath);
  465. }
  466. }
  467. private void DeselectAll()
  468. {
  469. SetSelection(new List<string>());
  470. selectionAnchorStart = -1;
  471. selectionAnchorEnd = -1;
  472. }
  473. private void Select(string path)
  474. {
  475. ElementEntry entry;
  476. if (!entryLookup.TryGetValue(path, out entry))
  477. return;
  478. bool ctrlDown = Input.IsButtonHeld(ButtonCode.LeftControl) || Input.IsButtonHeld(ButtonCode.RightControl);
  479. bool shiftDown = Input.IsButtonHeld(ButtonCode.LeftShift) || Input.IsButtonHeld(ButtonCode.RightShift);
  480. if (shiftDown)
  481. {
  482. if (selectionAnchorStart != -1 && selectionAnchorStart < entries.Count)
  483. {
  484. int start = Math.Min(entry.index, selectionAnchorStart);
  485. int end = Math.Max(entry.index, selectionAnchorStart);
  486. List<string> newSelection = new List<string>();
  487. for(int i = start; i <= end; i++)
  488. newSelection.Add(entries[i].path);
  489. SetSelection(newSelection);
  490. selectionAnchorEnd = entry.index;
  491. }
  492. else
  493. {
  494. SetSelection(new List<string>() {path});
  495. selectionAnchorStart = entry.index;
  496. selectionAnchorEnd = entry.index;
  497. }
  498. }
  499. else if (ctrlDown)
  500. {
  501. List<string> newSelection = new List<string>(selectionPaths);
  502. if (selectionPaths.Contains(path))
  503. {
  504. newSelection.Remove(path);
  505. if (newSelection.Count == 0)
  506. DeselectAll();
  507. else
  508. {
  509. if (selectionAnchorStart == entry.index)
  510. {
  511. ElementEntry newAnchorEntry;
  512. if (!entryLookup.TryGetValue(newSelection[0], out newAnchorEntry))
  513. selectionAnchorStart = -1;
  514. else
  515. selectionAnchorStart = newAnchorEntry.index;
  516. }
  517. if (selectionAnchorEnd == entry.index)
  518. {
  519. ElementEntry newAnchorEntry;
  520. if (!entryLookup.TryGetValue(newSelection[newSelection.Count - 1], out newAnchorEntry))
  521. selectionAnchorEnd = -1;
  522. else
  523. selectionAnchorEnd = newAnchorEntry.index;
  524. }
  525. SetSelection(newSelection);
  526. }
  527. }
  528. else
  529. {
  530. newSelection.Add(path);
  531. SetSelection(newSelection);
  532. selectionAnchorEnd = entry.index;
  533. }
  534. }
  535. else
  536. {
  537. SetSelection(new List<string>() { path });
  538. selectionAnchorStart = entry.index;
  539. selectionAnchorEnd = entry.index;
  540. }
  541. }
  542. private void MoveSelection(MoveDirection dir)
  543. {
  544. string newPath = "";
  545. if (selectionPaths.Count == 0 || selectionAnchorEnd == -1)
  546. {
  547. // Nothing is selected so we arbitrarily select first or last element
  548. if (entries.Count > 0)
  549. {
  550. switch (dir)
  551. {
  552. case MoveDirection.Left:
  553. case MoveDirection.Up:
  554. newPath = entries[entries.Count - 1].path;
  555. break;
  556. case MoveDirection.Right:
  557. case MoveDirection.Down:
  558. newPath = entries[0].path;
  559. break;
  560. }
  561. }
  562. }
  563. else
  564. {
  565. switch (dir)
  566. {
  567. case MoveDirection.Left:
  568. if (selectionAnchorEnd - 1 >= 0)
  569. newPath = entries[selectionAnchorEnd - 1].path;
  570. break;
  571. case MoveDirection.Up:
  572. if (selectionAnchorEnd - contentInfo.elementsPerRow >= 0)
  573. newPath = entries[selectionAnchorEnd - contentInfo.elementsPerRow].path;
  574. break;
  575. case MoveDirection.Right:
  576. if (selectionAnchorEnd + 1 < entries.Count)
  577. newPath = entries[selectionAnchorEnd + 1].path;
  578. break;
  579. case MoveDirection.Down:
  580. if (selectionAnchorEnd + contentInfo.elementsPerRow < entries.Count)
  581. newPath = entries[selectionAnchorEnd + contentInfo.elementsPerRow].path;
  582. break;
  583. }
  584. }
  585. if (!string.IsNullOrEmpty(newPath))
  586. {
  587. Select(newPath);
  588. ScrollToEntry(newPath);
  589. }
  590. }
  591. private void SetSelection(List<string> paths)
  592. {
  593. if (selectionPaths != null)
  594. {
  595. foreach (var path in selectionPaths)
  596. {
  597. ElementEntry entry;
  598. if (entryLookup.TryGetValue(path, out entry))
  599. entry.MarkAsSelected(false);
  600. }
  601. }
  602. selectionPaths = paths;
  603. if (selectionPaths != null)
  604. {
  605. foreach (var path in selectionPaths)
  606. {
  607. ElementEntry entry;
  608. if (entryLookup.TryGetValue(path, out entry))
  609. entry.MarkAsSelected(true);
  610. }
  611. }
  612. Ping(null);
  613. if (selectionPaths != null)
  614. Selection.resourcePaths = selectionPaths.ToArray();
  615. else
  616. Selection.resourcePaths = new string[0];
  617. }
  618. private void EnterDirectory(string directory)
  619. {
  620. currentDirectory = directory;
  621. DeselectAll();
  622. Refresh();
  623. }
  624. private void Cut(IEnumerable<string> sourcePaths)
  625. {
  626. foreach (var path in cutPaths)
  627. {
  628. ElementEntry entry;
  629. if (entryLookup.TryGetValue(path, out entry))
  630. entry.MarkAsCut(false);
  631. }
  632. cutPaths.Clear();
  633. cutPaths.AddRange(sourcePaths);
  634. foreach (var path in cutPaths)
  635. {
  636. ElementEntry entry;
  637. if (entryLookup.TryGetValue(path, out entry))
  638. entry.MarkAsCut(true);
  639. }
  640. copyPaths.Clear();
  641. }
  642. private void Copy(IEnumerable<string> sourcePaths)
  643. {
  644. copyPaths.Clear();
  645. copyPaths.AddRange(sourcePaths);
  646. foreach (var path in cutPaths)
  647. {
  648. ElementEntry entry;
  649. if (entryLookup.TryGetValue(path, out entry))
  650. entry.MarkAsCut(false);
  651. }
  652. cutPaths.Clear();
  653. }
  654. private void Duplicate(IEnumerable<string> sourcePaths)
  655. {
  656. foreach (var source in sourcePaths)
  657. {
  658. int idx = 0;
  659. string destination;
  660. do
  661. {
  662. destination = source + "_" + idx;
  663. idx++;
  664. } while (!ProjectLibrary.Exists(destination));
  665. ProjectLibrary.Copy(source, destination);
  666. }
  667. }
  668. private void Paste(string destinationFolder)
  669. {
  670. if (copyPaths.Count > 0)
  671. {
  672. for (int i = 0; i < copyPaths.Count; i++)
  673. {
  674. string cleanPath = copyPaths[i].TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
  675. string destination = Path.Combine(destinationFolder, Path.GetFileName(cleanPath));
  676. ProjectLibrary.Copy(copyPaths[i], destination, true);
  677. }
  678. Refresh();
  679. }
  680. else if (cutPaths.Count > 0)
  681. {
  682. for (int i = 0; i < cutPaths.Count; i++)
  683. {
  684. string cleanPath = cutPaths[i].TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
  685. string destination = Path.Combine(destinationFolder, Path.GetFileName(cleanPath));
  686. ProjectLibrary.Move(cutPaths[i], destination, true);
  687. }
  688. cutPaths.Clear();
  689. Refresh();
  690. }
  691. }
  692. private void EditorUpdate()
  693. {
  694. if (HasContentFocus)
  695. {
  696. if (Input.IsButtonHeld(ButtonCode.LeftControl) || Input.IsButtonHeld(ButtonCode.RightControl))
  697. {
  698. if (Input.IsButtonUp(ButtonCode.C))
  699. {
  700. CopySelection();
  701. }
  702. else if (Input.IsButtonUp(ButtonCode.X))
  703. {
  704. CutSelection();
  705. }
  706. else if (Input.IsButtonUp(ButtonCode.D))
  707. {
  708. DuplicateSelection();
  709. }
  710. else if (Input.IsButtonUp(ButtonCode.V))
  711. {
  712. PasteToSelection();
  713. }
  714. }
  715. if (Input.IsButtonDown(ButtonCode.Return))
  716. {
  717. if (selectionPaths.Count == 1)
  718. {
  719. LibraryEntry entry = ProjectLibrary.GetEntry(selectionPaths[0]);
  720. if (entry != null && entry.Type == LibraryEntryType.Directory)
  721. {
  722. EnterDirectory(entry.Path);
  723. }
  724. }
  725. }
  726. else if (Input.IsButtonDown(ButtonCode.Back))
  727. {
  728. LibraryEntry entry = ProjectLibrary.GetEntry(currentDirectory);
  729. if (entry != null && entry.Parent != null)
  730. {
  731. EnterDirectory(entry.Parent.Path);
  732. }
  733. }
  734. else if (Input.IsButtonDown(ButtonCode.Up))
  735. {
  736. MoveSelection(MoveDirection.Up);
  737. }
  738. else if (Input.IsButtonDown(ButtonCode.Down))
  739. {
  740. MoveSelection(MoveDirection.Down);
  741. }
  742. else if (Input.IsButtonDown(ButtonCode.Left))
  743. {
  744. MoveSelection(MoveDirection.Left);
  745. }
  746. else if (Input.IsButtonDown(ButtonCode.Right))
  747. {
  748. MoveSelection(MoveDirection.Right);
  749. }
  750. }
  751. if (autoScrollAmount != 0)
  752. {
  753. Rect2I contentBounds = contentScrollArea.ContentBounds;
  754. float scrollPct = autoScrollAmount / (float)contentBounds.height;
  755. contentScrollArea.VerticalScroll += scrollPct * Time.FrameDelta;
  756. }
  757. dropTarget.Update();
  758. }
  759. private void OnEntryChanged(string entry)
  760. {
  761. Refresh();
  762. }
  763. private void ScrollToEntry(string path)
  764. {
  765. ElementEntry entryGUI;
  766. if (!entryLookup.TryGetValue(path, out entryGUI))
  767. return;
  768. Rect2I entryBounds = entryGUI.Bounds;
  769. Rect2I contentBounds = contentScrollArea.Layout.Bounds;
  770. Rect2I windowEntryBounds = entryBounds;
  771. windowEntryBounds.x += contentBounds.x;
  772. windowEntryBounds.y += contentBounds.y;
  773. Rect2I scrollAreaBounds = contentScrollArea.Bounds;
  774. bool requiresScroll = windowEntryBounds.y < scrollAreaBounds.y ||
  775. (windowEntryBounds.y + windowEntryBounds.height) > (scrollAreaBounds.y + scrollAreaBounds.height);
  776. if (!requiresScroll)
  777. return;
  778. int scrollableSize = contentBounds.height - scrollAreaBounds.height;
  779. float percent = (((entryBounds.y + entryBounds.height * 0.5f) - scrollAreaBounds.height * 0.5f) / (float)scrollableSize);
  780. percent = MathEx.Clamp01(percent);
  781. contentScrollArea.VerticalScroll = percent;
  782. }
  783. private void Refresh()
  784. {
  785. LibraryEntry[] entriesToDisplay = new LibraryEntry[0];
  786. if (IsSearchActive)
  787. {
  788. entriesToDisplay = ProjectLibrary.Search("*" + searchQuery + "*");
  789. }
  790. else
  791. {
  792. DirectoryEntry entry = ProjectLibrary.GetEntry(currentDirectory) as DirectoryEntry;
  793. if (entry == null)
  794. {
  795. currentDirectory = ProjectLibrary.Root.Path;
  796. entry = ProjectLibrary.GetEntry(currentDirectory) as DirectoryEntry;
  797. }
  798. if(entry != null)
  799. entriesToDisplay = entry.Children;
  800. }
  801. if (scrollAreaPanel != null)
  802. scrollAreaPanel.Destroy();
  803. entries.Clear();
  804. entryLookup.Clear();
  805. scrollAreaPanel = contentScrollArea.Layout.AddPanel();
  806. RefreshDirectoryBar();
  807. SortEntries(entriesToDisplay);
  808. if (entriesToDisplay.Length == 0)
  809. return;
  810. contentInfo = new ContentInfo(this, viewType, entriesToDisplay.Length);
  811. if (viewType == ProjectViewType.List16)
  812. {
  813. for (int i = 0; i < entriesToDisplay.Length; i++)
  814. {
  815. ElementEntry guiEntry = new ElementEntry(contentInfo, contentInfo.main, entriesToDisplay[i], i);
  816. entries.Add(guiEntry);
  817. entryLookup[guiEntry.path] = guiEntry;
  818. if (i != entriesToDisplay.Length - 1)
  819. contentInfo.main.AddSpace(LIST_ENTRY_SPACING);
  820. }
  821. contentInfo.main.AddFlexibleSpace();
  822. }
  823. else
  824. {
  825. int tileSize = 64;
  826. switch (viewType)
  827. {
  828. case ProjectViewType.Grid64: tileSize = 64; break;
  829. case ProjectViewType.Grid48: tileSize = 48; break;
  830. case ProjectViewType.Grid32: tileSize = 32; break;
  831. }
  832. contentInfo.main.AddSpace(GRID_ENTRY_SPACING / 2);
  833. GUILayoutX rowLayout = contentInfo.main.AddLayoutX();
  834. contentInfo.main.AddSpace(GRID_ENTRY_SPACING);
  835. rowLayout.AddFlexibleSpace();
  836. int elemsInRow = 0;
  837. for (int i = 0; i < entriesToDisplay.Length; i++)
  838. {
  839. if (elemsInRow == contentInfo.elementsPerRow && elemsInRow > 0)
  840. {
  841. rowLayout = contentInfo.main.AddLayoutX();
  842. contentInfo.main.AddSpace(GRID_ENTRY_SPACING);
  843. rowLayout.AddFlexibleSpace();
  844. elemsInRow = 0;
  845. }
  846. ElementEntry guiEntry = new ElementEntry(contentInfo, rowLayout, entriesToDisplay[i], i);
  847. entries.Add(guiEntry);
  848. entryLookup[guiEntry.path] = guiEntry;
  849. rowLayout.AddFlexibleSpace();
  850. elemsInRow++;
  851. }
  852. int extraElements = contentInfo.elementsPerRow - elemsInRow;
  853. for (int i = 0; i < extraElements; i++)
  854. {
  855. rowLayout.AddSpace(contentInfo.labelWidth);
  856. rowLayout.AddFlexibleSpace();
  857. }
  858. contentInfo.main.AddFlexibleSpace();
  859. }
  860. for (int i = 0; i < entries.Count; i++)
  861. {
  862. ElementEntry guiEntry = entries[i];
  863. guiEntry.Initialize();
  864. if (cutPaths.Contains(guiEntry.path))
  865. guiEntry.MarkAsCut(true);
  866. if (selectionPaths.Contains(guiEntry.path))
  867. guiEntry.MarkAsSelected(true);
  868. else if (pingPath == guiEntry.path)
  869. guiEntry.MarkAsPinged(true);
  870. }
  871. Rect2I contentBounds = contentInfo.main.Bounds;
  872. Rect2I minimalBounds = GetScrollAreaBounds();
  873. contentBounds.height = Math.Max(contentBounds.height, minimalBounds.height);
  874. GUIButton catchAll = new GUIButton("", EditorStyles.Blank);
  875. catchAll.Bounds = contentBounds;
  876. catchAll.OnClick += OnCatchAllClicked;
  877. catchAll.SetContextMenu(entryContextMenu);
  878. contentInfo.underlay.AddElement(catchAll);
  879. Rect2I focusBounds = contentBounds; // Contents + Folder bar
  880. Rect2I scrollBounds = contentScrollArea.Bounds;
  881. focusBounds.x += scrollBounds.x;
  882. focusBounds.y += scrollBounds.y;
  883. Rect2I folderBarBounds = folderListLayout.Bounds;
  884. focusBounds.y -= folderBarBounds.height;
  885. focusBounds.height += folderBarBounds.height;
  886. GUIButton focusCatcher = new GUIButton("", EditorStyles.Blank);
  887. focusCatcher.OnFocusChanged += OnContentsFocusChanged;
  888. focusCatcher.Bounds = focusBounds;
  889. GUIPanel focusPanel = GUI.AddPanel(3);
  890. focusPanel.AddElement(focusCatcher);
  891. UpdateDragSelection(dragSelectionEnd);
  892. }
  893. private Vector2I WindowToScrollAreaCoords(Vector2I windowPos)
  894. {
  895. Rect2I scrollBounds = contentScrollArea.Layout.Bounds;
  896. Vector2I scrollPos = windowPos;
  897. scrollPos.x -= scrollBounds.x;
  898. scrollPos.y -= scrollBounds.y;
  899. return scrollPos;
  900. }
  901. private void StartDragSelection(Vector2I windowPos)
  902. {
  903. isDraggingSelection = true;
  904. dragSelectionStart = WindowToScrollAreaCoords(windowPos);
  905. dragSelectionEnd = dragSelectionStart;
  906. }
  907. private bool UpdateDragSelection(Vector2I windowPos)
  908. {
  909. if (!isDraggingSelection)
  910. return false;
  911. if (dragSelection == null)
  912. {
  913. dragSelection = new GUITexture(null, true, EditorStyles.SelectionArea);
  914. contentInfo.overlay.AddElement(dragSelection);
  915. }
  916. dragSelectionEnd = WindowToScrollAreaCoords(windowPos);
  917. Rect2I selectionArea = CalculateSelectionArea();
  918. SelectInArea(selectionArea);
  919. dragSelection.Bounds = selectionArea;
  920. return true;
  921. }
  922. private bool EndDragSelection()
  923. {
  924. if (!isDraggingSelection)
  925. return false;
  926. if (dragSelection != null)
  927. {
  928. dragSelection.Destroy();
  929. dragSelection = null;
  930. }
  931. Rect2I selectionArea = CalculateSelectionArea();
  932. SelectInArea(selectionArea);
  933. isDraggingSelection = false;
  934. return false;
  935. }
  936. private Rect2I CalculateSelectionArea()
  937. {
  938. Rect2I selectionArea = new Rect2I();
  939. if (dragSelectionStart.x < dragSelectionEnd.x)
  940. {
  941. selectionArea.x = dragSelectionStart.x;
  942. selectionArea.width = dragSelectionEnd.x - dragSelectionStart.x;
  943. }
  944. else
  945. {
  946. selectionArea.x = dragSelectionEnd.x;
  947. selectionArea.width = dragSelectionStart.x - dragSelectionEnd.x;
  948. }
  949. if (dragSelectionStart.y < dragSelectionEnd.y)
  950. {
  951. selectionArea.y = dragSelectionStart.y;
  952. selectionArea.height = dragSelectionEnd.y - dragSelectionStart.y;
  953. }
  954. else
  955. {
  956. selectionArea.y = dragSelectionEnd.y;
  957. selectionArea.height = dragSelectionStart.y - dragSelectionEnd.y;
  958. }
  959. return selectionArea;
  960. }
  961. private void SelectInArea(Rect2I scrollBounds)
  962. {
  963. ElementEntry[] foundElements = FindElementsOverlapping(scrollBounds);
  964. if (foundElements.Length > 0)
  965. {
  966. selectionAnchorStart = foundElements[0].index;
  967. selectionAnchorEnd = foundElements[foundElements.Length - 1].index;
  968. }
  969. else
  970. {
  971. selectionAnchorStart = -1;
  972. selectionAnchorEnd = -1;
  973. }
  974. List<string> elementPaths = new List<string>();
  975. foreach (var elem in foundElements)
  976. elementPaths.Add(elem.path);
  977. SetSelection(elementPaths);
  978. }
  979. private void RefreshDirectoryBar()
  980. {
  981. if (folderListLayout != null)
  982. {
  983. folderListLayout.Destroy();
  984. folderListLayout = null;
  985. }
  986. folderListLayout = folderBarLayout.AddLayoutX();
  987. string[] folders = null;
  988. string[] fullPaths = null;
  989. if (IsSearchActive)
  990. {
  991. folders = new[] {searchQuery};
  992. fullPaths = new[] { searchQuery };
  993. }
  994. else
  995. {
  996. string currentDir = Path.Combine("Resources", currentDirectory);
  997. folders = currentDir.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar },
  998. StringSplitOptions.RemoveEmptyEntries);
  999. fullPaths = new string[folders.Length];
  1000. for (int i = 0; i < folders.Length; i++)
  1001. {
  1002. if (i == 0)
  1003. fullPaths[i] = "";
  1004. else
  1005. fullPaths[i] = Path.Combine(fullPaths[i - 1], folders[i]);
  1006. }
  1007. }
  1008. int availableWidth = folderBarLayout.Bounds.width - FOLDER_BUTTON_WIDTH * 2;
  1009. int numFolders = 0;
  1010. for (int i = folders.Length - 1; i >= 0; i--)
  1011. {
  1012. GUIButton folderButton = new GUIButton(folders[i]);
  1013. if (!IsSearchActive)
  1014. {
  1015. string fullPath = fullPaths[i];
  1016. folderButton.OnClick += () => OnFolderButtonClicked(fullPath);
  1017. }
  1018. GUILabel separator = new GUILabel("/", GUIOption.FixedWidth(FOLDER_SEPARATOR_WIDTH));
  1019. folderListLayout.InsertElement(0, separator);
  1020. folderListLayout.InsertElement(0, folderButton);
  1021. numFolders++;
  1022. Rect2I folderListBounds = folderListLayout.Bounds;
  1023. if (folderListBounds.width > availableWidth)
  1024. {
  1025. if (numFolders > 2)
  1026. {
  1027. separator.Destroy();
  1028. folderButton.Destroy();
  1029. break;
  1030. }
  1031. }
  1032. }
  1033. }
  1034. private void SortEntries(LibraryEntry[] input)
  1035. {
  1036. Array.Sort(input, (x, y) =>
  1037. {
  1038. if (x.Type == y.Type)
  1039. return x.Name.CompareTo(y.Name);
  1040. else
  1041. return x.Type == LibraryEntryType.File ? 1 : -1;
  1042. });
  1043. }
  1044. private void OnFolderButtonClicked(string path)
  1045. {
  1046. EnterDirectory(path);
  1047. }
  1048. private void OnContentsFocusChanged(bool focus)
  1049. {
  1050. hasContentFocus = focus;
  1051. }
  1052. private void OnEntryClicked(string path)
  1053. {
  1054. Select(path);
  1055. }
  1056. private void OnEntryDoubleClicked(string path)
  1057. {
  1058. LibraryEntry entry = ProjectLibrary.GetEntry(path);
  1059. if (entry != null && entry.Type == LibraryEntryType.Directory)
  1060. {
  1061. EnterDirectory(path);
  1062. }
  1063. }
  1064. private void OnCatchAllClicked()
  1065. {
  1066. DeselectAll();
  1067. }
  1068. private void OnHomeClicked()
  1069. {
  1070. currentDirectory = ProjectLibrary.Root.Path;
  1071. Refresh();
  1072. }
  1073. private void OnUpClicked()
  1074. {
  1075. currentDirectory = currentDirectory.Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
  1076. if (!string.IsNullOrEmpty(currentDirectory))
  1077. {
  1078. string parent = Path.GetDirectoryName(currentDirectory);
  1079. currentDirectory = parent;
  1080. Refresh();
  1081. }
  1082. }
  1083. private void CutSelection()
  1084. {
  1085. if (selectionPaths.Count > 0)
  1086. Cut(selectionPaths);
  1087. }
  1088. private void CopySelection()
  1089. {
  1090. if (selectionPaths.Count > 0)
  1091. Copy(selectionPaths);
  1092. }
  1093. private void DuplicateSelection()
  1094. {
  1095. if (selectionPaths.Count > 0)
  1096. Duplicate(selectionPaths);
  1097. }
  1098. private void PasteToSelection()
  1099. {
  1100. DirectoryEntry selectedDirectory = null;
  1101. if (selectionPaths.Count == 1)
  1102. {
  1103. LibraryEntry entry = ProjectLibrary.GetEntry(selectionPaths[0]);
  1104. if (entry != null && entry.Type == LibraryEntryType.Directory)
  1105. selectedDirectory = (DirectoryEntry) entry;
  1106. }
  1107. if(selectedDirectory != null)
  1108. Paste(selectedDirectory.Path);
  1109. else
  1110. Paste(currentDirectory);
  1111. }
  1112. private void OnSearchChanged(string newValue)
  1113. {
  1114. searchQuery = newValue;
  1115. Refresh();
  1116. }
  1117. private void ClearSearch()
  1118. {
  1119. searchField.Value = "";
  1120. searchQuery = "";
  1121. Refresh();
  1122. }
  1123. private void OpenOptionsWindow()
  1124. {
  1125. Vector2I openPosition;
  1126. Rect2I buttonBounds = GUILayoutUtility.CalculateBounds(optionsButton, GUI);
  1127. openPosition.x = buttonBounds.x + buttonBounds.width / 2;
  1128. openPosition.y = buttonBounds.y + buttonBounds.height / 2;
  1129. ProjectDropDown dropDown = DropDownWindow.Open<ProjectDropDown>(this, openPosition);
  1130. dropDown.SetParent(this);
  1131. }
  1132. private void Reset()
  1133. {
  1134. currentDirectory = ProjectLibrary.Root.Path;
  1135. selectionAnchorStart = -1;
  1136. selectionAnchorEnd = -1;
  1137. selectionPaths.Clear();
  1138. pingPath = "";
  1139. hoverHighlightPath = "";
  1140. Refresh();
  1141. }
  1142. private Rect2I GetScrollAreaBounds()
  1143. {
  1144. Rect2I bounds = GUI.Bounds;
  1145. Rect2I folderListBounds = folderListLayout.Bounds;
  1146. Rect2I searchBarBounds = searchBarLayout.Bounds;
  1147. bounds.y += folderListBounds.height + searchBarBounds.height;
  1148. bounds.height -= folderListBounds.height + searchBarBounds.height;
  1149. return bounds;
  1150. }
  1151. protected override void WindowResized(int width, int height)
  1152. {
  1153. base.WindowResized(width, height);
  1154. Refresh();
  1155. dropTarget.Bounds = contentScrollArea.Bounds;
  1156. }
  1157. }
  1158. internal class ProjectDropDown : DropDownWindow
  1159. {
  1160. private ProjectWindow parent;
  1161. public ProjectDropDown()
  1162. :base(150, 30)
  1163. { }
  1164. internal void SetParent(ProjectWindow parent)
  1165. {
  1166. this.parent = parent;
  1167. GUIToggleGroup group = new GUIToggleGroup();
  1168. GUIToggle list16 = new GUIToggle("16", group, EditorStyles.Button, GUIOption.FixedWidth(30));
  1169. GUIToggle grid32 = new GUIToggle("32", group, EditorStyles.Button, GUIOption.FixedWidth(30));
  1170. GUIToggle grid48 = new GUIToggle("48", group, EditorStyles.Button, GUIOption.FixedWidth(30));
  1171. GUIToggle grid64 = new GUIToggle("64", group, EditorStyles.Button, GUIOption.FixedWidth(30));
  1172. ProjectViewType activeType = parent.ViewType;
  1173. switch (activeType)
  1174. {
  1175. case ProjectViewType.List16:
  1176. list16.ToggleOn();
  1177. break;
  1178. case ProjectViewType.Grid32:
  1179. grid32.ToggleOn();
  1180. break;
  1181. case ProjectViewType.Grid48:
  1182. grid48.ToggleOn();
  1183. break;
  1184. case ProjectViewType.Grid64:
  1185. grid64.ToggleOn();
  1186. break;
  1187. }
  1188. list16.OnToggled += (active) =>
  1189. {
  1190. if (active)
  1191. ChangeViewType(ProjectViewType.List16);
  1192. };
  1193. grid32.OnToggled += (active) =>
  1194. {
  1195. if (active)
  1196. ChangeViewType(ProjectViewType.Grid32);
  1197. };
  1198. grid48.OnToggled += (active) =>
  1199. {
  1200. if (active)
  1201. ChangeViewType(ProjectViewType.Grid48);
  1202. };
  1203. grid64.OnToggled += (active) =>
  1204. {
  1205. if (active)
  1206. ChangeViewType(ProjectViewType.Grid64);
  1207. };
  1208. GUILayoutY vertLayout = GUI.AddLayoutY();
  1209. vertLayout.AddFlexibleSpace();
  1210. GUILayoutX contentLayout = vertLayout.AddLayoutX();
  1211. contentLayout.AddFlexibleSpace();
  1212. contentLayout.AddElement(list16);
  1213. contentLayout.AddElement(grid32);
  1214. contentLayout.AddElement(grid48);
  1215. contentLayout.AddElement(grid64);
  1216. contentLayout.AddFlexibleSpace();
  1217. vertLayout.AddFlexibleSpace();
  1218. }
  1219. private void ChangeViewType(ProjectViewType viewType)
  1220. {
  1221. parent.ViewType = viewType;
  1222. }
  1223. }
  1224. }