Auto-generate configuration dialog, fix logger names, prepare for async initialization

This commit is contained in:
John Gross
2018-01-05 20:16:17 -08:00
parent 3f6f077833
commit ba8fa01ce5
50 changed files with 1953 additions and 590 deletions

View File

@@ -9,7 +9,7 @@
<target xsi:type="File" name="keen" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Keen-${shortdate}.log" />
<target xsi:type="File" name="main" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Torch-${shortdate}.log" />
<target xsi:type="File" name="chat" layout="${longdate} ${message}" fileName="Logs\Chat.log" />
<target xsi:type="ColoredConsole" name="console" layout="${var:logStamp} ${logger}: ${var:logContent}" />
<target xsi:type="ColoredConsole" name="console" layout="${var:logStamp} ${logger:shortName=true}: ${var:logContent}" />
<target xsi:type="File" name="patch" layout="${var:logContent}" fileName="Logs\patch.log"/>
</targets>

View File

@@ -23,6 +23,7 @@ namespace Torch.Server
private const string STEAMCMD_ZIP = "temp.zip";
private static readonly string STEAMCMD_PATH = $"{STEAMCMD_DIR}\\steamcmd.exe";
private static readonly string RUNSCRIPT_PATH = $"{STEAMCMD_DIR}\\runscript.txt";
private const string RUNSCRIPT = @"force_install_dir ../
login anonymous
app_update 298740
@@ -69,7 +70,6 @@ quit";
Console.Write(".");
Thread.Sleep(1000);
}
}
catch
{
@@ -86,17 +86,27 @@ quit";
_server = new TorchServer(_config);
try
{
_server.Init();
var initTask = Task.Run(() => { _server.Init(); });
if (!_config.NoGui)
{
var ui = new TorchUI(_server);
if (_config.Autostart)
_server.Init();
if (!_config.NoGui)
{
var ui = new TorchUI(_server);
if (_config.Autostart)
_server.Start();
ui.ShowDialog();
}
else
_server.Start();
ui.ShowDialog();
}
else
{
initTask.Wait();
_server.Start();
}
}
finally
{
@@ -106,100 +116,101 @@ quit";
}
}
private TorchConfig InitConfig()
{
var configName = "Torch.cfg";
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
if (File.Exists(configName))
private TorchConfig InitConfig()
{
Log.Info($"Loading config {configPath}");
return TorchConfig.LoadFrom(configPath);
}
else
{
Log.Info($"Generating default config at {configPath}");
var config = new TorchConfig { InstancePath = Path.GetFullPath("Instance") };
config.Save(configPath);
return config;
}
}
private static void RunSteamCmd()
{
var log = LogManager.GetLogger("SteamCMD");
if (!Directory.Exists(STEAMCMD_DIR))
{
Directory.CreateDirectory(STEAMCMD_DIR);
}
if (!File.Exists(RUNSCRIPT_PATH))
File.WriteAllText(RUNSCRIPT_PATH, RUNSCRIPT);
if (!File.Exists(STEAMCMD_PATH))
{
try
var configName = "Torch.cfg";
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
if (File.Exists(configName))
{
log.Info("Downloading SteamCMD.");
using (var client = new WebClient())
client.DownloadFile("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip", STEAMCMD_ZIP);
ZipFile.ExtractToDirectory(STEAMCMD_ZIP, STEAMCMD_DIR);
File.Delete(STEAMCMD_ZIP);
log.Info("SteamCMD downloaded successfully!");
Log.Info($"Loading config {configPath}");
return TorchConfig.LoadFrom(configPath);
}
catch
else
{
log.Error("Failed to download SteamCMD, unable to update the DS.");
return;
Log.Info($"Generating default config at {configPath}");
var config = new TorchConfig {InstancePath = Path.GetFullPath("Instance")};
config.Save(configPath);
return config;
}
}
log.Info("Checking for DS updates.");
var steamCmdProc = new ProcessStartInfo(STEAMCMD_PATH, "+runscript runscript.txt")
private static void RunSteamCmd()
{
WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), STEAMCMD_DIR),
UseShellExecute = false,
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.ASCII
};
var cmd = Process.Start(steamCmdProc);
var log = LogManager.GetLogger("SteamCMD");
// ReSharper disable once PossibleNullReferenceException
while (!cmd.HasExited)
{
log.Info(cmd.StandardOutput.ReadLine());
Thread.Sleep(100);
if (!Directory.Exists(STEAMCMD_DIR))
{
Directory.CreateDirectory(STEAMCMD_DIR);
}
if (!File.Exists(RUNSCRIPT_PATH))
File.WriteAllText(RUNSCRIPT_PATH, RUNSCRIPT);
if (!File.Exists(STEAMCMD_PATH))
{
try
{
log.Info("Downloading SteamCMD.");
using (var client = new WebClient())
client.DownloadFile("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip", STEAMCMD_ZIP);
ZipFile.ExtractToDirectory(STEAMCMD_ZIP, STEAMCMD_DIR);
File.Delete(STEAMCMD_ZIP);
log.Info("SteamCMD downloaded successfully!");
}
catch
{
log.Error("Failed to download SteamCMD, unable to update the DS.");
return;
}
}
log.Info("Checking for DS updates.");
var steamCmdProc = new ProcessStartInfo(STEAMCMD_PATH, "+runscript runscript.txt")
{
WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), STEAMCMD_DIR),
UseShellExecute = false,
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.ASCII
};
var cmd = Process.Start(steamCmdProc);
// ReSharper disable once PossibleNullReferenceException
while (!cmd.HasExited)
{
log.Info(cmd.StandardOutput.ReadLine());
Thread.Sleep(100);
}
}
}
private void LogException(Exception ex)
{
if (ex.InnerException != null)
private void LogException(Exception ex)
{
LogException(ex.InnerException);
if (ex.InnerException != null)
{
LogException(ex.InnerException);
}
Log.Fatal(ex);
if (ex is ReflectionTypeLoadException exti)
foreach (Exception exl in exti.LoaderExceptions)
LogException(exl);
}
Log.Fatal(ex);
if (ex is ReflectionTypeLoadException exti)
foreach (Exception exl in exti.LoaderExceptions)
LogException(exl);
}
private void HandleException(object sender, UnhandledExceptionEventArgs e)
{
var ex = (Exception)e.ExceptionObject;
LogException(ex);
Console.WriteLine("Exiting in 5 seconds.");
Thread.Sleep(5000);
LogManager.Flush();
if (_config.RestartOnCrash)
private void HandleException(object sender, UnhandledExceptionEventArgs e)
{
var exe = typeof(Program).Assembly.Location;
_config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
Process.Start(exe, _config.ToString());
var ex = (Exception)e.ExceptionObject;
LogException(ex);
Console.WriteLine("Exiting in 5 seconds.");
Thread.Sleep(5000);
LogManager.Flush();
if (_config.RestartOnCrash)
{
var exe = typeof(Program).Assembly.Location;
_config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
Process.Start(exe, _config.ToString());
}
Process.GetCurrentProcess().Kill();
}
Process.GetCurrentProcess().Kill();
}
}
}

View File

