Skip to content

Commit ec67e13

Browse files
204 update (#584)
* chat fix * Entity Manager updated with simple utility functions. (#583) - Spread Grid/Character/Voxel Maps/Floating Objects into individual tabs while keeping the original in its own tab. - Added ability to send message direct to players from selecting them in the Character tree. - Added Repair a grid button when selecting a grid from the Grids tree. - Get extra info for character steam Id, login time, and current speed (at time of clicking in tree, is not live) - Added Owned By information to block view, shows the player name and steam id. - Added speed information for grid, also not a live view. Updated on tree select only. - Added some null checks to make debug life easier. --------- Co-authored-by: SentorX <66237290+buttheadbob@users.noreply.github.com>
1 parent e9436a9 commit ec67e13

12 files changed

Lines changed: 490 additions & 98 deletions

File tree

‎Torch.Server/ViewModels/Entities/Blocks/BlockViewModel.cs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
using System.Text;
77
using System.Threading.Tasks;
88
using Sandbox.Game.Entities.Cube;
9+
using Sandbox.Game.World;
910
using Sandbox.ModAPI;
1011
using Sandbox.ModAPI.Interfaces;
1112
using Torch.Collections;
1213
using Torch.Server.ViewModels.Entities;
14+
using VRage.Game.ModAPI;
1315

1416
namespace Torch.Server.ViewModels.Blocks
1517
{
@@ -49,6 +51,26 @@ public long BuiltBy
4951
}
5052
}
5153

54+
public string OwnedBy
55+
{
56+
get
57+
{
58+
if (Block != null && Block.OwnerId != 0)
59+
{
60+
ulong getSteamId = MySession.Static.Players.TryGetSteamId(Block.OwnerId);
61+
List<IMyIdentity> players = new List<IMyIdentity>();
62+
MyAPIGateway.Players.GetAllIdentites(players);
63+
IMyIdentity player = players.FirstOrDefault(x => x.IdentityId == Block.OwnerId);
64+
if (player != null)
65+
{
66+
return $"{player.DisplayName} [{getSteamId}]";
67+
}
68+
}
69+
70+
return "Unknown/No Ownership";
71+
}
72+
}
73+
5274
public override bool CanStop => false;
5375

5476
/// <inheritdoc />

‎Torch.Server/ViewModels/Entities/CharacterViewModel.cs‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Sandbox.Game.Entities.Character;
2+
using Sandbox.Game.World;
23

34
namespace Torch.Server.ViewModels.Entities
45
{
@@ -23,5 +24,39 @@ public CharacterViewModel()
2324
}
2425

2526
public override bool CanDelete => _character.ControllerInfo?.Controller?.Player == null;
27+
28+
public string SteamID
29+
{
30+
get
31+
{
32+
if (Entity is MyCharacter c)
33+
return $"{c.ControlInfo.SteamId}";
34+
35+
return "nil";
36+
}
37+
}
38+
39+
public string GameID
40+
{
41+
get
42+
{
43+
if (Entity is MyCharacter c)
44+
return $"{MySession.Static.Players.TryGetIdentityId(c.ControlInfo.SteamId)}";
45+
46+
return "nil";
47+
}
48+
}
49+
50+
public string LoginTime
51+
{
52+
get
53+
{
54+
if (!(Entity is MyCharacter c)) return "Unknown?";
55+
if (c.ControlInfo.SteamId == 0) return "Unknown?";
56+
57+
var player = MySession.Static.Players.TryGetPlayerBySteamId(c.ControlInfo.SteamId);
58+
return player != null ? player.Identity.LastLoginTime.ToShortTimeString() : "Unknown?";
59+
}
60+
}
2661
}
2762
}

‎Torch.Server/ViewModels/Entities/EntityViewModel.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Windows;
45
using System.Windows.Controls;
56
using NLog;
7+
using Sandbox.Game;
68
using Sandbox.Game.Entities;
9+
using Sandbox.Game.Entities.Character;
10+
using Sandbox.Game.Entities.Cube;
711
using Sandbox.Game.World;
812
using Torch.API.Managers;
913
using Torch.Collections;
@@ -36,7 +40,7 @@ protected set
3640
}
3741
}
3842

39-
public long Id => Entity.EntityId;
43+
public long Id => Entity?.EntityId ?? 0; // Throws null then gives entity id
4044

4145
public MtObservableList<EntityControlViewModel> EntityControls { get; private set; }
4246

