コード例 #1
0
        public SuccessStory(IPlayniteAPI api) : base(api)
        {
            settings = new SuccessStorySettings(this);

            // Get plugin's location
            pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            // Add plugin localization in application ressource.
            PluginCommon.Localization.SetPluginLanguage(pluginFolder, api.ApplicationSettings.Language);
            // Add common in application ressource.
            PluginCommon.Common.Load(pluginFolder);

            // Check version
            if (settings.EnableCheckVersion)
            {
                CheckVersion cv = new CheckVersion();

                if (cv.Check("SuccessStory", pluginFolder))
                {
                    cv.ShowNotification(api, "SuccessStory - " + resources.GetString("LOCUpdaterWindowTitle"));
                }
            }

            // Init ui interagration
            successStoryUI = new SuccessStoryUI(api, settings, this.GetPluginUserDataPath(), this);

            // Custom theme button
            if (settings.EnableIntegrationInCustomTheme)
            {
                EventManager.RegisterClassHandler(typeof(Button), Button.ClickEvent, new RoutedEventHandler(successStoryUI.OnCustomThemeButtonClick));
            }

            // Load database
            var TaskLoadDatabase = Task.Run(() =>
            {
                achievementsDatabase = new AchievementsDatabase(this, PlayniteApi, settings, this.GetPluginUserDataPath());
                achievementsDatabase.Initialize();
            });

            // Add Event for WindowBase for get the "WindowSettings".
            EventManager.RegisterClassHandler(typeof(Window), Window.LoadedEvent, new RoutedEventHandler(WindowBase_LoadedEvent));
        }
    // LOGIC

    public void Initialize(string i_DatabaseResourcePath)
    {
        AchievementsDatabase database = Resources.Load <AchievementsDatabase>(i_DatabaseResourcePath);

        if (database != null)
        {
            foreach (string key in database.keys)
            {
                Achievement achievement = database.GetAchievement(key);
                if (achievement != null)
                {
                    int hash = StringUtils.GetHashCode(key);
                    m_Achievements.Add(hash, achievement);
                    m_AchievementsIds.Add(hash);
                }
            }
        }
        else
        {
            LogManager.LogWarning(this, "Database not loaded.");
        }
    }
コード例 #3
0
        private async Task <GameAchievements> LoadData(IPlayniteAPI PlayniteApi, string PluginUserDataPath, SuccessStorySettings settings)
        {
            // Refresh database
            if (SuccessStory.isFirstLoad)
            {
                achievementsDatabase = new AchievementsDatabase(PlayniteApi, settings, this.GetPluginUserDataPath());
                achievementsDatabase.Initialize();
                SuccessStory.isFirstLoad = false;
            }

            GameAchievements SelectedGameAchievements = achievementsDatabase.Get(GameSelected.Id);

            // Download Achievements if not exist in database.
            if (SelectedGameAchievements == null)
            {
                logger.Info("SuccessStory - Download achievements for " + GameSelected.Name);
                achievementsDatabase.Add(GameSelected, settings);
                achievementsDatabase.Initialize();
                SelectedGameAchievements = achievementsDatabase.Get(GameSelected.Id);
            }

            return(SelectedGameAchievements);
        }
コード例 #4
0
    // Use this for initialization
    void Start()
    {
        database = GetComponent <AchievementsDatabase>();
        // How many slots
        slotAmount = database.getCount();
        // Find InventoryPanel and instantiate slots
        achievementPanel = GameObject.Find("AchievementPanel");
        slotPanel        = achievementPanel.transform.Find("SlotPanel").gameObject;
        //slotPanel.GetComponent<GridLayoutGroup>().cellSize = new Vector2(GameObject.Find("AchievementPanel").GetComponent<RectTransform>().rect.width, 80);
        for (int i = 0; i < slotAmount; i++)
        {
            achivements.Add(new Achievement());
            slots.Add(GameObject.Instantiate(inventorySlot));
            slots[i].transform.SetParent(slotPanel.transform);
            slots[i].transform.position = new Vector3(0, 0, 0);
        }

        int[] aquired = PlayerPrefsX.GetIntArray("AnimalsAquired");
        for (int i = 0; i < database.getCount(); i++)
        {
            addAchievement(i);
        }
    }
