Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024.11 compatibility hacks #2013

Draft
wants to merge 29 commits into
base: underanalyzer
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fe9696b
2024.11 compatibility: Horrible hack to ignore null entries in list c…
Dobby233Liu Jan 9, 2025
9bed1ff
Assume GM 2024.11 if null pointers exist, add unknown property to UTFont
Dobby233Liu Jan 15, 2025
447f33e
Remove accidentally included debugging
Dobby233Liu Jan 15, 2025
6b110e8
**TEMP** Hack to make finding references work
Dobby233Liu Jan 15, 2025
9bc4c56
Make it possible to save with nulls in list chunk
Dobby233Liu Jan 16, 2025
fe1623e
Add ResourceListTreeViewItem with special handling for null items
Dobby233Liu Jan 16, 2025
01ad4ae
Random refactors to ResourceListTreeViewItem
Dobby233Liu Jan 18, 2025
82ea608
Convert resource list header hiding logic to style and restore old be…
Dobby233Liu Jan 18, 2025
3c2176f
Restore accidentally removed VisibleIfNotNull converter in MainWindow
Dobby233Liu Jan 18, 2025
d33c31f
Fix BGND reading & AGRP child object count miscounting
Dobby233Liu Jan 18, 2025
c1fe7da
Improve UndertaleResourceById handling regarding deleted objects
Dobby233Liu Jan 18, 2025
475643e
Fix UTFont estimated child object count in 2024.11+
Dobby233Liu Jan 18, 2025
97e5285
Add hidden setting ShowNullEntriesInDataHierarchy (disabled by default)
Dobby233Liu Jan 18, 2025
f61b170
Clarify ResourceById resource == null && cachedid >= 0 error
Dobby233Liu Jan 19, 2025
60caf58
Raise 2024.11 detection requirement to GMS2, better approach for null…
Dobby233Liu Jan 21, 2025
d1da607
Forgot to use old CachedId if the resource ocuppying the slot is stil…
Dobby233Liu Jan 21, 2025
a1fbca9
Check list boundary and fix typo
Dobby233Liu Jan 21, 2025
3633d1e
Try handling null in AddAssetsFromList
Dobby233Liu Feb 5, 2025
6db9587
Try handling null in GlobalDecompileContext
Dobby233Liu Feb 5, 2025
05cb9e7
Properly detect UnknownAlwaysZero in UTFont
Dobby233Liu Feb 16, 2025
aff5517
Cleanup
Dobby233Liu Feb 16, 2025
612b98c
Cleanup, properly calculate next glyph position, better safe than sorry
Dobby233Liu Feb 16, 2025
9e18dd6
Make the comment more coherent
Dobby233Liu Feb 16, 2025
e89d794
I promise this is the last cleanup
Dobby233Liu Feb 16, 2025
392ae25
Fix my broken XML comments
Dobby233Liu Feb 16, 2025
4723e12
Transform gm2024_11_WhatToSkip to BitArray
Dobby233Liu Feb 16, 2025
3958ec8
Null detection attempt
Dobby233Liu Feb 16, 2025
d5f7638
Forgot about this
Dobby233Liu Feb 16, 2025
c057ef9
Null adaptation 2: Parallel.ForEach flavor
Dobby233Liu Feb 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ResourceListTreeViewItem with special handling for null items
Dobby233Liu committed Mar 7, 2025
commit fe1623eaa95ac773df73d4a043505675fd5ab0b7
49 changes: 49 additions & 0 deletions UndertaleModTool/Controls/ResourceListTreeViewItem.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<TreeViewItem x:Class="UndertaleModTool.ResourceListTreeViewItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:UndertaleModTool"
xmlns:undertalelib="clr-namespace:UndertaleModLib;assembly=UndertaleModLib"
mc:Ignorable="d">

<TreeViewItem.Resources>
<local:ImplementsInterfaceConverter x:Key="ImplementsInterfaceConverter"/>

<DataTemplate x:Key="NullResourceItemTemplate">
<TextBlock Text="(null)"/>
</DataTemplate>

<local:ContextMenuDark x:Key="UndertaleResourceMenu" Opened="MenuItem_ContextMenuOpened">
<MenuItem Header="Open in new tab" Click="MenuItem_OpenInNewTab_Click"/>
<MenuItem Header="Find all references" Click="MenuItem_FindAllReferences_Click"/>
<MenuItem Header="Copy name to clipboard" Click="MenuItem_CopyName_Click"/>
<MenuItem Header="Delete" Click="MenuItem_Delete_Click"/>
</local:ContextMenuDark>

<!-- TODO: Would need some way to know the ID, IndexOf won't be reliable
<local:ContextMenuDark x:Key="NullResourceItemReplaceMenu" Opened="MenuItem_ContextMenuOpened_NullItem">
<MenuItem IsEnabled="False" Header="ID: " Name="ObjectIdLabel" />
<Separator />
<MenuItem Header="_Add in place" />
</local:ContextMenuDark>
-->

