Added Replace Colors functionality
This commit is contained in:
@@ -3,12 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Filtration.Models;
|
||||
using Filtration.Models.BlockItemTypes;
|
||||
using Filtration.Services;
|
||||
using Filtration.Translators;
|
||||
using Filtration.Views;
|
||||
using GalaSoft.MvvmLight.CommandWpf;
|
||||
|
||||
namespace Filtration.ViewModels
|
||||
@@ -23,14 +22,17 @@ namespace Filtration.ViewModels
|
||||
internal class LootFilterBlockViewModel : FiltrationViewModelBase, ILootFilterBlockViewModel
|
||||
{
|
||||
private readonly IStaticDataService _staticDataService;
|
||||
private readonly IReplaceColorsViewModel _replaceColorsViewModel;
|
||||
private readonly MediaPlayer _mediaPlayer = new MediaPlayer();
|
||||
private LootFilterScriptViewModel _parentScriptViewModel;
|
||||
|
||||
private bool _displaySettingsPopupOpen;
|
||||
|
||||
public LootFilterBlockViewModel(IStaticDataService staticDataService)
|
||||
public LootFilterBlockViewModel(IStaticDataService staticDataService, IReplaceColorsViewModel replaceColorsViewModel)
|
||||
{
|
||||
_staticDataService = staticDataService;
|
||||
_replaceColorsViewModel = replaceColorsViewModel;
|
||||
|
||||
CopyBlockCommand = new RelayCommand(OnCopyBlockCommand);
|
||||
PasteBlockCommand = new RelayCommand(OnPasteBlockCommand);
|
||||
AddBlockCommand = new RelayCommand(OnAddBlockCommand);
|
||||
@@ -40,6 +42,7 @@ namespace Filtration.ViewModels
|
||||
MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand);
|
||||
MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand);
|
||||
MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand);
|
||||
ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand);
|
||||
AddFilterBlockItemCommand = new RelayCommand<Type>(OnAddFilterBlockItemCommand);
|
||||
AddAudioVisualBlockItemCommand = new RelayCommand<Type>(OnAddAudioVisualBlockItemCommand);
|
||||
RemoveFilterBlockItemCommand = new RelayCommand<ILootFilterBlockItem>(OnRemoveFilterBlockItemCommand);
|
||||
@@ -74,6 +77,7 @@ namespace Filtration.ViewModels
|
||||
public RelayCommand MoveBlockDownCommand { get; private set; }
|
||||
public RelayCommand MoveBlockToTopCommand { get; private set; }
|
||||
public RelayCommand MoveBlockToBottomCommand { get; private set; }
|
||||
public RelayCommand ReplaceColorsCommand { get; private set; }
|
||||
public RelayCommand<Type> AddFilterBlockItemCommand { get; private set; }
|
||||
public RelayCommand<Type> AddAudioVisualBlockItemCommand { get; private set; }
|
||||
public RelayCommand<ILootFilterBlockItem> RemoveFilterBlockItemCommand { get; private set; }
|
||||
@@ -188,7 +192,7 @@ namespace Filtration.ViewModels
|
||||
|
||||
public bool HasTextColor
|
||||
{
|
||||
get { return FilterBlockItems.Count(b => b is TextColorBlockItem) > 0; }
|
||||
get { return Block.HasBlockItemOfType<TextColorBlockItem>(); }
|
||||
}
|
||||
|
||||
public Color DisplayTextColor
|
||||
@@ -203,7 +207,7 @@ namespace Filtration.ViewModels
|
||||
|
||||
public bool HasBackgroundColor
|
||||
{
|
||||
get { return FilterBlockItems.Count(b => b is BackgroundColorBlockItem) > 0; }
|
||||
get { return Block.HasBlockItemOfType<BackgroundColorBlockItem>(); }
|
||||
}
|
||||
|
||||
public Color DisplayBackgroundColor
|
||||
@@ -218,7 +222,7 @@ namespace Filtration.ViewModels
|
||||
|
||||
public bool HasBorderColor
|
||||
{
|
||||
get { return FilterBlockItems.Count(b => b is BorderColorBlockItem) > 0; }
|
||||
get { return Block.HasBlockItemOfType<BorderColorBlockItem>(); }
|
||||
}
|
||||
|
||||
public Color DisplayBorderColor
|
||||
@@ -233,12 +237,12 @@ namespace Filtration.ViewModels
|
||||
|
||||
public bool HasFontSize
|
||||
{
|
||||
get { return FilterBlockItems.Count(b => b is FontSizeBlockItem) > 0; }
|
||||
get { return Block.HasBlockItemOfType<FontSizeBlockItem>(); }
|
||||
}
|
||||
|
||||
public bool HasSound
|
||||
{
|
||||
get { return FilterBlockItems.Count(b => b is SoundBlockItem) > 0; }
|
||||
get { return Block.HasBlockItemOfType<SoundBlockItem>(); }
|
||||
}
|
||||
|
||||
private void OnAddFilterBlockItemCommand(Type blockItemType)
|
||||
@@ -320,6 +324,13 @@ namespace Filtration.ViewModels
|
||||
{
|
||||
_parentScriptViewModel.MoveBlockToBottom(this);
|
||||
}
|
||||
|
||||
private void OnReplaceColorsCommand()
|
||||
{
|
||||
_replaceColorsViewModel.Initialise(_parentScriptViewModel.Script, Block);
|
||||
var replaceColorsWindow = new ReplaceColorsWindow { DataContext = _replaceColorsViewModel };
|
||||
replaceColorsWindow.ShowDialog();
|
||||
}
|
||||
|
||||
private bool AddBlockItemAllowed(Type type)
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Filtration.ViewModels
|
||||
LootFilterScript Script { get; }
|
||||
bool IsDirty { get; }
|
||||
string Description { get; set; }
|
||||
string DisplayName { get; }
|
||||
void Initialise(LootFilterScript lootFilterScript);
|
||||
ILootFilterBlockViewModel SelectedBlockViewModel { get; set; }
|
||||
void RemoveDirtyFlag();
|
||||
@@ -93,7 +94,10 @@ namespace Filtration.ViewModels
|
||||
public bool IsDirty
|
||||
{
|
||||
get { return _isDirty || HasDirtyChildren; }
|
||||
set { _isDirty = value; }
|
||||
set
|
||||
{
|
||||
_isDirty = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasDirtyChildren
|
||||
@@ -113,6 +117,8 @@ namespace Filtration.ViewModels
|
||||
{
|
||||
CleanChildren();
|
||||
IsDirty = false;
|
||||
RaisePropertyChanged("Filename");
|
||||
RaisePropertyChanged("DisplayName");
|
||||
}
|
||||
|
||||
public string DisplayName
|
||||
@@ -279,7 +285,7 @@ namespace Filtration.ViewModels
|
||||
var newBlock = new LootFilterBlock();
|
||||
vm.Initialise(newBlock, this);
|
||||
|
||||
if (LootFilterBlockViewModels.Count > 0)
|
||||
if (targetBlockViewModel != null)
|
||||
{
|
||||
Script.LootFilterBlocks.Insert(Script.LootFilterBlocks.IndexOf(targetBlockViewModel.Block) + 1, newBlock);
|
||||
LootFilterBlockViewModels.Insert(LootFilterBlockViewModels.IndexOf(targetBlockViewModel) + 1, vm);
|
||||
|
||||
@@ -26,16 +26,19 @@ namespace Filtration.ViewModels
|
||||
private readonly ILootFilterScriptViewModelFactory _lootFilterScriptViewModelFactory;
|
||||
private readonly ILootFilterPersistenceService _persistenceService;
|
||||
private readonly ILootFilterScriptTranslator _lootFilterScriptTranslator;
|
||||
private readonly IReplaceColorsViewModel _replaceColorsViewModel;
|
||||
private ILootFilterScriptViewModel _currentScriptViewModel;
|
||||
private readonly ObservableCollection<ILootFilterScriptViewModel> _scriptViewModels;
|
||||
|
||||
public MainWindowViewModel(ILootFilterScriptViewModelFactory lootFilterScriptViewModelFactory,
|
||||
ILootFilterPersistenceService persistenceService,
|
||||
ILootFilterScriptTranslator lootFilterScriptTranslator)
|
||||
ILootFilterScriptTranslator lootFilterScriptTranslator,
|
||||
IReplaceColorsViewModel replaceColorsViewModel)
|
||||
{
|
||||
_lootFilterScriptViewModelFactory = lootFilterScriptViewModelFactory;
|
||||
_persistenceService = persistenceService;
|
||||
_lootFilterScriptTranslator = lootFilterScriptTranslator;
|
||||
_replaceColorsViewModel = replaceColorsViewModel;
|
||||
|
||||
_scriptViewModels = new ObservableCollection<ILootFilterScriptViewModel>();
|
||||
|
||||
@@ -48,8 +51,9 @@ namespace Filtration.ViewModels
|
||||
PasteCommand = new RelayCommand(OnPasteCommand, () => CurrentScriptViewModel != null);
|
||||
NewScriptCommand = new RelayCommand(OnNewScriptCommand);
|
||||
CloseScriptCommand = new RelayCommand<ILootFilterScriptViewModel>(OnCloseScriptCommand, v => CurrentScriptViewModel != null);
|
||||
ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand, () => CurrentScriptViewModel != null);
|
||||
|
||||
LoadScriptFromFile("C:\\ThioleLootFilter.txt");
|
||||
//LoadScriptFromFile("C:\\ThioleLootFilter.txt");
|
||||
|
||||
SetLootFilterScriptDirectory();
|
||||
}
|
||||
@@ -63,6 +67,7 @@ namespace Filtration.ViewModels
|
||||
public RelayCommand NewScriptCommand { get; private set; }
|
||||
public RelayCommand<ILootFilterScriptViewModel> CloseScriptCommand { get; private set; }
|
||||
public RelayCommand OpenAboutWindowCommand { get; private set; }
|
||||
public RelayCommand ReplaceColorsCommand { get; private set; }
|
||||
|
||||
public ObservableCollection<ILootFilterScriptViewModel> ScriptViewModels
|
||||
{
|
||||
@@ -87,11 +92,17 @@ namespace Filtration.ViewModels
|
||||
{
|
||||
_currentScriptViewModel = value;
|
||||
RaisePropertyChanged();
|
||||
RaisePropertyChanged("NoScriptsOpen");
|
||||
SaveScriptCommand.RaiseCanExecuteChanged();
|
||||
SaveScriptAsCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool NoScriptsOpen
|
||||
{
|
||||
get { return _currentScriptViewModel == null; }
|
||||
}
|
||||
|
||||
private void OnOpenAboutWindowCommand()
|
||||
{
|
||||
var aboutWindow = new AboutWindow();
|
||||
@@ -206,6 +217,13 @@ namespace Filtration.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReplaceColorsCommand()
|
||||
{
|
||||
_replaceColorsViewModel.Initialise(CurrentScriptViewModel.Script);
|
||||
var replaceColorsWindow = new ReplaceColorsWindow {DataContext = _replaceColorsViewModel};
|
||||
replaceColorsWindow.ShowDialog();
|
||||
}
|
||||
|
||||
private bool ValidateScript()
|
||||
{
|
||||
var result = CurrentScriptViewModel.Script.Validate();
|
||||
|
||||
171
Filtration/ViewModels/ReplaceColorsViewModel.cs
Normal file
171
Filtration/ViewModels/ReplaceColorsViewModel.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using Filtration.Models;
|
||||
using Filtration.Models.BlockItemTypes;
|
||||
using GalaSoft.MvvmLight.CommandWpf;
|
||||
|
||||
namespace Filtration.ViewModels
|
||||
{
|
||||
internal interface IReplaceColorsViewModel
|
||||
{
|
||||
void Initialise(LootFilterScript lootFilterScript, LootFilterBlock initialiseFromBlock);
|
||||
void Initialise(LootFilterScript lootFilterScript);
|
||||
}
|
||||
|
||||
internal class ReplaceColorsViewModel : FiltrationViewModelBase, IReplaceColorsViewModel
|
||||
{
|
||||
private LootFilterScript _lootFilterScript;
|
||||
private ReplaceColorsParameterSet _replaceColorsParameterSet;
|
||||
|
||||
public ReplaceColorsViewModel()
|
||||
{
|
||||
ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand);
|
||||
}
|
||||
|
||||
public RelayCommand ReplaceColorsCommand { get; private set; }
|
||||
|
||||
public void Initialise(LootFilterScript lootFilterScript, LootFilterBlock initialiseFromBlock)
|
||||
{
|
||||
_replaceColorsParameterSet = new ReplaceColorsParameterSet();
|
||||
|
||||
if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof (TextColorBlockItem)) > 0)
|
||||
{
|
||||
_replaceColorsParameterSet.ReplaceTextColor = true;
|
||||
_replaceColorsParameterSet.OldTextColor =
|
||||
((TextColorBlockItem)
|
||||
initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof (TextColorBlockItem))).Color;
|
||||
}
|
||||
|
||||
if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof(BackgroundColorBlockItem)) > 0)
|
||||
{
|
||||
_replaceColorsParameterSet.ReplaceBackgroundColor = true;
|
||||
_replaceColorsParameterSet.OldBackgroundColor =
|
||||
((BackgroundColorBlockItem)
|
||||
initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof(BackgroundColorBlockItem))).Color;
|
||||
}
|
||||
|
||||
if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof(BorderColorBlockItem)) > 0)
|
||||
{
|
||||
_replaceColorsParameterSet.ReplaceBorderColor = true;
|
||||
_replaceColorsParameterSet.OldBorderColor =
|
||||
((BorderColorBlockItem)
|
||||
initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof(BorderColorBlockItem))).Color;
|
||||
}
|
||||
|
||||
_lootFilterScript = lootFilterScript;
|
||||
}
|
||||
|
||||
public Color NewTextColor
|
||||
{
|
||||
get { return _replaceColorsParameterSet.NewTextColor; }
|
||||
set
|
||||
{
|
||||
_replaceColorsParameterSet.NewTextColor = value;
|
||||
RaisePropertyChanged();
|
||||
RaisePropertyChanged("DisplayTextColor");
|
||||
}
|
||||
}
|
||||
|
||||
public Color DisplayTextColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _replaceColorsParameterSet.ReplaceTextColor
|
||||
? _replaceColorsParameterSet.NewTextColor
|
||||
: new Color {A = 255, R = 255, G = 255, B = 255};
|
||||
}
|
||||
}
|
||||
|
||||
public bool ReplaceTextColor
|
||||
{
|
||||
get { return _replaceColorsParameterSet.ReplaceTextColor; }
|
||||
set
|
||||
{
|
||||
_replaceColorsParameterSet.ReplaceTextColor = value;
|
||||
RaisePropertyChanged("DisplayTextColor");
|
||||
}
|
||||
}
|
||||
|
||||
public Color NewBackgroundColor
|
||||
{
|
||||
get { return _replaceColorsParameterSet.NewBackgroundColor; }
|
||||
set
|
||||
{
|
||||
_replaceColorsParameterSet.NewBackgroundColor = value;
|
||||
RaisePropertyChanged();
|
||||
RaisePropertyChanged("DisplayBackgroundColor");
|
||||
}
|
||||
}
|
||||
|
||||
public Color DisplayBackgroundColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _replaceColorsParameterSet.ReplaceBackgroundColor
|
||||
? _replaceColorsParameterSet.NewBackgroundColor
|
||||
: new Color { A = 255, R = 0, G = 0, B = 0 };
|
||||
}
|
||||
}
|
||||
|
||||
public bool ReplaceBackgroundColor
|
||||
{
|
||||
get { return _replaceColorsParameterSet.ReplaceBackgroundColor; }
|
||||
set
|
||||
{
|
||||
_replaceColorsParameterSet.ReplaceBackgroundColor = value;
|
||||
RaisePropertyChanged("DisplayBackgroundColor");
|
||||
}
|
||||
}
|
||||
|
||||
public Color NewBorderColor
|
||||
{
|
||||
get { return _replaceColorsParameterSet.NewBorderColor; }
|
||||
set
|
||||
{
|
||||
_replaceColorsParameterSet.NewBorderColor = value;
|
||||
RaisePropertyChanged();
|
||||
RaisePropertyChanged("DisplayBorderColor");
|
||||
}
|
||||
}
|
||||
|
||||
public Color DisplayBorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _replaceColorsParameterSet.ReplaceBorderColor
|
||||
? _replaceColorsParameterSet.NewBorderColor
|
||||
: new Color { A = 255, R = 0, G = 0, B = 0 };
|
||||
}
|
||||
}
|
||||
|
||||
public bool ReplaceBorderColor
|
||||
{
|
||||
get { return _replaceColorsParameterSet.ReplaceBorderColor; }
|
||||
set
|
||||
{
|
||||
_replaceColorsParameterSet.ReplaceBorderColor = value;
|
||||
RaisePropertyChanged("DisplayBorderColor");
|
||||
}
|
||||
}
|
||||
|
||||
public ReplaceColorsParameterSet ReplaceColorsParameterSet
|
||||
{
|
||||
get
|
||||
{
|
||||
return _replaceColorsParameterSet;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialise(LootFilterScript lootFilterScript)
|
||||
{
|
||||
_replaceColorsParameterSet = new ReplaceColorsParameterSet();
|
||||
_lootFilterScript = lootFilterScript;
|
||||
}
|
||||
|
||||
private void OnReplaceColorsCommand()
|
||||
{
|
||||
_lootFilterScript.ReplaceColors(_replaceColorsParameterSet);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user