Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KKS: Seemingly Done, but not (scrolling not working) #34

Merged
merged 4 commits into from
Jun 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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