- Move all Launcher components to LANCommander.Launcher.UI namespace - Move all SCSS files next to components (when possible) - Refactor styles that control overflow of content into titlebar to MainWindow only - Remove use in launcher UI of SDK.Client
173 lines
No EOL
5.2 KiB
Text
173 lines
No EOL
5.2 KiB
Text
@using LANCommander.Launcher.Data.Models
|
|
@using LANCommander.Launcher.Models
|
|
@using System.Diagnostics
|
|
@namespace LANCommander.Launcher.UI
|
|
@implements IDisposable
|
|
@inject GameService GameService
|
|
@inject LibraryService LibraryService
|
|
@inject GameClient GameClient
|
|
@inject LobbyClient LobbyClient
|
|
@inject ModalService ModalService
|
|
@inject MessageService MessageService
|
|
@inject LocalizationService LocalizationService
|
|
|
|
@if (State == PlayButtonState.Running)
|
|
{
|
|
<Popconfirm Title="@LocalizationService.GetString("DoYouWantToStopGame")" OkText="@LocalizationService.GetString("Yes")" OnConfirm="() => Stop()">
|
|
<Button Type="ButtonType.Primary" Size="ButtonSize.Large" Icon="@IconType.Outline.CaretRight">@LocalizationService.GetString("Running")</Button>
|
|
</Popconfirm>
|
|
}
|
|
else if (State == PlayButtonState.Starting)
|
|
{
|
|
<Button Type="ButtonType.Primary" Size="ButtonSize.Large" Loading="true">@LocalizationService.GetString("Starting")</Button>
|
|
}
|
|
else if (State == PlayButtonState.Stopping)
|
|
{
|
|
<Button Type="ButtonType.Primary" Size="ButtonSize.Large" Loading="true">@LocalizationService.GetString("Stopping")</Button>
|
|
}
|
|
else
|
|
{
|
|
<Space Direction="SpaceDirection.Horizontal">
|
|
<SpaceItem>
|
|
<Button Type="ButtonType.Primary" Size="ButtonSize.Large" Icon="@IconType.Outline.CaretRight" OnClick="() => Run()">@LocalizationService.GetString("Play")</Button>
|
|
</SpaceItem>
|
|
|
|
<SpaceItem>
|
|
<Dropdown>
|
|
<Overlay>
|
|
<Menu>
|
|
<LibraryItemContextMenu Model="LibraryItem" MenuExtra="MenuExtra" />
|
|
</Menu>
|
|
</Overlay>
|
|
|
|
<ChildContent>
|
|
<Button Type="@ButtonType.Default" Size="ButtonSize.Large" Icon="@IconType.Outline.Ellipsis" />
|
|
</ChildContent>
|
|
</Dropdown>
|
|
</SpaceItem>
|
|
</Space>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public required Guid LibraryItemId { get; set; }
|
|
[Parameter] public required Models.ListItem LibraryItem { get; set; }
|
|
[Parameter] public required RenderFragment MenuExtra { get; set; }
|
|
|
|
Timer? StateTimer;
|
|
PlayButtonState State = PlayButtonState.Idle;
|
|
|
|
public enum PlayButtonState
|
|
{
|
|
Idle,
|
|
Starting,
|
|
Running,
|
|
Stopping
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
StateTimer = new Timer(state => { InvokeAsync(UpdateState); }, null, 0, 250);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (LibraryItem == null && LibraryItemId != Guid.Empty)
|
|
LibraryItem = await LibraryService.GetItemAsync(LibraryItemId);
|
|
}
|
|
|
|
async Task UpdateState()
|
|
{
|
|
if (GameClient.IsRunning(LibraryItem.Key))
|
|
{
|
|
await ChangeState(PlayButtonState.Running);
|
|
}
|
|
else if (State == PlayButtonState.Running && !GameClient.IsRunning(LibraryItem.Key))
|
|
{
|
|
await ChangeState(PlayButtonState.Idle);
|
|
}
|
|
}
|
|
|
|
async Task ChangeState(PlayButtonState state)
|
|
{
|
|
State = state;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task Run()
|
|
{
|
|
var game = (Game)LibraryItem.DataItem;
|
|
|
|
var actions = await GameClient.GetActionsAsync(game.InstallDirectory, game.Id);
|
|
|
|
await ChangeState(PlayButtonState.Starting);
|
|
|
|
if (actions == null || actions.Count() == 0)
|
|
{
|
|
MessageService.Error(LocalizationService.GetString("NoActionsFound"));
|
|
|
|
await ChangeState(PlayButtonState.Idle);
|
|
return;
|
|
}
|
|
|
|
var primaryActions = actions.Where(a => a.IsPrimaryAction && LibraryService.IsInstalled(game.Id));
|
|
|
|
if (primaryActions.Count() == 0)
|
|
{
|
|
MessageService.Error(LocalizationService.GetString("NoPrimaryActionFound"));
|
|
|
|
await ChangeState(PlayButtonState.Idle);
|
|
return;
|
|
}
|
|
|
|
if (primaryActions.Count() == 1)
|
|
{
|
|
var task = GameService.Run(game, primaryActions.First());
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
await task;
|
|
}
|
|
else
|
|
{
|
|
var modalOptions = new ModalOptions()
|
|
{
|
|
Title = LocalizationService.GetString("PlayGame", game.Title),
|
|
Maximizable = false,
|
|
DefaultMaximized = false,
|
|
Closable = true,
|
|
MaskClosable = true,
|
|
Footer = null,
|
|
Centered = true,
|
|
WrapClassName = "game-actions-dialog",
|
|
AfterClose = async () =>
|
|
{
|
|
LobbyClient.ReleaseSteam();
|
|
|
|
await ChangeState(PlayButtonState.Idle);
|
|
}
|
|
};
|
|
|
|
var model = new ActionSelectorDialogOptions
|
|
{
|
|
Actions = actions.Where(a => a.IsPrimaryAction),
|
|
Game = game
|
|
};
|
|
|
|
var modalRef = ModalService.CreateModal<ActionSelectorDialog, ActionSelectorDialogOptions, Process>(modalOptions, model);
|
|
}
|
|
}
|
|
|
|
async Task Stop()
|
|
{
|
|
await ChangeState(PlayButtonState.Stopping);
|
|
|
|
await GameClient.Stop(LibraryItem.Key);
|
|
|
|
await ChangeState(PlayButtonState.Idle);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
StateTimer?.Dispose();
|
|
}
|
|
} |