Skip to content

Commit c456677

Browse files
committed
add remove buttons to event actions and sprite collision masks
1 parent dcda0fb commit c456677

File tree

6 files changed

+68
-5
lines changed

6 files changed

+68
-5
lines changed

UndertaleModLib/Models/UndertaleGameObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader)
279279
// TODO: Add documentation for these methods.
280280
// These methods are used by scripts for getting a code entry for a certain event of the game object.
281281

282-
public UndertaleCode EventHandlerFor(EventType type, uint subtype, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> localslist)
282+
public UndertaleCode EventHandlerFor(EventType type, uint subtype, IList<UndertaleString> strg, IList<UndertaleCode> codelist, IList<UndertaleCodeLocals> localslist, EventAction addToAction = null)
283283
{
284284
Event subtypeObj = Events[(int)type].FirstOrDefault(x => x.EventSubtype == subtype);
285285
if (subtypeObj == null)
286286
Events[(int)type].Add(subtypeObj = new Event() { EventSubtype = subtype });
287-
EventAction action = subtypeObj.Actions.FirstOrDefault();
287+
EventAction action = addToAction is null ? subtypeObj.Actions.FirstOrDefault() : addToAction;
288288
if (action == null)
289289
{
290290
subtypeObj.Actions.Add(action = new EventAction());

UndertaleModTool/Controls/UndertaleObjectReference.xaml.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using UndertaleModLib.Models;
2222
using UndertaleModLib.Scripting;
2323
using UndertaleModTool.Windows;
24+
using static UndertaleModLib.Models.UndertaleGameObject;
2425

2526
namespace UndertaleModTool
2627
{
@@ -69,6 +70,12 @@ public partial class UndertaleObjectReference : UserControl
6970
new FrameworkPropertyMetadata(true,
7071
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
7172

73+
public static DependencyProperty ObjectEventActionProperty =
74+
DependencyProperty.Register("ObjectEventAction", typeof(EventAction),
75+
typeof(UndertaleObjectReference),
76+
new FrameworkPropertyMetadata(null,
77+
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
78+
7279
public static DependencyProperty ObjectEventTypeProperty =
7380
DependencyProperty.Register("ObjectEventType", typeof(EventType),
7481
typeof(UndertaleObjectReference),
@@ -100,6 +107,12 @@ public bool CanRemove
100107
set { SetValue(ObjectTypeProperty, value); }
101108
}
102109

110+
public EventAction ObjectEventAction
111+
{
112+
get { return (EventAction)GetValue(ObjectEventActionProperty); }
113+
set { SetValue(ObjectEventActionProperty, value); }
114+
}
115+
103116
public EventType ObjectEventType
104117
{
105118
get { return (EventType)GetValue(ObjectEventTypeProperty); }
@@ -159,7 +172,7 @@ private void Details_Click(object sender, RoutedEventArgs e)
159172
else if (mainWindow.Selected is UndertaleGameObject gameObject)
160173
{
161174
// Generate the code entry
162-
UndertaleCode code = gameObject.EventHandlerFor(ObjectEventType, ObjectEventSubtype, mainWindow.Data.Strings, mainWindow.Data.Code, mainWindow.Data.CodeLocals);
175+
UndertaleCode code = gameObject.EventHandlerFor(ObjectEventType, ObjectEventSubtype, mainWindow.Data.Strings, mainWindow.Data.Code, mainWindow.Data.CodeLocals, ObjectEventAction);
163176

164177
ObjectReference = code;
165178
}

UndertaleModTool/Editors/UndertaleGameObjectEditor.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@
494494
<DataTemplate>
495495
<local:UndertaleObjectReference ObjectReference="{Binding CodeId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ObjectType="{x:Type undertale:UndertaleCode}"
496496
Margin="23,3,3,3" CanRemove="False"
497+
Loaded="UndertaleObjectReference_Loaded"
498+
ObjectEventAction="{Binding Mode=OneTime}"
497499
ObjectEventType="{Binding Text, Mode=OneTime, ElementName=EventTypeName, Converter={StaticResource EventNameConverter}, ConverterParameter=EventType}"
498500
ObjectEventSubtype="{Binding DataContext.EventSubtype, Mode=OneWay, RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
499501
</DataTemplate>

UndertaleModTool/Editors/UndertaleGameObjectEditor.xaml.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Microsoft.CodeAnalysis.CSharp.Syntax;
2+
using System;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.Linq;
@@ -68,5 +69,38 @@ private void ComboBox_DropDownClosed(object sender, EventArgs e)
6869
{
6970
handleMouseScroll = true;
7071
}
72+
73+
private void UndertaleObjectReference_Loaded(object sender, RoutedEventArgs e)
74+
{
75+
var objRef = sender as UndertaleObjectReference;
76+
77+
objRef.ClearRemoveClickHandler();
78+
objRef.RemoveButton.Click += Remove_Click_Override;
79+
objRef.RemoveButton.ToolTip = "Remove action";
80+
objRef.RemoveButton.IsEnabled = true;
81+
}
82+
private void Remove_Click_Override(object sender, RoutedEventArgs e)
83+
{
84+
var btn = (ButtonDark)sender;
85+
var objRef = (UndertaleObjectReference)((Grid)btn.Parent).Parent;
86+
87+
if (objRef.ObjectReference is not null)
88+
{
89+
objRef.ObjectReference = null;
90+
return;
91+
}
92+
93+
var obj = (UndertaleGameObject)DataContext;
94+
var evType = objRef.ObjectEventType;
95+
var evSubtype = objRef.ObjectEventSubtype;
96+
var action = (UndertaleGameObject.EventAction)btn.DataContext;
97+
var evList = ((UndertaleGameObject)DataContext).Events[(int)evType];
98+
var ev = evList[(int)evSubtype];
99+
ev.Actions.Remove(action);
100+
if (ev.Actions.Count <= 0)
101+
{
102+
evList.Remove(ev);
103+
}
104+
}
71105
}
72106
}

UndertaleModTool/Editors/UndertaleSpriteEditor.xaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,15 @@
197197
<DataGridTemplateColumn Width="*">
198198
<DataGridTemplateColumn.CellTemplate>
199199
<DataTemplate>
200-
<TextBlock Margin="20,0,0,0" Text="(CollisionMask)"/>
200+
<Grid Margin="20,0,0,0">
201+
<Grid.ColumnDefinitions>
202+
<ColumnDefinition Width="*"/>
203+
<ColumnDefinition Width="Auto"/>
204+
</Grid.ColumnDefinitions>
205+
<TextBlock Grid.Column="0" VerticalAlignment="Center" Text="(CollisionMask)"/>
206+
<local:ButtonDark Grid.Column="1" x:Name="RemoveButton" Content=" X " Click="RemoveMask_Clicked" ToolTip="Remove">
207+
</local:ButtonDark>
208+
</Grid>
201209
</DataTemplate>
202210
</DataGridTemplateColumn.CellTemplate>
203211
</DataGridTemplateColumn>

UndertaleModTool/Editors/UndertaleSpriteEditor.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,11 @@ private void Remove_Click_Override(object sender, RoutedEventArgs e)
224224
if (DataContext is UndertaleSprite sprite && (sender as FrameworkElement).DataContext is UndertaleSprite.TextureEntry entry)
225225
sprite.Textures.Remove(entry);
226226
}
227+
228+
private void RemoveMask_Clicked(object sender, RoutedEventArgs e)
229+
{
230+
if (DataContext is UndertaleSprite sprite && (sender as FrameworkElement).DataContext is UndertaleSprite.MaskEntry entry)
231+
sprite.CollisionMasks.Remove(entry);
232+
}
227233
}
228234
}

0 commit comments

Comments
 (0)