Enable creation of new worlds in Torch
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
<DockPanel Grid.Row="0">
|
||||
<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="New World" Margin="3" Padding="3" DockPanel.Dock="Right" Click="NewWorld_OnClick"/>
|
||||
<ComboBox x:Name="WorldList" ItemsSource="{Binding Worlds}" SelectedItem="{Binding SelectedWorld}" Margin="3"
|
||||
SelectionChanged="Selector_OnSelectionChanged">
|
||||
<ComboBox.ItemTemplate>
|
||||
|
@@ -116,5 +116,11 @@ namespace Torch.Server.Views
|
||||
{
|
||||
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:local="clr-namespace:Torch.Server"
|
||||
xmlns:views="clr-namespace:Torch.Server.Views"
|
||||
xmlns:views1="clr-namespace:Torch.Views;assembly=Torch"
|
||||
mc:Ignorable="d"
|
||||
Title="WorldGeneratorDialog" Height="300" Width="700">
|
||||
Title="WorldGeneratorDialog" Height="500" Width="700">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="250"/>
|
||||
<ColumnDefinition Width="440"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</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>
|
||||
<DataTemplate DataType="local:PremadeCheckpointItem">
|
||||
<StackPanel HorizontalAlignment="Center">
|
||||
@@ -26,13 +27,18 @@
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</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">
|
||||
<Label Content="World Name: "/>
|
||||
<TextBox x:Name="WorldName" Width="300" Margin="3"/>
|
||||
</StackPanel>
|
||||
<views:SessionSettingsView/>
|
||||
<Button Content="Create World" Click="ButtonBase_OnClick"/>
|
||||
</StackPanel>
|
||||
<views1:PropertyGrid Grid.Row="1" x:Name="SettingsView" Margin="3"/>
|
||||
<Button Grid.Row="2" Content="Create World" Click="ButtonBase_OnClick" Margin ="3"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@@ -13,7 +13,15 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using NLog;
|
||||
using Sandbox.Definitions;
|
||||
using Sandbox.Engine.Networking;
|
||||
using Sandbox.Game.World;
|
||||
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.Utils;
|
||||
|
||||
@@ -26,19 +34,25 @@ namespace Torch.Server
|
||||
{
|
||||
private InstanceManager _instanceManager;
|
||||
private List<PremadeCheckpointItem> _checkpoints = new List<PremadeCheckpointItem>();
|
||||
private PremadeCheckpointItem _currentItem;
|
||||
|
||||
[ReflectedStaticMethod(Type = typeof(ConfigForm), Name = "LoadLocalization")]
|
||||
private static Action _loadLocalization;
|
||||
|
||||
public WorldGeneratorDialog(InstanceManager instanceManager)
|
||||
{
|
||||
_instanceManager = instanceManager;
|
||||
InitializeComponent();
|
||||
|
||||
MyDefinitionManager.Static.LoadScenarios();
|
||||
var scenarios = MyDefinitionManager.Static.GetScenarioDefinitions();
|
||||
MyDefinitionManager.Static.UnloadData();
|
||||
foreach (var scenario in scenarios)
|
||||
_loadLocalization();
|
||||
var scenarios = MyLocalCache.GetAvailableWorldInfos(Path.Combine(MyFileSystem.ContentPath, "CustomWorlds"));
|
||||
foreach (var tup in scenarios)
|
||||
{
|
||||
//TODO: Load localization
|
||||
_checkpoints.Add(new PremadeCheckpointItem { Name = scenario.DisplayNameText, Icon = @"C:\Users\jgross\Documents\Projects\TorchAPI\Torch\bin\x64\Release\Content\CustomWorlds\Empty World\thumb.jpg" });
|
||||
string directory = tup.Item1;
|
||||
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});
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -56,23 +70,39 @@ namespace Torch.Server
|
||||
}*/
|
||||
PremadeCheckpoints.ItemsSource = _checkpoints;
|
||||
}
|
||||
|
||||
|
||||
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
/*
|
||||
var worldPath = Path.Combine("Instance", "Saves", WorldName.Text);
|
||||
var checkpointItem = (PremadeCheckpointItem)PremadeCheckpoints.SelectedItem;
|
||||
string worldName = string.IsNullOrEmpty(WorldName.Text) ? _currentItem.Name : WorldName.Text;
|
||||
var worldPath = Path.Combine("Instance", "Saves", worldName);
|
||||
var checkpoint= _currentItem.Checkpoint;
|
||||
if (Directory.Exists(worldPath))
|
||||
{
|
||||
MessageBox.Show("World already exists with that name.");
|
||||
return;
|
||||
}
|
||||
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 Name { get; set; }
|
||||
public string Icon { get; set; }
|
||||
public MyObjectBuilder_Checkpoint Checkpoint { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user