Skip to content

Commit 2f4b005

Browse files
committed
Re-design of world selector UI and code tidy up for loading premade world data
1 parent c5f2ee2 commit 2f4b005

2 files changed

Lines changed: 31 additions & 55 deletions

File tree

‎Torch.Server/Views/WorldGeneratorDialog.xaml‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,16 @@
77
xmlns:views="clr-namespace:Torch.Server.Views"
88
xmlns:views1="clr-namespace:Torch.Views;assembly=Torch"
99
mc:Ignorable="d"
10-
Title="WorldGeneratorDialog" Height="500" Width="700">
10+
Title="Premade world selection" Height="500" Width="700">
1111
<Grid>
1212
<Grid.ColumnDefinitions>
13-
<ColumnDefinition Width="250"/>
14-
<ColumnDefinition Width="*"/>
13+
<ColumnDefinition Width="235"/>
14+
<ColumnDefinition/>
1515
</Grid.ColumnDefinitions>
16-
<ListView Grid.Column="0" x:Name="PremadeCheckpoints" ScrollViewer.CanContentScroll="False" HorizontalContentAlignment="Center" Margin="3" SelectionChanged="PremadeCheckpoints_SelectionChanged">
17-
<ListView.ItemTemplate>
18-
<DataTemplate DataType="local:PremadeCheckpointItem">
19-
<StackPanel HorizontalAlignment="Center">
20-
<Label Content="{Binding Name}" HorizontalAlignment="Center"/>
21-
<Image Stretch="Uniform" MaxHeight="100" HorizontalAlignment="Center">
22-
<Image.Source>
23-
<BitmapImage UriSource="{Binding Icon}"/>
24-
</Image.Source>
25-
</Image>
26-
</StackPanel>
27-
</DataTemplate>
28-
</ListView.ItemTemplate>
29-
</ListView>
30-
<Grid Grid.Column="1" Margin="3">
16+
<ListBox x:Name="PremadeCheckpoints" SelectionChanged="PremadeCheckpoints_SelectionChanged" d:ItemsSource="{d:SampleData ItemCount=20}" Margin="0,0,0,180"/>
17+
<Image Grid.Column="0" x:Name="CheckpointImage" Stretch="Uniform" Margin="2,0,1,44" Width="232" Height="136" VerticalAlignment="Bottom"/>
18+
19+
<Grid Grid.Column="1" Margin="3,3,3,3">
3120
<Grid.RowDefinitions>
3221
<RowDefinition Height ="Auto"/>
3322
<RowDefinition Height ="*"/>

‎Torch.Server/Views/WorldGeneratorDialog.xaml.cs‎

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public partial class WorldGeneratorDialog : Window
3434
{
3535
private InstanceManager _instanceManager;
3636
private List<PremadeCheckpointItem> _checkpoints = new List<PremadeCheckpointItem>();
37+
private List<string> _worldNames = new List<string>();
3738
private PremadeCheckpointItem _currentItem;
3839

3940
[ReflectedStaticMethod(Type = typeof(ConfigForm), Name = "LoadLocalization")]
@@ -67,7 +68,12 @@ public WorldGeneratorDialog(InstanceManager instanceManager)
6768
});
6869
}
6970

70-
PremadeCheckpoints.ItemsSource = _checkpoints;
71+
foreach (var checkpoint in _checkpoints)
72+
{
73+
_worldNames.Add(checkpoint.Name);
74+
}
75+
76+
PremadeCheckpoints.ItemsSource = _worldNames;
7177
}
7278

7379
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
@@ -102,55 +108,36 @@ private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
102108

103109
private void PremadeCheckpoints_SelectionChanged(object sender, SelectionChangedEventArgs e)
104110
{
105-
var selected = (PremadeCheckpointItem)PremadeCheckpoints.SelectedItem;
111+
var selected = _checkpoints.FirstOrDefault(x => x.Name == PremadeCheckpoints.SelectedItem.ToString());
106112
_currentItem = selected;
113+
if (_currentItem == null) return;
107114
SettingsView.DataContext = new SessionSettingsViewModel(_currentItem.Checkpoint.Settings);
115+
CheckpointImage.Source = new BitmapImage(new Uri(_currentItem.Icon));
108116
}
109117

110118
private void GetWorldInfo(string savesPath, List<Tuple<string, MyWorldInfo>> result)
111119
{
112120
foreach (var saveDir in Directory.GetDirectories(savesPath, "*", SearchOption.TopDirectoryOnly))
113121
{
114-
bool newScenario = Directory.GetFiles(saveDir, "*.scf", SearchOption.TopDirectoryOnly).Length == 1;
115-
116-
if (newScenario)
122+
bool isCompatible;
123+
string platformSessionPath = null;
124+
125+
platformSessionPath = MyLocalCache.GetSessionPathFromScenario(saveDir, false, out isCompatible);
126+
if (platformSessionPath != null && isCompatible)
117127
{
118-
bool isCompatible;
119-
string platformSessionPath = null;
120-
121-
122-
if (!Sandbox.Game.MyPlatformGameSettings.CONSOLE_COMPATIBLE)
123-
{
124-
platformSessionPath = MyLocalCache.GetSessionPathFromScenario(saveDir, false, out isCompatible);
125-
if (platformSessionPath != null && isCompatible)
126-
{
127-
AddWorldInfo(result, platformSessionPath, saveDir, " [PC]");
128-
}
129-
}
130-
131-
string xboxPlatformSessionPath = MyLocalCache.GetSessionPathFromScenario(saveDir, true, out isCompatible);
132-
if (xboxPlatformSessionPath != null && isCompatible)
133-
{
134-
AddWorldInfo(result, xboxPlatformSessionPath, saveDir, " [XBOX]");
135-
}
136-
137-
if (platformSessionPath == null && xboxPlatformSessionPath == null && isCompatible)
138-
{
139-
AddWorldInfo(result, saveDir, saveDir, "");
140-
}
128+
AddWorldInfo(result, platformSessionPath, saveDir, " [PC]");
141129
}
142-
else
130+
131+
string xboxPlatformSessionPath = MyLocalCache.GetSessionPathFromScenario(saveDir, true, out isCompatible);
132+
if (xboxPlatformSessionPath != null && isCompatible)
143133
{
144-
foreach (var file in Directory.GetFiles(saveDir, MyLocalCache.CHECKPOINT_FILE, SearchOption.AllDirectories))
145-
{
146-
var checkpointDir = Path.GetDirectoryName(file);
147-
if (checkpointDir.ToLower().Contains("backup"))
148-
continue;
149-
150-
AddWorldInfo(result, file, saveDir, "");
151-
}
134+
AddWorldInfo(result, xboxPlatformSessionPath, saveDir, " [XBOX]");
152135
}
153136

137+
if (platformSessionPath == null && xboxPlatformSessionPath == null && isCompatible)
138+
{
139+
AddWorldInfo(result, saveDir, saveDir, "");
140+
}
154141
}
155142
}
156143

0 commit comments

Comments
 (0)