Skip to content

Commit a1f9497

Browse files
committed
trigger editing works
1 parent 485e693 commit a1f9497

File tree

3 files changed

+96
-33
lines changed

3 files changed

+96
-33
lines changed

FF4/WorldMapTrigger.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ public abstract class WorldMapTrigger
1010
{
1111
public readonly byte[] Bytes;
1212

13-
protected WorldMapTrigger(byte[] bytes)
13+
public WorldMapTriggerType Type { get; set; }
14+
15+
protected WorldMapTrigger(byte[] bytes, WorldMapTriggerType type)
1416
{
1517
Bytes = bytes;
18+
Type = type;
1619
}
1720

1821
public byte X
@@ -27,9 +30,21 @@ public byte Y
2730
}
2831
}
2932

33+
public enum WorldMapTriggerType : byte
34+
{
35+
Teleport,
36+
Event = 0xFF
37+
}
38+
3039
public class WorldMapTeleport : WorldMapTrigger
3140
{
32-
public WorldMapTeleport(byte[] bytes) : base(bytes) {}
41+
public WorldMapTeleport(byte[] bytes) : base(bytes, WorldMapTriggerType.Teleport)
42+
{
43+
if (DestinationMap == 0xFF)
44+
{
45+
DestinationMap = 0x00;
46+
}
47+
}
3348

3449
public byte DestinationMap
3550
{
@@ -61,7 +76,7 @@ public FacingDirection FacingDirection
6176
}
6277
}
6378

