示例#1
0
 public void Init(PUIFrame parent, XElement el)
 {
     Parent       = parent;
     HandleEvents = parent.CommonWidgetResources.HandleEvents;
     XmlRoot      = el;
     LoadTemplate();
 } // init
示例#2
0
        public override void Load(PUIFrame parent, XElement el)
        {
            Init(parent, el);

            bool preMultiplyAlpha = false;

            var elAlpha = GetXMLElement("PreMultiplyAlpha");

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

            _image = ModManager.Instance.AssetManager.LoadTexture2D(parent.CommonWidgetResources.Graphics, GetXMLElement("AssetName").Value, preMultiplyAlpha);

            Width  = _image.Width;
            Height = _image.Height;

            var elSourceRect = GetXMLElement("SourceRect");

            if (elSourceRect != null)
            {
                _sourceRect = new Rectangle()
                {
                    X      = GetXMLAttribute <int>("SourceRect", "X"),
                    Y      = GetXMLAttribute <int>("SourceRect", "Y"),
                    Width  = GetXMLAttribute <int>("SourceRect", "Width"),
                    Height = GetXMLAttribute <int>("SourceRect", "Height"),
                };

                Width  = _sourceRect.Width;
                Height = _sourceRect.Height;
            }
        }
        public override void Load(PUIFrame parent, XElement el)
        {
            Init(parent, el);

            Texture2D texture = ModManager.Instance.AssetManager.LoadTexture2D(parent.CommonWidgetResources.Graphics, GetXMLElement("AssetName").Value);

            Width  = texture.Width;
            Height = texture.Height;

            _image = new AnimatedSprite(texture, texture.Width, texture.Height);
        }
示例#4
0
 public virtual void Load(PUIFrame parent, XElement el)
 {
 }
示例#5
0
        public override void Load(PUIFrame parent, XElement el)
        {
            Init(parent, el);

            bool preMultiplyAlpha = false;

            var elAlpha = GetXMLElement("PreMultiplyAlpha");

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

            Texture2D buttonimage          = null;
            Texture2D buttonimage_pressed  = null;
            Texture2D buttonimage_hover    = null;
            Texture2D buttonimage_disabled = null;

            var elImage         = GetXMLElement("AssetName");
            var elImagePressed  = GetXMLElement("AssetNamePressed");
            var elImageHover    = GetXMLElement("AssetNameHover");
            var elImageDisabled = GetXMLElement("AssetNameDisabled");

            if (elImage != null && string.IsNullOrWhiteSpace(elImage.Value) == false)
            {
                buttonimage = ModManager.Instance.AssetManager.LoadTexture2D(parent.CommonWidgetResources.Graphics, elImage.Value, preMultiplyAlpha);
            }
            if (elImagePressed != null && string.IsNullOrWhiteSpace(elImagePressed.Value) == false)
            {
                buttonimage_pressed = ModManager.Instance.AssetManager.LoadTexture2D(parent.CommonWidgetResources.Graphics, elImagePressed.Value, preMultiplyAlpha);
            }
            if (elImageHover != null && string.IsNullOrWhiteSpace(elImageHover.Value) == false)
            {
                buttonimage_hover = ModManager.Instance.AssetManager.LoadTexture2D(parent.CommonWidgetResources.Graphics, elImageHover.Value, preMultiplyAlpha);
            }
            if (elImageDisabled != null && string.IsNullOrWhiteSpace(elImageDisabled.Value) == false)
            {
                buttonimage_disabled = ModManager.Instance.AssetManager.LoadTexture2D(parent.CommonWidgetResources.Graphics, elImageDisabled.Value, preMultiplyAlpha);
            }

            XElement buttonLabelPosition = GetXMLElement("Label", "Position");
            XElement buttonLabelColor    = GetXMLElement("Label", "Color");

            Font     = parent.CommonWidgetResources.Fonts[GetXMLElement("Label", "FontName").Value];
            FontSize = int.Parse(GetXMLElement("Label", "FontSize").Value);

            Font.Size = FontSize;
            var labelSize = Font.MeasureString(GetXMLElement("Label", "Text").Value);

            int textX = (buttonLabelPosition.Element("X").Value.ToUpper() != "CENTER"
                ? int.Parse(buttonLabelPosition.Element("X").Value)
                : (int)((buttonimage.Width / 2) - (labelSize.X / 2)));

            int textY = (buttonLabelPosition.Element("Y").Value.ToUpper() != "CENTER"
                ? int.Parse(buttonLabelPosition.Element("Y").Value)
                : (int)((buttonimage.Height / 2) - (labelSize.Y / 2)));

            var elOnClick = GetXMLElement("OnClick");

            _buttonSprite         = buttonimage == null ? null : new AnimatedSprite(buttonimage, buttonimage.Width, buttonimage.Height);
            _buttonPressedSprite  = buttonimage_pressed == null ? null : new AnimatedSprite(buttonimage_pressed, buttonimage_pressed.Width, buttonimage_pressed.Height);
            _buttonHoverSprite    = buttonimage_hover == null ? null : new AnimatedSprite(buttonimage_hover, buttonimage_hover.Width, buttonimage_hover.Height);
            _buttonDisabledSprite = buttonimage_disabled == null ? null : new AnimatedSprite(buttonimage_disabled, buttonimage_disabled.Width, buttonimage_disabled.Height);
            Width        = buttonimage.Width;
            Height       = buttonimage.Height;
            _onClick     = elOnClick == null ? null : elOnClick.Value;
            ButtonText   = GetXMLElement("Label", "Text").Value;
            TextPosition = new Vector2()
            {
                X = textX, Y = textY
            };
            ButtonTextColor = PUIColorConversion.Instance.ToColor(buttonLabelColor.Value);

            var clickSoundElement = GetXMLElement("ClickSound");

            if (clickSoundElement != null)
            {
                _clickSound = clickSoundElement.Value;
            }

            UpdateRect();
        }
