Skip to content

Commit 63ea2d3

Browse files
Merge pull request #186 from ZeppelinGames/feature/projectcontextmenu
Added project list context menu.
2 parents d21ae30 + 79dabc7 commit 63ea2d3

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

Prowl.Editor/Editor/ProjectsWindow.cs

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using Prowl.Editor.Preferences;
1+
using Prowl.Editor.Assets;
2+
using Prowl.Editor.Preferences;
23
using Prowl.Icons;
34
using Prowl.Runtime;
45
using Prowl.Runtime.GUI;
56
using Prowl.Runtime.GUI.Graphics;
7+
using Prowl.Runtime.GUI.Layout;
68

79
namespace Prowl.Editor
810
{
@@ -73,9 +75,16 @@ private void DrawProjectsTab()
7375
var folders = new DirectoryInfo(Project.Projects_Directory).EnumerateDirectories();
7476
folders = folders.OrderByDescending((x) => x.LastWriteTimeUtc);
7577

76-
foreach (var projectFolder in folders)
77-
if (string.IsNullOrEmpty(_searchText) || projectFolder.Name.Contains(_searchText, StringComparison.OrdinalIgnoreCase))
78-
DisplayProject(projectFolder.Name);
78+
if (folders.Count() == 0)
79+
{
80+
gui.Draw2D.DrawText("No projects found! Navigate to the 'Create' tab to start a new project", rect);
81+
}
82+
else
83+
{
84+
foreach (var projectFolder in folders)
85+
if (string.IsNullOrEmpty(_searchText) || projectFolder.Name.Contains(_searchText, StringComparison.OrdinalIgnoreCase))
86+
DisplayProject(projectFolder.Name);
87+
}
7988
}
8089

8190
using (gui.Node("OpenBtn").TopLeft(Offset.Percentage(1f, -162), Offset.Percentage(1f, -60)).Scale(162, 60).Enter())
@@ -101,6 +110,8 @@ private void DrawProjectsTab()
101110
}
102111
}
103112
}
113+
114+
string? contextMenuProject = null;
104115
private void DisplayProject(string name)
105116
{
106117
var proj = Project.GetPath(name);
@@ -123,14 +134,63 @@ private void DisplayProject(string name)
123134
gui.Draw2D.DrawRect(gui.CurrentNode.LayoutData.Rect, new(0.7f, 0.7f, 0.7f, 1f), 1, 2);
124135
}
125136
else if (interact.IsHovered())
137+
{
126138
gui.Draw2D.DrawRectFilled(gui.CurrentNode.LayoutData.Rect, new(0.1f, 0.1f, 0.1f, 0.4f), 2);
139+
}
140+
141+
using (gui.Node("ProjectOptionsBtn").Top(new Offset(8, LayoutValueType.Pixel)).Left(new Offset(rect.width - 32, LayoutValueType.Pixel)).Height(24).Width(24).Enter())
142+
{
143+
rect = gui.CurrentNode.LayoutData.Rect;
144+
if (gui.IsNodePressed())
145+
{
146+
// Got to be a better way than doing this
147+
contextMenuProject = name;
148+
gui.OpenPopup("ProjectOptionsContextMenu", null, gui.CurrentNode.Parent);
149+
}
150+
else if (gui.IsNodeHovered())
151+
{
152+
gui.Draw2D.DrawRectFilled(rect, new(0.1f, 0.1f, 0.1f, 1f), 2);
153+
}
154+
155+
// Text centering/alignment functions?
156+
UIDrawList.DefaultFont.CalcTextSizeA(out Vector2 textSize, 20, rect.width, rect.width, "...", 0);
157+
gui.Draw2D.DrawText(UIDrawList.DefaultFont, "...", 20, rect.Position + new Vector2(textSize.x * 0.5f, 0), Color.white);
158+
}
159+
160+
// Outside ProjectOptionsBtn node as it wouldn't render (or too small in size?)
161+
if (contextMenuProject != null && contextMenuProject.Equals(name))
162+
{
163+
DrawProjectContextMenu(proj);
164+
}
127165
//else if (interact.IsDoubleClicked())
128166
//{
129167
// Project.Open(name);
130168
// isOpened = false;
131169
//}
132170
}
171+
}
133172

173+
private void DrawProjectContextMenu(DirectoryInfo proj)
174+
{
175+
bool closePopup = false;
176+
if (gui.BeginPopup("ProjectOptionsContextMenu", out var popupHolder) && popupHolder != null)
177+
{
178+
using (popupHolder.Width(180).Padding(5).Layout(LayoutType.Column).Spacing(5).FitContentHeight().Enter())
179+
{
180+
// Add options
181+
// - Delete project (with popup confirmation)
182+
if (EditorGUI.StyledButton("Show In Explorer"))
183+
{
184+
AssetDatabase.OpenPath(proj);
185+
closePopup = true;
186+
}
187+
}
188+
}
189+
if (closePopup)
190+
{
191+
contextMenuProject = null;
192+
gui.ClosePopup(popupHolder);
193+
}
134194
}
135195

136196
private string GetFormattedLastModifiedTime(DateTime lastModified)

Prowl.Runtime/Application.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public static void Run(string title, int width, int height, IAssetProvider asset
3030

3131
Debug.Log("Initializing...");
3232

33-
Window.InitWindow(title, width, height, Silk.NET.Windowing.WindowState.Normal, true);
34-
33+
Window.InitWindow(title, width, height, Silk.NET.Windowing.WindowState.Maximized, true);
3534

3635
Window.Load += () => {
3736
SceneManager.Initialize();

0 commit comments

Comments
 (0)