Exemple #1
0
        private static ObjectInfo Load(WzSubProperty parentObject, string oS, string l0, string l1, string l2)
        {
            WzCanvasProperty frame1    = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject["0"]);
            ObjectInfo       result    = new ObjectInfo(frame1.PngProperty.GetPNG(false), WzInfoTools.VectorToSystemPoint((WzVectorProperty)frame1["origin"]), oS, l0, l1, l2, parentObject);
            WzImageProperty  chairs    = parentObject["seat"];
            WzImageProperty  ropes     = frame1["rope"];
            WzImageProperty  ladders   = frame1["ladder"];
            WzImageProperty  footholds = frame1["foothold"];

            result.footholdOffsets = ParsePropToOffsetMap(footholds);
            result.ropeOffsets     = ParsePropToOffsetMap(ropes);
            result.ladderOffsets   = ParsePropToOffsetMap(ladders);
            if (chairs != null)
            {
                result.chairOffsets = ParsePropToOffsetList(chairs);
            }
            return(result);
        }
        /// <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));
        }
Exemple #3
0
        private static MobInfo Load(WzImage parentObject)
        {
            string id = WzInfoTools.RemoveExtension(parentObject.Name);

            return(new MobInfo(null, new System.Drawing.Point(), id, WzInfoTools.GetMobNameById(id), parentObject));
        }
 public static ReactorInfo Load(WzImage parentObject)
 {
     return(new ReactorInfo(null, new System.Drawing.Point(), WzInfoTools.RemoveExtension(parentObject.Name), parentObject));
 }
Exemple #5
0
        private static MapItem CreateMapItemFromProperty(WzImageProperty source, int x, int y, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);

            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                WzVectorProperty origin = (WzVectorProperty)source["origin"];

                if (source.MSTag == null)
                {
                    source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).PngProperty.GetPNG(false));
                    usedProps.Add(source);
                }

                return(new MapItem(new DXObject(x - origin.X.Value + mapCenterX, y - origin.Y.Value + mapCenterY, (Texture2D)source.MSTag), flip));
            }
            else if (source is WzSubProperty) //animooted
            {
                WzCanvasProperty frameProp;
                int             i      = 0;
                List <DXObject> frames = new List <DXObject>();

                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int?delay = null;

                    try
                    {
                        delay = InfoTool.GetOptionalInt(frameProp["delay"]);
                    }
                    catch (Exception e)
                    {
                        int ij = 0;
                        ij++;
                    }

                    if (delay == null)
                    {
                        delay = 100;
                    }

                    if (frameProp.MSTag == null)
                    {
                        frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.PngProperty.GetPNG(false));
                        usedProps.Add(frameProp);
                    }

                    WzVectorProperty origin = (WzVectorProperty)frameProp["origin"];
                    frames.Add(new DXObject(x - origin.X.Value + mapCenterX, y - origin.Y.Value + mapCenterY, (int)delay, (Texture2D)frameProp.MSTag));
                }

                return(new MapItem(frames, flip));
            }
            else
            {
                throw new Exception("unsupported property type in map simulator");
            }
        }
        /// <summary>
        /// Background
        /// </summary>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="rx"></param>
        /// <param name="ry"></param>
        /// <param name="cx"></param>
        /// <param name="cy"></param>
        /// <param name="a"></param>
        /// <param name="type"></param>
        /// <param name="front"></param>
        /// <param name="mapCenterX"></param>
        /// <param name="mapCenterY"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="flip"></param>
        /// <returns></returns>
        public static BackgroundItem CreateBackgroundFromProperty(WzImageProperty source, int x, int y, int rx, int ry, int cx, int cy, int a, BackgroundType type, bool front, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);
            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                if (source.MSTag == null)
                {
                    source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).GetLinkedWzCanvasBitmap());
                    usedProps.Add(source);
                }

                Texture2D texture = (Texture2D)source.MSTag;
                if (texture != null)
                {
                    System.Drawing.PointF origin = ((WzCanvasProperty)source).GetCanvasOriginPosition();
                    DXObject dxobj = new DXObject(x - (int)origin.X /* - mapCenterX*/, y - (int)origin.Y /* - mapCenterY*/, texture);

                    return(new BackgroundItem(cx, cy, rx, ry, type, a, front, dxobj, flip));
                }
                else
                {
                    throw new Exception("Texture is null for the background property.");
                }
            }
            else if (source is WzSubProperty) //animooted
            {
                WzCanvasProperty frameProp;
                int             i      = 0;
                List <DXObject> frames = new List <DXObject>();
                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int?delay = InfoTool.GetOptionalInt(frameProp["delay"]);
                    if (delay == null)
                    {
                        delay = 100;
                    }

                    if (frameProp.MSTag == null)
                    {
                        frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap());
                        usedProps.Add(frameProp);
                    }

                    Texture2D texture = (Texture2D)frameProp.MSTag;
                    if (texture != null)
                    {
                        System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition();
                        frames.Add(new DXObject(x - (int)origin.X /* - mapCenterX*/, y - (int)origin.Y /* - mapCenterY*/, texture, (int)delay));
                    }
                    else
                    {
                        throw new Exception("Texture is null for the animation");
                    }
                }
                return(new BackgroundItem(cx, cy, rx, ry, type, a, front, frames, flip));
            }
            else
            {
                throw new Exception("Unsupported property type in map simulator");
            }
        }
