Exemplo n.º 1
0
        internal static void SetColor(this UIStateImage button, Color?color, UIStateImage stockButton)
        {
            Image image = button?.GetComponent <Image>();

            if (image != null)
            {
                Image stockImage = stockButton?.GetComponent <Image>();
                image.SetColor(color, stockImage);
            }
        }
Exemplo n.º 2
0
        internal static void SetTexture(this UIStateImage button, Texture newTex, UIStateImage stockButton = null)
        {
            for (int i = 0; i < button?.states?.Length; i++)
            {
                IState state = button?.states[i];

                if (state != null)
                {
                    Texture stockTexture = stockButton?.states?.Length > i ? stockButton.states[i]?.sprite?.texture : null;
                    state.sprite = state.sprite.SetTexture(newTex ?? stockTexture);
                }
            }
        }
Exemplo n.º 3
0
            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);
                }
            }
        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;
        }
Exemplo n.º 5
0
        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;
        }