コード例 #1
0
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            Game GameMenu = args.Games.First();

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>
            {
                // Show plugin view with all activities for all game in database with data of selected game
                new GameMenuItem {
                    //MenuSection = "",
                    Icon        = Path.Combine(pluginFolder, "icon.png"),
                    Description = resources.GetString("LOCGameActivityViewGameActivity"),
                    Action      = (gameMenuItem) =>
                    {
                        DatabaseReference = PlayniteApi.Database;
                        var    ViewExtension   = new GameActivityView(settings, PlayniteApi, this.GetPluginUserDataPath(), GameMenu);
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCGameActivity"), ViewExtension);
                        windowExtension.ShowDialog();
                    }
                }
            };

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCGameActivity"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(gameMenuItems);
        }
コード例 #2
0
        public override IEnumerable <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            var menuSection = ResourceProvider.GetString("LOCGame_Sizes_Calculator_MenuSectionDescriptionGameSizesCalculator");

            return(new List <GameMenuItem>
            {
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCGame_Sizes_Calculator_MenuItemDescriptionCalculateSizesSelGames"),
                    MenuSection = menuSection,
                    Action = a =>
                    {
                        UpdateGamesListSizes(args.Games.Distinct().ToList(), false);
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCGame_Sizes_Calculator_MenuItemDescriptinoCalculateSizesSelGamesForce"),
                    MenuSection = menuSection,
                    Action = a =>
                    {
                        UpdateGamesListSizes(args.Games.Distinct().ToList(), true);
                    }
                }
            });
        }
コード例 #3
0
 public override List <ScriptGameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
 {
     if (SupportedMenus.Contains(SupportedMenuMethods.GameMenu))
     {
         var res = InvokeFunction(nameof(Plugin.GetGameMenuItems), new List <object> {
             args
         });
         if (res is ScriptGameMenuItem item)
         {
             return(new List <ScriptGameMenuItem> {
                 item
             });
         }
         else if (res is List <object> items)
         {
             return(items.Cast <ScriptGameMenuItem>().ToList());
         }
         else
         {
             return(base.GetGameMenuItems(args));
         }
     }
     else
     {
         return(base.GetGameMenuItems(args));
     }
 }
コード例 #4
0
        // Add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            Game GameMenu = args.Games.First();

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>
            {
                // Show list available localizations for the selected game
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCCheckLocalizations"),
                    Description = resources.GetString("LOCCheckLocalizationsGameMenuPluginView"),
                    Action      = (gameMenuItem) =>
                    {
                        var    ViewExtension   = new CheckLocalizationsView();
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, "CheckLocalizations", ViewExtension);
                        windowExtension.ShowDialog();
                    }
                },

                // Delete & download localizations data for the selected game
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCCheckLocalizations"),
                    Description = resources.GetString("LOCCommonRefreshGameData"),
                    Action      = (gameMenuItem) =>
                    {
                        PluginDatabase.GameSelectedData = new GameLocalizations();
                        var TaskIntegrationUI = Task.Run(() =>
                        {
                            PluginDatabase.RemoveWithManual(GameMenu.Id);
                            checkLocalizationsUI.RefreshElements(GameMenu);
                        });
                    }
                },

                // Open editor view to add a new supported language for the selected game
                new GameMenuItem
                {
                    MenuSection = resources.GetString("LOCCheckLocalizations"),
                    Description = resources.GetString("LOCCheckLocalizationsGameMenuAddLanguage"),
                    Action      = (mainMenuItem) =>
                    {
                        var    ViewExtension   = new CheckLocalizationsEditManual();
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, "CheckLocalizations", ViewExtension);
                        windowExtension.ShowDialog();
                    }
                }
            };

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCCheckLocalizations"),
                Description = "Test",
                Action      = (mainMenuItem) =>
                {
                }
            });
#endif

            return(gameMenuItems);
        }
コード例 #5
0
        public override IEnumerable <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            yield return(new GameMenuItem
            {
                Description = "test plugin root test"
            });

            yield return(new GameMenuItem
            {
                Description = "window test",
                MenuSection = "test plugin"
            });

            yield return(new GameMenuItem
            {
                Description = "-",
                MenuSection = "test plugin"
            });

            yield return(new GameMenuItem
            {
                Description = "serialization test",
                MenuSection = "test plugin"
            });
        }
コード例 #6
0
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            Game GameMenu = args.Games.First();

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>
            {
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCHowLongToBeat"),
                    Description = resources.GetString("LOCHowLongToBeatPluginView"),
                    Action      = (gameMenuItem) =>
                    {
                        try
                        {
                            GameHowLongToBeat gameHowLongToBeat = PluginDatabase.Get(GameMenu);

                            if (gameHowLongToBeat.HasData)
                            {
                                var    ViewExtension   = new HowLongToBeatView(PlayniteApi, settings, gameHowLongToBeat);
                                Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, "HowLongToBeat", ViewExtension);
                                windowExtension.ShowDialog();

                                var TaskIntegrationUI = Task.Run(() =>
                                {
                                    howLongToBeatUI.RefreshElements(HowLongToBeatDatabase.GameSelected);
                                });
                            }
                        }
                        catch (Exception ex)
                        {
                            Common.LogError(ex, "HowLongToBeat", $"Error to load game data for {args.Games.First().Name}");
                            PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "HowLongToBeat");
                        }
                    }
                },
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCHowLongToBeat"),
                    Description = resources.GetString("LOCCommonDeleteGameData"),
                    Action      = (gameMenuItem) =>
                    {
                        PluginDatabase.Remove(GameMenu.Id);
                        howLongToBeatUI.RefreshElements(HowLongToBeatDatabase.GameSelected);
                    }
                }
            };

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCHowLongToBeat"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(gameMenuItems);
        }
