Beispiel #1
0
        public override void Start()
        {
            if (!LinkedObject.HasComponent <Button2DComponent>())
            {
                Debug.LogWarning("The 2DObject \"" + LinkedObject.ObjectName + "\" has a Dropdown 2D Component but no button to interact with it. A button 2D Component has automatically been added.", true);
                LinkedObject.AddComponent(new Button2DComponent());
            }

            DropDownParent = new Object2D("Dropdown_" + LinkedObject.ObjectName, LinkedObject.Position + new Vector2(0, LinkedObject.Size.Y / 2), Size, LinkedObject.Rotation, new Component2D[] { new Image2DComponent(DefaultValues.PixelTexture, DropDownColor), new Spacer2DComponent(SpacerOption.VerticalSpacer, ItemSpacing, Alignment.TopLeft, ItemSpacing) }, Alignment.TopLeft, LinkedObject.Layer, LinkedObject);

            if (MustClick)
            {
                LinkedObject.GetComponent <Button2DComponent>().OnClick        += () => OpenDropdown();
                LinkedObject.GetComponent <Button2DComponent>().OnClickOutside += () => CloseDropdown();
            }
            else
            {
                LinkedObject.GetComponent <Button2DComponent>().OnEnter += () => OpenDropdown();
                LinkedObject.GetComponent <Button2DComponent>().OnExit  += () => CloseDropdown();
            }

            foreach (Object2D obj in DropdownItems.ToArray())
            {
                DropDownParent.AddChild(obj);
            }

            CloseDropdown();
        }
Beispiel #2
0
        public override void Start()
        {
            // Creates a whole new object JUST for the input to prevent confusion when looking for components in the main object this component is attatched to
            InputSeperateObject = new Object2D("Input_" + LinkedObject.ObjectName, LinkedObject.Position, LinkedObject.Size, LinkedObject.Rotation, new Component2D[] { InputTextComponent, GhostTextComponent, InputButton }, LinkedObject.Align, LinkedObject.Layer, LinkedObject);

            // Sets the input text to nothing once it's been instantiated, so it can be aligned correctly
            InputText = "";
            GhostText = GhostText.Substring(0, GhostText.Length - 1);
        }
