コード例 #1
0
        /// <summary>
        /// Integration plugin interface in application.
        /// </summary>
        private void Integration()
        {
            try
            {
                // Delete
                logger.Info("HowLongToBeat - Delete");
                ui.RemoveButtonInGameSelectedActionBarButtonOrToggleButton("PART_HltbButton");
                ui.RemoveElementInGameSelectedDescription("PART_HltbProgressBarIntegration");
                ui.ClearElementInCustomTheme("PART_hltbProgressBarWithTitle");
                ui.ClearElementInCustomTheme("PART_hltbProgressBar");


                HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath(), false);


                if (settings.EnableIntegrationButton)
                {
                    Button HltbButton = new Button();
                    HltbButton.Name       = "PART_HltbButton";
                    HltbButton.FontFamily = new FontFamily(new Uri("pack://application:,,,/HowLongToBeat;component/Resources/"), "./#font");
                    HltbButton.Margin     = new Thickness(10, 0, 0, 0);
                    HltbButton.Click     += OnBtGameSelectedActionBarClick;
                    HltbButton.Content    = TransformIcon.Get("HowLongToBeat");

                    ui.AddButtonInGameSelectedActionBarButtonOrToggleButton(HltbButton);
                }

                // Auto integration
                if (settings.EnableIntegrationInDescription)
                {
                    if (data.GetData() != null)
                    {
                        StackPanel spHltb = CreateHltb(GameSelected.Playtime, data.GetData(), settings.IntegrationShowTitle);
                        spHltb.Name = "PART_HltbProgressBarIntegration";

                        ui.AddElementInGameSelectedDescription(spHltb, settings.IntegrationTopGameDetails);
                    }
                }

                // Custom theme
                if (settings.EnableIntegrationInCustomTheme)
                {
                    // Create
                    StackPanel  spHltb          = CreateHltb(GameSelected.Playtime, data.GetData(), true);
                    UserControl hltbProgressBar = new HltbProgressBar(GameSelected.Playtime, data.GetData());

                    ui.AddElementInCustomTheme(spHltb, "PART_hltbProgressBarWithTitle");
                    ui.AddElementInCustomTheme(hltbProgressBar, "PART_hltbProgressBar");
                }
            }
            catch (Exception ex)
            {
                var    LineNumber = new StackTrace(ex, true).GetFrame(0).GetFileLineNumber();
                string FileName   = new StackTrace(ex, true).GetFrame(0).GetFileName();
                logger.Error(ex, $"HowLongToBeat [{FileName} {LineNumber}] - Impossible integration ");
            }
        }
コード例 #2
0
        public override IEnumerable <ExtensionFunction> GetFunctions()
        {
            return(new List <ExtensionFunction>
            {
                new ExtensionFunction(
                    resources.GetString("LOCHowLongToBeat"),
                    () =>
                {
                    // Add code to be execute when user invokes this menu entry.

                    try {
                        HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath(), PlayniteApi);
                        if (data.GetData() != null)
                        {
                            new Views.HowLongToBeat(data, GameSelected, PlayniteApi, settings).ShowDialog();
                            Integration();
                        }
                    }
                    catch (Exception ex)
                    {
                        Common.LogError(ex, "HowLongToBeat", "Error to load database");
                        PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "HowLongToBeat");
                    }
                })
            });
        }
コード例 #3
0
        private void OnBtGameSelectedActionBarClick(object sender, RoutedEventArgs e)
        {
            HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath());

            if (data.GetData() != null)
            {
                new Views.HowLongToBeat(data, GameSelected, PlayniteApi).ShowDialog();
            }
        }
コード例 #4
0
 private void OnBtGameSelectedActionBarClick(object sender, RoutedEventArgs e)
 {
     try
     {
         HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath(), PlayniteApi);
         if (data.GetData() != null)
         {
             new Views.HowLongToBeat(data, GameSelected, PlayniteApi, settings).ShowDialog();
             Integration();
         }
     }
     catch (Exception ex)
     {
         Common.LogError(ex, "HowLongToBeat", "Error to load data");
         PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "HowLongToBeat");
     }
 }