コード例 #7
0
        // To add new game menu items override GetGameMenuItems
        public override IEnumerable <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            var GameMenu = args.Games.First();

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>();

            if (PluginSettings.Settings.EnableBackgroundImage)
            {
                gameMenuItems.Add(new GameMenuItem
                {
                    // Manage game background
                    MenuSection = resources.GetString("LOCBc"),
                    Description = resources.GetString("LOCBcManageBackground"),
                    Action      = (gameMenuItem) =>
                    {
                        var ViewExtension      = new ImagesManager(PlayniteApi, PluginDatabase.Get(GameMenu), false);
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCBc") + " - " + resources.GetString("LOCGameBackgroundTitle"), ViewExtension);
                        windowExtension.ShowDialog();
                    }
                });
            }

            if (PluginSettings.Settings.EnableCoverImage)
            {
                gameMenuItems.Add(new GameMenuItem
                {
                    // Manage game cover
                    MenuSection = resources.GetString("LOCBc"),
                    Description = resources.GetString("LOCBcManageCover"),
                    Action      = (gameMenuItem) =>
                    {
                        var ViewExtension      = new ImagesManager(PlayniteApi, PluginDatabase.Get(GameMenu), true);
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCBc") + " - " + resources.GetString("LOCGameCoverImageTitle"), ViewExtension);
                        windowExtension.ShowDialog();
                    }
                });
            }

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCBc"),
                Description = "-"
            });
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCBc"),
                Description = "Test",
                Action      = (mainMenuItem) =>
                {
                }
            });
#endif

            return(gameMenuItems);
        }
コード例 #8
0
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            Game gameMenu          = args.Games.First();
            HowLongToBeatData data = new HowLongToBeatData(gameMenu, this.GetPluginUserDataPath(), PlayniteApi, false);

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>
            {
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCHowLongToBeat"),
                    Description = resources.GetString("LOCHowLongToBeatPluginView"),
                    Action      = (gameMenuItem) =>
                    {
                        try
                        {
                            if (!data.hasData)
                            {
                                data.SearchData(GameSelected);
                            }

                            if (data.hasData)
                            {
                                var    ViewExtension   = new HowLongToBeatView(data, gameMenu, PlayniteApi, settings);
                                Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, "HowLongToBeat", ViewExtension);
                                windowExtension.ShowDialog();
                            }
                        }
                        catch (Exception ex)
                        {
                            Common.LogError(ex, "HowLongToBeat", $"Error to load game data for {args.Games.First().Name}");
                            PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "HowLongToBeat");
                        }
                    }
                },
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCHowLongToBeat"),
                    Description = resources.GetString("LOCCommonDeleteGameData"),
                    Action      = (gameMenuItem) =>
                    {
                        data.RemoveData();
                    }
                }
            };

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCHowLongToBeat"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(gameMenuItems);
        }
コード例 #9
0
 public override IEnumerable <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
 {
     return(new List <GameMenuItem>
     {
         new GameMenuItem
         {
             Description = ResourceProvider.GetString("LOCReview_Viewer_MenuItemUpdateDataDescription"),
             MenuSection = "Review Viewer",
             Action = a => {
                 RefreshGameData(args.Games);
             }
         }
     });
 }
コード例 #10
0
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            var GameMenu = args.Games.First();

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>
            {
                // Show requierements for the selected game
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCSystemChecker"),
                    Description = resources.GetString("LOCSystemCheckerCheckConfig"),
                    Action      = (gameMenuItem) =>
                    {
                        PluginDatabase.IsViewOpen = true;
                        var    ViewExtension   = new SystemCheckerGameView(PlayniteApi, this.GetPluginUserDataPath(), GameMenu);
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, "SystemChecker", ViewExtension);
                        windowExtension.ShowDialog();
                        PluginDatabase.IsViewOpen = false;
                    }
                },

                // Delete & download requierements data for the selected game
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCSystemChecker"),
                    Description = resources.GetString("LOCCommonRefreshGameData"),
                    Action      = (gameMenuItem) =>
                    {
                        var TaskIntegrationUI = Task.Run(() =>
                        {
                            PluginDatabase.Remove(GameMenu);
                            var dispatcherOp        = systemCheckerUI.AddElements();
                            dispatcherOp.Completed += (s, e) => { systemCheckerUI.RefreshElements(GameMenu); };
                        });
                    }
                }
            };

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCSystemChecker"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(gameMenuItems);
        }
コード例 #11
0
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            var GameMenu = args.Games.First();

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>
            {
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCSuccessStoryViewGame"),
                    Action      = (gameMenuItem) =>
                    {
                        var    ViewExtension   = new SuccessView(this, settings, PlayniteApi, this.GetPluginUserDataPath(), false, GameMenu);
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                        windowExtension.ShowDialog();
                    }
                },
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCSuccessStoryRefreshData"),
                    Action      = (gameMenuItem) =>
                    {
                        if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription)
                        {
                            PlayniteUiHelper.ResetToggle();
                        }

                        var TaskIntegrationUI = Task.Run(() =>
                        {
                            achievementsDatabase.Remove(GameMenu);
                            successStoryUI.AddElements();
                            successStoryUI.RefreshElements(GameSelected);
                        });
                    }
                }
            };

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCSuccessStory"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(gameMenuItems);
        }
