mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Implemented profile selection and creation
This commit is contained in:
parent
a959d10263
commit
fa30bd657b
@ -42,9 +42,12 @@ namespace Artemis.DAL
|
|||||||
if (!(prof.GameName?.Length > 1) || !(prof.KeyboardName?.Length > 1) || !(prof.Name?.Length > 1))
|
if (!(prof.GameName?.Length > 1) || !(prof.KeyboardName?.Length > 1) || !(prof.Name?.Length > 1))
|
||||||
throw new ArgumentException("Profile is invalid. Name, GameName and KeyboardName are required");
|
throw new ArgumentException("Profile is invalid. Name, GameName and KeyboardName are required");
|
||||||
|
|
||||||
var serialized = JsonConvert.SerializeObject(prof);
|
var path = ProfileFolder + $@"\{prof.KeyboardName}\{prof.GameName}";
|
||||||
var path = ProfileFolder + $@"\{prof.KeyboardName}\{prof.GameName}\{prof.Name}.json";
|
if (!Directory.Exists(path))
|
||||||
File.WriteAllText(path, serialized);
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
var serialized = JsonConvert.SerializeObject(prof, Formatting.Indented);
|
||||||
|
File.WriteAllText(path + $@"\{prof.Name}.json", serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ProfileModel> ReadProfiles()
|
private static List<ProfileModel> ReadProfiles()
|
||||||
|
|||||||
@ -1,14 +1,45 @@
|
|||||||
using Artemis.Components;
|
using System.Collections.Generic;
|
||||||
|
using Artemis.Components;
|
||||||
|
|
||||||
namespace Artemis.Models
|
namespace Artemis.Models
|
||||||
{
|
{
|
||||||
public class ProfileModel
|
public class ProfileModel
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public ProfileModel(string name, string keyboardName, string gameName)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
KeyboardName = keyboardName;
|
||||||
|
GameName = gameName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
public string KeyboardName { get; set; }
|
public string KeyboardName { get; set; }
|
||||||
public string GameName { get; set; }
|
public string GameName { get; set; }
|
||||||
|
|
||||||
public LayerComposite Layers { get; set; }
|
public LayerComposite Layers { get; set; }
|
||||||
|
|
||||||
|
protected bool Equals(ProfileModel other)
|
||||||
|
{
|
||||||
|
return string.Equals(Name, other.Name) && string.Equals(KeyboardName, other.KeyboardName) && string.Equals(GameName, other.GameName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
|
return Equals((ProfileModel) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
var hashCode = (Name != null ? Name.GetHashCode() : 0);
|
||||||
|
hashCode = (hashCode*397) ^ (KeyboardName != null ? KeyboardName.GetHashCode() : 0);
|
||||||
|
hashCode = (hashCode*397) ^ (GameName != null ? GameName.GetHashCode() : 0);
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -17,7 +17,7 @@ namespace Artemis.Modules.Games.TheDivision
|
|||||||
GameModel = new TheDivisionModel(mainManager, (TheDivisionSettings) GameSettings);
|
GameModel = new TheDivisionModel(mainManager, (TheDivisionSettings) GameSettings);
|
||||||
MainManager.EffectManager.EffectModels.Add(GameModel);
|
MainManager.EffectManager.EffectModels.Add(GameModel);
|
||||||
|
|
||||||
ProfileEditor = new ProfileEditorViewModel(GameModel, MainManager.KeyboardManager.ActiveKeyboard);
|
ProfileEditor = new ProfileEditorViewModel(MainManager, GameModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileEditorViewModel ProfileEditor { get; set; }
|
public ProfileEditorViewModel ProfileEditor { get; set; }
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Artemis.DAL;
|
using Artemis.DAL;
|
||||||
using Artemis.KeyboardProviders;
|
using Artemis.Managers;
|
||||||
using Artemis.Models;
|
using Artemis.Models;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
|
|
||||||
@ -10,20 +10,76 @@ namespace Artemis.ViewModels
|
|||||||
public class ProfileEditorViewModel : Screen
|
public class ProfileEditorViewModel : Screen
|
||||||
{
|
{
|
||||||
private readonly GameModel _gameModel;
|
private readonly GameModel _gameModel;
|
||||||
private readonly KeyboardProvider _keyboard;
|
private readonly MainManager _mainManager;
|
||||||
private List<ProfileModel> _profiles;
|
private BindableCollection<ProfileModel> _profileModels;
|
||||||
|
private ProfileModel _selectedProfileModel;
|
||||||
|
|
||||||
public ProfileEditorViewModel(GameModel gameModel, KeyboardProvider keyboard)
|
public ProfileEditorViewModel(MainManager mainManager, GameModel gameModel)
|
||||||
{
|
{
|
||||||
|
_mainManager = mainManager;
|
||||||
_gameModel = gameModel;
|
_gameModel = gameModel;
|
||||||
_keyboard = keyboard;
|
|
||||||
|
|
||||||
GetProfiles();
|
ProfileModels = new BindableCollection<ProfileModel>();
|
||||||
|
LoadProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetProfiles()
|
public BindableCollection<ProfileModel> ProfileModels
|
||||||
{
|
{
|
||||||
_profiles = ProfileProvider.GetAll(_gameModel);
|
get { return _profileModels; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (Equals(value, _profileModels)) return;
|
||||||
|
_profileModels = value;
|
||||||
|
NotifyOfPropertyChange(() => ProfileModels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProfileModel SelectedProfileModel
|
||||||
|
{
|
||||||
|
get { return _selectedProfileModel; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (Equals(value, _selectedProfileModel)) return;
|
||||||
|
_selectedProfileModel = value;
|
||||||
|
NotifyOfPropertyChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadProfiles()
|
||||||
|
{
|
||||||
|
ProfileModels.Clear();
|
||||||
|
ProfileModels.AddRange(ProfileProvider.GetAll(_gameModel));
|
||||||
|
SelectedProfileModel = ProfileModels.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void AddProfile()
|
||||||
|
{
|
||||||
|
var name =
|
||||||
|
await
|
||||||
|
_mainManager.DialogService.ShowInputDialog("Add new profile",
|
||||||
|
"Please provide a profile name unique to this game and keyboard.");
|
||||||
|
if (name.Length < 1)
|
||||||
|
{
|
||||||
|
_mainManager.DialogService.ShowMessageBox("Invalid profile name", "Please provide a valid profile name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var profile = new ProfileModel(name, _mainManager.KeyboardManager.ActiveKeyboard.Name, _gameModel.Name);
|
||||||
|
var test = ProfileProvider.GetAll();
|
||||||
|
if (test.Contains(profile))
|
||||||
|
{
|
||||||
|
var overwrite =
|
||||||
|
await
|
||||||
|
_mainManager.DialogService.ShowQuestionMessageBox("Overwrite existing profile",
|
||||||
|
"A profile with this name already exists for this game. Would you like to overwrite it?");
|
||||||
|
if (!overwrite.Value)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileProvider.AddOrUpdate(profile);
|
||||||
|
|
||||||
|
LoadProfiles();
|
||||||
|
SelectedProfileModel = profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageSource GenerateKeyboardImage()
|
private ImageSource GenerateKeyboardImage()
|
||||||
|
|||||||
@ -32,129 +32,20 @@
|
|||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\keyboards\k95.png" Margin="50" />
|
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\keyboards\k95.png" Margin="50" />
|
||||||
</Border>
|
</Border>
|
||||||
</Border>
|
</Border>
|
||||||
|
<!-- Profile management -->
|
||||||
|
<StackPanel Grid.Column="0" Grid.Row="2" Orientation="Horizontal" Margin="0,5,0,0">
|
||||||
|
<Label Content="Active profile"></Label>
|
||||||
|
<ComboBox Grid.Row="1" Grid.Column="1" Width="110" VerticalAlignment="Top" x:Name="ProfileModels" DisplayMemberPath="Name" Margin="5,0,0,0" />
|
||||||
|
<Button x:Name="AddProfile" Content="Add profile" VerticalAlignment="Top"
|
||||||
|
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10,0,0,0" />
|
||||||
|
<Button x:Name="RemoveProfile" Content="Remove profile" VerticalAlignment="Top"
|
||||||
|
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Right" Margin="10,0,0,0" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
<!-- Layer list -->
|
<!-- Layer list -->
|
||||||
<Label Grid.Column="1" Grid.Row="0" FontSize="20" HorizontalAlignment="Left" Content="Layers" Margin="10,0,0,0" />
|
<Label Grid.Column="1" Grid.Row="0" FontSize="20" HorizontalAlignment="Left" Content="Layers" Margin="10,0,0,0" />
|
||||||
<Border Grid.Column="1" Grid.Row="1" Background="#FF232323" BorderBrush="{DynamicResource HighlightBrush}"
|
<Border Grid.Column="1" Grid.Row="1" Background="#FF232323" BorderBrush="{DynamicResource HighlightBrush}"
|
||||||
BorderThickness="3" Margin="10,0,0,0" Height="400" Width="200">
|
BorderThickness="3" Margin="10,0,0,0" Height="400" Width="200">
|
||||||
<!--<ListView x:Name="ListView1" BorderThickness="0">
|
|
||||||
<ListView.Resources>
|
|
||||||
<ResourceDictionary
|
|
||||||
Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
|
|
||||||
</ListView.Resources>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\rect.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\rect.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
<ListViewItem>
|
|
||||||
<StackPanel Orientation="Horizontal" Margin="5">
|
|
||||||
<CheckBox VerticalAlignment="Center" />
|
|
||||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\Config concept\circle.png"
|
|
||||||
Height="30" Margin="5,0" />
|
|
||||||
<TextBlock Text="Layer" VerticalAlignment="Center" />
|
|
||||||
</StackPanel>
|
|
||||||
</ListViewItem>
|
|
||||||
</ListView>-->
|
|
||||||
<TreeView>
|
<TreeView>
|
||||||
<TreeView.Resources>
|
<TreeView.Resources>
|
||||||
<ResourceDictionary
|
<ResourceDictionary
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
|
xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
|
||||||
dialogs:DialogParticipation.Register="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"
|
dialogs:DialogParticipation.Register="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Artemis" Height="670" Width="690"
|
Title="Artemis" Height="800" Width="1200"
|
||||||
MinWidth="500" MinHeight="400"
|
MinWidth="500" MinHeight="400"
|
||||||
GlowBrush="{DynamicResource AccentColorBrush}" Icon="../logo.ico">
|
GlowBrush="{DynamicResource AccentColorBrush}" Icon="../logo.ico">
|
||||||
<!-- Bit of extra code to use a different icon than in the taskbar -->
|
<!-- Bit of extra code to use a different icon than in the taskbar -->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user