Skip to content

Commit 2fb28fd

Browse files
Merge pull request #274 from xZekro51/tweaks/file-creation-flow-rework
Reworked File creation flow
2 parents 21e6656 + 845333d commit 2fb28fd

24 files changed

Lines changed: 1013 additions & 414 deletions

Prowl.Editor/AssetDatabase/AssetCreateMenu.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Prowl.Editor.Panels;
66
using Prowl.Editor.Widgets;
77
using Prowl.Runtime;
8+
using Prowl.Runtime.Resources;
89

910
namespace Prowl.Editor;
1011

@@ -19,15 +20,37 @@ public static class AssetCreateMenu
1920
/// </summary>
2021
public static void Build(ContextMenuBuilder builder, string currentFolder, Action<string>? onCreated = null)
2122
{
22-
builder.Item($"{EditorIcons.Folder} Folder", () => { var p = CreateFolder(currentFolder); if (p != null) onCreated?.Invoke(p); });
23+
builder.Item($"{EditorIcons.Folder} Folder", () => {
24+
25+
var task = new Tasks.CreateAssetTask();
26+
27+
task.TaskType = Tasks.CreateAssetTask.AssetType.Folder;
28+
task.BeginCreateTask(new CreateAssetMenuRegistry.Entry() { Name = "New Folder", Extension = "", Icon = FileIconRegistry.GetIconForExtension("") }, currentFolder);
29+
30+
});
2331
builder.Separator();
2432

2533
// Registry-discovered asset types (Scene, Material, InputActions, user-defined, etc.)
2634
CreateAssetMenuRegistry.BuildMenu(builder, currentFolder, onCreated);
2735

28-
builder.Item($"{EditorIcons.WandMagicSparkles} Shader", () => { var p = CreateShader(currentFolder); if (p != null) onCreated?.Invoke(p); });
36+
builder.Item($"{EditorIcons.WandMagicSparkles} Shader", () => {
37+
38+
var task = new Tasks.CreateAssetTask();
39+
40+
task.TaskType = Tasks.CreateAssetTask.AssetType.Shader;
41+
task.BeginCreateTask(new CreateAssetMenuRegistry.Entry() { Name = "New Shader", Extension = ".shader", Type = typeof(Shader), Icon = FileIconRegistry.GetIconForExtension(".shader") }, currentFolder);
42+
43+
});
2944
builder.Separator();
30-
builder.Item($"{EditorIcons.FileCode} C# Script", () => NewScriptDialog.Open(currentFolder, onCreated));
45+
builder.Item($"{EditorIcons.FileCode} C# Script", () =>
46+
{
47+
NewScriptDialog.Open(GetCurrentFolder());
48+
49+
/*var task = new Tasks.CreateAssetTask();
50+
task.TaskType = Tasks.CreateAssetTask.AssetType.Script;
51+
task.BeginCreateTask(new CreateAssetMenuRegistry.Entry() { Name = "New Script", Extension = ".cs", Type = typeof(MonoBehaviour), Icon = FileIconRegistry.GetIconForExtension(".cs") }, currentFolder);*/
52+
53+
});
3154
}
3255

3356
/// <summary>

