Skip to content

Commit

Permalink
Fixed studio custom controls being inconsistent across PCs
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Mar 10, 2019
1 parent 86fe544 commit 50ac577
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 79 deletions.
146 changes: 76 additions & 70 deletions KKAPI/Studio/UI/CurrentStateCategory.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,77 @@
using System.Collections.Generic;
using System.Linq;
using Studio;
using UnityEngine;
using UnityEngine.UI;

namespace KKAPI.Studio.UI
{
/// <summary>
/// Category under the Anim > CustomState tab
/// </summary>
public class CurrentStateCategory
{
/// <summary>
/// Create a new custom CurrentState category
/// </summary>
/// <param name="categoryName">Name of the category</param>
/// <param name="subItems">Controls under this category</param>
public CurrentStateCategory(string categoryName, IEnumerable<CurrentStateCategorySubItemBase> subItems)
{
CategoryName = categoryName;
SubItems = subItems.ToList();
}

/// <summary>
/// Name of the category. Controls are drawn under it.
/// </summary>
public string CategoryName { get; }

/// <summary>
/// All custom controls under this category.
/// </summary>
public IEnumerable<CurrentStateCategorySubItemBase> SubItems { get; }

/// <summary>
/// Used by the API to actually create the custom control object
/// </summary>
protected internal virtual void CreateCategory(GameObject containerObject)
{
var original = GameObject.Find("StudioScene/Canvas Main Menu/02_Manipulate/00_Chara/01_State/Viewport/Content/Cos/Text");

var cat = Object.Instantiate(original, containerObject.transform, true);
cat.AddComponent<LayoutElement>();
cat.name = "StudioAPI-Header-" + CategoryName;

var t = cat.GetComponent<Text>();
t.fontSize = 15;
t.resizeTextMaxSize = 15;
t.text = CategoryName;

var catContents = new GameObject("StudioAPI-Category-" + CategoryName);
catContents.transform.SetParent(containerObject.transform);
catContents.AddComponent<RectTransform>().anchorMin = new Vector2(0, 1.04f);
var vlg = catContents.AddComponent<VerticalLayoutGroup>();
vlg.padding = new RectOffset(0, 0, 4, 4);

foreach (var subItem in SubItems)
subItem.CreateItem(catContents);
}

/// <summary>
/// Fired when currently selected character changes and the controls need to be updated
/// </summary>
/// <param name="ociChar">Newly selected character</param>
protected internal virtual void UpdateInfo(OCIChar ociChar)
{
foreach (var subItem in SubItems)
subItem.OnUpdateInfo(ociChar);
}
}
using System.Collections.Generic;
using System.Linq;
using Studio;
using UnityEngine;
using UnityEngine.UI;

namespace KKAPI.Studio.UI
{
/// <summary>
/// Category under the Anim > CustomState tab
/// </summary>
public class CurrentStateCategory
{
/// <summary>
/// Create a new custom CurrentState category
/// </summary>
/// <param name="categoryName">Name of the category</param>
/// <param name="subItems">Controls under this category</param>
public CurrentStateCategory(string categoryName, IEnumerable<CurrentStateCategorySubItemBase> subItems)
{
CategoryName = categoryName;
SubItems = subItems.ToList();
}

/// <summary>
/// Name of the category. Controls are drawn under it.
/// </summary>
public string CategoryName { get; }

/// <summary>
/// All custom controls under this category.
/// </summary>
public IEnumerable<CurrentStateCategorySubItemBase> SubItems { get; }

/// <summary>
/// Used by the API to actually create the custom control object
/// </summary>
protected internal virtual void CreateCategory(GameObject containerObject)
{
var original = GameObject.Find("StudioScene/Canvas Main Menu/02_Manipulate/00_Chara/01_State/Viewport/Content/Cos/Text");

var cat = Object.Instantiate(original, containerObject.transform, true);
cat.AddComponent<LayoutElement>();
cat.name = CategoryName + "_Header_SAPI";

var t = cat.GetComponent<Text>();
t.fontSize = 15;
t.resizeTextMaxSize = 15;
t.text = CategoryName;

var catContents = new GameObject(CategoryName + "_Items_SAPI");
catContents.transform.SetParent(containerObject.transform);

var rt = catContents.AddComponent<RectTransform>();
// Fixes issue with left offset being wrong
rt.pivot = new Vector2(0, 0.5f);
rt.localScale = Vector3.one;

var vlg = catContents.AddComponent<VerticalLayoutGroup>();
vlg.padding = new RectOffset(0, 0, 0, 0);
vlg.spacing = 4;
vlg.childAlignment = TextAnchor.UpperLeft;
foreach (var subItem in SubItems)
subItem.CreateItem(catContents);
}

/// <summary>
/// Fired when currently selected character changes and the controls need to be updated
/// </summary>
/// <param name="ociChar">Newly selected character</param>
protected internal virtual void UpdateInfo(OCIChar ociChar)
{
foreach (var subItem in SubItems)
subItem.OnUpdateInfo(ociChar);
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions KKAPI/Studio/UI/CurrentStateCategoryToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,15 @@ protected internal override void CreateItem(GameObject categoryObject)

var copy = Object.Instantiate(original, categoryObject.transform, true);
copy.name = "CustomToggle-" + Name;
copy.transform.localScale = Vector3.one;

var text = copy.transform.Find("Text Tears");
text.name = "Text " + Name;
var text1 = text.GetComponent<Text>();
text1.text = Name;

var items = copy.transform.Cast<Transform>().ToList();

foreach (var transform in items.Select(x => x.GetComponent<RectTransform>()))
{
transform.offsetMin = new Vector2(transform.offsetMin.x + 21, transform.offsetMin.y);
transform.offsetMax = new Vector2(transform.offsetMax.x + 21, transform.offsetMax.y);
}

var buttons = items.Skip(1).Select(x => x.GetComponent<Button>()).ToList();
var subItems = copy.transform.Cast<Transform>();
var buttons = subItems.Skip(1).Select(x => x.GetComponent<Button>()).ToList();
for (var i = 0; i < 4; i++)
{
var btn = buttons[i];
Expand Down

0 comments on commit 50ac577

Please sign in to comment.