Skip to content

Commit

Permalink
✨ Change PropertiesView Title to "Entity Inspector" when an `Enti…
Browse files Browse the repository at this point in the history
…ty` is selected in the Scene Hierarchy (#258)
  • Loading branch information
softwareantics committed Aug 17, 2023
1 parent 01d9fdd commit 1f49618
Show file tree
Hide file tree
Showing 19 changed files with 327 additions and 21 deletions.
3 changes: 3 additions & 0 deletions FinalEngine.Editor.Desktop/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace FinalEngine.Editor.Desktop;
using System.Diagnostics;
using System.IO.Abstractions;
using System.Windows;
using CommunityToolkit.Mvvm.Messaging;
using FinalEngine.ECS;
using FinalEngine.Editor.Common.Extensions;
using FinalEngine.Editor.Common.Models.Scenes;
Expand Down Expand Up @@ -108,6 +109,8 @@ private static void ConfigureServices(HostBuilderContext context, IServiceCollec
builder.AddConsole().SetMinimumLevel(Debugger.IsAttached ? LogLevel.Debug : LogLevel.Information);
});

services.AddSingleton<IMessenger>(WeakReferenceMessenger.Default);

services.AddTransient<IEntityWorld, EntityWorld>();
services.AddSingleton<IRenderDevice, OpenGLRenderDevice>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource MahApps.Styles.TextBox.VisualStudio}">
<Setter Property="Margin" Value="5" />
<Setter Property="MinHeight" Value="25" />
<Setter Property="MinWidth" Value="250" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="{StaticResource MahApps.Brushes.TextBox.Border}" />
<Style.Triggers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
</Grid.RowDefinitions>

<Label Grid.Row="0" Content="GUID:" />
<TextBox Grid.Column="1" Grid.Row="0" MinWidth="250" IsEnabled="False" Text="{Binding EntityGuid, Mode=OneWay}" />
<TextBox Grid.Column="1" Grid.Row="0" IsEnabled="False" Text="{Binding EntityGuid, Mode=OneWay}" />

<Label Grid.Row="1" Content="Entity Name:" />
<TextBox x:Name="textBox" Grid.Column="1" Grid.Row="1" MinWidth="250" Text="{Binding EntityName, UpdateSourceTrigger=PropertyChanged}" />
<TextBox x:Name="textBox" Grid.Column="1" Grid.Row="1" Text="{Binding EntityName, UpdateSourceTrigger=PropertyChanged}" />

<WrapPanel Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Right">
<Button IsDefault="True" Content="Create" Command="{Binding CreateCommand}" CommandParameter="{Binding ElementName=Window}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</Grid.RowDefinitions>

<Label Grid.Row="0" Content="Layout Name:" />
<TextBox x:Name="textBox" Grid.Column="1" Grid.Row="0" MinWidth="250" Text="{Binding LayoutName, UpdateSourceTrigger=PropertyChanged}" />
<TextBox x:Name="textBox" Grid.Column="1" Grid.Row="0" Text="{Binding LayoutName, UpdateSourceTrigger=PropertyChanged}" />

<WrapPanel Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Right">
<Button IsDefault="True" Content="Save" Command="{Binding SaveCommand}" CommandParameter="{Binding ElementName=Window}" />
Expand Down
2 changes: 1 addition & 1 deletion FinalEngine.Editor.Desktop/Views/Docking/DockView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<!-- PROPERTIES -->
<data:PaneTemplateSelector.PropertiesTemplate>
<DataTemplate>
<inspectors:ConsoleView />
<inspectors:PropertiesView />
</DataTemplate>
</data:PaneTemplateSelector.PropertiesTemplate>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<UserControl x:Class="FinalEngine.Editor.Desktop.Views.Inspectors.EntityInspectorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <copyright file="EntityInspectorView.xaml.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Desktop.Views.Inspectors;

using System.Windows.Controls;

