Skip to content

Commit

Permalink
TrackingStation and MissionControl addition now respect UI scaling co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
MaximeBrean committed Jan 8, 2025
1 parent 2bbf08e commit 485b054
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
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
21 changes: 7 additions & 14 deletions source/ContractConfigurator/TrackingStationUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public void Awake()
offeredOrbitEnabledSprite = UnityEngine.Sprite.Create(uiAtlas, new Rect(0, 8, 40, 40), new Vector2(0, 0));
offeredOrbitDisabledSprite = UnityEngine.Sprite.Create(uiAtlas, new Rect(40, 8, 40, 40), new Vector2(0, 0));
}
this.foostart();
}

public void Start()
public void foostart()
{
LoggingUtil.LogVerbose(this, "Start");

Expand All @@ -80,12 +81,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 +128,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 +142,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

0 comments on commit 485b054

Please sign in to comment.