示例#1
0
 public static void Navigate(object link)
 {
     if (FullscreenApplication.Current.Dialogs.ShowMessage(
             string.Format(ResourceProvider.GetString("LOCUrlNavigationMessage"), link.ToString()),
             string.Empty,
             MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         GlobalCommands.NavigateUrl(link);
     }
 }
示例#2
0
        public void InitializeItems()
        {
            // Have to load icons as late as possible to make sure ovewritten theme resources are loaded.
            if (!iconsLoaded)
            {
                startIcon      = MenuHelpers.GetIcon("PlayIcon");
                removeIcon     = MenuHelpers.GetIcon("RemoveGameIcon");
                linksIcon      = MenuHelpers.GetIcon("LinksIcon");
                favoriteIcon   = MenuHelpers.GetIcon("AddFavoritesIcon");
                unFavoriteIcon = MenuHelpers.GetIcon("RemoveFavoritesIcon");
                hideIcon       = MenuHelpers.GetIcon("HideIcon");
                unHideIcon     = MenuHelpers.GetIcon("UnHideIcon");
                browseIcon     = MenuHelpers.GetIcon("OpenFolderIcon");
                shortcutIcon   = MenuHelpers.GetIcon("DesktopShortcutIcon");
                installIcon    = MenuHelpers.GetIcon("InstallIcon");
                editIcon       = MenuHelpers.GetIcon("EditGameIcon");
                manualIcon     = MenuHelpers.GetIcon("ManualIcon");
                iconsLoaded    = true;
            }

            Items.Clear();

            if (Games?.Count == 0 && Game == null)
            {
                return;
            }

            if (Games != null)
            {
                // Create Desktop Shortcut
                var shortcutItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCCreateDesktopShortcut"),
                    Icon             = shortcutIcon,
                    Command          = model.CreateDesktopShortcutsCommand,
                    CommandParameter = Games
                };

                Items.Add(shortcutItem);

                // Set Favorites
                var favoriteItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCFavoriteGame"),
                    Icon             = favoriteIcon,
                    Command          = model.SetAsFavoritesCommand,
                    CommandParameter = Games
                };

                Items.Add(favoriteItem);

                var unFavoriteItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCRemoveFavoriteGame"),
                    Icon             = unFavoriteIcon,
                    Command          = model.RemoveAsFavoritesCommand,
                    CommandParameter = Games
                };

                Items.Add(unFavoriteItem);

                // Set Hide
                var hideItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCHideGame"),
                    Icon             = hideIcon,
                    Command          = model.SetAsHiddensCommand,
                    CommandParameter = Games
                };

                Items.Add(hideItem);

                var unHideItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCUnHideGame"),
                    Icon             = unHideIcon,
                    Command          = model.RemoveAsHiddensCommand,
                    CommandParameter = Games
                };

                Items.Add(unHideItem);

                // Edit
                var editItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCEditGame"),
                    Icon             = editIcon,
                    Command          = model.EditGamesCommand,
                    CommandParameter = Games,
                    InputGestureText = model.EditSelectedGamesCommand.GestureText
                };

                Items.Add(editItem);

                // Set Category
                var categoryItem = new MenuItem()
                {
                    Header = resources.GetString("LOCSetGameCategory"),
                    //Icon = Images.GetEmptyImage(),
                    Command          = model.AssignGamesCategoryCommand,
                    CommandParameter = Games
                };

                Items.Add(categoryItem);

                // Set Completion Status
                Items.Add(LoadCompletionStatusItem());

                // Extensions items
                AddExtensionItems();
                Items.Add(new Separator());

                // Remove
                var removeItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCRemoveGame"),
                    Icon             = removeIcon,
                    Command          = model.RemoveGamesCommand,
                    CommandParameter = Games,
                    InputGestureText = model.RemoveSelectedGamesCommand.GestureText
                };

                Items.Add(removeItem);
            }
            else if (Game != null)
            {
                // Play / Install
                if (ShowStartSection)
                {
                    bool added = false;
                    if (Game.IsInstalled)
                    {
                        var playItem = new MenuItem()
                        {
                            Header           = resources.GetString("LOCPlayGame"),
                            Icon             = startIcon,
                            FontWeight       = FontWeights.Bold,
                            Command          = model.StartGameCommand,
                            CommandParameter = Game,
                            InputGestureText = model.StartSelectedGameCommand.GestureText
                        };

                        Items.Add(playItem);
                        added = true;
                    }
                    else if (!Game.IsCustomGame)
                    {
                        var installItem = new MenuItem()
                        {
                            Header           = resources.GetString("LOCInstallGame"),
                            Icon             = installIcon,
                            FontWeight       = FontWeights.Bold,
                            Command          = model.InstallGameCommand,
                            CommandParameter = Game
                        };

                        Items.Add(installItem);
                        added = true;
                    }

                    if (added)
                    {
                        Items.Add(new Separator());
                    }
                }

                // Custom Actions
                var otherActions = Game.GameActions?.Where(a => !a.IsPlayAction).ToList();
                if (otherActions.HasItems())
                {
                    foreach (var task in otherActions)
                    {
                        var taskItem = new MenuItem()
                        {
                            Header = task.Name
                        };

                        taskItem.Click += (s, e) =>
                        {
                            model.GamesEditor.ActivateAction(Game, task);
                        };

                        Items.Add(taskItem);
                    }

                    Items.Add(new Separator());
                }

                // Links
                if (Game.Links?.Any() == true)
                {
                    var linksItem = new MenuItem()
                    {
                        Header = resources.GetString("LOCLinksLabel"),
                        Icon   = linksIcon
                    };

                    foreach (var link in Game.Links)
                    {
                        if (link != null)
                        {
                            linksItem.Items.Add(new MenuItem()
                            {
                                Header  = link.Name,
                                Command = new RelayCommand <Link>((_) =>
                                {
                                    try
                                    {
                                        GlobalCommands.NavigateUrl(Game.ExpandVariables(link.Url));
                                    }
                                    catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                                    {
                                        logger.Error(e, "Failed to open url.");
                                    }
                                })
                            });
                        }
                    }

                    Items.Add(linksItem);
                    Items.Add(new Separator());
                }

                // Open Game Location
                if (Game.IsInstalled)
                {
                    var locationItem = new MenuItem()
                    {
                        Header           = resources.GetString("LOCOpenGameLocation"),
                        Icon             = browseIcon,
                        Command          = model.OpenGameLocationCommand,
                        CommandParameter = Game
                    };

                    Items.Add(locationItem);
                }

                // Create Desktop Shortcut
                var shortcutItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCCreateDesktopShortcut"),
                    Icon             = shortcutIcon,
                    Command          = model.CreateDesktopShortcutCommand,
                    CommandParameter = Game
                };

                Items.Add(shortcutItem);

                // Manual
                if (!Game.Manual.IsNullOrEmpty())
                {
                    Items.Add(new MenuItem()
                    {
                        Header           = resources.GetString("LOCOpenGameManual"),
                        Icon             = manualIcon,
                        Command          = model.OpenManualCommand,
                        CommandParameter = Game
                    });
                }

                Items.Add(new Separator());

                // Toggle Favorites
                var favoriteItem = new MenuItem()
                {
                    Header           = Game.Favorite ? resources.GetString("LOCRemoveFavoriteGame") : resources.GetString("LOCFavoriteGame"),
                    Icon             = Game.Favorite ? unFavoriteIcon : favoriteIcon,
                    Command          = model.ToggleFavoritesCommand,
                    CommandParameter = Game
                };

                Items.Add(favoriteItem);

                // Toggle Hide
                var hideItem = new MenuItem()
                {
                    Header           = Game.Hidden ? resources.GetString("LOCUnHideGame") : resources.GetString("LOCHideGame"),
                    Icon             = Game.Hidden ? unHideIcon : hideIcon,
                    Command          = model.ToggleVisibilityCommand,
                    CommandParameter = Game
                };

                Items.Add(hideItem);

                // Edit
                var editItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCEditGame"),
                    Icon             = editIcon,
                    Command          = model.EditGameCommand,
                    CommandParameter = Game,
                    InputGestureText = model.EditSelectedGamesCommand.GestureText
                };

                Items.Add(editItem);

                // Set Category
                var categoryItem = new MenuItem()
                {
                    Header = resources.GetString("LOCSetGameCategory"),
                    //Icon = Images.GetEmptyImage(),
                    Command          = model.AssignGameCategoryCommand,
                    CommandParameter = Game
                };

                Items.Add(categoryItem);

                // Set Completion Status
                Items.Add(LoadCompletionStatusItem());

                // Extensions items
                AddExtensionItems();
                Items.Add(new Separator());

                // Remove
                var removeItem = new MenuItem()
                {
                    Header           = resources.GetString("LOCRemoveGame"),
                    Icon             = removeIcon,
                    Command          = model.RemoveGameCommand,
                    CommandParameter = Game,
                    InputGestureText = model.RemoveGameCommand.GestureText
                };

                Items.Add(removeItem);

                // Uninstall
                if (!Game.IsCustomGame && Game.IsInstalled)
                {
                    var uninstallItem = new MenuItem()
                    {
                        Header = resources.GetString("LOCUninstallGame"),
                        //Icon = Images.GetEmptyImage(),
                        Command          = model.UninstallGameCommand,
                        CommandParameter = Game
                    };

                    Items.Add(uninstallItem);
                }
            }
        }