mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +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))
|
||||
throw new ArgumentException("Profile is invalid. Name, GameName and KeyboardName are required");
|
||||
|
||||
var serialized = JsonConvert.SerializeObject(prof);
|
||||
var path = ProfileFolder + $@"\{prof.KeyboardName}\{prof.GameName}\{prof.Name}.json";
|
||||
File.WriteAllText(path, serialized);
|
||||
var path = ProfileFolder + $@"\{prof.KeyboardName}\{prof.GameName}";
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
var serialized = JsonConvert.SerializeObject(prof, Formatting.Indented);
|
||||
File.WriteAllText(path + $@"\{prof.Name}.json", serialized);
|
||||
}
|
||||
|
||||
private static List<ProfileModel> ReadProfiles()
|
||||
|
||||
@ -1,14 +1,45 @@
|
||||
using Artemis.Components;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Components;
|
||||
|
||||
namespace Artemis.Models
|
||||
{
|
||||
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 GameName { 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);
|
||||
MainManager.EffectManager.EffectModels.Add(GameModel);
|
||||
|
||||
ProfileEditor = new ProfileEditorViewModel(GameModel, MainManager.KeyboardManager.ActiveKeyboard);
|
||||
ProfileEditor = new ProfileEditorViewModel(MainManager, GameModel);
|
||||
}
|
||||
|
||||
public ProfileEditorViewModel ProfileEditor { get; set; }
|
||||
|
||||
@ -1,24 +1,24 @@
|
||||
//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.
|
||||
// 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;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using Artemis.DAL;
|
||||
using Artemis.KeyboardProviders;
|
||||
using Artemis.Managers;
|
||||
using Artemis.Models;
|
||||
using Caliburn.Micro;
|
||||
|
||||
@ -10,20 +10,76 @@ namespace Artemis.ViewModels
|
||||
public class ProfileEditorViewModel : Screen
|
||||
{
|
||||
private readonly GameModel _gameModel;
|
||||
private readonly KeyboardProvider _keyboard;
|
||||
private List<ProfileModel> _profiles;
|
||||
private readonly MainManager _mainManager;
|
||||
private BindableCollection<ProfileModel> _profileModels;
|
||||
private ProfileModel _selectedProfileModel;
|
||||
|
||||
public ProfileEditorViewModel(GameModel gameModel, KeyboardProvider keyboard)
|
||||
public ProfileEditorViewModel(MainManager mainManager, GameModel gameModel)
|
||||
{
|
||||
_mainManager = mainManager;
|
||||
_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()
|
||||
|
||||
@ -32,129 +32,20 @@
|
||||
<Image Source="D:\Gebruiker folder\Mijn afbeeldingen\Artemis logo\keyboards\k95.png" Margin="50" />
|
||||
</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 -->
|
||||
<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}"
|
||||
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.Resources>
|
||||
<ResourceDictionary
|
||||
@ -172,22 +63,22 @@
|
||||
</StackPanel>
|
||||
</TreeViewItem.Header>
|
||||
<!-- Context menu -->
|
||||
<TreeViewItem.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Rename" />
|
||||
<MenuItem Header="Delete" />
|
||||
<MenuItem Header="Properties" />
|
||||
</ContextMenu>
|
||||
<TreeViewItem.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Rename" />
|
||||
<MenuItem Header="Delete" />
|
||||
<MenuItem Header="Properties" />
|
||||
</ContextMenu>
|
||||
</TreeViewItem.ContextMenu>
|
||||
</TreeViewItem>
|
||||
<TreeViewItem Header="Group 1">
|
||||
<!-- Context menu -->
|
||||
<TreeViewItem.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Rename" />
|
||||
<MenuItem Header="Delete" />
|
||||
<MenuItem Header="Properties" />
|
||||
</ContextMenu>
|
||||
<TreeViewItem.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Rename" />
|
||||
<MenuItem Header="Delete" />
|
||||
<MenuItem Header="Properties" />
|
||||
</ContextMenu>
|
||||
</TreeViewItem.ContextMenu>
|
||||
<!-- Group example -->
|
||||
<TreeViewItem>
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
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"
|
||||
Title="Artemis" Height="800" Width="1200"
|
||||
MinWidth="500" MinHeight="400"
|
||||
GlowBrush="{DynamicResource AccentColorBrush}" Icon="../logo.ico">
|
||||
<!-- Bit of extra code to use a different icon than in the taskbar -->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user