@@ -59,7 +59,7 @@ namespace Torch.Server.Managers
var worldFolders = Directory.EnumerateDirectories(Path.Combine(Torch.Config.InstancePath, "Saves"));
foreach (var f in worldFolders)
DedicatedConfig.Worlds.Add(new WorldViewModel(f, true));
DedicatedConfig.Worlds.Add(new WorldViewModel(f));
if (DedicatedConfig.Worlds.Count == 0)
{
@@ -92,7 +92,7 @@ namespace Torch.Server.Managers
foreach (var mod in world.Checkpoint.Mods)
sb.AppendLine(mod.PublishedFileId.ToString());
DedicatedConfig.Mods = sb.ToString();
DedicatedConfig.Mods = world.Checkpoint.Mods.Select(x => x.PublishedFileId).ToList(); //sb.ToString();
Log.Debug("Loaded mod list from world");
@@ -115,7 +115,7 @@ namespace Torch.Server.Managers
MyObjectBuilderSerializer.DeserializeXML(sandboxPath, out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
if (checkpoint == null)
{
Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {TorchBase.Instance.Config.InstancePath})");
Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {Torch.Config.InstancePath})");
return;
}
@@ -123,7 +123,7 @@ namespace Torch.Server.Managers
foreach (var mod in checkpoint.Mods)
sb.AppendLine(mod.PublishedFileId.ToString());
DedicatedConfig.Mods = sb.ToString();
DedicatedConfig.Mods = checkpoint.Mods.Select(x => x.PublishedFileId).ToList(); //sb.ToString();
Log.Debug("Loaded mod list from world");
@@ -144,18 +144,23 @@ namespace Torch.Server.Managers
try
{
MyObjectBuilderSerializer.DeserializeXML(Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc"), out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
var sandboxPath = Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc");
MyObjectBuilderSerializer.DeserializeXML(sandboxPath, out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
if (checkpoint == null)
{
Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {TorchBase.Instance.Config.InstancePath})");
Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {Torch.Config.InstancePath})");
return;
}
checkpoint.SessionName = DedicatedConfig.WorldName;
checkpoint.Settings = DedicatedConfig.SessionSettings;
checkpoint.Mods.Clear();
foreach (var modId in DedicatedConfig.Model.Mods)
checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId));
MyLocalCache.SaveCheckpoint(checkpoint, DedicatedConfig.LoadWorld);
MyObjectBuilderSerializer.SerializeXML(sandboxPath, false, checkpoint);
//MyLocalCache.SaveCheckpoint(checkpoint, DedicatedConfig.LoadWorld);
Log.Info("Saved world config.");
}
catch (Exception e)
@@ -185,15 +190,17 @@ namespace Torch.Server.Managers
{
public string FolderName { get; set; }
public string WorldPath { get; }
public long WorldSizeKB { get; }
private string _checkpointPath;
public CheckpointViewModel Checkpoint { get; private set; }
public WorldViewModel(string worldPath, bool loadCheckpointAsync = false)
public WorldViewModel(string worldPath)
{
WorldPath = worldPath;
WorldSizeKB = new DirectoryInfo(worldPath).GetFiles().Sum(x => x.Length) / 1024;
_checkpointPath = Path.Combine(WorldPath, "Sandbox.sbc");
FolderName = Path.GetFileName(worldPath);
LoadCheckpointAsync();
BeginLoadCheckpoint();
}
public async Task SaveCheckpointAsync()
@@ -201,19 +208,18 @@ namespace Torch.Server.Managers
await Task.Run(() =>
{
using (var f = File.Open(_checkpointPath, FileMode.Create))
MyObjectBuilderSerializer.SerializeXML(f, (MyObjectBuilder_Checkpoint)Checkpoint);
MyObjectBuilderSerializer.SerializeXML(f, Checkpoint);
});
}
public async Task<CheckpointViewModel> LoadCheckpointAsync()
private void BeginLoadCheckpoint()
{
Checkpoint = await Task.Run(() =>
Task.Run(() =>
{
MyObjectBuilderSerializer.DeserializeXML(_checkpointPath, out MyObjectBuilder_Checkpoint checkpoint);
return new CheckpointViewModel(checkpoint);
Checkpoint = new CheckpointViewModel(checkpoint);
OnPropertyChanged(nameof(Checkpoint));
});
OnPropertyChanged("Checkpoint");
return Checkpoint;
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -9,11 +10,14 @@ using NLog.Fluent;
using Sandbox;
using Sandbox.Engine.Multiplayer;
using Sandbox.Engine.Networking;
using Sandbox.Game.World;
using SteamSDK;
using Torch.API;
using Torch.API.Managers;
using Torch.Managers;
using Torch.Utils;
using Torch.ViewModels;
using VRage.Game;
using VRage.GameServices;
using VRage.Network;
using VRage.Steam;
@@ -35,6 +39,9 @@ namespace Torch.Server.Managers
private Dictionary<ulong, ulong> _gameOwnerIds = new Dictionary<ulong, ulong>();
[Dependency]
private InstanceManager _instanceManager;
/// <inheritdoc />
public MultiplayerManagerDedicated(ITorchBase torch) : base(torch)
{
@@ -135,22 +142,34 @@ namespace Torch.Server.Managers
}
//Largely copied from SE
private void ValidateAuthTicketResponse(ulong steamID, JoinResult response, ulong steamOwner)
private void ValidateAuthTicketResponse(ulong steamId, JoinResult response, ulong steamOwner)
{
_log.Debug($"ValidateAuthTicketResponse(user={steamID}, response={response}, owner={steamOwner}");
if (MySandboxGame.ConfigDedicated.GroupID == 0uL)
RunEvent(new ValidateAuthTicketEvent(steamID, steamOwner, response, 0, true, false));
var state = new P2PSessionState();
Peer2Peer.GetSessionState(steamId, ref state);
var ip = state.GetRemoteIP();
_log.Debug($"ValidateAuthTicketResponse(user={steamId}, response={response}, owner={steamOwner})");
_log.Info($"Connection attempt by {steamId} from {ip}");
// TODO implement IP bans
if (Torch.CurrentSession.KeenSession.OnlineMode == MyOnlineModeEnum.OFFLINE && !Torch.CurrentSession.KeenSession.IsUserAdmin(steamId))
{
_log.Warn($"Rejecting user {steamId}, world is set to offline and user is not admin.");
UserRejected(steamId, JoinResult.TicketCanceled);
}
else if (MySandboxGame.ConfigDedicated.GroupID == 0uL)
RunEvent(new ValidateAuthTicketEvent(steamId, steamOwner, response, 0, true, false));
else if (_getServerAccountType(MySandboxGame.ConfigDedicated.GroupID) != MyGameServiceAccountType.Clan)
UserRejected(steamID, JoinResult.GroupIdInvalid);
else if (MyGameService.GameServer.RequestGroupStatus(steamID, MySandboxGame.ConfigDedicated.GroupID))
UserRejected(steamId, JoinResult.GroupIdInvalid);
else if (MyGameService.GameServer.RequestGroupStatus(steamId, MySandboxGame.ConfigDedicated.GroupID))
lock (_waitingForGroupLocal)
{
if (_waitingForGroupLocal.Count >= _waitListSize)
_waitingForGroupLocal.RemoveAt(0);
_waitingForGroupLocal.Add(new WaitingForGroup(steamID, response, steamOwner));
_waitingForGroupLocal.Add(new WaitingForGroup(steamId, response, steamOwner));
}
else
UserRejected(steamID, JoinResult.SteamServersOffline);
UserRejected(steamId, JoinResult.SteamServersOffline);
}
private void RunEvent(ValidateAuthTicketEvent info)

View File

@@ -1,33 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using NLog;
using Sandbox.Game.World;
using Sandbox.ModAPI;
using Torch;
using Torch.API;
using Torch.Server.Views;
using VRage.Game.ModAPI;
using System.IO.Compression;
using System.Net;
using System.Security.Policy;
using Torch.Server.Managers;
using Torch.Utils;
using VRage.FileSystem;
using VRageRender;
namespace Torch.Server
{

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Torch.Collections;
namespace Torch.Server
{
public class ServerStatistics
{
public RollingAverage SimSpeed { get; } = new RollingAverage(30);
}
}

View File

@@ -102,6 +102,7 @@
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
@@ -201,8 +202,8 @@
<Compile Include="Managers\MultiplayerManagerDedicatedEventShim.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="Initializer.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServerStatistics.cs" />
<Compile Include="TorchConfig.cs" />
<Compile Include="TorchService.cs">
<SubType>Component</SubType>
@@ -224,9 +225,9 @@
<DesignTime>True</DesignTime>
<DependentUpon>SessionSettingsViewModel.tt</DependentUpon>
</Compile>
<Compile Include="Views\DynamicView.xaml.cs">
<DependentUpon>DynamicView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Converters\BooleanAndConverter.cs" />
<Compile Include="Views\Converters\ListConverter.cs" />
<Compile Include="Views\ValidationRules\ListConverterValidationRule.cs" />
<Compile Include="Views\Entities\EntityControlHost.xaml.cs">
<DependentUpon>EntityControlHost.xaml</DependentUpon>
</Compile>
@@ -287,6 +288,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="TorchServer.cs" />
<Compile Include="Views\ValidationRules\NumberValidationRule.cs" />
<Compile Include="Views\WorldGeneratorDialog.xaml.cs">
<DependentUpon>WorldGeneratorDialog.xaml</DependentUpon>
</Compile>
@@ -326,10 +328,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Page Include="Views\DynamicView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Entities\EntityControlHost.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -378,6 +376,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Resources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SessionSettingsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@@ -1,40 +1,20 @@
using Sandbox;
using Sandbox.Engine.Utils;
using Sandbox.Game;
using NLog;
using Sandbox;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.World;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Xml.Serialization.GeneratedAssembly;
using NLog;
using Sandbox.Engine.Analytics;
using Sandbox.Game.Multiplayer;
using Sandbox.ModAPI;
using SteamSDK;
using Torch.API;
using Torch.API.Managers;
using Torch.API.Session;
using Torch.Managers;
using Torch.Server.Managers;
using Torch.Utils;
using VRage.Dedicated;
using VRage.FileSystem;
using VRage.Game;
using VRage.Game.ModAPI;
using VRage.Game.ObjectBuilder;
using VRage.Game.SessionComponents;
using VRage.Library;
using VRage.ObjectBuilders;
using VRage.Plugins;
using VRage.Utils;
#pragma warning disable 618
@@ -131,7 +111,6 @@ namespace Torch.Server
Sandbox.Engine.Platform.Game.IsDedicated = true;
base.Init();
Managers.GetManager<ITorchSessionManager>().SessionStateChanged += OnSessionStateChanged;
GetManager<InstanceManager>().LoadInstance(Config.InstancePath);
}

View File

@@ -29,32 +29,10 @@ namespace Torch.Server.ViewModels
_config = configDedicated;
_config.IgnoreLastSession = true;
SessionSettings = new SessionSettingsViewModel(_config.SessionSettings);
Administrators = string.Join(Environment.NewLine, _config.Administrators);
Banned = string.Join(Environment.NewLine, _config.Banned);
Mods = string.Join(Environment.NewLine, _config.Mods);
}
public void Save(string path = null)
{
var newline = new [] {Environment.NewLine};
_config.Administrators.Clear();
foreach (var admin in Administrators.Split(newline, StringSplitOptions.RemoveEmptyEntries))
_config.Administrators.Add(admin);
_config.Banned.Clear();
foreach (var banned in Banned.Split(newline, StringSplitOptions.RemoveEmptyEntries))
_config.Banned.Add(ulong.Parse(banned));
_config.Mods.Clear();
foreach (var mod in Mods.Split(newline, StringSplitOptions.RemoveEmptyEntries))
{
if (ulong.TryParse(mod, out ulong modId))
_config.Mods.Add(modId);
else
Log.Warn($"'{mod}' is not a valid mod ID.");
}
// Never ever
_config.IgnoreLastSession = true;
_config.Save(path);
@@ -75,71 +53,30 @@ namespace Torch.Server.ViewModels
}
}
private string _administrators;
public string Administrators { get => _administrators; set { _administrators = value; OnPropertyChanged(); } }
private string _banned;
public string Banned { get => _banned; set { _banned = value; OnPropertyChanged(); } }
private string _mods;
public string Mods { get => _mods; set { _mods = value; OnPropertyChanged(); } }
public List<string> Administrators { get => _config.Administrators; set => SetValue(x => _config.Administrators = x, value); }
public int AsteroidAmount
{
get { return _config.AsteroidAmount; }
set { _config.AsteroidAmount = value; OnPropertyChanged(); }
}
public List<ulong> Banned { get => _config.Banned; set => SetValue(x => _config.Banned = x, value); }
public ulong GroupId
{
get { return _config.GroupID; }
set { _config.GroupID = value; OnPropertyChanged(); }
}
public List<ulong> Mods { get => _config.Mods; set => SetValue(x => _config.Mods = x, value); }
public string IP
{
get { return _config.IP; }
set { _config.IP = value; OnPropertyChanged(); }
}
public int AsteroidAmount { get => _config.AsteroidAmount; set => SetValue(x => _config.AsteroidAmount = x, value); }
public int Port
{
get { return _config.ServerPort; }
set { _config.ServerPort = value; OnPropertyChanged(); }
}
public ulong GroupId { get => _config.GroupID; set => SetValue(x => _config.GroupID = x, value); }
public string ServerName
{
get { return _config.ServerName; }
set { _config.ServerName = value; OnPropertyChanged(); }
}
public string IP { get => _config.IP; set => SetValue(x => _config.IP = x, value); }
public bool PauseGameWhenEmpty
{
get { return _config.PauseGameWhenEmpty; }
set { _config.PauseGameWhenEmpty = value; OnPropertyChanged(); }
}
public int Port { get => _config.ServerPort; set => SetValue(x => _config.ServerPort = x, value); }
public string PremadeCheckpointPath
{
get { return _config.PremadeCheckpointPath; }
set { _config.PremadeCheckpointPath = value; OnPropertyChanged(); }
}
public string ServerName { get => _config.ServerName; set => SetValue(x => _config.ServerName = x, value); }
public string LoadWorld
{
get { return _config.LoadWorld; }
set { _config.LoadWorld = value; OnPropertyChanged(); }
}
public bool PauseGameWhenEmpty { get => _config.PauseGameWhenEmpty; set => SetValue(x => _config.PauseGameWhenEmpty = x, value); }
public int SteamPort
{
get { return _config.SteamPort; }
set { _config.SteamPort = value; OnPropertyChanged(); }
}
public string PremadeCheckpointPath { get => _config.PremadeCheckpointPath; set => SetValue(x => _config.PremadeCheckpointPath = x, value); }
public string WorldName
{
get { return _config.WorldName; }
set { _config.WorldName = value; OnPropertyChanged(); }
}
public string LoadWorld { get => _config.LoadWorld; set => SetValue(x => _config.LoadWorld = x, value); }
public int SteamPort { get => _config.SteamPort; set => SetValue(x => _config.SteamPort = x, value); }
public string WorldName { get => _config.WorldName; set => SetValue(x => _config.WorldName = x, value); }
}
}

