diff --git a/src/Shared.KKalike/Maker/MakerInterfaceCreator.KK.cs b/src/Shared.KKalike/Maker/MakerInterfaceCreator.KK.cs index 5230d4d..a9a7477 100644 --- a/src/Shared.KKalike/Maker/MakerInterfaceCreator.KK.cs +++ b/src/Shared.KKalike/Maker/MakerInterfaceCreator.KK.cs @@ -256,6 +256,15 @@ private static void CreateCustomAccessoryWindowControls() 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(); +#if KKS + var content_image = original_scroll.content.GetComponent(); +#endif + var scroll_bar_area_sprite = original_scroll.verticalScrollbar.GetComponent().sprite; + var scroll_bar_handle_sprite = original_scroll.verticalScrollbar.image.sprite; +#endif foreach (var slotTransform in container.Cast().Where(x => x.name.StartsWith("tglSlot")).OrderBy(x => x.name)) { // Remove the red info text at the bottom to free up some space @@ -270,14 +279,11 @@ private static void CreateCustomAccessoryWindowControls() } } CreateCustomControlsInSubCategory(slotTransform, _accessoryWindowEntries); -#if KK - /*todo KKS version - copy existing scroll view and use that instead of making a new one - CustomScene/CustomRoot/FrontUIGroup/CustomUIGroup/CvsMenuTree/03_ClothesTop/tglGloves/GlovesTop/Scroll View/Viewport/Content - unparent everything under content, copy it into a work copy, reparent - copy to acc slots, reparent all the controls, destroy old layout elements and image - */ +#if KK || KKS var listParent = slotTransform.Cast().Where(x => x.name.EndsWith("Top")).First(); +#if KKS + GameObject.DestroyImmediate(listParent.GetComponent());//Destroy image that contains scrollbar +#endif var elements = new List(); foreach (Transform t in listParent) elements.Add(t); @@ -286,24 +292,37 @@ private static void CreateCustomAccessoryWindowControls() fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; - var go = DefaultControls.CreateScrollView(new DefaultControls.Resources()); - go.name = $"{slotTransform.name}ScrollView"; - go.transform.SetParent(listParent.transform, false); + var scrollTransform = DefaultControls.CreateScrollView(new DefaultControls.Resources()); + scrollTransform.name = $"{slotTransform.name}ScrollView"; + scrollTransform.transform.SetParent(listParent.transform, false); - var scroll = go.GetComponent(); + var scroll = scrollTransform.GetComponent(); scroll.horizontal = false; scroll.scrollSensitivity = 40f; scroll.movementType = ScrollRect.MovementType.Clamped; - scroll.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide; - scroll.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide; - GameObject.DestroyImmediate(scroll.GetComponent()); - GameObject.DestroyImmediate(scroll.horizontalScrollbar.gameObject); - GameObject.DestroyImmediate(scroll.verticalScrollbar.gameObject); + scroll.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport; + scroll.verticalScrollbar.image.sprite = scroll_bar_handle_sprite; + scroll.verticalScrollbar.GetComponent().sprite = scroll_bar_area_sprite; +#if KKS + //Add image that doesn't contain scroll bar + var image = scroll.content.gameObject.AddComponent(); + 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()); - var le = scroll.gameObject.AddComponent(); + var s_LE = scroll.gameObject.AddComponent(); +#if KK var height = (GameObject.Find("CustomScene/CustomRoot/FrontUIGroup/CustomUIGroup/CvsMenuTree/04_AccessoryTop/Slots").transform as RectTransform).rect.height; - le.preferredHeight = height; - le.preferredWidth = 360f; + var width = 360f; +#else + var height = 875f; //Slots from KK doesn't exist + var width = 380f; +#endif + s_LE.preferredHeight = height; + s_LE.preferredWidth = width; var vlg = scroll.content.gameObject.AddComponent(); vlg.childControlWidth = true; @@ -329,8 +348,8 @@ internal static void OnMakerAccSlotAdded(Transform newSlotTransform) { return;//Maker slots are added before CreateCustomAccessoryWindowControls is called. don't create controls yet } - //find parent of Content where controls are placed, additional Slots are copies of first slot as such they are currently named downstream Slot01 - newSlotTransform = newSlotTransform.Find("Slot01Top/tglSlot01ScrollView/Viewport"); + //find Content where controls are placed, additional Slots are copies of first slot as such they are currently named downstream Slot01 + newSlotTransform = newSlotTransform.Find("Slot01Top/tglSlot01ScrollView/Viewport/Content"); #endif RemoveCustomControlsInSubCategory(newSlotTransform);