Skip to content

Commit

Permalink
[Sprite Editor] - Fixed bug where opening a new sprite, while already…
Browse files Browse the repository at this point in the history
… having a sprite open, would cause the editor to stop responding to sprite clipping, picking and vertex editing changes.
  • Loading branch information
Tape-Worm committed Feb 18, 2022
1 parent 60898d2 commit 1cdc672
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
32 changes: 31 additions & 1 deletion PlugIns/Gorgon.Editor.SpriteEditor/_Internal/Forms/FormRibbon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,25 @@ private void SpriteClipContext_PropertyChanged(object sender, PropertyChangedEve
ValidateButtons();
}

/// <summary>Handles the PropertyChanging event of the DataContext control.</summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PropertyChangingEventArgs" /> instance containing the event data.</param>
private void DataContext_PropertyChanging(object sender, PropertyChangingEventArgs e)
{
switch (e.PropertyName)
{
case nameof(ISpriteContent.SpriteClipContext):
DataContext.SpriteClipContext.PropertyChanged -= SpriteClipContext_PropertyChanged;
break;
case nameof(ISpriteContent.SpritePickContext):
DataContext.SpriteClipContext.PropertyChanged -= SpritePickContext_PropertyChanged;
break;
case nameof(ISpriteContent.SpriteVertexEditContext):
DataContext.SpriteVertexEditContext.PropertyChanged -= SpriteVertexEditorContext_PropertyChanged;
break;
}
}

/// <summary>Handles the PropertyChanged event of the DataContext control.</summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The [PropertyChangedEventArgs] instance containing the event data.</param>
Expand All @@ -230,6 +249,15 @@ private void DataContext_PropertyChanged(object sender, PropertyChangedEventArgs
NumericFixedWidth.Maximum = DataContext?.Texture?.Width ?? 16384;
NumericFixedHeight.Maximum = DataContext?.Texture?.Height ?? 16384;
break;
case nameof(ISpriteContent.SpriteClipContext):
DataContext.SpriteClipContext.PropertyChanged += SpriteClipContext_PropertyChanged;
break;
case nameof(ISpriteContent.SpritePickContext):
DataContext.SpriteClipContext.PropertyChanged += SpritePickContext_PropertyChanged;
break;
case nameof(ISpriteContent.SpriteVertexEditContext):
DataContext.SpriteVertexEditContext.PropertyChanged += SpriteVertexEditorContext_PropertyChanged;
break;
}

ValidateButtons();
Expand Down Expand Up @@ -678,6 +706,7 @@ private void UnassignEvents()
DataContext.SpriteVertexEditContext.PropertyChanged -= SpriteVertexEditorContext_PropertyChanged;
}

DataContext.PropertyChanging -= DataContext_PropertyChanging;
DataContext.PropertyChanged -= DataContext_PropertyChanged;
}

Expand Down Expand Up @@ -845,7 +874,8 @@ public void SetDataContext(ISpriteContent dataContext)
}

DataContext.PropertyChanged += DataContext_PropertyChanged;
}
DataContext.PropertyChanging += DataContext_PropertyChanging;
}

/// <summary>
/// Function to validate the state of the buttons.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,10 @@ public void Initialize(GorgonSprite sprite, IContentFile file, IUndoService undo
SpritePickContext = spritePickContext;
SpriteVertexEditContext = spriteVertexEditContext;

SpriteClipContext.ApplyCommand = new EditorCommand<object>(DoApplyClip, CanApplyClip);
SpritePickContext.ApplyCommand = new EditorCommand<object>(DoApplyPick, CanApplyPick);
SpriteVertexEditContext.ApplyCommand = new EditorCommand<object>(DoCommitVertexOffsets, CanCommitVertexOffsets);

NotifyAllPropertiesChanged();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,11 @@ protected override void OnPropertyChanged(string propertyName)
break;
case nameof(ISpriteContent.SpriteClipContext):
_manualRectEditor.SetDataContext(DataContext.SpriteClipContext);
//DataContext.SpriteClipContext.PropertyChanged += SpriteClipContext_PropertyChanged;
DataContext.SpriteClipContext.PropertyChanged += SpriteClipContext_PropertyChanged;
break;
case nameof(ISpriteContent.SpritePickContext):
SpritePickMaskColor.SetDataContext(DataContext.SpritePickContext.SpritePickMaskEditor);
//DataContext.SpritePickContext.PropertyChanged += SpritePickContext_PropertyChanged;
break;
case nameof(ISpriteContent.SpriteVertexEditContext):
//_manualVertexEditor.SetDataContext(DataContext.SpriteVertexEditContext);
DataContext.SpritePickContext.PropertyChanged += SpritePickContext_PropertyChanged;
break;
}

Expand Down

0 comments on commit 1cdc672

Please sign in to comment.