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

Add ParentEntry to code editor #1939

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions UndertaleModTool/Controls/UndertaleObjectReference.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<local:TextBoxDark Grid.Column="0" x:Name="ObjectText" IsReadOnly="True" Cursor="Arrow" AllowDrop="True"
ToolTip="This is an object reference. Drag and drop an object of matching type from the tree on the left to change it!"
ToolTipService.InitialShowDelay="250"
PreviewDragOver="TextBox_DragOver" PreviewDrop="TextBox_Drop" PreviewMouseDoubleClick="TextBox_MouseDoubleClick" PreviewMouseDown="Details_MouseDown"
Text="{Binding ObjectReference, ElementName=objectReference}">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding CanChange, ElementName=objectReference}" Value="True">
<Setter Property="ToolTip" Value="This is an object reference. Drag and drop an object of matching type from the tree on the left to change it!" />
<Setter Property="ToolTipService.InitialShowDelay" Value="250" />
</DataTrigger>
<DataTrigger Binding="{Binding ObjectReference, ElementName=objectReference}" Value="{x:Null}">
<Setter Property="Background">
<Setter.Value>
Expand Down
29 changes: 22 additions & 7 deletions UndertaleModTool/Controls/UndertaleObjectReference.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ public partial class UndertaleObjectReference : UserControl
typeof(UndertaleObjectReference),
new FrameworkPropertyMetadata(true,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));


public static DependencyProperty CanChangeProperty =
DependencyProperty.Register("CanChange", typeof(bool),
typeof(UndertaleObjectReference),
new FrameworkPropertyMetadata(true,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

public static DependencyProperty ObjectEventTypeProperty =
DependencyProperty.Register("ObjectEventType", typeof(EventType),
typeof(UndertaleObjectReference),
Expand Down Expand Up @@ -94,8 +100,14 @@ public Type ObjectType

public bool CanRemove
{
get { return (bool)GetValue(ObjectTypeProperty); }
set { SetValue(ObjectTypeProperty, value); }
get { return (bool)GetValue(CanRemoveProperty); }
set { SetValue(CanRemoveProperty, value); }
}

public bool CanChange
{
get { return (bool)GetValue(CanChangeProperty); }
set { SetValue(CanChangeProperty, value); }
}

public EventType ObjectEventType
Expand Down Expand Up @@ -136,8 +148,11 @@ private void UndertaleObjectReference_Loaded(object sender, RoutedEventArgs e)
// If the first letter is a vowel
if (Array.IndexOf(vowels, typeName[0]) != -1)
n = "n";

label.Content = $"(drag & drop a{n} {typeName})";

if (CanChange)
label.Content = $"(drag & drop a{n} {typeName})";
else
label.Content = $"(empty {typeName} reference)";
}

public void ClearRemoveClickHandler()
Expand Down Expand Up @@ -244,15 +259,15 @@ private void TextBox_DragOver(object sender, DragEventArgs e)
{
UndertaleObject sourceItem = e.Data.GetData(e.Data.GetFormats()[0]) as UndertaleObject;

e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && sourceItem.GetType() == ObjectType ? DragDropEffects.Link : DragDropEffects.None;
e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && CanChange && sourceItem.GetType() == ObjectType ? DragDropEffects.Link : DragDropEffects.None;
e.Handled = true;
}

private void TextBox_Drop(object sender, DragEventArgs e)
{
UndertaleObject sourceItem = e.Data.GetData(e.Data.GetFormats()[0]) as UndertaleObject;

e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && sourceItem.GetType() == ObjectType ? DragDropEffects.Link : DragDropEffects.None;
e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && CanChange && sourceItem.GetType() == ObjectType ? DragDropEffects.Link : DragDropEffects.None;
if (e.Effects == DragDropEffects.Link)
{
ObjectReference = sourceItem;
Expand Down
9 changes: 8 additions & 1 deletion UndertaleModTool/Editors/UndertaleCodeEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<UserControl.InputBindings>
<KeyBinding Modifiers="Control" Key="K" Command="{x:Static local:UndertaleCodeEditor.Compile}"/>
</UserControl.InputBindings>
<UserControl.Resources>
<local:NullToVisibilityConverter x:Key="VisibleIfNotNull" nullValue="Collapsed" notNullValue="Visible"/>
</UserControl.Resources>
<Grid MaxHeight="{Binding ElementName=DataEditor, Path=ActualHeight}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
Expand All @@ -24,6 +27,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>

Expand All @@ -39,7 +43,10 @@
<TextBlock Grid.Row="3" Grid.Column="0" Margin="3">Offset</TextBlock>
<local:TextBoxDark Grid.Row="3" Grid.Column="1" Margin="3" Text="{Binding Offset}"/>

<TabControl x:Name="CodeModeTabs" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" SelectionChanged="TabControl_SelectionChanged">
<TextBlock Grid.Row="4" Grid.Column="0" Margin="3" Visibility="{Binding ParentEntry, Converter={StaticResource VisibleIfNotNull}}">Parent entry</TextBlock>
<local:UndertaleObjectReference Grid.Row="4" Grid.Column="1" Margin="3" Visibility="{Binding ParentEntry, Converter={StaticResource VisibleIfNotNull}}" ObjectReference="{Binding ParentEntry}" ObjectType="{x:Type undertale:UndertaleCode}" CanRemove="False" CanChange="False"/>

<TabControl x:Name="CodeModeTabs" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" SelectionChanged="TabControl_SelectionChanged">
<TabItem Header="Decompiled" Name="DecompiledTab">
<Grid>
<avalonEdit:TextEditor
Expand Down
Loading