/// <summary> /// Call this any time the title text has changed - this will make an attempt to update /// the contract window title. We do this because otherwise the window will only ever read /// the title once. /// </summary> /// <param name="newTitle">New title to display</param> public void UpdateContractWindow(string newTitle) { // Get the cascading list for our contract if (text == null && ContractsApp.Instance != null) { UICascadingList.CascadingListItem list = TitleTrackerHelper.uiListMap.ContainsKey(parameter.Root.ContractGuid) ? TitleTrackerHelper.uiListMap[parameter.Root.ContractGuid] : null; if (list != null) { foreach (KSP.UI.UIListItem item in list.items) { Text textComponent = item.GetComponentsInChildren <Text>(true).FirstOrDefault(); if (textComponent != null) { // Check for any string in titleTracker foreach (string title in titles) { if (textComponent.text.EndsWith(">" + title + "</color>")) { text = textComponent; layoutElement = item.GetComponentsInChildren <LayoutElement>(true).FirstOrDefault(); break; } } if (text != null) { break; } } } } } if (text) { // Clear the titleTracker, and replace the text if (!text.text.Contains(">" + newTitle + "<")) { float preHeight = text.preferredHeight; titles.Clear(); text.text = text.text.Substring(0, text.text.IndexOf(">") + 1) + newTitle + "</color>"; titles.Add(newTitle); float postHeight = text.preferredHeight; if (preHeight != postHeight) { text.rectTransform.sizeDelta = new Vector2(text.rectTransform.sizeDelta.x, postHeight + 4f); layoutElement.preferredHeight = postHeight + 6f; // Force an update to the layout even when not active if (!layoutElement.IsActive()) { LayoutRebuilder.MarkLayoutForRebuild(layoutElement.transform as RectTransform); } } } } // Contracts Window + update ContractsWindow.SetParameterTitle(parameter, newTitle); }