Prowl.Editor/AssetDatabase/CreateAssetMenuRegistry.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static void Initialize()
102102
/// <summary>
103103
/// Appends one menu item per registered asset type to the given context menu builder.
104104
/// Names containing '/' are split into nested submenus (e.g. "Shader Graph/Surface"
105-
/// produces an "Shader Graph" submenu with a "Surface" item inside).
105+
/// produces a "Shader Graph" submenu with a "Surface" item inside).
106106
/// </summary>
107107
public static void BuildMenu(ContextMenuBuilder builder, string currentFolder, Action<string>? onCreated = null)
108108
{
@@ -135,8 +135,11 @@ private static void BuildMenuRecursive(ContextMenuBuilder builder,
135135
string icon = !string.IsNullOrEmpty(captured.Icon) ? captured.Icon : EditorIcons.FileCirclePlus;
136136
builder.Item($"{icon} {display}", () =>
137137
{
138-
var path = CreateAsset(captured, currentFolder);
139-
if (path != null) onCreated?.Invoke(path);
138+
var task = new Tasks.CreateAssetTask();
139+
140+
task.TaskType = Tasks.CreateAssetTask.AssetType.Asset;
141+
task.BeginCreateTask(captured, currentFolder);
142+
140143
});
141144
}
142145
foreach (var (head, list) in branches)

Prowl.Editor/EditorApplication.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,49 @@ public override void EndGui(Paper paper)
695695

696696
private const int BarCount = 10;
697697

698+
public static string GetEmbeddedResourceText(string resource)
699+
{
700+
var stream = GetEmbeddedResource(resource);
701+
702+
string data = "";
703+
using (StreamReader reader = new StreamReader(stream))
704+
{
705+
data = reader.ReadToEnd();
706+
}
707+
708+
return data;
709+
}
710+
711+
public static Stream? GetEmbeddedResource(string resource)
712+
{
713+
var assembly = Assembly.GetExecutingAssembly();
714+
715+
var resourceName = "Prowl.Editor.Resources." + resource;
716+
717+
var stream = assembly.GetManifestResourceStream(resourceName);
718+
return stream;
719+
}
720+
721+
public static FileStream? GetResource(string resource)
722+
{
723+
var assembly = Assembly.GetExecutingAssembly();
724+
725+
var resourceName = resource;
726+
727+
var pathToFile = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) +
728+
resourceName;
729+
730+
using (var stream = assembly.GetManifestResourceStream(resourceName))
731+
{
732+
using (var fileStream = File.Create(pathToFile))
733+
{
734+
stream.Seek(0, SeekOrigin.Begin);
735+
stream.CopyTo(fileStream);
736+
}
737+
}
738+
return File.OpenRead(pathToFile);
739+
}
740+
698741
private void DrawIntro(Paper paper)
699742
{
700743
float w = paper.ScreenRect.Size.X;

Prowl.Editor/Panels/ProjectPanel.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ namespace Prowl.Editor.Panels;
2020
[EditorWindow("General/Project")]
2121
public class ProjectPanel : DockPanel
2222
{
23+
public static ProjectPanel Instance;
2324
public override string Title => "Project";
2425
public override string Icon => EditorIcons.Folder;
2526

27+
// Handled Virtual (Placeholder) content to be displayed with normal objects
28+
public List<ContentItem> VirtualContentItems = new();
29+
30+
public string CurrentFolder => _currentFolder;
2631
private string _currentFolder = ""; // Relative to Assets/, empty = Assets root
2732
private string _searchText = "";
2833
private float _thumbnailSize = 64f;
@@ -56,6 +61,9 @@ public override void OnGUI(Paper paper, float width, float height)
5661
var font = EditorTheme.DefaultFont;
5762
if (font == null || Project.Current == null) return;
5863

64+
// Sets itself as instance on start
65+
Instance ??= this;
66+
5967
// Detect new ping and navigate to the pinged asset's folder
6068
if (Selection.PingedGuid != Guid.Empty && Selection.PingedGuid != _lastPingedGuid)
6169
{
@@ -1009,6 +1017,7 @@ private void StartRename(ContentItem item, bool inTree = false)
10091017
});
10101018
}
10111019

