// 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); }
/// <summary> /// Valid the selection. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonSelect_Click(object sender, RoutedEventArgs e) { HltbDataUser Item = (HltbDataUser)lbSelectable.SelectedItem; gameHowLongToBeat = HowLongToBeat.PluginDatabase.GetDefault(_game); gameHowLongToBeat.Items = new List <HltbDataUser>() { Item }; ((Window)this.Parent).Close(); }
public void OnBtActionBarClick(object sender, RoutedEventArgs e) { GameHowLongToBeat gameHowLongToBeat = HowLongToBeat.PluginDatabase.Get(HowLongToBeatDatabase.GameSelected); if (gameHowLongToBeat.HasData || gameHowLongToBeat.HasDataEmpty) { var ViewExtension = new Views.HowLongToBeatView(_PlayniteApi, PluginDatabase.PluginSettings, gameHowLongToBeat); Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(_PlayniteApi, "HowLongToBeat", ViewExtension); windowExtension.ShowDialog(); var TaskIntegrationUI = Task.Run(() => { HowLongToBeat.howLongToBeatUI.RefreshElements(HowLongToBeatDatabase.GameSelected); }); } }
public void SetHltbData(GameHowLongToBeat gameHowLongToBeat) { _gameHowLongToBeat = gameHowLongToBeat; _Playtime = gameHowLongToBeat.Playtime; ShowToolTip = PluginDatabase.PluginSettings.ProgressBarShowToolTip; ShowTime = PluginDatabase.PluginSettings.ProgressBarShowTime; if (ShowToolTip) { PART_ShowToolTip.Visibility = Visibility.Visible; } else { PART_ShowToolTip.Visibility = Visibility.Collapsed; } LoadData(); }
public void SetData(GameHowLongToBeat GameSelectedData) { if (GameSelectedData.HasData) { this.Visibility = Visibility.Visible; } else { this.Visibility = Visibility.Collapsed; return; } string TimeToBeat = GameSelectedData.GetData().GameHltbData.TimeToBeatFormat; if (TimeToBeat == "--") { this.Visibility = Visibility.Collapsed; } else { PART_HltbTime.Text = TimeToBeat; } }
public override void RefreshElements(Game GameSelected, bool Force = false) { taskHelper.Check(); CancellationTokenSource tokenSource = new CancellationTokenSource(); CancellationToken ct = tokenSource.Token; Task TaskRefresh = Task.Run(() => { try { Initial(); // 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 = string.Empty }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainExtra", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainExtraFormat", Value = string.Empty }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Completionist", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CompletionistFormat", Value = string.Empty }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Solo", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_SoloFormat", Value = string.Empty }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CoOp", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CoOpFormat", Value = string.Empty }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Vs", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_VsFormat", Value = string.Empty }); resourcesLists.Add(new ResourcesList { Key = "Htlb_TimeToBeat", Value = 0 }); resourcesLists.Add(new ResourcesList { Key = "Htlb_TimeToBeatFormat", Value = string.Empty }); resourcesLists.Add(new ResourcesList { Key = "Htlb_EnableIntegrationInCustomTheme", Value = PluginDatabase.PluginSettings.EnableIntegrationInCustomTheme }); resourcesLists.Add(new ResourcesList { Key = "Htlb_ColorFirst", Value = new SolidColorBrush(PluginDatabase.PluginSettings.ColorFirst) }); resourcesLists.Add(new ResourcesList { Key = "Htlb_ColorSecond", Value = new SolidColorBrush(PluginDatabase.PluginSettings.ColorSecond) }); resourcesLists.Add(new ResourcesList { Key = "Htlb_ColorThird", Value = new SolidColorBrush(PluginDatabase.PluginSettings.ColorThird) }); resourcesLists.Add(new ResourcesList { Key = "Htlb_ColorFirstMulti", Value = new SolidColorBrush(PluginDatabase.PluginSettings.ColorFirstMulti) }); resourcesLists.Add(new ResourcesList { Key = "Htlb_ColorSecondMulti", Value = new SolidColorBrush(PluginDatabase.PluginSettings.ColorSecondMulti) }); resourcesLists.Add(new ResourcesList { Key = "Htlb_ColorThirdMulti", Value = new SolidColorBrush(PluginDatabase.PluginSettings.ColorThirdMulti) }); ui.AddResources(resourcesLists); // Load data if (!HowLongToBeat.PluginDatabase.IsLoaded) { return; } GameHowLongToBeat gameLocalizations = HowLongToBeat.PluginDatabase.Get(GameSelected, true); HltbDataUser hltbDataUser; if (gameLocalizations.HasData) { hltbDataUser = gameLocalizations.GetData(); resourcesLists = new List <ResourcesList>(); resourcesLists.Add(new ResourcesList { Key = "Htlb_HasData", Value = gameLocalizations.HasData }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainStory", Value = hltbDataUser.GameHltbData.MainStory }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainStoryFormat", Value = hltbDataUser.GameHltbData.MainStoryFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainExtra", Value = hltbDataUser.GameHltbData.MainExtra }); resourcesLists.Add(new ResourcesList { Key = "Htlb_MainExtraFormat", Value = hltbDataUser.GameHltbData.MainExtraFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Completionist", Value = hltbDataUser.GameHltbData.Completionist }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CompletionistFormat", Value = hltbDataUser.GameHltbData.CompletionistFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Solo", Value = hltbDataUser.GameHltbData.Solo }); resourcesLists.Add(new ResourcesList { Key = "Htlb_SoloFormat", Value = hltbDataUser.GameHltbData.SoloFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CoOp", Value = hltbDataUser.GameHltbData.CoOp }); resourcesLists.Add(new ResourcesList { Key = "Htlb_CoOpFormat", Value = hltbDataUser.GameHltbData.CoOpFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_Vs", Value = hltbDataUser.GameHltbData.Vs }); resourcesLists.Add(new ResourcesList { Key = "Htlb_VsFormat", Value = hltbDataUser.GameHltbData.VsFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_TimeToBeat", Value = hltbDataUser.GameHltbData.TimeToBeat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_TimeToBeatFormat", Value = hltbDataUser.GameHltbData.TimeToBeatFormat }); resourcesLists.Add(new ResourcesList { Key = "Htlb_EnableIntegrationInCustomTheme", Value = PluginDatabase.PluginSettings.EnableIntegrationInCustomTheme }); } else { logger.Warn("HowLongToBeat - No data for " + GameSelected.Name); } // If not cancel, show if (!ct.IsCancellationRequested && GameSelected.Id == HowLongToBeatDatabase.GameSelected.Id) { ui.AddResources(resourcesLists); if (_PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop) { HowLongToBeat.PluginDatabase.SetCurrent(gameLocalizations); } } } catch (Exception ex) { Common.LogError(ex, "HowLongToBeat", $"Error on TaskRefreshBtActionBar()"); } }, ct); taskHelper.Add(TaskRefresh, tokenSource); }
public void ConvertDB(IPlayniteAPI PlayniteApi) { GlobalProgressOptions globalProgressOptions = new GlobalProgressOptions( "HowLongToBeat - Database migration", false ); globalProgressOptions.IsIndeterminate = true; PlayniteApi.Dialogs.ActivateGlobalProgress((activateGlobalProgress) => { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); logger.Info($"HowLongToBeat - ConvertDB()"); int Converted = 0; foreach (var item in Items) { try { if (PlayniteApi.Database.Games.Get(item.Key) != null) { GameHowLongToBeat gameHowLongToBeat = HowLongToBeat.PluginDatabase.Get(item.Key, true); HltbDataUser hltbDataUser = new HltbDataUser { Id = item.Value.GameHltbData.Id, Name = item.Value.GameHltbData.Name, Url = item.Value.GameHltbData.Url, UrlImg = item.Value.GameHltbData.UrlImg, GameHltbData = new HltbData { MainStory = item.Value.GameHltbData.MainStory, MainExtra = item.Value.GameHltbData.MainExtra, Completionist = item.Value.GameHltbData.Completionist, Solo = item.Value.GameHltbData.Solo, CoOp = item.Value.GameHltbData.CoOp, Vs = item.Value.GameHltbData.Vs } }; gameHowLongToBeat.Items = new List <HltbDataUser> { hltbDataUser }; Thread.Sleep(10); HowLongToBeat.PluginDatabase.Add(gameHowLongToBeat); Converted++; } else { logger.Warn($"HowLongToBeat - Game is deleted - {item.Key.ToString()}"); } } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"Failed to load ConvertDB from {item.Key.ToString()}"); } } logger.Info($"HowLongToBeat - Converted {Converted} / {Items.Count}"); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; logger.Info($"HowLongToBeat - Migration - {String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)}"); }, globalProgressOptions); IsOld = false; }
public HowLongToBeatView(IPlayniteAPI PlayniteApi, HowLongToBeatSettings settings, GameHowLongToBeat gameHowLongToBeat) { _gameHowLongToBeat = gameHowLongToBeat; InitializeComponent(); HltbDataUser gameData = _gameHowLongToBeat.Items.FirstOrDefault(); if (gameData == null) { return; } if (_gameHowLongToBeat.HasData || _gameHowLongToBeat.HasDataEmpty) { CoverImage = gameData.UrlImg; if (!settings.ShowHltbImg) { if (!_gameHowLongToBeat.CoverImage.IsNullOrEmpty()) { CoverImage = PlayniteApi.Database.GetFullFilePath(_gameHowLongToBeat.CoverImage); } } GameName = _gameHowLongToBeat.Name; HltbName = resources.GetString("LOCSourceLabel") + ": " + gameData.Name; } if (_gameHowLongToBeat.HasData) { 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; TitleList titleList = PluginDatabase.GetUserHltbData(_gameHowLongToBeat.GetData().Id); if (gameData.GameHltbData.MainStory != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainStory"), gameData.GameHltbData.MainStoryFormat, (titleList != null) ? titleList.HltbUserData.MainStoryFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorFirst); } if (gameData.GameHltbData.MainExtra != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatMainExtra"), gameData.GameHltbData.MainExtraFormat, (titleList != null) ? titleList.HltbUserData.MainExtraFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorSecond); } if (gameData.GameHltbData.Completionist != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCompletionist"), gameData.GameHltbData.CompletionistFormat, (titleList != null) ? titleList.HltbUserData.CompletionistFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorThird); } if (gameData.GameHltbData.Solo != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatSolo"), gameData.GameHltbData.SoloFormat, (titleList != null) ? titleList.HltbUserData.SoloFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorFirstMulti); } if (gameData.GameHltbData.CoOp != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatCoOp"), gameData.GameHltbData.CoOpFormat, (titleList != null) ? titleList.HltbUserData.CoOpFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorSecondMulti); } if (gameData.GameHltbData.Vs != 0) { ElIndicator += 1; SetDataInView(ElIndicator, resources.GetString("LOCHowLongToBeatVs"), gameData.GameHltbData.VsFormat, (titleList != null) ? titleList.HltbUserData.VsFormat : string.Empty); SetColor(ElIndicator, PluginDatabase.PluginSettings.ColorThirdMulti); } LongToTimePlayedConverter converter = new LongToTimePlayedConverter(); PlaytimeFormat = (string)converter.Convert((long)_gameHowLongToBeat.Playtime, null, null, CultureInfo.CurrentCulture); hltbProgressBar = new HltbProgressBar(); PART_HltbProgressBar.Children.Add(hltbProgressBar); } // Set Binding data DataContext = this; }
// 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); }