コード例 #5
0
        // Create FrameworkElement with achievements datas
        public StackPanel CreateSc(AchievementsDatabase achievementsDatabase, GameAchievements SelectedGameAchievements, bool ShowTitle, bool ShowGraphic, bool ShowAchievements, bool ShowProgressBar, bool IsCustom = false)
        {
            StackPanel spA = new StackPanel();

            spA.Name = "PART_Achievements";

            if (ShowTitle)
            {
                TextBlock tbA = new TextBlock();
                tbA.Name   = "PART_Achievements_TextBlock";
                tbA.Text   = resources.GetString("LOCSucessStoryAchievements");
                tbA.Style  = (Style)resources.GetResource("BaseTextBlockStyle");
                tbA.Margin = new Thickness(0, 15, 0, 10);

                Separator sep = new Separator();
                sep.Name       = "PART_Achievements_Separator";
                sep.Background = (Brush)resources.GetResource("PanelSeparatorBrush");

                spA.Children.Add(tbA);
                spA.Children.Add(sep);
                spA.UpdateLayout();
            }

            if (ShowGraphic)
            {
                StackPanel spAG = new StackPanel();
                if (!IsCustom)
                {
                    spAG.Name      = "PART_Achievements_Graphics";
                    spAG.Height    = 120;
                    spAG.MaxHeight = 120;
                    spAG.Margin    = new Thickness(0, 5, 0, 5);
                }

                AchievementsGraphicsDataCount GraphicsData = null;
                if (settings.GraphicAllUnlockedByDay)
                {
                    GraphicsData = achievementsDatabase.GetCountByMonth(GameSelected.Id);
                }
                else
                {
                    GraphicsData = achievementsDatabase.GetCountByDay(GameSelected.Id);
                }
                string[]         StatsGraphicsAchievementsLabels = GraphicsData.Labels;
                SeriesCollection StatsGraphicAchievementsSeries  = new SeriesCollection();
                StatsGraphicAchievementsSeries.Add(new LineSeries
                {
                    Title  = "",
                    Values = GraphicsData.Series
                });

                spAG.Children.Add(new SuccessStoryAchievementsGraphics(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels));

                spA.Children.Add(spAG);
                spA.UpdateLayout();
            }

            if (ShowProgressBar)
            {
                StackPanel spPB = new StackPanel();
                if (!IsCustom)
                {
                    spPB.Name   = "PART_Achievements_ProgressBar";
                    spPB.Height = 40;
                    spPB.Margin = new Thickness(0, 5, 0, 5);
                }

                spPB.Children.Add(new SuccessStoryAchievementsProgressBar(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total, settings.IntegrationShowProgressBarPercent, settings.IntegrationShowProgressBarIndicator));

                spA.Children.Add(spPB);
                spA.UpdateLayout();
            }

            if (ShowAchievements)
            {
                StackPanel spAL = new StackPanel();
                if (!IsCustom)
                {
                    spAL.Name      = "PART_Achievements_List";
                    spAL.MaxHeight = 300;
                    spAL.Margin    = new Thickness(0, 5, 0, 5);
                }

                spAL.Children.Add(new SuccessStoryAchievementsList(SelectedGameAchievements.Achievements));

                spA.Children.Add(spAL);
                spA.UpdateLayout();
            }

            return(spA);
        }
コード例 #6
0
    // Use this for initialization
    void Start()
    {
        database  = gameObject.GetComponent <QuestionsDatabase>();
        aDatabase = gameObject.GetComponent <AchievementsDatabase>();

        allocButton = new List <Button>();
        allocAnswer = new bool[4];
        allocated   = new bool[4];
        answerText  = new string[4];
        System.Random srand = new System.Random();

        int      rand          = 0;
        int      correctAnswer = srand.Next(1, 4); // change this
        Question question      = database.FetchQuestionByID(DataManager.animalClicked);

        answerText[0] = question.answer1;
        answerText[1] = question.answer2;
        answerText[2] = question.answer3;
        answerText[3] = question.answer4;

        while (allocButton.Count != 4)
        {
            rand = srand.Next(0, 4);

            if (!allocated[rand] && !allocAnswer[rand])
            {
                buttons[rand].transform.GetChild(0).GetComponent <Text>().text = answerText[rand];
                if (rand == correctAnswer - 1)
                {
                    buttons[rand].onClick.AddListener(() => {
                        PlayerPrefs.SetInt("goldcoins", PlayerPrefs.GetInt("goldcoins") + 5);
                        PlayerPrefs.SetInt("answeredQuestion", PlayerPrefs.GetInt("answeredQuestion") + 1);

                        // Check if achieved something
                        Achievement answeredAchievement = aDatabase.FetchAchievementByName("Answer 3 Questions");
                        // Get user Achievements
                        bool[] userAchievements = PlayerPrefsX.GetBoolArray("userAchievements");
                        if (userAchievements.Length == 0)
                        {
                            userAchievements = new bool[aDatabase.getCount()];
                        }
                        if (answeredAchievement.requirement <= PlayerPrefs.GetInt("answeredQuestion") && !userAchievements[answeredAchievement.id])
                        {
                            PlayerPrefs.SetInt("goldcoins", PlayerPrefs.GetInt("goldcoins") + answeredAchievement.reward_gold);
                            PlayerPrefs.SetInt("exp", PlayerPrefs.GetInt("exp") + answeredAchievement.reward_exp);
                            achieved = true;

                            // Copy Achievements and save new
                            bool[] dummy = new bool[aDatabase.getCount()];
                            for (int i = 0; i < userAchievements.Length; i++)
                            {
                                dummy[i] = userAchievements[i];
                            }
                            dummy[answeredAchievement.id] = true;
                            PlayerPrefsX.SetBoolArray("userAchievements", dummy);
                        }
                        // Save
                        PlayerPrefs.Save();
                        rewardSound.Play();
                        correctPanel.SetActive(true);
                    });
                }
                else
                {
                    buttons[rand].onClick.AddListener(() => {
                        wrongPanel.SetActive(true);
                        wrongSound.Play();
                    });
                }
                allocButton.Add(buttons[rand]);
                allocated[rand]   = true;
                allocAnswer[rand] = true;
            }
        }

        correctPanel.transform.GetChild(1).GetComponent <Button>().onClick.AddListener(() => {
            if (achieved)
            {
                correctPanel.SetActive(false);
                achievedPanel.SetActive(true);
                rewardSound.Play();
            }
            else
            {
                GameObject.Find("SceneManager").GetComponent <ScreenManager>().returnToMenu();
            }
        });

        achievedPanel.transform.GetChild(1).GetComponent <Button>().onClick.AddListener(() => {
            GameObject.Find("SceneManager").GetComponent <ScreenManager>().returnToMenu();
        });

        wrongPanel.transform.GetChild(1).GetComponent <Button>().onClick.AddListener(() => {
            GameObject.Find("SceneManager").GetComponent <ScreenManager>().returnToMenu();
        });

        questionImage.GetComponent <Image>().sprite = Resources.Load <Sprite>("Sprite/AnimalInfoImage/" + question.animal_name + "/" + correctAnswer);
    }
