public void ResizeTo(Vector2 newSize, PanelDirection horizontalDir = PanelDirection.Right, PanelDirection verticalDir = PanelDirection.Bottom)
 {
     if (Group != null)
     {
         Group.ResizeElementTo(this, newSize, horizontalDir, verticalDir);
     }
 }
        private PanelDirection ShowDirectionButtons(string label)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(label);

            PanelDirection result = PanelDirection.None;

            if (GUILayout.Button("Left"))
            {
                result = PanelDirection.Left;
            }

            if (GUILayout.Button("Top"))
            {
                result = PanelDirection.Top;
            }

            if (GUILayout.Button("Right"))
            {
                result = PanelDirection.Right;
            }

            if (GUILayout.Button("Bottom"))
            {
                result = PanelDirection.Bottom;
            }

            GUILayout.EndHorizontal();

            return(result);
        }
        public ItemPanel(
            IAbilityUnit unit,
            PanelDirection direction,
            Vector2 defaultObjectSize,
            Func <SkillPanelObject, uint> orderFunction = null)
            : base(unit,
                   direction,
                   defaultObjectSize,
                   skill =>
        {
            if (!skill.IsItem)
            {
                return(false);
            }

            // Console.WriteLine(skill.Name + " " + skill.SourceItem.IsHidden);
            return(skill.IsItem);
        },
                   orderFunction,
                   (o, vector2) =>
        {
            if (o.Skill.Cooldown == null && o.Skill.Charges == null)
            {
                return(vector2 * new Vector2(0.65f));
            }

            return(vector2);
        })
        {
        }
        /// <summary>
        /// Calculates the size of the box layout container.
        /// </summary>
        /// <param name="obj">The container to lay out.</param>
        /// <param name="args">The parameters to use for layout.</param>
        /// <param name="direction">The direction which is being calculated.</param>
        /// <returns>The minimum and preferred box layout size.</returns>
        private static BoxLayoutResults Calc(GameObject obj, BoxLayoutParams args,
                                             PanelDirection direction)
        {
            var transform  = obj.AddOrGet <RectTransform>();
            int n          = transform.childCount;
            var result     = new BoxLayoutResults(direction, n);
            var components = ListPool <Component, BoxLayoutGroup> .Allocate();

            for (int i = 0; i < n; i++)
            {
                var child = transform.GetChild(i)?.gameObject;
                if (child != null && child.activeInHierarchy)
                {
                    // Only on active game objects
                    components.Clear();
                    child.GetComponents(components);
                    var hc = PUIUtils.CalcSizes(child, direction, components);
                    if (!hc.ignore)
                    {
                        if (args.Direction == direction)
                        {
                            result.Accum(hc, args.Spacing);
                        }
                        else
                        {
                            result.Expand(hc);
                        }
                        result.children.Add(hc);
                    }
                }
            }
            components.Recycle();
            return(result);
        }
        /// <summary>
        /// Calculates the size of the card layout container.
        /// </summary>
        /// <param name="obj">The container to lay out.</param>
        /// <param name="args">The parameters to use for layout.</param>
        /// <param name="direction">The direction which is being calculated.</param>
        /// <returns>The minimum and preferred box layout size.</returns>
        private static CardLayoutResults Calc(GameObject obj, PanelDirection direction)
        {
            var transform  = obj.AddOrGet <RectTransform>();
            int n          = transform.childCount;
            var result     = new CardLayoutResults(direction, n);
            var components = ListPool <Component, BoxLayoutGroup> .Allocate();

            for (int i = 0; i < n; i++)
            {
                var child = transform.GetChild(i)?.gameObject;
                if (child != null)
                {
                    bool active = child.activeInHierarchy;
                    // Not only on active game objects
                    components.Clear();
                    child.GetComponents(components);
                    child.SetActive(true);
                    var hc = PUIUtils.CalcSizes(child, direction, components);
                    if (!hc.ignore)
                    {
                        result.Expand(hc);
                        result.children.Add(hc);
                    }
                    child.SetActive(active);
                }
            }
            components.Recycle();
            return(result);
        }
        protected void TryChangeSizeOf(IPanelGroupElement element, PanelDirection direction, float deltaSize)
        {
            if (element.IsNull() || deltaSize <= MIN_SIZE_TOLERANCE || element.GetSurroundingElement(direction).IsNull())
            {
                return;
            }

            resizePropsIndex = 0;

            IPanelGroupElement surroundingElement = element.GetSurroundingElement(direction);

            element = surroundingElement.GetSurroundingElement(direction.Opposite());
            AddResizeProperty(element);

            float deltaMovement = TryChangeSizeOfInternal(surroundingElement, direction, deltaSize);

            if (resizePropsIndex > 1)
            {
                ResizeElementHelper(0, direction, deltaMovement);

                for (int i = 0; i < resizePropsIndex; i++)
                {
                    ElementDirtyProperties properties = resizeProperties[i];

                    Vector2 position = properties.element.Position + new Vector2(properties.posX, properties.posY);
                    Vector2 size     = properties.element.Size + new Vector2(properties.sizeX, properties.sizeY);

                    UpdateBoundsOf(properties.element, position, size);
                }
            }
        }
