1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Implemented popups using MahApps

This commit is contained in:
SpoinkyNL 2016-02-29 22:29:30 +01:00
parent d1e17c8dcd
commit 6ccfaf45d5
14 changed files with 289 additions and 51 deletions

View File

@ -1,14 +1,14 @@
<Application x:Class="Artemis.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Artemis"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:artemis="clr-namespace:Artemis"
DispatcherUnhandledException="Application_DispatcherUnhandledException"
ShutdownMode="OnExplicitShutdown">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<local:ArtemisBootstrapper x:Key="ArtemisBootstrapper" />
<artemis:ArtemisBootstrapper x:Key="ArtemisBootstrapper" />
</ResourceDictionary>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />

View File

@ -301,6 +301,8 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Services\DialogService.cs" />
<Compile Include="Services\MetroDialogService.cs" />
<Compile Include="Settings\General.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>

View File

@ -16,8 +16,8 @@ namespace Artemis.KeyboardProviders.Corsair
public CorsairRGB()
{
Name = "Corsair RGB Keyboards";
CantEnableText = "Couldn't connect to your Corsair keyboard.\n " +
"Please check your cables and/or drivers (could be outdated) and that Corsair Utility Engine is running.\n\n " +
CantEnableText = "Couldn't connect to your Corsair keyboard.\n" +
"Please check your cables and/or drivers (could be outdated) and that Corsair Utility Engine is running.\n\n" +
"If needed, you can select a different keyboard in Artemis under settings.";
KeyboardRegions = new List<KeyboardRegion>();
}

View File

@ -143,6 +143,8 @@ namespace Artemis.Managers
General.Default.LastEffect = null;
General.Default.Save();
_events.PublishOnUIThread(new ActiveEffectChanged(""));
_clearing = false;
_mainManager.Unpause();
}

View File

