forked from Misaki/GhostEngine
Update editor
This commit is contained in:
21
Ghost.Editor.Core/Services/InspectorService.cs
Normal file
21
Ghost.Editor.Core/Services/InspectorService.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Ghost.Editor.Core.Contracts;
|
||||
|
||||
namespace Ghost.Editor.Core.Services;
|
||||
|
||||
public class InspectorService : IInspectorService
|
||||
{
|
||||
private IInspectable? _selected;
|
||||
|
||||
public IInspectable? Selected => _selected;
|
||||
|
||||
public event EventHandler<InspectorSelectionChangedEventArgs>? OnSelectionChanged;
|
||||
|
||||
public void SetSelected(IInspectable? inspectable, object? source)
|
||||
{
|
||||
if (_selected != inspectable)
|
||||
{
|
||||
_selected = inspectable;
|
||||
OnSelectionChanged?.Invoke(this, new InspectorSelectionChangedEventArgs(source, inspectable));
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Ghost.Editor.Core/Services/NotificationService.cs
Normal file
51
Ghost.Editor.Core/Services/NotificationService.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using CommunityToolkit.WinUI.Behaviors;
|
||||
using Ghost.Editor.Core.Contracts;
|
||||
using Ghost.Editor.Core.Notifications;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Ghost.Editor.Core.Services;
|
||||
|
||||
public class NotificationService : INotificationService
|
||||
{
|
||||
private InfoBar? _infoBar;
|
||||
private StackedNotificationsBehavior? _notificationQueue;
|
||||
|
||||
internal void SetReference(InfoBar infoBar, StackedNotificationsBehavior notificationQueue)
|
||||
{
|
||||
_infoBar = infoBar;
|
||||
_notificationQueue = notificationQueue;
|
||||
}
|
||||
|
||||
public void ShowNotification(string? message, MessageType type, int duration = 5, string? title = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var notification = new Notification
|
||||
{
|
||||
Message = message,
|
||||
Severity = (InfoBarSeverity)type,
|
||||
Duration = TimeSpan.FromSeconds(duration),
|
||||
Title = title
|
||||
};
|
||||
|
||||
ShowNotification(notification);
|
||||
}
|
||||
|
||||
public void ShowNotification(Notification notification)
|
||||
{
|
||||
_notificationQueue?.Show(notification);
|
||||
}
|
||||
|
||||
internal void ClearReference()
|
||||
{
|
||||
if (_infoBar != null)
|
||||
{
|
||||
_infoBar.IsOpen = false;
|
||||
}
|
||||
_infoBar = null;
|
||||
_notificationQueue = null;
|
||||
}
|
||||
}
|
||||
35
Ghost.Editor.Core/Services/PreviewService.cs
Normal file
35
Ghost.Editor.Core/Services/PreviewService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Ghost.Editor.Core.Contracts;
|
||||
|
||||
namespace Ghost.Editor.Core.Services;
|
||||
|
||||
internal class PreviewService : IPreviewService
|
||||
{
|
||||
public string GetIconPath(string path, bool isDirectory, IconSize size)
|
||||
{
|
||||
string iconPath;
|
||||
if (isDirectory)
|
||||
{
|
||||
iconPath = "ms-appx:///Assets/EditorIcons/folder-{0}.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Generate preview icons dynamically for known file types like images, meshes, materials, etc.
|
||||
var ext = Path.GetExtension(path);
|
||||
iconPath = ext switch
|
||||
{
|
||||
".png" or ".jpg" or ".jpeg" or ".gif" or ".bmp" or ".tiff" or ".svg" => "ms-appx:///Assets/EditorIcons/image-{0}.png",
|
||||
_ => "ms-appx:///Assets/EditorIcons/document-{0}.png",
|
||||
};
|
||||
}
|
||||
|
||||
var sizeIndex = size switch
|
||||
{
|
||||
IconSize.Small => "0",
|
||||
IconSize.Large => "1",
|
||||
_ => "0"
|
||||
};
|
||||
|
||||
iconPath = string.Format(iconPath, sizeIndex);
|
||||
return iconPath;
|
||||
}
|
||||
}
|
||||
75
Ghost.Editor.Core/Services/ProgressService.cs
Normal file
75
Ghost.Editor.Core/Services/ProgressService.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using CommunityToolkit.WinUI;
|
||||
using Ghost.Editor.Core.Contracts;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ghost.Editor.Core.Services;
|
||||
|
||||
public class ProgressService : IProgressService
|
||||
{
|
||||
private Grid? _progressBarContainer;
|
||||
private TextBlock? _progressMessage;
|
||||
private ProgressBar? _progressBar;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private bool IsInitialized()
|
||||
{
|
||||
return _progressBarContainer != null && _progressMessage != null && _progressBar != null;
|
||||
}
|
||||
|
||||
internal void SetReference(Grid progressBarContainer)
|
||||
{
|
||||
_progressBarContainer = progressBarContainer;
|
||||
_progressMessage = _progressBarContainer.FindChild<TextBlock>();
|
||||
_progressBar = _progressBarContainer.FindChild<ProgressBar>();
|
||||
}
|
||||
|
||||
public void ShowProgress(string message, double progress = 0.0)
|
||||
{
|
||||
if (!IsInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_progressBarContainer!.Visibility = Visibility.Visible;
|
||||
_progressMessage!.Text = message;
|
||||
_progressBar!.Value = progress;
|
||||
}
|
||||
|
||||
public void ShowIndeterminateProgress(string message)
|
||||
{
|
||||
if (!IsInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_progressBarContainer!.Visibility = Visibility.Visible;
|
||||
_progressMessage!.Text = message;
|
||||
_progressBar!.IsIndeterminate = true;
|
||||
}
|
||||
|
||||
public void SetProgress(double progress)
|
||||
{
|
||||
_progressBar!.Value = progress;
|
||||
}
|
||||
|
||||
public void HideProgress()
|
||||
{
|
||||
if (!IsInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_progressBarContainer!.Visibility = Visibility.Collapsed;
|
||||
_progressMessage!.Text = string.Empty;
|
||||
_progressBar!.Value = 0.0;
|
||||
}
|
||||
|
||||
internal void ClearReference()
|
||||
{
|
||||
_progressBarContainer = null;
|
||||
_progressMessage = null;
|
||||
_progressBar = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user