示例#6
0
        public void Load(GraphicsDevice graphics, string assetName, string templatesName = "")
        {
            if (PandaMonogameConfig.Logging)
            {
                Console.WriteLine("Importing UI instance: " + assetName);
            }

            using (var fs = ModManager.Instance.AssetManager.GetFileStreamByAsset(assetName))
            {
                XDocument doc      = XDocument.Load(fs);
                XElement  menuRoot = doc.Element("Menu");

                XElement templatesRoot = null;

                if (!string.IsNullOrWhiteSpace(templatesName))
                {
                    using (var fsTemplates = ModManager.Instance.AssetManager.GetFileStreamByAsset(templatesName))
                    {
                        templatesRoot = XDocument.Load(fsTemplates).Element("Templates");

                        foreach (var template in templatesRoot.Elements("Template"))
                        {
                            var name = template.Attribute("TemplateName").Value;
                            Templates.Add(name, template);
                        }
                    }
                }

                List <XElement> fontElements = menuRoot.Elements("Font").ToList();

                foreach (var fontElement in fontElements)
                {
                    _fonts.Add(fontElement.Attribute("AssetName").Value, ModManager.Instance.AssetManager.LoadDynamicSpriteFont(fontElement.Attribute("AssetName").Value));
                    if (PandaMonogameConfig.Logging)
                    {
                        Console.WriteLine("New font: " + fontElement.Attribute("AssetName").Value);
                    }
                }

                List <XElement> scenes = menuRoot.Elements("Scene").ToList();

                foreach (var scene in scenes)
                {
                    PUIScene newScene = new PUIScene(scene);

                    List <XElement> frames = scene.Elements("Frame").ToList();

                    foreach (var frame in frames)
                    {
                        PUIFrame newFrame = new PUIFrame(graphics, this, frame, _fonts, HandleEvents, Templates);

                        newScene.SceneFrames.Add(newFrame);
                    } // foreach

                    newScene.SceneFrames.OrderByDrawOrder();
                    Scenes.Add(scene.Attribute("Name").Value, newScene);
                } // foreach

                List <XElement> scripts = menuRoot.Elements("Script").ToList();

                foreach (var script in scripts)
                {
                    PUIScript newScript = new PUIScript(this)
                    {
                        Name     = script.Element("Name").Value,
                        Filepath = ModManager.Instance.AssetManager.GetAssetPath(script.Element("AssetName").Value),
                    };

                    if (PandaMonogameConfig.Logging)
                    {
                        Console.WriteLine("New script: " + newScript.Name + " - " + newScript.Filepath);
                    }

                    List <XElement> scriptClasses = script.Elements("Class").ToList();

                    foreach (var scriptClass in scriptClasses)
                    {
                        newScript.Classes.Add(scriptClass.Attribute("Name").Value);
                    } // foreach

                    newScript.CreateScope();
                    newScript.Scope.SetVariable("MouseState", Mouse.GetState());
                    newScript.Scope.SetVariable("MenuState", this);

                    foreach (var scene in Scenes)
                    {
                        var widgetScriptList = scene.Value.SceneFrames.GetWidgetScriptList();

                        foreach (var s in widgetScriptList)
                        {
                            newScript.Scope.SetVariable(scene.Key + "_" + s.Key, s.Value);
                        }

                        foreach (var f in scene.Value.SceneFrames.GetFrameScriptList())
                        {
                            newScript.Scope.SetVariable(scene.Key + "_" + f.Key, f.Value);
                        }
                    }

                    newScript.Compile();

                    Scripts.Add(newScript.Name, newScript);
                } // foreach

                if (PandaMonogameConfig.Logging)
                {
                    Console.WriteLine("Finished importing UI instance: " + assetName);
                }
            }
        } // load