@@ -50,6 +54,8 @@ public virtual string Name
5054
OnPropertyChanged();
5155
}
5256
}
57+
58+
public virtual string Speed => Entity?.Physics?.Speed.ToString("N") ?? "0";
5359

5460
private string _descriptiveName;
5561
public string DescriptiveName

‎Torch.Server/Views/Entities/Blocks/BlockView.xaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
<StackPanel Grid.Row="0">
2121
<Label Content="{Binding FullName}" FontSize="16" />
2222
<StackPanel Orientation="Horizontal">
23-
<Label Content="Built By: "/>
23+
<Label Content="Built By: " Width="100"/>
2424
<TextBox Text="{Binding BuiltBy}" HorizontalAlignment="Stretch" Margin="3"/>
2525
</StackPanel>
26+
<StackPanel Orientation="Horizontal">
27+
<Label Content="Owned By: " Width="100"/>
28+
<TextBox Text="{Binding OwnedBy, Mode=OneWay}" Margin="3"/>
29+
</StackPanel>
2630
<Label Content="Properties"/>
2731
</StackPanel>
2832
<Expander Grid.Row="1" Header="Block Properties" IsExpanded="true">

‎Torch.Server/Views/Entities/CharacterView.xaml‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
</UserControl.DataContext>
1212
<Grid>
1313
<Grid.RowDefinitions>
14+
<RowDefinition Height="Auto"/>
15+
<RowDefinition Height="Auto"/>
16+
<RowDefinition Height="Auto"/>
17+
<RowDefinition Height="Auto"/>
18+
<RowDefinition Height="Auto"/>
1419
<RowDefinition Height="Auto"/>
1520
<RowDefinition Height="Auto"/>
1621
<RowDefinition Height="*"/>
@@ -23,7 +28,28 @@
2328
<Label Content="Position" Width="100"/>
2429
<TextBox Text="{Binding Position}" Margin="3" />
2530
</StackPanel>
26-
<ScrollViewer Grid.Row="2" Margin="3" VerticalScrollBarVisibility="Auto">
31+
<StackPanel Grid.Row="2" Orientation="Horizontal">
32+
<Label Content="SteamID" Width="100" />
33+
<TextBox Name="SelectedPlayerSteamID" Text="{Binding SteamID, Mode=OneWay}" Margin="3" IsReadOnly="True"/>
34+
</StackPanel>
35+
<StackPanel Grid.Row="3" Orientation="Horizontal">
36+
<Label Content="GameID" Width="100" />
37+
<TextBox Name="PlayerGameID" Text="{Binding GameID, Mode=OneWay}" Margin="3" IsReadOnly="True" />
38+
</StackPanel>
39+
<StackPanel Grid.Row="4" Orientation="Horizontal">
40+
<Label Content="Last Login" Width="100" />
41+
<TextBox Text="{Binding LoginTime, Mode=OneWay}" Margin="3" IsReadOnly="True" />
42+
</StackPanel>
43+
<StackPanel Grid.Row="5" Orientation="Horizontal">
44+
<Label Content="Speed" Width="100" />
45+
<TextBox Text="{Binding Speed, Mode=OneWay}" Margin="3" IsReadOnly="True" />
46+
</StackPanel>
47+
<StackPanel Grid.Row="6" Orientation="Vertical">
48+
<Label Content="Send DM" HorizontalAlignment="Left" />
49+
<TextBox x:Name="DM_TextToPlayer" Height="40" Margin="3"/>
50+
<Button Content="Send" Margin="3" Click="SendDM_ToPlayer"/>
51+
</StackPanel>
52+
<ScrollViewer Grid.Row="7" Margin="3" VerticalScrollBarVisibility="Auto">
2753
<local:EntityControlsView DataContext="{Binding}"/>
2854
</ScrollViewer>
2955
</Grid>

‎Torch.Server/Views/Entities/CharacterView.xaml.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -12,6 +13,8 @@
1213
using System.Windows.Media.Imaging;
1314
using System.Windows.Navigation;
1415
using System.Windows.Shapes;
16+
using Sandbox.Game;
17+
using Color = VRageMath.Color;
1518