コード例 #12
0
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>
            {
            };

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCThemeModifier"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(gameMenuItems);
        }
コード例 #13
0
 public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs menuArgs)
 {
     return(new List <GameMenuItem>
     {
         new GameMenuItem
         {
             Description = translator.BackUpSelectedGames_Label(),
             MenuSection = translator.Ludusavi(),
             Action = async args => {
                 if (UserConsents(translator.BackUpSelectedGames_Confirm(args.Games.Select(x => (GetGameName(x), RequiresCustomEntry(x))).ToList())))
                 {
                     foreach (var game in args.Games)
                     {
                         {
                             await Task.Run(() => BackUpOneGame(game));
                         }
                     }
                 }
             }
         },
コード例 #14
0
        // To add new game menu items override GetGameMenuItems
        public override IEnumerable <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            var GameMenu = args.Games.First();

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>();

            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCLm"),
                Description = resources.GetString("LOCLmMediaEditor"),
                Action      = (gameMenuItem) =>
                {
                    LmImageEditor ViewExtension = new LmImageEditor(PlayniteApi, GameMenu);
                    Window windowExtension      = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, "ImageEditor", ViewExtension);
                    windowExtension.ShowDialog();
                }
            });

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCLm"),
                Description = "-"
            });
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCLm"),
                Description = "Test",
                Action      = (gameMenuItem) =>
                {
                }
            });
#endif

            return(gameMenuItems);
        }
コード例 #15
0
        // To add new game menu items override GetGameMenuItems
        public override IEnumerable <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            Game                GameMenu      = args.Games.First();
            List <Guid>         Ids           = args.Games.Select(x => x.Id).ToList();
            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>();

            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonImageFormatter")}",
                Description = resources.GetString("LOCDescriptionEditorButtonRemoveImg"),
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.RemoveTag(game.Description, "img");
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });

            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonImageFormatter")}",
                Description = resources.GetString("LOCDescriptionEditorButtonAdd100PercentImg"),
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.Add100PercentStyle(game.Description);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });

            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonImageFormatter")}",
                Description = resources.GetString("LOCDescriptionEditorButtonRemoveStyleImg"),
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.RemoveSizeStyle(game.Description);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });

            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonImageFormatter")}",
                Description = resources.GetString("LOCDescriptionEditorButtonCenterImg"),
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.CenterImage(game.Description);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });


            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonHtmlFormatSteam")}",
                Description = resources.GetString("LOCDescriptionEditorRemoveAboutGame"),
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.SteamRemoveAbout(game.Description);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });


            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}",
                Description = resources.GetString("LOCDescriptionEditorButtonMarkdownToHtml"),
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.MarkdownToHtml(game.Description);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });


            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonHtmlFormater")}",
                Description = resources.GetString("LOCDescriptionEditorButtonHeaderToBold"),
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.HeaderToBold(game.Description);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });

            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonHtmlFormater")}",
                Description = resources.GetString("LOCDescriptionEditorButtonParagraphRemove"),
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.ParagraphRemove(game.Description);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });

            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonHtmlFormater")}",
                Description = "<br><br> => <br>",
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.BrRemove(game.Description, 2, 1);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });

            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonHtmlFormater")}",
                Description = "<br><br>br> => <br>",
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.BrRemove(game.Description, 3, 1);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });

            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = $"{resources.GetString("LOCDescriptionEditor")}|{resources.GetString("LOCDescriptionEditorButtonHtmlFormater")}",
                Description = "<br><br> => <br>br>",
                Action      = (mainMenuItem) =>
                {
                    MessageBoxResult response = PlayniteApi.Dialogs.ShowMessage(resources.GetString("LOCConfirumationAskGeneric"), resources.GetString("LOCDescriptionEditor"), MessageBoxButton.YesNo);
                    if (response == MessageBoxResult.Yes)
                    {
                        foreach (Guid Id in Ids)
                        {
                            Game game = PlayniteApi.Database.Games.Get(Id);
                            if (game != null)
                            {
                                game.Description = HtmlHelper.BrRemove(game.Description, 3, 2);
                                PlayniteApi.Database.Games.Update(game);
                            }
                        }
                    }
                }
            });


#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCDescriptionEditor"),
                Description = "-"
            });
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCDescriptionEditor"),
                Description = "Test",
                Action      = (mainMenuItem) =>
                {
                }
            });
#endif

            return(gameMenuItems);
        }
