Beispiel #1
0
        public static UIScrollPanel Create(UIScrollablePanel oldPanel)
        {
            UIScrollPanel scrollPanel = oldPanel.parent.AddUIComponent <UIScrollPanel>();

            scrollPanel.name             = oldPanel.name;
            scrollPanel.autoLayout       = false;
            scrollPanel.autoReset        = false;
            scrollPanel.autoSize         = false;
            scrollPanel.template         = "PlaceableItemTemplate";
            scrollPanel.itemWidth        = 109f;
            scrollPanel.itemHeight       = 100f;
            scrollPanel.canSelect        = true;
            scrollPanel.size             = new Vector2(763, 100);
            scrollPanel.relativePosition = new Vector3(48, 5);
            scrollPanel.atlas            = oldPanel.atlas;

            scrollPanel.parent.parent.eventSizeChanged += (c, p) =>
            {
                if (scrollPanel.isVisible)
                {
                    scrollPanel.size             = new Vector2((int)((p.x - 40f) / scrollPanel.itemWidth) * scrollPanel.itemWidth, (int)(p.y / scrollPanel.itemHeight) * scrollPanel.itemHeight);
                    scrollPanel.relativePosition = new Vector3(scrollPanel.relativePosition.x, Mathf.Floor((p.y - scrollPanel.height) / 2));

                    if (scrollPanel.rightArrow != null)
                    {
                        scrollPanel.rightArrow.relativePosition = new Vector3(scrollPanel.relativePosition.x + scrollPanel.width, 0);
                    }
                }
            };

            int zOrder = oldPanel.zOrder;

            DestroyImmediate(oldPanel.gameObject);
            DestroyScrollbars(scrollPanel.parent);

            scrollPanel.zOrder = zOrder;

            // Left / Right buttons
            UIButton button = scrollPanel.parent.AddUIComponent <UIButton>();

            button.atlas = SamsamTS.UIUtils.GetAtlas("Ingame");
            button.name  = "ArrowLeft";
            button.size  = new Vector2(32, 109);
            button.foregroundSpriteMode = UIForegroundSpriteMode.Scale;
            button.horizontalAlignment  = UIHorizontalAlignment.Center;
            button.verticalAlignment    = UIVerticalAlignment.Middle;
            button.normalFgSprite       = "ArrowLeft";
            button.focusedFgSprite      = "ArrowLeftFocused";
            button.hoveredFgSprite      = "ArrowLeftHovered";
            button.pressedFgSprite      = "ArrowLeftPressed";
            button.disabledFgSprite     = "ArrowLeftDisabled";
            button.isEnabled            = false;
            button.relativePosition     = new Vector3(16, 0);
            scrollPanel.leftArrow       = button;

            button       = scrollPanel.parent.AddUIComponent <UIButton>();
            button.atlas = SamsamTS.UIUtils.GetAtlas("Ingame");
            button.name  = "ArrowRight";
            button.size  = new Vector2(32, 109);
            button.foregroundSpriteMode = UIForegroundSpriteMode.Scale;
            button.horizontalAlignment  = UIHorizontalAlignment.Center;
            button.verticalAlignment    = UIVerticalAlignment.Middle;
            button.normalFgSprite       = "ArrowRight";
            button.focusedFgSprite      = "ArrowRightFocused";
            button.hoveredFgSprite      = "ArrowRightHovered";
            button.pressedFgSprite      = "ArrowRightPressed";
            button.disabledFgSprite     = "ArrowRightDisabled";
            button.isEnabled            = false;
            button.relativePosition     = new Vector3(811, 0);
            scrollPanel.rightArrow      = button;

            return(scrollPanel);
        }