/// <summary>
/// Interaction logic for EntityInspectorView.xaml.
/// </summary>
public partial class EntityInspectorView : UserControl
{
/// <summary>
/// Initializes a new instance of the <see cref="EntityInspectorView"/> class.
/// </summary>
public EntityInspectorView()
{
this.InitializeComponent();
}
}
10 changes: 10 additions & 0 deletions FinalEngine.Editor.Desktop/Views/Inspectors/PropertiesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:inspectors="clr-namespace:FinalEngine.Editor.Desktop.Views.Inspectors"
xmlns:vm="clr-namespace:FinalEngine.Editor.ViewModels.Docking.Tools.Inspectors;assembly=FinalEngine.Editor.ViewModels"
xmlns:vme="clr-namespace:FinalEngine.Editor.ViewModels.Inspectors;assembly=FinalEngine.Editor.ViewModels"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=vm:PropertiesToolViewModel}">

<UserControl.Resources>
<DataTemplate DataType="{x:Type vme:EntityInspectorViewModel}">
<inspectors:EntityInspectorView />
</DataTemplate>
</UserControl.Resources>

<Grid>
<ContentControl Content="{Binding CurrentViewModel}" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<Grid>
<ListBox ItemsSource="{Binding Entities, UpdateSourceTrigger=PropertyChanged}"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectedItem="{Binding SelectedEntity}">

<ListBox.Style>
<Style TargetType="ListBox" BasedOn="{StaticResource MahApps.Styles.ListBox.VisualStudio}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@

namespace FinalEngine.Editor.ViewModels.Docking.Tools.Inspectors;

using CommunityToolkit.Mvvm.ComponentModel;

