From 73bb475ef7362c2dfba4af8efcddc7a51f598c95 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 11 Feb 2024 15:39:34 +0900 Subject: [PATCH] added menu bar in Demo --- CHANGELOG.md | 1 + src/DotRecast.Core/RcProcess.cs | 34 +++++++++++++ src/DotRecast.Recast.Demo/RecastDemo.cs | 25 ++++----- src/DotRecast.Recast.Demo/UI/RcMenuView.cs | 59 ++++++++++++++++++++++ 4 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 src/DotRecast.Core/RcProcess.cs create mode 100644 src/DotRecast.Recast.Demo/UI/RcMenuView.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 317472c..bffea8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added DtNodeQueue UnitTest [@ikpil](https://github.com/ikpil) - Added RcSortedQueue UnitTest [@ikpil](https://github.com/ikpil) - Added IComparable interface to RcAtomicLong [@ikpil](https://github.com/ikpil) +- Added Menu bar in Demo [@ikpil](https://github.com/ikpil) ### Fixed diff --git a/src/DotRecast.Core/RcProcess.cs b/src/DotRecast.Core/RcProcess.cs new file mode 100644 index 0000000..05987ae --- /dev/null +++ b/src/DotRecast.Core/RcProcess.cs @@ -0,0 +1,34 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace DotRecast.Core +{ + public static class RcProcess + { + public static void OpenUrl(string url) + { + try + { + // OS에 따라 다른 명령 실행 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var psi = new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true }; + Process.Start(psi); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + Process.Start("open", url); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Process.Start("xdg-open", url); + } + } + catch (Exception ex) + { + Console.WriteLine($"Error opening web browser: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index c551aeb..e56a5da 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -43,7 +43,6 @@ using DotRecast.Recast.Demo.Messages; using DotRecast.Recast.Toolset.Geom; using DotRecast.Recast.Demo.Tools; using DotRecast.Recast.Demo.UI; -using DotRecast.Recast.Toolset; using MouseButton = Silk.NET.Input.MouseButton; using Window = Silk.NET.Windowing.Window; @@ -111,7 +110,8 @@ public class RecastDemo : IRecastDemoChannel private bool markerPositionSet; private RcVec3f markerPosition = new RcVec3f(); - private RcToolsetView toolset; + private RcMenuView _menuView; + private RcToolsetView _toolsetView; private RcSettingsView settingsView; private RcLogView logView; @@ -319,7 +319,7 @@ public class RecastDemo : IRecastDemoChannel if (null != mesh) { _sample.Update(_sample.GetInputGeom(), ImmutableArray.Empty, mesh); - toolset.SetEnabled(true); + _toolsetView.SetEnabled(true); } } catch (Exception e) @@ -379,11 +379,12 @@ public class RecastDemo : IRecastDemoChannel DemoInputGeomProvider geom = LoadInputMesh("nav_test.obj"); _sample = new DemoSample(geom, ImmutableArray.Empty, null); - + + _menuView = new RcMenuView(); settingsView = new RcSettingsView(this); settingsView.SetSample(_sample); - toolset = new RcToolsetView( + _toolsetView = new RcToolsetView( new TestNavmeshSampleTool(), new TileSampleTool(), new ObstacleSampleTool(), @@ -394,10 +395,10 @@ public class RecastDemo : IRecastDemoChannel new JumpLinkBuilderSampleTool(), new DynamicUpdateSampleTool() ); - toolset.SetEnabled(true); + _toolsetView.SetEnabled(true); logView = new RcLogView(); - _canvas = new RcCanvas(window, settingsView, toolset, logView); + _canvas = new RcCanvas(window, _menuView, settingsView, _toolsetView, logView); var vendor = _gl.GetStringS(GLEnum.Vendor); var version = _gl.GetStringS(GLEnum.Version); @@ -504,7 +505,7 @@ public class RecastDemo : IRecastDemoChannel timeAcc -= DELTA_TIME; if (simIter < 5 && _sample != null) { - var tool = toolset.GetTool(); + var tool = _toolsetView.GetTool(); if (null != tool) { tool.HandleUpdate(DELTA_TIME); @@ -591,7 +592,7 @@ public class RecastDemo : IRecastDemoChannel } _sample.SetChanged(false); - toolset.SetSample(_sample); + _toolsetView.SetSample(_sample); } if (_messages.TryDequeue(out var msg)) @@ -620,7 +621,7 @@ public class RecastDemo : IRecastDemoChannel dd.Fog(camr * 0.1f, camr * 1.25f); renderer.Render(_sample, settingsView.GetDrawMode()); - ISampleTool sampleTool = toolset.GetTool(); + ISampleTool sampleTool = _toolsetView.GetTool(); if (sampleTool != null) { sampleTool.HandleRender(renderer); @@ -707,7 +708,7 @@ public class RecastDemo : IRecastDemoChannel _sample.SetChanged(false); settingsView.SetBuildTime((RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond); //settingsUI.SetBuildTelemetry(buildResult.Item1.Select(x => x.GetTelemetry()).ToList()); - toolset.SetSample(_sample); + _toolsetView.SetSample(_sample); Logger.Information($"build times"); Logger.Information($"-----------------------------------------"); @@ -800,7 +801,7 @@ public class RecastDemo : IRecastDemoChannel RcVec3f rayDir = new RcVec3f(rayEnd.X - rayStart.X, rayEnd.Y - rayStart.Y, rayEnd.Z - rayStart.Z); rayDir = RcVec3f.Normalize(rayDir); - ISampleTool raySampleTool = toolset.GetTool(); + ISampleTool raySampleTool = _toolsetView.GetTool(); if (raySampleTool != null) { diff --git a/src/DotRecast.Recast.Demo/UI/RcMenuView.cs b/src/DotRecast.Recast.Demo/UI/RcMenuView.cs new file mode 100644 index 0000000..e727a82 --- /dev/null +++ b/src/DotRecast.Recast.Demo/UI/RcMenuView.cs @@ -0,0 +1,59 @@ +using DotRecast.Core; +using ImGuiNET; + +namespace DotRecast.Recast.Demo.UI; + +public class RcMenuView : IRcView +{ + private RcCanvas _canvas; + + public void Bind(RcCanvas canvas) + { + _canvas = canvas; + } + + public bool IsHovered() + { + //throw new System.NotImplementedException(); + return false; + } + + public void Update(double dt) + { + //throw new System.NotImplementedException(); + } + + public void Draw(double dt) + { + if (ImGui.BeginMainMenuBar()) + { + if (ImGui.BeginMenu("Help")) + { + if (ImGui.MenuItem("Repository")) + { + RcProcess.OpenUrl("https://github.com/ikpil/DotRecast"); + } + + if (ImGui.MenuItem("Nuget")) + { + RcProcess.OpenUrl("https://www.nuget.org/packages/DotRecast.Core/"); + } + + ImGui.Separator(); + if (ImGui.MenuItem("Issue Tracker")) + { + RcProcess.OpenUrl("https://github.com/ikpil/DotRecast/issues"); + } + + if (ImGui.MenuItem("Release Notes")) + { + RcProcess.OpenUrl("https://github.com/ikpil/DotRecast/blob/main/CHANGELOG.md"); + } + + ImGui.EndMenu(); + } + + ImGui.EndMainMenuBar(); + } + } +} \ No newline at end of file