Skip to content

Commit

Permalink
Merge pull request #1939 from Skirlez/master
Browse files Browse the repository at this point in the history
Add ParentEntry to code editor
  • Loading branch information
Miepee authored Nov 27, 2024
2 parents b286cd3 + 08a2034 commit 5bbc257
Show file tree
Hide file tree
Showing 3 changed files with 34 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 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

0 comments on commit 5bbc257

Please sign in to comment.