64-
public enum FacingDirection
79+
public enum FacingDirection : byte
6580
{
6681
North = 0x00,
6782
East = 0x40,
@@ -71,7 +86,10 @@ public enum FacingDirection
7186

7287
public class WorldMapEvent : WorldMapTrigger
7388
{
74-
public WorldMapEvent(byte[] bytes) : base(bytes) {}
89+
public WorldMapEvent(byte[] bytes) : base(bytes, WorldMapTriggerType.Event)
90+
{
91+
Bytes[2] = 0xFF;
92+
}
7593

7694
public byte EventCall
7795
{

FF4MapEdit/WorldMapTriggersWindow.xaml

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,58 @@
1010
Title="WorldMapTriggersWindow" Height="450" Width="800" Closed="Window_Closed">
1111
<Window.Resources>
1212
<!--Create list of enumeration values-->
13-
<ObjectDataProvider x:Key="facingDirection" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
13+
<ObjectDataProvider x:Key="FacingDirection" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
1414
<ObjectDataProvider.MethodParameters>
1515
<x:Type Type="ff4:FacingDirection"/>
1616
</ObjectDataProvider.MethodParameters>
1717
</ObjectDataProvider>
18+
<ObjectDataProvider x:Key="WorldMapTriggerType" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
19+
<ObjectDataProvider.MethodParameters>
20+
<x:Type Type="ff4:WorldMapTriggerType"/>
21+
</ObjectDataProvider.MethodParameters>
22+
</ObjectDataProvider>
1823
<local:HexValueConverter x:Key="HexValueConverter"/>
1924
<local:WorldMapTriggerDataTemplateSelector x:Key="WorldMapTriggerDataTemplateSelector"/>
2025
<DataTemplate x:Key="WorldMapTeleportTemplate" DataType="{x:Type ff4:WorldMapTeleport}">
21-
<StackPanel Orientation="Horizontal">
22-
<Label Margin="20,0,0,0">Coords:</Label>
23-
<TextBox Width="24" Text="{Binding X, Converter={StaticResource HexValueConverter}}"/>
24-
<TextBox Width="24" Text="{Binding Y, Converter={StaticResource HexValueConverter}}"/>
25-
<Label Margin="20,0,0,0">Map:</Label>
26-
<TextBox Width="24" Text="{Binding DestinationMap, Converter={StaticResource HexValueConverter}}"/>
27-
<Label Margin="20,0,0,0">Dest:</Label>
28-
<TextBox Width="24" Text="{Binding DestinationX, Converter={StaticResource HexValueConverter}}"/>
29-
<TextBox Width="24" Text="{Binding DestinationY, Converter={StaticResource HexValueConverter}}"/>
30-
<Label Margin="20,0,0,0">Facing:</Label>
31-
<ComboBox Width="60" SelectedValue="{Binding FacingDirection}" ItemsSource="{Binding Source={StaticResource facingDirection}}"></ComboBox>
32-
</StackPanel>
26+
<Border Padding="2">
27+
<StackPanel Orientation="Horizontal">
28+
<ComboBox Width="100" SelectedValue="{Binding Type, Mode=OneWay}" ItemsSource="{Binding Source={StaticResource WorldMapTriggerType}}" SelectionChanged="TriggerType_SelectionChanged"/>
29+
<Label Margin="20,0,0,0">Coords:</Label>
30+
<TextBox Width="24" Text="{Binding X, Converter={StaticResource HexValueConverter}}"/>
31+
<TextBox Width="24" Text="{Binding Y, Converter={StaticResource HexValueConverter}}"/>
32+
<Label Margin="20,0,0,0">Map:</Label>
33+
<TextBox Width="24" Text="{Binding DestinationMap, Converter={StaticResource HexValueConverter}}"/>
34+
<Label Margin="20,0,0,0">Dest:</Label>
35+
<TextBox Width="24" Text="{Binding DestinationX, Converter={StaticResource HexValueConverter}}"/>
36+
<TextBox Width="24" Text="{Binding DestinationY, Converter={StaticResource HexValueConverter}}"/>
37+
<Label Margin="20,0,0,0">Facing:</Label>
38+
<ComboBox Width="60" SelectedValue="{Binding FacingDirection}" ItemsSource="{Binding Source={StaticResource FacingDirection}}"></ComboBox>
39+
</StackPanel>
40+
</Border>
3341
</DataTemplate>
3442
<DataTemplate x:Key="WorldMapEventTemplate" DataType="{x:Type ff4:WorldMapEvent}">
35-
<StackPanel Orientation="Horizontal">
36-
<Label Margin="20,0,0,0">Coords:</Label>
37-
<TextBox Width="24" Text="{Binding X, Converter={StaticResource HexValueConverter}}"/>
38-
<TextBox Width="24" Text="{Binding Y, Converter={StaticResource HexValueConverter}}"/>
39-
<Label Margin="20,0,0,0">Event Call:</Label>
40-
<TextBox Width="24" Text="{Binding EventCall, Converter={StaticResource HexValueConverter}}"/>
41-
</StackPanel>
43+
<Border Padding="2">
44+
<StackPanel Orientation="Horizontal">
45+
<ComboBox Width="100" SelectedValue="{Binding Type}" ItemsSource="{Binding Source={StaticResource WorldMapTriggerType}}" SelectionChanged="TriggerType_SelectionChanged"/>
46+
<Label Margin="20,0,0,0">Coords:</Label>
47+
<TextBox Width="24" Text="{Binding X, Converter={StaticResource HexValueConverter}}"/>
48+
<TextBox Width="24" Text="{Binding Y, Converter={StaticResource HexValueConverter}}"/>
49+
<Label Margin="20,0,0,0">Event Call:</Label>
50+
<TextBox Width="24" Text="{Binding EventCall, Converter={StaticResource HexValueConverter}}"/>
51+
</StackPanel>
52+
</Border>
4253
</DataTemplate>
4354
<ControlTemplate x:Key="NoScroll">
4455
<ItemsPresenter></ItemsPresenter>
4556
</ControlTemplate>
4657
</Window.Resources>
4758
<ScrollViewer>
4859
<StackPanel VerticalAlignment="Top">
49-
<Label Margin="10,15,0,0">Overworld</Label>
60+
<Label Margin="10,15,0,0" FontWeight="Bold">Overworld</Label>
5061
<ListView x:Name="OverworldListView" Template="{StaticResource NoScroll}" ItemTemplateSelector="{StaticResource WorldMapTriggerDataTemplateSelector}"/>
51-
<Label Margin="10,15,0,0">Underworld</Label>
62+
<Label Margin="10,15,0,0" FontWeight="Bold">Underworld</Label>
5263
<ListView x:Name="UnderworldListView" Template="{StaticResource NoScroll}" ItemTemplateSelector="{StaticResource WorldMapTriggerDataTemplateSelector}"/>
53-
<Label Margin="10,15,0,0">Moon</Label>
64+
<Label Margin="10,15,0,0" FontWeight="Bold">Moon</Label>
5465
<ListView x:Name="MoonListView" Template="{StaticResource NoScroll}" ItemTemplateSelector="{StaticResource WorldMapTriggerDataTemplateSelector}"/>
5566
</StackPanel>
5667
</ScrollViewer>

FF4MapEdit/WorldMapTriggersWindow.xaml.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -23,9 +24,9 @@ public partial class WorldMapTriggersWindow : Window
2324
private readonly FF4Rom _rom;
2425

2526
private readonly ushort[] _pointers;
26-
private readonly List<WorldMapTrigger> _overworldTriggers;
27-
private readonly List<WorldMapTrigger> _underworldTriggers;
28-
private readonly List<WorldMapTrigger> _moonTriggers;
27+
private readonly ObservableCollection<WorldMapTrigger> _overworldTriggers;
28+
private readonly ObservableCollection<WorldMapTrigger> _underworldTriggers;
29+
private readonly ObservableCollection<WorldMapTrigger> _moonTriggers;
2930

3031
public WorldMapTriggersWindow(FF4Rom rom)
3132
{
@@ -37,9 +38,9 @@ public WorldMapTriggersWindow(FF4Rom rom)
3738
var overworldTriggerCount = _pointers[1] / FF4Rom.WorldMapTriggerSize;
3839
var underworldTriggerCount = _pointers[2] / FF4Rom.WorldMapTriggerSize - overworldTriggerCount;
3940
var moonTriggerCount = FF4Rom.WorldMapTriggerCount - overworldTriggerCount - underworldTriggerCount;
40-
_overworldTriggers = triggers.GetRange(0, overworldTriggerCount);
41-
_underworldTriggers = triggers.GetRange(overworldTriggerCount, underworldTriggerCount);
42-
_moonTriggers = triggers.GetRange(overworldTriggerCount + underworldTriggerCount, moonTriggerCount);
41+
_overworldTriggers = new ObservableCollection<WorldMapTrigger>(triggers.GetRange(0, overworldTriggerCount));
42+
_underworldTriggers = new ObservableCollection<WorldMapTrigger>(triggers.GetRange(overworldTriggerCount, underworldTriggerCount));
43+
_moonTriggers = new ObservableCollection<WorldMapTrigger>(triggers.GetRange(overworldTriggerCount + underworldTriggerCount, moonTriggerCount));
4344

4445
OverworldListView.ItemsSource = _overworldTriggers;
4546
UnderworldListView.ItemsSource = _underworldTriggers;
@@ -50,6 +51,39 @@ private void Window_Closed(object sender, EventArgs e)
5051
{
5152
_rom.SaveWorldMapTriggers(_overworldTriggers.Concat(_underworldTriggers).Concat(_moonTriggers).ToList(), _pointers);
5253
}
54+
55+
private void TriggerType_SelectionChanged(object sender, SelectionChangedEventArgs e)
56+
{
57+
var comboBox = (ComboBox)sender;
58+
var selectedType = (WorldMapTriggerType)comboBox.SelectedValue;
59+
60+
var parent = VisualTreeHelper.GetParent(comboBox);
61+
while (!(parent is ListViewItem))
62+
{
63+
parent = VisualTreeHelper.GetParent(parent);
64+
}
65+
var listViewItem = (ListViewItem)parent;
66+
67+
while (!(parent is ListView))
68+
{
69+
parent = VisualTreeHelper.GetParent(parent);
70+
}
71+
var listView = (ListView)parent;
72+
73+
var trigger = (WorldMapTrigger)listViewItem.DataContext;
74+
var selectedIndex = listView.Items.IndexOf(trigger);
75+
var items = (ObservableCollection<WorldMapTrigger>)listView.ItemsSource;
76+
if (trigger is WorldMapTeleport && selectedType == WorldMapTriggerType.Event)
77+
{
78+
items.RemoveAt(selectedIndex);
79+
items.Insert(selectedIndex, new WorldMapEvent(trigger.Bytes));
80+
}
81+
else if (trigger is WorldMapEvent && selectedType == WorldMapTriggerType.Teleport)
82+
{
83+
items.RemoveAt(selectedIndex);
84+
items.Insert(selectedIndex, new WorldMapTeleport(trigger.Bytes));
85+
}
86+
}
5387
}
5488

5589
public class WorldMapTriggerDataTemplateSelector : DataTemplateSelector

0 commit comments

Comments
 (0)