Skip to content

Commit

Permalink
add context menu to file info explorer (#43)
Browse files Browse the repository at this point in the history
* add context menu to file info explorer

* catch HwGfxObjId == 0 case
  • Loading branch information
gmriggs authored Jan 23, 2022
1 parent 5a02cca commit a828c0c
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
7 changes: 6 additions & 1 deletion ACViewer/Render/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ public void InitEmitters()
foreach (var createParticleHook in createParticleHooks)
{
var emitterIdx = staticObj.create_particle_emitter(createParticleHook.EmitterInfoId, (int)createParticleHook.PartIndex, new AFrame(createParticleHook.Offset), (int)createParticleHook.EmitterId);
var emitter = staticObj.ParticleManager.ParticleTable[emitterIdx];

if (!staticObj.ParticleManager.ParticleTable.TryGetValue(emitterIdx, out var emitter))
{
// can happen if HwGfxObjId==0, skip
continue;
}
Buffer.AddEmitter(emitter);
EmitterParents++;
}
Expand Down
10 changes: 9 additions & 1 deletion ACViewer/View/FileInfo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<!-- <VirtualizingStackPanel.VirtualizationMode="Recycling" -->
<TreeView ItemsSource="{Binding Path=Info}" ScrollViewer.VerticalScrollBarVisibility="Auto" VirtualizingStackPanel.IsVirtualizing="True">
<TreeView Name="FileInfo_TreeView" ItemsSource="{Binding Path=Info}" ScrollViewer.VerticalScrollBarVisibility="Auto" VirtualizingStackPanel.IsVirtualizing="True">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type entity:TreeNode}" ItemsSource="{Binding Path=Items}">
<TreeViewItem Header="{Binding Path=Name}" />
Expand All @@ -23,6 +23,14 @@
<EventSetter Event="MouseLeave" Handler="TreeViewItem_MouseLeave"/>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Header="Expand All" Click="TreeView_Expand"/>
<MenuItem Header="Collapse All" Click="TreeView_Collapse"/>
<Separator />
<MenuItem Header="Copy All" Click="TreeView_Copy"/>
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</Grid>
</UserControl>
92 changes: 92 additions & 0 deletions ACViewer/View/FileInfo.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;

using ACViewer.Entity;
Expand Down Expand Up @@ -39,10 +40,15 @@ public FileInfo()
Instance = this;

DataContext = this;

FileInfo_TreeView.ItemContainerGenerator.StatusChanged += new EventHandler(ItemContainerGenerator_StatusChanged);
}

private bool pendingLoad;

public void SetInfo(TreeNode treeNode)
{
pendingLoad = true;
Info = new List<TreeNode>() { treeNode };
}

Expand Down Expand Up @@ -106,5 +112,91 @@ private void TreeViewItem_MouseLeave(object sender, RoutedEventArgs e)

source.FontWeight = FontWeights.Normal;
}

private void TreeView_Expand(object sender, RoutedEventArgs e)
{
SetExpanded(true);
}

private void TreeView_Collapse(object sender, RoutedEventArgs e)
{
pendingLoad = true;
SetExpanded(false);
}

private void SetExpanded(bool expanded)
{
var style = new Style();
style.Setters.Add(new EventSetter(MouseLeftButtonUpEvent, new MouseButtonEventHandler(TreeViewItem_Selected)));
style.Setters.Add(new EventSetter(MouseEnterEvent, new MouseEventHandler(TreeViewItem_MouseEnter)));
style.Setters.Add(new EventSetter(MouseLeaveEvent, new MouseEventHandler(TreeViewItem_MouseLeave)));
style.Setters.Add(new Setter(TreeViewItem.IsExpandedProperty, expanded));

FileInfo_TreeView.ItemContainerStyle = style;
}

private void TreeView_Copy(object sender, RoutedEventArgs e)
{
var lines = new List<string>();

foreach (var node in Info)
TreeView_CopyAppend(lines, node);

/*foreach (var line in lines)
Console.WriteLine(line);*/

Clipboard.SetText(string.Join(Environment.NewLine, lines));
}

private void TreeView_CopyAppend(List<string> lines, TreeNode node, int depth = 0)
{
var padding = new string(' ', depth * 4);

lines.Add($"{padding}{node.Name}");

foreach (var childNode in node.Items)
TreeView_CopyAppend(lines, childNode, depth + 1);
}

private void ScrollTop()
{
if (FileInfo_TreeView.Items.Count == 0) return;

var firstItem = FileInfo_TreeView.Items[0];

var control = FileInfo_TreeView.ItemContainerGenerator.ContainerFromItem(firstItem) as ItemsControl;

if (control == null) return;

control.BringIntoView();
}

private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
{
if (!pendingLoad || FileInfo_TreeView.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) return;

pendingLoad = false;

ScrollTop();

ExpandFirstItem();
}

private void ExpandFirstItem()
{
if (FileInfo_TreeView.Items.Count == 0) return;

var firstItem = FileInfo_TreeView.Items[0];

var control = FileInfo_TreeView.ItemContainerGenerator.ContainerFromItem(firstItem) as ItemsControl;

if (control == null) return;

var tvi = control as TreeViewItem;

if (tvi == null) return;

tvi.IsExpanded = true;
}
}
}

0 comments on commit a828c0c

Please sign in to comment.