Skip to content

Commit

Permalink
Fix layout of card/coord load toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Jun 2, 2021
1 parent 004f66e commit 8a1fbfa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Shared.KKalike/Maker/UI/MakerCoordinateLoadToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ internal static void CreateCustomToggles()
var baseToggle = _baseToggles[index];
baseToggle.localPosition = new Vector3(_baseToggle.localPosition.x + singleWidth * index, _verticalOffset, 0);
baseToggle.offsetMax = new Vector2(baseToggle.offsetMin.x + singleWidth, baseToggle.offsetMin.y + 26);
#if KKS
// Need to fix text positioning in KKS
KoikatuAPI.Instance.StartCoroutine(FixLayout(baseToggle));
#endif
}
}

Expand Down Expand Up @@ -106,7 +110,10 @@ private static IEnumerator FixLayout(RectTransform rt)
{
yield return new WaitUntil(() => rt == null || rt.gameObject.activeInHierarchy);
yield return null;

#if KKS
// Need to fix text positioning in KKS
rt.GetComponent<HorizontalLayoutGroup>().enabled = true;
#endif
LayoutRebuilder.MarkLayoutForRebuild(rt);
}

Expand Down
22 changes: 21 additions & 1 deletion src/Shared.KKalike/Maker/UI/MakerLoadToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ namespace KKAPI.Maker.UI
/// </summary>
public class MakerLoadToggle : BaseEditableGuiEntry<bool>
{
#if KKS
private const int TotalWidth = 380 + 292 - 25; // KKS has fatter all on/off buttons
#else
private const int TotalWidth = 380 + 292 - 5; // -5 for KKP
#endif

private static readonly List<MakerLoadToggle> Toggles = new List<MakerLoadToggle>();
private static Transform _baseToggle;
Expand Down Expand Up @@ -89,7 +93,10 @@ private static IEnumerator FixLayout(RectTransform rt)
{
yield return new WaitUntil(() => rt.gameObject.activeInHierarchy);
yield return null;

#if KKS
// Need to fix text positioning in KKS
rt.GetComponent<HorizontalLayoutGroup>().enabled = true;
#endif
LayoutRebuilder.MarkLayoutForRebuild(rt);
}

Expand Down Expand Up @@ -128,13 +135,22 @@ internal static void Setup()
var baseToggle = baseToggles[index];
baseToggle.localPosition = new Vector3(_baseToggle.localPosition.x + singleWidth * index, 52, 0);
baseToggle.offsetMax = new Vector2(baseToggle.offsetMin.x + singleWidth, baseToggle.offsetMin.y + 26);
#if KKS
// Need to fix text positioning in KKS
KoikatuAPI.Instance.StartCoroutine(FixLayout(baseToggle));
#endif
}

var allon = _root.transform.Find("btnAllOn");
allon.GetComponentInChildren<Button>().onClick.AddListener(OnAllOn);
var alloff = _root.transform.Find("btnAllOff");
alloff.GetComponentInChildren<Button>().onClick.AddListener(OnAllOff);

#if KKS
allon.GetComponent<RectTransform>().sizeDelta = new Vector2(82, 24);
alloff.GetComponent<RectTransform>().sizeDelta = new Vector2(82, 24);
#endif

LoadButton = _root.transform.parent.Find("btnLoad").GetComponent<Button>();
}

Expand All @@ -143,6 +159,10 @@ internal static List<RectTransform> GetBaseToggles(Transform root)
var baseToggles = new List<RectTransform>();
foreach (var child in root.transform.Cast<Transform>().ToList())
{
#if KKS
// Ignore unused toggle in KKS trial
if (!child.gameObject.activeSelf) continue;
#endif
if (child.name.StartsWith("tglHeader"))
{
// Fix for Koikatsu Party, the toggles are now grouped
Expand Down

0 comments on commit 8a1fbfa

Please sign in to comment.