Exemple #7
0
        public void Initialize(Panel panel, PanelDirection direction, PanelResizeHelper helperBefore, PanelResizeHelper helperAfter)
        {
            this.panel = panel;

            this.direction    = direction;
            this.helperBefore = helperBefore;
            this.helperAfter  = helperAfter;
        }
 /// <summary>
 /// Change the currently displayed panel (without adding to the panelStack).
 /// </summary>
 /// <param name="newPanel">The new panel to display.</param>
 /// <param name="dir">Direction to animate the new panel into the window from.</param>
 public void ChangePanel(PanelBase newPanel, PanelDirection dir = PanelDirection.Right)
 {
     transitioning  = true;
     oldPanel       = currentPanel;
     currentPanel   = newPanel;
     transitionDir  = dir;
     transitionPerc = 0;
 }
 internal BoxLayoutResults(PanelDirection direction, int presize)
 {
     children       = new List <LayoutSizes>(presize);
     this.direction = direction;
     haveMinSpace   = false;
     havePrefSpace  = false;
     total          = new LayoutSizes();
 }
Exemple #10
0
 public InvokerSkillPanel(
     IAbilityUnit unit,
     PanelDirection direction,
     Vector2 defaultObjectSize,
     Func <IAbilitySkill, bool> selectionCondition,
     Func <SkillPanelObject, uint> orderFunction = null)
     : base(unit, direction, defaultObjectSize, selectionCondition, orderFunction)
 {
 }
Exemple #11
0
        public static void OnBeginResize(PanelDirection primary, PanelDirection secondary)
        {
            if (instance == null)
            {
                return;
            }

            instance.isResizing = true;
            instance.UpdateCursor(primary, secondary);
        }
        public PanelGroup(PanelCanvas canvas, PanelDirection direction)
        {
            Canvas   = canvas;
            Internal = new InternalSettings(this);

            this.direction = direction;

            elements     = new List <IPanelGroupElement>(2);
            surroundings = new IPanelGroupElement[4];
        }
Exemple #13
0
 public void ResizeTo(Vector2 newSize, PanelDirection horizontalDir = PanelDirection.Right, PanelDirection verticalDir = PanelDirection.Bottom)
 {
     if (IsDocked)
     {
         Group.Internal.ResizeElementTo(this, newSize, horizontalDir, verticalDir);
     }
     else
     {
         FloatingSize = newSize;
     }
 }