View File

@@ -8,235 +8,279 @@ using Torch.Collections;
using VRage.Game;
using VRage.Library.Utils;
using VRage.Serialization;
using System.ComponentModel.DataAnnotations;
namespace Torch.Server.ViewModels
{
public class SessionSettingsViewModel : ViewModel
{
private MyObjectBuilder_SessionSettings _settings;
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.GameMode" />
public string GameMode { get => _settings.GameMode.ToString(); set { Enum.TryParse(value, true, out VRage.Library.Utils.MyGameModeEnum parsedVal); SetValue(ref _settings.GameMode, parsedVal); } }
public List<string> GameModeValues { get; } = new List<string> {"Creative", "Survival"};
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.GameMode" />
[Display(Name = "Game mode")]
public VRage.Library.Utils.MyGameModeEnum GameMode { get => _settings.GameMode; set => SetValue(ref _settings.GameMode, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.InventorySizeMultiplier" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.InventorySizeMultiplier" />
[Display(Name = "Inventory size multiplier")]
public System.Single InventorySizeMultiplier { get => _settings.InventorySizeMultiplier; set => SetValue(ref _settings.InventorySizeMultiplier, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.AssemblerSpeedMultiplier" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.AssemblerSpeedMultiplier" />
[Display(Name = "Assembler speed multiplier")]
public System.Single AssemblerSpeedMultiplier { get => _settings.AssemblerSpeedMultiplier; set => SetValue(ref _settings.AssemblerSpeedMultiplier, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.AssemblerEfficiencyMultiplier" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.AssemblerEfficiencyMultiplier" />
[Display(Name = "Assembler efficiency multiplier")]
public System.Single AssemblerEfficiencyMultiplier { get => _settings.AssemblerEfficiencyMultiplier; set => SetValue(ref _settings.AssemblerEfficiencyMultiplier, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.RefinerySpeedMultiplier" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.RefinerySpeedMultiplier" />
[Display(Name = "Refinery speed multiplier")]
public System.Single RefinerySpeedMultiplier { get => _settings.RefinerySpeedMultiplier; set => SetValue(ref _settings.RefinerySpeedMultiplier, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.OnlineMode" />
public string OnlineMode { get => _settings.OnlineMode.ToString(); set { Enum.TryParse(value, true, out VRage.Game.MyOnlineModeEnum parsedVal); SetValue(ref _settings.OnlineMode, parsedVal); } }
public List<string> OnlineModeValues { get; } = new List<string> {"OFFLINE", "PUBLIC", "FRIENDS", "PRIVATE"};
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.OnlineMode" />
[Display(Name = "OnlineMode")]
public VRage.Game.MyOnlineModeEnum OnlineMode { get => _settings.OnlineMode; set => SetValue(ref _settings.OnlineMode, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxPlayers" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxPlayers" />
[Display(Name = "Max players")]
public System.Int16 MaxPlayers { get => _settings.MaxPlayers; set => SetValue(ref _settings.MaxPlayers, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxFloatingObjects" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxFloatingObjects" />
[Display(Name = "Max floating objects")]
public System.Int16 MaxFloatingObjects { get => _settings.MaxFloatingObjects; set => SetValue(ref _settings.MaxFloatingObjects, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxBackupSaves" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxBackupSaves" />
[Display(Name = "Max Backup Saves")]
public System.Int16 MaxBackupSaves { get => _settings.MaxBackupSaves; set => SetValue(ref _settings.MaxBackupSaves, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxGridSize" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxGridSize" />
[Display(Name = "Max grid size")]
public System.Int32 MaxGridSize { get => _settings.MaxGridSize; set => SetValue(ref _settings.MaxGridSize, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxBlocksPerPlayer" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxBlocksPerPlayer" />
[Display(Name = "Max blocks per player")]
public System.Int32 MaxBlocksPerPlayer { get => _settings.MaxBlocksPerPlayer; set => SetValue(ref _settings.MaxBlocksPerPlayer, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableBlockLimits" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableBlockLimits" />
[Display(Name = "Enable block limits")]
public System.Boolean EnableBlockLimits { get => _settings.EnableBlockLimits; set => SetValue(ref _settings.EnableBlockLimits, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableRemoteBlockRemoval" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableRemoteBlockRemoval" />
[Display(Name = "Enable remote removal of owned blocks")]
public System.Boolean EnableRemoteBlockRemoval { get => _settings.EnableRemoteBlockRemoval; set => SetValue(ref _settings.EnableRemoteBlockRemoval, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnvironmentHostility" />
public string EnvironmentHostility { get => _settings.EnvironmentHostility.ToString(); set { Enum.TryParse(value, true, out VRage.Game.MyEnvironmentHostilityEnum parsedVal); SetValue(ref _settings.EnvironmentHostility, parsedVal); } }
public List<string> EnvironmentHostilityValues { get; } = new List<string> {"SAFE", "NORMAL", "CATACLYSM", "CATACLYSM_UNREAL"};
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnvironmentHostility" />
[Display(Name = "Environment hostility")]
public VRage.Game.MyEnvironmentHostilityEnum EnvironmentHostility { get => _settings.EnvironmentHostility; set => SetValue(ref _settings.EnvironmentHostility, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.AutoHealing" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.AutoHealing" />
[Display(Name = "Auto healing")]
public System.Boolean AutoHealing { get => _settings.AutoHealing; set => SetValue(ref _settings.AutoHealing, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableCopyPaste" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableCopyPaste" />
[Display(Name = "Enable Copy&Paste")]
public System.Boolean EnableCopyPaste { get => _settings.EnableCopyPaste; set => SetValue(ref _settings.EnableCopyPaste, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.WeaponsEnabled" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.WeaponsEnabled" />
[Display(Name = "Weapons enabled")]
public System.Boolean WeaponsEnabled { get => _settings.WeaponsEnabled; set => SetValue(ref _settings.WeaponsEnabled, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.ShowPlayerNamesOnHud" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.ShowPlayerNamesOnHud" />
[Display(Name = "Show player names on HUD")]
public System.Boolean ShowPlayerNamesOnHud { get => _settings.ShowPlayerNamesOnHud; set => SetValue(ref _settings.ShowPlayerNamesOnHud, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.ThrusterDamage" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.ThrusterDamage" />
[Display(Name = "Thruster damage")]
public System.Boolean ThrusterDamage { get => _settings.ThrusterDamage; set => SetValue(ref _settings.ThrusterDamage, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.CargoShipsEnabled" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.CargoShipsEnabled" />
[Display(Name = "Cargo ships enabled")]
public System.Boolean CargoShipsEnabled { get => _settings.CargoShipsEnabled; set => SetValue(ref _settings.CargoShipsEnabled, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSpectator" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSpectator" />
[Display(Name = "Enable spectator")]
public System.Boolean EnableSpectator { get => _settings.EnableSpectator; set => SetValue(ref _settings.EnableSpectator, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.WorldSizeKm" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.WorldSizeKm" />
[Display(Name = "World size in Km")]
public System.Int32 WorldSizeKm { get => _settings.WorldSizeKm; set => SetValue(ref _settings.WorldSizeKm, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.RespawnShipDelete" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.RespawnShipDelete" />
[Display(Name = "Respawn ship delete")]
public System.Boolean RespawnShipDelete { get => _settings.RespawnShipDelete; set => SetValue(ref _settings.RespawnShipDelete, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.ResetOwnership" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.ResetOwnership" />
[Display(Name = "Reset ownership")]
public System.Boolean ResetOwnership { get => _settings.ResetOwnership; set => SetValue(ref _settings.ResetOwnership, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.WelderSpeedMultiplier" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.WelderSpeedMultiplier" />
[Display(Name = "Welder speed multiplier")]
public System.Single WelderSpeedMultiplier { get => _settings.WelderSpeedMultiplier; set => SetValue(ref _settings.WelderSpeedMultiplier, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.GrinderSpeedMultiplier" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.GrinderSpeedMultiplier" />
[Display(Name = "Grinder speed multiplier")]
public System.Single GrinderSpeedMultiplier { get => _settings.GrinderSpeedMultiplier; set => SetValue(ref _settings.GrinderSpeedMultiplier, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.RealisticSound" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.RealisticSound" />
[Display(Name = "Realistic sound")]
public System.Boolean RealisticSound { get => _settings.RealisticSound; set => SetValue(ref _settings.RealisticSound, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.HackSpeedMultiplier" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.HackSpeedMultiplier" />
[Display(Name = "Hack speed multiplier")]
public System.Single HackSpeedMultiplier { get => _settings.HackSpeedMultiplier; set => SetValue(ref _settings.HackSpeedMultiplier, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.PermanentDeath" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.PermanentDeath" />
[Display(Name = "Permanent death")]
public System.Nullable<System.Boolean> PermanentDeath { get => _settings.PermanentDeath; set => SetValue(ref _settings.PermanentDeath, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.AutoSaveInMinutes" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.AutoSaveInMinutes" />
[Display(Name = "AutoSave in minutes")]
public System.UInt32 AutoSaveInMinutes { get => _settings.AutoSaveInMinutes; set => SetValue(ref _settings.AutoSaveInMinutes, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSaving" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSaving" />
[Display(Name = "Enable saving from menu")]
public System.Boolean EnableSaving { get => _settings.EnableSaving; set => SetValue(ref _settings.EnableSaving, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableRespawnScreen" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableRespawnScreen" />
[Display(Name = "Enable respawn screen in the game")]
public System.Boolean EnableRespawnScreen { get => _settings.EnableRespawnScreen; set => SetValue(ref _settings.EnableRespawnScreen, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.InfiniteAmmo" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.InfiniteAmmo" />
[Display(Name = "Enable infinite ammunition in survival")]
public System.Boolean InfiniteAmmo { get => _settings.InfiniteAmmo; set => SetValue(ref _settings.InfiniteAmmo, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableContainerDrops" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableContainerDrops" />
[Display(Name = "Enable drop containers")]
public System.Boolean EnableContainerDrops { get => _settings.EnableContainerDrops; set => SetValue(ref _settings.EnableContainerDrops, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.SpawnShipTimeMultiplier" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.SpawnShipTimeMultiplier" />
[Display(Name = "Spawnship time multiplier")]
public System.Single SpawnShipTimeMultiplier { get => _settings.SpawnShipTimeMultiplier; set => SetValue(ref _settings.SpawnShipTimeMultiplier, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.ProceduralDensity" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.ProceduralDensity" />
[Display(Name = "Procedural density")]
public System.Single ProceduralDensity { get => _settings.ProceduralDensity; set => SetValue(ref _settings.ProceduralDensity, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.ProceduralSeed" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.ProceduralSeed" />
[Display(Name = "Procedural seed")]
public System.Int32 ProceduralSeed { get => _settings.ProceduralSeed; set => SetValue(ref _settings.ProceduralSeed, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.DestructibleBlocks" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.DestructibleBlocks" />
[Display(Name = "Destructible blocks")]
public System.Boolean DestructibleBlocks { get => _settings.DestructibleBlocks; set => SetValue(ref _settings.DestructibleBlocks, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableIngameScripts" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableIngameScripts" />
[Display(Name = "Enable ingame scripts")]
public System.Boolean EnableIngameScripts { get => _settings.EnableIngameScripts; set => SetValue(ref _settings.EnableIngameScripts, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.ViewDistance" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.ViewDistance" />
[Display(Name = "View distance")]
public System.Int32 ViewDistance { get => _settings.ViewDistance; set => SetValue(ref _settings.ViewDistance, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.FloraDensity" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.FloraDensity" />
[Display(Name = "Flora density")]
public System.Int32 FloraDensity { get => _settings.FloraDensity; set => SetValue(ref _settings.FloraDensity, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableToolShake" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableToolShake" />
[Display(Name = "Enable tool shake")]
public System.Boolean EnableToolShake { get => _settings.EnableToolShake; set => SetValue(ref _settings.EnableToolShake, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.VoxelGeneratorVersion" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.VoxelGeneratorVersion" />
[Display(Name = "Voxel generator version")]
public System.Int32 VoxelGeneratorVersion { get => _settings.VoxelGeneratorVersion; set => SetValue(ref _settings.VoxelGeneratorVersion, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableOxygen" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableOxygen" />
[Display(Name = "Enable oxygen")]
public System.Boolean EnableOxygen { get => _settings.EnableOxygen; set => SetValue(ref _settings.EnableOxygen, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableOxygenPressurization" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableOxygenPressurization" />
[Display(Name = "Enable airtightness")]
public System.Boolean EnableOxygenPressurization { get => _settings.EnableOxygenPressurization; set => SetValue(ref _settings.EnableOxygenPressurization, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.Enable3rdPersonView" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.Enable3rdPersonView" />
[Display(Name = "Enable 3rd person view")]
public System.Boolean Enable3rdPersonView { get => _settings.Enable3rdPersonView; set => SetValue(ref _settings.Enable3rdPersonView, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableEncounters" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableEncounters" />
[Display(Name = "Enable encounters")]
public System.Boolean EnableEncounters { get => _settings.EnableEncounters; set => SetValue(ref _settings.EnableEncounters, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableFlora" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableFlora" />
[Display(Name = "Enable flora")]
public System.Boolean EnableFlora { get => _settings.EnableFlora; set => SetValue(ref _settings.EnableFlora, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableConvertToStation" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableConvertToStation" />
[Display(Name = "Enable convert to station")]
public System.Boolean EnableConvertToStation { get => _settings.EnableConvertToStation; set => SetValue(ref _settings.EnableConvertToStation, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.StationVoxelSupport" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.StationVoxelSupport" />
[Display(Name = "Enable station grid with voxel")]
public System.Boolean StationVoxelSupport { get => _settings.StationVoxelSupport; set => SetValue(ref _settings.StationVoxelSupport, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSunRotation" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSunRotation" />
[Display(Name = "Enable sun rotation")]
public System.Boolean EnableSunRotation { get => _settings.EnableSunRotation; set => SetValue(ref _settings.EnableSunRotation, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableRespawnShips" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableRespawnShips" />
[Display(Name = "Enable respawn ships / carts")]
public System.Boolean EnableRespawnShips { get => _settings.EnableRespawnShips; set => SetValue(ref _settings.EnableRespawnShips, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.ScenarioEditMode" />
public System.Boolean ScenarioEditMode { get => _settings.ScenarioEditMode; set => SetValue(ref _settings.ScenarioEditMode, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.Scenario" />
public System.Boolean Scenario { get => _settings.Scenario; set => SetValue(ref _settings.Scenario, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.CanJoinRunning" />
public System.Boolean CanJoinRunning { get => _settings.CanJoinRunning; set => SetValue(ref _settings.CanJoinRunning, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.PhysicsIterations" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.PhysicsIterations" />
[Display(Name = "PhysicsIterations")]
public System.Int32 PhysicsIterations { get => _settings.PhysicsIterations; set => SetValue(ref _settings.PhysicsIterations, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.SunRotationIntervalMinutes" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.SunRotationIntervalMinutes" />
[Display(Name = "Sun rotation interval")]
public System.Single SunRotationIntervalMinutes { get => _settings.SunRotationIntervalMinutes; set => SetValue(ref _settings.SunRotationIntervalMinutes, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableJetpack" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableJetpack" />
[Display(Name = "Enable jetpack")]
public System.Boolean EnableJetpack { get => _settings.EnableJetpack; set => SetValue(ref _settings.EnableJetpack, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.SpawnWithTools" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.SpawnWithTools" />
[Display(Name = "Spawn with tools")]
public System.Boolean SpawnWithTools { get => _settings.SpawnWithTools; set => SetValue(ref _settings.SpawnWithTools, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.StartInRespawnScreen" />
public System.Boolean StartInRespawnScreen { get => _settings.StartInRespawnScreen; set => SetValue(ref _settings.StartInRespawnScreen, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableVoxelDestruction" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableVoxelDestruction" />
[Display(Name = "Enable voxel destruction")]
public System.Boolean EnableVoxelDestruction { get => _settings.EnableVoxelDestruction; set => SetValue(ref _settings.EnableVoxelDestruction, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxDrones" />
public System.Int32 MaxDrones { get => _settings.MaxDrones; set => SetValue(ref _settings.MaxDrones, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableDrones" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableDrones" />
[Display(Name = "Enable drones")]
public System.Boolean EnableDrones { get => _settings.EnableDrones; set => SetValue(ref _settings.EnableDrones, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableWolfs" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableWolfs" />
[Display(Name = "Enable wolfs")]
public System.Boolean EnableWolfs { get => _settings.EnableWolfs; set => SetValue(ref _settings.EnableWolfs, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSpiders" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSpiders" />
[Display(Name = "Enable spiders")]
public System.Boolean EnableSpiders { get => _settings.EnableSpiders; set => SetValue(ref _settings.EnableSpiders, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.FloraDensityMultiplier" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.FloraDensityMultiplier" />
[Display(Name = "Flora density multiplier")]
public System.Single FloraDensityMultiplier { get => _settings.FloraDensityMultiplier; set => SetValue(ref _settings.FloraDensityMultiplier, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableStructuralSimulation" />
public System.Boolean EnableStructuralSimulation { get => _settings.EnableStructuralSimulation; set => SetValue(ref _settings.EnableStructuralSimulation, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxActiveFracturePieces" />
public System.Int32 MaxActiveFracturePieces { get => _settings.MaxActiveFracturePieces; set => SetValue(ref _settings.MaxActiveFracturePieces, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.BlockTypeLimits" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.BlockTypeLimits" />
[Display(Name = "Block type limits")]
public VRage.Serialization.SerializableDictionary<System.String, System.Int16> BlockTypeLimits { get => _settings.BlockTypeLimits; set => SetValue(ref _settings.BlockTypeLimits, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableScripterRole" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableScripterRole" />
[Display(Name = "Enable Scripter role")]
public System.Boolean EnableScripterRole { get => _settings.EnableScripterRole; set => SetValue(ref _settings.EnableScripterRole, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.MinDropContainerRespawnTime" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.MinDropContainerRespawnTime" />
[Display(Name = "Min Drop Container Respawn Time")]
public System.Int32 MinDropContainerRespawnTime { get => _settings.MinDropContainerRespawnTime; set => SetValue(ref _settings.MinDropContainerRespawnTime, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxDropContainerRespawnTime" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.MaxDropContainerRespawnTime" />
[Display(Name = "Max Drop Container Respawn Time")]
public System.Int32 MaxDropContainerRespawnTime { get => _settings.MaxDropContainerRespawnTime; set => SetValue(ref _settings.MaxDropContainerRespawnTime, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableTurretsFriendlyFire" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableTurretsFriendlyFire" />
[Display(Name = "Enable Turrets Friendly Fire")]
public System.Boolean EnableTurretsFriendlyFire { get => _settings.EnableTurretsFriendlyFire; set => SetValue(ref _settings.EnableTurretsFriendlyFire, value); }
/// <inheritdoc cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSubgridDamage" />
/// <see cref="VRage.Game.MyObjectBuilder_SessionSettings.EnableSubgridDamage" />
[Display(Name = "Enable Sub-Grid damage")]
public System.Boolean EnableSubgridDamage { get => _settings.EnableSubgridDamage; set => SetValue(ref _settings.EnableSubgridDamage, value); }

View File

@@ -1,5 +1,6 @@
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.ComponentModel.DataAnnotations" #>
<#@ assembly name="$(SolutionDir)\GameBinaries\VRage.Game.dll" #>
<#@ assembly name="$(SolutionDir)\GameBinaries\VRage.Library.dll" #>
<#@ import namespace="System.Collections" #>
@@ -9,6 +10,7 @@
<#@ import namespace="System.Reflection" #>
<#@ import namespace="VRage.Game" #>
<#@ import namespace="VRage.Serialization" #>
<#@ import namespace="System.ComponentModel.DataAnnotations" #>
<#@ output extension=".cs" #>
// This file is generated automatically! Any changes will be overwritten.
@@ -20,6 +22,7 @@ using Torch.Collections;
using VRage.Game;
using VRage.Library.Utils;
using VRage.Serialization;
using System.ComponentModel.DataAnnotations;
namespace Torch.Server.ViewModels
{
@@ -32,9 +35,17 @@ namespace Torch.Server.ViewModels
PushIndent(" ");
foreach (var field in typeFields)
{
if (field.GetCustomAttribute<GameRelationAttribute>()?.RelatedTo == Game.MedievalEngineers)
continue;
var displayName = field.GetCustomAttribute<DisplayAttribute>()?.Name ?? field.Name;
if (string.IsNullOrEmpty(displayName))
continue;
var getSet = "";
WriteLine(GetPropertySummary(field));
if (field.FieldType.IsEnum)
WriteLine($"[Display(Name = \"{displayName}\")]");
if (false)//field.FieldType.IsEnum)
{
Write($"public string {field.Name} ");
WriteLine($"{{ get => _settings.{field.Name}.ToString(); set {{ Enum.TryParse(value, true, out {field.FieldType} parsedVal); SetValue(ref _settings.{field.Name}, parsedVal); }} }}");
@@ -65,7 +76,7 @@ namespace Torch.Server.ViewModels
string GetPropertySummary(FieldInfo info)
{
return $"/// <inheritdoc cref=\"VRage.Game.MyObjectBuilder_SessionSettings.{info.Name}\" />";
return $"/// <see cref=\"VRage.Game.MyObjectBuilder_SessionSettings.{info.Name}\" />";
}
string GetPropertyName(FieldInfo info)

View File

@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Torch.Server"
mc:Ignorable="d"
Title="Add Workshop Item" Height="200" Width="400">
<DockPanel Background="LightGray">

View File

@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>

View File

@@ -3,33 +3,45 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server.Views"
xmlns:viewModels="clr-namespace:Torch.Server.ViewModels"
xmlns:managers="clr-namespace:Torch.Server.Managers"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:validationRules="clr-namespace:Torch.Server.Views.ValidationRules"
xmlns:views="clr-namespace:Torch.Views;assembly=Torch"
mc:Ignorable="d"
Background="White">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<UserControl.DataContext>
<viewModels:ConfigDedicatedViewModel />
</UserControl.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0">
<Label Content="World:" DockPanel.Dock="Left" />
<Button Content="New World" Margin="3" DockPanel.Dock="Right" Click="NewWorld_OnClick"/>
<ComboBox ItemsSource="{Binding Worlds}" SelectedItem="{Binding SelectedWorld}" Margin="3" SelectionChanged="Selector_OnSelectionChanged">
<Button Content="New World" Margin="3" DockPanel.Dock="Right" Click="NewWorld_OnClick" />
<ComboBox ItemsSource="{Binding Worlds}" SelectedItem="{Binding SelectedWorld}" Margin="3"
SelectionChanged="Selector_OnSelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate DataType="managers:WorldViewModel">
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Checkpoint.SessionName}" FontWeight="Bold" Padding="0"/>
<Label Content="{Binding WorldPath}" Padding="5,0,0,0"/>
<Label Content="{Binding Checkpoint.SessionName}" FontWeight="Bold" Padding="0" />
<Label Content="{Binding WorldPath}" Padding="5,0,0,0" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Last saved: " Padding="0"/>
<Label Content="{Binding Checkpoint.LastSaveTime}" Padding="0"/>
<Label Content="Size (KB): " Padding="0"/>
<Label Content="{Binding WorldSizeKB}" Padding="0"/>
<Label Content="Last saved: " Padding="5,0,0,0" />
<Label Content="{Binding Checkpoint.LastSaveTime}" Padding="0" />
</StackPanel>
</StackPanel>
</DataTemplate>
@@ -38,13 +50,13 @@
</DockPanel>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0" Margin="3">
<StackPanel Orientation="Horizontal">
@@ -54,7 +66,16 @@
<Label Content="World Name" />
<TextBox Text="{Binding WorldName}" Margin="3,0,3,3" Width="160" />
<Label Content="Whitelist Group ID" />
<TextBox Text="{Binding GroupId}" Margin="3,0,3,3" Width="160" />
<TextBox Margin="3,0,3,3" Width="160" Style="{StaticResource ValidatedTextBox}">
<TextBox.Text>
<Binding Path="GroupId" UpdateSourceTrigger="PropertyChanged"
ValidatesOnDataErrors="True" NotifyOnValidationError="True">
<Binding.ValidationRules>
<validationRules:NumberValidationRule/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<Label Content="Server IP" />
<StackPanel Orientation="Horizontal" Margin="3,0,3,3">
<TextBox Text="{Binding IP}" Width="100" Height="20" />
@@ -65,19 +86,38 @@
</StackPanel>
<StackPanel Margin="3">
<Label Content="Mods" />
<TextBox Text="{Binding Mods}" Margin="3" Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto"/>
<TextBox Margin="3" Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto" Style="{StaticResource ValidatedTextBox}">
<TextBox.Text>
<Binding Path="Mods" UpdateSourceTrigger="PropertyChanged"
ValidatesOnDataErrors="True" NotifyOnValidationError="True"
Converter="{StaticResource ListConverterUInt64}">
<Binding.ValidationRules>
<validationRules:ListConverterValidationRule Type="system:UInt64" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<Label Content="Administrators" />
<TextBox Text="{Binding Administrators}" Margin="3" Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto"/>
<TextBox Text="{Binding Administrators, Converter={StaticResource ListConverterString}}" Margin="3"
Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto" />
<Label Content="Banned Players" />
<TextBox Text="{Binding Banned}" Margin="3" Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto"/>
<TextBox Margin="3" Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto" Style="{StaticResource ValidatedTextBox}">
<TextBox.Text>
<Binding Path="Banned" UpdateSourceTrigger="PropertyChanged"
ValidatesOnDataErrors="True" NotifyOnValidationError="True"
Converter="{StaticResource ListConverterUInt64}">
<Binding.ValidationRules>
<validationRules:ListConverterValidationRule Type="system:UInt64" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</StackPanel>
</StackPanel>
</ScrollViewer>
<Button Grid.Row="1" Content="Save Config" Margin="3" Click="Save_OnClick" />
</Grid>
<ScrollViewer Grid.Column="1" Margin="3">
<local:SessionSettingsView DataContext="{Binding SessionSettings}"/>
</ScrollViewer>
<views:PropertyGrid Grid.Column="1" Margin="3" DataContext="{Binding SessionSettings}"/>
</Grid>
</Grid>
</UserControl>

View File

@@ -1,6 +1,15 @@
using System.Windows;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Threading;
using Torch.API.Managers;
using Torch.Server.Annotations;
using Torch.Server.Managers;
using Torch.Server.ViewModels;
@@ -9,16 +18,69 @@ namespace Torch.Server.Views
/// <summary>
/// Interaction logic for ConfigControl.xaml
/// </summary>
public partial class ConfigControl : UserControl
public partial class ConfigControl : UserControl, INotifyPropertyChanged
{
private InstanceManager _instanceManager;
private bool _configValid;
public bool ConfigValid { get => _configValid; private set { _configValid = value; OnPropertyChanged(); } }
private List<BindingExpression> _bindingExpressions = new List<BindingExpression>();
public ConfigControl()
{
InitializeComponent();
_instanceManager = TorchBase.Instance.Managers.GetManager<InstanceManager>();
_instanceManager.InstanceLoaded += _instanceManager_InstanceLoaded;
DataContext = _instanceManager.DedicatedConfig;
// Gets called once all children are loaded
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(ApplyStyles));
}
private void CheckValid()
{
ConfigValid = !_bindingExpressions.Any(x => x.HasError);
}
private void ApplyStyles()
{
foreach (var textbox in GetAllChildren<TextBox>(this))
{
textbox.Style = (Style)Resources["ValidatedTextBox"];
var binding = textbox.GetBindingExpression(TextBox.TextProperty);
if (binding == null)
continue;
_bindingExpressions.Add(binding);
textbox.TextChanged += (sender, args) =>
{
binding.UpdateSource();
CheckValid();
};
textbox.LostKeyboardFocus += (sender, args) =>
{
if (binding.HasError)
binding.UpdateTarget();
CheckValid();
};
CheckValid();
}
}
private IEnumerable<T> GetAllChildren<T>(DependencyObject control) where T : DependencyObject
{
var children = LogicalTreeHelper.GetChildren(control).OfType<DependencyObject>();
foreach (var child in children)
{
if (child is T t)
yield return t;
foreach (var grandChild in GetAllChildren<T>(child))
yield return grandChild;
}
}
private void _instanceManager_InstanceLoaded(ConfigDedicatedViewModel obj)
@@ -46,5 +108,13 @@ namespace Torch.Server.Views
_instanceManager.SelectWorld(world.WorldPath, result != MessageBoxResult.Yes);
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Torch.Server.Views.Converters
{
public class BooleanAndConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
foreach (var value in values)
{
if (value is bool b && b == false)
{
return false;
}
}
return true;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException("BooleanAndConverter is a OneWay converter.");
}
}
}

View File

@@ -11,9 +11,6 @@ namespace Torch.Server.Views.Converters
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (targetType != typeof(bool))
throw new InvalidOperationException("The target must be a boolean");
return !(bool)value;
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Navigation;
namespace Torch.Server.Views.Converters
{
public class ListConverter : IValueConverter
{
public Type Type { get; set; }
/// <inheritdoc />
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is IList list))
throw new InvalidOperationException("Value is not the proper type.");
var sb = new StringBuilder();
foreach (var item in list)
{
sb.AppendLine(item.ToString());
}
return sb.ToString();
}
/// <inheritdoc />
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(Type));
var converter = TypeDescriptor.GetConverter(Type);
var input = ((string)value).Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in input)
{
try
{
list.Add(converter.ConvertFromString(item));
}
catch
{
throw new InvalidOperationException("Could not convert input value.");
}
}
return list;
}
}
}

View File

@@ -1,12 +0,0 @@
<UserControl x:Class="Torch.Server.Views.DynamicView"
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"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>

View File

@@ -1,81 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Torch.Server.Views
{
/// <summary>
/// Interaction logic for DynamicView.xaml
/// </summary>
public partial class DynamicView : UserControl
{
private static Dictionary<Type, StackPanel> _map = new Dictionary<Type, StackPanel>();
public DynamicView()
{
InitializeComponent();
DataContextChanged += DynamicView_DataContextChanged;
}
private void DynamicView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var content = GenerateForType(e.NewValue.GetType());
content.DataContext = e.NewValue;
Content = content;
}
public static StackPanel GenerateForType(Type t)
{
if (_map.TryGetValue(t, out StackPanel v))
return v;
var properties = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
var panel = new StackPanel();
foreach (var property in properties)
{
panel.Children.Add(GenerateDefault(property));
}
_map.Add(t, panel);
return panel;
}
private static StackPanel GenerateBool(PropertyInfo propInfo)
{
var panel = new StackPanel { Orientation = Orientation.Horizontal };
var label = new Label { Content = propInfo.Name };
var checkbox = new CheckBox();
checkbox.SetBinding(CheckBox.IsCheckedProperty, propInfo.Name);
panel.Children.Add(checkbox);
panel.Children.Add(label);
return panel;
}
private static StackPanel GenerateDefault(PropertyInfo propInfo)
{
var panel = new StackPanel { Orientation = Orientation.Horizontal };
var label = new Label { Content = propInfo.Name };
var textbox = new TextBox();
textbox.SetBinding(TextBox.TextProperty, propInfo.Name);
panel.Children.Add(label);
panel.Children.Add(textbox);
return panel;
}
}
}

View File

@@ -3,8 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server.Views.Blocks"
xmlns:blocks="clr-namespace:Torch.Server.ViewModels.Blocks"
xmlns:converters="clr-namespace:Torch.Server.Views.Converters"
mc:Ignorable="d">
<UserControl.Resources>

View File

@@ -3,11 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server.Views"
xmlns:viewModels="clr-namespace:Torch.Server.ViewModels"
xmlns:entities="clr-namespace:Torch.Server.ViewModels.Entities"
xmlns:blocks="clr-namespace:Torch.Server.ViewModels.Blocks"
xmlns:converters="clr-namespace:Torch.Server.Views.Converters"
xmlns:viewModels="clr-namespace:Torch.Server.ViewModels"
mc:Ignorable="d">
<UserControl.DataContext>
<viewModels:EntityTreeViewModel />

View File

@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server"
mc:Ignorable="d">
<StackPanel Margin="0,0,0,0" Orientation="Vertical">
<Label Content="Mods" Margin="5,5,5,5"/>

View File

@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server"
mc:Ignorable="d">
<DockPanel>
<StackPanel DockPanel.Dock="Bottom">

View File

@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server.Views"
xmlns:viewModels="clr-namespace:Torch.Server.ViewModels"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">

View File

@@ -1,15 +0,0 @@
<UserControl x:Class="Torch.Server.Views.PropertyGrid"
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"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<DataGrid x:Name="Grid" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn x:Name="NameCol" Width="1*" Header="Name" Binding="{Binding Name}" IsReadOnly="True"/>
<DataGridTemplateColumn x:Name="ValCol" Width="1*" Header="Value"/>
</DataGrid.Columns>
</DataGrid>
</UserControl>

View File

@@ -1,68 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Torch.Server.Views
{
/// <summary>
/// Interaction logic for PropertyGrid.xaml
/// </summary>
public partial class PropertyGrid : UserControl
{
public PropertyGrid()
{
InitializeComponent();
}
public void SetObject(object obj)
{
var props = obj.GetType().GetProperties();
foreach (var prop in props)
{
var p = prop.GetValue(obj);
Grid.Items.Add(new PropertyView(p, prop.Name));
}
}
}
public class PropertyView : ViewModel
{
private object _obj;
public string Name { get; }
public string Value { get { return _obj.ToString(); } }
public DataTemplate ValueEditTemplate;
public PropertyView(object obj, string name)
{
Name = name;
_obj = obj;
ValueEditTemplate = new DataTemplate();
}
}
/*
public class PropertyGridDataTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is IEnumerable)
{
}
}
}*/
}

View File

@@ -0,0 +1,22 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:Torch.Server.Views.Converters"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<Style x:Key="{x:Type Window}" TargetType="{x:Type Window}" BasedOn="{StaticResource {x:Type Window}}">
<Style.Setters>
<Setter Property="Background" Value="Black"/>
</Style.Setters>
</Style>
<Style x:Key="ValidatedTextBox" TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
<Setter Property="Background" Value="Pink"/>
</Trigger>
</Style.Triggers>
</Style>
<converters:ListConverter x:Key="ListConverterString" Type="system:String"/>
<converters:ListConverter x:Key="ListConverterUInt64" Type="system:UInt64"/>
<converters:BooleanAndConverter x:Key="BooleanAndConverter"/>
</ResourceDictionary>

View File

@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Torch.Server.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel>

View File

@@ -7,18 +7,41 @@
xmlns:views="clr-namespace:Torch.Server.Views"
xmlns:converters="clr-namespace:Torch.Server.Views.Converters"
mc:Ignorable="d"
Title="Torch">
Title="Torch"
Name="MainWindow">
<Window.Resources>
<converters:InverseBooleanConverter x:Key="InverseBool"/>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
<converters:InverseBooleanConverter x:Key="InverseBool"/>
</ResourceDictionary>
</Window.Resources>
<!--
<Window.DataContext>
<local:TorchServer/>
</Window.DataContext>
-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="5,5,5,5" Orientation="Horizontal">
<Menu Grid.Row="0">
<MenuItem Header="File"/>
<MenuItem Header="Tools"/>
</Menu>
<StackPanel Grid.Row="1" Margin="5,5,5,5" Orientation="Horizontal">
<Button x:Name="BtnStart" Content="Start" Height="24" Width="75" Margin="5,0,5,0"
HorizontalAlignment="Left" Click="BtnStart_Click" IsEnabled="{Binding IsRunning, Converter={StaticResource InverseBool}}"/>
HorizontalAlignment="Left" Click="BtnStart_Click">
<Button.IsEnabled>
<MultiBinding Converter="{StaticResource BooleanAndConverter}">
<Binding ElementName="MainWindow" Path="DataContext.IsRunning" Converter="{StaticResource InverseBool}"/>
<Binding ElementName="ConfigControl" Path="ConfigValid"/>
</MultiBinding>
</Button.IsEnabled>
</Button>
<Button x:Name="BtnStop" Content="Stop" Height="24" Width="75" Margin="5,0,5,0" HorizontalAlignment="Left"
Click="BtnStop_Click" IsEnabled="{Binding IsRunning}" />
<Label>
@@ -37,7 +60,7 @@
</Label.Content>
</Label>
</StackPanel>
<TabControl Grid.Row="1" Height="Auto" x:Name="TabControl" Margin="5,0,5,5">
<TabControl Grid.Row="2" Height="Auto" x:Name="TabControl" Margin="5,0,5,5">
<TabItem Header="Configuration">
<Grid IsEnabled="{Binding IsRunning, Converter={StaticResource InverseBool}}">
<Grid.RowDefinitions>

View File

@@ -36,6 +36,8 @@ namespace Torch.Server
{
_config = (TorchConfig)server.Config;
_server = server;
//TODO: data binding for whole server
DataContext = server;
InitializeComponent();
Left = _config.WindowPosition.X;
@@ -43,8 +45,6 @@ namespace Torch.Server
Width = _config.WindowSize.X;
Height = _config.WindowSize.Y;
//TODO: data binding for whole server
DataContext = server;
Chat.BindServer(server);
PlayerList.BindServer(server);
Plugins.BindServer(server);
@@ -65,7 +65,6 @@ namespace Torch.Server
private void BtnStart_Click(object sender, RoutedEventArgs e)
{
_server.GetManager<InstanceManager>().SaveConfig();
_server.Start();
}

View File

@@ -0,0 +1,32 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Controls;
namespace Torch.Server.Views.ValidationRules
{
public class ListConverterValidationRule : ValidationRule
{
public Type Type { get; set; }
/// <inheritdoc />
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
var converter = TypeDescriptor.GetConverter(Type);
var input = ((string)value).Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in input)
{
try
{
converter.ConvertFromString(item);
}
catch
{
return new ValidationResult(false, $"{item} is not a valid value.");
}
}
return ValidationResult.ValidResult;
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace Torch.Server.Views.ValidationRules
{
public class NumberValidationRule : ValidationRule
{
/// <inheritdoc />
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (!float.TryParse(value?.ToString(), out _))
return new ValidationResult(false, "Not a number.");
return ValidationResult.ValidResult;
}
}
}

2
Torch.sln.DotSettings Normal file
View File

@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Torch_002EServer_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@@ -27,7 +27,7 @@ namespace Torch.Commands
private readonly MethodInfo _method;
private ParameterInfo[] _parameters;
private int? _requiredParamCount;
private static readonly Logger Log = LogManager.GetLogger(nameof(Command));
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public Command(ITorchPlugin plugin, MethodInfo commandMethod)
{
@@ -80,7 +80,7 @@ namespace Torch.Commands
}
_requiredParamCount = _requiredParamCount ?? _parameters.Length;
LogManager.GetLogger(nameof(Command)).Debug($"Params: {_parameters.Length} ({_requiredParamCount} required)");
Log.Debug($"Params: {_parameters.Length} ({_requiredParamCount} required)");
SyntaxHelp = sb.ToString();
}

View File

@@ -21,7 +21,7 @@ namespace Torch.Commands
public char Prefix { get; set; }
public CommandTree Commands { get; set; } = new CommandTree();
private Logger _log = LogManager.GetLogger(nameof(CommandManager));
private Logger _log = LogManager.GetCurrentClassLogger();
[Dependency]
private IChatManagerServer _chatManager;

View File

@@ -3,11 +3,13 @@ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using Sandbox.ModAPI;
using SteamSDK;
using Torch;
using Torch.API;
using Torch.API.Managers;
@@ -21,6 +23,18 @@ namespace Torch.Commands
{
public class TorchCommands : CommandModule
{
[Command("whatsmyip")]
[Permission(MyPromoteLevel.None)]
public void GetIP(ulong steamId = 0)
{
var state = new P2PSessionState();
if (steamId == 0)
steamId = Context.Player.SteamUserId;
Peer2Peer.GetSessionState(steamId, ref state);
var ip = new IPAddress(BitConverter.GetBytes(state.RemoteIP).Reverse().ToArray());
Context.Respond($"Your IP is {ip}");
}
[Command("help", "Displays help for a command")]
[Permission(MyPromoteLevel.None)]
public void Help()
@@ -164,7 +178,7 @@ namespace Torch.Commands
else
{
if (save)
Context.Torch.Save(Context.Player?.IdentityId ?? 0).ContinueWith(x => Restart());
Context.Torch.Save().ContinueWith(x => Restart());
else
Restart();

View File

@@ -34,7 +34,7 @@ namespace Torch.Managers
{
public class EntityManager : Manager
{
private static readonly Logger Log = LogManager.GetLogger(nameof(EntityManager));
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public EntityManager(ITorchBase torch) : base(torch)
{

View File

@@ -18,7 +18,7 @@ namespace Torch.Managers
{
public class NetworkManager : Manager, INetworkManager
{
private static Logger _log = LogManager.GetLogger(nameof(NetworkManager));
private static Logger _log = LogManager.GetCurrentClassLogger();
private const string _myTransportLayerField = "TransportLayer";
private const string _transportHandlersField = "m_handlers";

View File

@@ -24,7 +24,7 @@ namespace Torch.Managers
private Timer _updatePollTimer;
private GitHubClient _gitClient = new GitHubClient(new ProductHeaderValue("Torch"));
private string _torchDir = new FileInfo(typeof(UpdateManager).Assembly.Location).DirectoryName;
private Logger _log = LogManager.GetLogger(nameof(UpdateManager));
private Logger _log = LogManager.GetCurrentClassLogger();
[Dependency]
private FilesystemManager _fsManager;

View File

@@ -25,7 +25,7 @@ namespace Torch.Managers
public class PluginManager : Manager, IPluginManager
{
private GitHubClient _gitClient = new GitHubClient(new ProductHeaderValue("Torch"));
private static Logger _log = LogManager.GetLogger(nameof(PluginManager));
private static Logger _log = LogManager.GetCurrentClassLogger();
private const string MANIFEST_NAME = "manifest.xml";
public readonly string PluginDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");
private readonly MtObservableSortedDictionary<Guid, ITorchPlugin> _plugins = new MtObservableSortedDictionary<Guid, ITorchPlugin>();
@@ -132,6 +132,10 @@ namespace Torch.Managers
private void DownloadPluginUpdates()
{
//TODO
_log.Warn("Automatic plugin updates are disabled in this build of Torch while the system is reworked.");
return;
_log.Info("Checking for plugin updates...");
var count = 0;
var pluginItems = Directory.EnumerateFiles(PluginDir, "*.zip").Union(Directory.EnumerateDirectories(PluginDir));
@@ -168,10 +172,14 @@ namespace Torch.Managers
await UpdatePluginAsync(path, latest.Item2).ConfigureAwait(false);
count++;
}
catch (NotFoundException)
{
_log.Warn($"GitHub repository not found for {manifest.Name}");
}
catch (Exception e)
{
_log.Error($"An error occurred updating the plugin {manifest.Name}.");
_log.Error(e);
_log.Warn($"An error occurred updating the plugin {manifest.Name}.");
_log.Warn(e);
}
});

View File

@@ -21,7 +21,7 @@ namespace Torch
{
private static CancellationTokenSource _tokenSource = new CancellationTokenSource();
private static CancellationToken _cancelToken;
private static Logger _log = LogManager.GetLogger(nameof(SteamHelper));
private static Logger _log = LogManager.GetCurrentClassLogger();
public static string BasePath { get; private set; }
private static string _libraryFolders;

View File

@@ -82,6 +82,7 @@
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
@@ -256,6 +257,9 @@
<Compile Include="Views\CollectionEditor.xaml.cs">
<DependentUpon>CollectionEditor.xaml</DependentUpon>
</Compile>
<Compile Include="Views\PropertyGrid.xaml.cs">
<DependentUpon>PropertyGrid.xaml</DependentUpon>
</Compile>
<Compile Include="VRageGame.cs" />
</ItemGroup>
<ItemGroup>
@@ -273,6 +277,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\PropertyGrid.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />

View File

@@ -79,6 +79,7 @@ namespace Torch
/// Hack because *keen*.
/// Use only if necessary, prefer dependency injection.
/// </summary>
[Obsolete("This is a hack, don't use it.")]
public static ITorchBase Instance { get; private set; }
/// <inheritdoc />

View File

@@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SteamSDK;
namespace Torch.Utils
{
@@ -49,5 +51,11 @@ namespace Torch.Utils
_streamBuffer.Value.SetTarget(buffer);
return result;
}
public static IPAddress GetRemoteIP(this P2PSessionState state)
{
// What is endianness anyway?
return new IPAddress(BitConverter.GetBytes(state.RemoteIP).Reverse().ToArray());
}
}
}

View File

@@ -11,7 +11,7 @@ namespace Torch.Utils
{
public static class Reflection
{
private static readonly Logger Log = LogManager.GetLogger("Reflection");
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public static bool HasMethod(Type type, string methodName, Type[] argTypes = null)
{

View File

@@ -48,6 +48,10 @@ namespace Torch
}
}
/// <summary>
/// Assign a value to the given field and raise PropertyChanged for the caller.
/// </summary>
protected virtual void SetValue<T>(ref T backingField, T value, [CallerMemberName] string propName = "")
{
if (backingField != null && backingField.Equals(value))
@@ -58,6 +62,19 @@ namespace Torch
OnPropertyChanged(propName);
}
/// <summary>
/// Assign a value using the given setter and raise PropertyChanged for the caller.
/// </summary>
protected virtual void SetValue<T>(Action<T> setter, T value, [CallerMemberName] string propName = "")
{
if (setter == null)
throw new ArgumentNullException(nameof(setter));
setter.Invoke(value);
// ReSharper disable once ExplicitCallerInfoArgument
OnPropertyChanged(propName);
}
/// <summary>
/// Fires PropertyChanged for all properties.
/// </summary>

View File

@@ -0,0 +1,23 @@
<UserControl x:Class="Torch.Views.PropertyGrid"
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"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Filter: " Margin="3"/>
<TextBox Grid.Column="1" Margin="3" TextChanged="UpdateFilter"/>
</Grid>
<ScrollViewer Grid.Row="1" x:Name="ScrollViewer"/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VRage.Game;
namespace Torch.Views
{
/// <summary>
/// Interaction logic for PropertyGrid.xaml
/// </summary>
public partial class PropertyGrid : UserControl
{
private Dictionary<Type, Grid> _viewCache = new Dictionary<Type, Grid>();
public PropertyGrid()
{
InitializeComponent();
DataContextChanged += OnDataContextChanged;
}
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue == null)
{
ScrollViewer.Content = null;
return;
}
var content = GenerateForType(e.NewValue.GetType());
content.DataContext = e.NewValue;
ScrollViewer.Content = content;
}
public Grid GenerateForType(Type t)
{
if (_viewCache.TryGetValue(t, out var v))
return v;
var properties = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition());
var curRow = 0;
foreach (var property in properties.OrderBy(x => x.Name))
{
if (property.GetGetMethod() == null)
continue;
grid.RowDefinitions.Add(new RowDefinition());
var displayName = property.GetCustomAttribute<DisplayAttribute>()?.Name;
var text = new TextBlock
{
Text = property.Name,
ToolTip = displayName,
VerticalAlignment = VerticalAlignment.Center
};
text.SetValue(Grid.ColumnProperty, 0);
text.SetValue(Grid.RowProperty, curRow);
text.Margin = new Thickness(3);
grid.Children.Add(text);
FrameworkElement valueControl;
if (property.GetSetMethod() == null)
{
valueControl = new TextBlock();
var binding = new Binding(property.Name)
{
Mode = BindingMode.OneWay
};
valueControl.SetBinding(TextBlock.TextProperty, binding);
}
else if (property.PropertyType == typeof(bool) || property.PropertyType == typeof(bool?))
{
valueControl = new CheckBox();
valueControl.SetBinding(CheckBox.IsCheckedProperty, property.Name);
}
else if (property.PropertyType.IsEnum)
{
valueControl = new ComboBox
{
ItemsSource = Enum.GetValues(property.PropertyType)
};
valueControl.SetBinding(ComboBox.SelectedItemProperty, property.Name);
}
else
{
valueControl = new TextBox();
valueControl.SetBinding(TextBox.TextProperty, property.Name);
}
valueControl.Margin = new Thickness(3);
valueControl.VerticalAlignment = VerticalAlignment.Center;
valueControl.SetValue(Grid.ColumnProperty, 1);
valueControl.SetValue(Grid.RowProperty, curRow);
grid.Children.Add(valueControl);
curRow++;
}
_viewCache.Add(t, grid);
return grid;
}
private void UpdateFilter(object sender, TextChangedEventArgs e)
{
var filterText = ((TextBox)sender).Text;
var grid = (Grid)ScrollViewer.Content;
foreach (var child in grid.Children)
{
if (!(child is TextBlock block))
continue;
var rowNum = (int)block.GetValue(Grid.RowProperty);
var row = grid.RowDefinitions[rowNum];
if (block.Text.Contains(filterText, StringComparison.InvariantCultureIgnoreCase))
{
row.Height = GridLength.Auto;
}
else
{
row.Height = new GridLength(0);
}
}
}
}
}