Skip to content

Commit

Permalink
Added CanDragInto property to UndertaleObjectReference
Browse files Browse the repository at this point in the history
  • Loading branch information
Skirlez committed Oct 24, 2024
1 parent f9b6d5a commit 7521b6c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
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 CanDragInto, 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 CanDragIntoProperty =
DependencyProperty.Register("CanDragInto", 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 CanDragInto
{
get { return (bool)GetValue(CanDragIntoProperty); }
set { SetValue(CanDragIntoProperty, 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 (CanDragInto)
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 && CanDragInto && 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 && CanDragInto && sourceItem.GetType() == ObjectType ? DragDropEffects.Link : DragDropEffects.None;
if (e.Effects == DragDropEffects.Link)
{
ObjectReference = sourceItem;
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTool/Editors/UndertaleCodeEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<local:TextBoxDark Grid.Row="3" Grid.Column="1" Margin="3" Text="{Binding Offset}"/>

<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"/>
<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" CanDragInto="True"/>

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

0 comments on commit 7521b6c

Please sign in to comment.