Exemple #14
0
        /// <summary>
        /// Calculates the size of a single game object.
        /// </summary>
        /// <param name="obj">The object to calculate.</param>
        /// <param name="direction">The direction to calculate.</param>
        /// <param name="components">The components of this game object.</param>
        /// <returns>The object's minimum and preferred size.</returns>
        internal static LayoutSizes CalcSizes(GameObject obj, PanelDirection direction,
                                              IEnumerable <Component> components)
        {
            float min = 0.0f, preferred = 0.0f, flexible = 0.0f, scaleFactor;
            int   minPri = int.MinValue, prefPri = int.MinValue, flexPri = int.MinValue;
            var   scale = obj.transform.localScale;

            // Find the correct scale direction
            if (direction == PanelDirection.Horizontal)
            {
                scaleFactor = Math.Abs(scale.x);
            }
            else
            {
                scaleFactor = Math.Abs(scale.y);
            }
            bool ignore = false;

            foreach (var component in components)
            {
                if ((component as ILayoutIgnorer)?.ignoreLayout == true)
                {
                    ignore = true;
                    break;
                }
                if ((component as Behaviour)?.isActiveAndEnabled != false && component is
                    ILayoutElement le)
                {
                    int lp = le.layoutPriority;
                    // Calculate must come first
                    if (direction == PanelDirection.Horizontal)
                    {
                        le.CalculateLayoutInputHorizontal();
                        PriValue(ref min, le.minWidth, lp, ref minPri);
                        PriValue(ref preferred, le.preferredWidth, lp, ref prefPri);
                        PriValue(ref flexible, le.flexibleWidth, lp, ref flexPri);
                    }
                    else                         // if (direction == PanelDirection.Vertical)
                    {
                        le.CalculateLayoutInputVertical();
                        PriValue(ref min, le.minHeight, lp, ref minPri);
                        PriValue(ref preferred, le.preferredHeight, lp, ref prefPri);
                        PriValue(ref flexible, le.flexibleHeight, lp, ref flexPri);
                    }
                }
            }
            return(new LayoutSizes(obj, min * scaleFactor, Math.Max(min, preferred) *
                                   scaleFactor, flexible)
            {
                ignore = ignore
            });
        }
        private Panel CreateInitialPanel(PanelProperties properties, Panel anchor, PanelDirection anchorDirection, HashSet <Transform> createdTabs)
        {
            Panel panel = null;

            for (int i = 0; i < properties.tabs.Count; i++)
            {
                PanelTabProperties panelProps = properties.tabs[i];
                if (panelProps.content)
                {
                    if (createdTabs.Contains(panelProps.content))
                    {
                        continue;
                    }

                    if (panelProps.content.parent != RectTransform)
                    {
                        panelProps.content.SetParent(RectTransform, false);
                    }

                    PanelTab tab;
                    if (panel == null)
                    {
                        panel = PanelUtils.CreatePanelFor(panelProps.content, this, panelPrefab);
                        tab   = panel[0];
                    }
                    else
                    {
                        tab = panel.AddTab(panelProps.content);
                    }

                    tab.Icon    = panelProps.tabIcon;
                    tab.Label   = panelProps.tabLabel;
                    tab.MinSize = panelProps.minimumSize;
                    tab.ID      = panelProps.id;

                    createdTabs.Add(panelProps.content);
                }
            }

            if (panel != null)
            {
                panel.ActiveTab = 0;

                if (anchor != null && anchorDirection != PanelDirection.None)
                {
                    panel.DockToPanel(anchor, anchorDirection);
                }
            }

            return(panel);
        }
Exemple #16
0
        public bool CanResizeInDirection(PanelDirection direction)
        {
            if (direction == PanelDirection.None)
            {
                return(false);
            }

            if (!IsDocked)
            {
                return(true);
            }

            return(surroundings[(int)direction] != null);
        }
        public bool IsInSameDirection(PanelDirection direction)
        {
            if (direction == PanelDirection.None)
            {
                return(false);
            }

            if (direction == PanelDirection.Left || direction == PanelDirection.Right)
            {
                return(this.direction == PanelDirection.Left || this.direction == PanelDirection.Right);
            }

            return(this.direction == PanelDirection.Top || this.direction == PanelDirection.Bottom);
        }
