Example #1
0
 public static Binding <T> ToBinding <T>(this IBindingValue <T> bv, BindingMode mode = BindingMode.TwoWay)
 {
     return(new Binding <T>(bv, mode));
 }
Example #2
0
 public static IBindingValue <T> Bind <T>(this Bindable <T> bindable, IBindingValue <T> source, BindingMode mode = BindingMode.TwoWay)
 {
     bindable.Binding = source.ToBinding(mode);
     return(source);
 }
Example #3
0
 public static IBindingValue <T> OnChange <T>(this IBindingValue <T> bv, Action <IBindingValue <T> > action)
 {
     bv.HasChanged += action;
     return(bv);
 }
Example #4
0
 public static Bindable <T> ToBindable <T>(this IBindingValue <T> bv)
 {
     return(new Bindable <T>(bv));
 }
Example #5
0
 public Bindable(IBindingValue <T> target)
 {
     _target             = target;
     _target.HasChanged += OnChanged;
 }
Example #6
0
        private void OnChanged(IBindingValue <T> bindingValue)
        {
            if (_isUpdating || Binding == null)
            {
                return;
            }
            var wasSourceDisposed = (bool?)null;

            _isUpdating = true;
            if (bindingValue == _target && (Binding.Mode & BindingMode.ToSource) == 0)
            {
                return;
            }
            if (bindingValue == Binding.Source && (Binding.Mode & BindingMode.FromSource) == 0)
            {
                return;
            }
            var gettingFrom = bindingValue == _target ? "target" : "source";
            var puttingIn   = bindingValue != _target ? "target" : "source";
            var valueTarget = bindingValue == _target ? Binding.Source : _target;
            T   value;

            try {
                value = bindingValue.Value;
            }
            catch (Exception ex) {
                //Unity's Mono does not support C#6's exception guards (even though they've been part of the CLI for a while...)
                if (ex is ObjectDisposedException || ex.InnerException is ObjectDisposedException)
                {
                    IEDebug.Log(
                        $"In binding ({BindingString}), when the {gettingFrom} changed, tried to get the value but the object was disposed.");
                    //IEDebug.PrintException(ex);
                    wasSourceDisposed = bindingValue != _target;
                    //!!!! WARNING WARNING WARNING !!!! CODER DISCRETION IS ADVISED:
                    goto skipUpdate;
                }
                else
                {
                    throw;
                }
            }
            try {
                valueTarget.Value = value;
            }
            catch (Exception ex) {
                if (ex is ObjectDisposedException || ex.InnerException is ObjectDisposedException)
                {
                    IEDebug.Log(
                        $"In binding ({BindingString}), when the {gettingFrom} changed, tried to update the {puttingIn}'s value, but the object was disposed.");
                    //IEDebug.PrintException(ex);
                    wasSourceDisposed = bindingValue != _target;
                }
                else
                {
                    throw;
                }
            }
skipUpdate:
            _isUpdating = false;

            switch (wasSourceDisposed)
            {
            case true:
                //means the binding is broken. Better clear it. However, the _target is fine as far as we know.
                IEDebug.Log(
                    $"In binding ({BindingString}), the source (thing bound to this) was disposed, so the binding will be scrapped.");
                SetBindingDirect(null);
                break;

            case false:
                //the _target has been disposed, so this Bindable is useless.
                IEDebug.Log(
                    $"In binding ({BindingString}), the target (the thing backing this) was disposed, so the binding will be scrapped.");
                Dispose();
                break;
            }
        }
Example #7
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 #8
0
		private static void TooltipOffsetChanged(IBindingValue<bool> source) {
			BigMapTooltip.Component<UIAnchor>().pixelOffset = source.Value ? new Vector2(150f, -25f) : new Vector2(25f, -25f);
		}
Example #9
0
 public Binding(IBindingValue <T> source, BindingMode mode = BindingMode.TwoWay)
 {
     Source = source;
     Mode   = mode;
 }
Example #10
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 #11
0
 private static void TooltipOffsetChanged(IBindingValue <bool> source)
 {
     BigMapTooltip.Component <UIAnchor>().pixelOffset = source.Value ? new Vector2(150f, -25f) : new Vector2(25f, -25f);
 }