Beispiel #3
0
 /// <summary>
 /// Adds a child, but does not change its Layer
 /// </summary>
 /// <param name="object2d">The parent 2D Object</param>
 public void AddChild(Object2D object2d)
 {
     Children.Add(object2d);
     object2d.Parent = this;
     object2d.CalcTransform();
     if (ChildAdded != null)
     {
         ChildAdded(object2d);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Adds a child and changes its layer to the parent's
 /// </summary>
 /// <param name="object2d">The parent 2D Object</param>
 /// <param name="SubLayer">The sub-layer of the child to the parent</param>
 public void AddChild(Object2D object2d, int SubLayer)
 {
     Children.Add(object2d);
     object2d.Parent = this;
     object2d.Layer  = Layer + (SubLayer / 1000);
     object2d.CalcTransform();
     if (ChildAdded != null)
     {
         ChildAdded(object2d);
     }
 }
Beispiel #5
0
        void SortChildren(Object2D object2d)
        {
            int     i           = 0;
            Vector2 ChildOffset = Vector2.Zero;

            ChildOffset -= Offset * 2;
            if (SpacerOption == SpacerOption.VerticalSpacer)
            {
                // Sets child offset for centering
                foreach (Object2D Child in LinkedObject.Children)
                {
                    Child.SetPivot(ChildAlign);
                    ChildOffset += new Vector2(0, (Child.Size.Y + Spacing.Y) * Child.Pivot.Y);
                    i++;
                }
                ChildOffset /= 2;

                i = 0;
                foreach (Object2D child in LinkedObject.Children)
                {
                    child.RelativePosition  = Vector2.Zero;
                    child.RelativePosition += (LinkedObject.Size * Pivot) - (LinkedObject.Size * LinkedObject.Pivot) - ChildOffset; // Initial Spacing
                    ChildOffset            -= new Vector2(0, Spacing.Y + child.Size.Y);
                    i++;
                }
            }
            else if (SpacerOption == SpacerOption.HorizontalSpacer)
            {
                // Sets child offset for centering
                foreach (Object2D Child in LinkedObject.Children)
                {
                    Child.SetPivot(ChildAlign);
                    ChildOffset += new Vector2((Child.Size.X + Spacing.X) * Child.Pivot.X, 0);
                    i++;
                }
                ChildOffset /= 2;

                i = 0;
                foreach (Object2D child in LinkedObject.Children)
                {
                    child.RelativePosition  = Vector2.Zero;
                    child.RelativePosition += (LinkedObject.Size * Pivot) - (LinkedObject.Size * LinkedObject.Pivot) - ChildOffset; // Initial Spacing
                    ChildOffset            -= new Vector2(Spacing.X + child.Size.X, 0);
                    i++;
                }
            }
        }
Beispiel #6
0
        void OnClickOutside()
        {
            IsFocused = false;

            if (InputText == "")
            {
                GhostTextComponent.Color = GhostTextColor;
            }

            Time.CancelWait(CaretBlinkTimer);

            if (CaretObject != null)
            {
                CaretObject.Dispose(true);
                CaretObject = null;
            }
        }
Beispiel #7
0
        void OnClick()
        {
            GhostTextComponent.Color = Color.Transparent;

            Time.CancelWait(CaretBlinkTimer);

            float CaretSize = InputTextComponent.FontSize * 100;

            if (CaretObject == null)
            {
                CaretObject = new Object2D("CaretObj_" + LinkedObject.ObjectName, LinkedObject.Position - new Vector2((LinkedObject.Pivot.X * LinkedObject.Size.X), (CaretSize / 2) - (LinkedObject.Size.Y * InputTextComponent.Pivot.Y)), new Vector2(2, CaretSize), 0, new Component2D[] { Caret }, InputTextComponent.Align, LinkedObject.Layer, InputSeperateObject);
            }

            Caret.Color.A = 0;
            UpdateCaret();

            CaretBlink();

            IsFocused = true;
        }
Beispiel #8
0
        public override void Start()
        {
            Sl = new Object2D("Slider_" + LinkedObject.ObjectName, Vector2.Zero, LinkedObject.Size, LinkedObject.Rotation, new Component2D[] { Bar, Fill, Handle, HandleButton }, LinkedObject.Align, LinkedObject.Layer, LinkedObject);

            UpdateSlider();
        }
Beispiel #9
0
        /// <summary>
        /// Creates a new 2D Object
        /// </summary>
        /// <param name="objectName">The name of the object. If the name of the object already exists, the name will be appended with a number</param>
        /// <param name="position">The position of the object in relative space</param>
        /// <param name="size">The size of the object in relative space</param>
        /// <param name="rotation">The rotation of the object in relative space</param>
        /// <param name="components">An array of components that are bound to the object</param>
        /// <param name="alignment">The pivot point of the object</param>
        /// <param name="layer">The sorting layer of the object</param>
        /// <param name="parent">The object's parent</param>
        /// <param name="subLayer">If the object has a parent, this will be its sub-layer</param>
        /// <param name="children">This object's children</param>
        public Object2D(string objectName, Vector2 position, Vector2 size, float rotation = 0, Component2D[] components = null, Alignment alignment = Alignment.TopLeft, float layer = 0, Object2D parent = null, int subLayer = 1, Object2D[] children = null)
        {
            Parent = parent;
            if (Parent != null)
            {
                Parent.AddChild(this, subLayer);
            }

            RelativePosition = position;
            RelativeRotation = rotation;
            RelativeSize     = size;

            Layer = layer;

            ObjectName = objectName;

            // Goes through all the possible errors
            if (ObjectName == "")
            {
                Debug.LogError("Object name can't be blank!", true, 3);
            }
            else if (Level.Objects2D.ContainsKey(ObjectName))
            {
                Debug.LogWarning("The 2DObject \"" + ObjectName + "\" already exists! Appending name.", true);

                List <string> Num            = Level.Objects2D.Keys.ToList().FindAll((x) => x.Contains(ObjectName + "_"));
                int           CurrentBiggest = 1;
                foreach (string item in Num.ToList())
                {
                    int.TryParse(item.Substring(ObjectName.Length + 1), out int num);
                    CurrentBiggest = Math.Max(num, CurrentBiggest) + 1;
                }

                ObjectName += "_" + CurrentBiggest;

                Level.Objects2D.Add(ObjectName, this);
            }
            else
            {
                Level.Objects2D.Add(ObjectName, this);
            }

            // Adds and Starts the scripts
            if (components != null)
            {
                foreach (Component2D com in components)
                {
                    AddComponent(com);
                }
            }

            if (children != null)
            {
                foreach (Object2D Child in children)
                {
                    AddChild(Child);
                    Child.Position += position;
                    Child.Size     *= Size;
                    Child.Rotation += rotation;
                }
            }

            SetPivot(alignment);
            CalcTransform();
        }
Beispiel #10
0
 public void RemoveChild(Object2D object2d)
 {
     object2d.Parent = null;
     Children.Remove(object2d);
 }
Beispiel #11
0
 public override void Start()
 {
     Button = new Button2DComponent(OnClick, OnClickOutside, new Action(OnCheckClick), OnPress, OnHover, OnEnter, OnExit);
     Image  = new Image2DComponent(IsDown ? DownTexture : UpTexture, IsDown ? DownColor : UpColor);
     ChkObj = new Object2D("Check_" + LinkedObject.ObjectName, LinkedObject.Position, LinkedObject.Size, LinkedObject.Rotation, new Component2D[] { Image, Button }, LinkedObject.Align, LinkedObject.Layer, LinkedObject);
 }