コード例 #7
0
        private void Integration()
        {
            bool noAchievements = false;

            try
            {
                AchievementsDatabase achievementsDatabase = new AchievementsDatabase(PlayniteApi, this.GetPluginUserDataPath());
                achievementsDatabase.Initialize();

                GameAchievements SelectedGameAchievements = achievementsDatabase.Get(GameSelected.Id);

                // Download Achievements if not exist in database.
                if (SelectedGameAchievements == null)
                {
                    logger.Info("SuccesStory - Download achievements for " + GameSelected.Name);
                    achievementsDatabase.Add(GameSelected, settings);
                    achievementsDatabase.Initialize();
                    SelectedGameAchievements = achievementsDatabase.Get(GameSelected.Id);
                }

                if (SelectedGameAchievements == null || !SelectedGameAchievements.HaveAchivements)
                {
                    logger.Info("SuccessStory - No achievement for " + GameSelected.Name);

                    if (settings.EnableIntegrationInDescription || settings.EnableIntegrationInDescriptionWithToggle)
                    {
                        Button PART_ScButton = (Button)LogicalTreeHelper.FindLogicalNode(PART_ActionButtons, "PART_ScButton");
                        // Delete old ButtonDetails
                        if (settings.EnableIntegrationButtonDetails)
                        {
                            PART_ActionButtons.Children.Remove(PART_ScButton);
                            PART_ScButton = null;
                        }

                        ToggleButton PART_ScToggleButton = (ToggleButton)LogicalTreeHelper.FindLogicalNode(PART_ActionButtons, "PART_ScToggleButton");
                        // Delete old ToggleDetails
                        if (settings.IntegrationToggleDetails)
                        {
                            PART_ActionButtons.Children.Remove(PART_ScToggleButton);
                            PART_ScToggleButton = null;
                        }

                        // Delete old
                        string     NameControl       = "PART_Achievements";
                        StackPanel PART_Achievements = (StackPanel)LogicalTreeHelper.FindLogicalNode(PART_ElemDescription, NameControl);
                        if (PART_Achievements != null)
                        {
                            PART_ElemDescription.Children.Remove(PART_Achievements);
                        }
                    }

                    noAchievements = true;
                }

                // Auto integration
                if (settings.EnableIntegrationInDescription || settings.EnableIntegrationInDescriptionWithToggle)
                {
                    // Search parent action buttons
                    if (PART_ActionButtons == null)
                    {
                        foreach (Button bt in Tools.FindVisualChildren <Button>(Application.Current.MainWindow))
                        {
                            if (bt.Name == "PART_ButtonEditGame")
                            {
                                PART_ActionButtons = (StackPanel)bt.Parent;
                                break;
                            }
                        }
                    }

                    //Adding togglebutton
                    if (settings.EnableIntegrationInDescriptionWithToggle && PART_ActionButtons != null)
                    {
                        ToggleButton PART_ScToggleButton = (ToggleButton)LogicalTreeHelper.FindLogicalNode(PART_ActionButtons, "PART_ScToggleButton");

                        // Delete old ToggleDetails
                        if (settings.IntegrationToggleDetails)
                        {
                            PART_ActionButtons.Children.Remove(PART_ScToggleButton);
                            PART_ScToggleButton = null;
                        }

                        if (PART_ScToggleButton == null && !noAchievements)
                        {
                            ToggleButton tb = new ToggleButton();
                            if (settings.IntegrationToggleDetails)
                            {
                                tb = new SuccessStoryToggleButtonDetails(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total);
                            }
                            else
                            {
                                tb.Content = resources.GetString("LOCSucessStoryAchievements");
                            }

                            tb.IsChecked           = false;
                            tb.Name                = "PART_ScToggleButton";
                            tb.Width               = 150;
                            tb.Height              = 40;
                            tb.HorizontalAlignment = HorizontalAlignment.Right;
                            tb.VerticalAlignment   = VerticalAlignment.Stretch;
                            tb.Margin              = new Thickness(10, 0, 0, 0);
                            tb.Click              += ScToggleButton_Click;

                            PART_ActionButtons.Children.Add(tb);
                            PART_ActionButtons.UpdateLayout();
                        }
                    }

                    // Search game description
                    if (PART_ElemDescription == null)
                    {
                        foreach (StackPanel sp in Tools.FindVisualChildren <StackPanel>(Application.Current.MainWindow))
                        {
                            if (sp.Name == "PART_ElemDescription")
                            {
                                PART_ElemDescription = sp;
                                break;
                            }
                        }
                    }

                    // Adding control
                    if (PART_ElemDescription != null)
                    {
                        // Delete old
                        string     NameControl       = "PART_Achievements";
                        StackPanel PART_Achievements = (StackPanel)LogicalTreeHelper.FindLogicalNode(PART_ElemDescription, NameControl);
                        if (PART_Achievements != null)
                        {
                            if (settings.EnableIntegrationInDescription)
                            {
                                PART_ElemDescription.Children.Remove(PART_Achievements);
                            }
                            if (settings.EnableIntegrationInDescriptionWithToggle)
                            {
                                PART_ElemDescription.Children.Remove(PART_Achievements);
                            }
                        }
                        else
                        {
                            logger.Error($"SuccessStory - {NameControl} not found in Integration()");
                        }

                        if (SelectedGameAchievements != null && SelectedGameAchievements.HaveAchivements)
                        {
                            StackPanel ScA = CreateSc(achievementsDatabase, SelectedGameAchievements, settings.IntegrationShowTitle, settings.IntegrationShowGraphic, settings.IntegrationShowAchievements, false);

                            if (settings.EnableIntegrationInDescription)
                            {
                                // Add
                                if (settings.IntegrationTopGameDetails)
                                {
                                    PART_ElemDescription.Children.Insert(0, ScA);
                                }
                                else
                                {
                                    PART_ElemDescription.Children.Add(ScA);
                                }

                                PART_ElemDescription.UpdateLayout();
                            }

                            if (settings.EnableIntegrationInDescriptionWithToggle)
                            {
                                ScA.Visibility = Visibility.Collapsed;
                                PART_ElemDescription.Children.Add(ScA);
                                PART_ElemDescription.UpdateLayout();
                            }
                        }
                    }
                    else
                    {
                        logger.Error($"SuccessStory - PART_ElemDescription not found in Integration()");
                    }
                }

                // Auto adding button
                if (settings.EnableIntegrationButton || settings.EnableIntegrationButtonDetails)
                {
                    // Search parent action buttons
                    if (PART_ActionButtons == null)
                    {
                        foreach (Button bt in Tools.FindVisualChildren <Button>(Application.Current.MainWindow))
                        {
                            if (bt.Name == "PART_ButtonEditGame")
                            {
                                PART_ActionButtons = (StackPanel)bt.Parent;
                                break;
                            }
                        }
                    }

                    // Adding button
                    if (PART_ActionButtons != null)
                    {
                        Button PART_ScButton = (Button)LogicalTreeHelper.FindLogicalNode(PART_ActionButtons, "PART_ScButton");

                        // Delete old ButtonDetails
                        if (settings.EnableIntegrationButtonDetails)
                        {
                            PART_ActionButtons.Children.Remove(PART_ScButton);
                            PART_ScButton = null;
                        }

                        if (PART_ScButton == null)
                        {
                            Button bt = new Button();

                            if (settings.EnableIntegrationButton)
                            {
                                bt.Content = resources.GetString("LOCSucessStoryAchievements");
                            }

                            if (settings.EnableIntegrationButtonDetails)
                            {
                                bt = new SuccessStoryButtonDetails(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total);
                            }

                            bt.Name   = "PART_ScButton";
                            bt.Width  = 150;
                            bt.Height = 40;
                            bt.HorizontalAlignment = HorizontalAlignment.Right;
                            bt.VerticalAlignment   = VerticalAlignment.Stretch;
                            bt.Margin = new Thickness(10, 0, 0, 0);
                            bt.Click += ScButton_Click;

                            PART_ActionButtons.Children.Add(bt);
                            PART_ActionButtons.UpdateLayout();
                        }
                    }
                }


                // Custom theme
                if (settings.EnableIntegrationInCustomTheme)
                {
                    // Search custom element
                    foreach (StackPanel sp in Tools.FindVisualChildren <StackPanel>(Application.Current.MainWindow))
                    {
                        if (sp.Name == "PART_Achievements_Graphics")
                        {
                            if (SelectedGameAchievements != null && SelectedGameAchievements.HaveAchivements)
                            {
                                // Create
                                StackPanel scAG = CreateSc(achievementsDatabase, SelectedGameAchievements, false, true, false, true);

                                // Clear & add
                                sp.Children.Clear();
                                sp.Children.Add(scAG);
                                sp.UpdateLayout();
                            }
                            else
                            {
                                sp.Children.Clear();
                                sp.UpdateLayout();
                            }
                        }

                        if (sp.Name == "PART_Achievements_List")
                        {
                            if (SelectedGameAchievements != null && SelectedGameAchievements.HaveAchivements)
                            {
                                // Create
                                StackPanel scAL = CreateSc(achievementsDatabase, SelectedGameAchievements, false, false, true, true);

                                // Clear & add
                                sp.Children.Clear();
                                sp.Children.Add(scAL);
                                sp.UpdateLayout();
                            }
                            else
                            {
                                sp.Children.Clear();
                                sp.UpdateLayout();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var    LineNumber = new StackTrace(ex, true).GetFrame(0).GetFileLineNumber();
                string FileName   = new StackTrace(ex, true).GetFrame(0).GetFileName();
                logger.Error(ex, $"SuccessStory [{FileName} {LineNumber}] - Impossible integration ");
            }
        }
コード例 #8
0
        public SuccessView(SuccessStorySettings settings, IPlayniteAPI PlayniteApi, string PluginUserDataPath, Game GameSelected = null)
        {
            this.PlayniteApi        = PlayniteApi;
            PlayniteApiDatabase     = PlayniteApi.Database;
            PlayniteApiPaths        = PlayniteApi.Paths;
            this.settings           = settings;
            this.PluginUserDataPath = PluginUserDataPath;


            AchievementsDatabase = new AchievementsDatabase(PlayniteApi, settings, PluginUserDataPath);
            AchievementsDatabase.Initialize();

            InitializeComponent();

            // Block hidden column.
            lvProgressionValue.IsEnabled = false;
            lvSourceName.IsEnabled       = false;


            pbProgressionGlobalCount.Value      = AchievementsDatabase.Progession().Unlocked;
            pbProgressionGlobalCount.Maximum    = AchievementsDatabase.Progession().Total;
            labelProgressionGlobalCount.Content = AchievementsDatabase.Progession().Progression + "%";

            pbProgressionLaunchedCount.Value      = AchievementsDatabase.ProgessionLaunched().Unlocked;
            pbProgressionLaunchedCount.Maximum    = AchievementsDatabase.ProgessionLaunched().Total;
            labelProgressionLaunchedCount.Content = AchievementsDatabase.ProgessionLaunched().Progression + "%";


            GetListGame();


            AchievementsGraphicsDataCount GraphicsData = null;

            if (settings.GraphicAllUnlockedByMonth)
            {
                GraphicTitleALL.Content = resources.GetString("LOCSucessStoryGraphicTitleALL");
                GraphicsData            = AchievementsDatabase.GetCountByMonth(null, 7);
            }
            else
            {
                GraphicTitleALL.Content = resources.GetString("LOCSucessStoryGraphicTitleALLDay");
                GraphicsData            = AchievementsDatabase.GetCountByDay();
            }
            string[]         StatsGraphicsAchievementsLabels = GraphicsData.Labels;
            SeriesCollection StatsGraphicAchievementsSeries  = new SeriesCollection();

            StatsGraphicAchievementsSeries.Add(new LineSeries
            {
                Title  = "",
                Values = GraphicsData.Series
            });

            SuccessStory_Achievements_Graphics.Children.Clear();
            SuccessStory_Achievements_Graphics.Children.Add(new SuccessStoryAchievementsGraphics(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels));
            SuccessStory_Achievements_Graphics.UpdateLayout();

            // Set game selected
            if (GameSelected != null)
            {
                for (int i = 0; i < ListviewGames.Items.Count; i++)
                {
                    if (((ListGames)ListviewGames.Items[i]).Name == GameSelected.Name)
                    {
                        ListviewGames.SelectedIndex = i;
                    }
                }
            }
            ListviewGames.ScrollIntoView(ListviewGames.SelectedItem);


            if (settings.EnableLocal)
            {
                //FilterSource.Items.Add(new { SourceName = "Playnite", IsCheck = false });
                FilterSourceItems.Add(new ListSource {
                    SourceName = "Playnite", IsCheck = false
                });
            }
            if (settings.EnableSteam)
            {
                //FilterSource.Items.Add(new { SourceName = "Steam", IsCheck = false });
                FilterSourceItems.Add(new ListSource {
                    SourceName = "Steam", IsCheck = false
                });
            }
            if (settings.EnableGog)
            {
                //FilterSource.Items.Add(new { SourceName = "GOG", IsCheck = false });
                FilterSourceItems.Add(new ListSource {
                    SourceName = "GOG", IsCheck = false
                });
            }
            if (settings.EnableOrigin)
            {
                //FilterSource.Items.Add(new { SourceName = "Origin", IsCheck = false });
                FilterSourceItems.Add(new ListSource {
                    SourceName = "Origin", IsCheck = false
                });
            }
            if (settings.EnableOrigin)
            {
                //FilterSource.Items.Add(new { SourceName = "Origin", IsCheck = false });
                FilterSourceItems.Add(new ListSource {
                    SourceName = "RetroAchievements", IsCheck = false
                });
            }
            //FilterSource.UpdateLayout();
            FilterSource.ItemsSource = FilterSourceItems;

            SetGraphicsAchievementsSources();

            // Set Binding data
            DataContext = this;
        }
コード例 #9
0
        public void SetScData(SuccessStorySettings settings, AchievementsDatabase achievementsDatabase, GameAchievements SelectedGameAchievements)
        {
            if (!settings.IntegrationShowTitle || _IsCustom)
            {
                PART_Title.Visibility     = Visibility.Collapsed;
                PART_Separator.Visibility = Visibility.Collapsed;
            }

#if DEBUG
            logger.Debug($"SuccessStory - _IsCustom: {_IsCustom} - _ShowAchievementsGraphic: {_ShowAchievementsGraphic} - _ShowAchievementsList: {_ShowAchievementsList} - _ShowAchievementsCompactLocked: {_ShowAchievementsCompactLocked} - _ShowAchievementsCompactUnlocked: {_ShowAchievementsCompactUnlocked} - _ShowProgressBar: {_ShowProgressBar}");
#endif

            bool Show = true;

            if (SelectedGameAchievements == null || !SelectedGameAchievements.HaveAchivements)
            {
                return;
            }

            PART_SuccessStory_ProgressBar.Visibility = Visibility.Collapsed;
            if (settings.IntegrationShowProgressBar)
            {
                Show = true;
                if (_IsCustom && !_ShowProgressBar)
                {
                    Show = false;
                }

#if DEBUG
                logger.Debug($"SuccessStory - PART_SuccessStory_ProgressBar - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}");
#endif
                if (Show)
                {
                    PART_SuccessStory_ProgressBar.Visibility = Visibility.Visible;

                    if (successStoryAchievementsProgressBar == null)
                    {
                        successStoryAchievementsProgressBar = new SuccessStoryAchievementsProgressBar();

                        if (!_IsCustom)
                        {
                            PART_SuccessStory_ProgressBar.Height = 40;
                            PART_SuccessStory_ProgressBar.Margin = new Thickness(0, 5, 0, 5);
                        }

                        PART_SuccessStory_ProgressBar.Children.Add(successStoryAchievementsProgressBar);
                    }

                    successStoryAchievementsProgressBar.SetScData(SelectedGameAchievements.Unlocked, SelectedGameAchievements.Total, settings.IntegrationShowProgressBarPercent, settings.IntegrationShowProgressBarIndicator, _IsCustom);
                }
            }

            PART_SuccessStory_Graphic.Visibility = Visibility.Collapsed;
            if (settings.IntegrationShowGraphic)
            {
                Show = true;
                if (_IsCustom && !_ShowAchievementsGraphic)
                {
                    Show = false;
                }

#if DEBUG
                logger.Debug($"SuccessStory - PART_SuccessStory_Graphic - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}");
#endif
                if (Show)
                {
                    PART_SuccessStory_Graphic.Visibility = Visibility.Visible;

                    AchievementsGraphicsDataCount GraphicsData = null;
                    if (!settings.GraphicAllUnlockedByDay)
                    {
                        GraphicsData = achievementsDatabase.GetCountByMonth(SuccessStory.GameSelected.Id, (settings.IntegrationGraphicOptionsCountAbscissa - 1));
                    }
                    else
                    {
                        GraphicsData = achievementsDatabase.GetCountByDay(SuccessStory.GameSelected.Id, (settings.IntegrationGraphicOptionsCountAbscissa - 1));
                    }
                    string[]         StatsGraphicsAchievementsLabels = GraphicsData.Labels;
                    SeriesCollection StatsGraphicAchievementsSeries  = new SeriesCollection();
                    StatsGraphicAchievementsSeries.Add(new LineSeries
                    {
                        Title  = string.Empty,
                        Values = GraphicsData.Series
                    });

                    if (successStoryAchievementsGraphics == null)
                    {
                        successStoryAchievementsGraphics = new SuccessStoryAchievementsGraphics(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels, settings);

                        if (!_IsCustom)
                        {
                            PART_SuccessStory_Graphic.Height = settings.IntegrationShowGraphicHeight;
                            PART_SuccessStory_Graphic.Margin = new Thickness(0, 5, 0, 5);
                        }

                        PART_SuccessStory_Graphic.Children.Add(successStoryAchievementsGraphics);
                    }

                    successStoryAchievementsGraphics.SetScData(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels, settings);
                }
            }

            PART_SuccessStory_List.Visibility = Visibility.Collapsed;
            if (settings.IntegrationShowAchievements)
            {
                Show = true;
                if (_IsCustom && !_ShowAchievementsList)
                {
                    Show = false;
                }

#if DEBUG
                logger.Debug($"SuccessStory - PART_SuccessStory_List - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}");
#endif
                if (Show)
                {
                    PART_SuccessStory_List.Visibility = Visibility.Visible;

                    if (successStoryAchievementsList == null)
                    {
                        successStoryAchievementsList = new SuccessStoryAchievementsList();

                        if (!_IsCustom)
                        {
                            PART_SuccessStory_List.Height = settings.IntegrationShowAchievementsHeight;
                            PART_SuccessStory_List.Margin = new Thickness(0, 5, 0, 5);
                        }

                        PART_SuccessStory_List.Children.Add(successStoryAchievementsList);
                    }

                    successStoryAchievementsList.SetScData(SelectedGameAchievements.Achievements, _IsCustom, settings.EnableRaretyIndicator);
                }
            }

            PART_SuccessStory_Compact_Locked.Visibility = Visibility.Collapsed;
            if (settings.IntegrationShowAchievementsCompactLocked)
            {
                Show = true;
                if (_IsCustom && !_ShowAchievementsCompactLocked)
                {
                    Show = false;
                }

#if DEBUG
                logger.Debug($"SuccessStory - PART_SuccessStory_Compact_Locked - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}");
#endif
                if (Show)
                {
                    PART_SuccessStory_Compact_Locked.Visibility = Visibility.Visible;

                    if (successStoryAchievementsCompact_Locked == null)
                    {
                        successStoryAchievementsCompact_Locked = new SuccessStoryAchievementsCompact(SelectedGameAchievements.Achievements, false, settings.EnableRaretyIndicator);

                        if (!_IsCustom)
                        {
                            PART_SuccessStory_Compact_Locked.Margin = new Thickness(0, 5, 0, 5);
                            PART_SuccessStory_Compact_Locked.Height = successStoryAchievementsCompact_Locked.Height;
                        }

                        PART_SuccessStory_Compact_Locked.Children.Add(successStoryAchievementsCompact_Locked);
                    }

                    successStoryAchievementsCompact_Locked.SetScData(SelectedGameAchievements.Achievements, false, settings.EnableRaretyIndicator);
                }
            }

            PART_SuccessStory_Compact_Unlocked.Visibility = Visibility.Collapsed;
            if (settings.IntegrationShowAchievementsCompactUnlocked)
            {
                Show = true;
                if (_IsCustom && !_ShowAchievementsCompactUnlocked)
                {
                    Show = false;
                }

#if DEBUG
                logger.Debug($"SuccessStory - PART_SuccessStory_Compact_Unlocked - Show: {Show} - SelectedGameAchievements: {JsonConvert.SerializeObject(SelectedGameAchievements)}");
#endif
                if (Show)
                {
                    PART_SuccessStory_Compact_Unlocked.Visibility = Visibility.Visible;

                    if (successStoryAchievementsCompact_Unlocked == null)
                    {
                        successStoryAchievementsCompact_Unlocked = new SuccessStoryAchievementsCompact(SelectedGameAchievements.Achievements, true, settings.EnableRaretyIndicator);

                        if (!_IsCustom)
                        {
                            PART_SuccessStory_Compact_Unlocked.Margin = new Thickness(0, 5, 0, 5);
                            PART_SuccessStory_Compact_Unlocked.Height = successStoryAchievementsCompact_Unlocked.Height;
                        }

                        PART_SuccessStory_Compact_Unlocked.Children.Add(successStoryAchievementsCompact_Unlocked);
                    }

                    successStoryAchievementsCompact_Unlocked.SetScData(SelectedGameAchievements.Achievements, true, settings.EnableRaretyIndicator);
                }
            }
        }
コード例 #10
0
        public SuccessView(SuccessStory plugin, SuccessStorySettings settings, IPlayniteAPI PlayniteApi, string PluginUserDataPath, bool isRetroAchievements = false, Game GameSelected = null)
        {
            this.plugin             = plugin;
            this._PlayniteApi       = PlayniteApi;
            _PlayniteApiDatabase    = PlayniteApi.Database;
            _PlayniteApiPaths       = PlayniteApi.Paths;
            this.settings           = settings;
            this.PluginUserDataPath = PluginUserDataPath;


            InitializeComponent();


            PART_DataLoad.Visibility = Visibility.Visible;
            PART_Data.Visibility     = Visibility.Hidden;

            var TaskView = Task.Run(() =>
            {
                AchievementsDb = new AchievementsDatabase(plugin, PlayniteApi, settings, PluginUserDataPath, isRetroAchievements);
                AchievementsDb.Initialize(false);

                GetListGame();
                SetGraphicsAchievementsSources();

                AchievementsGraphicsDataCount GraphicsData = null;
                if (settings.GraphicAllUnlockedByMonth)
                {
                    GraphicsData = AchievementsDb.GetCountByMonth(null, 6);
                }
                else
                {
                    GraphicsData = AchievementsDb.GetCountByDay(null, 5);
                }

                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                {
                    // Block hidden column.
                    lvProgressionValue.IsEnabled = false;
                    lvSourceName.IsEnabled       = false;


                    pbProgressionGlobalCount.Value      = AchievementsDb.Progession().Unlocked;
                    pbProgressionGlobalCount.Maximum    = AchievementsDb.Progession().Total;
                    labelProgressionGlobalCount.Content = AchievementsDb.Progession().Progression + "%";

                    pbProgressionLaunchedCount.Value      = AchievementsDb.ProgessionLaunched().Unlocked;
                    pbProgressionLaunchedCount.Maximum    = AchievementsDb.ProgessionLaunched().Total;
                    labelProgressionLaunchedCount.Content = AchievementsDb.ProgessionLaunched().Progression + "%";


                    GraphicTitle.Content = string.Empty;


                    // lvGames options
                    if (!settings.lvGamesIcon100Percent)
                    {
                        lvGameIcon100Percent.Width = 0;
                    }
                    if (!settings.lvGamesIcon)
                    {
                        lvGameIcon.Width = 0;
                    }
                    if (!settings.lvGamesName)
                    {
                        lvGameName.Width = 0;
                    }
                    if (!settings.lvGamesLastSession)
                    {
                        lvGameLastActivity.Width = 0;
                    }
                    if (!settings.lvGamesSource)
                    {
                        lvGamesSource.Width = 0;
                    }
                    if (!settings.lvGamesProgression)
                    {
                        lvGameProgression.Width = 0;
                    }


                    if (settings.GraphicAllUnlockedByMonth)
                    {
                        GraphicTitleALL.Content = resources.GetString("LOCSuccessStoryGraphicTitleALL");
                    }
                    else
                    {
                        GraphicTitleALL.Content = resources.GetString("LOCSuccessStoryGraphicTitleALLDay");
                    }
                    string[] StatsGraphicsAchievementsLabels        = GraphicsData.Labels;
                    SeriesCollection StatsGraphicAchievementsSeries = new SeriesCollection();
                    StatsGraphicAchievementsSeries.Add(new LineSeries
                    {
                        Title  = string.Empty,
                        Values = GraphicsData.Series
                    });

                    SuccessStory_Achievements_Graphics.Children.Clear();
                    settings.IgnoreSettings = true;
                    SuccessStory_Achievements_Graphics.Children.Add(new SuccessStoryAchievementsGraphics(StatsGraphicAchievementsSeries, StatsGraphicsAchievementsLabels, settings));
                    SuccessStory_Achievements_Graphics.UpdateLayout();

                    // Set game selected
                    if (GameSelected != null)
                    {
                        for (int i = 0; i < ListviewGames.Items.Count; i++)
                        {
                            if (((ListViewGames)ListviewGames.Items[i]).Name == GameSelected.Name)
                            {
                                ListviewGames.SelectedIndex = i;
                            }
                        }
                    }
                    ListviewGames.ScrollIntoView(ListviewGames.SelectedItem);

                    string icon = string.Empty;

                    if (settings.EnableRetroAchievementsView && settings.EnableRetroAchievements)
                    {
                        if (isRetroAchievements)
                        {
                            PART_GraphicBySource.Visibility = Visibility.Collapsed;
                            Grid.SetColumn(PART_GraphicAllUnlocked, 0);
                            Grid.SetColumnSpan(PART_GraphicAllUnlocked, 3);

                            if (settings.EnableRetroAchievements)
                            {
                                icon = TransformIcon.Get("RetroAchievements") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "RetroAchievements", SourceNameShort = "RetroAchievements", IsCheck = false
                                });
                            }
                        }
                        else
                        {
                            if (settings.EnableLocal)
                            {
                                icon = TransformIcon.Get("Playnite") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Playnite", SourceNameShort = "Playnite", IsCheck = false
                                });
                            }
                            if (settings.EnableSteam)
                            {
                                icon = TransformIcon.Get("Steam") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Steam", SourceNameShort = "Steam", IsCheck = false
                                });
                            }
                            if (settings.EnableGog)
                            {
                                icon = TransformIcon.Get("GOG") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "GOG", SourceNameShort = "GOG", IsCheck = false
                                });
                            }
                            if (settings.EnableOrigin)
                            {
                                icon = TransformIcon.Get("Origin") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Origin", SourceNameShort = "Origin", IsCheck = false
                                });
                            }
                            if (settings.EnableXbox)
                            {
                                icon = TransformIcon.Get("Xbox") + " ";
                                FilterSourceItems.Add(new ListSource {
                                    SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Xbox", SourceNameShort = "Xbox", IsCheck = false
                                });
                            }
                        }
                    }
                    else
                    {
                        if (settings.EnableLocal)
                        {
                            icon = TransformIcon.Get("Playnite") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Playnite", SourceNameShort = "Playnite", IsCheck = false
                            });
                        }
                        if (settings.EnableSteam)
                        {
                            icon = TransformIcon.Get("Steam") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Steam", SourceNameShort = "Steam", IsCheck = false
                            });
                        }
                        if (settings.EnableGog)
                        {
                            icon = TransformIcon.Get("GOG") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "GOG", SourceNameShort = "GOG", IsCheck = false
                            });
                        }
                        if (settings.EnableOrigin)
                        {
                            icon = TransformIcon.Get("Origin") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Origin", SourceNameShort = "Origin", IsCheck = false
                            });
                        }
                        if (settings.EnableXbox)
                        {
                            icon = TransformIcon.Get("Xbox") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "Xbox", SourceNameShort = "Xbox", IsCheck = false
                            });
                        }
                        if (settings.EnableRetroAchievements)
                        {
                            icon = TransformIcon.Get("RetroAchievements") + " ";
                            FilterSourceItems.Add(new ListSource {
                                SourceName = ((icon.Length == 2) ? icon : string.Empty) + "RetroAchievements", SourceNameShort = "RetroAchievements", IsCheck = false
                            });
                        }
                    }

                    FilterSource.ItemsSource = FilterSourceItems;


                    // Set Binding data
                    DataContext = this;

                    PART_DataLoad.Visibility = Visibility.Hidden;
                    PART_Data.Visibility     = Visibility.Visible;
                });
            });
        }
