Exemplo n.º 1
0
        public static bool ItemMatchesSearch(CustomSelectInfo data, string searchStr)
        {
            var searchIn = "";

            switch (EC_MakerSearch.searchBy.Value)
            {
            case SearchBy.Name:
                searchIn = data.name;

                if (EC_MakerSearch.useTranslatedCache.Value)
                {
                    AutoTranslator.Default.TranslateAsync(data.name, result => { searchIn = result.Succeeded ? result.TranslatedText : data.name; });
                }

                break;

            case SearchBy.AssetBundle:
                searchIn = data.assetBundle;
                break;
            }

            var rule = StringComparison.Ordinal;

            if (!EC_MakerSearch.caseSensitive.Value)
            {
                searchStr = searchStr.ToLowerInvariant();
                rule      = StringComparison.OrdinalIgnoreCase;
            }

            var splitSearchStr = searchStr.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);

            return(splitSearchStr.All(s => searchIn.IndexOf(s, rule) >= 0));
        }
            private static Sprite GetThumbSpriteHook(CustomSelectInfo item, MonoBehaviour csk)
            {
                var list = Traverse.Create(csk).Field <CustomSelectListCtrl>("listCtrl").Value;

                _listCache.TryGetValue(list, out var listData);
                return(listData?.GetThumbSprite(item));
            }
            private static void ChangeItem(CustomSelectListCtrl __instance, CustomSelectInfo itemInfo, VirtualListData listData)
            {
                // Calling original whenever possible is probably better for interop since any hooks will run
                if (itemInfo.sic != null)
                {
                    __instance.ChangeItem(itemInfo.sic.gameObject);
                    return;
                }

                __instance.onChangeItemFunc?.Invoke(itemInfo.index);

                var tv = new Traverse(__instance);

                tv.Field <string>("selectDrawName").Value = itemInfo.name;
#if KK
                var tmp = tv.Field <TMPro.TextMeshProUGUI>("textDrawName").Value;
                if (tmp)
                {
                    tmp.text = itemInfo.name;
                }
#endif

                if (VirtualListData.IsItemNew(itemInfo))
                {
                    VirtualListData.MarkItemAsNotNew(itemInfo);
                    MarkListDirty(__instance);
                }

                listData.SelectedItem = itemInfo;
            }
Exemplo n.º 4
0
        private void UnblacklistMod(string guid)
        {
            List <CustomSelectInfo> lstSelectInfo = (List <CustomSelectInfo>)Traverse.Create(CustomSelectListCtrlInstance).Field("lstSelectInfo").GetValue();

            bool changeFilter = false;

            for (var i = 0; i < lstSelectInfo.Count; i++)
            {
                CustomSelectInfo customSelectInfo = lstSelectInfo[i];
                if (customSelectInfo.index >= UniversalAutoResolver.BaseSlotID)
                {
                    ResolveInfo info = UniversalAutoResolver.TryGetResolutionInfo((ChaListDefine.CategoryNo)customSelectInfo.category, customSelectInfo.index);
                    if (info != null && info.GUID == guid)
                    {
                        if (!Blacklist.ContainsKey(info.GUID))
                        {
                            Blacklist[info.GUID] = new Dictionary <int, HashSet <int> >();
                        }
                        if (!Blacklist[info.GUID].ContainsKey(customSelectInfo.category))
                        {
                            Blacklist[info.GUID][customSelectInfo.category] = new HashSet <int>();
                        }
                        Blacklist[info.GUID][customSelectInfo.category].Remove(info.Slot);
                        SaveBlacklist();

                        var controls = CustomBase.Instance.GetComponentsInChildren <CustomSelectListCtrl>(true);
                        for (var j = 0; j < controls.Length; j++)
                        {
                            var customSelectListCtrl = controls[j];
                            if (customSelectListCtrl.GetSelectInfoFromIndex(customSelectInfo.index)?.category == customSelectInfo.category)
                            {
                                if (ListVisibility.TryGetValue(customSelectListCtrl, out var visibilityType))
                                {
                                    if (visibilityType == ListVisibilityType.Hidden)
                                    {
                                        customSelectListCtrl.DisvisibleItem(customSelectInfo.index, true);
                                    }
                                }

                                List <CustomSelectInfo> lstSelectInfo2 = (List <CustomSelectInfo>)Traverse.Create(customSelectListCtrl).Field("lstSelectInfo").GetValue();

                                if (lstSelectInfo2.All(x => x.disvisible))
                                {
                                    changeFilter = true;
                                }
                            }
                        }
                    }
                }
            }

            if (changeFilter)
            {
                ChangeListFilter(ListVisibilityType.Filtered);
            }
            SetMenuVisibility(false);
        }
                public Sprite GetThumbSprite(CustomSelectInfo item)
                {
                    if (!ThumbCache.TryGetValue(item, out var thumb) || thumb == null)
                    {
                        var thumbTex = CommonLib.LoadAsset <Texture2D>(item.assetBundle, item.assetName, false, string.Empty);
                        if (thumbTex)
                        {
                            thumb            = Sprite.Create(thumbTex, new Rect(0f, 0f, thumbTex.width, thumbTex.height), new Vector2(0.5f, 0.5f));
                            ThumbCache[item] = thumb;
                        }
                    }

                    return(thumb);
                }
