Filtration/Filtration.ObjectModel/ItemFilterBlock.cs

361 lines
12 KiB
C#
Raw Normal View History

2015-06-04 13:15:54 -04:00
using System;
using System.Collections.ObjectModel;
2018-08-20 13:12:45 -04:00
using System.Collections.Specialized;
2015-06-04 13:15:54 -04:00
using System.Linq;
using System.Windows.Media;
2015-06-24 14:57:16 -04:00
using Filtration.ObjectModel.BlockItemBaseTypes;
using Filtration.ObjectModel.BlockItemTypes;
using Filtration.ObjectModel.Commands;
2015-06-24 14:57:16 -04:00
using Filtration.ObjectModel.Enums;
using Filtration.ObjectModel.Extensions;
2015-06-04 13:15:54 -04:00
2015-06-24 14:57:16 -04:00
namespace Filtration.ObjectModel
2015-06-04 13:15:54 -04:00
{
public interface IItemFilterBlock : IItemFilterBlockBase
2015-12-28 12:30:34 -05:00
{
bool Enabled { get; set; }
event EventHandler EnabledStatusChanged;
2015-12-28 12:30:34 -05:00
string Description { get; set; }
ItemFilterBlockGroup BlockGroup { get; set; }
BlockAction Action { get; set; }
ActionBlockItem ActionBlockItem { get; }
2015-12-28 12:30:34 -05:00
ObservableCollection<IItemFilterBlockItem> BlockItems { get; }
Color DisplayBackgroundColor { get; }
Color DisplayTextColor { get; }
Color DisplayBorderColor { get; }
double DisplayFontSize { get; }
2018-08-29 13:12:02 -04:00
int DisplayIconSize { get; }
int DisplayIconColor { get; }
int DisplayIconShape { get; }
Color DisplayEffectColor { get; }
2015-12-28 12:30:34 -05:00
bool HasBlockItemOfType<T>();
bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup);
}
public interface IItemFilterBlockBase
{
2018-08-20 13:12:45 -04:00
bool IsEdited { get; set; }
string OriginalText { get; set; }
}
public abstract class ItemFilterBlockBase : IItemFilterBlockBase
{
protected ItemFilterBlockBase()
{
}
protected ItemFilterBlockBase(IItemFilterScript parentScript)
{
CommandManager = parentScript.CommandManager;
ParentScript = parentScript;
}
public ICommandManager CommandManager { get; }
public IItemFilterScript ParentScript { get; set; }
2018-08-20 13:12:45 -04:00
public bool IsEdited { get; set; }
public string OriginalText { get; set; }
}
public interface IItemFilterCommentBlock : IItemFilterBlockBase
{
string Comment { get; set; }
}
public class ItemFilterCommentBlock : ItemFilterBlockBase, IItemFilterCommentBlock
{
2018-08-20 13:12:45 -04:00
private string _comment;
public ItemFilterCommentBlock(IItemFilterScript parentScript) : base(parentScript)
{
}
2018-08-20 13:12:45 -04:00
public string Comment
{
get { return _comment; }
set
{
_comment = value;
IsEdited = true;
}
}
}
public class ItemFilterBlock : ItemFilterBlockBase, IItemFilterBlock
2015-06-04 13:15:54 -04:00
{
private ItemFilterBlockGroup _blockGroup;
2018-08-20 13:12:45 -04:00
private bool _enabled;
private string _description;
internal ItemFilterBlock()
{
BlockItems = new ObservableCollection<IItemFilterBlockItem> { ActionBlockItem };
2018-08-20 13:12:45 -04:00
BlockItems.CollectionChanged += new NotifyCollectionChangedEventHandler(OnBlockItemsChanged);
2018-09-06 06:54:54 -04:00
ActionBlockItem.PropertyChanged += OnActionBlockItemChanged;
2018-08-20 13:12:45 -04:00
_enabled = true;
}
public ItemFilterBlock(IItemFilterScript parentScript) : base(parentScript)
2015-06-04 13:15:54 -04:00
{
BlockItems = new ObservableCollection<IItemFilterBlockItem> { ActionBlockItem };
2018-08-20 13:12:45 -04:00
BlockItems.CollectionChanged += new NotifyCollectionChangedEventHandler(OnBlockItemsChanged);
2018-09-06 06:54:54 -04:00
ActionBlockItem.PropertyChanged += OnActionBlockItemChanged;
2018-08-20 13:12:45 -04:00
_enabled = true;
2015-06-04 13:15:54 -04:00
}
2015-07-06 13:19:05 -04:00
2018-08-20 13:12:45 -04:00
public bool Enabled
{
get { return _enabled; }
set
{
_enabled = value;
IsEdited = true;
EnabledStatusChanged?.Invoke(null, null);
2018-09-06 06:54:54 -04:00
if(BlockGroup != null && BlockGroup.IsEnableChecked != value)
{
BlockGroup.IsEnableChecked = value;
}
2018-08-20 13:12:45 -04:00
}
}
public event EventHandler EnabledStatusChanged;
2018-08-20 13:12:45 -04:00
public string Description
{
get { return _description; }
set
{
_description = value;
IsEdited = true;
}
}
public ItemFilterBlockGroup BlockGroup
{
get => _blockGroup;
set
{
var oldBlockGroup = _blockGroup;
_blockGroup = value;
if (_blockGroup != null)
{
_blockGroup.BlockGroupStatusChanged += OnBlockGroupStatusChanged;
if (oldBlockGroup != null)
{
oldBlockGroup.BlockGroupStatusChanged -= OnBlockGroupStatusChanged;
}
}
else
{
if (oldBlockGroup != null)
{
oldBlockGroup.BlockGroupStatusChanged -= OnBlockGroupStatusChanged;
}
}
}
}
2015-06-04 13:15:54 -04:00
public BlockAction Action
{
get
{
var actionBlock = BlockItems.OfType<ActionBlockItem>().First();
return actionBlock.Action;
}
set
{
var actionBlock = BlockItems.OfType<ActionBlockItem>().First();
actionBlock.Action = value;
2018-08-20 13:12:45 -04:00
IsEdited = true;
2015-06-04 13:15:54 -04:00
}
}
public ActionBlockItem ActionBlockItem { get; } = new ActionBlockItem(BlockAction.Show);
public ObservableCollection<IItemFilterBlockItem> BlockItems { get; }
2018-08-20 13:12:45 -04:00
private void OnBlockItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
IsEdited = true;
}
2018-09-06 06:54:54 -04:00
private void OnActionBlockItemChanged(object sender, EventArgs e)
{
if (BlockGroup != null && BlockGroup.IsShowChecked != (Action == BlockAction.Show))
{
BlockGroup.IsShowChecked = (Action == BlockAction.Show);
}
}
2015-06-04 13:15:54 -04:00
public bool AddBlockItemAllowed(Type type)
{
int BlockCount()
{
return BlockItems?.Count(b => b.GetType() == type) ?? 0;
}
var blockItem = (IItemFilterBlockItem)Activator.CreateInstance(type);
return BlockCount() < blockItem.MaximumAllowed;
2015-06-04 13:15:54 -04:00
}
2015-06-06 15:44:38 -04:00
public bool HasBlockItemOfType<T>()
{
return BlockItems.Count(b => b is T) > 0;
}
public bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup)
{
if (startingBlockGroup == targetBlockGroup)
{
return true;
}
if (BlockGroup == null)
{
return false;
}
return startingBlockGroup.ParentGroup != null && HasBlockGroupInParentHierarchy(targetBlockGroup, startingBlockGroup.ParentGroup);
}
private void OnBlockGroupStatusChanged(object sender, EventArgs e)
{
if (BlockGroup.IsShowChecked == false && Action == BlockAction.Show)
{
Action = BlockAction.Hide;
}
2018-09-06 06:54:54 -04:00
else if (BlockGroup.IsShowChecked == true && Action == BlockAction.Hide)
{
Action = BlockAction.Show;
}
if (BlockGroup.IsEnableChecked == false && Enabled)
{
Enabled = false;
}
2018-09-06 06:54:54 -04:00
else if (BlockGroup.IsEnableChecked == true && !Enabled)
{
Enabled = true;
}
}
public Color DisplayTextColor
{
get
{
var textColorBlockItem = BlockItems.OfType<TextColorBlockItem>().FirstOrDefault();
if (textColorBlockItem != null)
{
return textColorBlockItem.Color;
}
var itemClassBlockItem = BlockItems.OfType<ClassBlockItem>().FirstOrDefault();
if (itemClassBlockItem != null)
{
if (itemClassBlockItem.Items.All(i => i.Contains("Gems")))
{
return PathOfExileNamedColors.Colors[PathOfExileNamedColor.GemItem];
}
if (itemClassBlockItem.Items.All(i => i.Contains("Quest")))
{
return PathOfExileNamedColors.Colors[PathOfExileNamedColor.QuestItem];
}
}
var rarityBlockItem = BlockItems.OfType<RarityBlockItem>().FirstOrDefault();
return rarityBlockItem != null
? ((ItemRarity) rarityBlockItem.FilterPredicate.PredicateOperand).DefaultRarityTextColor()
: PathOfExileNamedColors.Colors[PathOfExileNamedColor.WhiteItem];
}
}
public Color DisplayBackgroundColor
{
get
{
var backgroundColorBlockItem = BlockItems.OfType<BackgroundColorBlockItem>().FirstOrDefault();
2018-09-03 08:37:10 -04:00
return backgroundColorBlockItem?.Color ?? new Color { A = 240, R = 0, G = 0, B = 0 };
}
}
public Color DisplayBorderColor
{
get
{
var borderColorBlockItem = BlockItems.OfType<BorderColorBlockItem>().FirstOrDefault();
return borderColorBlockItem?.Color ?? new Color { A = 0, R = 255, G = 255, B = 255 };
}
}
public double DisplayFontSize
{
get
{
var fontSizeBlockItem = BlockItems.OfType<FontSizeBlockItem>().FirstOrDefault();
return fontSizeBlockItem?.Value ?? 34;
}
}
2018-08-21 10:03:42 -04:00
2018-08-29 13:12:02 -04:00
public int DisplayIconSize
2018-08-21 10:03:42 -04:00
{
get
{
2018-08-29 13:12:02 -04:00
var mapIconBlockItem = BlockItems.OfType<MapIconBlockItem>().FirstOrDefault();
if (mapIconBlockItem != null)
return (int)mapIconBlockItem.Size;
return -1;
2018-08-21 10:03:42 -04:00
}
}
2018-08-29 13:12:02 -04:00
public int DisplayIconColor
{
get
{
2018-08-29 13:12:02 -04:00
var mapIconBlockItem = BlockItems.OfType<MapIconBlockItem>().FirstOrDefault();
if (mapIconBlockItem != null)
return (int)mapIconBlockItem.Color;
return -1;
}
}
public int DisplayIconShape
{
get
{
var mapIconBlockItem = BlockItems.OfType<MapIconBlockItem>().FirstOrDefault();
if (mapIconBlockItem != null)
return (int)mapIconBlockItem.Shape;
return -1;
}
}
public Color DisplayEffectColor
{
get
{
var beamBlockItem = BlockItems.OfType<PlayEffectBlockItem>().FirstOrDefault();
if (beamBlockItem != null)
{
switch (beamBlockItem.Color)
{
case EffectColor.Red:
return Colors.Red;
case EffectColor.Green:
return Colors.Green;
case EffectColor.Blue:
return Colors.Blue;
case EffectColor.Brown:
return Colors.Brown;
case EffectColor.White:
return Colors.White;
case EffectColor.Yellow:
return Colors.Yellow;
}
}
return Colors.Transparent;
}
}
2015-06-04 13:15:54 -04:00
}
}