コード例 #1
0
        private void FixListItem(KSP.UI.UIListItem item)
        {
            float width = 166 * resizeFactor - (166 - 163);

            // Resize the item
            Text t = item.GetComponentsInChildren <Text>(true).FirstOrDefault();

            if (t)
            {
                t.rectTransform.sizeDelta = new Vector2(width, t.rectTransform.sizeDelta.y);
            }
        }
コード例 #2
0
        public void OnPreCull()
        {
            // Try to find the app frame for the contracts window.  Note that we may pick up
            // the ones from the Engineer's report in the VAB/SPH instead, so check by name.
            if (!contractsFrame)
            {
                // Check if this scene even has a contracts app
                IEnumerable <GenericAppFrame> frames = Resources.FindObjectsOfTypeAll <GenericAppFrame>();
                if (!frames.Any())
                {
                    Destroy(this);
                    return;
                }

                foreach (GenericAppFrame appFrame in frames)
                {
                    if (appFrame.header.text == "Contracts")
                    {
                        contractsFrame = appFrame;
                        break;
                    }
                }
            }

            if (contractsFrame)
            {
                LoggingUtil.LogInfo(this, "Making adjustments to contract frame...");

                // Set the new width and height (old value * factor)
                int width  = (int)(166 * resizeFactor);
                int height = (int)(176 * 2.5);
                widthField.SetValue(contractsFrame, width);

                // Apply the changes
                RectTransform rectTransform = (RectTransform)transformField.GetValue(contractsFrame);
                rectTransform.sizeDelta = new Vector2((float)width, (float)height);

                // Remove the limit on max height (technically should be a little less than screen height, but close enough)
                contractsFrame.maxHeight = Screen.height;

                // Apply the changes
                contractsFrame.Reposition();

                if (ContractsApp.Instance != null)
                {
                    // Find the cascading list field
                    foreach (FieldInfo cascadingListField in cascadingListFields)
                    {
                        GenericCascadingList ccl = (GenericCascadingList)cascadingListField.GetValue(ContractsApp.Instance);
                        if (ccl != null)
                        {
                            // Set the body width (I think this is used for word wrap logic)
                            ccl.bodyTextStartWidth = (int)(166 * resizeFactor - (166 - 151));

                            // Fix the prefab for the header - will apply to any newly added contracts
                            FixListItem(ccl.cascadeHeader);

                            // Fix the prefab for the body - used for contract notes
                            FixListItem(ccl.cascadeBody);
                        }
                    }

                    // Fix the prefab used for contract parameters
                    KSP.UI.UIListItem uiListPrefab = (KSP.UI.UIListItem)uiListPrefabField.GetValue(ContractsApp.Instance);
                    Text text = uiListPrefab.GetComponentsInChildren <Text>(true).FirstOrDefault();
                    if (text)
                    {
                        text.rectTransform.sizeDelta = new Vector2(166 * resizeFactor - (166 - 163), 14.0f);
                    }

                    // Refresh the contract list, forces everything to get recreated
                    refreshMethod.Invoke(ContractsApp.Instance, new object[] { });

                    // No need to hang around, the changes will stick for the lifetime of the app
                    Destroy(this);
                }
            }
        }