Skip to content

Commit 4570407

Browse files
committed
Fix crashes when deleting grids and the list of concealed entities.
1 parent c7362e0 commit 4570407

6 files changed

Lines changed: 178 additions & 62 deletions

File tree

Concealment/Commands.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,19 @@ public void RevealAll()
4141
int num = Plugin.RevealAll();
4242
Context.Respond($"{num} grids revealed.");
4343
}
44+
45+
[Command("conceal on", "Enable concealment.")]
46+
public void Enable()
47+
{
48+
Plugin.Settings.Data.Enabled = true;
49+
Plugin.ConcealGrids(Plugin.Settings.Data.ConcealDistance);
50+
}
51+
52+
[Command("conceal off", "Disable concealment.")]
53+
public void Disable()
54+
{
55+
Plugin.Settings.Data.Enabled = false;
56+
Plugin.RevealAll();
57+
}
4458
}
4559
}

Concealment/ConcealGroup.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
5+
using NLog;
56
using Sandbox.Game.Entities;
67
using Sandbox.Game.Entities.Blocks;
78
using Sandbox.Game.World;
@@ -48,21 +49,26 @@ public void UpdatePostConceal()
4849
public void UpdatePostReveal()
4950
{
5051
IsConcealed = false;
51-
foreach (var grid in Grids)
52-
grid.OnClosing -= Grid_OnClosing;
52+
UnhookOnClosing();
5353
}
5454

5555
private void HookOnClosing()
5656
{
5757
foreach (var grid in Grids)
58-
grid.OnClosing += Grid_OnClosing;
58+
grid.OnMarkForClose += Grid_OnMarkForClose;
5959
}
6060

61-
private void Grid_OnClosing(VRage.Game.Entity.MyEntity obj)
61+
private void UnhookOnClosing()
6262
{
63-
Closing?.Invoke(this);
6463
foreach (var grid in Grids)
65-
grid.OnClosing -= Grid_OnClosing;
64+
grid.OnMarkForClose -= Grid_OnMarkForClose;
65+
}
66+
67+
private void Grid_OnMarkForClose(VRage.Game.Entity.MyEntity obj)
68+
{
69+
LogManager.GetLogger(nameof(ConcealGroup)).Info($"Grid group '{GridNames}' was marked for close.");
70+
UnhookOnClosing();
71+
Closing?.Invoke(this);
6672
}
6773

6874
public void UpdateAABB()

Concealment/ConcealmentControl.xaml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66
xmlns:local="clr-namespace:Concealment"
77
mc:Ignorable="d"
88
d:DesignHeight="300" d:DesignWidth="300">
9-
<DockPanel>
10-
<StackPanel DockPanel.Dock="Top">
9+
<UserControl.DataContext>
10+
<local:ConcealmentPlugin/>
11+
</UserControl.DataContext>
12+
<Grid>
13+
<Grid.RowDefinitions>
14+
<RowDefinition Height="Auto"/>
15+
<RowDefinition/>
16+
</Grid.RowDefinitions>
17+
<StackPanel Grid.Row="0">
1118
<StackPanel DataContext="{Binding Settings.Data}">
1219
<CheckBox Content="Enable Concealment" Margin="3" IsChecked="{Binding Enabled}" />
13-
<CheckBox Content="Exempt Production" ToolTip="Don't conceal grids with active production blocks." Margin="3" IsChecked="{Binding ExemptProduction}" />
20+
<CheckBox Content="Conceal Production" ToolTip="Conceal grids with active production blocks." Margin="3" IsChecked="{Binding ConcealProduction}" />
21+
<CheckBox Content="Conceal Pirates" ToolTip="Conceal grids owned by Space Pirates." Margin="3" IsChecked="{Binding ConcealPirates}" />
1422
<StackPanel Orientation="Horizontal">
1523
<TextBox Margin="3" Width="150" Text="{Binding ConcealDistance}" />
1624
<Label Content="Conceal Distance (meters)" Margin="3" />
@@ -33,9 +41,10 @@
3341
<Button Content="Manual Reveal" Margin="3" Click="Reveal_OnClick" />
3442
</StackPanel>
3543
<Button Content="Edit Excluded Subtypes" Margin="3" Click="EditExclusion_OnClick"/>
44+
<Label Content="{Binding ConcealedGroups.Count, StringFormat=Concealed groups: {0}}"/>
45+
<Button Content="Reveal Selected" Margin="3" DockPanel.Dock="Bottom" Click="RevealSelected_OnClick" />
3646
</StackPanel>
37-
<Button Content="Reveal Selected" Margin="3" DockPanel.Dock="Bottom" Click="RevealSelected_OnClick" />
38-
<ListView Name="Concealed" Margin="3" DockPanel.Dock="Bottom" ItemsSource="{Binding ConcealGroups}">
47+
<ListView Grid.Row="1" Name="Concealed" Margin="3" DockPanel.Dock="Bottom" ItemsSource="{Binding ConcealedGroups}">
3948
<ItemsControl.ItemTemplate>
4049
<DataTemplate>
4150
<StackPanel>
@@ -44,6 +53,6 @@
4453
</DataTemplate>
4554
</ItemsControl.ItemTemplate>
4655
</ListView>
47-
</DockPanel>
56+
</Grid>
4857

4958
</UserControl>

Concealment/ConcealmentControl.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private void RevealSelected_OnClick(object sender, RoutedEventArgs e)
3939
private void Reveal_OnClick(object sender, RoutedEventArgs e)
4040
{
4141
var p = Plugin;
42-
Plugin.Torch.Invoke(delegate { p.RevealNearbyGrids(p.Settings.Data.RevealDistance); });
42+
Plugin.Torch.Invoke(delegate { p.RevealGrids(p.Settings.Data.RevealDistance); });
4343
}
4444

4545
private void Conceal_OnClick(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)