コード例 #1
0
        private void SelectSavedLevelPack()
        {
            string lastLevelPackString = PluginConfig.LastLevelPackID;
            int    separatorPos        = lastLevelPackString.IndexOf(PluginConfig.LastLevelPackIDSeparator);

            if (separatorPos < 0 || separatorPos + PluginConfig.LastLevelPackIDSeparator.Length >= lastLevelPackString.Length)
            {
                goto OnError;
            }

            string lastLevelPackCollectionTitle = lastLevelPackString.Substring(0, separatorPos);
            string lastLevelPackID = lastLevelPackString.Substring(separatorPos + PluginConfig.LastLevelPackIDSeparator.Length);

            TabBarViewController tabBarVC = LevelFilteringNavigationController.GetPrivateField <TabBarViewController>("_tabBarViewController");

            TabBarViewController.TabBarItem[] tabBarItems = tabBarVC.GetPrivateField <TabBarViewController.TabBarItem[]>("_items");
            var item = tabBarItems.FirstOrDefault(x => x.title == lastLevelPackCollectionTitle);

            if (item == null)
            {
                goto OnError;
            }

            int itemIndex = Array.IndexOf(tabBarItems, item);

            if (itemIndex < 0)
            {
                goto OnError;
            }

            var tabBarDatas = LevelFilteringNavigationController.GetPrivateField <object[]>("_tabBarDatas");

            if (itemIndex >= tabBarDatas.Length)
            {
                goto OnError;
            }

            var levelPacks = tabBarDatas[itemIndex].GetField <IAnnotatedBeatmapLevelCollection[]>("annotatedBeatmapLevelCollections");
            IAnnotatedBeatmapLevelCollection levelPack = levelPacks.FirstOrDefault(x => x.collectionName == lastLevelPackID || (x is IBeatmapLevelPack && ((IBeatmapLevelPack)x).packID == lastLevelPackID));

            if (levelPack == null)
            {
                goto OnError;
            }

            // this should trigger the LevelPackSelected() delegate and sort the level pack as well
            LevelFilteringNavigationController.SelectAnnotatedBeatmapLevelCollection(levelPack);

            // try to select last level as well
            string[] lastLevelData = PluginConfig.LastLevelID.Split(new string[] { PluginConfig.LastLevelIDSeparator }, StringSplitOptions.None);
            if (lastLevelData.Length != 3)
            {
                return;
            }

            string levelID = lastLevelData[0];

            IPreviewBeatmapLevel level = levelPack.beatmapLevelCollection.beatmapLevels.FirstOrDefault(x => x.levelID == levelID);

            if (level != null)
            {
                SelectLevel(level);
            }
            else
            {
                // could not find level with levelID
                // either song was deleted or is a WIP level and was changed
                // try using song name and level author as fallback
                string songName    = lastLevelData[1];
                string levelAuthor = lastLevelData[2];

                level = levelPack.beatmapLevelCollection.beatmapLevels.FirstOrDefault(x => x.songName == songName && x.levelAuthorName == levelAuthor);
                if (level != null)
                {
                    SelectLevel(level);
                }
            }

            return;

OnError:
            SongSortModule.ResetSortMode();
            ButtonPanel.instance.UpdateSortButtons();
        }