Modules - Added activation mechanism and conditions

This commit is contained in:
SpoinkyNL committed 2020-08-16 23:44:59 +02:00
1 parent 12456519d5
commit 6a32ecc3a4
17 files changed
+357 -149

No files matched your search

+2 -2
View File
@@ -51,13 +51,13 @@
</mde:MaterialWindow.Resources>
<materialDesign:DialogHost Identifier="RootDialog" DialogTheme="Inherit" SnackbarMessageQueue="{Binding MainMessageQueue}">
<Grid>
<materialDesign:DrawerHost IsLeftDrawerOpen="{Binding IsSidebarVisible}">
<materialDesign:DrawerHost IsLeftDrawerOpen="{Binding SidebarViewModel.IsSidebarOpen}">
<materialDesign:DrawerHost.LeftDrawerContent>
<ContentControl s:View.Model="{Binding SidebarViewModel}" Width="220" ClipToBounds="False" />
</materialDesign:DrawerHost.LeftDrawerContent>
<DockPanel>
<mde:AppBar Type="Dense"
IsNavigationDrawerOpen="{Binding IsSidebarVisible, Mode=TwoWay}"
IsNavigationDrawerOpen="{Binding SidebarViewModel.IsSidebarOpen, Mode=TwoWay}"
Title="{Binding ActiveItem.DisplayName}"
ShowNavigationDrawerButton="True"
DockPanel.Dock="Top">
+3 -9
View File
@@ -66,13 +66,7 @@ namespace Artemis.UI.Screens
get => _mainMessageQueue;
set => SetAndNotify(ref _mainMessageQueue, value);
}
public bool IsSidebarVisible
{
get => _isSidebarVisible;
set => SetAndNotify(ref _isSidebarVisible, value);
}
public bool ActiveItemReady
{
get => _activeItemReady;
@@ -140,7 +134,7 @@ namespace Artemis.UI.Screens
{
if (e.PropertyName == nameof(SidebarViewModel.SelectedItem))
{
IsSidebarVisible = false;
SidebarViewModel.IsSidebarOpen = false;
ActiveItemReady = false;
// Allow the menu to close, it's slower but feels more responsive, funny how that works right
@@ -254,7 +248,7 @@ namespace Artemis.UI.Screens
protected override void OnClose()
{
SidebarViewModel.Dispose();
// Lets force the GC to run after closing the window so it is obvious to users watching task manager
// that closing the UI will decrease the memory footprint of the application.
+13 -16
View File
@@ -10,22 +10,19 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance sidebar:SidebarViewModel}">
<StackPanel>
<!-- Placeholder -->
<StackPanel Margin="15">
<materialDesign:PackIcon Kind="QuestionMarkCircle" Width="50" Height="50" />
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}" Margin="0 15 0 0">
Active module
</TextBlock>
<ComboBox BorderThickness="0" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" materialDesign:HintAssist.Hint="Active profile">
<ComboBoxItem>Profile 1</ComboBoxItem>
<ComboBoxItem>Profile 2</ComboBoxItem>
<ComboBoxItem>Profile 3</ComboBoxItem>
<ComboBoxItem>Profile 4</ComboBoxItem>
</ComboBox>
</StackPanel>
<Grid>
<Grid.RowDefinitions>
<!-- no idea why this has to be 0 -->
<RowDefinition Height="0" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<controls:SideNavigation Items="{Binding SidebarItems}" SelectedItem="{Binding SelectedItem}" WillSelectNavigationItemCommand="{s:Action SelectItem}" />
</StackPanel>
<Image Grid.Row="0" Grid.RowSpan="2" Source="/Resources/Images/Sidebar/sidebar-header.png" Stretch="Uniform" VerticalAlignment="Top" />
<TextBlock Grid.Row="1" Style="{StaticResource MaterialDesignHeadline6TextBlock}" Margin="15" materialDesign:ShadowAssist.ShadowDepth="Depth1" Text="{Binding ActiveModules}"/>
<controls:SideNavigation Grid.Row="3" Items="{Binding SidebarItems}" SelectedItem="{Binding SelectedItem}" WillSelectNavigationItemCommand="{s:Action SelectItem}" Margin="0 5 0 0"/>
</Grid>
</UserControl>
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using Artemis.Core.Events;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Events;
@@ -27,6 +28,9 @@ namespace Artemis.UI.Screens.Sidebar
private BindableCollection<INavigationItem> _sidebarItems;
private Dictionary<INavigationItem, Core.Plugins.Abstract.Module> _sidebarModules;
private IScreen _selectedItem;
private bool _isSidebarOpen;
private readonly Timer _activeModulesUpdateTimer;
private string _activeModules;
public SidebarViewModel(IKernel kernel, IEventAggregator eventAggregator, IModuleVmFactory moduleVmFactory, IPluginService pluginService)
{
@@ -37,6 +41,10 @@ namespace Artemis.UI.Screens.Sidebar
SidebarModules = new Dictionary<INavigationItem, Core.Plugins.Abstract.Module>();
SidebarItems = new BindableCollection<INavigationItem>();
_activeModulesUpdateTimer = new Timer(1000);
_activeModulesUpdateTimer.Start();
_activeModulesUpdateTimer.Elapsed += ActiveModulesUpdateTimerOnElapsed;
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
@@ -44,6 +52,15 @@ namespace Artemis.UI.Screens.Sidebar
eventAggregator.Subscribe(this);
}
private void ActiveModulesUpdateTimerOnElapsed(object sender, EventArgs e)
{
if (!IsSidebarOpen)
return;
var activeModules = SidebarModules.Count(m => m.Value.IsActivated);
ActiveModules = activeModules == 1 ? "1 active module" : $"{activeModules} active modules";
}
public BindableCollection<INavigationItem> SidebarItems
{
get => _sidebarItems;
@@ -56,19 +73,35 @@ namespace Artemis.UI.Screens.Sidebar
set => SetAndNotify(ref _sidebarModules, value);
}
public string ActiveModules
{
get => _activeModules;
set => SetAndNotify(ref _activeModules, value);
}
public IScreen SelectedItem
{
get => _selectedItem;
set => SetAndNotify(ref _selectedItem, value);
}
public bool IsSidebarOpen
{
get => _isSidebarOpen;
set
{
SetAndNotify(ref _isSidebarOpen, value);
if (value)
ActiveModulesUpdateTimerOnElapsed(this, EventArgs.Empty);
}
}
public void SetupSidebar()
{
SidebarItems.Clear();
SidebarItems.Clear();
SidebarModules.Clear();
// Add all default sidebar items
SidebarItems.Add(new DividerNavigationItem());
SidebarItems.Add(new FirstLevelNavigationItem {Icon = PackIconKind.Home, Label = "Home"});
SidebarItems.Add(new FirstLevelNavigationItem {Icon = PackIconKind.Newspaper, Label = "News"});
SidebarItems.Add(new FirstLevelNavigationItem {Icon = PackIconKind.TestTube, Label = "Workshop"});
@@ -83,7 +116,7 @@ namespace Artemis.UI.Screens.Sidebar
AddModule(module);
// Select the top item, which will be one of the defaults
Task.Run(() => SelectSidebarItem(SidebarItems[1]));
Task.Run(() => SelectSidebarItem(SidebarItems[0]));
}
// ReSharper disable once UnusedMember.Global - Called by view
@@ -202,6 +235,9 @@ namespace Artemis.UI.Screens.Sidebar
_pluginService.PluginEnabled -= PluginServiceOnPluginEnabled;
_pluginService.PluginDisabled -= PluginServiceOnPluginDisabled;
_activeModulesUpdateTimer.Stop();
_activeModulesUpdateTimer.Elapsed -= ActiveModulesUpdateTimerOnElapsed;
}
}
}