Exemplo n.º 6
0
        public static bool ItemMatchesSearch(CustomSelectInfo data, string searchStr)
        {
            var searchIn = "";

            switch (HS2_MakerSearch.searchBy.Value)
            {
            case SearchBy.Name:
                searchIn = data.name;

                if (HS2_MakerSearch.useTranslatedCache.Value)
                {
                    searchIn = searchNameStrings.TryGetValue(data, out var cachedTranslation) ? cachedTranslation : data.name;
                }

                break;

            case SearchBy.AssetBundle:
                searchIn = data.assetBundle;
                break;
            }

            if (data.id >= UniversalAutoResolver.BaseSlotID)
            {
                ResolveInfo info = UniversalAutoResolver.TryGetResolutionInfo((ChaListDefine.CategoryNo)data.category, data.id);
                if (info != null)
                {
                    Manifest manifest = Sideloader.Sideloader.GetManifest(info.GUID);
                    if (manifest.Author != null)
                    {
                        searchIn = searchIn + " " + manifest.Author;
                    }
                }
            }

            var rule = StringComparison.Ordinal;

            if (!HS2_MakerSearch.caseSensitive.Value)
            {
                searchStr = searchStr.ToLowerInvariant();
                rule      = StringComparison.OrdinalIgnoreCase;
            }

            var splitSearchStr = searchStr.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);

            return(splitSearchStr.All(s => searchIn.IndexOf(s, rule) >= 0));
        }
Exemplo n.º 7
0
        private void BlacklistMod(string guid)
        {
            for (var i = 0; i < CustomSelectListCtrlInstance.lstSelectInfo.Count; i++)
            {
                CustomSelectInfo customSelectInfo = CustomSelectListCtrlInstance.lstSelectInfo[i];
                if (customSelectInfo.index >= UniversalAutoResolver.BaseSlotID)
                {
                    ResolveInfo info = UniversalAutoResolver.TryGetResolutionInfo((ChaListDefine.CategoryNo)customSelectInfo.category, customSelectInfo.index);
                    if (info != null && info.GUID == guid)
                    {
                        if (!Blacklist.ContainsKey(info.GUID))
                        {
                            Blacklist[info.GUID] = new Dictionary <int, HashSet <int> >();
                        }
                        if (!Blacklist[info.GUID].ContainsKey(customSelectInfo.category))
                        {
                            Blacklist[info.GUID][customSelectInfo.category] = new HashSet <int>();
                        }
                        Blacklist[info.GUID][customSelectInfo.category].Add(info.Slot);
                        SaveBlacklist();

                        var controls = CustomBase.Instance.GetComponentsInChildren <CustomSelectListCtrl>(true);
                        for (var j = 0; j < controls.Length; j++)
                        {
                            var customSelectListCtrl = controls[j];
                            if (customSelectListCtrl.GetSelectInfoFromIndex(customSelectInfo.index)?.category == customSelectInfo.category)
                            {
                                if (ListVisibility.TryGetValue(customSelectListCtrl, out var visibilityType))
                                {
                                    if (visibilityType == ListVisibilityType.Filtered)
                                    {
                                        customSelectListCtrl.DisvisibleItem(customSelectInfo.index, true);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            SetMenuVisibility(false);
        }
Exemplo n.º 8
0
        public static void ChangeListFilter(CustomSelectListCtrl customSelectListCtrl, ListVisibilityType visibilityType)
        {
            List <CustomSelectInfo> lstSelectInfo = (List <CustomSelectInfo>)Traverse.Create(customSelectListCtrl).Field("lstSelectInfo").GetValue();

            int count = 0;

            for (var i = 0; i < lstSelectInfo.Count; i++)
            {
                CustomSelectInfo customSelectInfo = lstSelectInfo[i];
                if (visibilityType == ListVisibilityType.All)
                {
                    customSelectListCtrl.DisvisibleItem(customSelectInfo.index, false);
                    continue;
                }

                bool hide = visibilityType != ListVisibilityType.Filtered;

                if (customSelectInfo.index >= UniversalAutoResolver.BaseSlotID)
                {
                    ResolveInfo Info = UniversalAutoResolver.TryGetResolutionInfo((ChaListDefine.CategoryNo)customSelectInfo.category, customSelectInfo.index);
                    if (Info != null)
                    {
                        if (CheckBlacklist(Info.GUID, (int)Info.CategoryNo, Info.Slot))
                        {
                            hide = visibilityType == ListVisibilityType.Filtered;
                            count++;
                        }
                    }
                }
                customSelectListCtrl.DisvisibleItem(customSelectInfo.index, hide);
            }
            ListVisibility[customSelectListCtrl] = visibilityType;

            if (count == 0 && visibilityType == ListVisibilityType.Hidden)
            {
                Logger.LogMessage("No items are hidden");
                ChangeListFilter(customSelectListCtrl, ListVisibilityType.Filtered);
            }
        }
 public static void MarkItemAsNotNew(CustomSelectInfo customSelectInfo)
 {
     Singleton <Character> .Instance.chaListCtrl.AddItemID(customSelectInfo.category, customSelectInfo.index, 2);
 }
 public static bool IsItemNew(CustomSelectInfo item)
 {
     return(!DisableNewIndicator.Value && Singleton <Character> .Instance.chaListCtrl.CheckItemID(item.category, item.index) == 1);
 }