From 213eb9ad0f507a3e178425712020ed9a5af95143 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Wed, 8 May 2019 22:59:01 -0500 Subject: [PATCH] Fixed viewport Fixed positioning Fixed scroll sensitivities --- .../UI/ViewControllers/MarkdownView.cs | 120 ++++++++++++++---- .../ViewControllers/ModInfoViewController.cs | 17 ++- .../UI/ViewControllers/ModListController.cs | 3 + BSIPA-ModList/manifest.json | 36 +++++- 4 files changed, 138 insertions(+), 38 deletions(-) diff --git a/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs b/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs index 6222277d..4f60c105 100644 --- a/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs +++ b/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs @@ -22,13 +22,14 @@ namespace BSIPA_ModList.UI.ViewControllers } private string markdown = ""; + private bool mdDirty = false; public string Markdown { get => markdown; set { markdown = value; - UpdateMd(); + mdDirty = true; } } @@ -71,12 +72,12 @@ namespace BSIPA_ModList.UI.ViewControllers protected void Awake() { - rectTransform.sizeDelta = new Vector2(100f, 100f); view = GetComponent(); view.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide; view.vertical = true; view.horizontal = false; view.scrollSensitivity = 0f; + view.inertia = true; view.movementType = ScrollRect.MovementType.Clamped; scrollbar = new GameObject("Scrollbar", typeof(RectTransform)).AddComponent(); @@ -91,22 +92,30 @@ namespace BSIPA_ModList.UI.ViewControllers viewport.localPosition = Vector2.zero; viewport.anchorMin = Vector2.zero; viewport.anchorMax = Vector2.one; - vpgo.AddComponent(); + viewport.anchoredPosition = new Vector2(.5f, .5f); + viewport.sizeDelta = Vector2.zero; + var vpmask = vpgo.AddComponent(); + var vpim = vpgo.AddComponent(); // supposedly Mask needs an Image? + vpmask.showMaskGraphic = false; + vpim.color = Color.white; + vpim.sprite = WhitePixel; + vpim.material = CustomUI.Utilities.UIUtilities.NoGlowMaterial; view.viewport = viewport; content = new GameObject("Content Wrapper").AddComponent(); content.SetParent(viewport); - content.localPosition = Vector2.zero; - content.anchorMin = Vector2.zero; - content.anchorMax = Vector2.one; var contentLayout = content.gameObject.AddComponent(); var contentFitter = content.gameObject.AddComponent(); - contentFitter.horizontalFit = ContentSizeFitter.FitMode.MinSize; + contentFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; contentFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained; - contentLayout.preferredWidth = contentLayout.minWidth = 100f; // to be adjusted - contentLayout.preferredHeight = 0f; + contentLayout.preferredWidth = contentLayout.minWidth = rectTransform.sizeDelta.x; // to be adjusted content.gameObject.AddComponent(); + content.localPosition = Vector2.zero; + content.anchorMin = new Vector2(.5f, .5f); + content.anchorMax = new Vector2(.5f, .5f); + content.anchoredPosition = Vector2.zero; + //content.sizeDelta = Vector2.zero; view.content = content; } @@ -125,10 +134,11 @@ namespace BSIPA_ModList.UI.ViewControllers #if DEBUG #if UI_CONFIGURE_MARKDOWN_THEMATIC_BREAK private byte tbreakSettings = 0; +#endif #endif public void Update() { -#if UI_CONFIGURE_MARKDOWN_THEMATIC_BREAK +#if DEBUG && UI_CONFIGURE_MARKDOWN_THEMATIC_BREAK if (Input.GetKeyDown(KeyCode.K)) { tbreakSettings = (byte)((tbreakSettings + 1) % 16); @@ -136,11 +146,22 @@ namespace BSIPA_ModList.UI.ViewControllers Logger.md.Info(tbreakSettings.ToString()); } #endif + if (mdDirty) + UpdateMd(); + else if (resetContentPosition) + { + resetContentPosition = false; + var v = content.anchoredPosition; + v.y = -(content.rect.height / 2); + content.anchoredPosition = v; + } + } -#endif + private bool resetContentPosition = false; private void UpdateMd() { + mdDirty = false; Clear(); var doc = CommonMarkConverter.Parse(markdown, settings); @@ -156,20 +177,42 @@ namespace BSIPA_ModList.UI.ViewControllers { var block = node.Block; - HorizontalOrVerticalLayoutGroup BlockNode(string name, float spacing, bool isVertical, Action apply = null, bool isDoc = false) + void Spacer(float size = 1.5f) + { + var go = new GameObject("Spacer", typeof(RectTransform)); + var vlayout = go.GetComponent(); + vlayout.SetParent(layout.Peek()); + vlayout.anchorMin = new Vector2(.5f, .5f); + vlayout.anchorMax = new Vector2(.5f, .5f); + vlayout.localScale = Vector3.one; + vlayout.localPosition = Vector3.zero; + + var l = go.AddComponent(); + l.minHeight = l.preferredHeight = size; + } + + HorizontalOrVerticalLayoutGroup BlockNode(string name, float spacing, bool isVertical, Action apply = null, float? spacer = null, bool isDoc = false) { - var type = isVertical ? typeof(VerticalLayoutGroup) : typeof(HorizontalLayoutGroup); if (node.IsOpening) { Logger.md.Debug($"Creating block container {name}"); currentText = null; - var go = new GameObject(name, typeof(RectTransform), type); + var go = new GameObject(name, typeof(RectTransform)); var vlayout = go.GetComponent(); vlayout.SetParent(layout.Peek()); - vlayout.anchoredPosition = Vector2.zero; + //vlayout.anchoredPosition = new Vector2(.5f, .5f); + vlayout.anchorMin = new Vector2(.5f, .5f); + vlayout.anchorMax = new Vector2(.5f, .5f); vlayout.localScale = Vector3.one; vlayout.localPosition = Vector3.zero; + + if (isDoc) + { + vlayout.sizeDelta = Vector2.zero; + vlayout.anchorMin = Vector2.zero; + vlayout.anchorMax = Vector2.one; + } var tt = go.AddComponent(); tt.Tag = block.Tag; apply?.Invoke(tt); @@ -177,20 +220,27 @@ namespace BSIPA_ModList.UI.ViewControllers HorizontalOrVerticalLayoutGroup l; if (isVertical) - l = go.GetComponent(); + l = go.AddComponent(); else - l = go.GetComponent(); + l = go.AddComponent(); l.childControlHeight = l.childControlWidth = true; l.childForceExpandHeight = l.childForceExpandWidth = false; l.childForceExpandWidth = isDoc; l.spacing = spacing; + /*var cfit = go.AddComponent(); + cfit.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; + cfit.verticalFit = ContentSizeFitter.FitMode.Unconstrained;*/ + return l; } else if (node.IsClosing) { currentText = null; layout.Pop(); + + if (spacer.HasValue) + Spacer(spacer.Value); } return null; } @@ -198,7 +248,7 @@ namespace BSIPA_ModList.UI.ViewControllers switch (block.Tag) { case BlockTag.Document: - BlockNode("DocumentRoot", .2f, true, isDoc: true); + BlockNode("DocumentRoot", .5f, true, isDoc: true); break; case BlockTag.SetextHeading: var l = BlockNode("SeHeading", .1f, false, t => t.hData = block.Heading); @@ -210,7 +260,7 @@ namespace BSIPA_ModList.UI.ViewControllers l.childAlignment = TextAnchor.UpperCenter; break; case BlockTag.Paragraph: - BlockNode("Paragraph", .1f, false); + l = BlockNode("Paragraph", .1f, false, spacer: 1.5f); break; case BlockTag.ThematicBreak: { // TODO: fix this, it doesn't want to actually show up properly @@ -219,8 +269,6 @@ namespace BSIPA_ModList.UI.ViewControllers var go = new GameObject("ThematicBreak", typeof(RectTransform), typeof(HorizontalLayoutGroup)); var vlayout = go.GetComponent(); vlayout.SetParent(layout.Peek()); - vlayout.anchoredPosition = Vector2.zero; - l = go.GetComponent(); #if DEBUG && UI_CONFIGURE_MARKDOWN_THEMATIC_BREAK l.childControlHeight = (tbreakSettings & 0b0001) != 0; // if set, not well behaved @@ -235,21 +283,34 @@ namespace BSIPA_ModList.UI.ViewControllers #endif l.spacing = 0f; + vlayout.localScale = Vector3.one; + vlayout.anchoredPosition = Vector2.zero; + vlayout.anchorMin = new Vector2(.5f, .5f); + vlayout.anchorMax = new Vector2(.5f, .5f); + vlayout.sizeDelta = new Vector2(layout.Peek().rect.width - BreakHeight, BreakHeight); + vlayout.localPosition = Vector3.zero; + currentText = null; - go = new GameObject("ThematicBreakBar", typeof(RectTransform), typeof(Image), typeof(LayoutElement)); + go = new GameObject("ThematicBreak Bar", typeof(RectTransform), typeof(Image), typeof(LayoutElement)); var im = go.GetComponent(); im.color = Color.white; - im.sprite = WhitePixel; - im.material = new Material(CustomUI.Utilities.UIUtilities.NoGlowMaterial); + // i think i need to copy the sprite because i'm using the same one for the mask + im.sprite = Sprite.Create(WhitePixel.texture, WhitePixel.rect, Vector2.zero); + im.material = CustomUI.Utilities.UIUtilities.NoGlowMaterial; var rt = go.GetComponent(); rt.SetParent(vlayout); - rt.anchorMin = Vector2.zero; - rt.anchorMax = Vector2.one; - rt.sizeDelta = new Vector2(100f, BreakHeight); var le = go.GetComponent(); - le.minWidth = le.preferredWidth = 100f; + le.minWidth = le.preferredWidth = layout.Peek().rect.width - BreakHeight; le.minHeight = le.preferredHeight = BreakHeight; le.flexibleHeight = le.flexibleWidth = 1f; + rt.localScale = Vector3.one; + rt.localPosition = Vector3.zero; + rt.anchoredPosition = Vector3.zero; + rt.anchorMin = Vector2.zero; + rt.anchorMax = Vector2.one; + rt.sizeDelta = new Vector2(layout.Peek().rect.width - BreakHeight, BreakHeight); + + Spacer(1f); } break; // TODO: add the rest of the tag types @@ -300,6 +361,8 @@ namespace BSIPA_ModList.UI.ViewControllers } } } + + resetContentPosition = true; } private void Clear() @@ -311,6 +374,7 @@ namespace BSIPA_ModList.UI.ViewControllers { Clear(child); Logger.md.Debug($"Destroying {child.name}"); + child.SetParent(null); Destroy(child.gameObject); } } diff --git a/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs b/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs index 838fb2f0..f6cf4b4a 100644 --- a/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs +++ b/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs @@ -190,16 +190,15 @@ namespace BSIPA_ModList.UI descText.enableWordWrapping = true; descText.overflowMode = TextOverflowModes.ScrollRect;*/ - var mdv = new GameObject("MarkDown Desc").AddComponent(); + var mdvgo = new GameObject("MarkDown Desc"); + mdvgo.SetActive(false); + var mdv = mdvgo.AddComponent(); mdv.rectTransform.SetParent(rectTransform); - mdv.rectTransform.anchorMin = new Vector2(.22f, 0f); - mdv.rectTransform.anchorMax = new Vector2(1f, .25f); - mdv.rectTransform.anchoredPosition = Vector2.zero; - var le = mdv.gameObject.AddComponent(); - le.minWidth = le.preferredWidth = 30f; - var asv = mdv.gameObject.AddComponent(); - asv.aspectMode = AspectRatioFitter.AspectMode.HeightControlsWidth; - asv.aspectRatio = 1f; + mdv.rectTransform.anchorMin = new Vector2(.5f, .5f); + mdv.rectTransform.anchorMax = new Vector2(.5f, .5f); + mdv.rectTransform.anchoredPosition = new Vector2(-4f, -3.5f); + mdv.rectTransform.sizeDelta = new Vector2(65f, 40f); + mdvgo.SetActive(true); mdv.Markdown = controller.Description; icon = new GameObject("Mod Info View Icon", typeof(RectTransform)).AddComponent(); diff --git a/BSIPA-ModList/UI/ViewControllers/ModListController.cs b/BSIPA-ModList/UI/ViewControllers/ModListController.cs index 33dcf369..8277f049 100644 --- a/BSIPA-ModList/UI/ViewControllers/ModListController.cs +++ b/BSIPA-ModList/UI/ViewControllers/ModListController.cs @@ -11,6 +11,7 @@ using VRUI; using IPA.Loader.Features; using TMPro; using BSIPA_ModList.UI.ViewControllers; +using UnityEngine.UI; namespace BSIPA_ModList.UI { @@ -65,6 +66,8 @@ namespace BSIPA_ModList.UI var rt = _customListTableView.transform as RectTransform; rt.anchorMin = new Vector2(.1f, 0f); rt.anchorMax = new Vector2(.9f, 1f); + + _customListTableView.gameObject.GetComponent().scrollSensitivity = 0f; } } } diff --git a/BSIPA-ModList/manifest.json b/BSIPA-ModList/manifest.json index bcbacb9d..2de160fe 100644 --- a/BSIPA-ModList/manifest.json +++ b/BSIPA-ModList/manifest.json @@ -11,7 +11,41 @@ "", "Look, ma! Markdown! Its **[CommonMark](w::https://commonmark.org/)**!", "", - "# H1 type 2 test" + "# H1 type 2 test", + "", + "***", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!", + "", + "and many lines to come!" ], "gameVersion": "0.13.2", "id": "BSIPA Mod List",