/// <summary>
        /// Get background by name
        /// </summary>
        /// <param name="graphicsDevice">The graphics device that the backgroundInfo is to be rendered on (loading spine)</param>
        /// <param name="bS"></param>
        /// <param name="type">Select type</param>
        /// <param name="no"></param>
        /// <returns></returns>
        public static BackgroundInfo Get(GraphicsDevice graphicsDevice, string bS, BackgroundInfoType type, string no)
        {
            if (!Program.InfoManager.BackgroundSets.ContainsKey(bS))
            {
                return(null);
            }

            WzImage         bsImg      = Program.InfoManager.BackgroundSets[bS];
            WzImageProperty bgInfoProp = bsImg[type == BackgroundInfoType.Animation ? "ani" : type == BackgroundInfoType.Spine ? "spine" : "back"][no];

            if (type == BackgroundInfoType.Spine)
            {
                if (bgInfoProp.HCTagSpine == null)
                {
                    bgInfoProp.HCTagSpine = Load(graphicsDevice, bgInfoProp, bS, type, no);
                }

                return((BackgroundInfo)bgInfoProp.HCTagSpine);
            }
            else
            {
                if (bgInfoProp.HCTag == null)
                {
                    bgInfoProp.HCTag = Load(graphicsDevice, bgInfoProp, bS, type, no);
                }
                return((BackgroundInfo)bgInfoProp.HCTag);
            }
        }
        /// <summary>
        /// Load background from WzImageProperty
        /// </summary>
        /// <param name="parentObject"></param>
        /// <param name="spineParentObject"></param>
        /// <param name="bS"></param>
        /// <param name="type"></param>
        /// <param name="no"></param>
        /// <returns></returns>
        private static BackgroundInfo Load(WzImageProperty parentObject, string bS, BackgroundInfoType type, string no)
        {
            WzCanvasProperty frame0;

            if (type == BackgroundInfoType.Animation)
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject["0"]);
            }
            else if (type == BackgroundInfoType.Spine)
            {
                // TODO: make a preview of the spine image ffs
                WzCanvasProperty spineCanvas = (WzCanvasProperty)parentObject["0"];
                if (spineCanvas != null)
                {
                    Bitmap bitmap   = spineCanvas.GetLinkedWzCanvasBitmap();
                    PointF origin__ = spineCanvas.GetCanvasOriginPosition();

                    return(new BackgroundInfo(parentObject, bitmap, WzInfoTools.PointFToSystemPoint(origin__), bS, type, no, parentObject));
                }
                else
                {
                    PointF origin_ = new PointF();
                    return(new BackgroundInfo(parentObject, Properties.Resources.placeholder, WzInfoTools.PointFToSystemPoint(origin_), bS, type, no, parentObject));
                }
            }
            else
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject);
            }

            PointF origin = frame0.GetCanvasOriginPosition();

            return(new BackgroundInfo(frame0, frame0.GetLinkedWzCanvasBitmap(), WzInfoTools.PointFToSystemPoint(origin), bS, type, no, parentObject));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get background by name
        /// </summary>
        /// <param name="graphicsDevice">The graphics device that the backgroundInfo is to be rendered on (loading spine)</param>
        /// <param name="bS"></param>
        /// <param name="type">Select type</param>
        /// <param name="no"></param>
        /// <returns></returns>
        public static BackgroundInfo Get(GraphicsDevice graphicsDevice, string bS, BackgroundInfoType type, string no)
        {
            if (!Program.InfoManager.BackgroundSets.ContainsKey(bS))
            {
                return(null);
            }

            WzImage         bsImg      = Program.InfoManager.BackgroundSets[bS];
            WzImageProperty bgInfoProp = bsImg[type == BackgroundInfoType.Animation ? "ani" : type == BackgroundInfoType.Spine ? "spine" : "back"]?[no];

            if (bgInfoProp == null)
            {
                string logError = string.Format("Background image {0}/{1} is null, {2}", bS, no, bsImg.ToString());
                MapleLib.Helpers.ErrorLogger.Log(ErrorLevel.IncorrectStructure, logError);
                return(null);
            }

            if (type == BackgroundInfoType.Spine)
            {
                if (bgInfoProp.HCTagSpine == null)
                {
                    bgInfoProp.HCTagSpine = Load(graphicsDevice, bgInfoProp, bS, type, no);
                }

                return((BackgroundInfo)bgInfoProp.HCTagSpine);
            }
            else
            {
                if (bgInfoProp.HCTag == null)
                {
                    bgInfoProp.HCTag = Load(graphicsDevice, bgInfoProp, bS, type, no);
                }
                return((BackgroundInfo)bgInfoProp.HCTag);
            }
        }
 /// <summary>
 /// Constructor
 /// Only to be initialized in Get
 /// </summary>
 /// <param name="image"></param>
 /// <param name="origin"></param>
 /// <param name="bS"></param>
 /// <param name="_type"></param>
 /// <param name="no"></param>
 /// <param name="parentObject"></param>
 private BackgroundInfo(WzImageProperty imageProperty, Bitmap image, System.Drawing.Point origin, string bS, BackgroundInfoType _type, string no, WzObject parentObject)
     : base(image, origin, parentObject)
 {
     this.imageProperty = imageProperty;
     this._bS           = bS;
     this._type         = _type;
     this._no           = no;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// On image selection changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bgSetListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (bgSetListBox.SelectedItem == null)
            {
                return;
            }
            bgImageContainer.Controls.Clear();

            string             path;
            BackgroundInfoType infoType = BackgroundInfoType.Animation;

            if (radioButton_spine.Checked)
            {
                infoType = BackgroundInfoType.Spine;
                path     = "spine";
            }
            else if (aniBg.Checked)
            {
                infoType = BackgroundInfoType.Animation;
                path     = "ani";
            }
            else
            {
                infoType = BackgroundInfoType.Background;
                path     = "back";
            }

            WzImageProperty parentProp = Program.InfoManager.BackgroundSets[(string)bgSetListBox.SelectedItem][path];

            if (parentProp == null || parentProp.WzProperties == null)
            {
                return;
            }

            foreach (WzImageProperty prop in parentProp.WzProperties)
            {
                BackgroundInfo bgInfo = BackgroundInfo.Get((string)bgSetListBox.SelectedItem, infoType, prop.Name);
                if (bgInfo == null)
                {
                    continue;
                }

                ImageViewer item = bgImageContainer.Add(bgInfo.Image, prop.Name, true);
                item.Tag        = bgInfo;
                item.MouseDown += new MouseEventHandler(bgItem_Click);
                item.MouseUp   += new MouseEventHandler(ImageViewer.item_MouseUp);
                item.MaxHeight  = UserSettings.ImageViewerHeight;
                item.MaxWidth   = UserSettings.ImageViewerWidth;
            }
        }
        /// <summary>
        /// Load background from WzImageProperty
        /// </summary>
        /// <param name="graphicsDevice">The graphics device that the backgroundInfo is to be rendered on (loading spine)</param>
        /// <param name="parentObject"></param>
        /// <param name="spineParentObject"></param>
        /// <param name="bS"></param>
        /// <param name="type"></param>
        /// <param name="no"></param>
        /// <returns></returns>
        private static BackgroundInfo Load(GraphicsDevice graphicsDevice, WzImageProperty parentObject, string bS, BackgroundInfoType type, string no)
        {
            WzCanvasProperty frame0;

            if (type == BackgroundInfoType.Animation)
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject["0"]);
            }
            else if (type == BackgroundInfoType.Spine)
            {
                // TODO: make a preview of the spine image ffs
                WzCanvasProperty spineCanvas = (WzCanvasProperty)parentObject["0"];
                if (spineCanvas != null)
                {
                    // Load spine
                    WzSpineAnimationItem wzSpineAnimationItem = null;
                    if (graphicsDevice != null) // graphicsdevice needed to work.. assuming that it is loaded by now before BackgroundPanel
                    {
                        WzImageProperty spineAtlasProp = ((WzSubProperty)parentObject).WzProperties.FirstOrDefault(
                            wzprop => wzprop is WzStringProperty property && property.IsSpineAtlasResources);
                        if (spineAtlasProp != null)
                        {
                            WzStringProperty stringObj = (WzStringProperty)spineAtlasProp;
                            wzSpineAnimationItem = new WzSpineAnimationItem(stringObj);

                            wzSpineAnimationItem.LoadResources(graphicsDevice);
                        }
                    }

                    // Preview Image
                    Bitmap bitmap = spineCanvas.GetLinkedWzCanvasBitmap();

                    // Origin
                    PointF origin__ = spineCanvas.GetCanvasOriginPosition();

                    return(new BackgroundInfo(parentObject, bitmap, WzInfoTools.PointFToSystemPoint(origin__), bS, type, no, parentObject, wzSpineAnimationItem));
                }
                else
                {
                    PointF origin_ = new PointF();
                    return(new BackgroundInfo(parentObject, Properties.Resources.placeholder, WzInfoTools.PointFToSystemPoint(origin_), bS, type, no, parentObject, null));
                }
            }
            else
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject);
            }

            PointF origin = frame0.GetCanvasOriginPosition();

            return(new BackgroundInfo(frame0, frame0.GetLinkedWzCanvasBitmap(), WzInfoTools.PointFToSystemPoint(origin), bS, type, no, parentObject, null));
        }