diff --git a/Torch.Server/Managers/InstanceManager.cs b/Torch.Server/Managers/InstanceManager.cs
index 5e63b77..a3c06b1 100644
--- a/Torch.Server/Managers/InstanceManager.cs
+++ b/Torch.Server/Managers/InstanceManager.cs
@@ -234,9 +234,11 @@ namespace Torch.Server.Managers
try
{
- var world = DedicatedConfig.Worlds.FirstOrDefault(x => x.WorldPath == DedicatedConfig.LoadWorld) ?? new WorldViewModel(DedicatedConfig.LoadWorld);
+ var world = DedicatedConfig.SelectedWorld;
- world.Checkpoint.SessionName = DedicatedConfig.WorldName;
+ world.Checkpoint.SessionName = string.IsNullOrEmpty(DedicatedConfig.WorldName)
+ ? Path.GetDirectoryName(DedicatedConfig.LoadWorld)
+ : DedicatedConfig.WorldName;
world.WorldConfiguration.Settings = DedicatedConfig.SessionSettings;
world.WorldConfiguration.Mods.Clear();
@@ -268,7 +270,7 @@ namespace Torch.Server.Managers
private void ValidateInstance(string path)
{
Directory.CreateDirectory(Path.Combine(path, "Saves"));
- Directory.CreateDirectory(Path.Combine(path, "Mods"));
+ // Directory.CreateDirectory(Path.Combine(path, "Mods"));
var configPath = Path.Combine(path, CONFIG_NAME);
if (File.Exists(configPath))
return;
diff --git a/Torch.Server/Patches/CheckpointLoadPatch.cs b/Torch.Server/Patches/CheckpointLoadPatch.cs
index e4f0ef5..d9d4fe1 100644
--- a/Torch.Server/Patches/CheckpointLoadPatch.cs
+++ b/Torch.Server/Patches/CheckpointLoadPatch.cs
@@ -33,6 +33,9 @@ public static class CheckpointLoadPatch
return false;
}
+ world.KeenCheckpoint.Settings = world.WorldConfiguration.Settings;
+ world.KeenCheckpoint.Mods = world.WorldConfiguration.Mods;
+
__result = world.Checkpoint;
return false;
}
diff --git a/Torch.Server/Views/ModListControl.xaml b/Torch.Server/Views/ModListControl.xaml
index 723d2da..c87c8c3 100644
--- a/Torch.Server/Views/ModListControl.xaml
+++ b/Torch.Server/Views/ModListControl.xaml
@@ -5,8 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:viewModels="clr-namespace:Torch.Server.ViewModels"
mc:Ignorable="d"
- d:DesignHeight="450" d:DesignWidth="800"
- MouseMove="UserControl_MouseMove">
+ d:DesignHeight="450" d:DesignWidth="800">
@@ -18,7 +17,7 @@
-
+
-
+
@@ -98,10 +94,10 @@
-
+
-
@@ -110,6 +106,6 @@
-
+
diff --git a/Torch.Server/Views/ModListControl.xaml.cs b/Torch.Server/Views/ModListControl.xaml.cs
index c17dcb5..2a456f1 100644
--- a/Torch.Server/Views/ModListControl.xaml.cs
+++ b/Torch.Server/Views/ModListControl.xaml.cs
@@ -1,32 +1,15 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Collections.Specialized;
-using System.ComponentModel;
+using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Text.RegularExpressions;
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 System.Runtime.CompilerServices;
-using System.Windows.Threading;
-using VRage.Game;
using NLog;
-using Sandbox.Engine.Networking;
using Torch.API;
using Torch.Server.Managers;
using Torch.API.Managers;
using Torch.Server.ViewModels;
-using Torch.Server.Annotations;
-using Torch.Collections;
using Torch.Utils;
using Torch.Views;
@@ -35,14 +18,12 @@ namespace Torch.Server.Views
///
/// Interaction logic for ModListControl.xaml
///
- public partial class ModListControl : UserControl, INotifyPropertyChanged
+ public partial class ModListControl : UserControl
{
private static Logger Log = LogManager.GetLogger(nameof(ModListControl));
private InstanceManager _instanceManager;
- ModItemInfo _draggedMod;
- bool _hasOrderChanged = false;
- bool _isSortedByLoadOrder = true;
private readonly ITorchConfig _config;
+ private ConfigDedicatedViewModel _viewModel;
//private List _bindingExpressions = new List();
///
@@ -51,9 +32,11 @@ namespace Torch.Server.Views
public ModListControl()
{
InitializeComponent();
+#pragma warning disable CS0618
_instanceManager = TorchBase.Instance.Managers.GetManager();
- _instanceManager.InstanceLoaded += _instanceManager_InstanceLoaded;
_config = TorchBase.Instance.Config;
+#pragma warning restore CS0618
+ _instanceManager.InstanceLoaded += _instanceManager_InstanceLoaded;
//var mods = _instanceManager.DedicatedConfig?.Mods;
//if( mods != null)
// DataContext = new ObservableCollection();
@@ -67,39 +50,22 @@ namespace Torch.Server.Views
//Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(ApplyStyles));
}
- private void ModListControl_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- throw new NotImplementedException();
- }
-
- private void ResetSorting()
- {
- CollectionViewSource.GetDefaultView(ModList.ItemsSource).SortDescriptions.Clear();
- }
-
private void _instanceManager_InstanceLoaded(ConfigDedicatedViewModel obj)
{
- Dispatcher.Invoke(() => {
- DataContext = obj?.Mods ?? new MtObservableList();
+ Dispatcher.InvokeAsync(() =>
+ {
+ _viewModel = obj;
+ DataContext = obj;
UpdateLayout();
- ((MtObservableList)DataContext).CollectionChanged += OnModlistUpdate;
- if (obj is { })
- Task.Run(async () =>
- {
- await obj.UpdateAllModInfosAsync();
- Log.Info("Instance loaded.");
- });
+ Task.Run(async () =>
+ {
+ await obj.UpdateAllModInfosAsync();
+ Log.Info("Instance loaded.");
+ });
});
}
- private void OnModlistUpdate(object sender, NotifyCollectionChangedEventArgs e)
- {
- ModList.Items.Refresh();
- //if (e.Action == NotifyCollectionChangedAction.Remove)
- // _instanceManager.SaveConfig();
- }
-
private void SaveBtn_OnClick(object sender, RoutedEventArgs e)
{
_instanceManager.SaveConfig();
@@ -108,31 +74,28 @@ namespace Torch.Server.Views
private void AddBtn_OnClick(object sender, RoutedEventArgs e)
{
- if (TryExtractId(AddModIDTextBox.Text, out ulong id))
+ if (TryExtractId(AddModIdTextBox.Text, out ulong id))
{
var mod = new ModItemInfo(ModItemUtils.Create(id, UgcServiceTypeBox.SelectedValue?.ToString()));
_instanceManager.DedicatedConfig.Mods.Add(mod);
Task.Run(mod.UpdateModInfoAsync)
- .ContinueWith((t) =>
+ .ContinueWith(_ =>
{
- Dispatcher.Invoke(() =>
- {
- _instanceManager.DedicatedConfig.Save();
- });
+ _instanceManager.DedicatedConfig.Save();
});
- AddModIDTextBox.Text = "";
+ AddModIdTextBox.Text = "";
}
else
{
- AddModIDTextBox.BorderBrush = Brushes.Red;
+ AddModIdTextBox.BorderBrush = Brushes.Red;
Log.Warn("Invalid mod id!");
MessageBox.Show("Invalid mod id!");
}
}
private void RemoveBtn_OnClick(object sender, RoutedEventArgs e)
{
- var modList = ((MtObservableList)DataContext);
+ var modList = _viewModel.Mods;
if (ModList.SelectedItem is ModItemInfo mod && modList.Contains(mod))
modList.Remove(mod);
}
@@ -150,113 +113,9 @@ namespace Torch.Server.Views
return success;
}
- private void ModList_Sorting(object sender, DataGridSortingEventArgs e)
- {
- Log.Info($"Sorting by '{e.Column.Header}'");
- if (e.Column == ModList.Columns[0])
- {
- var dataView = CollectionViewSource.GetDefaultView(ModList.ItemsSource);
- dataView.SortDescriptions.Clear();
- dataView.Refresh();
- _isSortedByLoadOrder = true;
- }
- else
- _isSortedByLoadOrder = false;
- }
-
- private void ModList_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- //return;
-
- _draggedMod = (ModItemInfo) TryFindRowAtPoint((UIElement) sender, e.GetPosition(ModList))?.DataContext;
-
- //DraggedMod = (ModItemInfo) ModList.SelectedItem;
- }
-
- private static DataGridRow TryFindRowAtPoint(UIElement reference, Point point)
- {
- var element = reference.InputHitTest(point) as DependencyObject;
- if (element == null)
- return null;
- if (element is DataGridRow row)
- return row;
- else
- return TryFindParent(element);
- }
-
- private static T TryFindParent(DependencyObject child) where T : DependencyObject
- {
- DependencyObject parent;
- if (child == null)
- return null;
- if (child is ContentElement contentElement)
- {
- parent = ContentOperations.GetParent(contentElement);
- if (parent == null && child is FrameworkContentElement fce)
- parent = fce.Parent;
- }
- else
- {
- parent = VisualTreeHelper.GetParent(child);
- }
-
- if (parent is T result)
- return result;
- else
- return TryFindParent(parent);
- }
-
- private void UserControl_MouseMove(object sender, MouseEventArgs e)
- {
- if (_draggedMod == null)
- return;
-
- if (!_isSortedByLoadOrder)
- return;
-
- var targetMod = (ModItemInfo)TryFindRowAtPoint((UIElement)sender, e.GetPosition(ModList))?.DataContext;
- if( targetMod != null && !ReferenceEquals(_draggedMod, targetMod))
- {
- _hasOrderChanged = true;
- var modList = (MtObservableList)DataContext;
- modList.Move(modList.IndexOf(targetMod), _draggedMod);
- //modList.RemoveAt(modList.IndexOf(_draggedMod));
- //modList.Insert(modList.IndexOf(targetMod), _draggedMod);
- ModList.Items.Refresh();
- ModList.SelectedItem = _draggedMod;
- }
- }
-
- private void ModList_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- if (!_isSortedByLoadOrder)
- {
- var targetMod = (ModItemInfo)TryFindRowAtPoint((UIElement)sender, e.GetPosition(ModList))?.DataContext;
- if (targetMod != null && !ReferenceEquals(_draggedMod, targetMod))
- {
- var msg = "Drag and drop is only available when sorted by load order!";
- Log.Warn(msg);
- MessageBox.Show(msg);
- }
- }
- //if (DraggedMod != null && HasOrderChanged)
- //Log.Info("Dragging over, saving...");
- //_instanceManager.SaveConfig();
- _draggedMod = null;
- }
-
- public event PropertyChangedEventHandler PropertyChanged;
- [NotifyPropertyChangedInvocator]
- protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
-
private void ModList_Selected(object sender, SelectedCellsChangedEventArgs e)
{
- if (_draggedMod != null)
- ModList.SelectedItem = _draggedMod;
- else if( e.AddedCells.Count > 0)
+ if( e.AddedCells.Count > 0)
ModList.SelectedItem = e.AddedCells[0].Item;
}
@@ -265,7 +124,7 @@ namespace Torch.Server.Views
var editor = new CollectionEditor();
//let's see just how poorly we can do this
- var modList = ((MtObservableList)DataContext).ToList();
+ var modList = _viewModel.Mods.ToList();
var idList = modList.Select(m => m.ToString()).ToList();
var tasks = new List();
//blocking