Skip to content

Commit 5731706

Browse files
committed
Skeleton viewer: animations list: add offset column and filter text box
1 parent 2768df2 commit 5731706

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

Z64Utils/ViewModels/ObjectAnalyzerWindowViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ private void OpenSkeletonViewerObjectHolderEntryCommandExecute(ObjectHolderEntry
638638
var skeletonHolder = (Z64Object.SkeletonHolder)ohe.ObjectHolder;
639639
skelvVM.SetSkeleton(skeletonHolder);
640640
skelvVM.SetAnimations(
641+
_object,
641642
_object
642643
.Entries.FindAll(oh => oh.GetEntryType() == Z64Object.EntryType.AnimationHeader)
643644
.Cast<Z64Object.AnimationHolder>()

Z64Utils/ViewModels/SkeletonViewerWindowViewModel.cs

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public partial class SkeletonViewerWindowViewModel : ObservableObject
5858
public interface IAnimationEntry
5959
{
6060
string Name { get; }
61+
string Offset { get; }
6162
void OnSelected();
6263
}
6364

@@ -70,16 +71,19 @@ public class RegularAnimationEntry : IAnimationEntry
7071
{
7172
private SkeletonViewerWindowViewModel _parentVM;
7273
public string Name { get; }
74+
public string Offset { get; }
7375
public Z64Object.AnimationHolder AnimationHolder { get; }
7476

7577
public RegularAnimationEntry(
7678
SkeletonViewerWindowViewModel parentVM,
7779
string name,
80+
uint offset,
7881
Z64Object.AnimationHolder animationHolder
7982
)
8083
{
8184
_parentVM = parentVM;
8285
Name = name;
86+
Offset = $"0x{offset:X6}";
8387
AnimationHolder = animationHolder;
8488
}
8589

@@ -96,10 +100,11 @@ public class ExternalRegularAnimationEntry : RegularAnimationEntry, IExternalAni
96100
public ExternalRegularAnimationEntry(
97101
SkeletonViewerWindowViewModel parentVM,
98102
string name,
103+
uint offset,
99104
Z64Object.AnimationHolder animationHolder,
100105
Dictionary<int, F3DZEX.Memory.Segment> externalData
101106
)
102-
: base(parentVM, name, animationHolder)
107+
: base(parentVM, name, offset, animationHolder)
103108
{
104109
ExternalData = externalData;
105110
}
@@ -109,16 +114,19 @@ public class PlayerAnimationEntry : IAnimationEntry
109114
{
110115
private SkeletonViewerWindowViewModel _parentVM;
111116
public string Name { get; }
117+
public string Offset { get; }
112118
public Z64Object.PlayerAnimationHolder PlayerAnimationHolder { get; }
113119

114120
public PlayerAnimationEntry(
115121
SkeletonViewerWindowViewModel parentVM,
116122
string name,
123+
uint offset,
117124
Z64Object.PlayerAnimationHolder playerAnimationHolder
118125
)
119126
{
120127
_parentVM = parentVM;
121128
Name = name;
129+
Offset = $"0x{offset:X6}";
122130
PlayerAnimationHolder = playerAnimationHolder;
123131
}
124132

@@ -135,17 +143,23 @@ public class ExternalPlayerAnimationEntry : PlayerAnimationEntry, IExternalAnima
135143
public ExternalPlayerAnimationEntry(
136144
SkeletonViewerWindowViewModel parentVM,
137145
string name,
146+
uint offset,
138147
Z64Object.PlayerAnimationHolder playerAnimationHolder,
139148
Dictionary<int, F3DZEX.Memory.Segment> externalData
140149
)
141-
: base(parentVM, name, playerAnimationHolder)
150+
: base(parentVM, name, offset, playerAnimationHolder)
142151
{
143152
ExternalData = externalData;
144153
}
145154
}
146155

156+
public ObservableCollection<IAnimationEntry> AnimationEntries { get; } = new();
157+
158+
[ObservableProperty]
159+
string _animationFilterText = "";
160+
147161
[ObservableProperty]
148-
private ObservableCollection<IAnimationEntry> _animationEntries = new();
162+
private IEnumerable<IAnimationEntry> _filteredAnimationEntries = new List<IAnimationEntry>();
149163

150164
[ObservableProperty]
151165
private double _playAnimTickPeriodMs;
@@ -255,8 +269,16 @@ public SkeletonViewerWindowViewModel(Z64Game? game)
255269
PlayAnimTickPeriodMs = 1;
256270
_playAnimTimer.Interval = TimeSpan.FromMilliseconds(PlayAnimTickPeriodMs);
257271
break;
272+
case nameof(AnimationFilterText):
273+
UpdateFilteredAnimationEntries();
274+
break;
258275
}
259276
};
277+
AnimationEntries.CollectionChanged += (sender, e) =>
278+
{
279+
Logger.Debug("AnimationEntries.CollectionChanged");
280+
UpdateFilteredAnimationEntries();
281+
};
260282
SelectedLimbNodes.CollectionChanged += (sender, e) =>
261283
{
262284
Logger.Debug("SelectedLimbNodes.CollectionChanged");
@@ -395,6 +417,7 @@ public async Task LoadExternalFileAnimationsImpl(byte[] data)
395417
new ExternalRegularAnimationEntry(
396418
this,
397419
"ext_" + eAnim.Name,
420+
(uint)extObj.OffsetOf(eAnim),
398421
eAnim,
399422
externalData
400423
)
@@ -477,6 +500,7 @@ private async void LoadPlayerAnimationsImpl(Func<byte[], Task<Z64Object?>> gKeep
477500
new ExternalPlayerAnimationEntry(
478501
this,
479502
"ext_" + ePlayerAnim.Name,
503+
(uint)gKeepObj.OffsetOf(ePlayerAnim),
480504
ePlayerAnim,
481505
externalData
482506
)
@@ -558,16 +582,23 @@ private void UpdateLimbsDLists()
558582
LimbsDLists = null;
559583
}
560584

561-
public void SetAnimations(IEnumerable<Z64Object.AnimationHolder> animationHolders)
585+
public void SetAnimations(
586+
Z64Object obj,
587+
IEnumerable<Z64Object.AnimationHolder> animationHolders
588+
)
562589
{
563-
ObservableCollection<IAnimationEntry> newAnimations = new(
564-
animationHolders.Select(animationHolder => new RegularAnimationEntry(
565-
this,
566-
animationHolder.Name,
567-
animationHolder
568-
))
569-
);
570-
AnimationEntries = newAnimations;
590+
AnimationEntries.Clear();
591+
foreach (var animationHolder in animationHolders)
592+
{
593+
AnimationEntries.Add(
594+
new RegularAnimationEntry(
595+
this,
596+
animationHolder.Name,
597+
(uint)obj.OffsetOf(animationHolder),
598+
animationHolder
599+
)
600+
);
601+
}
571602
}
572603

573604
[MemberNotNull(nameof(CurPose))]
@@ -673,6 +704,17 @@ public void StopPlayingAnim()
673704
_playAnimTimer.IsEnabled = false;
674705
}
675706

707+
private void UpdateFilteredAnimationEntries()
708+
{
709+
var filter = AnimationFilterText.ToLower();
710+
if (filter == "")
711+
FilteredAnimationEntries = new List<IAnimationEntry>(AnimationEntries);
712+
else
713+
FilteredAnimationEntries = AnimationEntries.Where(a =>
714+
a.Name.ToLower().Contains(filter) || a.Offset.ToLower().Contains(filter)
715+
);
716+
}
717+
676718
public void OnAnimationEntrySelected(IAnimationEntry animationEntry)
677719
{
678720
Utils.Assert(Renderer != null);

Z64Utils/Views/SkeletonViewerWindow.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@
104104
<GridSplitter Grid.Row="1" ResizeDirection="Rows" />
105105
<DockPanel Grid.Row="2">
106106
<TextBlock DockPanel.Dock="Top">Animations</TextBlock>
107+
<TextBox DockPanel.Dock="Top" Text="{Binding AnimationFilterText}" />
107108
<DataGrid
108109
Name="AnimationEntriesDataGrid"
109-
ItemsSource="{Binding AnimationEntries}"
110+
ItemsSource="{Binding FilteredAnimationEntries}"
110111
IsReadOnly="True"
111112
CanUserResizeColumns="True"
112113
GridLinesVisibility="All"
@@ -115,6 +116,7 @@
115116
>
116117
<DataGrid.Columns>
117118
<DataGridTextColumn Header="Name" Binding="{Binding Name}" />
119+
<DataGridTextColumn Header="Offset" Binding="{Binding Offset}" />
118120
</DataGrid.Columns>
119121
</DataGrid>
120122
</DockPanel>

0 commit comments

Comments
 (0)