@ -9,7 +9,6 @@ namespace Artemis.Managers
public class KeyboardManager
{
private readonly MainManager _mainManager;
private KeyboardProvider _pauseKeyboard;
public KeyboardManager(MainManager mainManager)
{
@ -52,8 +51,9 @@ namespace Artemis.Managers
// Disable everything if there's no active keyboard found
if (!keyboardProvider.CanEnable())
{
MessageBox.Show(keyboardProvider.CantEnableText, "Artemis (╯°□°)╯︵ ┻━┻", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
_mainManager.DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText);
//MessageBox.Show(keyboardProvider.CantEnableText, "Artemis (╯°□°)╯︵ ┻━┻", MessageBoxButtons.OK,
// MessageBoxIcon.Warning);
return;
}

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading;
using Artemis.Events;
using Artemis.Models;
using Artemis.Services;
using Artemis.Utilities.GameState;
using Artemis.Utilities.Keyboard;
using Caliburn.Micro;
@ -18,9 +19,10 @@ namespace Artemis.Managers
private bool _paused;
private bool _restarting;
public MainManager(IEventAggregator events)
public MainManager(IEventAggregator events, MetroDialogService dialogService)
{
Events = events;
DialogService = dialogService;
KeyboardManager = new KeyboardManager(this);
EffectManager = new EffectManager(this, Events);
@ -57,6 +59,7 @@ namespace Artemis.Managers
public GameStateWebServer GameStateWebServer { get; set; }
public IEventAggregator Events { get; set; }
public MetroDialogService DialogService { get; set; }
public bool ProgramEnabled { get; private set; }
public bool Suspended { get; set; }

View File

@ -0,0 +1,48 @@
//The MIT License(MIT)
//Copyright(c) 2015 ihtfw
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System;
using System.Threading.Tasks;
namespace Artemis.Services
{
public abstract class DialogService
{
public void ShowErrorMessageBox(Exception e)
{
ShowErrorMessageBox(e.Message);
}
public void ShowErrorMessageBox(string message)
{
ShowMessageBox("Error", message);
}
public abstract void ShowMessageBox(string title, string message);
public abstract bool ShowOpenDialog(out string path, string defaultExt, string filter, string initialDir = null);
public abstract Task<string> ShowInputDialog(string title, string message);
public abstract Task<bool?> ShowQuestionMessageBox(string title, string message);
}
}

View File

@ -0,0 +1,143 @@
//The MIT License(MIT)
//Copyright(c) 2015 ihtfw
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Artemis.ViewModels;
using Caliburn.Micro;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.Win32;
namespace Artemis.Services
{
public class MetroDialogService : DialogService
{
private readonly ShellViewModel _shellViewModel;
public MetroDialogService(ShellViewModel shellViewModel)
{
_shellViewModel = shellViewModel;
}
private MetroWindow GetActiveWindow()
{
MetroWindow window = null;
Execute.OnUIThread(() =>
{
window = Application.Current.Windows.OfType<MetroWindow>().FirstOrDefault(w => w.IsActive);
if (window == null)
{
window = Application.Current.Windows.OfType<MetroWindow>().FirstOrDefault();
}
});
return window;
}
public override void ShowMessageBox(string title, string message)
{
if (_shellViewModel.IsActive == false)
return;
Execute.OnUIThread(() => GetActiveWindow().ShowMessageAsync(title, message));
}
public override async Task<bool?> ShowQuestionMessageBox(string title, string message)
{
if (_shellViewModel.IsActive == false)
return null;
var metroDialogSettings = new MetroDialogSettings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"};
var result =
await
GetActiveWindow()
.ShowMessageAsync(title, message, MessageDialogStyle.AffirmativeAndNegative, metroDialogSettings);
switch (result)
{
case MessageDialogResult.Negative:
return false;
case MessageDialogResult.Affirmative:
return true;
default:
return null;
}
}
public override Task<string> ShowInputDialog(string title, string message)
{
if (_shellViewModel.IsActive == false)
return null;
return GetActiveWindow().ShowInputAsync(title, message);
}
public override bool ShowOpenDialog(out string path, string defaultExt, string filter, string initialDir = null)
{
if (_shellViewModel.IsActive == false)
{
path = null;
return false;
}
bool? res = null;
string lPath = null;
Execute.OnUIThread(() =>
{
var ofd = new OpenFileDialog
{
DefaultExt = defaultExt,
Filter = filter
};
if (initialDir != null)
{
ofd.InitialDirectory = initialDir;
}
if (Application.Current.MainWindow != null)
{
res = ofd.ShowDialog(Application.Current.MainWindow);
}
else
{
res = ofd.ShowDialog();
}
if (res == true)
{
lPath = ofd.FileName;
}
else
{
res = false;
}
});
path = lPath;
return res.Value;
}
}
}

View File

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Windows.Forms;
using System.Threading.Tasks;
using Artemis.Models;
using Artemis.Services;
using Artemis.Settings;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -15,20 +16,25 @@ namespace Artemis.Utilities
{
public static int CurrentVersion = 100;
public static void CheckForUpdate()
public static async Task<Action> CheckForUpdate(MetroDialogService dialogService)
{
if (!General.Default.CheckForUpdates)
return null;
var newRelease = IsUpdateAvailable();
if (newRelease == null)
return;
return null;
var viewUpdate =
MessageBox.Show(
var viewUpdate = await
dialogService.ShowQuestionMessageBox("Update available",
$"A new version of Artemis is available, version {newRelease["tag_name"].Value<string>()}.\n" +
"Do you wish to view the update on GitHub now?\n\n" +
"Note: You can disable update notifications in the settings menu", "Artemis - Update available",
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (viewUpdate == DialogResult.Yes)
"Note: You can disable update notifications in the settings menu");
if (viewUpdate.Value)
Process.Start(new ProcessStartInfo(newRelease["html_url"].Value<string>()));
return null;
}
public static JObject IsUpdateAvailable()

View File

@ -8,8 +8,9 @@ using MahApps.Metro.Controls;
namespace Artemis.ViewModels.Flyouts
{
public class FlyoutSettingsViewModel : FlyoutBaseViewModel, IHandle<ToggleEnabled>
public class FlyoutSettingsViewModel : FlyoutBaseViewModel, IHandle<ToggleEnabled>, IHandle<ActiveEffectChanged>
{
private string _activeEffectName;
private bool _enabled;
private GeneralSettings _generalSettings;
private string _selectedKeyboardProvider;
@ -77,6 +78,23 @@ namespace Artemis.ViewModels.Flyouts
}
}
public string ActiveEffectName
{
get { return _activeEffectName; }
set
{
if (value == _activeEffectName) return;
_activeEffectName = value;
NotifyOfPropertyChange(() => ActiveEffectName);
}
}
public void Handle(ActiveEffectChanged message)
{
var effectDisplay = message.ActiveEffect.Length > 0 ? message.ActiveEffect : "none";
ActiveEffectName = $"Active effect: {effectDisplay}";
}
public void Handle(ToggleEnabled message)
{
NotifyOfPropertyChange(() => Enabled);
@ -108,8 +126,8 @@ namespace Artemis.ViewModels.Flyouts
protected override void HandleOpen()
{
SelectedKeyboardProvider = MainManager.KeyboardManager.ActiveKeyboard != null
? MainManager.KeyboardManager.ActiveKeyboard.Name
SelectedKeyboardProvider = General.Default.LastKeyboard.Length > 0
? General.Default.LastKeyboard
: "None";
}
}

View File

@ -1,5 +1,6 @@
using System.Linq;
using Artemis.Managers;
using Artemis.Services;
using Artemis.ViewModels.Flyouts;
using Caliburn.Micro;
@ -14,8 +15,10 @@ namespace Artemis.ViewModels
public ShellViewModel()
{
var dialogService = new MetroDialogService(this);
IEventAggregator events = new EventAggregator();
MainManager = new MainManager(events);
MainManager = new MainManager(events, dialogService);
DisplayName = "Artemis";
_welcomeVm = new WelcomeViewModel {DisplayName = "Welcome"};

View File

@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using Artemis.Events;
using Artemis.Settings;
using Artemis.Utilities;
using Caliburn.Micro;
@ -15,14 +15,6 @@ namespace Artemis.ViewModels
private bool _checkedForUpdate;
private bool _enabled;
private string _toggleText;
/*
* NOTE: In this sample the system tray view-model doesn't receive any notification
* when the other window gets closed by pressing the top right 'x'.
* Thus no property notification is invoked, and system tray context-menu appears
* out of sync, still allowing 'Hide' and disabling 'Show'.
* Given the purpose of the sample - integrating Caliburn.Micro with WPF NotifyIcon -
* syncing the two view-models is not of interest here.
* */
public SystemTrayViewModel(IWindowManager windowManager, ShellViewModel shellViewModel)
{
@ -32,7 +24,8 @@ namespace Artemis.ViewModels
_shellViewModel.MainManager.EnableProgram();
_checkedForUpdate = false;
// TODO: Check if show on startup is enabled, if so, show window.
if (General.Default.ShowOnStartup)
ShowWindow();
}
public bool CanShowWindow => !_shellViewModel.IsActive;
@ -89,18 +82,17 @@ namespace Artemis.ViewModels
if (!CanShowWindow)
return;
if (!_checkedForUpdate)
{
_checkedForUpdate = true;
var updateTask = new Task(Updater.CheckForUpdate);
updateTask.Start();
}
// manually show the next window view-model
_windowManager.ShowWindow(_shellViewModel);
NotifyOfPropertyChange(() => CanShowWindow);
NotifyOfPropertyChange(() => CanHideWindow);
if (_checkedForUpdate)
return;
_checkedForUpdate = true;
Updater.CheckForUpdate(_shellViewModel.MainManager.DialogService);
}

View File

@ -6,7 +6,7 @@
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
d:DesignHeight="600" d:DesignWidth="300"
Width="300">
<UserControl.Resources>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
@ -24,6 +24,8 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
@ -41,38 +43,52 @@
IsChecked="{Binding Path=GeneralSettings.Autorun, Mode=TwoWay}"
VerticalAlignment="Center" HorizontalAlignment="Right" Width="125" />
<!-- Keyboard selection -->
<!-- Show on startup -->
<Label Grid.Row="2" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
Content="Show on startup:" />
<controls:ToggleSwitch Grid.Row="2" Grid.Column="1" Margin="5" OnLabel="Yes" OffLabel="No"
IsChecked="{Binding Path=GeneralSettings.ShowOnStartup, Mode=TwoWay}"
VerticalAlignment="Center" HorizontalAlignment="Right" Width="125" />
<!-- Keyboard selection -->
<Label Grid.Row="3" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
Content="Keyboard:" />
<ComboBox Grid.Row="2" Grid.Column="1" x:Name="KeyboardProviders" Margin="10" VerticalAlignment="Center"
<ComboBox Grid.Row="3" Grid.Column="1" x:Name="KeyboardProviders" Margin="10" VerticalAlignment="Center"
HorizontalAlignment="Right"
Width="140" />
<!-- TODO: Ugly -->
<!-- Gamestate port -->
<Label Grid.Row="3" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
<Label Grid.Row="4" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
Content="Gamestate server port:" />
<controls:NumericUpDown Grid.Row="3" Grid.Column="1" Margin="10" VerticalAlignment="Center"
<controls:NumericUpDown Grid.Row="4" Grid.Column="1" Margin="10" VerticalAlignment="Center"
HorizontalAlignment="Right" Width="120"
Value="{Binding Path=GeneralSettings.GamestatePort, Mode=TwoWay}" />
<!-- Updates check -->
<Label Grid.Row="5" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
Content="Check for updates:" />
<controls:ToggleSwitch Grid.Row="5" Grid.Column="1" Margin="5" OnLabel="Yes" OffLabel="No"
VerticalAlignment="Center" HorizontalAlignment="Right" Width="125"
IsChecked="{Binding Path=GeneralSettings.CheckForUpdates, Mode=TwoWay}" />
<!-- Update pointers -->
<Label Grid.Row="4" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
<Label Grid.Row="6" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
Content="Download pointers:" />
<controls:ToggleSwitch Grid.Row="4" Grid.Column="1" Margin="5" OnLabel="Yes" OffLabel="No"
<controls:ToggleSwitch Grid.Row="6" Grid.Column="1" Margin="5" OnLabel="Yes" OffLabel="No"
VerticalAlignment="Center" HorizontalAlignment="Right" Width="125"
IsChecked="{Binding Path=GeneralSettings.EnablePointersUpdate, Mode=TwoWay}" />
<!-- Buttons -->
<Button Grid.Row="5" Grid.Column="0" Margin="10" x:Name="ResetSettings" Content="Reset settings"
<Button Grid.Row="7" Grid.Column="0" Margin="10" x:Name="ResetSettings" Content="Reset settings"
VerticalAlignment="Center" HorizontalAlignment="Left" Width="120"
Style="{DynamicResource SquareButtonStyle}" />
<Button Grid.Row="5" Grid.Column="1" Margin="10" x:Name="SaveSettings" Content="Save changes"
<Button Grid.Row="7" Grid.Column="1" Margin="10" x:Name="SaveSettings" Content="Save changes"
VerticalAlignment="Center" HorizontalAlignment="Right" Width="120"
Style="{DynamicResource SquareButtonStyle}" />
<!-- Version -->
<Grid Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Margin="10" VerticalAlignment="Bottom">
<Grid Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2" Margin="10" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
@ -81,11 +97,14 @@
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Artemis 1.0.1" VerticalAlignment="Center"
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" x:Name="ActiveEffectName" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="Artemis 1.0.2" VerticalAlignment="Center"
HorizontalAlignment="Left" />
<Button Grid.Row="0" Grid.Column="1" Focusable="False" Style="{StaticResource AccentedSquareButtonStyle}"
<Button Grid.Row="1" Grid.Column="1" Focusable="False"
Style="{StaticResource AccentedSquareButtonStyle}"
cal:Message.Attach="[Action NavigateTo('https://github.com/SpoinkyNL/Artemis')]"
Content="View on GitHub" Margin="5,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Right" />
Content="View on GitHub" Margin="5,0,0,0" VerticalAlignment="Center"
HorizontalAlignment="Right" />
</Grid>
</Grid>
</UserControl>

View File

@ -5,6 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:cal="http://www.caliburnproject.org"
xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
dialogs:DialogParticipation.Register="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"
mc:Ignorable="d"
Title="Artemis" Height="670" Width="690"
MinWidth="500" MinHeight="400"