mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Launcher page can launch games
This commit is contained in:
parent
f7a9be2d7e
commit
c345451d6c
@ -2,14 +2,36 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:controls="clr-namespace:Wabbajack.App.Controls"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Wabbajack.App.Screens.LauncherView">
|
||||
<Grid RowDefinitions="40, *, Auto">
|
||||
<TextBlock Grid.Row="0" x:Name="StatusText" FontSize="20" FontWeight="Bold"></TextBlock>
|
||||
<Viewbox Grid.Row="1" HorizontalAlignment="Center"
|
||||
<Grid RowDefinitions="*, Auto">
|
||||
<Viewbox Grid.Row="0"
|
||||
Name="Banner"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform">
|
||||
<Image x:Name="SlideImage"></Image>
|
||||
Stretch="UniformToFill">
|
||||
<Image x:Name="ModListImage" Margin="0,0,0,0" Source="../Assets/Wabba_Mouth.png" />
|
||||
</Viewbox>
|
||||
<Grid Grid.Row="0" RowDefinitions="40, 40" HorizontalAlignment="Left" VerticalAlignment="Bottom">
|
||||
<TextBlock x:Name="ModListName"></TextBlock>
|
||||
</Grid>
|
||||
<Grid Margin="40" RowDefinitions="40, 40, 40, *" ColumnDefinitions="100, *, 200" Grid.Row="1">
|
||||
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center">ModList:</Label>
|
||||
<TextBox Grid.Column="1" Grid.Row="0" IsEnabled="False" Height="20" x:Name="ModList"></TextBox>
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center">Location:</Label>
|
||||
<TextBox Grid.Column="1" Grid.Row="1" IsEnabled="False" Height="20" x:Name="InstallPath"></TextBox>
|
||||
|
||||
<Grid Grid.Column="1" Grid.Row="3" Grid.ColumnDefinitions="*, *, *" HorizontalAlignment="Center">
|
||||
<Button Grid.Column="0" x:Name="WebsiteButton">Website</Button>
|
||||
<Button Grid.Column="1" x:Name="ReadmeButton">Readme</Button>
|
||||
<Button Grid.Column="2" x:Name="LocalFilesButton">Local Files</Button>
|
||||
</Grid>
|
||||
|
||||
<controls:LargeIconButton x:Name="PlayGame" Margin="40, 0, 0, 0" Grid.Row="0" Grid.Column="2" Grid.RowSpan="4" Icon="PlayCircle" Text="Play">
|
||||
|
||||
</controls:LargeIconButton>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
@ -14,9 +14,10 @@ namespace Wabbajack.App.Screens
|
||||
InitializeComponent();
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
this.OneWayBind(ViewModel, vm => vm.Image, view => view.SlideImage.Source)
|
||||
this.OneWayBind(ViewModel, vm => vm.Image, view => view.ModListImage.Source)
|
||||
.DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.Title, view => view.StatusText.Text)
|
||||
|
||||
this.BindCommand(ViewModel, vm => vm.PlayButton, view => view.PlayGame.Button)
|
||||
.DisposeWith(disposables);
|
||||
});
|
||||
}
|
||||
|
@ -1,14 +1,24 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Media.Imaging;
|
||||
using GameFinder.StoreHandlers.Origin.DTO;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.App.Extensions;
|
||||
using Wabbajack.App.Messages;
|
||||
using Wabbajack.App.Models;
|
||||
using Wabbajack.App.ViewModels;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.DTOs;
|
||||
using Wabbajack.DTOs.SavedSettings;
|
||||
using Wabbajack.Paths;
|
||||
using Wabbajack.Paths.IO;
|
||||
|
||||
namespace Wabbajack.App.Screens
|
||||
{
|
||||
@ -26,9 +36,17 @@ namespace Wabbajack.App.Screens
|
||||
[Reactive]
|
||||
public string Title { get; set; }
|
||||
|
||||
public LauncherViewModel(InstallationStateManager manager)
|
||||
public ReactiveCommand<Unit, Unit> PlayButton;
|
||||
private readonly ILogger<LauncherViewModel> _logger;
|
||||
|
||||
public LauncherViewModel(ILogger<LauncherViewModel> logger, InstallationStateManager manager)
|
||||
{
|
||||
Activator = new ViewModelActivator();
|
||||
PlayButton = ReactiveCommand.Create(() =>
|
||||
{
|
||||
StartGame().FireAndForget();
|
||||
});
|
||||
_logger = logger;
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
@ -54,6 +72,27 @@ namespace Wabbajack.App.Screens
|
||||
});
|
||||
}
|
||||
|
||||
private async Task StartGame()
|
||||
{
|
||||
var mo2Path = InstallFolder.Combine("ModOrganizer.exe");
|
||||
var gamePath = GameRegistry.Games.Values.Select(g => g.MainExecutable)
|
||||
.Where(ge => ge != null)
|
||||
.Select(ge => InstallFolder.Combine(ge!))
|
||||
.FirstOrDefault(ge => ge.FileExists());
|
||||
if (mo2Path.FileExists())
|
||||
{
|
||||
Process.Start(mo2Path.ToString());
|
||||
}
|
||||
else if (gamePath.FileExists())
|
||||
{
|
||||
Process.Start(gamePath.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogError("No way to launch game, no acceptable executable found");
|
||||
}
|
||||
}
|
||||
|
||||
public void Receive(ConfigureLauncher val)
|
||||
{
|
||||
InstallFolder = val.InstallFolder;
|
||||
|
Loading…
Reference in New Issue
Block a user