public async Task <GameTypeSelectionResult> SelectGameTypeAsync(GameTypeSelectionViewModel gameTypeSelectionViewModel, [CallerMemberName] string origin = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
        {
            RL.Logger?.LogTraceSource($"A game type selection dialog was opened", origin: origin, filePath: filePath, lineNumber: lineNumber);

            if (Application.Current.Dispatcher == null)
            {
                throw new Exception("The application does not have a valid dispatcher");
            }

            // Create the dialog and get the result
            var result = await Application.Current.Dispatcher.Invoke(() => new GameTypeSelectionDialog(gameTypeSelectionViewModel)).ShowDialogAsync();

            if (result == null)
            {
                RL.Logger?.LogTraceSource($"The game type selection dialog returned null");
            }
            else if (result.CanceledByUser)
            {
                RL.Logger?.LogTraceSource($"The game type selection dialog was canceled by the user");
            }
            else
            {
                RL.Logger?.LogTraceSource($"The game type selection dialog returned the selected type {result.SelectedType}");
            }

            // Return the result
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Gets a type for the game, or null if the operation was canceled
        /// </summary>
        /// <returns>The type or null if the operation was canceled</returns>
        public async Task <GameTypeSelectionResult> GetGameTypeAsync()
        {
            // Get the available types
            var types = RCPServices.App.GamesManager.GameManagers[Game].Keys.ToArray();

            // If only one type, return that
            if (types.Length == 1)
            {
                return new GameTypeSelectionResult()
                       {
                           CanceledByUser = false,
                           SelectedType   = types.First()
                       }
            }
            ;

            // Create the view model
            var vm = new GameTypeSelectionViewModel()
            {
                Title = Resources.App_SelectGameTypeHeader
            };

            // Enumerate the available types
            foreach (var type in types)
            {
                if (type == GameType.Win32)
                {
                    vm.AllowWin32 = true;
                }
                else if (type == GameType.Steam)
                {
                    vm.AllowSteam = true;
                }
                else if (type == GameType.WinStore)
                {
                    vm.AllowWinStore = true;
                }
                else if (type == GameType.DosBox)
                {
                    vm.AllowDosBox = true;
                }
                else if (type == GameType.EducationalDosBox)
                {
                    vm.AllowEducationalDosBox = true;
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }
            }

            // Create and show the dialog and return the result
            return(await RCPServices.UI.SelectGameTypeAsync(vm));
        }