Skip to content

Commit

Permalink
Merge branch 'MacTests'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsakharov committed Mar 31, 2024
2 parents c93bda1 + 082091e commit 0d036e0
Show file tree
Hide file tree
Showing 96 changed files with 15,614 additions and 224 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,6 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

# Mac OSX Folder info
.DS_Store
2 changes: 1 addition & 1 deletion Prowl.Editor/Assets/Importers/ModelImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ private void Scene(ModelImporter importer, SerializedAsset? serialized)
ImGui.Checkbox("Merge Objects", ref importer.OptimizeGraph);
ImGui.Checkbox("Cull Empty Objects", ref importer.CullEmpty);
ImGui.Separator();
ImGui.BeginChild("##SceneGraph", new Vector2(0, 250), true);
ImGui.BeginChild("##SceneGraph", new Vector2(0, 250), ImGuiChildFlags.Border);
ImGui.GetWindowDrawList().AddRectFilled(ImGui.GetCursorScreenPos(), new System.Numerics.Vector2(9999f, 9999f), ImGui.ColorConvertFloat4ToU32(new Vector4(0.1f, 0.1f, 0.1f, 1f)));
DrawNode(root);
ImGui.EndChild();
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Editor/Assets/Importers/MonoScriptImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override void Import(SerializedAsset ctx, FileInfo assetPath)

if (lastReload == default)
lastReload = DateTime.UtcNow;
if (lastReload.AddSeconds(2) > DateTime.UtcNow)
else if (lastReload.AddSeconds(2) > DateTime.UtcNow)
return;

EditorApplication.Instance.RegisterReloadOfExternalAssemblies();
Expand Down
9 changes: 5 additions & 4 deletions Prowl.Editor/Drawers/NodeSystem/NodeSystemDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,15 @@ public virtual bool Draw(NodeGraph graph)
}
}

ImNodes.MiniMap();
//ImNodes.MiniMap();
ImNodes.EndNodeEditor();