コード例 #16
0
ファイル: GameMenu.cs プロジェクト: wuhan890809/Playnite
        private void AddExtensionItems()
        {
            var args  = new GetGameMenuItemsArgs();
            var toAdd = new List <GameMenuItem>();

            if (Games != null)
            {
                args.Games = Games;
            }
            else
            {
                args.Games = new List <Game>(1)
                {
                    Game
                };
            }

            foreach (var plugin in model.Extensions.Plugins.Values)
            {
                try
                {
                    var items = plugin.Plugin.GetGameMenuItems(args);
                    if (items.HasItems())
                    {
                        toAdd.AddRange(items);
                    }
                }
                catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                {
                    logger.Error(e, $"Failed to get menu items from plugin {plugin.Description.Name}");
                }
            }

            foreach (var script in model.Extensions.Scripts)
            {
                if (script.SupportedMenus.Contains(Scripting.SupportedMenuMethods.GameMenu))
                {
                    try
                    {
                        var items = script.GetGameMenuItems(args);
                        if (items.HasItems())
                        {
                            foreach (var item in items)
                            {
                                var newItem = GameMenuItem.FromScriptGameMenuItem(item);
                                newItem.Action = (a) =>
                                {
                                    script.InvokeFunction(item.FunctionName, new List <object>
                                    {
                                        new ScriptGameMenuItemActionArgs
                                        {
                                            Games      = a.Games,
                                            SourceItem = item
                                        }
                                    });
                                };

                                toAdd.Add(newItem);
                            }
                        }
                    }
                    catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                    {
                        logger.Error(e, $"Failed to get menu items from script {script.Name}");
                    }
                }
            }

            if (toAdd.Count > 0)
            {
                Items.Add(new Separator());
                var menuItems = new Dictionary <string, MenuItem>();
                foreach (var item in toAdd)
                {
                    object newItem = null;
                    if (item.Description == "-")
                    {
                        newItem = new Separator();
                    }
                    else
                    {
                        newItem = new MenuItem()
                        {
                            Header = item.Description,
                            Icon   = MenuHelpers.GetIcon(item.Icon)
                        };

                        if (item.Action != null)
                        {
                            ((MenuItem)newItem).Click += (_, __) =>
                            {
                                try
                                {
                                    item.Action(new GameMenuItemActionArgs
                                    {
                                        Games      = args.Games,
                                        SourceItem = item
                                    });
                                }
                                catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                                {
                                    logger.Error(e, "Game menu extension action failed.");
                                    Dialogs.ShowErrorMessage(
                                        ResourceProvider.GetString("LOCMenuActionExecError") +
                                        Environment.NewLine + Environment.NewLine +
                                        e.Message, "");
                                }
                            };
                        }
                    }

                    if (item.MenuSection.IsNullOrEmpty())
                    {
                        Items.Add(newItem);
                    }
                    else
                    {
                        var parent = MenuHelpers.GenerateMenuParents(menuItems, item.MenuSection, Items);
                        parent?.Items.Add(newItem);
                    }
                }
            }
        }
コード例 #17
0
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            Game GameMenu = args.Games.First();
            GameHowLongToBeat gameHowLongToBeat = PluginDatabase.Get(GameMenu, true);

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>
            {
                new GameMenuItem {
                    MenuSection = resources.GetString("LOCHowLongToBeat"),
                    Description = resources.GetString("LOCHowLongToBeatPluginView"),
                    Action      = (gameMenuItem) =>
                    {
                        try
                        {
                            gameHowLongToBeat = PluginDatabase.Get(GameMenu);

                            if (gameHowLongToBeat.HasData)
                            {
                                var    ViewExtension   = new HowLongToBeatView(PlayniteApi, settings, gameHowLongToBeat);
                                Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, "HowLongToBeat", ViewExtension);
                                windowExtension.ShowDialog();

                                var TaskIntegrationUI = Task.Run(() =>
                                {
                                    howLongToBeatUI.RefreshElements(HowLongToBeatDatabase.GameSelected);
                                });
                            }
                        }
                        catch (Exception ex)
                        {
                            Common.LogError(ex, "HowLongToBeat", $"Error to load game data for {args.Games.First().Name}");
                            PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "HowLongToBeat");
                        }
                    }
                }
            };


            if (gameHowLongToBeat.HasData)
            {
                gameMenuItems.Add(new GameMenuItem
                {
                    MenuSection = resources.GetString("LOCHowLongToBeat"),
                    Description = resources.GetString("LOCHowLongToBeatSetCurrentTimeManual"),
                    Action      = (mainMenuItem) =>
                    {
                        GlobalProgressOptions globalProgressOptions = new GlobalProgressOptions(
                            $"HowLongToBeat - {resources.GetString("LOCCommonProcessing")}",
                            false
                            );
                        globalProgressOptions.IsIndeterminate = true;

                        PlayniteApi.Dialogs.ActivateGlobalProgress((activateGlobalProgress) =>
                        {
                            PluginDatabase.SetCurrentPlayTime(GameMenu, 0);
                        }, globalProgressOptions);
                    }
                });

                gameMenuItems.Add(new GameMenuItem
                {
                    MenuSection = resources.GetString("LOCHowLongToBeat"),
                    Description = resources.GetString("LOCCommonDeleteGameData"),
                    Action      = (gameMenuItem) =>
                    {
                        PluginDatabase.Remove(GameMenu.Id);
                        howLongToBeatUI.RefreshElements(HowLongToBeatDatabase.GameSelected);
                    }
                });
            }

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCHowLongToBeat"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(gameMenuItems);
        }
