Skip to content

Commit

Permalink
Add notice + explanation when xbox files are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
tylercamp committed Apr 28, 2024
1 parent 39ce071 commit b972454
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
8 changes: 7 additions & 1 deletion PalCalc.SaveReader/ISavesLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace PalCalc.SaveReader
public interface ISavesLocation
{
public string FolderPath { get; }
public string FolderName => Path.GetFileName(FolderPath);
public string FolderName => FolderPath == null ? "None" : Path.GetFileName(FolderPath);

public IEnumerable<ISaveGame> AllSaveGames { get; }
public IEnumerable<ISaveGame> ValidSaveGames => AllSaveGames.Where(g => g.IsValid);
Expand Down Expand Up @@ -197,6 +197,12 @@ private XboxSavesLocation(string userFolderPath, List<XboxSaveGame> saves)
}
}

public XboxSavesLocation()
{
AllSaveGames = new List<ISaveGame>();
FolderPath = null;
}

public string FolderPath { get; }

public IEnumerable<ISaveGame> AllSaveGames { get; }
Expand Down
8 changes: 6 additions & 2 deletions PalCalc.UI/View/SaveSelectorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:local="clr-namespace:PalCalc.UI.View"
mc:Ignorable="d"
d:Background="White"
d:DataContext="{d:DesignInstance vm:SaveSelectorViewModel, IsDesignTimeCreatable=True}">
d:DataContext="{d:DesignInstance vm:SaveSelectorViewModel, IsDesignTimeCreatable=True}" d:DesignWidth="436.57">
<Label Content="Saves Location" />
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -47,10 +47,14 @@
</ItemsControl.ItemTemplate>
</ComboBox>

<Button Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Stretch" Click="SaveGameFolder_Click" ToolTipService.ToolTip="Open in Explorer">
<Button Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Stretch" Click="SaveGameFolder_Click" IsEnabled="{Binding CanOpenSaveFileLocation}" ToolTipService.ToolTip="Open in Explorer">
<Image Source="{x:Static m:InternalIcons.FolderIcon}" Width="20" Height="15" />
</Button>
</Grid>

<TextBlock Visibility="{Binding NoXboxSavesMsgVisibility}" Margin="5,5,5,5" TextWrapping="Wrap" FontStyle="Italic">
No Xbox saves were found. Palworld must be installed on the PC through the Xbox app. Save files are synced to your PC when you run the game.
</TextBlock>

<TextBlock Visibility="{Binding InvalidSaveMessageVisibility}" Margin="0,5,0,0" Text="The selected save file is invalid!" Foreground="DarkRed" />
</StackPanel>
16 changes: 14 additions & 2 deletions PalCalc.UI/ViewModel/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@ public MainWindowViewModel(Dispatcher dispatcher)
};

PalTargetList = new PalTargetListViewModel();
SaveSelection = new SaveSelectorViewModel(DirectSavesLocation.AllLocal.Cast<ISavesLocation>().Concat(XboxSavesLocation.FindAll().Cast<ISavesLocation>()).ToList(), settings.ExtraSaveLocations.Select(saveFolder => new StandardSaveGame(saveFolder)));

var availableSavesLocations = new List<ISavesLocation>();
availableSavesLocations.AddRange(DirectSavesLocation.AllLocal);

var xboxSaves = XboxSavesLocation.FindAll();
if (xboxSaves.Count > 0) availableSavesLocations.AddRange(xboxSaves);
else
{
// add a placeholder so the user can (optionally) see the explanation why no saves are available (game isn't installed/synced via xbox app)
availableSavesLocations.Add(new XboxSavesLocation());
}

SaveSelection = new SaveSelectorViewModel(availableSavesLocations, settings.ExtraSaveLocations.Select(saveFolder => new StandardSaveGame(saveFolder)));

targetsBySaveFile = SaveSelection.SavesLocations
.SelectMany(l => l.SaveGames)
Expand Down Expand Up @@ -241,7 +253,7 @@ private void PalTargetList_PropertyChanged(object sender, PropertyChangedEventAr

public void RunSolver()
{
var currentSpec = PalTarget.CurrentPalSpecifier.ModelObject;
var currentSpec = PalTarget?.CurrentPalSpecifier?.ModelObject;
if (currentSpec == null) return;

var cachedData = SaveSelection.SelectedGame.CachedValue;
Expand Down
10 changes: 9 additions & 1 deletion PalCalc.UI/ViewModel/Mapped/SavesLocationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ public StandardSavesLocationViewModel(ISavesLocation sl)

var saveType = sl is XboxSavesLocation ? "Xbox" : "Steam";

Label = $"{saveType} user {sl.FolderName.LimitLength(12)} - {sl.ValidSaveGames.Count()} valid saves";
if (sl.FolderPath == null)
{
Label = saveType;
}
else
{
Label = $"{saveType} user {sl.FolderName.LimitLength(12)} - {sl.ValidSaveGames.Count()} valid saves";
}

SaveGames = new ReadOnlyObservableCollection<SaveGameViewModel>(
new ObservableCollection<SaveGameViewModel>(sl.ValidSaveGames.Select(sg => new SaveGameViewModel(sg)))
);
Expand Down
16 changes: 5 additions & 11 deletions PalCalc.UI/ViewModel/SaveSelectorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public ISavesLocationViewModel SelectedLocation
if (SetProperty(ref selectedLocation, value))
{
OnPropertyChanged(nameof(CanOpenSavesLocation));
OnPropertyChanged(nameof(NoXboxSavesMsgVisibility));
OnPropertyChanged(nameof(AvailableSaves));
SelectedGame = MostRecentSave;
}
Expand Down Expand Up @@ -107,7 +108,10 @@ public SaveSelectorViewModel() : this(DirectSavesLocation.AllLocal, Enumerable.E
{
}

public bool CanOpenSavesLocation => SelectedLocation is not ManualSavesLocationViewModel;
public bool CanOpenSavesLocation => (SelectedLocation as StandardSavesLocationViewModel)?.Value?.FolderPath != null;
public bool CanOpenSaveFileLocation => (SelectedLocation as SaveGameViewModel)?.Value?.BasePath != null;

public Visibility NoXboxSavesMsgVisibility => (SelectedLocation as StandardSavesLocationViewModel)?.Value is XboxSavesLocation && !SelectedLocation.SaveGames.Any() ? Visibility.Visible : Visibility.Collapsed;

public SaveSelectorViewModel(IEnumerable<ISavesLocation> savesLocations, IEnumerable<ISaveGame> manualSaves)
{
Expand All @@ -118,15 +122,5 @@ public SaveSelectorViewModel(IEnumerable<ISavesLocation> savesLocations, IEnumer

SelectedLocation = MostRecentLocation;
}

public void OpenSelectedSavesLocation()
{

}

public void OpenSelectedGameLocation()
{

}
}
}

0 comments on commit b972454

Please sign in to comment.