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

Fix UI scaling issue #49

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions source/ContractConfigurator/MissionControlUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void Update()
{
toggleAllObj = UnityEngine.Object.Instantiate<GameObject>(toggleAvailable);
toggleAllObj.name = "Toggle All";
toggleAllObj.transform.SetParent(sortGroup.transform);
toggleAllObj.transform.SetParent(sortGroup.transform, false);
toggleAllObj.transform.SetAsFirstSibling();
}

Expand Down Expand Up @@ -1012,7 +1012,7 @@ protected void SetupGroupItem(GroupContainer groupContainer)
{
availableTextObject = UnityEngine.Object.Instantiate<GameObject>(groupContainer.mcListItem.title.gameObject);
availableTextObject.name = "AvailableText";
availableTextObject.transform.SetParent(groupContainer.mcListItem.title.transform.parent);
availableTextObject.transform.SetParent(groupContainer.mcListItem.title.transform.parent, false);
RectTransform availableTextRect = availableTextObject.GetComponent<RectTransform>();
availableTextRect.anchoredPosition3D = textRect.anchoredPosition3D;
availableTextRect.sizeDelta = new Vector2(textRect.sizeDelta.x + 4, textRect.sizeDelta.y - 4);
Expand Down Expand Up @@ -1070,7 +1070,7 @@ protected void CreateContractItem(ContractContainer cc, int indent = 0, KSP.UI.U
cc.statusImage = statusImage.AddComponent<UIStateImage>();
cc.statusImage.states = itemStatusStates;
cc.statusImage.image = statusImage.AddComponent<Image>();
statusImage.transform.SetParent(mcListItem.transform);
statusImage.transform.SetParent(mcListItem.transform, false);

// Finalize difficulty UI
RectTransform diffRect = mcListItem.difficulty.GetComponent<RectTransform>();
Expand Down Expand Up @@ -1148,7 +1148,7 @@ protected void InsertIntoList(Container container, int indent, KSP.UI.UIListItem
UIList<KSP.UI.UIListItem> childUIList = (UIList<KSP.UI.UIListItem>)childUIListField.GetValue(MissionControl.Instance.scrollListContracts);
List<UIListData<KSP.UI.UIListItem>> listData = (List<UIListData<KSP.UI.UIListItem>>)listDataField.GetValue(childUIList);
listData.Insert(index + 1, new UIListData<KSP.UI.UIListItem>((KSP.UI.UIListItem)null, container.mcListItem.container));
container.mcListItem.container.transform.SetParent(childUIList.listAnchor);
container.mcListItem.container.transform.SetParent(childUIList.listAnchor, false);
container.mcListItem.container.transform.localPosition = new Vector3(container.mcListItem.container.transform.localPosition.x, container.mcListItem.container.transform.localPosition.y, 0.0f);

container.listItemTransform = container.mcListItem.transform;
Expand Down Expand Up @@ -1214,7 +1214,7 @@ protected void SetIndent(MCListItem mcListItem, int indent)

// Re-order the hierarchy to add spacers for indented items
GameObject go = new GameObject("GroupContainer");
go.transform.parent = mcListItem.transform.parent;
go.transform.SetParent(mcListItem.transform.parent, false);
go.AddComponent<RectTransform>();
go.AddComponent<CanvasRenderer>();
go.AddComponent<HorizontalLayoutGroup>();
Expand All @@ -1229,8 +1229,8 @@ protected void SetIndent(MCListItem mcListItem, int indent)
spacerFitter.horizontalFit = ContentSizeFitter.FitMode.MinSize;

// Re-parent the spacer and list item
spacer.transform.SetParent(go.transform);
mcListItem.transform.SetParent(go.transform);
spacer.transform.SetParent(go.transform, false);
mcListItem.transform.SetParent(go.transform, false);

// Perform some surgery on the list item to set its preferred width to the correct value
LayoutElement le = mcListItem.GetComponent<LayoutElement>();
Expand Down
18 changes: 5 additions & 13 deletions source/ContractConfigurator/TrackingStationUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ public void Start()
offeredOrbitButton = UnityEngine.Object.Instantiate(lastButton.button.gameObject);
offeredOrbitButton.name = "Button Offered Orbits";

// Fix z coordinates
activeWaypointButton.GetComponent<RectTransform>().SetLocalPositionZ(750);
offeredWaypointButton.GetComponent<RectTransform>().SetLocalPositionZ(750);
activeOrbitButton.GetComponent<RectTransform>().SetLocalPositionZ(750);
offeredOrbitButton.GetComponent<RectTransform>().SetLocalPositionZ(750);

// Set up the tool-tips
activeWaypointButton.GetComponent<TooltipController_Text>().textString = "Toggle Active Waypoints";
offeredWaypointButton.GetComponent<TooltipController_Text>().textString = "Toggle Offered Waypoints";
Expand Down Expand Up @@ -133,12 +127,10 @@ public void Start()

// Re-parent
GameObject trackingFilters = lastButton.button.transform.parent.gameObject;
RectTransform trackingFiltersRect = trackingFilters.GetComponent<RectTransform>();
trackingFiltersRect.sizeDelta = new Vector2(trackingFiltersRect.sizeDelta.x + 44 * 2, trackingFiltersRect.sizeDelta.y);
activeWaypointButton.transform.SetParent(trackingFilters.transform);
offeredWaypointButton.transform.SetParent(trackingFilters.transform);
activeOrbitButton.transform.SetParent(trackingFilters.transform);
offeredOrbitButton.transform.SetParent(trackingFilters.transform);
activeWaypointButton.transform.SetParent(trackingFilters.transform, false);
offeredWaypointButton.transform.SetParent(trackingFilters.transform, false);
activeOrbitButton.transform.SetParent(trackingFilters.transform, false);
offeredOrbitButton.transform.SetParent(trackingFilters.transform, false);
activeWaypointButton.SetActive(true);
offeredWaypointButton.SetActive(true);
activeOrbitButton.SetActive(true);
Expand All @@ -149,7 +141,7 @@ public void Start()
if (commNet != null)
{
RectTransform r = commNet.GetComponent<RectTransform>();
r.localPosition = new Vector3(r.localPosition.x + 132, r.localPosition.y);
r.localPosition = new Vector3(r.localPosition.x + 140, r.localPosition.y);
}

LoggingUtil.LogVerbose(this, "Finished setup");
Expand Down
Loading