JD2022-TU1/main/tools/modules/JD.Guinness.WPF.Module/GuinnessModule.cs

164 lines
6.6 KiB
C#

using System;
using System.Windows;
using System.Windows.Input;
using JD.GoogleAchievement.Service;
using JD.Guinness.WPF.Module.Configuration;
using JD.Guinness.WPF.Module.PlumeAction;
using JD.Guinness.WPF.Module.View;
using JD.Guinness.WPF.Module.ViewModel;
using JD.MicrosoftAchievement.Service;
using JD.Oasis.Service.API;
using JD.Oasis.Service.Implementation;
using JD.SonyTrophy.Service;
using Plume.Icons;
using Plume.Interfaces.Modules;
using Plume.Interfaces.WPF.Actions;
using Plume.Interfaces.WPF.Dialogs;
using Plume.Interfaces.WPF.Menu;
using Plume.Interfaces.WPF.Modules;
using Plume.Interfaces.WPF.Window;
using Plume.Perforce.Service.Api;
namespace JD.Guinness.WPF.Module
{
public class GuinnessModule : IWpfModule
{
private GameViewModel _gameViewModel;
private Tuple<string, string> AskLoginCredentials(Plume.Interfaces.WPF.Dialog.IDialogManager dialogManager)
{
DialogButton result = dialogManager.ShowLoginBox(
"Login to Oasis Web Service",
"Please use your Ubisoft credentials to login into Oasis Web Service",
out string userName, out string password);
return result?.StandardButton == StandardButton.Ok ? Tuple.Create(userName, password) : null;
}
#region IWpfModule
public void Initialize(IWpfModuleContext context)
{
context.SettingsManager.Register<GuinnessSettings>("Guinness Settings");
IOasisService oasisService = context.GetService<IOasisService>();
oasisService.SetCredentialsManager(new CredentialsManager(() => AskLoginCredentials(context.DialogManager)));
_gameViewModel = new GameViewModel(
context.GetService<IPerforceService>(),
oasisService,
context.SettingsManager,
context.StatusBarManager,
context.NotificationManager,
context.Logger,
new ItemFocuser());
context.WindowManager.AddToolWindow(
"Guinness.Languages",
"Languages",
StandardIcon.TextFile,
new LanguageView(_gameViewModel),
DockingSide.Right,
new KeyGesture(Key.L, ModifierKeys.Control));
context.WindowManager.AddToolWindow(
"Guinness.Challenges",
"Challenges",
StandardIcon.TextFile,
new ChallengeView(new ChallengeViewModel(_gameViewModel)),
DockingSide.Top,
new KeyGesture(Key.C, ModifierKeys.Control));
context.WindowManager.AddToolWindow(
"Guinness.Ps4",
"PS4",
StandardIcon.TextFile,
new Ps4View(new Ps4ViewModel(_gameViewModel, context.GetService<ISonyTrophyService>())),
DockingSide.Top,
new KeyGesture(Key.P, ModifierKeys.Control));
context.WindowManager.AddToolWindow(
"Guinness.Ps5",
"PS5",
StandardIcon.TextFile,
new Ps5View(new Ps5ViewModel(_gameViewModel, context.GetService<ISonyTrophyService>())),
DockingSide.Top,
new KeyGesture(Key.P, ModifierKeys.Control));
context.WindowManager.AddToolWindow(
"Guinness.XBoxOne",
"XBOX ONE",
StandardIcon.TextFile,
new XBoxOneView(new XBoxOneViewModel(_gameViewModel, context.GetService<IMicrosoftAchievementService>())),
DockingSide.Top,
new KeyGesture(Key.X, ModifierKeys.Control));
context.WindowManager.AddToolWindow(
"Guinness.XBoxSeriesX",
"XBOX SERIES X",
StandardIcon.TextFile,
new XBoxSeriesXView(new XBoxSeriesXViewModel(_gameViewModel, context.GetService<IMicrosoftAchievementService>())),
DockingSide.Top,
new KeyGesture(Key.X, ModifierKeys.Control));
context.WindowManager.AddToolWindow(
"Guinness.Stadia",
"Stadia",
StandardIcon.TextFile,
new StadiaView(new StadiaViewModel(_gameViewModel, context.GetService<IGoogleAchievementService>())),
DockingSide.Top,
new KeyGesture(Key.S, ModifierKeys.Control));
context.WindowManager.AddToolWindow(
"Guinness.Warnings",
"Warnings",
StandardIcon.TextFile,
new WarningView(new WarningViewModel(_gameViewModel)),
DockingSide.Bottom,
new KeyGesture(Key.W, ModifierKeys.Control));
context.ActionManager.Register(() => new SetWorkspaceAction(_gameViewModel));
context.ToolBarManager.AddTextButton("Guinness", context.ActionManager.Get<SetWorkspaceAction>());
context.ActionManager.Register(() => new LoadOasisDataAction(_gameViewModel));
context.ToolBarManager.AddTextButton("Guinness", context.ActionManager.Get<LoadOasisDataAction>());
context.ActionManager.Register(() => new RefreshResourcesAction(_gameViewModel, context.GetService<IPerforceService>()));
context.ToolBarManager.AddTextButton("Guinness", context.ActionManager.Get<RefreshResourcesAction>());
context.ActionManager.Register(() => new SaveAction(_gameViewModel));
context.MenuManager.AddMenuItem(MenuPath.FileMenu, context.ActionManager.Get<SaveAction>(), _ => 0);
context.ActionManager.Register(() => new SubmitAction(_gameViewModel, context.GetService<IPerforceService>()));
context.MenuManager.AddMenuItem(MenuPath.FileMenu, context.ActionManager.Get<SubmitAction>(), _ => 1);
_gameViewModel
.SetWorkspaceCommand.ExecuteAsync(false)
.ContinueWith(async _ =>
{
if (!_gameViewModel.HasWorkspace)
{
context.Logger.Info("No workspace has been selected, Guinness will exit");
Application.Current.Dispatcher.Invoke(() => context.ActionManager.Get(StandardAction.Exit).Command.Execute(null));
}
await _gameViewModel.LoadOasisDataCommand.ExecuteAsync().ConfigureAwait(true);
});
}
#endregion
#region IModule
public void Setup(IModuleSetup setup)
{ }
#endregion
#region IDisposable
public void Dispose() => _gameViewModel.SaveCommand.Execute(true);
#endregion
}
}