<Style x:Key="ResourceListTreeViewItem.ItemContainerStyle" TargetType="{x:Type TreeViewItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding ., Converter={StaticResource ImplementsInterfaceConverter}, ConverterParameter={x:Type undertalelib:UndertaleResource}}" Value="True">
<Setter Property="ContextMenu" Value="{StaticResource UndertaleResourceMenu}"/>
</DataTrigger>
<DataTrigger Binding="{Binding .}" Value="{x:Null}">
<Setter Property="Foreground" Value="Gray"/>
<!--<Setter Property="ContextMenu" Value="{StaticResource NullResourceItemReplaceMenu}"/>-->
</DataTrigger>
</Style.Triggers>
</Style>
</TreeViewItem.Resources>

<TreeViewItem.ItemContainerStyle>
<StaticResource ResourceKey="ResourceListTreeViewItem.ItemContainerStyle"/>
</TreeViewItem.ItemContainerStyle>

</TreeViewItem>
127 changes: 127 additions & 0 deletions UndertaleModTool/Controls/ResourceListTreeViewItem.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using UndertaleModLib;
using UndertaleModTool.Windows;

namespace UndertaleModTool
{
public partial class ResourceListTreeViewItem : TreeViewItem
{
public static readonly DependencyProperty DefaultTemplateProperty = DependencyProperty.Register(
"DefaultTemplate", typeof(DataTemplate), typeof(ResourceListTreeViewItem),
new FrameworkPropertyMetadata(default(DataTemplate), FrameworkPropertyMetadataOptions.AffectsRender, OnDefaultTemplateChanged));

public DataTemplate DefaultTemplate
{
get { return (DataTemplate)GetValue(DefaultTemplateProperty); }
set { SetValue(DefaultTemplateProperty, value); }
}

public ResourceListTreeViewItem()
{
InitializeComponent();

Binding visibilityBinding = new("ItemsSource")
{
Converter = new NullToVisibilityConverter() {
nullValue = Visibility.Collapsed,
notNullValue = Visibility.Visible
},
RelativeSource = RelativeSource.Self,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
SetBinding(VisibilityProperty, visibilityBinding);

ItemTemplateSelector = new ResourceItemTemplateSelector()
{
DefaultTemplate = DefaultTemplate,
NullTemplate = FindResource("NullResourceItemTemplate") as DataTemplate
};
}

private static void OnDefaultTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ResourceListTreeViewItem item = d as ResourceListTreeViewItem;
if (item is not null)
(item.ItemTemplateSelector as ResourceItemTemplateSelector).DefaultTemplate = item.DefaultTemplate;
}

private void MenuItem_ContextMenuOpened(object sender, RoutedEventArgs e)
{
var menu = sender as ContextMenu;
foreach (var item in menu.Items)
{
var menuItem = item as MenuItem;
if ((menuItem.Header as string) == "Find all references")
{
menuItem.Visibility = UndertaleResourceReferenceMap.IsTypeReferenceable(menu.DataContext?.GetType())
? Visibility.Visible : Visibility.Collapsed;

break;
}
}
}

private void MenuItem_OpenInNewTab_Click(object sender, RoutedEventArgs e)
{
MainWindow window = (MainWindow)Application.Current.MainWindow;
window.OpenInTab(window.Highlighted, true);
}

private void MenuItem_FindAllReferences_Click(object sender, RoutedEventArgs e)
{
MainWindow window = (MainWindow)Application.Current.MainWindow;
var obj = (sender as FrameworkElement)?.DataContext as UndertaleResource;
if (obj is null)
{
window.ShowError("The selected object is not an \"UndertaleResource\".");
return;
}

FindReferencesTypesDialog dialog = null;
try
{
dialog = new(obj, window.Data);
dialog.ShowDialog();
}
catch (Exception ex)
{
window.ShowError("An error occured in the object references related window.\n" +
$"Please report this on GitHub.\n\n{ex}");
}
finally
{
dialog?.Close();
}
}

private void MenuItem_CopyName_Click(object sender, RoutedEventArgs e)
{
MainWindow window = (MainWindow)Application.Current.MainWindow;
window.CopyItemName(window.Highlighted);
}

private void MenuItem_Delete_Click(object sender, RoutedEventArgs e)
{
MainWindow window = (MainWindow)Application.Current.MainWindow;
if (window.Highlighted is UndertaleObject obj)
window.DeleteItem(obj);
}
}

public class ResourceItemTemplateSelector : DataTemplateSelector
{
public DataTemplate DefaultTemplate { get; set; }
public DataTemplate NullTemplate { get; set; }

public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is null)
return NullTemplate;
return DefaultTemplate;
}
}
}
Loading