mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Modules - Added activation mechanism and conditions
This commit is contained in:
1 parent
2cf64df35d
commit
830ef33b0a
17 files changed
+357
-149
No files matched your search
@@ -121,6 +121,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Resources\Cursors\aero_rotate.cur" />
|
||||
<Resource Include="Resources\Images\Sidebar\sidebar-header.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentValidation" Version="8.6.2" />
|
||||
@@ -296,6 +297,7 @@
|
||||
<ItemGroup>
|
||||
<None Remove="Resources\Fonts\RobotoMono-Regular.ttf" />
|
||||
<None Remove="Resources\Images\Logo\logo-512.ico" />
|
||||
<None Remove="Resources\Images\Sidebar\sidebar-header.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 7.3 KiB |
@@ -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">
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user