コード例 #11
0
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        public void GetListGame()
        {
            string pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            try
            {
                if (ListGames.Count == 0)
                {
                    var dataGameAchievements = AchievementsDb.gameAchievements.Where(x => x.Value.HaveAchivements);
                    foreach (var item in dataGameAchievements)
                    {
                        Game   game       = _PlayniteApiDatabase.Games.Get(item.Key);
                        string SourceName = PlayniteTools.GetSourceName(game, _PlayniteApi);

                        if (AchievementsDatabase.VerifToAddOrShow(plugin, _PlayniteApi, SourceName, settings, PluginUserDataPath))
                        {
                            string   GameId           = game.Id.ToString();
                            string   GameName         = game.Name;
                            string   GameIcon         = string.Empty;
                            string   Icon100          = string.Empty;
                            DateTime?GameLastActivity = null;

                            GameAchievements GameAchievements = AchievementsDb.Get(game.Id);

                            if (game.LastActivity != null)
                            {
                                GameLastActivity = ((DateTime)game.LastActivity).ToLocalTime();
                            }

                            if (!game.Icon.IsNullOrEmpty())
                            {
                                GameIcon = _PlayniteApiDatabase.GetFullFilePath(game.Icon);
                            }

                            if (GameAchievements.Is100Percent)
                            {
                                Icon100 = Path.Combine(pluginFolder, "Resources\\badge.png");
                            }

                            ListGames.Add(new ListViewGames()
                            {
                                Icon100Percent   = Icon100,
                                Id               = GameId,
                                Name             = GameName,
                                Icon             = GameIcon,
                                LastActivity     = GameLastActivity,
                                SourceName       = SourceName,
                                SourceIcon       = TransformIcon.Get(SourceName),
                                ProgressionValue = GameAchievements.Progression,
                                Total            = GameAchievements.Total,
                                TotalPercent     = GameAchievements.Progression + "%",
                                Unlocked         = GameAchievements.Unlocked
                            });
                        }
                    }
                }

                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                {
                    ListviewGames.ItemsSource = ListGames;
                    Sorting();
                });
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SuccessStory", "Errorn on GetListGames()");
            }
        }