예제 #1
0
        public PUIFrame(GraphicsDevice graphics, PUIMenu parent, XElement el, Dictionary <string, DynamicSpriteFont> fonts, BASICEVENT_FUNC handleEvents, Dictionary <string, XElement> templates)
        {
            var screenWidth  = graphics.PresentationParameters.BackBufferWidth;
            var screenHeight = graphics.PresentationParameters.BackBufferHeight;

            _parent   = parent;
            Templates = templates;

            var drawOrderAttribute = el.Attribute("DrawOrder");

            if (drawOrderAttribute != null)
            {
                DrawOrder = int.Parse(drawOrderAttribute.Value);
            }

            bool preMultiplyAlpha = false;

            var elAlpha = el.Element("PreMultiplyAlpha");

            if (elAlpha != null)
            {
                preMultiplyAlpha = bool.Parse(elAlpha.Value);
            }

            var backgroundImage = el.Element("BackgroundImage");

            if (backgroundImage != null)
            {
                var backgroundImageTexture = ModManager.Instance.AssetManager.LoadTexture2D(graphics, backgroundImage.Value, preMultiplyAlpha);
                FrameSprite = new AnimatedSprite(backgroundImageTexture, backgroundImageTexture.Width, backgroundImageTexture.Height);
            }

            foreach (var scrollPanel in el.Elements("ScrollPanel"))
            {
            }

            var framePosition = el.Element("Position");
            var frameSize     = el.Element("Size");

            var frameSizeW = frameSize.Element("Width").Value;
            var frameSizeH = frameSize.Element("Height").Value;

            if (frameSizeW.ToUpper() == "FILL")
            {
                Width = screenWidth;
            }
            else if (frameSizeW.ToUpper() == "AUTO")
            {
                AutoWidth = true;
            }
            else if (frameSizeW.ToUpper() == "BG")
            {
                Width = FrameSprite.Width;
            }
            else
            {
                Width = int.Parse(frameSizeW);
            }

            if (frameSizeH.ToUpper() == "FILL")
            {
                Height = screenHeight;
            }
            else if (frameSizeH.ToUpper() == "AUTO")
            {
                AutoHeight = true;
            }
            else if (frameSizeH.ToUpper() == "BG")
            {
                Height = FrameSprite.Height;
            }
            else
            {
                Height = int.Parse(frameSizeH);
            }

            //X = (framePosition.Element("X").Value.ToUpper() != "CENTER"
            //    ? int.Parse(framePosition.Element("X").Value)
            //    : (int)((screenWidth / 2) - (Width / 2))
            //    );

            //Y = (framePosition.Element("Y").Value.ToUpper() != "CENTER"
            //    ? int.Parse(framePosition.Element("Y").Value)
            //    : (int)((screenHeight / 2) - (Height / 2))
            //    );

            var frameX = framePosition.Element("X").Value.ToUpper();
            var frameY = framePosition.Element("Y").Value.ToUpper();

            if (frameX == "CENTER")
            {
                CenterX = true;
            }
            else if (frameX == "LEFT")
            {
                AnchorLeft = true;
            }
            else if (frameX == "RIGHT")
            {
                AnchorRight = true;
            }
            else
            {
                X = int.Parse(framePosition.Element("X").Value);
            }

            if (frameY == "CENTER")
            {
                CenterY = true;
            }
            else if (frameY == "TOP")
            {
                AnchorTop = true;
            }
            else if (frameY == "BOTTOM")
            {
                AnchorBottom = true;
            }
            else
            {
                Y = int.Parse(framePosition.Element("Y").Value);
            }

            var visibleAttribute   = el.Attribute("Visible");
            var activeAttribute    = el.Attribute("Active");
            var draggableAttribute = el.Attribute("Draggable");

            if (visibleAttribute != null)
            {
                Visible = bool.Parse(visibleAttribute.Value);
            }
            if (activeAttribute != null)
            {
                Active = bool.Parse(activeAttribute.Value);
            }
            if (draggableAttribute != null)
            {
                Draggable = bool.Parse(draggableAttribute.Value);
            }

            Name = el.Attribute("Name").Value;

            if (PandaMonogameConfig.Logging)
            {
                Console.WriteLine("New frame: " + Name);
            }

            XElement widgetsRoot = el.Element("Widgets");

            var currentWidth  = 0;
            var currentHeight = 0;

            CommonWidgetResources.Fonts        = fonts;
            CommonWidgetResources.Graphics     = graphics;
            CommonWidgetResources.HandleEvents = handleEvents;
            CommonWidgetResources.Templates    = templates;

            var tempWidgets = new List <PUIWidget>();

            foreach (var kvp in PandaMonogameConfig.UIWidgetTypes)
            {
                var type        = kvp.Key;
                var xmlElements = widgetsRoot.Elements(kvp.Value).ToList();

                foreach (var xmlElement in xmlElements)
                {
                    PUIWidget widget = (PUIWidget)Activator.CreateInstance(type);
                    widget.Load(this, xmlElement);
                    tempWidgets.Add(widget);
                }
            }

            foreach (var widget in tempWidgets)
            {
                if (AutoWidth)
                {
                    if ((widget.X + widget.Width) > currentWidth)
                    {
                        currentWidth = widget.X + widget.Width;
                    }
                }

                if (AutoHeight)
                {
                    if ((widget.Y + widget.Height) > currentHeight)
                    {
                        currentHeight = widget.Y + widget.Height;
                    }
                }
            }

            if (AutoWidth)
            {
                Width = currentWidth;
            }
            if (AutoHeight)
            {
                Height = currentHeight;
            }

            if (CenterX)
            {
                X = (int)((screenWidth / 2) - (Width / 2));
            }

            if (CenterY)
            {
                Y = (int)((screenHeight / 2) - (Height / 2));
            }

            if (AnchorLeft)
            {
                X = 0;
            }
            if (AnchorRight)
            {
                X = screenWidth - Width;
            }
            if (AnchorTop)
            {
                Y = 0;
            }
            if (AnchorBottom)
            {
                Y = screenHeight - Height;
            }

            var elOffset = el.Element("Offset");

            if (elOffset != null)
            {
                X += int.Parse(elOffset.Element("X").Value);
                Y += int.Parse(elOffset.Element("Y").Value);
            }

            var draggableRectAttribute = el.Attribute("DraggableRect");

            if (draggableRectAttribute != null)
            {
                var rectParts = draggableRectAttribute.Value.Split(',');
                _draggableRect.X = int.Parse(rectParts[0]);
                _draggableRect.Y = int.Parse(rectParts[1]);

                var widthPart  = rectParts[2];
                var heightPart = rectParts[3];

                if (widthPart.ToUpper() == "FILL")
                {
                    _draggableRect.Width = Width;
                }
                else
                {
                    _draggableRect.Width = int.Parse(widthPart);
                }

                if (heightPart.ToUpper() == "FILL")
                {
                    _draggableRect.Height = Height;
                }
                else
                {
                    _draggableRect.Height = int.Parse(heightPart);
                }
            }

            foreach (var widget in tempWidgets)
            {
                widget.LoadStandardXML();
                AddWidget(widget, false);
            }

            Widgets.OrderByDrawOrder();
        }
예제 #2
0
        public PUIScript(PUIMenu parent)
        {
            this._parent = parent;

            _engine.Runtime.IO.RedirectToConsole();
        }