Exemple #18
0
        /// <summary>
        /// Calculates the size of a single game object.
        /// </summary>
        /// <param name="obj">The object to calculate.</param>
        /// <param name="direction">The direction to calculate.</param>
        /// <param name="elements">The layout eligible components of this game object.</param>
        /// <returns>The object's minimum and preferred size.</returns>
        internal static LayoutSizes GetSize(GameObject obj, PanelDirection direction,
                                            IEnumerable <ILayoutElement> elements)
        {
            float min = 0.0f, preferred = 0.0f, flexible = 0.0f, scaleFactor;
            int   minPri = int.MinValue, prefPri = int.MinValue, flexPri = int.MinValue;
            var   scale = obj.transform.localScale;

            // Find the correct scale direction
            if (direction == PanelDirection.Horizontal)
            {
                scaleFactor = Math.Abs(scale.x);
            }
            else
            {
                scaleFactor = Math.Abs(scale.y);
            }
            foreach (var component in elements)
            {
                if (((component as Behaviour)?.isActiveAndEnabled ?? false) && !IgnoreLayout(
                        component))
                {
                    // Calculate must come first
                    if (direction == PanelDirection.Horizontal)
                    {
                        component.CalculateLayoutInputHorizontal();
                    }
                    else                     // if (direction == PanelDirection.Vertical)
                    {
                        component.CalculateLayoutInputVertical();
                    }
                    int lp = component.layoutPriority;
                    // Larger values win
                    if (direction == PanelDirection.Horizontal)
                    {
                        PriValue(ref min, component.minWidth, lp, ref minPri);
                        PriValue(ref preferred, component.preferredWidth, lp, ref prefPri);
                        PriValue(ref flexible, component.flexibleWidth, lp, ref flexPri);
                    }
                    else
                    {
                        PriValue(ref min, component.minHeight, lp, ref minPri);
                        PriValue(ref preferred, component.preferredHeight, lp, ref prefPri);
                        PriValue(ref flexible, component.flexibleHeight, lp, ref flexPri);
                    }
                }
            }
            return(new LayoutSizes(obj, min * scaleFactor, Math.Max(min, preferred) *
                                   scaleFactor, flexible));
        }
Exemple #19
0
 public PanelObjectManager(
     IObjectPanel <TObject> objectPanel,
     PanelDirection direction,
     Vector2 defaultObjectSize,
     Func <TObject, uint> orderFunction,
     Func <TObject, Vector2, Vector2> objectSizeFunction = null)
 {
     this.ObjectPanel        = objectPanel;
     this.Objects            = new List <TObject>();
     this.OrderFunction      = orderFunction;
     this.Direction          = direction;
     this.defaultObjectSize  = defaultObjectSize;
     this.ObjectSize         = defaultObjectSize;
     this.ObjectSizeFunction = objectSizeFunction ?? ((o, vector2) => this.ObjectSize);
 }
Exemple #20
0
        public override bool Execute(PanelTab panelTab, PointerEventData eventData)
        {
            PanelDirection anchorDirection = GetAnchorDirection(eventData);

            if (anchorDirection == PanelDirection.None)
            {
                return(false);
            }

            Panel detachedPanel = PanelManager.Instance.DetachPanelTab(panelTab.Panel, panelTab.Panel.GetTabIndex(panelTab));

            PanelManager.Instance.AnchorPanel(detachedPanel, panel, anchorDirection);

            return(true);
        }