int start_node_id = 0;
int start_link_id = 0;
int end_node_id = 0;
int end_link_id = 0;
if (ImNodes.IsLinkCreated(ref start_node_id, ref start_link_id, ref end_node_id, ref end_link_id))
bool createdFromSnaps = false;
if (ImNodes.IsLinkCreatedIntPtr(ref start_node_id, ref start_link_id, ref end_node_id, ref end_link_id, ref createdFromSnaps))
{
changed = true;
var output = graph.GetNode(start_node_id);
Expand Down Expand Up @@ -262,7 +263,7 @@ public virtual bool OnDrawPort(NodePort port)
bool changed = false;
if (port.IsInput)
{
ImNodes.BeginInputAttribute(port.InstanceID);
ImNodes.BeginInputAttribute(port.InstanceID, ImNodesPinShape.CircleFilled);

bool drawField = false;
var fieldInfo = GetFieldInfo(port.node.GetType(), port.fieldName);
Expand All @@ -288,7 +289,7 @@ public virtual bool OnDrawPort(NodePort port)
}
else if (port.IsOutput)
{
ImNodes.BeginOutputAttribute(port.InstanceID);
ImNodes.BeginOutputAttribute(port.InstanceID, ImNodesPinShape.CircleFilled);
ImGui.Text(port.fieldName);
ImNodes.EndOutputAttribute();
}
Expand Down
12 changes: 11 additions & 1 deletion Prowl.Editor/Editor/AssetBrowserWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,30 @@ private void RenderHeader()
if (!Project.HasProject)
return;

Console.WriteLine(153);
ImGui.SetCursorPosY(cPY);
Console.WriteLine(155);
ImGui.SetCursorPosX(cPX + searchBarSize + padding);
string assetPath = Path.GetRelativePath(Project.ProjectDirectory, CurDirectory.FullName);
ImGui.Text(assetPath);

Console.WriteLine(160);
ImGui.SetCursorPosY(cPY);
Console.WriteLine(161);
ImGui.SetCursorPosX(windowWidth - rightOffset - sizeSliderSize - padding - 30);
if (ImGui.Button(Locked ? FontAwesome6.Lock : FontAwesome6.LockOpen))
Locked = !Locked;

Console.WriteLine(167);
ImGui.SetCursorPosY(cPY);
Console.WriteLine(169);
ImGui.SetCursorPosX(windowWidth - rightOffset - sizeSliderSize - padding);
ImGui.SetNextItemWidth(sizeSliderSize);
ImGui.SliderFloat("##ThumbnailSizeSlider", ref AssetPipelinePreferences.Instance.ThumbnailSize, -0.2f, 1.0f);

Console.WriteLine(174);
ImGui.SetCursorPosY(cPY);
Console.WriteLine(176);
ImGui.SetCursorPosX(windowWidth - rightOffset);
if (ImGui.Button(" " + FontAwesome6.Gears + " "))
_ = new ProjectSettingsWindow(typeof(AssetPipelinePreferences));
Expand Down Expand Up @@ -214,8 +222,9 @@ private void RenderBody()
private void RenderEntry(int rowCount, float itemSize, ref System.Numerics.Vector2 curPos, ref int i, FileSystemInfo entry)
{
ImGui.PushID(i);
Console.WriteLine(225);
ImGui.SetCursorPos(curPos);
ImGui.BeginChild("ClipBox", new System.Numerics.Vector2(ThumbnailSize, ThumbnailSize), false, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse);
ImGui.BeginChild("ClipBox", new System.Numerics.Vector2(ThumbnailSize, ThumbnailSize), ImGuiChildFlags.None, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse);
RenderFileSystemEntry(entry);
ImGui.EndChild();

Expand Down Expand Up @@ -373,6 +382,7 @@ private void DrawThumbnailForEntry(Texture2D thumbnail, float thumbnailSize)
thumbnailSize -= 30;
float thumbnailWidth = ((float)thumbnail.Width / thumbnail.Height) * thumbnailSize;
float xOffset = ((thumbnailSize - thumbnailWidth) / 2) + 15;
Console.WriteLine(385);
ImGui.SetCursorPos(new System.Numerics.Vector2(xOffset, 10));
ImGui.Image((IntPtr)thumbnail.Handle, new System.Numerics.Vector2(thumbnailWidth, thumbnailSize), System.Numerics.Vector2.UnitY, System.Numerics.Vector2.UnitX);
}
Expand Down
13 changes: 9 additions & 4 deletions Prowl.Editor/Editor/CustomEditors/GameObjectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public override void OnInspectorGUI()
PropertyDrawer.Draw(go.transform, typeof(Transform).GetProperty("localScale")!, -1, "Scale");

// Draw Components
HashSet<int> editorsNeeded = new();
HashSet<int> editorsNeeded = [];
List<MonoBehaviour> toDelete = [];
foreach (var comp in go.GetComponents<MonoBehaviour>()) {
editorsNeeded.Add(comp.InstanceID);

Expand All @@ -107,7 +108,7 @@ public override void OnInspectorGUI()
var cType = comp.GetType();
if (ImGui.CollapsingHeader(GetComponentDisplayName(cType), ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.OpenOnArrow)) {

HandleComponentContextMenu(go, comp);
HandleComponentContextMenu(go, comp, ref toDelete);

if (compEditors.TryGetValue(comp.InstanceID, out var editor)) {
editor.OnInspectorGUI();
Expand Down Expand Up @@ -143,6 +144,10 @@ public override void OnInspectorGUI()
GUIHelper.Space();
}

// Handle Deletion
foreach (var comp in toDelete)
go.RemoveComponent(comp);

// Remove any editors that are no longer needed
HandleUnusedEditors(editorsNeeded);

Expand Down Expand Up @@ -205,7 +210,7 @@ private void HandleAddComponentButton(GameObject? go)
ImGui.PopStyleVar();
}

private static void HandleComponentContextMenu(GameObject? go, MonoBehaviour comp)
private static void HandleComponentContextMenu(GameObject? go, MonoBehaviour comp, ref List<MonoBehaviour> toDelete)
{
if (ImGui.BeginPopupContextItem()) {
if (ImGui.MenuItem("Duplicate")) {
Expand All @@ -214,7 +219,7 @@ private static void HandleComponentContextMenu(GameObject? go, MonoBehaviour com
go.AddComponentDirectly(copy);
copy.OnValidate();
}
if (ImGui.MenuItem("Delete")) go.RemoveComponent(comp);
if (ImGui.MenuItem("Delete")) toDelete.Add(comp);
ImGui.EndPopup();
}
}
Expand Down
108 changes: 62 additions & 46 deletions Prowl.Editor/Editor/EditorWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hexa.NET.ImGui;
using System.Diagnostics;
using System.Numerics;

namespace Prowl.Editor.EditorWindows;
Expand Down Expand Up @@ -39,66 +40,81 @@ public EditorWindow() : base()
}

private void DrawWindow() {
isOpened = true;

if (BackgroundFade)
try
{
ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0);
ImGui.PushStyleColor(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 0.5f));
ImGui.PushStyleColor(ImGuiCol.Border, new Vector4(0, 0, 0, 0.5f));
if (ImGui.Begin("Fader", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoNav | ImGuiWindowFlags.NoDecoration))
isOpened = true;

if (BackgroundFade)
{
ImGui.SetWindowSize(new Vector2(ImGui.GetIO().DisplaySize.X, ImGui.GetIO().DisplaySize.Y));
ImGui.SetWindowPos(new Vector2(0, 0));
ImGui.End();
ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0);
ImGui.PushStyleColor(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 0.5f));
ImGui.PushStyleColor(ImGuiCol.Border, new Vector4(0, 0, 0, 0.5f));
if (ImGui.Begin("Fader", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoNav | ImGuiWindowFlags.NoDecoration))
{
ImGui.SetWindowSize(new Vector2(ImGui.GetIO().DisplaySize.X, ImGui.GetIO().DisplaySize.Y));
ImGui.SetWindowPos(new Vector2(0, 0));
ImGui.End();
}
ImGui.PopStyleColor(2);
ImGui.PopStyleVar(1);

// Next window should be focused
ImGui.SetNextWindowFocus();
}
ImGui.PopStyleColor(2);
ImGui.PopStyleVar(1);

