137 lines
4.2 KiB
C#
137 lines
4.2 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using JD.Interfaces.Editors;
|
|
|
|
namespace JD.Serialization
|
|
{
|
|
partial class PictogramClip
|
|
{
|
|
#region Variables
|
|
|
|
private PictogramModel _model;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
[Browsable(true)]
|
|
[Category("Picto")]
|
|
[PropertyEditor("PictogramModelEditor")]
|
|
public PictogramModel Model
|
|
{
|
|
get { return _model; }
|
|
set
|
|
{
|
|
if (_model != value)
|
|
{
|
|
if (_model != null)
|
|
_model.PropertyChanged -= model_propertyChanged;
|
|
_model = value;
|
|
_model.PropertyChanged += model_propertyChanged;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
[Browsable(false)]
|
|
public override float BeatDuration { get { return base.BeatDuration; } set { base.BeatDuration = value; } }
|
|
|
|
[Browsable(false)]
|
|
public override int StopFrame { get { return base.StopFrame; } set { base.StopFrame = value; } }
|
|
|
|
[Browsable(false)]
|
|
public override int Duration { get { return base.Duration; } set { base.Duration = value; } }
|
|
|
|
#endregion
|
|
|
|
#region methods
|
|
|
|
private void RefreshModel()
|
|
{
|
|
if (Tape != null && PictoPath != null)
|
|
{
|
|
Model = Tape.GetOrCreatePictogramModel(PictoPath);
|
|
}
|
|
}
|
|
|
|
protected override void OnPropertyChanged([CallerMemberName] string propertyName = "")
|
|
{
|
|
base.OnPropertyChanged(propertyName);
|
|
|
|
if (propertyName == nameof(Tape) || propertyName == nameof(PictoPath))
|
|
{
|
|
RefreshModel();
|
|
}
|
|
|
|
if (Model != null)
|
|
{
|
|
switch (propertyName)
|
|
{
|
|
case nameof(Duration):
|
|
Model.BeatDuration = BeatDuration;
|
|
break;
|
|
case nameof(Model):
|
|
if (Model.BeatDuration > 0)
|
|
{
|
|
BeatDuration = Model.BeatDuration;
|
|
}
|
|
PictoPath = Model.PictoPath;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void model_propertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
switch (e.PropertyName)
|
|
{
|
|
case "BeatDuration":
|
|
BeatDuration = Model.BeatDuration;
|
|
break;
|
|
case "PictoPath":
|
|
PictoPath = Model.PictoPath;
|
|
break;
|
|
default:
|
|
OnPropertyChanged(e.PropertyName);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public override Clip ConvertToFit(TapeTrack track)
|
|
{
|
|
var clip = base.ConvertToFit(track);
|
|
if (track is MoveTrack)
|
|
{
|
|
var moveTrack = (MoveTrack) track;
|
|
var motionClip = (MotionClip)clip;
|
|
motionClip.Model = Tape.GetOrCreateMoveModel(Model.Name, moveTrack.MoveType);
|
|
motionClip.CoachId = moveTrack.CoachId;
|
|
}
|
|
return clip;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Computed properties are not considered in undo/redo and to make the document "dirty"
|
|
/// </summary>
|
|
public override bool IsComputedProperty(string propertyName)
|
|
{
|
|
return base.IsComputedProperty(propertyName) || propertyName == nameof(BeatDuration) || propertyName == nameof(Duration);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
public static class PictogramClipExtensions
|
|
{
|
|
public static PictogramClip InstantiatePictogramClip(this TapeTrack track, string modelName, int startFrame)
|
|
{
|
|
if (string.IsNullOrEmpty(modelName))
|
|
return null;
|
|
|
|
var newClip = (PictogramClip)Clip.Instantiate(typeof(PictogramClip), track, startFrame);
|
|
newClip.Model = track.Tape.GetOrCreatePictogramModel(modelName);
|
|
return newClip;
|
|
}
|
|
}
|
|
}
|