Exemple #7
0
        private void loadButton_Click(object sender, EventArgs e)
        {
            //Hide();
            WaitWindow ww = new WaitWindow("Loading...");

            ww.Show();
            Application.DoEvents();

            MapLoader     loader = new MapLoader();
            WzImage       mapImage = null;
            int           mapid = -1;
            string        mapName = null, streetName = "", categoryName = "";
            WzSubProperty strMapProp = null;


            if (HAMSelect.Checked)
            {
                loader.CreateMapFromHam(multiBoard, Tabs, File.ReadAllText(HAMBox.Text), rightClickHandler);
                DialogResult = DialogResult.OK;
                ww.EndWait();
                Close();
                return;
            }
            else if (XMLSelect.Checked)
            {
                try
                {
                    mapImage = (WzImage) new WzXmlDeserializer(false, null).ParseXML(XMLBox.Text)[0];
                }
                catch
                {
                    MessageBox.Show("Error while loading XML. Aborted.");
                    ww.EndWait();
                    Show();
                    return;
                }
            }
            else if (WZSelect.Checked)
            {
                string selectedName = mapBrowser.SelectedItem;

                if (selectedName.StartsWith("MapLogin")) // MapLogin, MapLogin1, MapLogin2, MapLogin3
                {
                    mapImage = (WzImage)Program.WzManager["ui"][selectedName + ".img"];
                    mapName  = streetName = categoryName = selectedName;
                }
                else if (mapBrowser.SelectedItem == "CashShopPreview")
                {
                    mapImage = (WzImage)Program.WzManager["ui"]["CashShopPreview.img"];
                    mapName  = streetName = categoryName = "CashShopPreview";
                }
                else
                {
                    string mapid_str = mapBrowser.SelectedItem.Substring(0, 9);
                    int.TryParse(mapid_str, out mapid);

                    string mapcat = "Map" + mapid_str.Substring(0, 1);

                    WzDirectory directory = Program.WzManager.FindMapWz(mapcat);
                    mapImage = (WzImage)directory[mapid_str + ".img"];

                    strMapProp   = WzInfoTools.GetMapStringProp(mapid_str);
                    mapName      = WzInfoTools.GetMapName(strMapProp);
                    streetName   = WzInfoTools.GetMapStreetName(strMapProp);
                    categoryName = WzInfoTools.GetMapCategoryName(strMapProp);
                }
            }
            loader.CreateMapFromImage(mapid, mapImage, mapName, streetName, categoryName, strMapProp, Tabs, multiBoard, rightClickHandler);
            DialogResult = DialogResult.OK;
            ww.EndWait();
            Close();
        }