Beispiel #1
0
        /// <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(ContractParameter param, string newTitle)
        {
            // Try to find the cascading list in the contracts window.  Note that we may pick up
            // the ones from the Engineer's report in the VAB/SPH instead - but we don't care about
            // title updates in those scenes anyway.
            if (cascadingList == null || !cascadingList.gameObject.activeSelf)
            {
                cascadingList = UnityEngine.Object.FindObjectOfType <GenericCascadingList>();
            }

            // Every time the clock ticks over, make an attempt to update the contract window
            // title.  We do this because otherwise the window will only ever read the title once,
            // so this is the only way to get our fancy timer to work.

            // Go through all the list items in the contracts window
            if (cascadingList != null)
            {
                UIScrollList list = cascadingList.ruiList.cascadingList;
                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        // Try to find a rich text control that matches the expected text
                        UIListItemContainer listObject = (UIListItemContainer)list.GetItem(i);
                        SpriteTextRich      richText   = listObject.GetComponentInChildren <SpriteTextRich>();
                        if (richText != null)
                        {
                            // Check for any string in titleTracker
                            string found = null;
                            foreach (string title in titles)
                            {
                                if (richText.Text.Contains(title))
                                {
                                    found = title;
                                    break;
                                }
                            }

                            // Clear the titleTracker, and replace the text
                            if (found != null)
                            {
                                titles.Clear();
                                richText.Text = richText.Text.Replace(found, newTitle);
                                titles.Add(newTitle);
                            }
                        }
                    }

                    // Reposition items to account for items where the height increased or decreased
                    list.RepositionItems();
                }
            }

            // Contracts Window + update
            ContractsWindow.SetParameterTitle(param, newTitle);
        }
Beispiel #2
0
        /// <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);
        }