Skip to content

Commit

Permalink
Merge pull request #932 from VladiStep/textureReferences
Browse files Browse the repository at this point in the history
Improved sprite texture entries removing.
  • Loading branch information
Grossley authored May 25, 2022
2 parents 8d8f186 + 1a5568d commit d2a20b6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
9 changes: 6 additions & 3 deletions UndertaleModTool/Controls/UndertaleObjectReference.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" IsReadOnly="True" Cursor="Arrow" ToolTip="This is an object reference. Drag and drop an object of matching type from the tree on the left to change it!" AllowDrop="True" PreviewDragOver="TextBox_DragOver" PreviewDrop="TextBox_Drop" PreviewMouseDoubleClick="TextBox_MouseDoubleClick" Text="{Binding ObjectReference, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
<Button Grid.Column="1" Click="Details_Click">
<TextBox Grid.Column="0" 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!"
PreviewDragOver="TextBox_DragOver" PreviewDrop="TextBox_Drop" PreviewMouseDoubleClick="TextBox_MouseDoubleClick"
Text="{Binding ObjectReference, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
<Button Grid.Column="1" Name="DetailsButton" Click="Details_Click">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Content" Value=" ... " />
Expand All @@ -36,7 +39,7 @@
</Style>
</Button.Style>
</Button>
<Button Grid.Column="2" Click="Remove_Click" Content=" X " ToolTip="Remove reference">
<Button Grid.Column="2" Name="RemoveButton" Click="Remove_Click" Content=" X " ToolTip="Remove reference">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
Expand Down
5 changes: 5 additions & 0 deletions UndertaleModTool/Controls/UndertaleObjectReference.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public UndertaleObjectReference()
InitializeComponent();
}

public void ClearRemoveClickHandler()
{
RemoveButton.Click -= Remove_Click;
}

private void Details_Click(object sender, RoutedEventArgs e)
{
if (ObjectReference is null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<local:DataUserControl x:Class="UndertaleModTool.UndertaleTexturePageItemDisplay"
<UserControl x:Class="UndertaleModTool.UndertaleTexturePageItemDisplay"
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"
Expand All @@ -21,4 +21,4 @@
</Border.Background>
</Border>
</Canvas>
</local:DataUserControl>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace UndertaleModTool
/// <summary>
/// Logika interakcji dla klasy UndertaleTexturePageItemDisplay.xaml
/// </summary>
public partial class UndertaleTexturePageItemDisplay : DataUserControl
public partial class UndertaleTexturePageItemDisplay : UserControl
{
public UndertaleTexturePageItemDisplay()
{
Expand Down
10 changes: 8 additions & 2 deletions UndertaleModTool/Editors/UndertaleSpriteEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@
</Grid>

<TextBlock Grid.Row="10" Grid.Column="0" Margin="3">Textures</TextBlock>
<DataGrid Grid.Row="10" Grid.Column="1" Margin="3" ItemsSource="{Binding Textures, Mode=OneWay}" Name="TextureList" AutoGenerateColumns="False" CanUserAddRows="True" CanUserDeleteRows="True" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" HeadersVisibility="None" SelectionMode="Single" SelectionUnit="FullRow" IsSynchronizedWithCurrentItem="True">
<DataGrid Grid.Row="10" Grid.Column="1" Margin="3" ItemsSource="{Binding Textures, Mode=OneWay}" Name="TextureList"
AutoGenerateColumns="False" CanUserAddRows="True" CanUserDeleteRows="True"
HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray"
HeadersVisibility="None" SelectionMode="Single" SelectionUnit="FullRow" IsSynchronizedWithCurrentItem="True">
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF26A0DA"/>
<Style TargetType="{x:Type DataGridCell}">
Expand Down Expand Up @@ -135,7 +138,10 @@
<DataGridTemplateColumn Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<local:UndertaleObjectReference Margin="20,0,0,0" ObjectReference="{Binding Texture, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ObjectType="{x:Type undertale:UndertaleTexturePageItem}" CanRemove="False"/>
<local:UndertaleObjectReference Margin="20,0,0,0" CanRemove="True"
Loaded="UndertaleObjectReference_Loaded"
ObjectReference="{Binding Texture, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ObjectType="{x:Type undertale:UndertaleTexturePageItem}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Expand Down
22 changes: 22 additions & 0 deletions UndertaleModTool/Editors/UndertaleSpriteEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,27 @@ private void MaskExport_Click(object sender, RoutedEventArgs e)
}
}
}

private void UndertaleObjectReference_Loaded(object sender, RoutedEventArgs e)
{
var objRef = sender as UndertaleObjectReference;

objRef.ClearRemoveClickHandler();
objRef.RemoveButton.Click += Remove_Click_Override;
objRef.RemoveButton.ToolTip = "Remove texture entry";
objRef.RemoveButton.IsEnabled = true;
objRef.DetailsButton.ToolTip = "Open texture entry";
objRef.ObjectText.PreviewKeyDown += ObjectText_PreviewKeyDown;
}
private void ObjectText_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Delete)
Remove_Click_Override(sender, null);
}
private void Remove_Click_Override(object sender, RoutedEventArgs e)
{
if (DataContext is UndertaleSprite sprite && (sender as FrameworkElement).DataContext is UndertaleSprite.TextureEntry entry)
sprite.Textures.Remove(entry);
}
}
}

0 comments on commit d2a20b6

Please sign in to comment.