コード例 #5
0
        public override IEnumerable <ExtensionFunction> GetFunctions()
        {
            return(new List <ExtensionFunction>
            {
                new ExtensionFunction(
                    "HowLongToBeat",
                    () =>
                {
                    // Add code to be execute when user invokes this menu entry.

                    HowLongToBeatData data = new HowLongToBeatData(GameSelected, this.GetPluginUserDataPath());
                    if (data.GetData() != null)
                    {
                        new Views.HowLongToBeat(data, GameSelected, PlayniteApi).ShowDialog();
                    }
                })
            });
        }
コード例 #6
0
        public HowLongToBeat(HowLongToBeatData data, Game game, IPlayniteAPI PlayniteApi)
        {
            this.data = data;

            InitializeComponent();

            HltbDataUser gameData = data.GetData();

            CoverImage = PlayniteApi.Database.GetFullFilePath(game.CoverImage);
            GameName   = game.Name;


            int ElIndicator = 0;

            Hltb_El1.Visibility       = System.Windows.Visibility.Hidden;
            Hltb_El1_Color.Visibility = System.Windows.Visibility.Hidden;
            Hltb_El2.Visibility       = System.Windows.Visibility.Hidden;
            Hltb_El2_Color.Visibility = System.Windows.Visibility.Hidden;
            Hltb_El3.Visibility       = System.Windows.Visibility.Hidden;
            Hltb_El3_Color.Visibility = System.Windows.Visibility.Hidden;

            if (gameData.GameHltbData.MainStory != 0)
            {
                ElIndicator += 1;
                SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainStory"), gameData.GameHltbData.MainStoryFormat);
            }

            if (gameData.GameHltbData.MainExtra != 0)
            {
                ElIndicator += 1;
                SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainExtra"), gameData.GameHltbData.MainExtraFormat);
            }

            if (gameData.GameHltbData.Completionist != 0)
            {
                ElIndicator += 1;
                SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCompletionist"), gameData.GameHltbData.CompletionistFormat);
            }

            if (gameData.GameHltbData.Solo != 0)
            {
                ElIndicator += 1;
                SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatSolo"), gameData.GameHltbData.SoloFormat);
            }

            if (gameData.GameHltbData.CoOp != 0)
            {
                ElIndicator += 1;
                SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCoOp"), gameData.GameHltbData.CoOpFormat);
            }

            if (gameData.GameHltbData.Vs != 0)
            {
                ElIndicator += 1;
                SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatVs"), gameData.GameHltbData.VsFormat);
            }


            LongToTimePlayedConverter converter = new LongToTimePlayedConverter();

            PlaytimeFormat = (string)converter.Convert((long)game.Playtime, null, null, CultureInfo.CurrentCulture);


            HltbProgressBar.Children.Add(new HltbProgressBar(game.Playtime, gameData));
            HltbProgressBar.UpdateLayout();


            // Set Binding data
            DataContext = this;
        }
        public HowLongToBeatView(HowLongToBeatData data, Game game, IPlayniteAPI PlayniteApi, HowLongToBeatSettings settings)
        {
            _data = data;

            InitializeComponent();

            HltbDataUser gameData = data.GetData();

            if (data.hasData && gameData != null && gameData.GameHltbData != null)
            {
                if (string.IsNullOrEmpty(game.CoverImage))
                {
                    CoverImage = gameData.GameHltbData.UrlImg;
                }
                else
                {
                    CoverImage = gameData.GameHltbData.UrlImg;
                    if (!settings.ShowHltbImg)
                    {
                        CoverImage = PlayniteApi.Database.GetFullFilePath(game.CoverImage);
                    }
                }
                GameName = game.Name;
                HltbName = resources.GetString("LOCSourceLabel") + ": " + gameData.GameHltbData.Name;


                int ElIndicator = 0;

                Hltb_El1.Visibility       = Visibility.Hidden;
                Hltb_El1_Color.Visibility = Visibility.Hidden;
                Hltb_El2.Visibility       = Visibility.Hidden;
                Hltb_El2_Color.Visibility = Visibility.Hidden;
                Hltb_El3.Visibility       = Visibility.Hidden;
                Hltb_El3_Color.Visibility = Visibility.Hidden;

                if (gameData.GameHltbData.MainStory != 0)
                {
                    ElIndicator += 1;
                    SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainStory"), gameData.GameHltbData.MainStoryFormat);
                }

                if (gameData.GameHltbData.MainExtra != 0)
                {
                    ElIndicator += 1;
                    SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainExtra"), gameData.GameHltbData.MainExtraFormat);
                }

                if (gameData.GameHltbData.Completionist != 0)
                {
                    ElIndicator += 1;
                    SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCompletionist"), gameData.GameHltbData.CompletionistFormat);
                }

                if (gameData.GameHltbData.Solo != 0)
                {
                    ElIndicator += 1;
                    SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatSolo"), gameData.GameHltbData.SoloFormat);
                }

                if (gameData.GameHltbData.CoOp != 0)
                {
                    ElIndicator += 1;
                    SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCoOp"), gameData.GameHltbData.CoOpFormat);
                }

                if (gameData.GameHltbData.Vs != 0)
                {
                    ElIndicator += 1;
                    SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatVs"), gameData.GameHltbData.VsFormat);
                }


                Hltb_El1_Color.Background = new SolidColorBrush(settings.ColorFirst);
                Hltb_El2_Color.Background = new SolidColorBrush(settings.ColorSecond);
                Hltb_El3_Color.Background = new SolidColorBrush(settings.ColorThird);


                LongToTimePlayedConverter converter = new LongToTimePlayedConverter();
                PlaytimeFormat = (string)converter.Convert((long)game.Playtime, null, null, CultureInfo.CurrentCulture);

                if (!data.isEmpty)
                {
                    HltbProgressBar hltbProgressBar = new HltbProgressBar();
                    hltbProgressBar.SetHltbData(game.Playtime, data, settings);
                    PART_HltbProgressBar.Children.Add(hltbProgressBar);
                }
            }

            // Set Binding data
            DataContext = this;
        }
        private void LoadData()
        {
            try
            {
                if (_gameData == null || !_gameData.hasData || _gameData.isEmpty)
                {
                    return;
                }

                if (_settings.ProgressBarShowTime && !_settings.ProgressBarShowTimeInterior)
                {
                    PART_HltbProgressBar_Contener.Height = PART_HltbProgressBar_Contener.Height - spShowTime.Height;
#if DEBUG
                    logger.Debug($"HowLongToBeat - ProgressBarShowTime & !ProgressBarShowTimeInterior -  Height: {PART_HltbProgressBar_Contener.Height} - Width: {PART_HltbProgressBar_Contener.Width}");
#endif
                }
                else
                {
                    spShowTime.Height = 0;
                }

                if (_settings.ProgressBarShowTimeAbove)
                {
                    Grid.SetRow(spShowTime, 0);
                    Grid.SetRow(PART_HltbProgressBar_Contener, 1);
                }
                if (_settings.ProgressBarShowTimeInterior)
                {
                    Grid.SetRow(spShowTime, 0);
                    spShowTime.Height = PART_HltbProgressBar_Contener.Height;
                }

                // Definied data value in different component.
                int  ElIndicator = 0;
                long MaxValue    = 0;
                long MaxHltb     = 0;
                List <ListProgressBar> listProgressBars = new List <ListProgressBar>();
                if (_gameData != null)
                {
                    if (_gameData.GetData().GameHltbData.MainStory != 0)
                    {
                        ElIndicator += 1;
                        listProgressBars.Add(new ListProgressBar {
                            Indicator = ElIndicator, Value = _gameData.GetData().GameHltbData.MainStory, Format = _gameData.GetData().GameHltbData.MainStoryFormat
                        });
                        if (MaxValue < _gameData.GetData().GameHltbData.MainStory)
                        {
                            MaxValue = _gameData.GetData().GameHltbData.MainStory;
                        }
                    }

                    if (_gameData.GetData().GameHltbData.MainExtra != 0)
                    {
                        ElIndicator += 1;
                        listProgressBars.Add(new ListProgressBar {
                            Indicator = ElIndicator, Value = _gameData.GetData().GameHltbData.MainExtra, Format = _gameData.GetData().GameHltbData.MainExtraFormat
                        });
                        if (MaxValue < _gameData.GetData().GameHltbData.MainExtra)
                        {
                            MaxValue = _gameData.GetData().GameHltbData.MainExtra;
                        }
                    }

                    if (_gameData.GetData().GameHltbData.Completionist != 0)
                    {
                        ElIndicator += 1;
                        listProgressBars.Add(new ListProgressBar {
                            Indicator = ElIndicator, Value = _gameData.GetData().GameHltbData.Completionist, Format = _gameData.GetData().GameHltbData.CompletionistFormat
                        });
                        if (MaxValue < _gameData.GetData().GameHltbData.Completionist)
                        {
                            MaxValue = _gameData.GetData().GameHltbData.Completionist;
                        }
                    }

                    if (_gameData.GetData().GameHltbData.Solo != 0)
                    {
                        ElIndicator += 1;
                        listProgressBars.Add(new ListProgressBar {
                            Indicator = ElIndicator, Value = _gameData.GetData().GameHltbData.Solo, Format = _gameData.GetData().GameHltbData.SoloFormat
                        });
                        if (MaxValue < _gameData.GetData().GameHltbData.Solo)
                        {
                            MaxValue = _gameData.GetData().GameHltbData.Solo;
                        }
                    }

                    if (_gameData.GetData().GameHltbData.CoOp != 0)
                    {
                        ElIndicator += 1;
                        listProgressBars.Add(new ListProgressBar {
                            Indicator = ElIndicator, Value = _gameData.GetData().GameHltbData.CoOp, Format = _gameData.GetData().GameHltbData.CoOpFormat
                        });
                        if (MaxValue < _gameData.GetData().GameHltbData.CoOp)
                        {
                            MaxValue = _gameData.GetData().GameHltbData.CoOp;
                        }
                    }

                    if (_gameData.GetData().GameHltbData.Vs != 0)
                    {
                        ElIndicator += 1;
                        listProgressBars.Add(new ListProgressBar {
                            Indicator = ElIndicator, Value = _gameData.GetData().GameHltbData.Vs, Format = _gameData.GetData().GameHltbData.VsFormat
                        });
                        if (MaxValue < _gameData.GetData().GameHltbData.Vs)
                        {
                            MaxValue = _gameData.GetData().GameHltbData.Vs;
                        }
                    }
                }

                // Define the maxvalue for progressbar & slider
                MaxHltb = MaxValue;
                if (_Playtime > MaxValue)
                {
                    MaxValue = _Playtime;
                }

                // Adjust position tracker
                if (_Playtime > 69)
                {
                    SliderPlaytime.Margin = new Thickness(-8, 0, -3, 0);
                }

                // Limit MaxValue when playtime is more than MaxHltb
                long MaxPercent = (long)Math.Ceiling((double)(10 * MaxHltb / 100));
                if (MaxValue > MaxHltb + MaxPercent)
                {
                    MaxValue = MaxHltb + MaxPercent;
                }


                // Add data
                ProgressHltb_El1.Maximum = MaxValue;
                ProgressHltb_El2.Maximum = MaxValue;
                ProgressHltb_El3.Maximum = MaxValue;

                SliderPlaytime.Value   = _Playtime;
                SliderPlaytime.Maximum = MaxValue;

#if DEBUG
                logger.Debug($"HowLongToBeat - listProgressBars: {JsonConvert.SerializeObject(listProgressBars)}");
#endif

                ProgressHltb_El1.Visibility = Visibility.Hidden;
                spHltb_El1.Visibility       = Visibility.Hidden;
                spHltbTime_El1.Visibility   = Visibility.Hidden;

                ProgressHltb_El2.Visibility = Visibility.Hidden;
                spHltb_El2.Visibility       = Visibility.Hidden;
                spHltbTime_El2.Visibility   = Visibility.Hidden;

                ProgressHltb_El3.Visibility = Visibility.Hidden;
                spHltb_El3.Visibility       = Visibility.Hidden;
                spHltbTime_El3.Visibility   = Visibility.Hidden;

                foreach (var listProgressBar in listProgressBars)
                {
                    SetDataInView(listProgressBar.Indicator, listProgressBar.Value, listProgressBar.Format);
                }


                SliderPlaytime.UpdateLayout();
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "HowLongToBeat", "Error on LoadData()");
            }
        }
