Esempio n. 1
0
        private static void CreateCustomAccessoryWindowControls()
        {
            var customAcsChangeSlot = Object.FindObjectOfType <CustomAcsChangeSlot>();

            if (customAcsChangeSlot == null)
            {
                throw new ArgumentNullException(nameof(customAcsChangeSlot));
            }
            var tglSlot01GameObject = customAcsChangeSlot.transform.FindLoop("tglSlot01");

            if (tglSlot01GameObject == null)
            {
                throw new ArgumentNullException(nameof(tglSlot01GameObject));
            }
            var container = tglSlot01GameObject.transform.parent;

            foreach (var slotTransform in container.Cast <Transform>().Where(x => x.name.StartsWith("tglSlot")).OrderBy(x => x.name))
            {
                // Remove the red info text at the bottom to free up some space
                var contentParent = FindSubcategoryContentParent(slotTransform);
                foreach (var txtName in new[] { "txtExplanation", "txtAcsExplanation" }) // Named differently in KK and EC
                {
                    var text = contentParent.Find(txtName);
                    if (text != null)
                    {
                        text.GetComponent <LayoutElement>().enabled = false;
                        text.Cast <Transform>().First().gameObject.SetActive(false);
                    }
                }
                CreateCustomControlsInSubCategory(slotTransform, _accessoryWindowEntries, true);
            }
            AccessoriesApi.AutomaticControlVisibility();
        }
Esempio n. 2
0
 private static void CheckIndexRangeThrow(int accessoryIndex)
 {
     if (accessoryIndex < 0 || accessoryIndex >= AccessoriesApi.GetCvsAccessoryCount())
     {
         throw new IndexOutOfRangeException("accessoryIndex has to be between 0 and AccessoriesApi.GetCvsAccessoryCount() - 1");
     }
 }
        private static void CreateCustomAccessoryWindowControls()
        {
            var customAcsChangeSlot = Object.FindObjectOfType <CustomAcsChangeSlot>();

            if (customAcsChangeSlot == null)
            {
                throw new ArgumentNullException(nameof(customAcsChangeSlot));
            }
            var tglSlot01GameObject = customAcsChangeSlot.transform.FindLoop("tglSlot01");

            if (tglSlot01GameObject == null)
            {
                throw new ArgumentNullException(nameof(tglSlot01GameObject));
            }
            var container = tglSlot01GameObject.transform.parent;

#if KK || KKS
            //Set source early rather than search every time
            var original_scroll = GameObject.Find("CustomScene/CustomRoot/FrontUIGroup/CustomUIGroup/CvsMenuTree/03_ClothesTop/tglTop/TopTop/Scroll View").transform.GetComponent <ScrollRect>();
#if KKS
            var content_image = original_scroll.content.GetComponent <Image>();
#endif
            var scroll_bar_area_sprite   = original_scroll.verticalScrollbar.GetComponent <Image>().sprite;
            var scroll_bar_handle_sprite = original_scroll.verticalScrollbar.image.sprite;

#if KK
            var root = container.parent.parent.parent;
            root.Find("tglCopy").GetComponent <LayoutElement>().minWidth   = 200f;
            root.Find("tglChange").GetComponent <LayoutElement>().minWidth = 200f;
#endif
            foreach (var slotTransform in container.Cast <Transform>())
            {
                var layout = slotTransform.GetComponent <LayoutElement>();
                layout.minWidth       = 200f;
                layout.preferredWidth = 200f;
            }
#endif
            foreach (var slotTransform in container.Cast <Transform>().Where(x => x.name.StartsWith("tglSlot")).OrderBy(x => x.name))
            {
                // Remove the red info text at the bottom to free up some space
                var contentParent = FindSubcategoryContentParent(slotTransform);
                foreach (var txtName in new[] { "txtExplanation", "txtAcsExplanation" }) // Named differently in KK and EC
                {
                    var text = contentParent.Find(txtName);
                    if (text != null)
                    {
                        text.GetComponent <LayoutElement>().enabled = false;
                        text.Cast <Transform>().First().gameObject.SetActive(false);
                    }
                }
                CreateCustomControlsInSubCategory(slotTransform, _accessoryWindowEntries, true);
#if KK || KKS
                var listParent = slotTransform.Cast <Transform>().Where(x => x.name.EndsWith("Top")).First();
#if KKS
                GameObject.DestroyImmediate(listParent.GetComponent <Image>());//Destroy image that contains scrollbar
#endif
                var elements = new List <Transform>();
                foreach (Transform t in listParent)
                {
                    elements.Add(t);
                }

                var fitter = listParent.GetComponent <ContentSizeFitter>();
                fitter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
                fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;

                var scrollTransform = DefaultControls.CreateScrollView(new DefaultControls.Resources());
                scrollTransform.name = $"{slotTransform.name}ScrollView";
                scrollTransform.transform.SetParent(listParent.transform, false);
                listParent.transform.position -= new Vector3(30, 0, 0);
                var scroll = scrollTransform.GetComponent <ScrollRect>();
                scroll.horizontal        = false;
                scroll.scrollSensitivity = 40f;

                scroll.movementType = ScrollRect.MovementType.Clamped;
                scroll.verticalScrollbarVisibility    = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
                scroll.verticalScrollbar.image.sprite = scroll_bar_handle_sprite;
                scroll.verticalScrollbar.GetComponent <Image>().sprite = scroll_bar_area_sprite;

#if KKS
                //Add image that doesn't contain scroll bar
                var image = scroll.content.gameObject.AddComponent <Image>();
                image.sprite = content_image.sprite;
                image.type   = content_image.type;
#endif
                Object.DestroyImmediate(scroll.horizontalScrollbar.gameObject);
                var content = scroll.content.transform;
                Object.Destroy(scroll.GetComponent <Image>());

                var s_LE = scroll.gameObject.AddComponent <LayoutElement>();
#if KK
                var height = (GameObject.Find("CustomScene/CustomRoot/FrontUIGroup/CustomUIGroup/CvsMenuTree/04_AccessoryTop/Slots").transform as RectTransform).rect.height;
                var width  = 400f;
#else
                var height = 875f;   //Slots from KK doesn't exist
                var width  = 400f;
#endif
                s_LE.preferredHeight = height;
                s_LE.preferredWidth  = width;

                var vlg = scroll.content.gameObject.AddComponent <VerticalLayoutGroup>();
                vlg.childControlWidth      = true;
                vlg.childControlHeight     = true;
                vlg.childForceExpandWidth  = true;
                vlg.childForceExpandHeight = false;

                scroll.content.gameObject.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

                foreach (var item in elements)
                {
                    item.SetParent(scroll.content);
                }
                slotTransform.SetParent(scroll.content);
#endif
            }
            AccessoriesApi.AutomaticControlVisibility();
        }