Skip to content

Commit

Permalink
KKS: Seemingly Done, but not (scrolling not working) (#34)
Browse files Browse the repository at this point in the history
* Seemingly Done, but not

Not sure why I can't select the scroll

* "fixed" scrolling and did adjustments

* returned to old method, but added scroll bar

* Fix for changes to FindSubcategoryContentParent
  • Loading branch information
jalil49 authored and ManlyMarco committed Jun 3, 2021
1 parent 24f547d commit ee56a2f
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions src/Shared.KKalike/Maker/MakerInterfaceCreator.KK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
#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
Expand All @@ -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<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);
Expand All @@ -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<ScrollRect>();
var scroll = scrollTransform.GetComponent<ScrollRect>();
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<Image>());
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<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 le = scroll.gameObject.AddComponent<LayoutElement>();
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;
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<VerticalLayoutGroup>();
vlg.childControlWidth = true;
Expand All @@ -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);

Expand Down

0 comments on commit ee56a2f

Please sign in to comment.