コード例 #9
0
        /// <summary>
        /// Integration plugin interface in application.
        /// </summary>
        private void Integration(Game game = null)
        {
            try
            {
                if (game != null)
                {
                    GameSelected = game;
                }

                // Delete
                logger.Info("HowLongToBeat - Delete integeration");
                ui.RemoveButtonInGameSelectedActionBarButtonOrToggleButton("PART_HltbButton");
                ui.RemoveElementInGameSelectedDescription("PART_HltbProgressBarIntegration");
                ui.ClearElementInCustomTheme("PART_hltbProgressBarWithTitle");
                ui.ClearElementInCustomTheme("PART_hltbProgressBar");

                // Reset resources
                List <ResourcesList> resourcesLists = new List <ResourcesList>();
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_HasData", Value = false
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_MainStory", Value = 0
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_MainStoryFormat", Value = ""
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_MainExtra", Value = 0
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_MainExtraFormat", Value = ""
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_Completionist", Value = 0
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_CompletionistFormat", Value = ""
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_Solo", Value = 0
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_SoloFormat", Value = ""
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_CoOp", Value = 0
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_CoOpFormat", Value = ""
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_Vs", Value = 0
                });
                resourcesLists.Add(new ResourcesList {
                    Key = "Htlb_VsFormat", Value = ""
                });
                ui.AddResources(resourcesLists);


                var taskIntegration = Task.Run(() => LoadData(PlayniteApi, this.GetPluginUserDataPath(), settings))
                                      .ContinueWith(antecedent =>
                {
                    HowLongToBeatData HltbGameData = antecedent.Result;

                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        if (HltbGameData.hasData)
                        {
                            // Add resources
                            resourcesLists = new List <ResourcesList>();
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_HasData", Value = HltbGameData.hasData
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_MainStory", Value = HltbGameData.GetData().GameHltbData.MainStory
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_MainStoryFormat", Value = HltbGameData.GetData().GameHltbData.MainStoryFormat
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_MainExtra", Value = HltbGameData.GetData().GameHltbData.MainExtra
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_MainExtraFormat", Value = HltbGameData.GetData().GameHltbData.MainExtraFormat
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_Completionist", Value = HltbGameData.GetData().GameHltbData.Completionist
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_CompletionistFormat", Value = HltbGameData.GetData().GameHltbData.CompletionistFormat
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_Solo", Value = HltbGameData.GetData().GameHltbData.Solo
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_SoloFormat", Value = HltbGameData.GetData().GameHltbData.SoloFormat
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_CoOp", Value = HltbGameData.GetData().GameHltbData.CoOp
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_CoOpFormat", Value = HltbGameData.GetData().GameHltbData.CoOpFormat
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_Vs", Value = HltbGameData.GetData().GameHltbData.Vs
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Htlb_VsFormat", Value = HltbGameData.GetData().GameHltbData.VsFormat
                            });
                            ui.AddResources(resourcesLists);

                            // Add button in action bar
                            if (settings.EnableIntegrationButton)
                            {
                                Button HltbButton     = new Button();
                                HltbButton.Name       = "PART_HltbButton";
                                HltbButton.FontFamily = new FontFamily(new Uri("pack://application:,,,/HowLongToBeat;component/Resources/"), "./#font");
                                HltbButton.Margin     = new Thickness(10, 0, 0, 0);
                                HltbButton.Click     += OnBtGameSelectedActionBarClick;
                                HltbButton.Content    = TransformIcon.Get("HowLongToBeat");

                                ui.AddButtonInGameSelectedActionBarButtonOrToggleButton(HltbButton);
                            }


                            // Auto integration
                            if (settings.EnableIntegrationInDescription)
                            {
                                StackPanel spHltb = CreateHltb(GameSelected.Playtime, HltbGameData.GetData(), settings.IntegrationShowTitle);
                                spHltb.Name       = "PART_HltbProgressBarIntegration";

                                ui.AddElementInGameSelectedDescription(spHltb, settings.IntegrationTopGameDetails);
                            }

                            // Custom theme
                            if (settings.EnableIntegrationInCustomTheme)
                            {
                                // Create
                                StackPanel spHltb           = CreateHltb(GameSelected.Playtime, HltbGameData.GetData(), true);
                                UserControl hltbProgressBar = new HltbProgressBar(GameSelected.Playtime, HltbGameData.GetData(), settings);

                                ui.AddElementInCustomTheme(spHltb, "PART_hltbProgressBarWithTitle");
                                ui.AddElementInCustomTheme(hltbProgressBar, "PART_hltbProgressBar");
                            }
                        }
                    }));
                });
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "HowLongToBeat", "Impossible integration");
            }
        }