private void onFlightReady() { if (!buttonInit) { modebuttons = FindObjectOfType <VesselAutopilotUI>().modeButtons; modebuttons[0].getSpriteStates(out buttonActive, out buttonDisabled); foreach (UIStateToggleButton button in modebuttons) { button.onClick.AddListener(delegate { onSASbuttonPressed(button); }); } GameObject parallelNegative = Instantiate(modebuttons[5].gameObject); GameObject parallelPlus = Instantiate(modebuttons[5].gameObject); parallelNegative.SetActive(true); parallelPlus.SetActive(true); this.parallelNegative = parallelNegative.GetComponent <UIStateToggleButton>(); this.parallelNegative.onClick.RemoveAllListeners(); this.parallelNegative.onClick.AddListener(delegate { onToggleButtonPressed(this.parallelNegative); }); this.parallelNegative.stateTrue = buttonActive; this.parallelNegative.stateFalse = buttonDisabled; this.parallelNegative.name = "ParallelNegative"; this.parallelNegative.SetState(false); this.parallelNegative.interactable = false; this.parallelNegative.transform.position = modebuttons[7].transform.position; this.parallelNegative.transform.localScale = new Vector3(1 * GameSettings.UI_SCALE * GameSettings.UI_SCALE_NAVBALL, 1 * GameSettings.UI_SCALE * GameSettings.UI_SCALE_NAVBALL); this.parallelNegative.transform.position = new Vector3(parallelNegative.gameObject.transform.position.x + ((4 * GameSettings.UI_SCALE_NAVBALL) * GameSettings.UI_SCALE), parallelNegative.gameObject.transform.position.y - ((25 * GameSettings.UI_SCALE_NAVBALL) * GameSettings.UI_SCALE)); this.parallelPlus = parallelPlus.GetComponent <UIStateToggleButton>(); this.parallelPlus.onClick.RemoveAllListeners(); this.parallelPlus.onClick.AddListener(delegate { onToggleButtonPressed(this.parallelPlus); }); this.parallelPlus.stateTrue = buttonActive; this.parallelPlus.stateFalse = buttonDisabled; this.parallelPlus.name = "ParallelPlus"; this.parallelPlus.SetState(false); this.parallelPlus.interactable = false; this.parallelPlus.transform.position = modebuttons[8].transform.position; this.parallelPlus.transform.localScale = new Vector3(1 * GameSettings.UI_SCALE * GameSettings.UI_SCALE_NAVBALL, 1 * GameSettings.UI_SCALE * GameSettings.UI_SCALE_NAVBALL); this.parallelPlus.transform.position = new Vector3(parallelPlus.gameObject.transform.position.x + ((4 * GameSettings.UI_SCALE_NAVBALL) * GameSettings.UI_SCALE), parallelPlus.gameObject.transform.position.y - ((25 * GameSettings.UI_SCALE_NAVBALL) * GameSettings.UI_SCALE)); parallelNegative.GetComponent <TooltipController_Text>().textString = "Parallel -"; parallelNegative.GetChild("Image").GetComponent <Image>().sprite = AssetLoader.parallelMinus.toSprite(); parallelNegative.transform.SetParent(UnityEngine.Object.FindObjectOfType <VesselAutopilotUI>().transform); parallelPlus.GetComponent <TooltipController_Text>().textString = "Parallel +"; parallelPlus.GetChild("Image").GetComponent <Image>().sprite = AssetLoader.parallelPlus.toSprite(); parallelPlus.transform.SetParent(UnityEngine.Object.FindObjectOfType <VesselAutopilotUI>().transform); buttonInit = true; Debug.Log($"[{DISPLAYNAME}] UI initiated"); } vessel = FlightGlobals.ActiveVessel; SetNewState(false, true); }
private void onSASbuttonPressed(UIStateToggleButton button) { if (autopilotState) { parallelNegative.SetState(false); parallelPlus.SetState(false); vesselDockingAid.onModeChange(TargetMode.OFF); SetNewState(false, false); } }
internal static void SetColor(this UIStateToggleButton toggle, Color?color, UIStateToggleButton stockButton = null) { Image image = toggle?.GetComponent <Image>(); if (image != null && color != null) { Image stockImage = stockButton?.GetComponent <Image>(); image.SetColor(color, stockImage); } }
private void onToggleButtonPressed(UIStateToggleButton button) { modebuttons[0].changeState(buttonDisabled); if (button == parallelNegative) { vesselDockingAid.onModeChange(TargetMode.PARALLEL_NEGATIVE); SetNewState(false, false); } else { vesselDockingAid.onModeChange(TargetMode.PARALLEL_PLUS); SetNewState(false, false); } }
internal static void SetTexture(this UIStateToggleButton toggle, Texture newTex, UIStateToggleButton stockToggle = null) { if (toggle != null) { BState[] states = { toggle.stateTrue, toggle.stateFalse }; BState[] stockStates = { stockToggle?.stateTrue, stockToggle?.stateFalse }; for (int i = 0; i < states?.Length; i++) { BState stock = stockStates[i]; states[i].disabled = states[i].disabled.SetTexture(newTex ?? stock?.disabled?.texture); states[i].normal = states[i].normal.SetTexture(newTex ?? stock?.normal?.texture); states[i].highlight = states[i].highlight.SetTexture(newTex ?? stock?.highlight?.texture); states[i].pressed = states[i].pressed.SetTexture(newTex ?? stock?.pressed?.texture); } } }
internal void ApplyTo(FlightUIModeController controller) { Debug.Log("CustomNavBall.ApplyTo", "controller = " + controller); if (Nyan.forever) { NyanNavBall.ApplyTo(controller); return; } if (controller == null) { return; } Transform original = DefaultNavBall.Instance?.transform; Material newNavball = controller?.gameObject?.GetChild("NavBall")?.GetComponent <Renderer>()?.material; Material stockNavball = original?.gameObject?.GetChild("NavBall")?.GetComponent <Renderer>()?.material; Debug.Log("StockTexturesAndColors", "NavBall = " + stockNavball?.GetColor("_TintColor") + "NavBallTex = " + stockNavball?.GetTexture("_MainTexture")); if (newNavball != null) { newNavball.SetTintColor(NavBall, stockNavball); newNavball.SetMainTexture(NavBallTex, stockNavball); } GameObject newShadingObj = controller?.gameObject?.GetChild("NavBall_OverlayMask"); GameObject stockShadingObj = original?.gameObject?.GetChild("NavBall_OverlayMask"); if (newShadingObj != null) { Image newShading = newShadingObj?.GetChild("shadingOverlay")?.GetComponent <Image>(); Image stockShading = stockShadingObj?.GetChild("shadingOverlay")?.GetComponent <Image>(); Debug.Log("StockTexturesAndColors", "Shading = " + stockShading?.color + "ShadingTex = " + stockShading?.sprite?.texture); if (newShading != null) { newShading.SetColor(Shading, stockShading); newShading.SetTexture(ShadingTex, stockShading, true); } Image newShadingMask = newShadingObj.GetComponent <Image>(); Image stockShadingMask = stockShadingObj.GetComponent <Image>(); Debug.Log("StockTexturesAndColors", "ShadingMaskTex = " + stockShadingMask?.sprite?.texture); if (newShadingMask != null) { newShadingMask.SetTexture(ShadingMaskTex, stockShadingMask, true); } } Image newCursor = controller?.gameObject?.GetChild("NavBallCursor")?.GetComponent <Image>(); Image stockCursor = original?.gameObject?.GetChild("NavBallCursor")?.GetComponent <Image>(); Debug.Log("StockTexturesAndColors", "Cursor = " + stockCursor?.color + "CursorTex = " + stockCursor?.sprite?.texture); if (newCursor != null) { newCursor.SetColor(Cursor, stockCursor); newCursor.SetTexture(CursorTex, stockCursor); } Renderer[] newVectors = controller?.gameObject?.GetChild("NavBallVectorsPivot")?.GetComponentsInChildren <Renderer>(true); Renderer[] stockVectors = original?.gameObject?.GetChild("NavBallVectorsPivot")?.GetComponentsInChildren <Renderer>(true); for (int i = 0; i < newVectors?.Length; i++) { string name = newVectors[i]?.name; Material material = newVectors[i]?.material; if (material == null) { continue; } Material stock = stockVectors?.Length > i ? stockVectors[i]?.material : null; if (name == "ProgradeVector") { Debug.Log("StockTexturesAndColors", "ProgradeVector = " + stock?.GetColor("_TintColor") + "ProgradeVectorTex = " + stock?.GetTexture("_MainTexture")); material.SetTintColor(ProgradeVector ?? Vectors, stock); material.SetMainTexture(ProgradeVectorTex ?? VectorsTex, stock); } else if (name == "ProgradeWaypoint") { Debug.Log("StockTexturesAndColors", "ProgradeWaypoint = " + stock?.GetColor("_TintColor") + "ProgradeWaypointTex = " + stock?.GetTexture("_MainTexture")); material.SetTintColor(ProgradeWaypoint ?? Vectors, stock); material.SetMainTexture(ProgradeWaypointTex ?? VectorsTex, stock); } else if (name == "RetrogradeVector") { Debug.Log("StockTexturesAndColors", "RetrogradeVector = " + stock?.GetColor("_TintColor") + "RetrogradeVectorTex = " + stock?.GetTexture("_MainTexture")); material.SetTintColor(RetrogradeVector ?? Vectors, stock); material.SetMainTexture(RetrogradeVectorTex ?? VectorsTex, stock); } else if (name == "RetrogradeWaypoint") { Debug.Log("StockTexturesAndColors", "RetrogradeWaypoint = " + stock?.GetColor("_TintColor") + "RetrogradeWaypointTex = " + stock?.GetTexture("_MainTexture")); material.SetTintColor(RetrogradeWaypoint ?? Vectors, stock); material.SetMainTexture(RetrogradeWaypointTex ?? VectorsTex, stock); } else if (name == "RadialInVector") { Debug.Log("StockTexturesAndColors", "RadialInVector = " + stock?.GetColor("_TintColor") + "RadialInVectorTex = " + stock?.GetTexture("_MainTexture")); material.SetTintColor(RadialInVector ?? Maneuvers, stock); material.SetMainTexture(RadialInVectorTex ?? ManeuversTex, stock); } else if (name == "RadialOutVector") { Debug.Log("StockTexturesAndColors", "RadialOutVector = " + stock?.GetColor("_TintColor") + "RadialOutVectorTex = " + stock?.GetTexture("_MainTexture")); material.SetTintColor(RadialOutVector ?? Maneuvers, stock); material.SetMainTexture(RadialOutVectorTex ?? ManeuversTex, stock); } else if (name == "NormalVector") { Debug.Log("StockTexturesAndColors", "NormalVector = " + stock?.GetColor("_TintColor") + "NormalVectorTex = " + stock?.GetTexture("_MainTexture")); material.SetTintColor(NormalVector ?? Maneuvers, stock); material.SetMainTexture(NormalVectorTex ?? ManeuversTex, stock); } else if (name == "AntiNormalVector") { Debug.Log("StockTexturesAndColors", "AntiNormalVector = " + stock?.GetColor("_TintColor") + "AntiNormalVectorTex = " + stock?.GetTexture("_MainTexture")); material.SetTintColor(AntiNormalVector ?? Maneuvers, stock); material.SetMainTexture(AntiNormalVectorTex ?? ManeuversTex, stock); } else if (name == "BurnVector") { Debug.Log("StockTexturesAndColors", "BurnVector = " + stock?.GetColor("_TintColor") + "BurnVectorTex = " + stock?.GetTexture("_MainTexture")); material.SetTintColor(BurnVector ?? Maneuvers, stock); material.SetMainTexture(BurnVectorTex ?? ManeuversTex, stock); } else if (name == "BurnVectorArrow") { material.SetTintColor(Arrows, stock); material.SetMainTexture(ArrowsTex, stock); } } UIStateImage[] newButtons = controller?.gameObject?.GetComponentsInChildren <UIStateImage>(); UIStateImage[] stockButtons = original?.gameObject?.GetComponentsInChildren <UIStateImage>(); for (int i = 0; i < newButtons?.Length; i++) { string name = newButtons[i]?.name; if (name == "RCS" || name == "SAS") { UIStateImage button = newButtons[i]; UIStateImage stock = stockButtons?.Length > i ? stockButtons[i] : null; button.SetColor(Buttons, stock); button.SetTexture(ButtonsTex, stock); } } Image newToggle = controller?.gameObject?.GetChild("ButtonTabToggle")?.GetComponent <Image>(); Image stockToggle = original?.gameObject?.GetChild("ButtonTabToggle")?.GetComponent <Image>(); Debug.Log("StockTexturesAndColors", "ButtonsTex = " + stockToggle?.sprite?.texture); if (newToggle != null) { newToggle.SetColor(Buttons, stockToggle); newToggle.SetTexture(ButtonsTex, stockToggle); newToggle.rectTransform.SetAsLastSibling(); } Image[] newGauges = controller?.gameObject?.GetChild("SideGauges")?.GetComponentsInChildren <Image>(true); Image[] stockGauges = original?.gameObject?.GetChild("SideGauges")?.GetComponentsInChildren <Image>(true); for (int i = 0; i < newGauges?.Length; i++) { string name = newGauges[i]?.name; if (name == "ThrottleGaugePointerImage" || name == "GeeGaugePointerImage") { Image stock = stockGauges?.Length > i ? stockGauges[i] : null; newGauges[i].SetColor(Buttons, stock); newGauges[i].SetTexture(ButtonsTex, stock); } } UIStateToggleButton[] newModes = controller?.gameObject?.GetChild("AutopilotModes")?.GetComponentsInChildren <UIStateToggleButton>(true); UIStateToggleButton[] stockModes = original?.gameObject?.GetChild("AutopilotModes")?.GetComponentsInChildren <UIStateToggleButton>(true); for (int i = 0; i < newModes?.Length; i++) { UIStateToggleButton mode = newModes[i]; UIStateToggleButton stock = stockModes?.Length > i ? stockModes[i] : null; mode.SetColor(Buttons, stock); mode.SetTexture(ButtonsTex, stock); } Image newFrame = controller?.gameObject?.GetChild("Frame")?.GetComponent <Image>(); Image stockFrame = original?.gameObject?.GetChild("Frame")?.GetComponent <Image>(); Debug.Log("StockTexturesAndColors", "Frame = " + stockFrame?.color + ", FrameTex = " + stockFrame?.sprite?.texture); if (newFrame != null) { newFrame.SetColor(Frame, stockFrame); newFrame.SetTexture(FrameTex, stockFrame, true, true, FrameTexRes); } Image headingframe = controller?.gameObject?.GetChild("HeadingFrame")?.GetComponent <Image>(); if (headingframe != null) { headingframe.color = new Color(0, 0, 0, 0); } }
/// <summary> /// Exchanges UIStateToggleButton Button States /// </summary> /// <param name="button"></param> /// <param name="buttonState"></param> public static void changeState(this UIStateToggleButton button, ButtonState buttonState) { button.stateTrue = buttonState; button.SetState(UIStateToggleButton.BtnState.True); }
/// <summary> /// Outputs both UIStateToggleButton Button States (stateTrue = buttonActive, stateFalse = buttonDisabled) /// </summary> /// <param name="button"></param> /// <param name="buttonActive"></param> /// <param name="buttonDisabled"></param> public static void getSpriteStates(this UIStateToggleButton button, out ButtonState buttonActive, out ButtonState buttonDisabled) { buttonActive = button.stateTrue; buttonDisabled = button.stateFalse; }