// Next window should be focused
ImGui.SetNextWindowFocus();
}
PreWindowDraw();

PreWindowDraw();
if (Center)
{
var vp_size = ImGui.GetMainViewport().Size / 2;
ImGui.SetNextWindowPos(new Vector2(vp_size.X - (Width / 2), vp_size.Y - (Height / 2)));
}
if (LockSize)
ImGui.SetNextWindowSize(new Vector2(Width, Height));
else
ImGui.SetNextWindowSize(new Vector2(Width, Height), ImGuiCond.FirstUseEver);
// push id doesnt work with windows since it cant be handled with the id stack, c++ uses ## or ### to set an identifier
ImGui.PushID(_id + (Project.HasProject ? 1000 : 0));

if (Center)
{
var vp_size = ImGui.GetMainViewport().Size / 2;
ImGui.SetNextWindowPos(new Vector2(vp_size.X - (Width/2), vp_size.Y - (Height / 2)));
}
if(LockSize)
ImGui.SetNextWindowSize(new Vector2(Width, Height));
else
ImGui.SetNextWindowSize(new Vector2(Width, Height), ImGuiCond.FirstUseEver);
// push id doesnt work with windows since it cant be handled with the id stack, c++ uses ## or ### to set an identifier
ImGui.PushID(_id + (Project.HasProject ? 1000 : 0));
// Adding a ID to the title after the first iteration is required for Multi-Windows, the first cant have one for Docking
if (_windowCount != 0)
ImGui.Begin(Title + " " + _windowCount, ref isOpened, Flags);
else
ImGui.Begin(Title, ref isOpened, Flags);

// Adding a ID to the title after the first iteration is required for Multi-Windows, the first cant have one for Docking
if (_windowCount != 0)
ImGui.Begin(Title + " " + _windowCount, ref isOpened, Flags);
else
ImGui.Begin(Title, ref isOpened, Flags);
ImGUIWindow = ImGui.GetCurrentWindow();

ImGUIWindow = ImGui.GetCurrentWindow();
DrawToolbar();

DrawToolbar();

Draw();
ImGui.End();
ImGui.PopID();
Draw();
ImGui.End();
ImGui.PopID();

PostWindowDraw();
PostWindowDraw();

if (!isOpened)
if (!isOpened)
{
EditorApplication.OnDrawEditor -= DrawWindow;
EditorApplication.OnUpdateEditor -= UpdateWindow;
Close();
}
}
catch(Exception e)
{
EditorApplication.OnDrawEditor -= DrawWindow;
EditorApplication.OnUpdateEditor -= UpdateWindow;
Close();
Runtime.Debug.LogError("Error in EditorWindow: " + e.Message + "\n" + e.StackTrace);
}
}