/// <summary>
/// Defines an interface that represents a model of a properties tool view.
/// </summary>
/// <seealso cref="FinalEngine.Editor.ViewModels.Docking.Tools.IToolViewModel" />
/// <seealso cref="IToolViewModel" />
public interface IPropertiesToolViewModel : IToolViewModel
{
/// <summary>
/// Gets the current view model.
/// </summary>
/// <value>
/// The current view model.
/// </value>
ObservableObject? CurrentViewModel { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
namespace FinalEngine.Editor.ViewModels.Docking.Tools.Inspectors;

using System;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using FinalEngine.ECS.Components.Core;
using FinalEngine.Editor.ViewModels.Inspectors;
using FinalEngine.Editor.ViewModels.Messages.Entities;
using Microsoft.Extensions.Logging;

/// <summary>
Expand All @@ -14,22 +19,71 @@ namespace FinalEngine.Editor.ViewModels.Docking.Tools.Inspectors;
/// <seealso cref="IPropertiesToolViewModel" />
public sealed class PropertiesToolViewModel : ToolViewModelBase, IPropertiesToolViewModel
{
/// <summary>
/// The logger.
/// </summary>
private readonly ILogger<PropertiesToolViewModel> logger;

/// <summary>
/// The messenger.
/// </summary>
private readonly IMessenger messenger;

/// <summary>
/// The current view model to be shown in the properties view.
/// </summary>
private ObservableObject? currentViewModel;

/// <summary>
/// Initializes a new instance of the <see cref="PropertiesToolViewModel"/> class.
/// </summary>
/// <param name="logger">
/// The logger.
/// </param>
public PropertiesToolViewModel(ILogger<PropertiesToolViewModel> logger)
/// <param name="messenger">
/// The messenger.
/// </param>
public PropertiesToolViewModel(
ILogger<PropertiesToolViewModel> logger,
IMessenger messenger)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
this.messenger = messenger ?? throw new ArgumentNullException(nameof(messenger));

this.Title = "Properties";
this.ContentID = "Properties";

logger.LogInformation($"Initializing {this.Title}...");

this.messenger.Register<EntitySelectedMessage>(this, this.HandleEntitySelected);
}

/// <inheritdoc/>
public ObservableObject? CurrentViewModel
{
get { return this.currentViewModel; }
private set { this.SetProperty(ref this.currentViewModel, value); }
}

/// <summary>
/// Handles the <see cref="EntitySelectedMessage"/> and updates the view.
/// </summary>
/// <param name="recipient">
/// The recipient.
/// </param>
/// <param name="message">
/// The message.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// The specified <paramref name="message"/> parameter cannot be null.
/// </exception>
private void HandleEntitySelected(object recipient, EntitySelectedMessage message)
{
this.logger.LogInformation($"Changing properties view to: '{nameof(EntityInspectorViewModel)}'.");

var entity = message.Entity;

this.Title = $"Entity Inspector - {entity.GetComponent<TagComponent>().Tag}";
this.CurrentViewModel = new EntityInspectorViewModel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FinalEngine.Editor.ViewModels.Docking.Tools.Scenes;
/// <summary>
/// Defines an interface that represents a model of a scene hierarchy tool view.
/// </summary>
/// <seealso cref="FinalEngine.Editor.ViewModels.Docking.Tools.IToolViewModel" />
/// <seealso cref="IToolViewModel" />
public interface ISceneHierarchyToolViewModel : IToolViewModel
{
/// <summary>
Expand All @@ -20,4 +20,12 @@ public interface ISceneHierarchyToolViewModel : IToolViewModel
/// The entities within the active scene.
/// </value>
IReadOnlyCollection<Entity> Entities { get; }

/// <summary>
/// Gets or sets the selected entity.
/// </summary>
/// <value>
/// The selected entity.
/// </value>
Entity? SelectedEntity { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace FinalEngine.Editor.ViewModels.Docking.Tools.Scenes;

using System;
using System.Collections.Generic;
using CommunityToolkit.Mvvm.Messaging;
using FinalEngine.ECS;
using FinalEngine.Editor.Common.Services.Scenes;
using FinalEngine.Editor.ViewModels.Messages.Entities;
using Microsoft.Extensions.Logging;

/// <summary>
Expand All @@ -17,30 +19,47 @@ namespace FinalEngine.Editor.ViewModels.Docking.Tools.Scenes;
/// <seealso cref="ISceneHierarchyToolViewModel" />
public sealed class SceneHierarchyToolViewModel : ToolViewModelBase, ISceneHierarchyToolViewModel
{
/// <summary>
/// The messenger.
/// </summary>
private readonly IMessenger messenger;

/// <summary>
/// The scene manager.
/// </summary>
private readonly ISceneManager sceneManager;

/// <summary>
/// The selected entity, or <c>null</c> if one is not selected.
/// </summary>
private Entity? selectedEntity;

/// <summary>
/// Initializes a new instance of the <see cref="SceneHierarchyToolViewModel"/> class.
/// </summary>
/// <param name="logger">
/// The logger.
/// </param>
/// <param name="messenger">
/// The messenger.
/// </param>
/// <param name="sceneManager">
/// The scene manager.
/// </param>
/// <exception cref="ArgumentNullException">
/// The specified <paramref name="logger"/> or <paramref name="sceneManager"/> parameter cannot be null.
/// The specified <paramref name="logger"/>, <paramref name="messenger"/> or <paramref name="sceneManager"/> parameter cannot be null.
/// </exception>
public SceneHierarchyToolViewModel(ILogger<SceneHierarchyToolViewModel> logger, ISceneManager sceneManager)
public SceneHierarchyToolViewModel(
ILogger<SceneHierarchyToolViewModel> logger,
IMessenger messenger,
ISceneManager sceneManager)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

this.messenger = messenger ?? throw new ArgumentNullException(nameof(messenger));
this.sceneManager = sceneManager ?? throw new ArgumentNullException(nameof(sceneManager));

this.Title = "Scene Hierarchy";
Expand All @@ -54,4 +73,23 @@ public IReadOnlyCollection<Entity> Entities
{
get { return this.sceneManager.ActiveScene.Entities; }
}

/// <inheritdoc/>
public Entity? SelectedEntity
{
get
{
return this.selectedEntity;
}

set
{
this.SetProperty(ref this.selectedEntity, value);

if (this.SelectedEntity != null)
{
this.messenger.Send(new EntitySelectedMessage(this.SelectedEntity));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// <copyright file="EntityInspectorViewModel.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.ViewModels.Inspectors;

using CommunityToolkit.Mvvm.ComponentModel;

/// <summary>
/// Provides a standard implementation of an <see cref="IEntityInspectorViewModel"/>.
/// </summary>
/// <seealso cref="ObservableObject" />
/// <seealso cref="IEntityInspectorViewModel" />
public sealed class EntityInspectorViewModel : ObservableObject, IEntityInspectorViewModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// <copyright file="IEntityInspectorViewModel.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.ViewModels.Inspectors;

using System.Diagnostics.CodeAnalysis;

/// <summary>
/// Defines an interface that represents a model of the entity inspector view.
/// </summary>
[SuppressMessage("Design", "CA1040:Avoid empty interfaces", Justification = "TODO")]
public interface IEntityInspectorViewModel
{
}
Loading

0 comments on commit 1f49618

Please sign in to comment.