public override TableCell CellForIdx(TableView view, int row, CountersPlusHorizontalSettingsListViewController settings)
        {
            AnnotatedBeatmapLevelCollectionTableCell cell = view.DequeueReusableCellForIdentifier(settings.ReuseIdentifier) as AnnotatedBeatmapLevelCollectionTableCell;

            if (cell == null) //Dequeue the cell, and make an instance if it doesn't exist.
            {
                cell = Object.Instantiate(settings.levelPackTableCellInstance);
                cell.reuseIdentifier = settings.ReuseIdentifier;
            }
            cell.showNewRibbon = false; //Dequeued cells will keep NEW ribbon value. Always change it to false.
            TextMeshProUGUI packInfoText = cell.GetPrivateField <TextMeshProUGUI>("_infoText");

            packInfoText.richText = true;                                //Enable rich text for info text. Optional, but I use it for Counters+.
            UnityEngine.UI.Image packCoverImage = cell.GetPrivateField <UnityEngine.UI.Image>("_coverImage");
            packCoverImage.mainTexture.wrapMode = TextureWrapMode.Clamp; //Fixes bordering on images (especially transparent ones)
            switch (row)
            {
            case 0:
                SetText("Main Settings", "Configure basic Counters+ settings.", Images.Images.LoadSprite("MainSettings"),
                        ref packInfoText, ref packCoverImage);
                break;

            case 1:
                SetText("Donators", "See who supported me on Ko-fi!", Images.Images.LoadSprite("Donators"),
                        ref packInfoText, ref packCoverImage);
                break;

            case 2:
                SetText("Contributors", "See who helped with Counters+!", Images.Images.LoadSprite("Contributors"),
                        ref packInfoText, ref packCoverImage);
                break;
            }
            return(cell);
        }
        public override TableCell CellForIdx(TableView view, int row, CountersPlusHorizontalSettingsListViewController settings)
        {
            AnnotatedBeatmapLevelCollectionTableCell cell = view.DequeueReusableCellForIdentifier(settings.ReuseIdentifier) as AnnotatedBeatmapLevelCollectionTableCell;

            if (cell == null) //Dequeue the cell, and make an instance if it doesn't exist.
            {
                cell = UnityEngine.Object.Instantiate(settings.levelPackTableCellInstance);
                cell.reuseIdentifier = settings.ReuseIdentifier;
            }
            cell.showNewRibbon = false; //Dequeued cells will keep NEW ribbon value. Always change it to false.

            switch (row)
            {
            case 0:
                SetCellInfo(ref cell, "General HUD Settings", "Change general settings, such as HUD size.", "HUD_General");
                break;

            case 1:
                SetCellInfo(ref cell, "Lock HUD to Camera", "Allows the HUD to be locked to various cameras.", "HUD_Camera");
                break;

            case 2:
                SetCellInfo(ref cell, "HUD Position Offset", "Changes the positional offset of the HUD.", "HUD_Position");
                break;

            case 3:
                SetCellInfo(ref cell, "HUD Rotation Offset", "Changes the rotational offset of the HUD.", "HUD_Rotation");
                break;
            }
            return(cell);
        }
        public static void Prefix(AnnotatedBeatmapLevelCollectionTableCell __instance)
        {
            // Logger.Debug("AnnotatedBeatmapLevelCollectionTableCell.OnPointerEnter");

            try
            {
                // なぜかLevelListTableCellも呼ばれるのでオブジェクト名ではじく
                if (__instance.name.IndexOf("AnnotatedBeatmapLevelCollectionTableCell") < 0)
                {
                    return;
                }

                var collection = __instance.GetPrivateField <IAnnotatedBeatmapLevelCollection>("_annotatedBeatmapLevelCollection");
                if (collection is IAsyncDataSource c)
                {
                    // データは非同期に取ってくるので、読み込みが終わっていたらビューを更新
                    if (!c.IsRefreshedVisualAfterInitialLoad && c.IsInitialLoaded)
                    {
                        Logger.Debug(__instance.name);
                        var parent = __instance.GetComponentInParent <AnnotatedBeatmapLevelCollectionsTableView>();
                        var model  = parent.GetPrivateField <AdditionalContentModel>("_additionalContentModel");
                        __instance.RefreshAvailabilityAsync(model);
                        c.IsRefreshedVisualAfterInitialLoad = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Debug(ex);
            }
        }
        public static void Prefix(AnnotatedBeatmapLevelCollectionTableCell __instance)
        {
            // Logger.Debug("AnnotatedBeatmapLevelCollectionTableCell.OnPointerClick");
            try
            {
                // なぜかLevelListTableCellも呼ばれるのでオブジェクト名ではじく
                if (__instance.name.IndexOf("AnnotatedBeatmapLevelCollectionTableCell") < 0)
                {
                    return;
                }

                var collection = __instance.GetPrivateField <IAnnotatedBeatmapLevelCollection>("_annotatedBeatmapLevelCollection");
                if (collection is IAsyncDataSource c)
                {
                    // 選択されたコレクションをビューに反映
                    var controller = Resources.FindObjectsOfTypeAll <LevelCollectionViewController>().First();
                    controller.SetData(collection.beatmapLevelCollection, collection.collectionName, collection.coverImage, false, null);

                    // 選択されてない状態のとき、クリックされたらなぜか一回目は選択されず
                    // 二回目だと選択される状態になっているので一回目で強制的に選択する
                    if (!__instance.selected)
                    {
                        __instance.selected = true;
                    }

                    controller.SelectLevel(collection.beatmapLevelCollection.beatmapLevels.FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                Logger.Debug(ex);
            }
        }
        private void SetCellInfo(ref AnnotatedBeatmapLevelCollectionTableCell cell, string name, string info, string imageResource, bool ribbon = true)
        {
            TextMeshProUGUI packInfoText = cell.GetPrivateField <TextMeshProUGUI>("_infoText");

            packInfoText.richText = true;                                //Enable rich text for info text. Optional, but I use it for Counters+.
            UnityEngine.UI.Image packCoverImage = cell.GetPrivateField <UnityEngine.UI.Image>("_coverImage");
            packCoverImage.mainTexture.wrapMode = TextureWrapMode.Clamp; //Fixes bordering on images
            cell.showNewRibbon = ribbon;

            packInfoText.text     = $"{name}\n\n{info}";
            packCoverImage.sprite = Images.Images.LoadSprite(imageResource);
        }
Example #6
0
 protected void GetCell(TableView view, out AnnotatedBeatmapLevelCollectionTableCell cell, out TextMeshProUGUI packText, out Image image)
 {
     cell = view.DequeueReusableCellForIdentifier(settingsList.Value.ReuseIdentifier) as AnnotatedBeatmapLevelCollectionTableCell;
     if (cell == null) //Dequeue the cell, and make an instance if it doesn't exist.
     {
         cell = Object.Instantiate(settingsList.Value.levelPackTableCellInstance);
         cell.reuseIdentifier = settingsList.Value.ReuseIdentifier;
     }
     cell.showNewRibbon = false;                         //Dequeued cells will keep NEW ribbon value. Always change it to false.
     packText           = PackInfoTextAccessor(ref cell);
     packText.richText  = true;                          //Enable rich text for info text. Optional, but I use it for Counters+.
     image = CoverImageAccessor(ref cell);
     image.mainTexture.wrapMode = TextureWrapMode.Clamp; //Fixes bordering on images (especially transparent ones)
 }
        public override TableCell CellForIdx(TableView view, int row, CountersPlusHorizontalSettingsListViewController settings)
        {
            if (!counterInfos.Any())
            {
                LoadData();
            }
            AnnotatedBeatmapLevelCollectionTableCell cell = view.DequeueReusableCellForIdentifier(settings.ReuseIdentifier) as AnnotatedBeatmapLevelCollectionTableCell;

            if (cell == null) //Dequeue the cell, and make an instance if it doesn't exist.
            {
                cell = UnityEngine.Object.Instantiate(settings.levelPackTableCellInstance);
                cell.reuseIdentifier = settings.ReuseIdentifier;
            }
            cell.showNewRibbon = false; //Dequeued cells will keep NEW ribbon value. Always change it to false.
            TextMeshProUGUI packInfoText = cell.GetPrivateField <TextMeshProUGUI>("_infoText");

            packInfoText.richText = true;                                //Enable rich text for info text. Optional, but I use it for Counters+.
            UnityEngine.UI.Image packCoverImage = cell.GetPrivateField <UnityEngine.UI.Image>("_coverImage");
            packCoverImage.mainTexture.wrapMode = TextureWrapMode.Clamp; //Fixes bordering on images (especially transparent ones)

            SettingsInfo info = counterInfos[row];

            packInfoText.text = $"{info.Name}\n\n{info.Description}";
            try
            {
                if (info.IsCustom)
                {
                    if ((info.Model as CustomConfigModel).CustomCounter.LoadedIcon != null)
                    {
                        packCoverImage.sprite = (info.Model as CustomConfigModel).CustomCounter.LoadedIcon;
                    }
                    else
                    {
                        packCoverImage.sprite = Images.Images.LoadSprite("Custom");
                    }
                    cell.showNewRibbon = (info.Model as CustomConfigModel).CustomCounter.IsNew;
                }
                else
                {
                    packCoverImage.sprite = Images.Images.LoadSprite(info.Name);
                    if (info.Model.VersionAdded != null)
                    {
                        cell.showNewRibbon = Plugin.PluginVersion == info.Model.VersionAdded;
                        packInfoText.text += $"\n\n<i>Version added: {info.Model.VersionAdded.ToString()}</i>";
                    }
                }
            }
            catch { packCoverImage.sprite = Images.Images.LoadSprite("Bug"); }
            return(cell);
        }
Example #8
0
        static void Postfix(AnnotatedBeatmapLevelCollectionTableCell __instance, ref IAnnotatedBeatmapLevelCollection annotatedBeatmapLevelCollection, ref Image ____coverImage)
        {
            AnnotatedBeatmapLevelCollectionTableCell cell = __instance;

            if (annotatedBeatmapLevelCollection is IDeferredSpriteLoad deferredSpriteLoad)
            {
                if (deferredSpriteLoad.SpriteWasLoaded)
                {
#if DEBUG
                    Plugin.Log.Debug($"Sprite was already loaded for {(deferredSpriteLoad as IAnnotatedBeatmapLevelCollection).collectionName}");
#endif
                }
                if (EventTable.TryGetValue(deferredSpriteLoad, out AnnotatedBeatmapLevelCollectionTableCell existing))
                {
                    EventTable.Remove(deferredSpriteLoad);
                }
                EventTable.Add(deferredSpriteLoad, cell);
                deferredSpriteLoad.SpriteLoaded -= OnSpriteLoaded;
                deferredSpriteLoad.SpriteLoaded += OnSpriteLoaded;
            }
        }
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            try
            {
                if (firstActivation)
                {
                    //loadedSettingsGroups = TypesUtility.GetListOfType<SettingsGroup>();
                    //Largely unchanged from CustomListController. Keep all of this.
                    levelPackTableCellInstance = Resources.FindObjectsOfTypeAll <AnnotatedBeatmapLevelCollectionTableCell>().First(x => x.name == "AnnotatedBeatmapLevelCollectionTableCell");

                    RectTransform container = new GameObject("HorizontalListContainer", typeof(RectTransform)).transform as RectTransform;
                    container.SetParent(rectTransform, false);
                    container.sizeDelta = Vector2.zero;
                    container.anchorMin = new Vector2(0.1f, 0); //Squish the list container a little bit
                    container.anchorMax = new Vector2(0.9f, 1); //To make room for the forward/backward buttons

                    var go = new GameObject("CustomListTableView");
                    go.SetActive(false);                                        //Disable GameObject to not have scripts run.
                    customListTableView = go.AddComponent <TableView>();        //Add TableView
                    customListTableView.gameObject.AddComponent <RectMask2D>(); //Add Mask
                    customListTableView.transform.SetParent(container, false);
                    TVTableType(ref customListTableView) = TableView.TableType.Horizontal;

                    (customListTableView.transform as RectTransform).anchorMin        = Vector2.zero;
                    (customListTableView.transform as RectTransform).anchorMax        = Vector2.one;
                    (customListTableView.transform as RectTransform).sizeDelta        = Vector2.zero;
                    (customListTableView.transform as RectTransform).anchoredPosition = Vector2.zero;

                    TVPreallocCells(ref customListTableView) = new TableView.CellsGroup[0];
                    TVIsInitialized(ref customListTableView) = false;

                    // Code copied from monkeymanboy's Beat Saber Custom Campaigns mod. Keep these too.
                    PageLeftButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => x.name == "PageLeftButton"), transform);
                    RectTransform buttonTransform = PageLeftButton.transform.Find("BG") as RectTransform;
                    RectTransform glow            = Instantiate(Resources.FindObjectsOfTypeAll <GameObject>().Last(x => (x.name == "GlowContainer")), PageLeftButton.transform).transform as RectTransform;
                    glow.localPosition    = buttonTransform.localPosition;
                    glow.anchoredPosition = buttonTransform.anchoredPosition;
                    glow.anchorMin        = buttonTransform.anchorMin;
                    glow.anchorMax        = buttonTransform.anchorMax;
                    glow.sizeDelta        = buttonTransform.sizeDelta;
                    PageLeftButton.transform.localPosition = new Vector3(-80, 2.5f, -5);
                    (PageLeftButton.transform as RectTransform).anchoredPosition = Vector3.up * 2.5f;
                    PageLeftButton.interactable = true;
                    PageLeftButton.gameObject.SetActive(false);
                    PageRightButton       = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "PageRightButton")), transform);
                    buttonTransform       = PageRightButton.transform.Find("BG") as RectTransform;
                    glow                  = Instantiate(Resources.FindObjectsOfTypeAll <GameObject>().Last(x => (x.name == "GlowContainer")), PageRightButton.transform).transform as RectTransform;
                    glow.localPosition    = buttonTransform.localPosition;
                    glow.anchoredPosition = buttonTransform.anchoredPosition;
                    glow.anchorMin        = buttonTransform.anchorMin;
                    glow.anchorMax        = buttonTransform.anchorMax;
                    glow.sizeDelta        = buttonTransform.sizeDelta;
                    PageRightButton.transform.localPosition = new Vector3(80, 2.5f, -5);
                    (PageRightButton.transform as RectTransform).anchoredPosition = Vector3.up * 2.5f;
                    PageRightButton.interactable = true;
                    PageRightButton.gameObject.SetActive(false);

                    RectTransform viewport = new GameObject("Viewport").AddComponent <RectTransform>(); //Make a Viewport RectTransform
                    viewport.SetParent(customListTableView.transform as RectTransform, false);          //It expects one from a ScrollRect, so we have to make one ourselves.
                    viewport.sizeDelta = Vector2.zero;                                                  //Important to set this to zero so the TableView can scroll through all available cells.

                    TVPageUpButton(ref customListTableView)   = PageLeftButton;                         // Set Up button to Left
                    TVPageDownButton(ref customListTableView) = PageRightButton;                        // Set Down button to Right
                    customListTableView.Init();                                                         // Init, have "_scrollRectTransform" be null.
                    TVScrollRect(ref customListTableView) = viewport;                                   // Set it with our hot-out-of-the-oven Viewport.
                    customListTableView.dataSource        = this;                                       //Add data source
                    go.SetActive(true);
                    customListTableView.Show();

                    //Finally, reset some anchors of each child so that all of the available cells are shown.
                    for (int i = 0; i < customListTableView.transform.childCount; i++)
                    {
                        (customListTableView.transform.GetChild(i).transform as RectTransform).anchoredPosition = Vector3.zero;
                        (customListTableView.transform.GetChild(i).transform as RectTransform).anchorMin        = Vector3.zero;
                        (customListTableView.transform.GetChild(i).transform as RectTransform).anchorMax        = Vector3.one;
                    }
                    HandleSettingsGroupChanged(0);
                }
                selectedSettingsGroup?.OnEnable();
            }
            catch (Exception e)
            {  //Edit this with your logging system of choice, or delete it altogether (As this shouldn't really cause Exceptions)
                Plugin.Logger.Error(e);
            }
            customListTableView.didSelectCellWithIdxEvent += OnCellSelect;
            sectionSelection.Value.OnSettingsGroupChanged += HandleSettingsGroupChanged;
            (transform as RectTransform).anchoredPosition  = Vector3.zero;
        }