Enable creation of new worlds in Torch
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
<DockPanel Grid.Row="0">
|
<DockPanel Grid.Row="0">
|
||||||
<Label Content="World:" DockPanel.Dock="Left" />
|
<Label Content="World:" DockPanel.Dock="Left" />
|
||||||
<Button Content="Import World Config" Margin="3" Padding="3" DockPanel.Dock="Right" Click="ImportConfig_OnClick" ToolTip="Override the DS config with the one from the selected world." IsEnabled="{Binding ElementName=WorldList, Path=Items.Count, Mode=OneWay}"/>
|
<Button Content="Import World Config" Margin="3" Padding="3" DockPanel.Dock="Right" Click="ImportConfig_OnClick" ToolTip="Override the DS config with the one from the selected world." IsEnabled="{Binding ElementName=WorldList, Path=Items.Count, Mode=OneWay}"/>
|
||||||
|
<Button Content="New World" Margin="3" Padding="3" DockPanel.Dock="Right" Click="NewWorld_OnClick"/>
|
||||||
<ComboBox x:Name="WorldList" ItemsSource="{Binding Worlds}" SelectedItem="{Binding SelectedWorld}" Margin="3"
|
<ComboBox x:Name="WorldList" ItemsSource="{Binding Worlds}" SelectedItem="{Binding SelectedWorld}" Margin="3"
|
||||||
SelectionChanged="Selector_OnSelectionChanged">
|
SelectionChanged="Selector_OnSelectionChanged">
|
||||||
<ComboBox.ItemTemplate>
|
<ComboBox.ItemTemplate>
|
||||||
|
@@ -116,5 +116,11 @@ namespace Torch.Server.Views
|
|||||||
{
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void NewWorld_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var c = new WorldGeneratorDialog(_instanceManager);
|
||||||
|
c.Show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,14 +5,15 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:Torch.Server"
|
xmlns:local="clr-namespace:Torch.Server"
|
||||||
xmlns:views="clr-namespace:Torch.Server.Views"
|
xmlns:views="clr-namespace:Torch.Server.Views"
|
||||||
|
xmlns:views1="clr-namespace:Torch.Views;assembly=Torch"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="WorldGeneratorDialog" Height="300" Width="700">
|
Title="WorldGeneratorDialog" Height="500" Width="700">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="250"/>
|
<ColumnDefinition Width="250"/>
|
||||||
<ColumnDefinition Width="440"/>
|
<ColumnDefinition Width="*"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<ListView Grid.Column="0" x:Name="PremadeCheckpoints" ScrollViewer.CanContentScroll="False" HorizontalContentAlignment="Center" Margin="3">
|
<ListView Grid.Column="0" x:Name="PremadeCheckpoints" ScrollViewer.CanContentScroll="False" HorizontalContentAlignment="Center" Margin="3" SelectionChanged="PremadeCheckpoints_SelectionChanged">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate DataType="local:PremadeCheckpointItem">
|
<DataTemplate DataType="local:PremadeCheckpointItem">
|
||||||
<StackPanel HorizontalAlignment="Center">
|
<StackPanel HorizontalAlignment="Center">
|
||||||
@@ -26,13 +27,18 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListView.ItemTemplate>
|
</ListView.ItemTemplate>
|
||||||
</ListView>
|
</ListView>
|
||||||
<StackPanel Grid.Column="1" Margin="3">
|
<Grid Grid.Column="1" Margin="3">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height ="Auto"/>
|
||||||
|
<RowDefinition Height ="*"/>
|
||||||
|
<RowDefinition Height ="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Label Content="World Name: "/>
|
<Label Content="World Name: "/>
|
||||||
<TextBox x:Name="WorldName" Width="300" Margin="3"/>
|
<TextBox x:Name="WorldName" Width="300" Margin="3"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<views:SessionSettingsView/>
|
<views1:PropertyGrid Grid.Row="1" x:Name="SettingsView" Margin="3"/>
|
||||||
<Button Content="Create World" Click="ButtonBase_OnClick"/>
|
<Button Grid.Row="2" Content="Create World" Click="ButtonBase_OnClick" Margin ="3"/>
|
||||||
</StackPanel>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
@@ -13,7 +13,15 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Sandbox.Definitions;
|
using Sandbox.Definitions;
|
||||||
|
using Sandbox.Engine.Networking;
|
||||||
|
using Sandbox.Game.World;
|
||||||
using Torch.Server.Managers;
|
using Torch.Server.Managers;
|
||||||
|
using Torch.Server.ViewModels;
|
||||||
|
using Torch.Utils;
|
||||||
|
using VRage;
|
||||||
|
using VRage.Dedicated;
|
||||||
|
using VRage.FileSystem;
|
||||||
|
using VRage.Game;
|
||||||
using VRage.Game.Localization;
|
using VRage.Game.Localization;
|
||||||
using VRage.Utils;
|
using VRage.Utils;
|
||||||
|
|
||||||
@@ -26,19 +34,25 @@ namespace Torch.Server
|
|||||||
{
|
{
|
||||||
private InstanceManager _instanceManager;
|
private InstanceManager _instanceManager;
|
||||||
private List<PremadeCheckpointItem> _checkpoints = new List<PremadeCheckpointItem>();
|
private List<PremadeCheckpointItem> _checkpoints = new List<PremadeCheckpointItem>();
|
||||||
|
private PremadeCheckpointItem _currentItem;
|
||||||
|
|
||||||
|
[ReflectedStaticMethod(Type = typeof(ConfigForm), Name = "LoadLocalization")]
|
||||||
|
private static Action _loadLocalization;
|
||||||
|
|
||||||
public WorldGeneratorDialog(InstanceManager instanceManager)
|
public WorldGeneratorDialog(InstanceManager instanceManager)
|
||||||
{
|
{
|
||||||
_instanceManager = instanceManager;
|
_instanceManager = instanceManager;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_loadLocalization();
|
||||||
MyDefinitionManager.Static.LoadScenarios();
|
var scenarios = MyLocalCache.GetAvailableWorldInfos(Path.Combine(MyFileSystem.ContentPath, "CustomWorlds"));
|
||||||
var scenarios = MyDefinitionManager.Static.GetScenarioDefinitions();
|
foreach (var tup in scenarios)
|
||||||
MyDefinitionManager.Static.UnloadData();
|
|
||||||
foreach (var scenario in scenarios)
|
|
||||||
{
|
{
|
||||||
//TODO: Load localization
|
string directory = tup.Item1;
|
||||||
_checkpoints.Add(new PremadeCheckpointItem { Name = scenario.DisplayNameText, Icon = @"C:\Users\jgross\Documents\Projects\TorchAPI\Torch\bin\x64\Release\Content\CustomWorlds\Empty World\thumb.jpg" });
|
MyWorldInfo info = tup.Item2;
|
||||||
|
string localizedName = MyTexts.GetString(MyStringId.GetOrCompute(info.SessionName));
|
||||||
|
var checkpoint = MyLocalCache.LoadCheckpoint(directory, out _);
|
||||||
|
checkpoint.OnlineMode = MyOnlineModeEnum.PUBLIC;
|
||||||
|
_checkpoints.Add(new PremadeCheckpointItem { Name = localizedName, Icon = Path.Combine(directory, "thumb.jpg"), Path = directory, Checkpoint = checkpoint});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -59,20 +73,36 @@ namespace Torch.Server
|
|||||||
|
|
||||||
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
/*
|
string worldName = string.IsNullOrEmpty(WorldName.Text) ? _currentItem.Name : WorldName.Text;
|
||||||
var worldPath = Path.Combine("Instance", "Saves", WorldName.Text);
|
var worldPath = Path.Combine("Instance", "Saves", worldName);
|
||||||
var checkpointItem = (PremadeCheckpointItem)PremadeCheckpoints.SelectedItem;
|
var checkpoint= _currentItem.Checkpoint;
|
||||||
if (Directory.Exists(worldPath))
|
if (Directory.Exists(worldPath))
|
||||||
{
|
{
|
||||||
MessageBox.Show("World already exists with that name.");
|
MessageBox.Show("World already exists with that name.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Directory.CreateDirectory(worldPath);
|
Directory.CreateDirectory(worldPath);
|
||||||
foreach (var file in Directory.EnumerateFiles(checkpointItem.Path, "*", SearchOption.AllDirectories))
|
foreach (var file in Directory.EnumerateFiles(_currentItem.Path, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
File.Copy(file, Path.Combine(worldPath, file.Replace($"{checkpointItem.Path}\\", "")));
|
File.Copy(file, Path.Combine(worldPath, file.Replace($"{_currentItem.Path}\\", "")));
|
||||||
}
|
}
|
||||||
_instanceManager.SelectWorld(worldPath, false);*/
|
|
||||||
|
checkpoint.SessionName = worldName;
|
||||||
|
|
||||||
|
MyLocalCache.SaveCheckpoint(checkpoint, worldPath);
|
||||||
|
|
||||||
|
|
||||||
|
_instanceManager.SelectWorld(worldPath, false);
|
||||||
|
_instanceManager.LoadInstance(worldPath);
|
||||||
|
_instanceManager.ImportSelectedWorldConfig();
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PremadeCheckpoints_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var selected = (PremadeCheckpointItem)PremadeCheckpoints.SelectedItem;
|
||||||
|
_currentItem = selected;
|
||||||
|
SettingsView.DataContext = new SessionSettingsViewModel(_currentItem.Checkpoint.Settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,5 +111,6 @@ namespace Torch.Server
|
|||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Icon { get; set; }
|
public string Icon { get; set; }
|
||||||
|
public MyObjectBuilder_Checkpoint Checkpoint { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user