private void UpdateWindow() {
Update();

private void UpdateWindow()
{
try
{
Update();
}
catch (Exception e)
{
Runtime.Debug.LogError("Error in UpdateWindow: " + e.Message + "\n" + e.StackTrace);
}
}

protected virtual void PreWindowDraw() { }
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Editor/Editor/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected override void Draw()
}

// Header Bar with resolution settings, then Image under it
ImGui.BeginChild("Header", new System.Numerics.Vector2(0, HeaderHeight), true, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse);
ImGui.BeginChild("Header", new System.Numerics.Vector2(0, HeaderHeight), ImGuiChildFlags.Border, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse);
{
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 5);
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + 5);
Expand Down
2 changes: 1 addition & 1 deletion Prowl.Editor/Editor/RenderPipelineWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void Draw()
if (CurrentRenderPipeline.IsAvailable == false) return;

var size = changed ? new System.Numerics.Vector2(ImGui.GetContentRegionAvail().X, ImGui.GetContentRegionAvail().Y - 30) : ImGui.GetContentRegionAvail();
ImGui.BeginChild("RenderPipeline", size, true, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse);
ImGui.BeginChild("RenderPipeline", size, ImGuiChildFlags.Border, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse);
bool changedThisFrame = NodeSystemDrawer.Draw(CurrentRenderPipeline.Res);
ImGui.EndChild();

Expand Down
2 changes: 1 addition & 1 deletion Prowl.Editor/EditorGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static void HandleBeginImGUIAttributes(IEnumerable<IImGUIAttri> attribs)
var group = (imGuiAttribute as StartGroupAttribute);
GUIHelper.TextCenter(group.name, group.headerSize);
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - 2);
ImGui.BeginChild(group.name, new System.Numerics.Vector2(-1, group.height), true, group.collapsable ? ImGuiWindowFlags.None : ImGuiWindowFlags.NoCollapse);
ImGui.BeginChild(group.name, new System.Numerics.Vector2(-1, group.height), ImGuiChildFlags.Border, group.collapsable ? ImGuiWindowFlags.None : ImGuiWindowFlags.NoCollapse);
break;

}
Expand Down
35 changes: 21 additions & 14 deletions Prowl.Editor/EditorMainMenubar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,33 @@ public EditorMainMenubar() {
EditorApplication.OnDrawEditor += Draw;
}

private void Draw() {
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new System.Numerics.Vector2(4, 4));
if(ImGui.BeginMainMenuBar()) {
private void Draw()
{
try
{
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new System.Numerics.Vector2(4, 4));
if (ImGui.BeginMainMenuBar())
{

DrawPlayControls();
DrawPlayControls();

ImGui.SetCursorPosX(0);
DrawMenuItems();
ImGui.SetCursorPosX(0);
DrawMenuItems();

if(ImGui.Button($"{FontAwesome6.ArrowsSpin}"))
EditorApplication.Instance.RegisterReloadOfExternalAssemblies();
GUIHelper.Tooltip("Recompile Project Scripts.");
if (ImGui.Button($"{FontAwesome6.ArrowsSpin}"))
EditorApplication.Instance.RegisterReloadOfExternalAssemblies();
GUIHelper.Tooltip("Recompile Project Scripts.");


ImGui.EndMainMenuBar();
ImGui.EndMainMenuBar();
}
// pop main menu bar size
ImGui.PopStyleVar();
}
catch (Exception e)
{
Runtime.Debug.LogError("Error in EditorMainMenuBar: " + e.Message + "\n" + e.StackTrace);
}
// pop main menu bar size
ImGui.PopStyleVar();
}

private static void DrawPlayControls() {
Expand Down Expand Up @@ -98,8 +107,6 @@ private static void DrawMenuItems()
ImGui.SetCursorPosX(2);
if (ImGui.BeginMenu("File"))
{
if (ImGui.MenuItem("Open Project")) { new ProjectsWindow(); }
ImGui.Separator();
MenuItem.DrawMenuRoot("Scene");
ImGui.Separator();
if (ImGui.MenuItem("Quit")) Application.Quit();
Expand Down
Loading

0 comments on commit 0d036e0

Please sign in to comment.