mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Layer editor progress
This commit is contained in:
parent
1d648fe606
commit
1a6c4d55da
@ -378,6 +378,7 @@
|
||||
<DependentUpon>Offsets.settings</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Utilities\ColorHelpers.cs" />
|
||||
<Compile Include="Utilities\ExtensionMethods.cs" />
|
||||
<Compile Include="Utilities\GameState\GameDataReceivedEventArgs.cs" />
|
||||
<Compile Include="Utilities\GameState\GameStateWebServer.cs" />
|
||||
<Compile Include="Utilities\GeneralHelpers.cs" />
|
||||
|
||||
@ -11,8 +11,6 @@ namespace Artemis.KeyboardProviders.Logitech
|
||||
{
|
||||
internal class Orion : KeyboardProvider
|
||||
{
|
||||
private string _versionString;
|
||||
|
||||
public Orion()
|
||||
{
|
||||
Name = "Logitech G910 RGB";
|
||||
|
||||
12
Artemis/Artemis/Utilities/ExtensionMethods.cs
Normal file
12
Artemis/Artemis/Utilities/ExtensionMethods.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Artemis.Utilities
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
{
|
||||
public static string SplitCamelCase(this string str)
|
||||
{
|
||||
return Regex.Replace(Regex.Replace(str, @"(\P{Ll})(\P{Ll}\p{Ll})", "$1 $2"), @"(\p{Ll})(\P{Ll})", "$1 $2");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,6 @@ namespace Artemis.ViewModels.Flyouts
|
||||
public class FlyoutSettingsViewModel : FlyoutBaseViewModel, IHandle<ToggleEnabled>, IHandle<ActiveEffectChanged>
|
||||
{
|
||||
private string _activeEffectName;
|
||||
private bool _enabled;
|
||||
private GeneralSettings _generalSettings;
|
||||
private string _selectedKeyboardProvider;
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ namespace Artemis.ViewModels
|
||||
_counterStrikeVm = new CounterStrikeViewModel(mainManager) {DisplayName = "CS:GO"};
|
||||
_dota2Vm = new Dota2ViewModel(mainManager) {DisplayName = "Dota 2"};
|
||||
_witcher3Vm = new Witcher3ViewModel(mainManager) {DisplayName = "The Witcher 3"};
|
||||
// _divisionVm = new TheDivisionViewModel(mainManager) {DisplayName = "The Division"};
|
||||
_divisionVm = new TheDivisionViewModel(mainManager) {DisplayName = "The Division"};
|
||||
}
|
||||
|
||||
protected override void OnActivate()
|
||||
@ -33,7 +33,7 @@ namespace Artemis.ViewModels
|
||||
ActivateItem(_counterStrikeVm);
|
||||
ActivateItem(_dota2Vm);
|
||||
ActivateItem(_witcher3Vm);
|
||||
// ActivateItem(_divisionVm);
|
||||
ActivateItem(_divisionVm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Artemis.Models.Profiles;
|
||||
using Artemis.Utilities;
|
||||
using Caliburn.Micro;
|
||||
@ -7,24 +8,67 @@ namespace Artemis.ViewModels.LayerEditor
|
||||
{
|
||||
public class LayerConditionViewModel<T> : Screen
|
||||
{
|
||||
private readonly NamedOperator[] _boolOperators =
|
||||
{
|
||||
new NamedOperator("True", "== True"),
|
||||
new NamedOperator("False", "== False")
|
||||
};
|
||||
|
||||
private readonly LayerEditorViewModel<T> _conditionModel;
|
||||
|
||||
private readonly NamedOperator[] _int32Operators =
|
||||
{
|
||||
new NamedOperator("Lower than", "<"),
|
||||
new NamedOperator("Lower or equal to", "<="),
|
||||
new NamedOperator("Higher than", ">"),
|
||||
new NamedOperator("Higher or equal to", ">="),
|
||||
new NamedOperator("Equal to", "=="),
|
||||
new NamedOperator("Not equal to", "!=")
|
||||
};
|
||||
|
||||
private readonly NamedOperator[] _operators =
|
||||
{
|
||||
new NamedOperator("Equal to", "=="),
|
||||
new NamedOperator("Not equal to", "!=")
|
||||
};
|
||||
|
||||
private bool _preselecting;
|
||||
|
||||
private GeneralHelpers.PropertyCollection _selectedDataModelProp;
|
||||
private string _selectedOperator;
|
||||
private NamedOperator _selectedOperator;
|
||||
private string _userValue;
|
||||
private bool _userValueIsVisible;
|
||||
|
||||
public LayerConditionViewModel(LayerEditorViewModel<T> conditionModel, LayerConditionModel layerConditionModel,
|
||||
BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps)
|
||||
{
|
||||
_conditionModel = conditionModel;
|
||||
_preselecting = false;
|
||||
|
||||
LayerConditionModel = layerConditionModel;
|
||||
DataModelProps = dataModelProps;
|
||||
Operators = new BindableCollection<string>();
|
||||
Operators = new BindableCollection<NamedOperator>();
|
||||
|
||||
PropertyChanged += UpdateModel;
|
||||
PropertyChanged += UpdateForm;
|
||||
|
||||
PreSelect();
|
||||
}
|
||||
|
||||
public string UserValue
|
||||
{
|
||||
get { return _userValue; }
|
||||
set
|
||||
{
|
||||
if (value == _userValue) return;
|
||||
_userValue = value;
|
||||
NotifyOfPropertyChange(() => UserValue);
|
||||
}
|
||||
}
|
||||
|
||||
public LayerConditionModel LayerConditionModel { get; set; }
|
||||
public BindableCollection<GeneralHelpers.PropertyCollection> DataModelProps { get; set; }
|
||||
public BindableCollection<string> Operators { get; set; }
|
||||
public BindableCollection<NamedOperator> Operators { get; set; }
|
||||
|
||||
public GeneralHelpers.PropertyCollection SelectedDataModelProp
|
||||
{
|
||||
@ -33,21 +77,10 @@ namespace Artemis.ViewModels.LayerEditor
|
||||
{
|
||||
if (value.Equals(_selectedDataModelProp)) return;
|
||||
_selectedDataModelProp = value;
|
||||
OnSelectedItemChangedAction(_selectedDataModelProp);
|
||||
NotifyOfPropertyChange(() => SelectedDataModelProp);
|
||||
}
|
||||
}
|
||||
|
||||
public string SelectedOperator
|
||||
{
|
||||
get { return _selectedOperator; }
|
||||
set
|
||||
{
|
||||
if (value == _selectedOperator) return;
|
||||
_selectedOperator = value;
|
||||
NotifyOfPropertyChange(() => SelectedOperator);
|
||||
}
|
||||
}
|
||||
|
||||
public bool UserValueIsVisible
|
||||
{
|
||||
@ -60,31 +93,47 @@ namespace Artemis.ViewModels.LayerEditor
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSelectedItemChangedAction(GeneralHelpers.PropertyCollection prop)
|
||||
public NamedOperator SelectedOperator
|
||||
{
|
||||
Operators.Clear();
|
||||
if (prop.EnumValues != null)
|
||||
get { return _selectedOperator; }
|
||||
set
|
||||
{
|
||||
Operators.AddRange(prop.EnumValues);
|
||||
if (value.Equals(_selectedOperator)) return;
|
||||
_selectedOperator = value;
|
||||
NotifyOfPropertyChange(() => SelectedOperator);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles updating the form to match the selected data model property
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void UpdateForm(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName != "SelectedDataModelProp")
|
||||
return;
|
||||
|
||||
Operators.Clear();
|
||||
if (SelectedDataModelProp.EnumValues != null)
|
||||
{
|
||||
Operators.AddRange(
|
||||
SelectedDataModelProp.EnumValues.Select(val => new NamedOperator(val.SplitCamelCase(), "== " + val)));
|
||||
UserValueIsVisible = false;
|
||||
}
|
||||
else
|
||||
switch (prop.Type)
|
||||
switch (SelectedDataModelProp.Type)
|
||||
{
|
||||
case "Int32":
|
||||
Operators.AddRange(new[]
|
||||
{
|
||||
"Lower than", "Lower or equal to", "Higher than", "Higher or equal to", "Equal to",
|
||||
"Not equal to"
|
||||
});
|
||||
Operators.AddRange(_int32Operators);
|
||||
UserValueIsVisible = true;
|
||||
break;
|
||||
case "Boolean":
|
||||
Operators.AddRange(new[] {"False", "True"});
|
||||
Operators.AddRange(_boolOperators);
|
||||
UserValueIsVisible = false;
|
||||
break;
|
||||
default:
|
||||
Operators.AddRange(new[] {"Equal to", "Not equal to"});
|
||||
Operators.AddRange(_operators);
|
||||
UserValueIsVisible = true;
|
||||
break;
|
||||
}
|
||||
@ -92,9 +141,59 @@ namespace Artemis.ViewModels.LayerEditor
|
||||
SelectedOperator = Operators.First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles saving user input to the model
|
||||
/// TODO: Data validation?
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void UpdateModel(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
// Don't mess with model during preselect
|
||||
if (_preselecting)
|
||||
return;
|
||||
|
||||
// Only care about these fields
|
||||
if (e.PropertyName != "UserValue" &&
|
||||
e.PropertyName != "SelectedOperator" &&
|
||||
e.PropertyName != "SelectedDataModelProp")
|
||||
return;
|
||||
|
||||
LayerConditionModel.Field = SelectedDataModelProp.Path;
|
||||
LayerConditionModel.Operator = SelectedOperator.Value;
|
||||
LayerConditionModel.Value = UserValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup the current UI elements to show the backing model
|
||||
/// </summary>
|
||||
private void PreSelect()
|
||||
{
|
||||
_preselecting = true;
|
||||
SelectedDataModelProp = DataModelProps.FirstOrDefault(m => m.Path == LayerConditionModel.Field);
|
||||
SelectedOperator = Operators.FirstOrDefault(o => o.Value == LayerConditionModel.Operator);
|
||||
UserValue = LayerConditionModel.Value;
|
||||
_preselecting = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the current model from the parent
|
||||
/// </summary>
|
||||
public void Delete()
|
||||
{
|
||||
_conditionModel.DeleteCondition(this, LayerConditionModel);
|
||||
}
|
||||
|
||||
public struct NamedOperator
|
||||
{
|
||||
public string Display { get; set; }
|
||||
public string Value { get; set; }
|
||||
|
||||
public NamedOperator(string display, string value)
|
||||
{
|
||||
Display = display;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -22,7 +22,7 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Left -->
|
||||
<ComboBox x:Name="DataModelProps" Grid.Column="0" Width="250" MaxDropDownHeight="125"
|
||||
<ComboBox x:Name="DataModelProps" Grid.Column="0" Width="229" MaxDropDownHeight="125"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Top">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
@ -37,7 +37,7 @@
|
||||
<!-- Center -->
|
||||
<TextBlock Grid.Column="1" Text="is" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,3,0,0" />
|
||||
<ComboBox x:Name="Operators" Grid.Column="2" Width="150" MaxDropDownHeight="125" HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top" />
|
||||
VerticalAlignment="Top" DisplayMemberPath="Display" />
|
||||
|
||||
<!-- Right -->
|
||||
<Grid Grid.Column="3" HorizontalAlignment="Left" Margin="10,0,0,0" Width="152">
|
||||
|
||||
@ -9,24 +9,57 @@
|
||||
mc:Ignorable="d"
|
||||
Title="Artemis | Edit Layer" Height="800" Width="630"
|
||||
GlowBrush="{DynamicResource AccentColorBrush}" Icon="../logo.ico" ResizeMode="NoResize">
|
||||
<Grid>
|
||||
<Grid Margin="10,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="25*" />
|
||||
<ColumnDefinition Width="53*" />
|
||||
<ColumnDefinition Width="25*" />
|
||||
<ColumnDefinition Width="53*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="10" FontSize="16" Text="Display if.." />
|
||||
<ListBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" x:Name="LayerConditionVms" />
|
||||
<Button Grid.Row="2" Grid.Column="0" x:Name="AddCondition" Content="Add condition" VerticalAlignment="Top"
|
||||
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10" />
|
||||
<Button Grid.Row="3" Grid.Column="0" x:Name="Apply" Content="Apply" VerticalAlignment="Bottom"
|
||||
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10" />
|
||||
<!-- Header -->
|
||||
<Label Grid.Row="0" Grid.ColumnSpan="4" FontSize="20" HorizontalAlignment="Left">
|
||||
<Label.Content>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Path=Layer.Name}" />
|
||||
<TextBlock Text=" - Basics" />
|
||||
</StackPanel>
|
||||
</Label.Content>
|
||||
</Label>
|
||||
|
||||
<!-- Layer name -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Margin="10" FontSize="16" Text="Name:" />
|
||||
<TextBox Grid.Row="1" Grid.Column="1" x:Name="Name" Margin="10" />
|
||||
|
||||
<!-- Layer type -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="2" Margin="10" FontSize="16" Text="Type:" />
|
||||
<ComboBox Grid.Row="1" Grid.Column="3" x:Name="Operators" Margin="10" />
|
||||
|
||||
<!-- Condition editor -->
|
||||
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" FontSize="20" Content="Display if.." />
|
||||
<ScrollViewer Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" Height="145">
|
||||
<ListBox x:Name="LayerConditionVms" />
|
||||
</ScrollViewer>
|
||||
<Button Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" x:Name="AddCondition" Content="Add condition" VerticalAlignment="Top"
|
||||
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10,10,0,0"
|
||||
Height="20" />
|
||||
|
||||
<!-- Advanced -->
|
||||
<Label Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" FontSize="20" HorizontalAlignment="Left"
|
||||
Content="Advanced" />
|
||||
|
||||
<Button Grid.Row="6" Grid.Column="0" x:Name="Apply" Content="Apply" VerticalAlignment="Bottom"
|
||||
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10,0,0,10"
|
||||
Height="20" Grid.ColumnSpan="2" />
|
||||
</Grid>
|
||||
|
||||
|
||||
</controls:MetroWindow>
|
||||
Loading…
x
Reference in New Issue
Block a user