Exemplo n.º 1
0
        public void ExtractMaps()
        {
            WzImage mapStringsParent = (WzImage)String["Map.img"];

            if (!mapStringsParent.Parsed)
            {
                mapStringsParent.ParseImage();
            }
            foreach (WzSubProperty mapCat in mapStringsParent.WzProperties)
            {
                foreach (WzSubProperty map in mapCat.WzProperties)
                {
                    WzStringProperty mapName = (WzStringProperty)map["mapName"];
                    string           id;
                    if (map.Name.Length == 9)
                    {
                        id = map.Name;
                    }
                    else
                    {
                        id = WzInfoTools.AddLeadingZeros(map.Name, 9);
                    }

                    if (mapName == null)
                    {
                        Program.InfoManager.Maps[id] = "";
                    }
                    else
                    {
                        Program.InfoManager.Maps[id] = mapName.Value;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void ExtractStringWzMaps()
        {
            WzImage mapStringsParent = (WzImage)String["Map.img"];

            if (!mapStringsParent.Parsed)
            {
                mapStringsParent.ParseImage();
            }
            foreach (WzSubProperty mapCat in mapStringsParent.WzProperties)
            {
                foreach (WzSubProperty map in mapCat.WzProperties)
                {
                    WzStringProperty streetName = (WzStringProperty)map["streetName"];
                    WzStringProperty mapName    = (WzStringProperty)map["mapName"];
                    string           id;
                    if (map.Name.Length == 9)
                    {
                        id = map.Name;
                    }
                    else
                    {
                        id = WzInfoTools.AddLeadingZeros(map.Name, 9);
                    }

                    if (mapName == null)
                    {
                        Program.InfoManager.Maps[id] = new Tuple <string, string>("", "");
                    }
                    else
                    {
                        Program.InfoManager.Maps[id] = new Tuple <string, string>(streetName?.Value == null ? string.Empty : streetName.Value, mapName.Value);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static string GetFieldFullName(int mapId)
        {
            string path;
            int    section = mapId / 10000000;

            if (section <= 9)
            {
                path = "maple";
            }
            else if (section >= 10 && section <= 19)
            {
                path = "victoria";
            }
            else if (section >= 20 && section <= 28)
            {
                path = "ossyria";
            }
            else if (section >= 50 && section <= 55)
            {
                path = "singapore";
            }
            else if (section >= 60 && section <= 61)
            {
                path = "MasteriaGL";
            }
            else if (section >= 67 && section <= 68)
            {
                path = "weddingGL";
            }
            else
            {
                path = "etc";
            }
            path += "/" + mapId;
            WzSubProperty subProperty = (WzSubProperty)_map.GetFromPath(path);

            if (subProperty == null)
            {
                return("NO-NAME");
            }

            string           retName    = "";
            WzStringProperty mapName    = (WzStringProperty)subProperty.GetFromPath("mapName");
            WzStringProperty streetName = (WzStringProperty)subProperty.GetFromPath("streetName");

            if (mapName != null)
            {
                retName += mapName.Value;
            }
            if (mapName != null && streetName != null)
            {
                retName += " - ";                                        // x f*****g d
            }
            if (streetName != null)
            {
                retName += streetName.Value;
            }
            return(retName);
        }
        /// <summary>
        /// On click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bgItem_Click(object sender, MouseEventArgs e)
        {
            ImageViewer    imageViewer = sender as ImageViewer;
            BackgroundInfo bgInfo      = (BackgroundInfo)((ImageViewer)sender).Tag;

            if (e.Button == MouseButtons.Left)
            {
                lock (hcsm.MultiBoard)
                {
                    hcsm.EnterEditMode(ItemTypes.Backgrounds);
                    hcsm.MultiBoard.SelectedBoard.Mouse.SetHeldInfo(bgInfo);
                    hcsm.MultiBoard.Focus();
                    ((ImageViewer)sender).IsActive = true;
                }
            }
            else // right click
            {
                if (bgInfo.Type == BackgroundInfoType.Spine) // only shows an animation preview window if its a spine object.
                {
                    ContextMenu cm = new ContextMenu();

                    MenuItem menuItem = new MenuItem();
                    menuItem.Text   = "Preview";
                    menuItem.Tag    = bgInfo;
                    menuItem.Click += new EventHandler(delegate(object sender_, EventArgs e_)
                    {
                        MenuItem menuItem_     = sender_ as MenuItem;
                        BackgroundInfo bgInfo_ = menuItem_.Tag as BackgroundInfo;

                        WzImageProperty spineAtlasProp = bgInfo_.WzImageProperty.WzProperties.FirstOrDefault(
                            wzprop => wzprop is WzStringProperty && ((WzStringProperty)wzprop).IsSpineAtlasResources);

                        if (spineAtlasProp != null)
                        {
                            WzStringProperty stringObj = (WzStringProperty)spineAtlasProp;
                            Thread thread = new Thread(() =>
                            {
                                try
                                {
                                    WzSpineAnimationItem item = new WzSpineAnimationItem(stringObj);

                                    // Create xna window
                                    SpineAnimationWindow Window = new SpineAnimationWindow(item);
                                    Window.Run();
                                }
                                catch (Exception ex)
                                {
                                }
                            });
                            thread.Start();
                            thread.Join();
                        }
                    });
                    cm.MenuItems.Add(menuItem);

                    cm.Show(imageViewer, new Point(0, 50));
                }
            }
        }
Exemplo n.º 5
0
        private Bitmap RenderMinimap(Size bmpSize, WzFile wzFile, WzImage img, string mapIdName, WzSubProperty miniMapSubProperty)
        {
            Bitmap minimapRender = new Bitmap(400, 200);

            using (Graphics drawBuf = Graphics.FromImage(minimapRender))
            {
                // Draw map mark
                WzStringProperty mapMark = ((WzStringProperty)img["info"]["mapMark"]);
                if (mapMark != null)
                {
                    string           mapMarkPath   = wzFile.WzDirectory.Name + "/MapHelper.img/mark/" + mapMark.GetString();
                    WzCanvasProperty mapMarkCanvas = (WzCanvasProperty)wzFile.GetObjectFromPath(mapMarkPath);

                    if (mapMarkCanvas != null && mapMark.ToString() != "None") // Doesnt have to render mapmark if its not available. Actual client does not crash
                    {
                        drawBuf.DrawImage(mapMarkCanvas.GetLinkedWzCanvasBitmap(), 10, 10);
                    }
                }
                // Get map name
                string mapName    = string.Empty;
                string streetName = string.Empty;

                string  mapNameStringPath = "String.wz/Map.img";
                WzImage mapNameImages     = (WzImage)WzFile.GetObjectFromMultipleWzFilePath(mapNameStringPath, Program.WzMan.WzFileListReadOnly);
                foreach (WzSubProperty subAreaImgProp in mapNameImages.WzProperties)
                {
                    foreach (WzSubProperty mapImg in subAreaImgProp.WzProperties)
                    {
                        if (mapImg.Name == mapIdName)
                        {
                            mapName    = mapImg["mapName"].ReadString(string.Empty);
                            streetName = mapImg["streetName"].ReadString(string.Empty);
                            break;
                        }
                    }
                }

                // Draw map name and ID
                //drawBuf.FillRectangle(new SolidBrush(Color.CornflowerBlue), 0, 0, bmpSize.Width, bmpSize.Height);
                drawBuf.DrawString(string.Format("[{0}] {1}", mapIdName, streetName), FONT_DISPLAY_MAPID, new SolidBrush(Color.Black), new PointF(60, 10));
                drawBuf.DrawString(mapName, FONT_DISPLAY_MAPID, new SolidBrush(Color.Black), new PointF(60, 30));

                // Draw mini map
                if (miniMapSubProperty != null)
                {
                    drawBuf.DrawImage(((WzCanvasProperty)miniMapSubProperty["canvas"]).GetLinkedWzCanvasBitmap(), 10, 80);
                }
                else
                {
                    drawBuf.DrawString("Minimap not availible", FONT_DISPLAY_MINIMAP_NOT_AVAILABLE, new SolidBrush(Color.Black), new PointF(10, 45));
                }
            }
            minimapRender.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_miniMapRender.bmp");
            return(minimapRender);
        }
        /// <summary>
        /// Load skeleton data by json or binary automatically
        /// </summary>
        /// <param name="atlasNode"></param>
        /// <param name="atlas"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private static bool TryLoadSkeletonJsonOrBinary(WzImageProperty atlasNode, Atlas atlas, out SkeletonData data)
        {
            data = null;

            if (atlasNode == null || atlasNode.Parent == null || atlas == null)
            {
                return(false);
            }
            WzObject parent = atlasNode.Parent;

            List <WzImageProperty> childProperties;

            if (parent is WzImageProperty)
            {
                childProperties = ((WzImageProperty)parent).WzProperties;
            }
            else
            {
                childProperties = ((WzImage)parent).WzProperties;
            }


            if (childProperties != null)
            {
                WzStringProperty stringJsonProp = (WzStringProperty)childProperties.Where(child => child.Name.EndsWith(".json")).FirstOrDefault();

                if (stringJsonProp != null) // read json based
                {
                    StringReader skeletonReader = new StringReader(stringJsonProp.GetString());
                    SkeletonJson json           = new SkeletonJson(atlas);
                    data = json.ReadSkeletonData(skeletonReader);

                    return(true);
                }
                else
                {
                    // try read binary based
                    foreach (WzImageProperty property in childProperties)
                    {
                        if (property is WzBinaryProperty)
                        {
                            WzBinaryProperty soundProp = (WzBinaryProperty)property; // should be called binaryproperty actually

                            using (MemoryStream ms = new MemoryStream(soundProp.GetBytes(false)))
                            {
                                SkeletonBinary skeletonBinary = new SkeletonBinary(atlas);
                                data = skeletonBinary.ReadSkeletonData(ms);
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
        /// <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));
        }
Exemplo n.º 8
0
        private void CreateWzProp(IPropertyContainer parent, WzPropertyType propType, string propName, object value)
        {
            WzImageProperty addedProp;

            switch (propType)
            {
            case WzPropertyType.Float:
                addedProp = new WzFloatProperty(propName);
                break;

            case WzPropertyType.Canvas:
                addedProp = new WzCanvasProperty(propName);
                ((WzCanvasProperty)addedProp).PngProperty = new WzPngProperty();
                break;

            case WzPropertyType.Int:
                addedProp = new WzIntProperty(propName);
                break;

            case WzPropertyType.Double:
                addedProp = new WzDoubleProperty(propName);
                break;

            /*case WzPropertyType.Sound:
             *  addedProp = new WzSoundProperty(propName);
             *  break;*/
            case WzPropertyType.String:
                addedProp = new WzStringProperty(propName);
                break;

            case WzPropertyType.Short:
                addedProp = new WzShortProperty(propName);
                break;

            case WzPropertyType.Vector:
                addedProp = new WzVectorProperty(propName);
                ((WzVectorProperty)addedProp).X = new WzIntProperty("X");
                ((WzVectorProperty)addedProp).Y = new WzIntProperty("Y");
                break;

            case WzPropertyType.Lua:     // probably dont allow the user to create custom Lua for now..
            {
                addedProp = new WzLuaProperty(propName, new byte[] { });
                break;
            }

            default:
                throw new NotSupportedException("Not supported type");
            }
            addedProp.SetValue(value);
            parent.AddProperty(addedProp);
        }
Exemplo n.º 9
0
        public static string GetNpcNameById(string id)
        {
            id = RemoveLeadingZeros(id);
            WzStringProperty npcName = (WzStringProperty)Program.WzManager.String.GetObjectFromPath(@"String.wz/Npc.img/" + id + @"/name");

            if (npcName != null)
            {
                return(npcName.Value);
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 10
0
        public override void ParseImage()
        {
            WzStringProperty link = (WzStringProperty)((WzSubProperty)((WzImage)ParentObject)["info"])["link"];

            if (link != null)
            {
                LinkedImage = (WzImage)Program.WzManager["reactor"][link.Value + ".img"];
                ExtractPNGFromImage(LinkedImage);
            }
            else
            {
                ExtractPNGFromImage((WzImage)ParentObject);
            }
        }
Exemplo n.º 11
0
        public static string GetMapStreetName(WzSubProperty mapProp)
        {
            if (mapProp == null)
            {
                return("");
            }
            WzStringProperty streetName = (WzStringProperty)mapProp["streetName"];

            if (streetName == null)
            {
                return("");
            }
            return(streetName.Value);
        }
Exemplo n.º 12
0
        public override void ParseImage()
        {
            WzStringProperty link = (WzStringProperty)((WzSubProperty)((WzImage)ParentObject)["info"])["link"];

            if (link != null)
            {
                LinkedImage = SearchMobImg(link.Value);
                ExtractPNGFromImage(LinkedImage);
            }
            else
            {
                ExtractPNGFromImage((WzImage)ParentObject);
            }
        }
Exemplo n.º 13
0
        public void ExtractMobFile()
        {
            WzImage mobImage = (WzImage)String["Mob.img"];

            if (!mobImage.Parsed)
            {
                mobImage.ParseImage();
            }
            foreach (WzSubProperty mob in mobImage.WzProperties)
            {
                WzStringProperty nameProp = (WzStringProperty)mob["name"];
                string           name     = nameProp == null ? "" : nameProp.Value;
                Program.InfoManager.Mobs.Add(WzInfoTools.AddLeadingZeros(mob.Name, 7), name);
            }
        }
Exemplo n.º 14
0
        public void ExtractNpcFile()
        {
            WzImage npcImage = (WzImage)String["Npc.img"];

            if (!npcImage.Parsed)
            {
                npcImage.ParseImage();
            }
            foreach (WzSubProperty npc in npcImage.WzProperties)
            {
                WzStringProperty nameProp = (WzStringProperty)npc["name"];
                string           name     = nameProp == null ? "" : nameProp.Value;
                Program.InfoManager.NPCs.Add(WzInfoTools.AddLeadingZeros(npc.Name, 7), name);
            }
        }
Exemplo n.º 15
0
        public void ExtractItems()
        {
            WzImage consImage = (WzImage)String["Consume.img"];

            if (!consImage.Parsed)
            {
                consImage.ParseImage();
            }
            foreach (WzSubProperty item in consImage.WzProperties)
            {
                WzStringProperty nameProp = (WzStringProperty)item["name"];
                string           name     = nameProp == null ? "" : nameProp.Value;
                Program.InfoManager.Items.Add(WzInfoTools.AddLeadingZeros(item.Name, 7), name);
            }
        }
Exemplo n.º 16
0
        private void CreateWzProp(IPropertyContainer parent, WzPropertyType propType, string propName, object value)
        {
            IWzImageProperty addedProp;

            switch (propType)
            {
            case WzPropertyType.ByteFloat:
                addedProp = new WzByteFloatProperty(propName);
                break;

            case WzPropertyType.Canvas:
                addedProp = new WzCanvasProperty(propName);
                ((WzCanvasProperty)addedProp).PngProperty = new WzPngProperty();
                break;

            case WzPropertyType.CompressedInt:
                addedProp = new WzCompressedIntProperty(propName);
                break;

            case WzPropertyType.Double:
                addedProp = new WzDoubleProperty(propName);
                break;

            /*case WzPropertyType.Sound:
             *  addedProp = new WzSoundProperty(propName);
             *  break;*/
            case WzPropertyType.String:
                addedProp = new WzStringProperty(propName);
                break;

            case WzPropertyType.UnsignedShort:
                addedProp = new WzUnsignedShortProperty(propName);
                break;

            case WzPropertyType.Vector:
                addedProp = new WzVectorProperty(propName);
                ((WzVectorProperty)addedProp).X = new WzCompressedIntProperty("X");
                ((WzVectorProperty)addedProp).Y = new WzCompressedIntProperty("Y");
                break;

            default:
                throw new NotSupportedException("not supported type");
            }
            addedProp.SetValue(value);
            parent.AddProperty(addedProp);
        }
Exemplo n.º 17
0
        public static string GetNpcNameById(string id)
        {
            id = RemoveLeadingZeros(id);
            WzObject obj = Program.WzManager.String["Npc.img"][id];

            if (obj == null)
            {
                return("");
            }
            WzStringProperty npcName = (WzStringProperty)obj["name"];

            if (npcName == null)
            {
                return("");
            }
            return(npcName.Value);
        }
Exemplo n.º 18
0
        public static string GetStreetNameById(string id)
        {
            id = RemoveLeadingZeros(id);
            WzImage mapNameParent = (WzImage)Program.WzManager.String.WzDirectory["Map.img"];

            foreach (WzSubProperty mapNameCategory in mapNameParent.WzProperties)
            {
                WzSubProperty mapNameDirectory = (WzSubProperty)mapNameCategory[id];
                if (mapNameDirectory != null)
                {
                    WzStringProperty streetName = (WzStringProperty)mapNameCategory["streetName"];
                    if (streetName != null)
                    {
                        return(streetName.Value);
                    }
                }
            }
            return("");
        }
        /// <summary>
        /// Loads skeleton
        /// </summary>
        /// <param name="atlasNode"></param>
        /// <param name="textureLoader"></param>
        /// <returns></returns>
        public static SkeletonData LoadSkeleton(WzStringProperty atlasNode, TextureLoader textureLoader)
        {
            string atlasData = atlasNode.GetString();

            if (string.IsNullOrEmpty(atlasData))
            {
                return(null);
            }
            StringReader atlasReader = new StringReader(atlasData);

            Atlas        atlas = new Atlas(atlasReader, string.Empty, textureLoader);
            SkeletonData skeletonData;

            if (!TryLoadSkeletonJsonOrBinary(atlasNode, atlas, out skeletonData))
            {
                atlas.Dispose();
                return(null);
            }
            return(skeletonData);
        }
Exemplo n.º 20
0
        //tbd load mob2.wz etc
        public void ExtractMobFile()
        {
            WzImage mobImage = (WzImage)String["Mob.img"];

            if (!mobImage.Parsed)
            {
                mobImage.ParseImage();
            }
            foreach (WzSubProperty mob in mobImage.WzProperties)
            {
                WzStringProperty nameProp = (WzStringProperty)mob["name"];
                string           name     = nameProp == null ? "" : nameProp.Value;
                Program.InfoManager.Mobs.Add(WzInfoTools.AddLeadingZeros(mob.Name, 7), name);
            }

            /*   WzImage mobImage2 = (WzImage)String["Mob001.img"];
             * if (mobImage2 != null)
             * {
             *     if (!mobImage2.Parsed) mobImage2.ParseImage();
             *     foreach (WzSubProperty mob in mobImage2.WzProperties)
             *     {
             *         WzStringProperty nameProp = (WzStringProperty)mob["name"];
             *         string name = nameProp == null ? "" : nameProp.Value;
             *         Program.InfoManager.Mobs.Add(WzInfoTools.AddLeadingZeros(mob.Name, 7), name);
             *     }
             * }
             * WzImage mobImage3 = (WzImage)String["Mob2.img"];
             * if (mobImage3 != null)
             * {
             *     if (!mobImage3.Parsed) mobImage3.ParseImage();
             *     foreach (WzSubProperty mob in mobImage3.WzProperties)
             *     {
             *         WzStringProperty nameProp = (WzStringProperty)mob["name"];
             *         string name = nameProp == null ? "" : nameProp.Value;
             *         Program.InfoManager.Mobs.Add(WzInfoTools.AddLeadingZeros(mob.Name, 7), name);
             *     }
             * }*/
        }
Exemplo n.º 21
0
 // TODO: this is not deserializable due to missing type information
 protected void WritePropertyToJson(TextWriter tw, WzImageProperty prop, bool isArray = false)
 {
     tw.Write("\n");
     if (prop is WzCanvasProperty)
     {
         WzCanvasProperty property = (WzCanvasProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         if (ExportBase64Data)
         {
             MemoryStream stream = new MemoryStream();
             property.PngProperty.GetPNG(false).Save(stream, System.Drawing.Imaging.ImageFormat.Png);
             byte[] pngbytes = stream.ToArray();
             stream.Close();
             tw.Write($"{{" +
                      $"\"width\": {property.PngProperty.Width}, " +
                      $"\"height\": {property.PngProperty.Height}, " +
                      $"\"basedata\": {Convert.ToBase64String(pngbytes)}\",");
         }
         else
         {
             tw.Write($"{{" +
                      $"\"width\": {property.PngProperty.Width}, " +
                      $"\"height\": {property.PngProperty.Height},");
         }
         if (property.WzProperties.Count() > 0)
         {
             var last = property.WzProperties.Last();
             foreach (WzImageProperty p in property.WzProperties)
             {
                 WritePropertyToJson(tw, p);
                 if (!p.Equals(last))
                 {
                     tw.Write(",");
                 }
             }
         }
         tw.Write("}");
     }
     else if (prop is WzIntProperty)
     {
         WzIntProperty property = (WzIntProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value}");
     }
     else if (prop is WzDoubleProperty)
     {
         WzDoubleProperty property = (WzDoubleProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value}");
     }
     else if (prop is WzNullProperty)
     {
         WzNullProperty property = (WzNullProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": null");
     }
     else if (prop is WzSoundProperty)
     {
         WzSoundProperty property = (WzSoundProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         if (ExportBase64Data)
         {
             tw.Write($"{{" +
                      $"\"length\":\"{property.Length}\", " +
                      $"\"basehead\": \"{Convert.ToBase64String(property.Header)}\"" +
                      $"\"basedata\": \"{Convert.ToBase64String(property.GetBytes(false))}\"" +
                      $"}}");
         }
         else
         {
             tw.Write("{}");
         }
     }
     else if (prop is WzStringProperty)
     {
         WzStringProperty property = (WzStringProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {JsonConvert.ToString(property.Value)}");
     }
     else if (prop is WzSubProperty)
     {
         WzSubProperty property = (WzSubProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         // This has the same problem as the convex property
         bool propertyIsArray = property.WzProperties.TrueForAll(x => { int num; return(int.TryParse(x.Name, out num)); });
         tw.Write(propertyIsArray ? "[" : "{");
         if (property.WzProperties.Count() > 0)
         {
             var last = property.WzProperties.Last();
             foreach (WzImageProperty p in property.WzProperties)
             {
                 bool isObject = p is WzConvexProperty || p is WzSubProperty || p is WzSoundProperty || p is WzCanvasProperty || p is WzVectorProperty;
                 if (propertyIsArray)
                 {
                     tw.Write($"{{\"index\":{p.Name}, \"item\":");
                     tw.Write(!isObject ? "{" : "");
                 }
                 WritePropertyToJson(tw, p, propertyIsArray);
                 if (propertyIsArray)
                 {
                     tw.Write(!isObject ? "}" : "");
                     tw.Write("}");
                 }
                 if (!p.Equals(last))
                 {
                     tw.Write(",");
                 }
             }
         }
         tw.Write(propertyIsArray ? "]" : "}");
     }
     else if (prop is WzShortProperty)
     {
         WzShortProperty property = (WzShortProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value}");
     }
     else if (prop is WzLongProperty)
     {
         WzLongProperty property = (WzLongProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value}");
     }
     else if (prop is WzUOLProperty)
     {
         WzUOLProperty property = (WzUOLProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": \"{property.Value}\"");
     }
     else if (prop is WzVectorProperty)
     {
         WzVectorProperty property = (WzVectorProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         tw.Write($"{{" +
                  $"\"x\": {property.X.Value}, " +
                  $"\"y\": {property.Y.Value}" +
                  $"}}");
     }
     else if (prop is WzFloatProperty)
     {
         WzFloatProperty property = (WzFloatProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value * 1.0}");
     }
     else if (prop is WzConvexProperty)
     {
         WzConvexProperty property = (WzConvexProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         tw.Write("[");
         if (property.WzProperties.Count() > 0)
         {
             var last = property.WzProperties.Last();
             foreach (WzImageProperty p in property.WzProperties)
             {
                 bool isObject = p is WzConvexProperty || p is WzSubProperty || p is WzSoundProperty || p is WzCanvasProperty || p is WzVectorProperty;
                 tw.Write(isObject ? "" : "{");
                 WritePropertyToJson(tw, p, true);
                 tw.Write(isObject ? "" : "}");
                 if (!p.Equals(last))
                 {
                     tw.Write(",");
                 }
             }
         }
         tw.Write("]");
     }
 }
Exemplo n.º 22
0
        public void SaveMap(WzImage img, double zoom)
        {
            node = MainPanel.DataTree.SelectedNode;
            WzFile wzFile = (WzFile)((WzObject)node.Tag).WzFileParent;
            // Spawnpoint foothold and portal lists
            List <SpawnPoint.Spawnpoint> MSPs = new List <SpawnPoint.Spawnpoint>();
            List <FootHold.Foothold>     FHs  = new List <FootHold.Foothold>();
            List <Portals.Portal>        Ps   = new List <Portals.Portal>();
            Size  bmpSize;
            Point center;

            WzSubProperty miniMapSubProperty = ((WzSubProperty)img["miniMap"]);

            try
            {
                bmpSize = new Size(((WzIntProperty)miniMapSubProperty["width"]).Value, ((WzIntProperty)miniMapSubProperty["height"]).Value);
                center  = new Point(((WzIntProperty)miniMapSubProperty["centerX"]).Value, ((WzIntProperty)miniMapSubProperty["centerY"]).Value);
            }
            catch (Exception exp)
            {
                if (exp is KeyNotFoundException || exp is NullReferenceException)
                {
                    try
                    {
                        WzSubProperty infoSubProperty = ((WzSubProperty)img["info"]);

                        bmpSize = new Size(((WzIntProperty)infoSubProperty["VRRight"]).Value - ((WzIntProperty)infoSubProperty["VRLeft"]).Value, ((WzIntProperty)infoSubProperty["VRBottom"]).Value - ((WzIntProperty)infoSubProperty["VRTop"]).Value);
                        center  = new Point(((WzIntProperty)infoSubProperty["VRRight"]).Value, ((WzIntProperty)infoSubProperty["VRBottom"]).Value);
                    }
                    catch
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            Bitmap mapRender = new Bitmap(bmpSize.Width, bmpSize.Height + 10);

            using (Graphics drawBuf = Graphics.FromImage(mapRender))
            {
                //drawBuf.FillRectangle(new SolidBrush(Color.CornflowerBlue), 0, 0, bmpSize.Width, bmpSize.Height);
                drawBuf.DrawString("Map " + img.Name.Substring(0, img.Name.Length - 4), FONT_DISPLAY_MAPID, new SolidBrush(Color.Black), new PointF(10, 10));

                if (miniMapSubProperty != null)
                {
                    drawBuf.DrawImage(((WzCanvasProperty)miniMapSubProperty["canvas"]).PngProperty.GetPNG(false), 10, 45);
                }
                else
                {
                    drawBuf.DrawString("Minimap not availible", FONT_DISPLAY_MINIMAP_NOT_AVAILABLE, new SolidBrush(Color.Black), new PointF(10, 45));
                }

                WzSubProperty ps = (WzSubProperty)img["portal"];
                foreach (WzSubProperty p in ps.WzProperties)
                {
                    //WzSubProperty p = (WzSubProperty)p10.ExtendedProperty;
                    int   x      = ((WzIntProperty)p["x"]).Value + center.X;
                    int   y      = ((WzIntProperty)p["y"]).Value + center.Y;
                    int   type   = ((WzIntProperty)p["pt"]).Value;
                    Color pColor = Color.Red;
                    if (type == 0)
                    {
                        pColor = Color.Orange;
                    }
                    else if (type == 2 || type == 7)//Normal
                    {
                        pColor = Color.Blue;
                    }
                    else if (type == 3)//Auto-enter
                    {
                        pColor = Color.Magenta;
                    }
                    else if (type == 1 || type == 8)
                    {
                        pColor = Color.BlueViolet;
                    }
                    else
                    {
                        pColor = Color.IndianRed;
                    }
                    drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, pColor.R, pColor.G, pColor.B)), x - 20, y - 20, 40, 40);
                    drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x - 20, y - 20, 40, 40);
                    drawBuf.DrawString(p.Name, FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Red), x - 8, y - 7.7F);
                    Portals.Portal portal = new Portals.Portal();
                    portal.Shape = new Rectangle(x - 20, y - 20, 40, 40);
                    portal.Data  = p;
                    Ps.Add(portal);
                }
                try
                {
                    WzSubProperty SPs = (WzSubProperty)img["life"];
                    foreach (WzSubProperty sp in SPs.WzProperties)
                    {
                        Color MSPColor = Color.ForestGreen;

                        switch (((WzStringProperty)sp["type"]).Value)
                        {
                        case "m":     // monster
                        {
                            int monsterId = int.Parse(((WzStringProperty)sp["id"]).GetString());

                            int x      = ((WzIntProperty)sp["x"]).Value + center.X;
                            int y      = ((WzIntProperty)sp["y"]).Value + center.Y;
                            int x_text = x - 15;
                            int y_text = y - 15;

                            SpawnPoint.Spawnpoint MSP = new SpawnPoint.Spawnpoint();
                            MSP.Shape = new Rectangle(x_text, y_text, 30, 30);
                            MSP.Data  = sp;
                            MSPs.Add(MSP);


                            // Render monster image
                            string monsterStrId = monsterId < 1000000 ? ("0" + monsterId) : monsterId.ToString();

                            WzStringProperty linkInfo = (WzStringProperty)WzFile.GetObjectFromMultipleWzFilePath(string.Format("Mob.wz/{0}.img/info/link", monsterStrId), Program.WzMan.WzFileListReadOnly);
                            if (linkInfo != null)
                            {
                                monsterId    = int.Parse(linkInfo.GetString());
                                monsterStrId = monsterId < 1000000 ? ("0" + monsterId) : monsterId.ToString();
                            }
                            WzCanvasProperty mobImage = (WzCanvasProperty)WzFile.GetObjectFromMultipleWzFilePath(string.Format("Mob.wz/{0}.img/stand/0", monsterStrId), Program.WzMan.WzFileListReadOnly);
                            if (mobImage != null)
                            {
                                WzVectorProperty originXY = (WzVectorProperty)mobImage["origin"];
                                PointF           renderXY;
                                if (originXY != null)
                                {
                                    renderXY = new PointF(x - originXY.Pos.X, y - originXY.Pos.Y);
                                }
                                else
                                {
                                    renderXY = new PointF(x, y);
                                }

                                WzImageProperty linkedCanvas = mobImage.GetLinkedWzCanvasProperty();
                                if (linkedCanvas != null)
                                {
                                    drawBuf.DrawImage(linkedCanvas.GetBitmap(), renderXY);
                                }
                                else
                                {
                                    drawBuf.DrawImage(mobImage.GetBitmap(), renderXY);
                                }
                            }
                            else
                            {
                                drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, MSPColor.R, MSPColor.G, MSPColor.B)), x_text, y_text, 30, 30);
                                drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x_text, y_text, 30, 30);
                            }
                            // Get monster name
                            WzStringProperty stringName = (WzStringProperty)WzFile.GetObjectFromMultipleWzFilePath(string.Format("String.wz/Mob.img/{0}/name", monsterId), Program.WzMan.WzFileListReadOnly);

                            drawBuf.DrawString(string.Format("SP: {0}, Name: {1}, ID: {2}", sp.Name, stringName != null ? stringName.GetString() : string.Empty, monsterId), FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Red), x_text + 7, y_text + 7.3F);
                            break;
                        }

                        case "n":     // NPC
                        {
                            break;
                        }
                        }
                    }
                }
                catch (Exception exp)
                {
                    Debug.WriteLine(exp.ToString());
                }

                WzSubProperty fhs = (WzSubProperty)img["foothold"];
                foreach (WzImageProperty fhspl0 in fhs.WzProperties)
                {
                    foreach (WzImageProperty fhspl1 in fhspl0.WzProperties)
                    {
                        Color c = Color.FromArgb(95, Color.FromArgb(GetPseudoRandomColor(fhspl1.Name)));
                        foreach (WzSubProperty fh in fhspl1.WzProperties)
                        {
                            int x      = ((WzIntProperty)fh["x1"]).Value + center.X;
                            int y      = ((WzIntProperty)fh["y1"]).Value + center.Y;
                            int width  = ((((WzIntProperty)fh["x2"]).Value + center.X) - x);
                            int height = ((((WzIntProperty)fh["y2"]).Value + center.Y) - y);
                            if (width < 0)
                            {
                                x    += width;// *2;
                                width = -width;
                            }
                            if (height < 0)
                            {
                                y     += height;// *2;
                                height = -height;
                            }
                            if (width == 0 || width < 15)
                            {
                                width = 15;
                            }
                            height += 10;
                            FootHold.Foothold nFH = new FootHold.Foothold();
                            nFH.Shape = new Rectangle(x, y, width, height);
                            nFH.Data  = fh;
                            FHs.Add(nFH);
                            //drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, Color.Gray.R, Color.Gray.G, Color.Gray.B)), x, y, width, height);
                            drawBuf.FillRectangle(new SolidBrush(c), x, y, width, height);
                            drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x, y, width, height);
                            drawBuf.DrawString(fh.Name, FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Red), new PointF(x + (width / 2) - 8, y + (height / 2) - 7.7F));
                        }
                    }
                }
            }
            mapRender.Save("Renders\\" + img.Name.Substring(0, img.Name.Length - 4) + "\\" + img.Name.Substring(0, img.Name.Length - 4) + "_footholdRender.bmp");

            Bitmap tileRender = new Bitmap(bmpSize.Width, bmpSize.Height);

            using (Graphics tileBuf = Graphics.FromImage(tileRender))
            {
                for (int i = 0; i < 7; i++)
                {
                    // The below code was commented out because it was creating problems when loading certain maps. When debugging it would throw an exception at line 469.
                    // Objects first
                    if (((WzSubProperty)((WzSubProperty)img[i.ToString()])["obj"]).WzProperties.Count > 0)
                    {
                        foreach (WzSubProperty obj in ((WzSubProperty)((WzSubProperty)img[i.ToString()])["obj"]).WzProperties)
                        {
                            //WzSubProperty obj = (WzSubProperty)oe.ExtendedProperty;
                            string           imgName = ((WzStringProperty)obj["oS"]).Value + ".img";
                            string           l0      = ((WzStringProperty)obj["l0"]).Value;
                            string           l1      = ((WzStringProperty)obj["l1"]).Value;
                            string           l2      = ((WzStringProperty)obj["l2"]).Value;
                            int              x       = ((WzIntProperty)obj["x"]).Value + center.X;
                            int              y       = ((WzIntProperty)obj["y"]).Value + center.Y;
                            WzVectorProperty origin;
                            WzPngProperty    png;

                            string imgObjPath = wzFile.WzDirectory.Name + "/Obj/" + imgName + "/" + l0 + "/" + l1 + "/" + l2 + "/0";

                            WzImageProperty objData = (WzImageProperty)WzFile.GetObjectFromMultipleWzFilePath(imgObjPath, Program.WzMan.WzFileListReadOnly);
tryagain:
                            if (objData is WzCanvasProperty)
                            {
                                png    = ((WzCanvasProperty)objData).PngProperty;
                                origin = (WzVectorProperty)((WzCanvasProperty)objData)["origin"];
                            }
                            else if (objData is WzUOLProperty)
                            {
                                WzObject currProp = objData.Parent;
                                foreach (string directive in ((WzUOLProperty)objData).Value.Split("/".ToCharArray()))
                                {
                                    if (directive == "..")
                                    {
                                        currProp = currProp.Parent;
                                    }
                                    else
                                    {
                                        if (currProp.GetType() == typeof(WzSubProperty))
                                        {
                                            currProp = ((WzSubProperty)currProp)[directive];
                                        }
                                        else if (currProp.GetType() == typeof(WzCanvasProperty))
                                        {
                                            currProp = ((WzCanvasProperty)currProp)[directive];
                                        }
                                        else if (currProp.GetType() == typeof(WzImage))
                                        {
                                            currProp = ((WzImage)currProp)[directive];
                                        }
                                        else if (currProp.GetType() == typeof(WzConvexProperty))
                                        {
                                            currProp = ((WzConvexProperty)currProp)[directive];
                                        }
                                        else
                                        {
                                            throw new Exception("UOL error at map renderer");
                                        }
                                    }
                                }
                                objData = (WzImageProperty)currProp;
                                goto tryagain;
                            }
                            else
                            {
                                throw new Exception("unknown type at map renderer");
                            }
                            //WzVectorProperty origin = (WzVectorProperty)wzFile.GetObjectFromPath(wzFile.WzDirectory.Name + "/Obj/" + imgName + "/" + l0 + "/" + l1 + "/" + l2 + "/0");
                            //WzPngProperty png = (WzPngProperty)wzFile.GetObjectFromPath(wzFile.WzDirectory.Name + "/Obj/" + imgName + "/" + l0 + "/" + l1 + "/" + l2 + "/0/PNG");
                            tileBuf.DrawImage(png.GetPNG(false), x - origin.X.Value, y - origin.Y.Value);
                        }
                    }
                    if (((WzSubProperty)((WzSubProperty)img[i.ToString()])["info"]).WzProperties.Count == 0)
                    {
                        continue;
                    }

                    if (((WzSubProperty)((WzSubProperty)img[i.ToString()])["tile"]).WzProperties.Count == 0)
                    {
                        continue;
                    }

                    // Ok, we have some tiles and a tileset

                    string tileSetName = ((WzStringProperty)((WzSubProperty)((WzSubProperty)img[i.ToString()])["info"])["tS"]).Value;

                    // Browse to the tileset
                    string  tilePath = wzFile.WzDirectory.Name + "/Tile/" + tileSetName + ".img";
                    WzImage tileSet  = (WzImage)WzFile.GetObjectFromMultipleWzFilePath(tilePath, Program.WzMan.WzFileListReadOnly);
                    if (!tileSet.Parsed)
                    {
                        tileSet.ParseImage();
                    }

                    foreach (WzSubProperty tile in ((WzSubProperty)((WzSubProperty)img[i.ToString()])["tile"]).WzProperties)
                    {
                        //WzSubProperty tile = (WzSubProperty)te.ExtendedProperty;

                        int    x            = ((WzIntProperty)tile["x"]).Value + center.X;
                        int    y            = ((WzIntProperty)tile["y"]).Value + center.Y;
                        string tilePackName = ((WzStringProperty)tile["u"]).Value;
                        string tileID       = ((WzIntProperty)tile["no"]).Value.ToString();
                        Point  origin       = new Point(((WzVectorProperty)((WzCanvasProperty)((WzSubProperty)tileSet[tilePackName])[tileID])["origin"]).X.Value, ((WzVectorProperty)((WzCanvasProperty)((WzSubProperty)tileSet[tilePackName])[tileID])["origin"]).Y.Value);

                        tileBuf.DrawImage(((WzCanvasProperty)((WzSubProperty)tileSet[tilePackName])[tileID]).PngProperty.GetPNG(false), x - origin.X, y - origin.Y);
                    }
                }
            }

            tileRender.Save("Renders\\" + img.Name.Substring(0, img.Name.Length - 4) + "\\" + img.Name.Substring(0, img.Name.Length - 4) + "_tileRender.bmp");

            Bitmap fullBmp = new Bitmap(bmpSize.Width, bmpSize.Height + 10);

            using (Graphics fullBuf = Graphics.FromImage(fullBmp))
            {
                fullBuf.FillRectangle(new SolidBrush(Color.CornflowerBlue), 0, 0, bmpSize.Width, bmpSize.Height + 10);
                fullBuf.DrawImage(tileRender, 0, 0);
                fullBuf.DrawImage(mapRender, 0, 0);
            }
            //pbx_Foothold_Render.Image = fullBmp;
            fullBmp.Save("Renders\\" + img.Name.Substring(0, img.Name.Length - 4) + "\\" + img.Name.Substring(0, img.Name.Length - 4) + "_fullRender.bmp");

            DisplayMap showMap = new DisplayMap();

            showMap.map            = fullBmp;
            showMap.Footholds      = FHs;
            showMap.thePortals     = Ps;
            showMap.settings       = settings;
            showMap.MobSpawnPoints = MSPs;
            showMap.FormClosed    += new FormClosedEventHandler(DisplayMapClosed);
            try
            {
                showMap.scale = zoom;
                showMap.Show();
            }
            catch (FormatException)
            {
                MessageBox.Show("You must set the render scale to a valid number.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Attempts to render the map and save the progress
        /// </summary>
        /// <param name="img"></param>
        /// <param name="zoom"></param>
        /// <param name="errorList"></param>
        public bool TryRenderMapAndSave(WzImage img, double zoom, ref List <string> errorList)
        {
            string mapIdName = img.Name.Substring(0, img.Name.Length - 4);

            node = MainPanel.DataTree.SelectedNode;
            WzFile wzFile = ((WzObject)node.Tag).WzFileParent;

            // Spawnpoint foothold and portal lists
            List <SpawnPoint.Spawnpoint> MSPs = new List <SpawnPoint.Spawnpoint>();
            List <FootHold.Foothold>     FHs  = new List <FootHold.Foothold>();
            List <Portals.Portal>        Ps   = new List <Portals.Portal>();
            Size  bmpSize;
            Point center;

            WzSubProperty miniMapSubProperty = ((WzSubProperty)img["miniMap"]);

            try
            {
                bmpSize = new Size(((WzIntProperty)miniMapSubProperty["width"]).Value, ((WzIntProperty)miniMapSubProperty["height"]).Value);
                center  = new Point(((WzIntProperty)miniMapSubProperty["centerX"]).Value, ((WzIntProperty)miniMapSubProperty["centerY"]).Value);
            }
            catch (Exception exp)
            {
                if (exp is KeyNotFoundException || exp is NullReferenceException)
                {
                    try
                    {
                        WzSubProperty infoSubProperty = ((WzSubProperty)img["info"]);

                        bmpSize = new Size(((WzIntProperty)infoSubProperty["VRRight"]).Value - ((WzIntProperty)infoSubProperty["VRLeft"]).Value, ((WzIntProperty)infoSubProperty["VRBottom"]).Value - ((WzIntProperty)infoSubProperty["VRTop"]).Value);
                        center  = new Point(((WzIntProperty)infoSubProperty["VRRight"]).Value, ((WzIntProperty)infoSubProperty["VRBottom"]).Value);
                    }
                    catch
                    {
                        errorList.Add("Missing map info WzSubProperty. Path: " + mapIdName + ".img/info/VRRight; VRLeft; VRBottom; VRTop\r\n OR info/miniMap/width ; height; centerX; centerY");
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            // Render minimap
            Bitmap minimapRender = RenderMinimap(bmpSize, wzFile, img, mapIdName, miniMapSubProperty);

            // Render map
            Bitmap mapRender = new Bitmap(bmpSize.Width, bmpSize.Height);

            using (Graphics drawBuf = Graphics.FromImage(mapRender))
            {
                WzSubProperty ps = (WzSubProperty)img["portal"];
                foreach (WzSubProperty p in ps.WzProperties)
                {
                    //WzSubProperty p = (WzSubProperty)p10.ExtendedProperty;
                    int    x  = ((WzIntProperty)p["x"]).Value + center.X;
                    int    y  = ((WzIntProperty)p["y"]).Value + center.Y;
                    int    pt = ((WzIntProperty)p["pt"]).Value;
                    string pn = ((WzStringProperty)p["pn"]).ReadString(string.Empty);
                    int    tm = ((WzIntProperty)p["tm"]).ReadValue(999999999);

                    Color pColor = Color.Red;
                    if (pt == 0)
                    {
                        pColor = Color.Orange;
                    }
                    else if (pt == 2 || pt == 7)//Normal
                    {
                        pColor = Color.Blue;
                    }
                    else if (pt == 3)//Auto-enter
                    {
                        pColor = Color.Magenta;
                    }
                    else if (pt == 1 || pt == 8)
                    {
                        pColor = Color.BlueViolet;
                    }
                    else
                    {
                        pColor = Color.IndianRed;
                    }

                    // Draw portal preview image
                    bool drewPortalImg = false;
                    if (pn != string.Empty || pt == 2)
                    {
                        string           portalEditorImage  = wzFile.WzDirectory.Name + "/MapHelper.img/portal/editor/" + (pt == 2 ? "pv" : pn);
                        WzCanvasProperty portalEditorCanvas = (WzCanvasProperty)wzFile.GetObjectFromPath(portalEditorImage);
                        if (portalEditorCanvas != null)
                        {
                            drewPortalImg = true;

                            PointF canvasOriginPosition = portalEditorCanvas.GetCanvasVectorPosition();
                            drawBuf.DrawImage(portalEditorCanvas.GetLinkedWzCanvasBitmap(), x - canvasOriginPosition.X, y - canvasOriginPosition.Y);
                        }
                    }
                    if (!drewPortalImg)
                    {
                        drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, pColor.R, pColor.G, pColor.B)), x - 20, y - 20, 40, 40);
                        drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x - 20, y - 20, 40, 40);
                    }

                    // Draw portal name
                    drawBuf.DrawString("Portal: " + p.Name, FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Red), x - 8, y - 7.7F);

                    Portals.Portal portal = new Portals.Portal();
                    portal.Shape = new Rectangle(x - 20, y - 20, 40, 40);
                    portal.Data  = p;
                    Ps.Add(portal);
                }

                WzSubProperty SPs = (WzSubProperty)img["life"];
                foreach (WzSubProperty sp in SPs.WzProperties)
                {
                    Color MSPColor = Color.ForestGreen;

                    string type = ((WzStringProperty)sp["type"]).Value;
                    switch (type)
                    {
                    case "n":     // NPC
                    case "m":     // monster
                    {
                        bool isNPC  = type == "n";
                        int  lifeId = int.Parse(((WzStringProperty)sp["id"]).GetString());

                        int  x          = ((WzIntProperty)sp["x"]).Value + center.X;
                        int  y          = ((WzIntProperty)sp["y"]).Value + center.Y;
                        int  x_text     = x - 15;
                        int  y_text     = y - 15;
                        bool facingLeft = ((WzIntProperty)sp["f"]).ReadValue(0) == 0;         // This value is optional. If its not stated in the WZ, its assumed to be 0

                        SpawnPoint.Spawnpoint MSP = new SpawnPoint.Spawnpoint();
                        MSP.Shape = new Rectangle(x_text, y_text, 30, 30);
                        MSP.Data  = sp;
                        MSPs.Add(MSP);


                        // Render monster image
                        string lifeStrId = lifeId.ToString().PadLeft(7, '0');

                        string mobWzPath;
                        string mobLinkWzPath;
                        string mobNamePath;

                        if (!isNPC)
                        {
                            mobWzPath   = string.Format("Mob.wz/{0}.img/info/link", lifeStrId);
                            mobNamePath = string.Format("String.wz/Mob.img/{0}/name", lifeId);
                        }
                        else
                        {
                            mobWzPath   = string.Format("Npc.wz/{0}.img/info/link", lifeStrId);
                            mobNamePath = string.Format("String.wz/Npc.img/{0}/name", lifeId);
                        }

                        WzStringProperty linkInfo = (WzStringProperty)WzFile.GetObjectFromMultipleWzFilePath(mobWzPath, Program.WzMan.WzFileListReadOnly);
                        if (linkInfo != null)
                        {
                            lifeId    = int.Parse(linkInfo.GetString());
                            lifeStrId = lifeId.ToString().PadLeft(7, '0');
                        }

                        if (!isNPC)
                        {
                            mobLinkWzPath = string.Format("Mob.wz/{0}.img/stand/0", lifeStrId);
                        }
                        else
                        {
                            mobLinkWzPath = string.Format("Npc.wz/{0}.img/stand/0", lifeStrId);
                        }

                        WzCanvasProperty lifeImg = (WzCanvasProperty)WzFile.GetObjectFromMultipleWzFilePath(mobLinkWzPath, Program.WzMan.WzFileListReadOnly);
                        if (lifeImg != null)
                        {
                            PointF canvasOriginPosition = lifeImg.GetCanvasVectorPosition();
                            PointF renderXY             = new PointF(x - canvasOriginPosition.X, y - canvasOriginPosition.Y);

                            Bitmap renderMobbitmap = lifeImg.GetLinkedWzCanvasBitmap();

                            if (!facingLeft)
                            {
                                renderMobbitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
                            }

                            drawBuf.DrawImage(renderMobbitmap, renderXY);
                        }
                        else
                        {
                            //drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, MSPColor.R, MSPColor.G, MSPColor.B)), x_text, y_text, 30, 30);
                            //drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x_text, y_text, 30, 30);
                            errorList.Add("Missing monster/npc object. Path: " + mobWzPath + "\r\n" + mobLinkWzPath);
                        }

                        // Get monster name
                        WzStringProperty stringName = (WzStringProperty)WzFile.GetObjectFromMultipleWzFilePath(mobNamePath, Program.WzMan.WzFileListReadOnly);
                        if (stringName != null)
                        {
                            drawBuf.DrawString(string.Format("SP: {0}, Name: {1}, ID: {2}", sp.Name, stringName.GetString(), lifeId), FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Red), x_text + 7, y_text + 7.3F);
                        }
                        else
                        {
                            errorList.Add("Missing monster/npc string object. Path: " + mobNamePath);
                        }
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }


                WzSubProperty fhs = (WzSubProperty)img["foothold"];
                foreach (WzImageProperty fhspl0 in fhs.WzProperties)
                {
                    foreach (WzImageProperty fhspl1 in fhspl0.WzProperties)
                    {
                        Color c = Color.FromArgb(95, Color.FromArgb(GetPseudoRandomColor(fhspl1.Name)));
                        foreach (WzSubProperty fh in fhspl1.WzProperties)
                        {
                            int x      = ((WzIntProperty)fh["x1"]).Value + center.X;
                            int y      = ((WzIntProperty)fh["y1"]).Value + center.Y;
                            int width  = ((((WzIntProperty)fh["x2"]).Value + center.X) - x);
                            int height = ((((WzIntProperty)fh["y2"]).Value + center.Y) - y);

                            if (width < 0)
                            {
                                x    += width;// *2;
                                width = -width;
                            }
                            if (height < 0)
                            {
                                y     += height;// *2;
                                height = -height;
                            }
                            if (width == 0 || width < 15)
                            {
                                width = 15;
                            }
                            height += 10;

                            FootHold.Foothold nFH = new FootHold.Foothold();
                            nFH.Shape = new Rectangle(x, y, width, height);
                            nFH.Data  = fh;
                            FHs.Add(nFH);

                            //drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, Color.Gray.R, Color.Gray.G, Color.Gray.B)), x, y, width, height);
                            drawBuf.FillRectangle(new SolidBrush(c), x, y, width, height);
                            drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x, y, width, height);
                            drawBuf.DrawString(fh.Name, FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Red), new PointF(x + (width / 2) - 8, y + (height / 2) - 7.7F));
                        }
                    }
                }
            }
            mapRender.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_footholdRender.bmp");

            Bitmap backgroundRender = new Bitmap(bmpSize.Width, bmpSize.Height);

            using (Graphics tileBuf = Graphics.FromImage(backgroundRender))
            {
                WzSubProperty backImg = (WzSubProperty)img["back"];
                if (backImg != null)
                {
                    foreach (WzSubProperty bgItem in backImg.WzProperties)
                    {
                        string bS         = ((WzStringProperty)bgItem["bS"]).Value;
                        int    front      = ((WzIntProperty)bgItem["front"]).Value;
                        int    ani        = ((WzIntProperty)bgItem["ani"]).Value;
                        int    no         = ((WzIntProperty)bgItem["no"]).Value;
                        int    x          = ((WzIntProperty)bgItem["x"]).Value;
                        int    y          = ((WzIntProperty)bgItem["y"]).Value;
                        int    rx         = ((WzIntProperty)bgItem["rx"]).Value;
                        int    ry         = ((WzIntProperty)bgItem["ry"]).Value;
                        int    type       = ((WzIntProperty)bgItem["type"]).Value;
                        int    cx         = ((WzIntProperty)bgItem["cx"]).Value;
                        int    cy         = ((WzIntProperty)bgItem["cy"]).Value;
                        int    a          = ((WzIntProperty)bgItem["a"]).Value;
                        bool   facingLeft = ((WzIntProperty)bgItem["f"]).ReadValue(0) == 0;

                        if (bS == string.Empty)
                        {
                            continue;
                        }

                        string           bgObjImagePath = "Map.wz/Back/" + bS + ".img/Back/" + no;
                        WzCanvasProperty wzBgCanvas     = (WzCanvasProperty)WzFile.GetObjectFromMultipleWzFilePath(bgObjImagePath, Program.WzMan.WzFileListReadOnly);
                        if (wzBgCanvas != null)
                        {
                            PointF canvasOriginPosition = wzBgCanvas.GetCanvasVectorPosition();
                            PointF renderXY             = new PointF(x + canvasOriginPosition.X + center.X, y + canvasOriginPosition.X + center.Y);

                            Bitmap drawImage = wzBgCanvas.GetLinkedWzCanvasBitmap();

                            if (!facingLeft)
                            {
                                drawImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
                            }

                            tileBuf.DrawImage(drawImage, renderXY);
                        }
                        else
                        {
                            errorList.Add("Missing Map BG object. Path: " + bgObjImagePath);
                        }
                    }
                }
            }
            backgroundRender.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_backgroundRender.bmp");


            // Render tooltip
            WzSubProperty tooltipProperty = (WzSubProperty)img["ToolTip"];
            Bitmap        toolTip         = null;

            if (tooltipProperty != null)
            {
                toolTip = new Bitmap(bmpSize.Width, bmpSize.Height);
                using (Graphics toolTipBuf = Graphics.FromImage(toolTip))
                {
                    string        stringTooltipPath = "String.wz/ToolTipHelp.img/Mapobject/" + mapIdName;
                    WzSubProperty wzToolTip         = (WzSubProperty)WzFile.GetObjectFromMultipleWzFilePath(stringTooltipPath, Program.WzMan.WzFileListReadOnly);

                    if (wzToolTip == null)
                    {
                        errorList.Add("Map tooltip object is missing. Path: " + stringTooltipPath);
                    }

                    for (int i = 0; i < 99; i++) // starts from 0
                    {
                        WzSubProperty toolTipItem = (WzSubProperty)tooltipProperty[i.ToString()];
                        if (toolTipItem == null)
                        {
                            break;
                        }

                        int x1 = toolTipItem["x1"].ReadValue();
                        int x2 = toolTipItem["x2"].ReadValue();
                        int y1 = toolTipItem["y1"].ReadValue();
                        int y2 = toolTipItem["y2"].ReadValue();

                        // Check String.wz
                        WzSubProperty wzToolTipForI = (WzSubProperty)wzToolTip[i.ToString()];
                        if (wzToolTipForI == null)
                        {
                            errorList.Add("Map tooltip is missing. Path: " + stringTooltipPath + "/" + i);
                        }
                        string title = wzToolTipForI["Title"].ReadString(null);
                        string desc  = wzToolTipForI["Desc"].ReadString(null);

                        if (title == null)
                        {
                            errorList.Add("Map tooltip is missing. Path: " + stringTooltipPath + "/" + i + "/Title");
                        }
                        toolTipBuf.DrawString(string.Format("{0}\n{1}", title, desc == null ? string.Empty : desc), FONT_GAME_TOOLTIP, new SolidBrush(Color.Black), new PointF(x1 + center.X, y1 + center.Y));
                    }
                }
                toolTip.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_tooltip.bmp");
            }

            // Render Tiles
            Bitmap tileRender = new Bitmap(bmpSize.Width, bmpSize.Height);

            using (Graphics tileBuf = Graphics.FromImage(tileRender))
            {
                for (int i = 0; i < 7; i++)
                {
                    // The below code was commented out because it was creating problems when loading certain maps. When debugging it would throw an exception at line 469.
                    // Objects first
                    WzSubProperty iProperty      = (WzSubProperty)img[i.ToString()];
                    WzSubProperty objProperties  = ((WzSubProperty)iProperty["obj"]);
                    WzSubProperty infoProperties = ((WzSubProperty)iProperty["info"]);
                    WzSubProperty tileProperties = ((WzSubProperty)iProperty["tile"]);

                    if (objProperties.WzProperties.Count > 0)
                    {
                        foreach (WzSubProperty obj in objProperties.WzProperties)
                        {
                            //WzSubProperty obj = (WzSubProperty)oe.ExtendedProperty;
                            string imgName = ((WzStringProperty)obj["oS"]).Value + ".img";
                            string l0      = ((WzStringProperty)obj["l0"]).Value;
                            string l1      = ((WzStringProperty)obj["l1"]).Value;
                            string l2      = ((WzStringProperty)obj["l2"]).Value;
                            int    x       = ((WzIntProperty)obj["x"]).Value + center.X;
                            int    y       = ((WzIntProperty)obj["y"]).Value + center.Y;

                            PointF           origin;
                            WzCanvasProperty png;

                            string imgObjPath = string.Format("{0}/Obj/{1}/{2}/{3}/{4}/0", wzFile.WzDirectory.Name, imgName, l0, l1, l2);

                            WzImageProperty objData = (WzImageProperty)WzFile.GetObjectFromMultipleWzFilePath(imgObjPath, Program.WzMan.WzFileListReadOnly);
tryagain:
                            if (objData is WzCanvasProperty)
                            {
                                png    = ((WzCanvasProperty)objData);
                                origin = ((WzCanvasProperty)objData).GetCanvasVectorPosition();
                            }
                            else if (objData is WzUOLProperty)
                            {
                                WzObject currProp = objData.Parent;
                                foreach (string directive in ((WzUOLProperty)objData).Value.Split("/".ToCharArray()))
                                {
                                    if (directive == "..")
                                    {
                                        currProp = currProp.Parent;
                                    }
                                    else
                                    {
                                        if (currProp.GetType() == typeof(WzSubProperty))
                                        {
                                            currProp = ((WzSubProperty)currProp)[directive];
                                        }
                                        else if (currProp.GetType() == typeof(WzCanvasProperty))
                                        {
                                            currProp = ((WzCanvasProperty)currProp)[directive];
                                        }
                                        else if (currProp.GetType() == typeof(WzImage))
                                        {
                                            currProp = ((WzImage)currProp)[directive];
                                        }
                                        else if (currProp.GetType() == typeof(WzConvexProperty))
                                        {
                                            currProp = ((WzConvexProperty)currProp)[directive];
                                        }
                                        else
                                        {
                                            errorList.Add("UOL error at map renderer");
                                            return(false);
                                        }
                                    }
                                }
                                objData = (WzImageProperty)currProp;
                                goto tryagain;
                            }
                            else
                            {
                                errorList.Add("Unknown Wz type at map renderer");
                                return(false);
                            }

                            //WzVectorProperty origin = (WzVectorProperty)wzFile.GetObjectFromPath(wzFile.WzDirectory.Name + "/Obj/" + imgName + "/" + l0 + "/" + l1 + "/" + l2 + "/0");
                            //WzPngProperty png = (WzPngProperty)wzFile.GetObjectFromPath(wzFile.WzDirectory.Name + "/Obj/" + imgName + "/" + l0 + "/" + l1 + "/" + l2 + "/0/PNG");
                            tileBuf.DrawImage(png.GetLinkedWzCanvasBitmap(), x - origin.X, y - origin.Y);
                        }
                    }
                    if (infoProperties.WzProperties.Count == 0)
                    {
                        continue;
                    }

                    if (tileProperties.WzProperties.Count == 0)
                    {
                        continue;
                    }

                    // Ok, we have some tiles and a tileset
                    string tileSetName = ((WzStringProperty)infoProperties["tS"]).Value;

                    // Browse to the tileset
                    string  tilePath = wzFile.WzDirectory.Name + "/Tile/" + tileSetName + ".img";
                    WzImage tileSet  = (WzImage)WzFile.GetObjectFromMultipleWzFilePath(tilePath, Program.WzMan.WzFileListReadOnly);
                    if (!tileSet.Parsed)
                    {
                        tileSet.ParseImage();
                    }

                    foreach (WzSubProperty tile in tileProperties.WzProperties)
                    {
                        //WzSubProperty tile = (WzSubProperty)te.ExtendedProperty;

                        int    x            = ((WzIntProperty)tile["x"]).Value + center.X;
                        int    y            = ((WzIntProperty)tile["y"]).Value + center.Y;
                        string tilePackName = ((WzStringProperty)tile["u"]).Value;
                        string tileID       = ((WzIntProperty)tile["no"]).Value.ToString();

                        WzSubProperty    tilePack   = ((WzSubProperty)tileSet[tilePackName]);
                        WzCanvasProperty tileCanvas = (WzCanvasProperty)tilePack[tileID];
                        if (tileCanvas == null)
                        {
                            errorList.Add(string.Format("Tile {0}, ID: {1} is not found.", tilePackName, tileID));
                        }
                        PointF tileVector = tileCanvas.GetCanvasVectorPosition();
                        tileBuf.DrawImage(tileCanvas.GetBitmap(), x - tileVector.X, y - tileVector.Y);
                    }
                }
            }
            tileRender.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_tileRender.bmp");

            // Render nodeInfo
            Bitmap        nodeInfoRender   = null;
            WzSubProperty nodeInfoProperty = (WzSubProperty)img["nodeInfo"];

            if (nodeInfoProperty != null)
            {
                nodeInfoRender = new Bitmap(bmpSize.Width, bmpSize.Height);
                using (Graphics nodeInfoBuffer = Graphics.FromImage(nodeInfoRender))
                {
                    int start = 0;
                    int end   = 0;

                    foreach (WzImageProperty nodeInfoImg in nodeInfoProperty.WzProperties)
                    {
                        switch (nodeInfoImg.Name)
                        {
                        case "edgeInfo":
                        {
                            break;
                        }

                        case "end":
                        {
                            end = ((WzIntProperty)nodeInfoImg).ReadValue();
                            break;
                        }

                        case "start":
                        {
                            start = ((WzIntProperty)nodeInfoImg).ReadValue();
                            break;
                        }

                        default:
                        {
                            int nodeInfoImgFileName = -1;
                            if (int.TryParse(nodeInfoImg.Name, out nodeInfoImgFileName))
                            {
                                int attr = ((WzIntProperty)nodeInfoImg["attr"]).ReadValue();
                                int key  = ((WzIntProperty)nodeInfoImg["key"]).ReadValue();
                                int x    = ((WzIntProperty)nodeInfoImg["x"]).ReadValue() + center.X;
                                int y    = ((WzIntProperty)nodeInfoImg["y"]).ReadValue() + center.Y;

                                List <int> edges = new List <int>();
                                foreach (WzImageProperty edge in nodeInfoImg["edge"].WzProperties)
                                {
                                    edges.Add(edge.ReadValue());
                                }

                                const int width  = 200;
                                const int height = 20;

                                nodeInfoBuffer.FillRectangle(new SolidBrush(Color.Wheat), x, y, width, height);
                                nodeInfoBuffer.DrawRectangle(new Pen(Color.Black, 1F), x, y, width, height);
                                nodeInfoBuffer.DrawString(
                                    string.Format("Key: {0}, x: {1}, y: {1}", key, x, y),
                                    FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Black), new PointF(x + (width / 2) - 8, y + (height / 2) - 7.7F));
                            }
                            break;
                        }
                        }
                    }
                }
                nodeInfoRender.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_nodeInfoRender.bmp");
            }


            // Render everything combined
            Bitmap fullBmp = new Bitmap(bmpSize.Width, bmpSize.Height + 10);

            using (Graphics fullBuf = Graphics.FromImage(fullBmp))
            {
                fullBuf.FillRectangle(new SolidBrush(Color.CornflowerBlue), 0, 0, bmpSize.Width, bmpSize.Height + 10);
                fullBuf.DrawImage(backgroundRender, 0, 0);
                fullBuf.DrawImage(tileRender, 0, 0);
                fullBuf.DrawImage(mapRender, 0, 0);
                if (toolTip != null)
                {
                    fullBuf.DrawImage(toolTip, 0, 0);
                }
                if (nodeInfoRender != null)
                {
                    fullBuf.DrawImage(nodeInfoRender, 0, 0);
                }
                fullBuf.DrawImage(minimapRender, 0, 0);
            }
            //pbx_Foothold_Render.Image = fullBmp;
            fullBmp.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_fullRender.bmp");

            // Cleanup resources
            backgroundRender.Dispose();
            tileRender.Dispose();
            mapRender.Dispose();
            toolTip?.Dispose();
            minimapRender.Dispose();

            if (errorList.Count() > 0)
            {
                return(false);
            }

            // Display render map
            DisplayMap showMap = new DisplayMap();

            showMap.map            = fullBmp;
            showMap.Footholds      = FHs;
            showMap.thePortals     = Ps;
            showMap.settings       = settings;
            showMap.MobSpawnPoints = MSPs;
            showMap.FormClosed    += new FormClosedEventHandler(DisplayMapClosed);
            try
            {
                showMap.scale = zoom;
                showMap.Show();
                return(true);
            }
            catch (FormatException)
            {
                MessageBox.Show("You must set the render scale to a valid number.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
        }
Exemplo n.º 24
0
        internal WzImageProperty ParsePropertyFromXMLElement(XmlElement element)
        {
            switch (element.Name)
            {
            case "imgdir":
                WzSubProperty sub = new WzSubProperty(element.GetAttribute("name"));
                foreach (XmlElement subelement in element)
                {
                    sub.AddProperty(ParsePropertyFromXMLElement(subelement));
                }
                return(sub);

            case "canvas":
                WzCanvasProperty canvas = new WzCanvasProperty(element.GetAttribute("name"));
                if (!element.HasAttribute("basedata"))
                {
                    throw new NoBase64DataException("no base64 data in canvas element with name " + canvas.Name);
                }
                canvas.PngProperty = new WzPngProperty();
                MemoryStream pngstream = new MemoryStream(Convert.FromBase64String(element.GetAttribute("basedata")));
                canvas.PngProperty.SetPNG((Bitmap)Image.FromStream(pngstream, true, true));
                foreach (XmlElement subelement in element)
                {
                    canvas.AddProperty(ParsePropertyFromXMLElement(subelement));
                }
                return(canvas);

            case "int":
                WzIntProperty compressedInt = new WzIntProperty(element.GetAttribute("name"), int.Parse(element.GetAttribute("value"), formattingInfo));
                return(compressedInt);

            case "double":
                WzDoubleProperty doubleProp = new WzDoubleProperty(element.GetAttribute("name"), double.Parse(element.GetAttribute("value"), formattingInfo));
                return(doubleProp);

            case "null":
                WzNullProperty nullProp = new WzNullProperty(element.GetAttribute("name"));
                return(nullProp);

            case "sound":
                if (!element.HasAttribute("basedata") || !element.HasAttribute("basehead") || !element.HasAttribute("length"))
                {
                    throw new NoBase64DataException("no base64 data in sound element with name " + element.GetAttribute("name"));
                }
                WzSoundProperty sound = new WzSoundProperty(element.GetAttribute("name"),
                                                            int.Parse(element.GetAttribute("length")),
                                                            Convert.FromBase64String(element.GetAttribute("basehead")),
                                                            Convert.FromBase64String(element.GetAttribute("basedata")));
                return(sound);

            case "string":
                WzStringProperty stringProp = new WzStringProperty(element.GetAttribute("name"), element.GetAttribute("value"));
                return(stringProp);

            case "short":
                WzShortProperty shortProp = new WzShortProperty(element.GetAttribute("name"), short.Parse(element.GetAttribute("value"), formattingInfo));
                return(shortProp);

            case "long":
                WzLongProperty longProp = new WzLongProperty(element.GetAttribute("name"), long.Parse(element.GetAttribute("value"), formattingInfo));
                return(longProp);

            case "uol":
                WzUOLProperty uol = new WzUOLProperty(element.GetAttribute("name"), element.GetAttribute("value"));
                return(uol);

            case "vector":
                WzVectorProperty vector = new WzVectorProperty(element.GetAttribute("name"), new WzIntProperty("x", Convert.ToInt32(element.GetAttribute("x"))), new WzIntProperty("y", Convert.ToInt32(element.GetAttribute("y"))));
                return(vector);

            case "float":
                WzFloatProperty floatProp = new WzFloatProperty(element.GetAttribute("name"), float.Parse(element.GetAttribute("value"), formattingInfo));
                return(floatProp);

            case "extended":
                WzConvexProperty convex = new WzConvexProperty(element.GetAttribute("name"));
                foreach (XmlElement subelement in element)
                {
                    convex.AddProperty(ParsePropertyFromXMLElement(subelement));
                }
                return(convex);
            }
            throw new InvalidDataException("unknown XML prop " + element.Name);
        }
Exemplo n.º 25
0
 /// <summary>
 /// SpineAnimationItem Constructor
 /// </summary>
 /// <param name="wzSpineAtlasPropertyNode">.atlas WzStringProperty</param>
 /// <param name="loadWithJson"></param>
 public WzSpineAnimationItem(WzStringProperty wzSpineAtlasPropertyNode)
 {
     this.wzSpineAtlasPropertyNode = wzSpineAtlasPropertyNode;
 }
Exemplo n.º 26
0
 protected void WritePropertyToXML(TextWriter tw, string depth, WzImageProperty prop)
 {
     if (prop is WzCanvasProperty)
     {
         WzCanvasProperty property3 = (WzCanvasProperty)prop;
         if (ExportBase64Data)
         {
             MemoryStream stream = new MemoryStream();
             property3.PngProperty.GetPNG(false).Save(stream, System.Drawing.Imaging.ImageFormat.Png);
             byte[] pngbytes = stream.ToArray();
             stream.Close();
             tw.Write(string.Concat(new object[] { depth, "<canvas name=\"", XmlUtil.SanitizeText(property3.Name), "\" width=\"", property3.PngProperty.Width, "\" height=\"", property3.PngProperty.Height, "\" basedata=\"", Convert.ToBase64String(pngbytes), "\">" }) + lineBreak);
         }
         else
         {
             tw.Write(string.Concat(new object[] { depth, "<canvas name=\"", XmlUtil.SanitizeText(property3.Name), "\" width=\"", property3.PngProperty.Width, "\" height=\"", property3.PngProperty.Height, "\">" }) + lineBreak);
         }
         string newDepth = depth + indent;
         foreach (WzImageProperty property in property3.WzProperties)
         {
             WritePropertyToXML(tw, newDepth, property);
         }
         tw.Write(depth + "</canvas>" + lineBreak);
     }
     else if (prop is WzIntProperty)
     {
         WzIntProperty property4 = (WzIntProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<int name=\"", XmlUtil.SanitizeText(property4.Name), "\" value=\"", property4.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzDoubleProperty)
     {
         WzDoubleProperty property5 = (WzDoubleProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<double name=\"", XmlUtil.SanitizeText(property5.Name), "\" value=\"", property5.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzNullProperty)
     {
         WzNullProperty property6 = (WzNullProperty)prop;
         tw.Write(depth + "<null name=\"" + XmlUtil.SanitizeText(property6.Name) + "\"/>" + lineBreak);
     }
     else if (prop is WzSoundProperty)
     {
         WzSoundProperty property7 = (WzSoundProperty)prop;
         if (ExportBase64Data)
         {
             tw.Write(string.Concat(new object[] { depth, "<sound name=\"", XmlUtil.SanitizeText(property7.Name), "\" length=\"", property7.Length.ToString(), "\" basehead=\"", Convert.ToBase64String(property7.Header), "\" basedata=\"", Convert.ToBase64String(property7.GetBytes(false)), "\"/>" }) + lineBreak);
         }
         else
         {
             tw.Write(depth + "<sound name=\"" + XmlUtil.SanitizeText(property7.Name) + "\"/>" + lineBreak);
         }
     }
     else if (prop is WzStringProperty)
     {
         WzStringProperty property8 = (WzStringProperty)prop;
         string           str       = XmlUtil.SanitizeText(property8.Value);
         tw.Write(depth + "<string name=\"" + XmlUtil.SanitizeText(property8.Name) + "\" value=\"" + str + "\"/>" + lineBreak);
     }
     else if (prop is WzSubProperty)
     {
         WzSubProperty property9 = (WzSubProperty)prop;
         tw.Write(depth + "<imgdir name=\"" + XmlUtil.SanitizeText(property9.Name) + "\">" + lineBreak);
         string newDepth = depth + indent;
         foreach (WzImageProperty property in property9.WzProperties)
         {
             WritePropertyToXML(tw, newDepth, property);
         }
         tw.Write(depth + "</imgdir>" + lineBreak);
     }
     else if (prop is WzShortProperty)
     {
         WzShortProperty property10 = (WzShortProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<short name=\"", XmlUtil.SanitizeText(property10.Name), "\" value=\"", property10.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzLongProperty)
     {
         WzLongProperty long_prop = (WzLongProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<long name=\"", XmlUtil.SanitizeText(long_prop.Name), "\" value=\"", long_prop.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzUOLProperty)
     {
         WzUOLProperty property11 = (WzUOLProperty)prop;
         tw.Write(depth + "<uol name=\"" + property11.Name + "\" value=\"" + XmlUtil.SanitizeText(property11.Value) + "\"/>" + lineBreak);
     }
     else if (prop is WzVectorProperty)
     {
         WzVectorProperty property12 = (WzVectorProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<vector name=\"", XmlUtil.SanitizeText(property12.Name), "\" x=\"", property12.X.Value, "\" y=\"", property12.Y.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzFloatProperty)
     {
         WzFloatProperty property13 = (WzFloatProperty)prop;
         string          str2       = Convert.ToString(property13.Value, formattingInfo);
         if (!str2.Contains("."))
         {
             str2 = str2 + ".0";
         }
         tw.Write(depth + "<float name=\"" + XmlUtil.SanitizeText(property13.Name) + "\" value=\"" + str2 + "\"/>" + lineBreak);
     }
     else if (prop is WzConvexProperty)
     {
         tw.Write(depth + "<extended name=\"" + XmlUtil.SanitizeText(prop.Name) + "\">" + lineBreak);
         WzConvexProperty property14 = (WzConvexProperty)prop;
         string           newDepth   = depth + indent;
         foreach (WzImageProperty property in property14.WzProperties)
         {
             WritePropertyToXML(tw, newDepth, property);
         }
         tw.Write(depth + "</extended>" + lineBreak);
     }
 }
Exemplo n.º 27
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (method == 0)
            {
                switch (data.GetType().Name)
                {
                case "WzDirectory":
                    ((WzDirectory)data).Name = textBox1.Text;
                    break;

                case "WzImage":
                    ((WzImage)data).Name    = textBox1.Text;
                    ((WzImage)data).changed = true;
                    tree.Text = textBox1.Text;
                    Close();
                    return;

                case "WzSubProperty":
                    ((WzSubProperty)data).Name = textBox1.Text;
                    break;

                case "WzCompressedIntProperty":
                    ((WzCompressedIntProperty)data).Name  = textBox1.Text;
                    ((WzCompressedIntProperty)data).Value = Convert.ToInt32(textBox2.Text);
                    break;

                case "WzCanvasProperty":
                    if (((WzCanvasProperty)data).PngProperty == null)
                    {
                        ((WzCanvasProperty)data).PngProperty = new WzPngProperty();
                    }
                    ((WzCanvasProperty)data).PngProperty.Name   = textBox1.Text;
                    ((WzCanvasProperty)data).PngProperty.Height = pictureBox1.Image.Height;
                    ((WzCanvasProperty)data).PngProperty.Width  = pictureBox1.Image.Width;
                    ((WzCanvasProperty)data).PngProperty.PNG    = (Bitmap)pictureBox1.Image;
                    break;

                case "WzVectorProperty":
                    ((WzVectorProperty)data).Name    = textBox1.Text;
                    ((WzVectorProperty)data).X.Value = Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[0]);
                    ((WzVectorProperty)data).Y.Value = Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[1]);
                    break;

                case "WzStringProperty":
                    ((WzStringProperty)data).Name  = textBox1.Text;
                    ((WzStringProperty)data).Value = textBox2.Text;
                    break;

                case "WzUOLProperty":
                    ((WzUOLProperty)data).Name  = textBox1.Text;
                    ((WzUOLProperty)data).Value = textBox2.Text;
                    break;

                case "WzDoubleProperty":
                    ((WzDoubleProperty)data).Name  = textBox1.Text;
                    ((WzDoubleProperty)data).Value = Convert.ToDouble(textBox2.Text);
                    break;

                case "WzByteFloatProperty":
                    ((WzByteFloatProperty)data).Name  = textBox1.Text;
                    ((WzByteFloatProperty)data).Value = Convert.ToSingle(textBox2.Text);
                    break;

                case "WzSoundProperty":
                    ((WzSoundProperty)data).Name = textBox1.Text;
                    FileStream readmp3 = File.OpenRead(textBox2.Text);
                    byte[]     mpd     = new byte[readmp3.Length];
                    readmp3.Read(mpd, 0, (int)readmp3.Length);
                    ((WzSoundProperty)data).SoundData = mpd;
                    readmp3.Close();
                    break;

                case "WzConvexProperty":
                    ((WzConvexProperty)data).Name = textBox1.Text;
                    break;

                case "WzUnsignedShortProperty":
                    ((WzUnsignedShortProperty)data).Name  = textBox1.Text;
                    ((WzUnsignedShortProperty)data).Value = Convert.ToUInt16(textBox2.Text);
                    break;

                default:
                    break;
                }
                tree.Text = textBox1.Text;
                ((IWzImageProperty)data).ParentImage.changed = true;
                Close();
            }
            else if (method == 1)
            {
                switch (data.GetType().Name)
                {
                case "WzDirectory":
                    switch (comboBox1.SelectedIndex)
                    {
                    case 0:
                        WzDirectory dir = new WzDirectory(textBox1.Text);
                        ((WzDirectory)data).AddDirectory(dir);
                        tree.Nodes.Add(textBox1.Text).Tag = dir;
                        break;

                    case 1:
                        WzImage img = new WzImage(textBox1.Text);
                        ((WzDirectory)data).AddImage(img);
                        tree.Nodes.Add(textBox1.Text).Tag = img;
                        img.changed = true;
                        break;
                    }
                    Close();
                    return;

                    break;

                case "WzImage":
                    switch (comboBox1.SelectedIndex)
                    {
                    case 0:
                        WzCompressedIntProperty integer = new WzCompressedIntProperty(textBox1.Text, Convert.ToInt32(textBox2.Text));
                        ((WzImage)data).AddProperty(integer);
                        tree.Nodes.Add(textBox1.Text).Tag = integer;
                        break;

                    case 1:
                        WzCanvasProperty png = new WzCanvasProperty(textBox1.Text);
                        (png.PngProperty = new WzPngProperty()).PNG = (Bitmap)pictureBox1.Image;
                        png.PngProperty.Height = pictureBox1.Image.Height;
                        png.PngProperty.Width  = pictureBox1.Image.Width;
                        ((WzImage)data).AddProperty(png);
                        tree.Nodes.Add(textBox1.Text).Tag = png;
                        break;

                    case 2:
                        WzVectorProperty vector = new WzVectorProperty(textBox1.Text, new WzCompressedIntProperty("X", Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[0])), new WzCompressedIntProperty("Y", Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[1])));
                        ((WzImage)data).AddProperty(vector);
                        tree.Nodes.Add(textBox1.Text).Tag = vector;
                        break;

                    case 3:
                        WzStringProperty str = new WzStringProperty(textBox1.Text, textBox2.Text);
                        ((WzImage)data).AddProperty(str);
                        tree.Nodes.Add(textBox1.Text).Tag = str;
                        break;

                    case 4:
                        WzUOLProperty uol = new WzUOLProperty(textBox1.Text, textBox2.Text);
                        ((WzImage)data).AddProperty(uol);
                        tree.Nodes.Add(textBox1.Text).Tag = uol;
                        break;

                    case 5:
                        WzDoubleProperty dou = new WzDoubleProperty(textBox1.Text, Convert.ToDouble(textBox2.Text));
                        ((WzImage)data).AddProperty(dou);
                        tree.Nodes.Add(textBox1.Text).Tag = dou;
                        break;

                    case 6:
                        WzByteFloatProperty flo = new WzByteFloatProperty(textBox1.Text, Convert.ToSingle(textBox2.Text));
                        ((WzImage)data).AddProperty(flo);
                        tree.Nodes.Add(textBox1.Text).Tag = flo;
                        break;

                    case 7:
                        WzSubProperty sub = new WzSubProperty(textBox1.Text);
                        ((WzImage)data).AddProperty(sub);
                        tree.Nodes.Add(textBox1.Text).Tag = sub;
                        break;

                    case 8:
                        WzSoundProperty mps       = new WzSoundProperty(textBox1.Text);
                        FileStream      readsound = File.OpenRead(textBox2.Text);
                        byte[]          mpdata    = new byte[readsound.Length];
                        readsound.Read(mpdata, 0, (int)readsound.Length);
                        mps.SoundData = mpdata;
                        ((WzImage)data).AddProperty(mps);
                        tree.Nodes.Add(textBox1.Text).Tag = mps;
                        readsound.Close();
                        break;

                    case 9:
                        WzConvexProperty convex = new WzConvexProperty(textBox1.Text);
                        ((WzImage)data).AddProperty(convex);
                        tree.Nodes.Add(textBox1.Text).Tag = convex;
                        break;

                    case 10:
                        WzUnsignedShortProperty us = new WzUnsignedShortProperty(textBox1.Text, Convert.ToUInt16(textBox2.Text));
                        ((WzImage)data).AddProperty(us);
                        tree.Nodes.Add(textBox1.Text).Tag = us;
                        break;

                    default:
                        break;
                    }
                    break;

                case "WzSubProperty":
                    switch (comboBox1.SelectedIndex)
                    {
                    case 0:
                        WzCompressedIntProperty integer = new WzCompressedIntProperty(textBox1.Text, Convert.ToInt32(textBox2.Text));
                        ((WzSubProperty)data).AddProperty(integer);
                        tree.Nodes.Add(textBox1.Text).Tag = integer;
                        break;

                    case 1:
                        WzCanvasProperty png = new WzCanvasProperty(textBox1.Text);
                        (png.PngProperty = new WzPngProperty()).PNG = (Bitmap)pictureBox1.Image;
                        png.PngProperty.Height = pictureBox1.Image.Height;
                        png.PngProperty.Width  = pictureBox1.Image.Width;
                        ((WzSubProperty)data).AddProperty(png);
                        tree.Nodes.Add(textBox1.Text).Tag = png;
                        break;

                    case 2:
                        WzVectorProperty vector = new WzVectorProperty(textBox1.Text, new WzCompressedIntProperty("X", Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[0])), new WzCompressedIntProperty("Y", Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[1])));
                        ((WzSubProperty)data).AddProperty(vector);
                        tree.Nodes.Add(textBox1.Text).Tag = vector;
                        break;

                    case 3:
                        WzStringProperty str = new WzStringProperty(textBox1.Text, textBox2.Text);
                        ((WzSubProperty)data).AddProperty(str);
                        tree.Nodes.Add(textBox1.Text).Tag = str;
                        break;

                    case 4:
                        WzUOLProperty uol = new WzUOLProperty(textBox1.Text, textBox2.Text);
                        ((WzSubProperty)data).AddProperty(uol);
                        tree.Nodes.Add(textBox1.Text).Tag = uol;
                        break;

                    case 5:
                        WzDoubleProperty dou = new WzDoubleProperty(textBox1.Text, Convert.ToDouble(textBox2.Text));
                        ((WzSubProperty)data).AddProperty(dou);
                        tree.Nodes.Add(textBox1.Text).Tag = dou;
                        break;

                    case 6:
                        WzByteFloatProperty flo = new WzByteFloatProperty(textBox1.Text, Convert.ToSingle(textBox2.Text));
                        ((WzSubProperty)data).AddProperty(flo);
                        tree.Nodes.Add(textBox1.Text).Tag = flo;
                        break;

                    case 7:
                        WzSubProperty sub = new WzSubProperty(textBox1.Text);
                        ((WzSubProperty)data).AddProperty(sub);
                        tree.Nodes.Add(textBox1.Text).Tag = sub;
                        break;

                    case 8:
                        WzSoundProperty mps       = new WzSoundProperty(textBox1.Text);
                        FileStream      readsound = File.OpenRead(textBox2.Text);
                        byte[]          mpdata    = new byte[readsound.Length];
                        readsound.Read(mpdata, 0, (int)readsound.Length);
                        mps.SoundData = mpdata;
                        ((WzSubProperty)data).AddProperty(mps);
                        tree.Nodes.Add(textBox1.Text).Tag = mps;
                        readsound.Close();
                        break;

                    case 9:
                        WzConvexProperty convex = new WzConvexProperty(textBox1.Text);
                        ((WzSubProperty)data).AddProperty(convex);
                        tree.Nodes.Add(textBox1.Text).Tag = convex;
                        break;

                    case 10:
                        WzUnsignedShortProperty us = new WzUnsignedShortProperty(textBox1.Text, Convert.ToUInt16(textBox2.Text));
                        ((WzSubProperty)data).AddProperty(us);
                        tree.Nodes.Add(textBox1.Text).Tag = us;
                        break;

                    default:
                        break;
                    }
                    break;

                case "WzCanvasProperty":
                    WzCanvasProperty canvas = (WzCanvasProperty)data;
                    switch (comboBox1.SelectedIndex)
                    {
                    case 0:
                        WzCompressedIntProperty integer = new WzCompressedIntProperty(textBox1.Text, Convert.ToInt32(textBox2.Text));
                        canvas.AddProperty(integer);
                        tree.Nodes.Add(textBox1.Text).Tag = integer;
                        break;

                    case 1:
                        WzCanvasProperty png = new WzCanvasProperty(textBox1.Text);
                        png.PngProperty.PNG    = (Bitmap)pictureBox1.Image;
                        png.PngProperty.Height = pictureBox1.Image.Height;
                        png.PngProperty.Width  = pictureBox1.Image.Width;
                        canvas.AddProperty(png);
                        tree.Nodes.Add(textBox1.Text).Tag = png;
                        break;

                    case 2:
                        WzVectorProperty vector = new WzVectorProperty(textBox1.Text, new WzCompressedIntProperty("X", Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[0])), new WzCompressedIntProperty("Y", Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[1])));
                        canvas.AddProperty(vector);
                        tree.Nodes.Add(textBox1.Text).Tag = vector;
                        break;

                    case 3:
                        WzStringProperty str = new WzStringProperty(textBox1.Text, textBox2.Text);
                        canvas.AddProperty(str);
                        tree.Nodes.Add(textBox1.Text).Tag = str;
                        break;

                    case 4:
                        WzUOLProperty uol = new WzUOLProperty(textBox1.Text, textBox2.Text);
                        canvas.AddProperty(uol);
                        tree.Nodes.Add(textBox1.Text).Tag = uol;
                        break;

                    case 5:
                        WzDoubleProperty dou = new WzDoubleProperty(textBox1.Text, Convert.ToDouble(textBox2.Text));
                        canvas.AddProperty(dou);
                        tree.Nodes.Add(textBox1.Text).Tag = dou;
                        break;

                    case 6:
                        WzByteFloatProperty flo = new WzByteFloatProperty(textBox1.Text, Convert.ToSingle(textBox2.Text));
                        canvas.AddProperty(flo);
                        tree.Nodes.Add(textBox1.Text).Tag = flo;
                        break;

                    case 7:
                        WzSubProperty sub = new WzSubProperty(textBox1.Text);
                        canvas.AddProperty(sub);
                        tree.Nodes.Add(textBox1.Text).Tag = sub;
                        break;

                    case 8:
                        WzSoundProperty mps       = new WzSoundProperty(textBox1.Text);
                        FileStream      readsound = File.OpenRead(textBox2.Text);
                        byte[]          mpdata    = new byte[readsound.Length];
                        readsound.Read(mpdata, 0, (int)readsound.Length);
                        mps.SoundData = mpdata;
                        canvas.AddProperty(mps);
                        tree.Nodes.Add(textBox1.Text).Tag = mps;
                        readsound.Close();
                        break;

                    case 9:
                        WzConvexProperty convex = new WzConvexProperty(textBox1.Text);
                        canvas.AddProperty(convex);
                        tree.Nodes.Add(textBox1.Text).Tag = convex;
                        break;

                    case 10:
                        WzUnsignedShortProperty us = new WzUnsignedShortProperty(textBox1.Text, Convert.ToUInt16(textBox2.Text));
                        canvas.AddProperty(us);
                        tree.Nodes.Add(textBox1.Text).Tag = us;
                        break;

                    default:
                        break;
                    }
                    break;

                case "WzConvexProperty":
                    WzExtendedProperty ext = new WzExtendedProperty(textBox1.Text);
                    switch (comboBox1.SelectedIndex)
                    {
                    case 0:
                        WzCompressedIntProperty integer = new WzCompressedIntProperty(textBox1.Text, Convert.ToInt32(textBox2.Text));
                        ext.ExtendedProperty = integer;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = integer;
                        break;

                    case 1:
                        WzCanvasProperty png = new WzCanvasProperty(textBox1.Text);
                        (png.PngProperty = new WzPngProperty()).PNG = (Bitmap)pictureBox1.Image;
                        png.PngProperty.Height = pictureBox1.Image.Height;
                        png.PngProperty.Width  = pictureBox1.Image.Width;
                        ext.ExtendedProperty   = png;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = png;
                        break;

                    case 2:
                        WzVectorProperty vector = new WzVectorProperty(textBox1.Text, new WzCompressedIntProperty("X", Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[0])), new WzCompressedIntProperty("Y", Convert.ToInt32(textBox2.Text.Split(Convert.ToChar(","))[1])));
                        ext.ExtendedProperty = vector;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = vector;
                        break;

                    case 3:
                        WzStringProperty str = new WzStringProperty(textBox1.Text, textBox2.Text);
                        ext.ExtendedProperty = str;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = str;
                        break;

                    case 4:
                        WzUOLProperty uol = new WzUOLProperty(textBox1.Text, textBox2.Text);
                        ext.ExtendedProperty = uol;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = uol;
                        break;

                    case 5:
                        WzDoubleProperty dou = new WzDoubleProperty(textBox1.Text, Convert.ToDouble(textBox2.Text));
                        ext.ExtendedProperty = dou;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = dou;
                        break;

                    case 6:
                        WzByteFloatProperty flo = new WzByteFloatProperty(textBox1.Text, Convert.ToSingle(textBox2.Text));
                        ext.ExtendedProperty = flo;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = flo;
                        break;

                    case 7:
                        WzSubProperty sub = new WzSubProperty(textBox1.Text);
                        ext.ExtendedProperty = sub;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = sub;
                        break;

                    case 8:
                        WzSoundProperty mps       = new WzSoundProperty(textBox1.Text);
                        FileStream      readsound = File.OpenRead(textBox2.Text);
                        byte[]          mpdata    = new byte[readsound.Length];
                        readsound.Read(mpdata, 0, (int)readsound.Length);
                        mps.SoundData        = mpdata;
                        ext.ExtendedProperty = mps;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = mps;
                        readsound.Close();
                        break;

                    case 9:
                        WzConvexProperty convex = new WzConvexProperty(textBox1.Text);
                        ext.ExtendedProperty = convex;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = convex;
                        break;

                    case 10:
                        WzUnsignedShortProperty us = new WzUnsignedShortProperty(textBox1.Text, Convert.ToUInt16(textBox2.Text));
                        ext.ExtendedProperty = us;
                        ((WzConvexProperty)data).AddProperty(ext);
                        tree.Nodes.Add(textBox1.Text).Tag = us;
                        break;

                    default:
                        break;
                    }
                    break;
                }
                if (data is WzImage)
                {
                    ((WzImage)data).changed = true;
                }
                else
                {
                    ((IWzImageProperty)data).ParentImage.changed = true;
                }
                Close();
            }
        }
        /// <summary>
        /// Load spine object from WzImageProperty (bg, map item)
        /// </summary>
        /// <param name="source"></param>
        /// <param name="prop"></param>
        /// <param name="device"></param>
        /// <returns></returns>
        private static bool LoadSpineMapObjectItem(WzImageProperty source, WzImageProperty prop, GraphicsDevice device, string spineAniPath = null)
        {
            WzImageProperty spineAtlas = null;

            bool bIsObjectLayer = source.Parent.Name == "spine";

            if (bIsObjectLayer) // load spine if the source is already the directory we need
            {
                string spineAtlasPath = ((WzStringProperty)source["spine"])?.GetString();
                if (spineAtlasPath != null)
                {
                    spineAtlas = source[spineAtlasPath + ".atlas"];
                }
            }
            else if (spineAniPath != null)
            {
                WzImageProperty spineSource = (WzImageProperty)source.Parent?.Parent["spine"]?[source.Name];

                string spineAtlasPath = ((WzStringProperty)spineSource["spine"])?.GetString();
                if (spineAtlasPath != null)
                {
                    spineAtlas = spineSource[spineAtlasPath + ".atlas"];
                }
            }

            if (spineAtlas != null)
            {
                if (spineAtlas is WzStringProperty)
                {
                    WzStringProperty stringObj = (WzStringProperty)spineAtlas;
                    if (!stringObj.IsSpineAtlasResources)
                    {
                        return(false);
                    }

                    try
                    {
                        WzSpineObject spineObject = new WzSpineObject(new WzSpineAnimationItem(stringObj));

                        spineObject.spineAnimationItem.LoadResources(device); //  load spine resources (this must happen after window is loaded)
                        spineObject.skeleton = new Skeleton(spineObject.spineAnimationItem.SkeletonData);
                        //spineObject.skeleton.R =153;
                        //spineObject.skeleton.G = 255;
                        //spineObject.skeleton.B = 0;
                        //spineObject.skeleton.A = 1f;

                        // Skin
                        foreach (Skin skin in spineObject.spineAnimationItem.SkeletonData.Skins)
                        {
                            spineObject.skeleton.SetSkin(skin); // just set the first skin
                            break;
                        }

                        // Define mixing between animations.
                        spineObject.stateData = new AnimationStateData(spineObject.skeleton.Data);
                        spineObject.state     = new AnimationState(spineObject.stateData);
                        if (!bIsObjectLayer)
                        {
                            spineObject.state.TimeScale = 0.1f;
                        }

                        if (spineAniPath != null)
                        {
                            spineObject.state.SetAnimation(0, spineAniPath, true);
                        }
                        else
                        {
                            int i = 0;
                            foreach (Animation animation in spineObject.spineAnimationItem.SkeletonData.Animations)
                            {
                                spineObject.state.SetAnimation(i++, animation.Name, true);
                            }
                        }
                        prop.MSTagSpine = spineObject;
                        return(true);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
            return(false);
        }
Exemplo n.º 29
0
 private static void ParseXML(XmlElement element, IPropertyContainer wo)
 {
     foreach (XmlNode node in element)
     {
         if (!(node is XmlElement))
         {
             continue;
         }
         XmlElement childElement = (XmlElement)node;
         if (childElement.Name == "imgdir")
         {
             WzSubProperty sub = new WzSubProperty(childElement.GetAttribute("name"));
             wo.AddProperty(sub);
             ParseXML(childElement, (IPropertyContainer)sub);
         }
         else if (childElement.Name == "canvas")
         {
             WzCanvasProperty canvas = new WzCanvasProperty(childElement.GetAttribute("name"));
             canvas.PngProperty = new WzPngProperty();
             MemoryStream pngstream = new MemoryStream(Convert.FromBase64String(childElement.GetAttribute("basedata")));
             canvas.PngProperty.SetPNG((Bitmap)Image.FromStream(pngstream, true, true));
             wo.AddProperty(canvas);
             ParseXML(childElement, (IPropertyContainer)canvas);
         }
         if (childElement.Name == "int")
         {
             WzCompressedIntProperty compressedInt = new WzCompressedIntProperty(childElement.GetAttribute("name"), int.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(compressedInt);
         }
         if (childElement.Name == "double")
         {
             WzDoubleProperty doubleProp = new WzDoubleProperty(childElement.GetAttribute("name"), double.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(doubleProp);
         }
         if (childElement.Name == "null")
         {
             WzNullProperty nullProp = new WzNullProperty(childElement.GetAttribute("name"));
             wo.AddProperty(nullProp);
         }
         if (childElement.Name == "sound")
         {
             WzSoundProperty sound = new WzSoundProperty(childElement.GetAttribute("name"));
             sound.SetDataUnsafe(Convert.FromBase64String(childElement.GetAttribute("basedata")));
             wo.AddProperty(sound);
         }
         if (childElement.Name == "string")
         {
             string           str        = childElement.GetAttribute("value").Replace("&lt;", "<").Replace("&amp;", "&").Replace("&gt;", ">").Replace("&apos;", "'").Replace("&quot;", "\"");
             WzStringProperty stringProp = new WzStringProperty(childElement.GetAttribute("name"), str);
             wo.AddProperty(stringProp);
         }
         if (childElement.Name == "short")
         {
             WzUnsignedShortProperty shortProp = new WzUnsignedShortProperty(childElement.GetAttribute("name"), ushort.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(shortProp);
         }
         if (childElement.Name == "uol")
         {
             WzUOLProperty uol = new WzUOLProperty(childElement.GetAttribute("name"), childElement.GetAttribute("value"));
             wo.AddProperty(uol);
         }
         if (childElement.Name == "vector")
         {
             WzVectorProperty vector = new WzVectorProperty(childElement.GetAttribute("name"), new WzCompressedIntProperty("x", Convert.ToInt32(childElement.GetAttribute("x"))), new WzCompressedIntProperty("y", Convert.ToInt32(childElement.GetAttribute("y"))));
             wo.AddProperty(vector);
         }
         if (childElement.Name == "float")
         {
             WzByteFloatProperty floatProp = new WzByteFloatProperty(childElement.GetAttribute("name"), float.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(floatProp);
         }
         if (childElement.Name == "extended")
         {
             WzConvexProperty convex = new WzConvexProperty(childElement.GetAttribute("name"));
             wo.AddProperty(convex);
             ParseXML(childElement, (IPropertyContainer)convex);
         }
     }
 }
Exemplo n.º 30
0
 private static void DumpXML(TextWriter tw, string depth, List <IWzImageProperty> props)
 {
     foreach (IWzImageProperty property in props)
     {
         if (property != null)
         {
             if (property is WzCanvasProperty)
             {
                 WzCanvasProperty canvas = (WzCanvasProperty)property;
                 MemoryStream     stream = new MemoryStream();
                 canvas.PngProperty.GetPNG(false).Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                 byte[] pngbytes = stream.ToArray();
                 stream.Close();
                 tw.WriteLine(string.Concat(new object[] { depth, "<canvas name=\"", canvas.Name, "\" width=\"", canvas.PngProperty.Width, "\" height=\"", canvas.PngProperty.Height, "\" basedata=\"", Convert.ToBase64String(pngbytes), "\">" }));
                 DumpXML(tw, depth + indent, canvas.WzProperties);
                 tw.WriteLine(depth + "</canvas>");
             }
             else if (property is WzCompressedIntProperty)
             {
                 WzCompressedIntProperty compressedInt = (WzCompressedIntProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<int name=\"", compressedInt.Name, "\" value=\"", compressedInt.Value, "\"/>" }));
             }
             else if (property is WzDoubleProperty)
             {
                 WzDoubleProperty doubleProp = (WzDoubleProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<double name=\"", doubleProp.Name, "\" value=\"", doubleProp.Value.ToString(formattingInfo), "\"/>" }));
             }
             else if (property is WzNullProperty)
             {
                 WzNullProperty nullProp = (WzNullProperty)property;
                 tw.WriteLine(depth + "<null name=\"" + nullProp.Name + "\"/>");
             }
             else if (property is WzSoundProperty)
             {
                 WzSoundProperty sound = (WzSoundProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<sound name=\"", sound.Name, "\" basedata=\"", Convert.ToBase64String(sound.GetBytes(false)), "\"/>" }));
             }
             else if (property is WzStringProperty)
             {
                 WzStringProperty stringProp = (WzStringProperty)property;
                 string           str        = stringProp.Value.Replace("<", "&lt;").Replace("&", "&amp;").Replace(">", "&gt;").Replace("'", "&apos;").Replace("\"", "&quot;");
                 tw.WriteLine(depth + "<string name=\"" + stringProp.Name + "\" value=\"" + str + "\"/>");
             }
             else if (property is WzSubProperty)
             {
                 WzSubProperty sub = (WzSubProperty)property;
                 tw.WriteLine(depth + "<imgdir name=\"" + sub.Name + "\">");
                 DumpXML(tw, depth + indent, sub.WzProperties);
                 tw.WriteLine(depth + "</imgdir>");
             }
             else if (property is WzUnsignedShortProperty)
             {
                 WzUnsignedShortProperty ushortProp = (WzUnsignedShortProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<short name=\"", ushortProp.Name, "\" value=\"", ushortProp.Value.ToString(formattingInfo), "\"/>" }));
             }
             else if (property is WzUOLProperty)
             {
                 WzUOLProperty uol = (WzUOLProperty)property;
                 tw.WriteLine(depth + "<uol name=\"" + uol.Name + "\" value=\"" + uol.Value + "\"/>");
             }
             else if (property is WzVectorProperty)
             {
                 WzVectorProperty vector = (WzVectorProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<vector name=\"", vector.Name, "\" x=\"", vector.X.Value, "\" y=\"", vector.Y.Value, "\"/>" }));
             }
             else if (property is WzByteFloatProperty)
             {
                 WzByteFloatProperty floatProp = (WzByteFloatProperty)property;
                 string str2 = floatProp.Value.ToString(formattingInfo);
                 if (!str2.Contains("."))
                 {
                     str2 = str2 + ".0";
                 }
                 tw.WriteLine(depth + "<float name=\"" + floatProp.Name + "\" value=\"" + str2 + "\"/>");
             }
             else if (property is WzConvexProperty)
             {
                 tw.WriteLine(depth + "<extended name=\"" + property.Name + "\">");
                 DumpXML(tw, depth + indent, ((WzConvexProperty)property).WzProperties);
                 tw.WriteLine(depth + "</extended>");
             }
         }
     }
 }