Пример #1
0
 public WindowBuilder Icon(SpriteFrame icon)
 {
     this.icon = icon;
     return(this);
 }
Пример #2
0
        public UIWindow(Scene parentScene, Point contentSize, bool canBeClosed, bool canBeMaximized,
                        bool canbeMinimized, SpriteFrame icon, UIStyle style)
        {
            this.style = style;
            var headerSize = 32;
            var windowRoot = parentScene.AddActor("Window");

            new BoundingRect(windowRoot,
                             contentSize + new Point(0, headerSize) + new Point(this.margin * 2, this.margin * 2));

            var rootGroup = new LayoutGroup(windowRoot, Orientation.Vertical);

            rootGroup.SetMarginSize(new Point(this.margin, this.margin));
            rootGroup.AddHorizontallyStretchedElement("HeaderContent", 32, headerContentActor =>
            {
                new Hoverable(headerContentActor);
                new Draggable(headerContentActor).DragStart +=
                    (position, delta) => OnAnyPartOfWindowClicked(MouseButton.Left);
                new MoveOnDrag(headerContentActor, windowRoot.transform);

                var headerGroup = new LayoutGroup(headerContentActor, Orientation.Horizontal);
                if (icon != null)
                {
                    headerGroup.AddVerticallyStretchedElement("Icon", 32, iconActor =>
                    {
                        new SpriteRenderer(iconActor, icon.spriteSheet).SetAnimation(icon.animation);

                        iconActor.GetComponent <BoundingRect>().SetOffsetToCenter();
                    });
                    headerGroup.PixelSpacer(5); // Spacing between icon and title
                }

                headerGroup.AddBothStretchedElement("Title",
                                                    titleActor =>
                {
                    this.titleTextRenderer = new BoundedTextRenderer(titleActor, "Window title goes here",
                                                                     style.uiElementFont, Color.White, Alignment.CenterLeft,
                                                                     depthOffset: -2).EnableDropShadow(Color.Black);
                });

                if (canbeMinimized)
                {
                    CreateControlButton(headerGroup, windowRoot, win => Minimized?.Invoke(win),
                                        this.style.minimizeButtonFrames);
                }

                if (canBeMaximized)
                {
                    CreateControlButton(headerGroup, windowRoot, win => Maximized?.Invoke(win),
                                        this.style.maximizeButtonFrames);
                }

                if (canBeClosed)
                {
                    CreateControlButton(headerGroup, windowRoot, win => Closed?.Invoke(win),
                                        this.style.closeButtonFrames);
                }
            });

            // These variables with _local at the end of their name are later assigned to readonly values
            // The locals are assigned in lambdas which is illegal for readonly assignment
            SceneRenderer sceneRenderer_local = null;
            Actor         canvasActor_local   = null;
            LayoutGroup   contentGroup_local  = null;

            // "Content" means everything below the header

            rootGroup.AddBothStretchedElement("ContentGroup", contentActor =>
            {
                new NinepatchRenderer(contentActor, style.windowSheet, NinepatchSheet.GenerationDirection.Outer);

                contentGroup_local = new LayoutGroup(contentActor, Orientation.Horizontal)
                                     .AddBothStretchedElement("Canvas", viewActor =>
                {
                    canvasActor_local = viewActor;
                    new BoundedCanvas(viewActor);
                    new Hoverable(viewActor);
                    new Clickable(viewActor).ClickStarted += OnAnyPartOfWindowClicked;
                    sceneRenderer_local = new SceneRenderer(viewActor);
                })
                ;
            })
            ;

            this.sceneRenderer    = sceneRenderer_local;
            this.canvasActor      = canvasActor_local;
            this.rootTransform    = windowRoot.transform;
            this.rootBoundingRect = windowRoot.GetComponent <BoundingRect>();
            this.contentGroup     = contentGroup_local;
        }