1020+
10121021
private static void OpenWithSystem(ContentItem item)
10131022
{
10141023
string absPath = Path.Combine(Project.Current!.AssetsPath, item.RelativePath);
@@ -1033,6 +1042,8 @@ private void DrawGridView(Paper paper, Prowl.Scribe.FontFile font, List<ContentI
10331042
{
10341043
float cellSize = _thumbnailSize + 8f;
10351044
float labelH = 18f;
1045+
1046+
10361047
float totalCellH = cellSize + labelH;
10371048
float gap = 6f;
10381049
// Available width minus padding (12 = 6 left margin + 6 right margin from parent)
@@ -1056,7 +1067,17 @@ private void DrawGridView(Paper paper, Prowl.Scribe.FontFile font, List<ContentI
10561067
var item = entries[idx];
10571068
bool isSelected = Selection.IsSelected(item);
10581069

1059-
DrawGridItem(paper, font, $"proj_gc_{idx}", item, idx, itemObjects, cellSize, labelH, totalCellH);
1070+
1071+
var size = paper.MeasureText(item.Name, EditorTheme.FontSize - 3, font);
1072+
1073+
if (size.X > cellSize)
1074+
{
1075+
size *= 2;
1076+
}
1077+
1078+
//Runtime.Debug.Log($"Size: ({item.Name}) {labelH} - {sizeY} - {sizeYo} ({(EditorTheme.FontSize - 5)/paper.Canvas.Scale})");
1079+
1080+
DrawGridItem(paper, font, $"proj_gc_{idx}", item, idx, itemObjects, cellSize, size.Y, totalCellH);
10601081
}
10611082
}
10621083
row++;
@@ -1185,16 +1206,19 @@ private void DrawGridItem(Paper paper, Prowl.Scribe.FontFile font, string id, Co
11851206
// Label
11861207
if (RenameOverlay.IsRenaming($"proj_asset_{item.RelativePath}"))
11871208
{
1188-
RenameOverlay.Draw(paper, $"{id}_rename");
1209+
RenameOverlay.Draw(paper, $"{id}_rename", RenameOverlay.Position.Bottom);
11891210
}
11901211
else
11911212
{
11921213
paper.Box($"{id}_l")
1214+
.PositionType(PositionType.SelfDirected)
1215+
.Position(0,UnitValue.Stretch())
11931216
.Width(cellSize).Height(labelH)
11941217
.Clip()
11951218
.Text(item.Name, font)
1219+
.Wrap(Scribe.TextWrapMode.Wrap)
11961220
.TextColor(isSubAsset ? EditorTheme.Purple300 : EditorTheme.Ink500)
1197-
.FontSize(EditorTheme.FontSize - 2).Alignment(TextAlignment.MiddleCenter);
1221+
.FontSize(EditorTheme.FontSize - 3).Alignment(TextAlignment.MiddleCenter);
11981222
}
11991223

12001224
BuildItemContextMenu(paper, $"{id}_ctx", item);
@@ -1249,6 +1273,8 @@ private List<ContentItem> GetContentEntries(EditorAssetDatabase db)
12491273
}
12501274
catch { }
12511275

1276+
items.AddRange(VirtualContentItems);
1277+
12521278
// Files
12531279
try
12541280
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Prowl.Runtime;
2+
3+
[RequireComponent(typeof(AudioSource))]
4+
public class {[className]} : MonoBehaviour
5+
{
6+
public bool PlayOnStart = true;
7+
8+
private AudioSource _source = null!;
9+
10+
public override void Start()
11+
{
12+
_source = GetComponent<AudioSource>()!;
13+
if (PlayOnStart) Play();
14+
}
15+
16+
public void Play()
17+
{
18+
if (_source.Clip != null) _source.Play();
19+
}
20+
21+
public void Stop() => _source.Stop();
22+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Prowl.Runtime;
2+
using Prowl.Vector;
3+
4+
[RequireComponent(typeof(CharacterController))]
5+
public class {[className]} : MonoBehaviour
6+
{
7+
public float MoveSpeed = 6f;
8+
public float JumpSpeed = 8f;
9+
public float Gravity = -20f;
10+
11+
private CharacterController _controller = null!;
12+
private Float3 _velocity;
13+
14+
public override void Start()
15+
{
16+
_controller = GetComponent<CharacterController>()!;
17+
}
18+
19+
public override void Update()
20+
{
21+
Float2 wasd = Input.GetWASD();
22+
Float3 planar = Transform.Right * wasd.X + Transform.Forward * wasd.Y;
23+
_velocity.X = planar.X * MoveSpeed;
24+
_velocity.Z = planar.Z * MoveSpeed;
25+
26+
if (_controller.IsGrounded)
27+
{
28+
_velocity.Y = 0f;
29+
if (Input.GetKeyDown(KeyCode.Space))
30+
_velocity.Y = JumpSpeed;
31+
}
32+
else
33+
{
34+
_velocity.Y += Gravity * Time.DeltaTime;
35+
}
36+
37+
_controller.Move(_velocity * Time.DeltaTime);
38+
}
39+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Prowl.Runtime;
2+
3+
[CreateAssetMenu("{[className]}", Extension = ".asset")]
4+
public class {[className]} : EngineObject
5+
{
6+
public float ExampleFloat = 1f;
7+
public string ExampleText = "";
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
3+
using Prowl.Runtime;
4+
using Prowl.Vector;
5+
6+
public class {[className]} : MonoBehaviour
7+
{
8+
public float Sensitivity = 0.15f;
9+
public float MinPitch = -89f;
10+
public float MaxPitch = 89f;
11+
12+
private float _yaw;
13+
private float _pitch;
14+
15+
public override void Start()
16+
{
17+
Float3 euler = Transform.LocalEulerAngles;
18+
_pitch = euler.X;
19+
_yaw = euler.Y;
20+
}
21+
22+
public override void Update()
23+
{
24+
if (!Input.CursorLocked) return;
25+
26+
Float2 delta = Input.MouseDelta;
27+
_yaw += delta.X * Sensitivity;
28+
_pitch = Math.Clamp(_pitch - delta.Y * Sensitivity, MinPitch, MaxPitch);
29+
30+
Transform.LocalEulerAngles = new Float3(_pitch, _yaw, 0f);
31+
}
32+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
using Prowl.Runtime;
4+
using Prowl.Vector;
5+
6+
public class {[className]} : MonoBehaviour
7+
{
8+
public GameObject? Target;
9+
public Float3 Offset = new Float3(0, 3, -6);
10+
public float FollowSmoothing = 8f;
11+
public float LookSmoothing = 8f;
12+
13+
public override void LateUpdate()
14+
{
15+
if (Target == null) return;
16+
17+
Float3 desiredPos = Target.Transform.Position + Target.Transform.Rotation * Offset;
18+
float tMove = 1f - MathF.Exp(-FollowSmoothing * Time.DeltaTime);
19+
Transform.Position = Maths.Lerp(Transform.Position, desiredPos, tMove);
20+
21+
Float3 lookDir = Target.Transform.Position - Transform.Position;
22+
if (Float3.LengthSquared(lookDir) > 0.0001f)
23+
{
24+
Quaternion desiredRot = Quaternion.LookRotation(Float3.Normalize(lookDir), Float3.UnitY);
25+
float tLook = 1f - MathF.Exp(-LookSmoothing * Time.DeltaTime);
26+
Transform.Rotation = Quaternion.Slerp(Transform.Rotation, desiredRot, tLook);
27+
}
28+
}
29+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
3+
using Prowl.Runtime;
4+
5+
public class {[className]} : MonoBehaviour
6+
{
7+
public float MaxHealth = 100f;
8+
9+
private float _current;
10+
11+
public float Current => _current;
12+
public float Normalized => MaxHealth > 0 ? _current / MaxHealth : 0f;
13+
public bool IsDead => _current <= 0f;
14+
15+
public event Action<float>? HealthChanged;
16+
public event Action? Died;
17+
18+
public override void OnEnable()
19+
{
20+
_current = MaxHealth;
21+
}
22+
23+
public void Damage(float amount)
24+
{
25+
if (IsDead || amount <= 0f) return;
26+
_current = MathF.Max(0f, _current - amount);
27+
HealthChanged?.Invoke(_current);
28+
if (IsDead) Died?.Invoke();
29+
}
30+
31+
public void Heal(float amount)
32+
{
33+
if (IsDead || amount <= 0f) return;
34+
_current = MathF.Min(MaxHealth, _current + amount);
35+
HealthChanged?.Invoke(_current);
36+
}
37+
}

0 commit comments

Comments
 (0)