Skip to content

Commit

Permalink
Fix up options menu button styling
Browse files Browse the repository at this point in the history
  • Loading branch information
throckmorpheus committed Aug 21, 2024
1 parent b7c7e92 commit f375f3d
Showing 1 changed file with 68 additions and 16 deletions.
84 changes: 68 additions & 16 deletions src/OWML.ModHelper.Menus/NewMenuSystem/OptionsMenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,30 +467,80 @@ public GameObject AddSeparator(Menu menu, bool dots)

public SubmitAction CreateButton(Menu menu, string buttonLabel, string tooltip, MenuSide side)
{
var rootObj = new GameObject($"UIElement-{buttonLabel}");
rootObj.transform.parent = GetParentForAddedElements(menu);
rootObj.transform.localScale = Vector3.one;
rootObj.transform.localRotation = Quaternion.identity;
rootObj.transform.localPosition = Vector3.zero;

var layoutElement = rootObj.AddComponent<LayoutElement>();
layoutElement.minHeight = 70;
layoutElement.flexibleWidth = 1;

var existingHorizLayout = Resources.FindObjectsOfTypeAll<Menu>()
.Single(x => x.name == "GraphicsMenu").transform
.Find("Scroll View")
.Find("Viewport")
.Find("Content")
.Find("UIElement-ResolutionSelect")
.Find("HorizontalLayoutGroup").gameObject;

var newHorizLayout = Object.Instantiate(existingHorizLayout);
newHorizLayout.transform.parent = rootObj.transform;
newHorizLayout.transform.localPosition = Vector3.zero;
newHorizLayout.transform.localScale = Vector3.one;
newHorizLayout.transform.localRotation = Quaternion.identity;

var hrt = newHorizLayout.GetComponent<RectTransform>();
var ohrt = existingHorizLayout.GetComponent<RectTransform>();
//hrt.anchorMin = ohrt.anchorMin;
//hrt.anchorMax = ohrt.anchorMax;
hrt.offsetMin = ohrt.offsetMin;
hrt.offsetMax = ohrt.offsetMax;
hrt.anchoredPosition3D = ohrt.anchoredPosition3D;
hrt.sizeDelta = ohrt.sizeDelta;

hrt.anchorMax = new Vector2(0.5f, 1f);
switch (side)
{
case MenuSide.LEFT:
hrt.anchorMin = new Vector2(0f, 1f);
break;
case MenuSide.CENTER:
hrt.anchorMin = new Vector2(0.25f, 1f);
break;
case MenuSide.RIGHT:
hrt.anchorMin = new Vector2(0.5f, 1f);
break;
}

Object.Destroy(newHorizLayout.GetComponentInChildren<LocalizedText>());

var oldLabelComponent = newHorizLayout.transform
.Find("LabelBlock")
.Find("HorizontalLayoutGroup")
.Find("Label")
.GetComponent<Text>();
var labelFont = oldLabelComponent.font;
var labelFontSize = oldLabelComponent.fontSize;

Object.Destroy(newHorizLayout.transform.Find("LabelBlock").gameObject);

var controlBlock = newHorizLayout.transform.Find("ControlBlock");
Object.Destroy(controlBlock.Find("OptionSelectorBG").gameObject);
Object.Destroy(controlBlock.Find("HorizontalLayoutGroup").gameObject);

var existingButton = Resources.FindObjectsOfTypeAll<Button>().First(x => x.name == "UIElement-ButtonContinue");

var newButtonObj = Object.Instantiate(existingButton);
newButtonObj.transform.parent = GetParentForAddedElements(menu);
newButtonObj.transform.parent = controlBlock;
newButtonObj.transform.localPosition = Vector3.zero;
newButtonObj.transform.localScale = Vector3.one;
newButtonObj.name = $"UIElement-Button-{buttonLabel}";
newButtonObj.transform.localRotation = Quaternion.identity;

if (side == MenuSide.LEFT)
{
Object.Destroy(newButtonObj.transform.Find("ForegroundLayoutGroup/RightSpacer").gameObject);
newButtonObj.transform.Find("ForegroundLayoutGroup/LeftSpacer").SetAsFirstSibling();
}
else if (side == MenuSide.CENTER)
{
Object.Destroy(newButtonObj.transform.Find("ForegroundLayoutGroup/RightSpacer").gameObject);
Object.Destroy(newButtonObj.transform.Find("ForegroundLayoutGroup/LeftSpacer").gameObject);
}
else if (side == MenuSide.RIGHT)
{
Object.Destroy(newButtonObj.transform.Find("ForegroundLayoutGroup/LeftSpacer").gameObject);
newButtonObj.transform.Find("ForegroundLayoutGroup/RightSpacer").SetAsFirstSibling();
}
Object.Destroy(newButtonObj.transform.Find("ForegroundLayoutGroup/RightSpacer").gameObject);
Object.Destroy(newButtonObj.transform.Find("ForegroundLayoutGroup/LeftSpacer").gameObject);

Object.Destroy(newButtonObj.GetComponent<SubmitAction>());
var submitAction = newButtonObj.gameObject.AddComponent<SubmitAction>();
Expand All @@ -502,6 +552,8 @@ public SubmitAction CreateButton(Menu menu, string buttonLabel, string tooltip,
menuOption._overrideTooltipText = tooltip;
menuOption._label = newButtonObj.GetComponentInChildren<Text>();
menuOption._label.text = buttonLabel;
menuOption._label.font = labelFont;
menuOption._label.fontSize = labelFontSize;

menu._menuOptions = menu._menuOptions.Add(menuOption);

Expand Down

0 comments on commit f375f3d

Please sign in to comment.