/// <summary> /// When notified the Engineer's Report app is ready, bind to it and set up a clobber. /// </summary> public void BindToEngineersReport() { // Set up all our fields BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy; Type typeER = EngineersReport.Instance.GetType(); _refERsizeLH = (TMPro.TextMeshProUGUI)typeER.GetField("sizeLH", flags).GetValue(EngineersReport.Instance); _refERsizeRH = (TMPro.TextMeshProUGUI)typeER.GetField("sizeRH", flags).GetValue(EngineersReport.Instance); _refERpartMassLH = (TMPro.TextMeshProUGUI)typeER.GetField("partMassLH", flags).GetValue(EngineersReport.Instance); _refERpartMassRH = (TMPro.TextMeshProUGUI)typeER.GetField("partMassRH", flags).GetValue(EngineersReport.Instance); _refERappFrame = (GenericAppFrame)typeER.GetField("appFrame", flags).GetValue(EngineersReport.Instance); EditorStarted(); }
private void UIAppAwake(ApplicationLauncherButton button, UIApp app) { if (button == null || app == null) { return; } buttons.Add(button); if (app is ContractsApp) { button.onHover = (Callback)Delegate.Combine(button.onHover, new Callback(OnContractHover)); button.onTrue = (Callback)Delegate.Combine(button.onTrue, new Callback(OnContractOpen)); button.onHoverOut = (Callback)Delegate.Combine(button.onHoverOut, new Callback(OnContractHoverOut)); button.onFalse = (Callback)Delegate.Combine(button.onFalse, new Callback(OnContractClosed)); var fields = typeof(ContractsApp).GetFields(BindingFlags.NonPublic | BindingFlags.Instance); GenericAppFrame appframe = fields[7].GetValue((ContractsApp)app) as GenericAppFrame; if (appframe != null) { appframe.AddGlobalInputDelegate(new UnityAction <PointerEventData>(OnAppEnter), new UnityAction <PointerEventData>(OnAppExit)); } } else if (app is EngineersReport) { button.onHover = (Callback)Delegate.Combine(button.onHover, new Callback(OnEngineerHover)); button.onTrue = (Callback)Delegate.Combine(button.onTrue, new Callback(OnEngineerOpen)); button.onHoverOut = (Callback)Delegate.Combine(button.onHoverOut, new Callback(OnEngineerHoverOut)); button.onFalse = (Callback)Delegate.Combine(button.onFalse, new Callback(OnEngineerClosed)); var fields = typeof(EngineersReport).GetFields(BindingFlags.NonPublic | BindingFlags.Instance); GenericAppFrame appframe = fields[1].GetValue((EngineersReport)app) as GenericAppFrame; if (appframe != null) { appframe.AddGlobalInputDelegate(new UnityAction <PointerEventData>(OnAppEnter), new UnityAction <PointerEventData>(OnAppExit)); } } }
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); } } }
private void loadSprites() { Texture2D twr = GameDatabase.Instance.GetTexture("BasicDeltaV/Resources/TWRGauge", false); twrGaugeSprite = Sprite.Create(twr, new Rect(0, 0, twr.width, twr.height), new Vector2(0.5f, 0.5f)); ContractsApp prefab = null; var prefabs = Resources.FindObjectsOfTypeAll <ContractsApp>(); for (int i = prefabs.Length - 1; i >= 0; i--) { var pre = prefabs[i]; if (pre.name != "ContractsApp") { continue; } prefab = pre; break; } if (prefab == null) { return; } GenericAppFrame appFrame = null; GenericCascadingList cascadingList = null; UIListItem_spacer spacer = null; try { var fields = typeof(ContractsApp).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).ToArray(); appFrame = fields[7].GetValue(prefab) as GenericAppFrame; cascadingList = fields[9].GetValue(prefab) as GenericCascadingList; spacer = fields[11].GetValue(prefab) as UIListItem_spacer; } catch (Exception e) { BasicDeltaV.BasicLogging("Error in processing toolbar panel UI: {0}", e); } if (appFrame != null) { windowSprite = appFrame.gfxBg.sprite; titleSprite = appFrame.gfxHeader.sprite; footerSprite = appFrame.gfxFooter.sprite; } if (cascadingList != null) { buttonSprite = cascadingList.cascadeHeader.GetComponent <Image>().sprite; contentFooterSprite = cascadingList.cascadeFooter.GetComponent <Image>().sprite; } if (spacer != null) { componentSprite = spacer.GetComponent <Image>().sprite; UIStateImage stateImage = spacer.GetComponentInChildren <UIStateImage>(); selectedSprite = stateImage.states[1].sprite; unselectedSprite = stateImage.states[0].sprite; } spritesLoaded = true; }
private void loadSprites() { ContractsApp prefab = null; var prefabs = Resources.FindObjectsOfTypeAll <ContractsApp>(); for (int i = prefabs.Length - 1; i >= 0; i--) { var pre = prefabs[i]; if (pre.name != "ContractsApp") { continue; } prefab = pre; break; } if (prefab != null) { GenericAppFrame appFrame = null; GenericCascadingList cascadingList = null; UIListItem_spacer spacer = null; try { var fields = typeof(ContractsApp).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).ToArray(); appFrame = fields[7].GetValue(prefab) as GenericAppFrame; cascadingList = fields[9].GetValue(prefab) as GenericCascadingList; spacer = fields[11].GetValue(prefab) as UIListItem_spacer; } catch (Exception e) { BasicOrbit.BasicLogging("Error in processing toolbar panel UI: {0}", e); } if (appFrame != null) { windowSprite = appFrame.gfxBg.sprite; titleSprite = appFrame.gfxHeader.sprite; footerSprite = appFrame.gfxFooter.sprite; } if (cascadingList != null) { buttonSprite = cascadingList.cascadeHeader.GetComponent <Image>().sprite; contentFooterSprite = cascadingList.cascadeFooter.GetComponent <Image>().sprite; } if (spacer != null) { componentSprite = spacer.GetComponent <Image>().sprite; UIStateImage stateImage = spacer.GetComponentInChildren <UIStateImage>(); selectedSprite = stateImage.states[1].sprite; unselectedSprite = stateImage.states[0].sprite; } } StageManager prefabFlight = null; var stages = Resources.FindObjectsOfTypeAll <StageManager>(); for (int i = stages.Length - 1; i >= 0; i--) { var pre = stages[i]; if (pre.name == "StageManager") { prefabFlight = pre; } } if (prefabFlight != null) { StageGroup group = prefabFlight.stageGroupPrefab; Transform layout = group.transform.FindChild("IconLayout"); if (layout != null) { panelSprite = layout.GetComponent <Image>().sprite; } } spritesLoaded = true; }