Example #1
0
        private static void UseNoFrame()
        {
            BigMapTooltip.Component <UIAnchor>().pixelOffset = new Vector2(25f, -25f);

            HudTrim.Child("Right").gameObject.SetActive(true);

            var hudTrimLeft = HudTrim.Child("Left");

            if (DefaultLeftCornerTexture != null)
            {
                hudTrimLeft.Component <UITexture>().mainTexture = DefaultLeftCornerTexture;
            }

            hudTrimLeft.Children().ToList().ForEach(x => x.SetActive(false));

            if (hudTrimLeft.GetComponent <UIResolutionScaler>() != null)
            {
                Object.Destroy(hudTrimLeft.Component <UIResolutionScaler>());
            }

            hudTrimLeft.transform.localScale = new Vector3(248f, 160f, 1);
        }
Example #2
0
        private static void OnFrameChanged(IBindingValue <string> uframePaths)
        {
            var uframePath = uframePaths.Value;

            if (string.IsNullOrEmpty(uframePath))
            {
                UseNoFrame();
                return;
            }
            if (!TooltipOffset.Value)
            {
                BigMapTooltip.Component <UIAnchor>().pixelOffset = new Vector2(150f, -25f);
                // enemy tooltip in the left upper corner
            }

            var textpath = Path.ChangeExtension(uframePath, ".txt");

            var leftBarWidthPixels    = 0f;
            var bottomBarHeightPixels = 0f;
            var rightBarPixels        = 0f;

            var leftBarWidth    = 0f;
            var bottomBarHeight = 0f;
            var rightBarWidth   = 0f;

            if (File.Exists(textpath))
            {
                var threeLines = File.ReadAllLines(textpath);
                leftBarWidthPixels    = int.Parse(threeLines[0]);
                bottomBarHeightPixels = int.Parse(threeLines[1]);
                rightBarPixels        = int.Parse(threeLines[2]);

                leftBarWidth    = (leftBarWidthPixels * 2) / Screen.width;
                bottomBarHeight = (bottomBarHeightPixels * 2) / Screen.height;
                rightBarWidth   = (rightBarPixels * 2) / Screen.width;
            }
            else
            {
                Console.AddMessage("Couldn't read file at path: " + textpath, Color.red);
            }

            if (File.Exists(uframePath))
            {
                var SolidUFrame = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
                var bytes       = File.ReadAllBytes(uframePath);
                SolidUFrame.LoadImage(bytes);
                SolidUFrame.name = uframePath;
                //Console.AddMessage ("Texture loaded: "+uframeName);


                // Displaying U-frame
                HudTrim.Child("Right").gameObject.SetActive(false);

                // we load it only once
                var hudTrimLeft = HudTrim.Child("Left");
                if (DefaultLeftCornerTexture == null)
                {
                    DefaultLeftCornerTexture = hudTrimLeft.Component <UITexture>().mainTexture;
                }

                hudTrimLeft.Component <UITexture>().mainTexture = SolidUFrame;
                float width  = Screen.width;
                float height = Screen.height;
                hudTrimLeft.transform.localScale = new Vector3(width, height, 1f);

                var scaler = HudTrim.gameObject.GetComponent <UIResolutionScaler>()
                             ?? HudTrim.gameObject.AddComponent <UIResolutionScaler>();
                scaler.DesignedWidth   = (int)width;
                scaler.DesignedHeight  = (int)height;
                scaler.UseMaximumScale = true;
                scaler.Apply();
                hudTrimLeft.Component <UITexture>().MakePixelPerfect();
                // end of U-frame

                // destroying the 3 colliders?

                hudTrimLeft.Children().ToList().ForEach(Object.Destroy);

                // if we hadn't previously created 3 colliders, we create them, otherwise we just activate them

                // no-click collider for the left bar
                var leftBarTexture = NGUITools.AddWidget <UITexture>(hudTrimLeft.gameObject);
                var leftbar        = leftBarTexture.gameObject;
                leftbar.transform.localScale = new Vector3(leftBarWidth, 2f, 1f);
                // i seriously have no idea why those values have to be used, i just guessed them after a few hours of trying... you'd think that you need to use (126, 1080, 1), but apperently not... WHY???
                leftBarTexture.mainTexture = new Texture2D((int)leftBarWidthPixels, Screen.height);
                var box = NGUITools.AddWidgetCollider(leftbar.gameObject);
                // adding a box collider, it's required for the UINoClick component
                box.gameObject.AddComponent <UINoClick>();                // this prevents clicks from going through the U-frame
                var ank = leftbar.gameObject.AddComponent <UIAnchor>();
                ank.side             = UIAnchor.Side.BottomLeft;
                leftBarTexture.depth = 1;
                // end of left bar collider

                // no click collider for the right bar
                var rightBarTexture = NGUITools.AddWidget <UITexture>(hudTrimLeft.gameObject);
                var righttbar       = rightBarTexture.gameObject;
                righttbar.transform.localScale = new Vector3(rightBarWidth, 2f, 1f);
                // i seriously have no idea why those values have to be used, i just guessed them after a few hours of trying... you'd think that you need to use (126, 1080, 1), but apperently not... WHY???
                rightBarTexture.mainTexture = new Texture2D((int)rightBarPixels, Screen.height);
                var boxRight = NGUITools.AddWidgetCollider(righttbar.gameObject);
                // adding a box collider, it's required for the UINoClick component
                boxRight.gameObject.AddComponent <UINoClick>();                // this prevents clicks from going through the U-frame
                var ankRight = righttbar.gameObject.AddComponent <UIAnchor>();
                ankRight.side         = UIAnchor.Side.BottomRight;
                rightBarTexture.depth = 1;
                // end of right bar collider

                // no click collider for the bottom
                var bottomBarTexture = NGUITools.AddWidget <UITexture>(hudTrimLeft.gameObject);
                var bottombar        = bottomBarTexture.gameObject;
                bottombar.transform.localScale = new Vector3(1f, bottomBarHeight, 1f);
                // i seriously have no idea why those values have to be used, i just guessed them after a few hours of trying... you'd think that you need to use (126, 1080, 1), but apperently not... WHY???
                bottomBarTexture.mainTexture = new Texture2D(Screen.width, (int)bottomBarHeightPixels);
                var boxBottom = NGUITools.AddWidgetCollider(bottombar.gameObject);
                // adding a box collider, it's required for the UINoClick component
                boxBottom.gameObject.AddComponent <UINoClick>();                // this prevents clicks from going through the U-frame
                var ankBottom = bottombar.gameObject.AddComponent <UIAnchor>();
                ankBottom.side         = UIAnchor.Side.Bottom;
                bottomBarTexture.depth = 1;
                // end of bottom bar collider
            }
            else
            {
                Console.AddMessage("Couldn't read file at path: " + uframePath, Color.red);
            }
        }
Example #3
0
 private static void TooltipOffsetChanged(IBindingValue <bool> source)
 {
     BigMapTooltip.Component <UIAnchor>().pixelOffset = source.Value ? new Vector2(150f, -25f) : new Vector2(25f, -25f);
 }