347 lines
10 KiB
C#
347 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using JD.Core.ProjectManaging;
|
|
using JD.SceneExplorer.Utils;
|
|
using JD.WPF.Models;
|
|
|
|
namespace JD.SceneExplorer.ViewModels
|
|
{
|
|
public class ObjectWithRef : TreeViewItemData, IComparable<ObjectWithRef>, IEquatable<ObjectWithRef>
|
|
{
|
|
public static ObjectWithRef InvalidObject = new ObjectWithRef(0, null, null);
|
|
|
|
protected readonly uint m_objectRef;
|
|
protected string m_friendlyName;
|
|
protected string m_friendlyNameLower;
|
|
private string m_filePath;
|
|
protected bool m_currentlyEdited;
|
|
protected bool m_visible;
|
|
protected bool m_active;
|
|
protected bool m_locked;
|
|
protected bool m_isFavorite;
|
|
protected bool m_isPhantom;
|
|
protected PropertyChangedEventHandler m_propertyChangedHandler;
|
|
private readonly List<string> m_tags;
|
|
|
|
public ObjectWithRef(uint objectRef, ObjectWithRef parent, PropertyChangedEventHandler propertyChangedHandler)
|
|
: base(parent)
|
|
{
|
|
m_objectRef = objectRef;
|
|
FriendlyName = "";
|
|
ReserveIconSpace = EditorIconsManager.Instance.HasTags;
|
|
m_propertyChangedHandler = propertyChangedHandler;
|
|
if (m_propertyChangedHandler != null)
|
|
PropertyChanged += m_propertyChangedHandler;
|
|
m_tags = new List<string>();
|
|
m_isFavorite = false;
|
|
m_isPhantom = false;
|
|
m_visible = true;
|
|
m_active = true;
|
|
}
|
|
|
|
protected void UnregisterPropertyChanged()
|
|
{
|
|
if (m_propertyChangedHandler != null)
|
|
PropertyChanged -= m_propertyChangedHandler;
|
|
}
|
|
|
|
public ObjectWithRef(uint objectRef, PropertyChangedEventHandler propertyChangedHandler)
|
|
: base(null)
|
|
{
|
|
m_objectRef = objectRef;
|
|
FriendlyName = "";
|
|
m_propertyChangedHandler = propertyChangedHandler;
|
|
if (m_propertyChangedHandler != null)
|
|
PropertyChanged += m_propertyChangedHandler;
|
|
m_tags = new List<string>();
|
|
m_isFavorite = false;
|
|
m_isPhantom = false;
|
|
}
|
|
|
|
public virtual ObjectWithRefType Type { get { return ObjectWithRefType.ObjectWithRef; } }
|
|
|
|
public int CompareTo(ObjectWithRef other)
|
|
{
|
|
return m_friendlyName.CompareTo(other.m_friendlyName);
|
|
}
|
|
|
|
public uint ObjectRef
|
|
{
|
|
get { return m_objectRef; }
|
|
}
|
|
|
|
public virtual uint PickableRef
|
|
{
|
|
get { return m_objectRef; }
|
|
}
|
|
|
|
public bool IsValid
|
|
{
|
|
get { return m_objectRef != 0; }
|
|
}
|
|
|
|
public List<string> Tags
|
|
{
|
|
get { return m_tags; }
|
|
}
|
|
|
|
public string FriendlyName
|
|
{
|
|
get { return m_friendlyName; }
|
|
set
|
|
{
|
|
if (m_friendlyName != value)
|
|
{
|
|
m_friendlyName = value;
|
|
m_friendlyNameLower = value.ToLower();
|
|
RaisePropertyChanged("FriendlyName");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string FriendlyNameLower
|
|
{
|
|
get { return m_friendlyNameLower; }
|
|
}
|
|
|
|
public string FilePath
|
|
{
|
|
get { return m_filePath; }
|
|
set
|
|
{
|
|
string fullFilePath = "";
|
|
if(!String.IsNullOrEmpty(value))
|
|
fullFilePath = DataPath.GetAbsolutePath(value);
|
|
|
|
if (m_filePath != fullFilePath)
|
|
{
|
|
m_filePath = fullFilePath;
|
|
if(!String.IsNullOrEmpty(m_filePath))
|
|
UpdatePerforceStatus(FilePath);
|
|
|
|
RaisePropertyChanged("FilePath");
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool CurrentlyEdited
|
|
{
|
|
get { return m_currentlyEdited; }
|
|
set
|
|
{
|
|
if (m_currentlyEdited != value)
|
|
{
|
|
if (value)
|
|
{
|
|
ObjectWithRef rootObjRef = Root as ObjectWithRef;
|
|
if (rootObjRef == null)
|
|
throw new InvalidOperationException("Invalid root element! ");
|
|
|
|
if (rootObjRef.HasLockedItem)
|
|
{
|
|
ObjectWithRef parentObjRef = Parent as ObjectWithRef;
|
|
bool hasLockedParent = Locked;
|
|
while (!hasLockedParent && parentObjRef != null)
|
|
{
|
|
if (parentObjRef.Locked)
|
|
hasLockedParent = true;
|
|
|
|
parentObjRef = parentObjRef.Parent as ObjectWithRef;
|
|
}
|
|
|
|
if (!hasLockedParent)
|
|
return; // We are trying to set the edited element outside the locked scene : do nothing in this case.
|
|
}
|
|
}
|
|
|
|
m_currentlyEdited = value;
|
|
RaisePropertyChanged("CurrentlyEdited");
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual bool Visible
|
|
{
|
|
get { return m_visible; }
|
|
set
|
|
{
|
|
if (m_visible != value)
|
|
{
|
|
m_visible = value;
|
|
RaisePropertyChanged("Visible");
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual bool CanHide { get { return true; } }
|
|
|
|
public bool Active
|
|
{
|
|
get { return m_active; }
|
|
set
|
|
{
|
|
if (m_active != value)
|
|
{
|
|
m_active = value;
|
|
RaisePropertyChanged("Active");
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool Locked
|
|
{
|
|
get { return m_locked; }
|
|
set
|
|
{
|
|
if (m_locked != value)
|
|
{
|
|
m_locked = value;
|
|
RaisePropertyChanged("Locked");
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsFavorite
|
|
{
|
|
get { return m_isFavorite; }
|
|
set
|
|
{
|
|
if (m_isFavorite != value)
|
|
{
|
|
m_isFavorite = value;
|
|
RaisePropertyChanged("IsFavorite");
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsPhantom
|
|
{
|
|
get { return m_isPhantom; }
|
|
set
|
|
{
|
|
if (m_isPhantom != value)
|
|
{
|
|
m_isPhantom = value;
|
|
RaisePropertyChanged("IsPhantom");
|
|
}
|
|
}
|
|
}
|
|
|
|
protected bool HasLockedItem
|
|
{
|
|
get
|
|
{
|
|
if (Locked)
|
|
return true;
|
|
|
|
if (NeedUpdate)
|
|
{
|
|
// FIXME : Temp fix for a rare crash (UAF-15144). Requires too much rewriting to be fixed the "good" way.
|
|
return false;
|
|
}
|
|
|
|
foreach (ObjectWithRef objRef in Children)
|
|
{
|
|
if (objRef.HasLockedItem)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public PropertyChangedEventHandler PropertyChangedHandler { get { return m_propertyChangedHandler; } }
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
ObjectWithRef objRef = obj as ObjectWithRef;
|
|
if (objRef == null)
|
|
return false;
|
|
|
|
return Equals(objRef);
|
|
}
|
|
|
|
public bool Equals(ObjectWithRef obj)
|
|
{
|
|
return ObjectRef == obj.ObjectRef;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return Convert.ToInt32(Convert.ToInt64(m_objectRef) + Int32.MinValue);
|
|
}
|
|
|
|
public override bool SetFilter(object filterData)
|
|
{
|
|
TagSelectorData<ObjectWithRef> newFilter = (TagSelectorData<ObjectWithRef>)filterData;
|
|
IsFiltered = !newFilter.MatchFilter(this);
|
|
return IsFiltered;
|
|
}
|
|
|
|
public override bool SetFilter(object filterData, System.Threading.CancellationToken cancellationToken)
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
if (filterData == null) return false;
|
|
TagSelectorData<ObjectWithRef> newFilter = (TagSelectorData<ObjectWithRef>)filterData;
|
|
IsFiltered = !newFilter.MatchFilter(this);
|
|
return IsFiltered;
|
|
}
|
|
|
|
private void UpdateVisibleOnParent()
|
|
{
|
|
if (Parent != null)
|
|
{
|
|
ObjectWithRef objRef = Parent as ObjectWithRef;
|
|
if (objRef != null)
|
|
objRef.UpdateVisibleOnChildren(false);
|
|
}
|
|
}
|
|
|
|
private void UpdateVisibleOnChildren(bool recursive)
|
|
{
|
|
if (!ChildrenLoaded)
|
|
return;
|
|
|
|
if (recursive)
|
|
{
|
|
foreach (ObjectWithRef childObjRef in Children)
|
|
{
|
|
childObjRef.UpdateVisibleOnChildren(true);
|
|
}
|
|
}
|
|
|
|
if (Children.Count > 0 && Children.Cast<ObjectWithRef>().All(child => child.Visible == false))
|
|
Visible = false;
|
|
else
|
|
Visible = true;
|
|
}
|
|
|
|
public void UpdateFlags(bool recursive)
|
|
{
|
|
UpdateVisibleOnChildren(recursive);
|
|
}
|
|
|
|
protected void UpdatePerforceStatus(string filePath)
|
|
{
|
|
//if (this is SceneTree)
|
|
//{
|
|
// if (!PerforceManager.Instance.WasInit)
|
|
// {
|
|
// if (EngineBranchManager.Instance.CurrentBranch.PerforceServer == null)
|
|
// return;
|
|
// PerforceManager.Instance.InitPerforceWrapper(EngineBranchManager.Instance.CurrentBranch);
|
|
// }
|
|
|
|
// if (PerforceManager.Instance.IsWrapperReady)
|
|
// {
|
|
// PerforceFStatRequest request = new PerforceFStatRequest(new PerforceRequestEventHandler(OnRequestFileStatusCompleted));
|
|
// request.AddFile(filePath);
|
|
// PerforceManager.Instance.SendRequest(request);
|
|
// }
|
|
//}
|
|
}
|
|
|
|
}
|
|
}
|