private IEnumerator HandleUpgradeButton() { //borrowed from Magico13's KCT :) yield return(new WaitForFixedUpdate()); SpaceCenterBuilding hostBuilding = GetMember <SpaceCenterBuilding>("host"); overriddenFacility = hostBuilding.Facility; Debug.Log("[Bureaucracy]: Trying to override upgrade button of menu for " + hostBuilding.facilityName); Button button = GetMember <Button>("UpgradeButton"); if (button == null) { Debug.Log("[Bureaucracy]: Could not find UpgradeButton by name, using index instead."); button = GetMember <Button>(2); } if (button != null) { Debug.Log("[Bureaucracy]: Found upgrade button, overriding it."); button.onClick = new Button.ButtonClickedEvent(); //Clear existing KSP listener button.onClick.AddListener(HandleUpgrade); } else { throw new Exception("[Bureaucracy]: UpgradeButton not found. Cannot override."); } }
public IEnumerator OnContextMenuSpawn() { yield return(new WaitForFixedUpdate()); if (KCT_PresetManager.Instance.ActivePreset.generalSettings.KSCUpgradeTimes && _menu != null) { SpaceCenterBuilding hostBuilding = getMember <SpaceCenterBuilding>("host"); KCTDebug.Log("Trying to override upgrade button of menu for " + hostBuilding.facilityName); UnityEngine.UI.Button button = getMember <UnityEngine.UI.Button>("UpgradeButton"); if (button == null) { KCTDebug.Log("Could not find UpgradeButton by name, using index instead.", true); button = getMember <UnityEngine.UI.Button>(2); } if (button != null) { KCTDebug.Log("Found upgrade button, overriding it."); button.onClick = new UnityEngine.UI.Button.ButtonClickedEvent(); //Clear existing KSP listener button.onClick.AddListener(handleUpgrade); } else { throw new Exception("UpgradeButton not found. Cannot override."); } } }
/// <summary> /// Triggers the right-click building method /// </summary> /// <param name="b"></param> private void rightClick(SpaceCenterBuilding b) { if (!overlay && !InputLockManager.IsLocked(ControlTypes.KSC_FACILITIES)) { SpaceCenterSetup.rightClick.Invoke(b, null); } }
/// <summary> /// UI setup method; primarily taken from http://chikkooos.blogspot.jp/2015/03/new-ui-implementation-using-c-scripts.html /// </summary> private void UISetup() { canvas = createCanvas(this.transform); eventSystem = createEvent(canvas.transform); panel = createCanvas(canvas.transform); for (int i = 0; i < SpaceCenterSetup.buttons.Length; i++) { float f = 1f; if (i == 6) { f = 0.85f; } else if (i == 8) { f = 0.95f; } else if (i == 9) { f = 0.75f; } SpaceCenterBuilding B = buildings[i]; createButton(panel.transform, SpaceCenterSetup.buttons[i], SpaceCenterSetup.icons[i], delegate { leftClick(B); }, delegate { rightClick(B); }, B.OnMouseOver, B.OnMouseExit, f); string m = i < 9 ? (i + 1).ToString() : "0"; createText(panel.transform, new Rect(SpaceCenterSetup.buttons[i].x - 9, SpaceCenterSetup.buttons[i].y + 18, 18, 18), m, 24); } }
public IEnumerator OnContextMenuSpawn() { yield return(new WaitForFixedUpdate()); if (KCT_PresetManager.Instance.ActivePreset.generalSettings.KSCUpgradeTimes && _menu != null) { SpaceCenterBuilding hostBuilding = getMember <SpaceCenterBuilding>("host"); KCTDebug.Log("Trying to override upgrade button of menu for " + hostBuilding.facilityName); Button button = getMember <Button>("UpgradeButton"); if (button == null) { KCTDebug.Log("Could not find UpgradeButton by name, using index instead.", true); button = getMember <UnityEngine.UI.Button>(2); } if (button != null) { KCTDebug.Log("Found upgrade button, overriding it."); button.onClick = new Button.ButtonClickedEvent(); //Clear existing KSP listener button.onClick.AddListener(HandleUpgrade); if (KCT_PresetManager.Instance.ActivePreset.generalSettings.DisableLPUpgrades && GetFacilityID().ToLower().Contains("launchpad")) { button.interactable = false; var hov = button.gameObject.GetComponent <UIOnHover>(); hov.gameObject.DestroyGameObject(); _menu.levelStatsText.text = "<color=red><b>Launchpads cannot be upgraded. Build a new launchpad from the KCT menu instead.</b></color>"; } } else { throw new Exception("UpgradeButton not found. Cannot override."); } } }
public IEnumerator OnContextMenuSpawn() { yield return(new WaitForFixedUpdate()); if (PresetManager.Instance.ActivePreset.GeneralSettings.KSCUpgradeTimes && _menu != null) { SpaceCenterBuilding hostBuilding = GetMember <SpaceCenterBuilding>("host"); KCTDebug.Log($"Trying to override upgrade button of menu for {hostBuilding.facilityName}"); Button button = GetMember <Button>("UpgradeButton"); if (button == null) { KCTDebug.Log("Could not find UpgradeButton by name, using index instead."); button = GetMember <Button>(2); } if (button != null) { KCTDebug.Log("Found upgrade button, overriding it."); button.onClick = new Button.ButtonClickedEvent(); //Clear existing KSP listener button.onClick.AddListener(HandleUpgrade); if ((PresetManager.Instance.ActivePreset.GeneralSettings.DisableLPUpgrades && GetFacilityID().IndexOf("launchpad", StringComparison.OrdinalIgnoreCase) >= 0) || (PresetManager.Instance.ActivePreset.GeneralSettings.CommonBuildLine && GetFacilityID().IndexOf("SpaceplaneHangar", StringComparison.OrdinalIgnoreCase) >= 0)) { button.interactable = false; var hov = button.gameObject.GetComponent <UIOnHover>(); hov.gameObject.DestroyGameObject(); } } else { throw new Exception("UpgradeButton not found. Cannot override."); } } }
/// <summary> /// Triggers the right-click building method /// </summary> /// <param name="b"></param> private void rightClick(SpaceCenterBuilding b) { if (!overlay && !InputLockManager.IsLocked(ControlTypes.KSC_FACILITIES)) SpaceCenterSetup.rightClick.Invoke(b, null); }