Exemple #21
0
        /// <summary>
        /// Gets the offset required for a component in its box.
        /// </summary>
        /// <param name="alignment">The alignment to use.</param>
        /// <param name="direction">The direction of layout.</param>
        /// <param name="delta">The remaining space.</param>
        /// <returns>The offset from the edge.</returns>
        internal static float GetOffset(TextAnchor alignment, PanelDirection direction,
                                        float delta)
        {
            float offset = 0.0f;

            // Based on alignment, offset component
            if (direction == PanelDirection.Horizontal)
            {
                switch (alignment)
                {
                case TextAnchor.LowerCenter:
                case TextAnchor.MiddleCenter:
                case TextAnchor.UpperCenter:
                    offset = delta * 0.5f;
                    break;

                case TextAnchor.LowerRight:
                case TextAnchor.MiddleRight:
                case TextAnchor.UpperRight:
                    offset = delta;
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (alignment)
                {
                case TextAnchor.MiddleLeft:
                case TextAnchor.MiddleCenter:
                case TextAnchor.MiddleRight:
                    offset = delta * 0.5f;
                    break;

                case TextAnchor.LowerLeft:
                case TextAnchor.LowerCenter:
                case TextAnchor.LowerRight:
                    offset = delta;
                    break;

                default:
                    break;
                }
            }
            return(offset);
        }
Exemple #22
0
        public void AnchorPanel(IPanelGroupElement source, PanelCanvas canvas, PanelDirection anchorDirection)
        {
            PanelGroup rootGroup = canvas.RootPanelGroup;
            PanelGroup tempGroup = new PanelGroup(canvas, PanelDirection.Right);

            for (int i = 0; i < rootGroup.Count; i++)
            {
                if (rootGroup[i].Group == rootGroup)
                {
                    tempGroup.AddElement(rootGroup[i]);
                }
            }

            rootGroup.AddElement(tempGroup);
            AnchorPanel(source, tempGroup, anchorDirection);
        }
Exemple #23
0
        private PanelResizeHelper GetResizeZone(PanelDirection direction)
        {
            PanelResizeHelper resizeZone = resizeZones[(int)direction];

            if (resizeZone != null)
            {
                return(resizeZone);
            }

            resizeZone = new GameObject("ResizeZone" + direction, typeof(RectTransform)).AddComponent <PanelResizeHelper>();
            resizeZone.RectTransform.SetParent(resizeZonesParent, false);
            resizeZone.gameObject.AddComponent <NonDrawingGraphic>();

            resizeZones[(int)direction] = resizeZone;

            return(resizeZone);
        }
        private void CreateAnchorZone(PanelDirection direction, Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta)
        {
            CanvasAnchorZone anchorZone = new GameObject("AnchorZone" + direction, typeof(RectTransform)).AddComponent <CanvasAnchorZone>();

            anchorZone.Initialize(dummyPanel);
            anchorZone.SetDirection(direction);

            anchorZone.RectTransform.SetParent(anchorZonesParent, false);

            anchorZone.RectTransform.pivot            = anchorMin;
            anchorZone.RectTransform.anchorMin        = anchorMin;
            anchorZone.RectTransform.anchorMax        = anchorMax;
            anchorZone.RectTransform.anchoredPosition = Vector2.zero;
            anchorZone.RectTransform.sizeDelta        = sizeDelta;

            anchorZones[(int)direction] = anchorZone;
        }
Exemple #25
0
        public void OnBeginDrag(PointerEventData eventData)
        {
            // Cancel drag event if panel is already being resized by another pointer
            // or panel is anchored to a fixed anchor in that direction
            if (!panel.CanResizeInDirection(direction))
            {
                eventData.pointerDrag = null;
                return;
            }

            pointerId       = eventData.pointerId;
            secondDirection = GetSecondDirection(eventData.pressPosition);

#if ENABLE_CURSOR_MANAGEMENT
            PanelCursorHandler.OnBeginResize(direction, secondDirection);
#endif
        }
        /// <summary>
        /// Throws an error when resolution fails.
        /// </summary>
        /// <param name="children">The children, some of which failed to resolve.</param>
        /// <param name="limit">The number of passes executed before failing.</param>
        /// <param name="direction">The direction that failed.</param>
        internal static void ThrowUnresolvable(this IEnumerable <RelativeLayoutResults> children,
                                               int limit, PanelDirection direction)
        {
            var message = new StringBuilder(256);

            message.Append("After ").Append(limit);
            message.Append(" passes, unable to complete resolution of RelativeLayout:");
            foreach (var child in children)
            {
                string name = child.Transform.gameObject.name;
                if (direction == PanelDirection.Horizontal)
                {
                    if (!child.LeftEdge.Locked)
                    {
                        message.Append(' ');
                        message.Append(name);
                        message.Append(".Left");
                    }
                    if (!child.RightEdge.Locked)
                    {
                        message.Append(' ');
                        message.Append(name);
                        message.Append(".Right");
                    }
                }
                else
                {
                    if (!child.BottomEdge.Locked)
                    {
                        message.Append(' ');
                        message.Append(name);
                        message.Append(".Bottom");
                    }
                    if (!child.TopEdge.Locked)
                    {
                        message.Append(' ');
                        message.Append(name);
                        message.Append(".Top");
                    }
                }
            }
            throw new InvalidOperationException(message.ToString());
        }
 protected PanelField(
     IAbilityUnit unit,
     IUnitOverlayElement parent,
     Func <Vector2> basePosition,
     PanelDirection panelDirection,
     Func <IUnitOverlayElement, Vector2> positionFromHealthbar   = null,
     Func <IUnitOverlayElement, Vector2> positionFromLastElement = null)
 {
     this.Unit           = unit;
     this.BasePosition   = basePosition;
     this.PanelDirection = panelDirection;
     this.ParentElement  = parent;
     this.StoredElements = new List <IUnitOverlayElement>();
     this.Position       = this.BasePosition.Invoke();
     this.PositionFromElementHealthbarFunc = positionFromHealthbar;
     this.PositionFromLastElementFunc      = positionFromLastElement;
     this.Vertical = panelDirection == PanelDirection.Top || panelDirection == PanelDirection.Bottom;
     this.Size     = parent.Size;
 }
        internal BoxLayoutStatus(PanelDirection direction, RectOffset margins, float size)
        {
            this.direction = direction;
            switch (direction)
            {
            case PanelDirection.Horizontal:
                edge      = RectTransform.Edge.Left;
                offset    = margins.left;
                this.size = size - offset - margins.right;
                break;

            case PanelDirection.Vertical:
                edge      = RectTransform.Edge.Top;
                offset    = margins.top;
                this.size = size - offset - margins.bottom;
                break;

            default:
                throw new ArgumentException("direction");
            }
        }
 protected ObjectPanel(
     IAbilityUnit unit,
     PanelDirection direction,
     Vector2 defaultObjectSize,
     Func <TObject, uint> orderFunction = null,
     Func <TObject, Vector2, Vector2> objectSizeFunction = null,
     bool generateMenu      = false,
     string menuName        = null,
     string menuDisplayName = null)
     : base(unit)
 {
     this.ObjectManager = new PanelObjectManager <TObject>(
         this,
         direction,
         defaultObjectSize,
         orderFunction,
         objectSizeFunction);
     this.GenerateMenuBool = generateMenu;
     this.MenuName         = menuName;
     this.MenuDisplayName  = menuDisplayName;
 }
        public void ChangePosition(PanelDirection direction)
        {
            this.Panel?.RemoveElement(this);
            switch (direction)
            {
            case PanelDirection.Bottom:
                this.Unit.Overlay.BotPanel.AddElement(this);
                break;

            case PanelDirection.Left:
                this.Unit.Overlay.LeftPanel.AddElement(this);
                break;

            case PanelDirection.Right:
                this.Unit.Overlay.RightPanel.AddElement(this);
                break;

            case PanelDirection.Top:
                this.Unit.Overlay.TopPanel.AddElement(this);
                break;
            }
        }