1619
namespace Torch.Server.Views.Entities
1720
{
@@ -33,5 +36,14 @@ public void UpdateResourceDict(ResourceDictionary dictionary)
3336
this.Resources.MergedDictionaries.Clear();
3437
this.Resources.MergedDictionaries.Add(dictionary);
3538
}
39+
40+
private void SendDM_ToPlayer(object sender, RoutedEventArgs e)
41+
{
42+
if (string.IsNullOrWhiteSpace(PlayerGameID.Text)) return;
43+
if (string.IsNullOrWhiteSpace(DM_TextToPlayer.Text)) return;
44+
if (!long.TryParse(PlayerGameID.Text, out long Id)) return;
45+
46+
MyVisualScriptLogicProvider.SendChatMessageColored(DM_TextToPlayer.Text, Color.Red, "Server", Id);
47+
}
3648
}
3749
}

‎Torch.Server/Views/Entities/GridView.xaml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
</UserControl.DataContext>
1313
<Grid>
1414
<Grid.RowDefinitions>
15+
<RowDefinition Height="Auto"/>
16+
<RowDefinition Height="Auto"/>
1517
<RowDefinition Height="Auto"/>
1618
<RowDefinition Height="Auto"/>
1719
<RowDefinition Height="Auto"/>
@@ -27,9 +29,16 @@
2729
</StackPanel>
2830
<StackPanel Grid.Row="2" Orientation="Horizontal">
2931
<Label Content="EntityID" Width="100"/>
30-
<TextBox Text="{Binding Id, Mode=OneWay}" Margin="3" />
32+
<TextBox x:Name="EntityIDText" Text="{Binding Id, Mode=OneWay}" Margin="3" />
33+
</StackPanel>
34+
<StackPanel Grid.Row="3" Orientation="Horizontal">
35+
<Label Content="Speed" Width="100" />
36+
<TextBox Text="{Binding Speed, Mode=OneWay}" Margin="3" />
37+
</StackPanel>
38+
<StackPanel Grid.Row="4" Orientation="Horizontal">
39+
<Button Content="Repair" Margin="3" Width="100" Tag="{Binding ElementName=EntityIDText, Path=Text}" Click="RepairGrid"/>
3140
</StackPanel>
32-
<ScrollViewer Grid.Row="3" Margin="3" VerticalScrollBarVisibility="Auto">
41+
<ScrollViewer Grid.Row="5" Margin="3" VerticalScrollBarVisibility="Auto">
3342
<local:EntityControlsView DataContext="{Binding}"/>
3443
</ScrollViewer>
3544
</Grid>

‎Torch.Server/Views/Entities/GridView.xaml.cs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
using System.Windows.Media.Imaging;
1313
using System.Windows.Navigation;
1414
using System.Windows.Shapes;
15+
using NLog;
16+
using Sandbox.Game.Entities;
17+
using Sandbox.Game.Entities.Cube;
18+
using Sandbox.Game.World;
19+
using VRage.Game.Entity;
1520

1621
namespace Torch.Server.Views.Entities
1722
{
@@ -20,6 +25,7 @@ namespace Torch.Server.Views.Entities
2025
/// </summary>
2126
public partial class GridView : UserControl
2227
{
28+
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
2329
public GridView()
2430
{
2531
InitializeComponent();
@@ -33,5 +39,36 @@ public void UpdateResourceDict(ResourceDictionary dictionary)
3339
this.Resources.MergedDictionaries.Clear();
3440
this.Resources.MergedDictionaries.Add(dictionary);
3541
}
42+
43+
protected virtual void RepairGrid(object sender, RoutedEventArgs e)
44+
{
45+
if (sender is Button btn)
46+
{
47+
if (!long.TryParse(btn.Tag.ToString(), out long id)) return;
48+
if (id != 0)
49+
{
50+
// MyEntities.GetEntityById() always returned null but this works...
51+
MyCubeGrid grid = MyEntities.GetEntities().Where(x=>x.GetType()==typeof(MyCubeGrid)).Cast<MyCubeGrid>().FirstOrDefault(x=>x.EntityId==id);
52+
if (grid is null) return;
53+
TorchBase.Instance.InvokeBlocking(() =>
54+
{
55+
try
56+
{
57+
foreach (MySlimBlock block in grid.GetBlocks())
58+
{
59+
block.IncreaseMountLevel(block.MaxIntegrity - block.BuildIntegrity, block.OwnerId);
60+
}
61+
}
62+
catch (Exception ex)
63+
{
64+
Log.Error(ex);
65+
}
66+
});
67+
return;
68+
}
69+
}
70+
71+
Log.Warn("Cannot repair entity");
72+
}
3673
}
3774
}

0 commit comments

Comments
 (0)