コード例 #18
0
        public override IEnumerable <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            var logosSection       = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemSectionLogos");
            var videosSection      = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemSectionVideos");
            var videosMicroSection = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemSectionMicrovideos");

            //TODO Move each action to separate methods?
            var gameMenuItems = new List <GameMenuItem>
            {
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionDownloadSteamLogosSelectedGames"),
                    MenuSection = $"Extra Metadata|{logosSection}",
                    Action      = _ => {
                        var overwrite       = GetBoolFromYesNoDialog(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageOverwriteLogosChoice"));
                        var progressOptions = new GlobalProgressOptions(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDownloadingLogosSteam"), true);
                        progressOptions.IsIndeterminate = false;
                        PlayniteApi.Dialogs.ActivateGlobalProgress((a) =>
                        {
                            var games          = args.Games.Distinct();
                            a.ProgressMaxValue = games.Count();
                            foreach (var game in games)
                            {
                                if (a.CancelToken.IsCancellationRequested)
                                {
                                    break;
                                }
                                logosDownloader.DownloadSteamLogo(game, overwrite, false);
                                a.CurrentProgressValue++;
                            }
                            ;
                        }, progressOptions);
                        PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionDownloadSgdbLogosSelectedGames"),
                    MenuSection = $"Extra Metadata|{logosSection}",
                    Action      = _ => {
                        var overwrite       = GetBoolFromYesNoDialog(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageOverwriteLogosChoice"));
                        var progressOptions = new GlobalProgressOptions(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDownloadingLogosSgdb"), true);
                        progressOptions.IsIndeterminate = false;
                        PlayniteApi.Dialogs.ActivateGlobalProgress((a) =>
                        {
                            var games          = args.Games.Distinct();
                            a.ProgressMaxValue = games.Count();
                            foreach (var game in games)
                            {
                                if (a.CancelToken.IsCancellationRequested)
                                {
                                    break;
                                }
                                logosDownloader.DownloadSgdbLogo(game, overwrite, false);
                                a.CurrentProgressValue++;
                            }
                            ;
                        }, progressOptions);
                        PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionDownloadGoogleLogoSelectedGame"),
                    MenuSection = $"Extra Metadata|{logosSection}",
                    Action      = _ =>
                    {
                        CreateGoogleWindow();
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionSetLogoFromFile"),
                    MenuSection = $"Extra Metadata|{logosSection}",
                    Action      = _ => {
                        var game     = args.Games.Last();
                        var filePath = PlayniteApi.Dialogs.SelectFile("Logo|*.png");
                        if (!filePath.IsNullOrEmpty())
                        {
                            var logoPath   = extraMetadataHelper.GetGameLogoPath(game, true);
                            var fileCopied = IoHelper.MoveFile(filePath, logoPath, true);
                            if (settings.Settings.ProcessLogosOnDownload && fileCopied)
                            {
                                logosDownloader.ProcessLogoImage(logoPath);
                            }
                            PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                        }
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionDeleteLogosSelectedGames"),
                    MenuSection = $"Extra Metadata|{logosSection}",
                    Action      = _ => {
                        foreach (var game in args.Games.Distinct())
                        {
                            extraMetadataHelper.DeleteGameLogo(game);
                        }
                        ;
                        PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionDownloadSteamVideosSelectedGames"),
                    MenuSection = $"Extra Metadata|{videosSection}|{videosSection}",
                    Action      = _ =>
                    {
                        if (!ValidateExecutablesSettings(true, false))
                        {
                            return;
                        }
                        var overwrite       = GetBoolFromYesNoDialog(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageOverwriteVideosChoice"));
                        var progressOptions = new GlobalProgressOptions(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDownloadingVideosSteam"), true);
                        progressOptions.IsIndeterminate = false;
                        ClearVideoSources();
                        PlayniteApi.Dialogs.ActivateGlobalProgress((a) =>
                        {
                            var games          = args.Games.Distinct();
                            a.ProgressMaxValue = games.Count();
                            foreach (var game in games)
                            {
                                if (a.CancelToken.IsCancellationRequested)
                                {
                                    break;
                                }
                                videosDownloader.DownloadSteamVideo(game, overwrite, false, true, false);
                                a.CurrentProgressValue++;
                            }
                            ;
                        }, progressOptions);
                        UpdatePlayersData();
                        PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionDownloadVideoFromYoutube"),
                    MenuSection = $"Extra Metadata|{videosSection}|{videosSection}",
                    Action      = _ =>
                    {
                        ClearVideoSources();
                        if (!ValidateExecutablesSettings(true, true))
                        {
                            return;
                        }
                        CreateYoutubeWindow();
                        UpdatePlayersData();
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionDownloadSteamVideosMicroSelectedGames"),
                    MenuSection = $"Extra Metadata|{videosSection}|{videosMicroSection}",
                    Action      = _ =>
                    {
                        if (!ValidateExecutablesSettings(true, false))
                        {
                            return;
                        }
                        ClearVideoSources();
                        var overwrite       = GetBoolFromYesNoDialog(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageOverwriteVideosChoice"));
                        var progressOptions = new GlobalProgressOptions(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDownloadingVideosMicroSteam"), true);
                        progressOptions.IsIndeterminate = false;
                        PlayniteApi.Dialogs.ActivateGlobalProgress((a) =>
                        {
                            var games          = args.Games.Distinct();
                            a.ProgressMaxValue = games.Count();
                            foreach (var game in games)
                            {
                                if (a.CancelToken.IsCancellationRequested)
                                {
                                    break;
                                }
                                videosDownloader.DownloadSteamVideo(game, overwrite, false, false, true);
                                a.CurrentProgressValue++;
                            }
                            ;
                        }, progressOptions);
                        UpdatePlayersData();
                        PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionOpenExtraMetadataDirectory"),
                    MenuSection = $"Extra Metadata",
                    Action      = _ =>
                    {
                        foreach (var game in args.Games.Distinct())
                        {
                            Process.Start(extraMetadataHelper.GetExtraMetadataDirectory(game, true));
                        }
                        ;
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionGenerateMicroFromVideo"),
                    MenuSection = $"Extra Metadata|{videosSection}|{videosMicroSection}",
                    Action      = _ =>
                    {
                        if (!ValidateExecutablesSettings(true, false))
                        {
                            return;
                        }
                        ClearVideoSources();
                        var overwrite       = GetBoolFromYesNoDialog(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageOverwriteVideosChoice"));
                        var progressOptions = new GlobalProgressOptions(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageGeneratingMicroVideosFromVideos"), true);
                        progressOptions.IsIndeterminate = false;
                        PlayniteApi.Dialogs.ActivateGlobalProgress((a) =>
                        {
                            var games          = args.Games.Distinct();
                            a.ProgressMaxValue = games.Count();
                            foreach (var game in games)
                            {
                                if (a.CancelToken.IsCancellationRequested)
                                {
                                    break;
                                }
                                videosDownloader.ConvertVideoToMicro(game, overwrite);
                                a.CurrentProgressValue++;
                            }
                            ;
                        }, progressOptions);
                        UpdatePlayersData();
                        PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionSetVideoFromSelectionToSelGame"),
                    MenuSection = $"Extra Metadata|{videosSection}|{videosSection}",
                    Action      = _ =>
                    {
                        if (!ValidateExecutablesSettings(true, false))
                        {
                            return;
                        }
                        ClearVideoSources();
                        PlayniteApi.Dialogs.ActivateGlobalProgress((a) =>
                        {
                            videosDownloader.SelectedDialogFileToVideo(args.Games[0]);
                        }, new GlobalProgressOptions(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogProcessSettingVideoFromSelFile")));
                        UpdatePlayersData();
                        PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionDeleteVideosSelectedGames"),
                    MenuSection = $"Extra Metadata|{videosSection}|{videosSection}",
                    Action      = _ =>
                    {
                        ClearVideoSources();
                        foreach (var game in args.Games.Distinct())
                        {
                            extraMetadataHelper.DeleteGameVideo(game);
                        }
                        ;
                        UpdatePlayersData();
                        PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                    }
                },
                new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemDescriptionDeleteVideosMicroSelectedGames"),
                    MenuSection = $"Extra Metadata|{videosSection}|{videosMicroSection}",
                    Action      = _ =>
                    {
                        ClearVideoSources();
                        foreach (var game in args.Games.Distinct())
                        {
                            extraMetadataHelper.DeleteGameVideoMicro(game);
                        }
                        ;
                        UpdatePlayersData();
                        PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageDone"), "Extra Metadata Loader");
                    }
                }
            };

            if (settings.Settings.EnableYoutubeSearch)
            {
                gameMenuItems.Add(new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemViewYoutubeReview"),
                    MenuSection = $"{videosSection}",
                    Action      = _ =>
                    {
                        ClearVideoSources();
                        var game        = args.Games.Last();
                        var searchTerm  = $"{game.Name} review";
                        var searchItems = YoutubeCommon.GetYoutubeSearchResults(searchTerm, false);
                        if (searchItems.Count > 0)
                        {
                            ViewYoutubeVideo(searchItems.First().VideoId);
                        }
                        else
                        {
                            PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageVideoNotFound"));
                        }
                        UpdatePlayersData();
                    }
                });
                gameMenuItems.Add(new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemViewYoutubeGameplay"),
                    MenuSection = $"{videosSection}",
                    Action      = _ =>
                    {
                        ClearVideoSources();
                        var game        = args.Games.Last();
                        var searchTerm  = $"{game.Name} gameplay";
                        var searchItems = YoutubeCommon.GetYoutubeSearchResults(searchTerm, false);
                        if (searchItems.Count > 0)
                        {
                            ViewYoutubeVideo(searchItems.First().VideoId);
                        }
                        else
                        {
                            PlayniteApi.Dialogs.ShowMessage(ResourceProvider.GetString("LOCExtra_Metadata_Loader_DialogMessageVideoNotFound"));
                        }
                        UpdatePlayersData();
                    }
                });
                gameMenuItems.Add(new GameMenuItem
                {
                    Description = ResourceProvider.GetString("LOCExtra_Metadata_Loader_MenuItemViewYoutubeSearch"),
                    MenuSection = $"{videosSection}",
                    Action      = _ =>
                    {
                        ClearVideoSources();
                        var game       = args.Games.Last();
                        var searchTerm = $"{game.Name}";
                        CreateYoutubeWindow(false, false, searchTerm);
                        UpdatePlayersData();
                    }
                });
            }

            return(gameMenuItems);
        }
コード例 #19
0
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            var GameMenu = args.Games.First();

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>();

            if (!PluginDatabase.PluginSettings.EnableOneGameView ||
                (PluginDatabase.PluginSettings.EnableOneGameView && PluginDatabase.Get(GameMenu, true).HasData))
            {
                // Show list achievements for the selected game
                gameMenuItems.Add(new GameMenuItem
                {
                    MenuSection = resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCSuccessStoryViewGame"),
                    Action      = (gameMenuItem) =>
                    {
                        dynamic ViewExtension     = null;
                        PluginDatabase.IsViewOpen = true;
                        if (PluginDatabase.PluginSettings.EnableOneGameView)
                        {
                            ViewExtension = new SuccessStoryOneGameView(GameMenu);
                        }
                        else
                        {
                            ViewExtension = new SuccessView(this, PlayniteApi, this.GetPluginUserDataPath(), false, GameMenu);
                        }
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                        windowExtension.ShowDialog();
                        PluginDatabase.IsViewOpen = false;
                    }
                });
            }

            gameMenuItems.Add(new GameMenuItem
            {
                // Delete & download localizations data for the selected game
                MenuSection = resources.GetString("LOCSuccessStory"),
                Description = resources.GetString("LOCCommonRefreshGameData"),
                Action      = (gameMenuItem) =>
                {
                    if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription)
                    {
                        PlayniteUiHelper.ResetToggle();
                    }

                    var TaskIntegrationUI = Task.Run(() =>
                    {
                        PluginDatabase.Remove(GameMenu);
                        var dispatcherOp        = successStoryUI.AddElements();
                        dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); };
                    });
                }
            });

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCSuccessStory"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(gameMenuItems);
        }
コード例 #20
0
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            Game             GameMenu          = args.Games.First();
            string           SourceName        = PlayniteTools.GetSourceName(PlayniteApi, GameMenu);
            bool             IsAddOrShowManual = SuccessStoryDatabase.IsAddOrShowManual(GameMenu, SourceName);
            GameAchievements gameAchievements  = PluginDatabase.Get(GameMenu, true);

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>();

            if (!settings.EnableOneGameView || (settings.EnableOneGameView && gameAchievements.HasData))
            {
                // Show list achievements for the selected game
                gameMenuItems.Add(new GameMenuItem
                {
                    MenuSection = resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCSuccessStoryViewGame"),
                    Action      = (gameMenuItem) =>
                    {
                        dynamic ViewExtension     = null;
                        PluginDatabase.IsViewOpen = true;
                        if (PluginDatabase.PluginSettings.EnableOneGameView)
                        {
                            ViewExtension = new SuccessStoryOneGameView(GameMenu);
                        }
                        else
                        {
                            ViewExtension = new SuccessView(this, PlayniteApi, this.GetPluginUserDataPath(), false, GameMenu);
                        }
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                        windowExtension.ShowDialog();
                        PluginDatabase.IsViewOpen = false;
                    }
                });
            }

            if (!IsAddOrShowManual)
            {
                gameMenuItems.Add(new GameMenuItem
                {
                    MenuSection = resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCCommonRefreshGameData"),
                    Action      = (gameMenuItem) =>
                    {
                        if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription)
                        {
                            PlayniteUiHelper.ResetToggle();
                        }

                        var TaskIntegrationUI = Task.Run(() =>
                        {
                            PluginDatabase.Remove(GameMenu);
                            var dispatcherOp        = successStoryUI.AddElements();
                            dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); };
                        });
                    }
                });
            }

            if (settings.EnableManual && IsAddOrShowManual)
            {
                if (!gameAchievements.HasData)
                {
                    gameMenuItems.Add(new GameMenuItem
                    {
                        MenuSection = resources.GetString("LOCSuccessStory"),
                        Description = resources.GetString("LOCAddTitle"),
                        Action      = (mainMenuItem) =>
                        {
                            var TaskIntegrationUI = Task.Run(() =>
                            {
                                PluginDatabase.Remove(GameMenu);
                                PluginDatabase.GetManual(GameMenu);

                                var dispatcherOp        = successStoryUI.AddElements();
                                dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); };
                            });
                        }
                    });
                }
                else
                {
                    gameMenuItems.Add(new GameMenuItem
                    {
                        MenuSection = resources.GetString("LOCSuccessStory"),
                        Description = resources.GetString("LOCEditGame"),
                        Action      = (mainMenuItem) =>
                        {
                            var ViewExtension      = new SuccessStoryEditManual(GameMenu);
                            Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                            windowExtension.ShowDialog();
                        }
                    });

                    gameMenuItems.Add(new GameMenuItem
                    {
                        MenuSection = resources.GetString("LOCSuccessStory"),
                        Description = resources.GetString("LOCRemoveTitle"),
                        Action      = (gameMenuItem) =>
                        {
                            if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription)
                            {
                                PlayniteUiHelper.ResetToggle();
                            }

                            var TaskIntegrationUI = Task.Run(() =>
                            {
                                PluginDatabase.Remove(GameMenu);
                                var dispatcherOp        = successStoryUI.AddElements();
                                dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); };
                            });
                        }
                    });
                }
            }

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCSuccessStory"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif
            return(gameMenuItems);
        }
        // To add new game menu items override GetGameMenuItems
        public override IEnumerable <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            Game            GameMenu        = args.Games.First();
            List <Guid>     Ids             = args.Games.Select(x => x.Id).ToList();
            GameScreenshots gameScreenshots = PluginDatabase.Get(GameMenu);

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>();

            if (gameScreenshots.HasData)
            {
                gameMenuItems.Add(new GameMenuItem
                {
                    // Delete & download localizations data for the selected game
                    MenuSection = resources.GetString("LOCSsv"),
                    Description = resources.GetString("LOCSsvViewScreenshots"),
                    Action      = (gameMenuItem) =>
                    {
                        WindowOptions windowOptions = new WindowOptions
                        {
                            ShowMinimizeButton = false,
                            ShowMaximizeButton = true,
                            ShowCloseButton    = true
                        };

                        var ViewExtension          = new SsvScreenshotsView(PluginDatabase.GameContext);
                        Window windowExtension     = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSsvTitle"), ViewExtension, windowOptions);
                        windowExtension.ResizeMode = ResizeMode.CanResize;
                        windowExtension.ShowDialog();
                    }
                });

                if (gameScreenshots.ScreenshotsFolders != null && gameScreenshots.ScreenshotsFolders.Count != 0 && gameScreenshots.FoldersExist)
                {
                    gameMenuItems.Add(new GameMenuItem
                    {
                        // Open directory
                        MenuSection = resources.GetString("LOCSsv"),
                        Description = resources.GetString("LOCSsvOpenScreenshotsDirectory"),
                        Action      = (gameMenuItem) =>
                        {
                            foreach (string Folder in gameScreenshots.ScreenshotsFolders)
                            {
                                Process.Start(Folder);
                            }
                        }
                    });
                }

                if (gameScreenshots.Items.Count > 0 && PluginDatabase.PluginSettings.Settings.EnableFolderToSave)
                {
                    gameMenuItems.Add(new GameMenuItem
                    {
                        MenuSection = resources.GetString("LOCSsv"),
                        Description = resources.GetString("LOCSsvMoveToSave"),
                        Action      = (gameMenuItem) =>
                        {
                            if (Ids.Count == 1)
                            {
                                PluginDatabase.MoveToFolderToSave(GameMenu);
                            }
                            else
                            {
                                PluginDatabase.MoveToFolderToSave(Ids);
                            }
                        }
                    });
                }

                if (gameScreenshots.Items.Count > 0)
                {
                    gameMenuItems.Add(new GameMenuItem
                    {
                        MenuSection = resources.GetString("LOCSsv"),
                        Description = resources.GetString("LOCSsvConvertToJPG"),
                        Action      = (gameMenuItem) =>
                        {
                            GlobalProgressOptions globalProgressOptions = new GlobalProgressOptions(
                                $"{PluginDatabase.PluginName} - {resources.GetString("LOCCommonConverting")}",
                                true
                                );
                            globalProgressOptions.IsIndeterminate = Ids.Count == 1;

                            PlayniteApi.Dialogs.ActivateGlobalProgress((activateGlobalProgress) =>
                            {
                                Stopwatch stopWatch = new Stopwatch();
                                stopWatch.Start();

                                string CancelText = string.Empty;
                                if (Ids.Count > 1)
                                {
                                    activateGlobalProgress.ProgressMaxValue = Ids.Count;
                                }

                                try
                                {
                                    Ids.ForEach(y =>
                                    {
                                        GameScreenshots data = PluginDatabase.Get(y);
                                        if (data.HasData)
                                        {
                                            bool HasConvert = false;
                                            data.Items.ForEach(x =>
                                            {
                                                if (activateGlobalProgress.CancelToken.IsCancellationRequested)
                                                {
                                                    CancelText = " canceled";
                                                    return;
                                                }

                                                if (!x.IsVideo)
                                                {
                                                    string oldFile = x.FileName;
                                                    string newFile = ImageTools.ConvertToJpg(oldFile, PluginDatabase.PluginSettings.Settings.JpgQuality);

                                                    if (!newFile.IsNullOrEmpty())
                                                    {
                                                        DateTime dt = File.GetLastWriteTime(oldFile);
                                                        File.SetLastWriteTime(newFile, dt);
                                                        FileSystem.DeleteFileSafe(oldFile);
                                                        HasConvert = true;
                                                    }
                                                }
                                            });

                                            if (HasConvert)
                                            {
                                                GameSettings gameSettings = PluginDatabase.GetGameSettings(y);
                                                if (gameSettings != null)
                                                {
                                                    PluginDatabase.SetDataFromSettings(gameSettings);
                                                }
                                            }

                                            if (activateGlobalProgress.CancelToken.IsCancellationRequested)
                                            {
                                                CancelText = " canceled";
                                                return;
                                            }

                                            if (Ids.Count > 1)
                                            {
                                                activateGlobalProgress.CurrentProgressValue++;
                                            }
                                        }
                                    });
                                }
                                catch (Exception ex)
                                {
                                    Common.LogError(ex, false, true, PluginDatabase.PluginName);
                                }

                                stopWatch.Stop();
                                TimeSpan ts = stopWatch.Elapsed;
                                logger.Info($"Task RefreshData(){CancelText} - {string.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)} for {activateGlobalProgress.CurrentProgressValue}/{Ids.Count} items");
                            }, globalProgressOptions);
                        }
                    });
                }

                gameMenuItems.Add(new GameMenuItem
                {
                    MenuSection = resources.GetString("LOCSsv"),
                    Description = "-"
                });
            }

            gameMenuItems.Add(new GameMenuItem
            {
                // Refresh data
                MenuSection = resources.GetString("LOCSsv"),
                Description = resources.GetString("LOCCommonRefreshGameData"),
                Action      = (gameMenuItem) =>
                {
                    if (Ids.Count == 1)
                    {
                        PluginDatabase.RefreshData(GameMenu);
                    }
                    else
                    {
                        PluginDatabase.RefreshData(Ids);
                    }
                }
            });

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCSsv"),
                Description = "-"
            });
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCSsv"),
                Description = "Test",
                Action      = (mainMenuItem) =>
                {
                }
            });
#endif

            return(gameMenuItems);
        }