public UserObjectsManager(MultiBoard multiBoard)
        {
            this.multiBoard = multiBoard;

            if (Program.InfoManager == null)
            {
                // Prevents VS designer from crashing when rendering this control; there is no way that Program.InfoManager will be null
                // in the real execution of this code.
                return;
            }

            // Make sure that all our structures exist
            if (!Program.InfoManager.ObjectSets.ContainsKey(oS))
            {
                Program.InfoManager.ObjectSets[oS] = new WzImage(oS);
                Program.InfoManager.ObjectSets[oS].Changed = true;
            }
            WzImage osimg = Program.InfoManager.ObjectSets[oS];
            if (osimg[l0] == null)
            {
                osimg[l0] = new WzSubProperty();
            }
            WzImageProperty l0prop = osimg[l0];
            if (l0prop[l1] == null)
            {
                l0prop[l1] = new WzSubProperty();
            }
            l1prop = l0prop[l1];
        }
Beispiel #2
0
 private static List<List<XNA.Point>> ParsePropToOffsetMap(WzImageProperty prop)
 {
     if (prop == null)
         return null;
     List<List<XNA.Point>> result = new List<List<XNA.Point>>();
     if (prop is WzConvexProperty)
     {
         result.Add(ParsePropToOffsetList((WzConvexProperty)prop));
     }
     else if (prop is WzSubProperty)
     {
         foreach (WzConvexProperty offsetSet in prop.WzProperties)
         {
             result.Add(ParsePropToOffsetList(offsetSet));
         }
     }
     else
     {
         result = null;
     }
     return result;
 }
Beispiel #3
0
 private static List<XNA.Point> ParsePropToOffsetList(WzImageProperty prop)
 {
     List<XNA.Point> result = new List<XNA.Point>();
     foreach (WzVectorProperty point in prop.WzProperties)
     {
         result.Add(WzInfoTools.VectorToXNAPoint(point));
     }
     return result;
 }
Beispiel #4
0
 private static MapItem CreateMapItemFromProperty(WzImageProperty source, int x, int y, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List<WzObject> usedProps, bool flip)
 {
     source = WzInfoTools.GetRealProperty(source);
     if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
         source = ((WzSubProperty)source).WzProperties[0];
     if (source is WzCanvasProperty) //one-frame
     {
         WzVectorProperty origin = (WzVectorProperty)source["origin"];
         if (source.MSTag == null)
         {
             source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).PngProperty.GetPNG(false));
             usedProps.Add(source);
         }
         return new MapItem(new DXObject(x - origin.X.Value + mapCenterX, y - origin.Y.Value + mapCenterY, (Texture2D)source.MSTag), flip);
     }
     else if (source is WzSubProperty) //animooted
     {
         WzCanvasProperty frameProp;
         int i = 0;
         List<DXObject> frames = new List<DXObject>();
         while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
         {
             int? delay = InfoTool.GetOptionalInt(frameProp["delay"]);
             if (delay == null) delay = 100;
             if (frameProp.MSTag == null)
             {
                 frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.PngProperty.GetPNG(false));
                 usedProps.Add(frameProp);
             }
             WzVectorProperty origin = (WzVectorProperty)frameProp["origin"];
             frames.Add(new DXObject(x - origin.X.Value + mapCenterX, y - origin.Y.Value + mapCenterY, (int)delay, (Texture2D)frameProp.MSTag));
         }
         return new MapItem(frames, flip);
     }
     else throw new Exception("unsupported property type in map simulator");
 }
        private void ExtractSettingsImage(WzImage settingsImage, Type settingsHolderType)
        {
            if (!settingsImage.Parsed)
            {
                settingsImage.ParseImage();
            }
            foreach (FieldInfo fieldInfo in settingsHolderType.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                string          settingName = fieldInfo.Name;
                WzImageProperty settingProp = settingsImage[settingName];
                byte[]          argb;
                if (settingProp == null)
                {
                    SaveField(settingsImage, fieldInfo);
                }
                else if (fieldInfo.FieldType.BaseType != null && fieldInfo.FieldType.BaseType.FullName == "System.Enum")
                {
                    fieldInfo.SetValue(null, InfoTool.GetInt(settingProp));
                }
                else
                {
                    switch (fieldInfo.FieldType.FullName)
                    {
                    //case "Microsoft.Xna.Framework.Graphics.Color":
                    case "Microsoft.Xna.Framework.Color":
                        if (xnaColorType == null)
                        {
                            throw new InvalidDataException("XNA color detected, but XNA type activator is null");
                        }
                        argb = BitConverter.GetBytes((uint)((WzDoubleProperty)settingProp).Value);
                        fieldInfo.SetValue(null, Activator.CreateInstance(xnaColorType, argb[0], argb[1], argb[2], argb[3]));
                        break;

                    case "System.Drawing.Color":
                        argb = BitConverter.GetBytes((uint)((WzDoubleProperty)settingProp).Value);
                        fieldInfo.SetValue(null, System.Drawing.Color.FromArgb(argb[3], argb[2], argb[1], argb[0]));
                        break;

                    case "System.Int32":
                        fieldInfo.SetValue(null, InfoTool.GetInt(settingProp));
                        break;

                    case "System.Double":
                        fieldInfo.SetValue(null, ((WzDoubleProperty)settingProp).Value);
                        break;

                    case "System.Boolean":
                        fieldInfo.SetValue(null, InfoTool.GetBool(settingProp));
                        //bool a = (bool)fieldInfo.GetValue(null);
                        break;

                    case "System.Single":
                        fieldInfo.SetValue(null, ((WzFloatProperty)settingProp).Value);
                        break;

                    /*case "WzMapleVersion":
                     *  fieldInfo.SetValue(null, (WzMapleVersion)InfoTool.GetInt(settingProp));
                     *  break;
                     * case "ItemTypes":
                     *  fieldInfo.SetValue(null, (ItemTypes)InfoTool.GetInt(settingProp));
                     *  break;*/
                    case "System.Drawing.Size":
                        fieldInfo.SetValue(null, new System.Drawing.Size(((WzVectorProperty)settingProp).X.Value, ((WzVectorProperty)settingProp).Y.Value));
                        break;

                    case "System.String":
                        fieldInfo.SetValue(null, InfoTool.GetString(settingProp));
                        break;

                    case "System.Drawing.Bitmap":
                        fieldInfo.SetValue(null, ((WzCanvasProperty)settingProp).PngProperty.GetPNG(false));
                        break;

                    default:
                        throw new Exception("unrecognized setting type");
                    }
                }
            }
        }
        /// <summary>
        /// Parses the image from the wz filetod
        /// </summary>
        /// <param name="wzReader">The BinaryReader that is currently reading the wz file</param>
        /// <returns>bool Parse status</returns>
        public bool ParseImage(bool forceReadFromData = false)
        {
            if (!forceReadFromData)   // only check if parsed or changed if its not false read
            {
                if (Parsed)
                {
                    return(true);
                }
                else if (Changed)
                {
                    Parsed = true;
                    return(true);
                }
            }

            lock (reader) // for multi threaded XMLWZ export.
            {
                long originalPos = reader.BaseStream.Position;
                reader.BaseStream.Position = offset;

                byte b = reader.ReadByte();
                switch (b)
                {
                case 0x1:     // .lua
                {
                    if (IsLuaWzImage)
                    {
                        WzLuaProperty          lua      = WzImageProperty.ParseLuaProperty(offset, reader, this, this);
                        List <WzImageProperty> luaImage = new List <WzImageProperty>
                        {
                            lua
                        };
                        properties.AddRange(luaImage);
                        parsed = true;         // test
                        return(true);
                    }

                    return(false);        // unhandled for now, if it isnt an .lua image
                }

                case WzImageHeaderByte:
                {
                    string prop = reader.ReadString();
                    ushort val  = reader.ReadUInt16();
                    if (prop != "Property" || val != 0)
                    {
                        return(false);
                    }
                    break;
                }

                default:
                {
                    // todo: log this or warn.
                    Helpers.ErrorLogger.Log(Helpers.ErrorLevel.MissingFeature, "[WzImage] New Wz image header found. b = " + b);
                    return(false);
                }
                }
                List <WzImageProperty> images = WzImageProperty.ParsePropertyList(offset, reader, this, this);
                properties.AddRange(images);

                parsed = true;
            }
            return(true);
        }
Beispiel #7
0
        internal static WzExtended ExtractMore(WzBinaryReader reader, uint offset, int eob, string name, string iname, WzObject parent, WzImage imgParent)
        {
            if (iname == "")
            {
                iname = reader.ReadString();
            }
            switch (iname)
            {
            case "Property":
                WzSubProperty subProp = new WzSubProperty(name)
                {
                    Parent = parent
                };
                reader.BaseStream.Position += 2;     // Reserved?
                subProp.AddProperties(WzImageProperty.ParsePropertyList(offset, reader, subProp, imgParent));
                return(subProp);

            case "Canvas":
                WzCanvasProperty canvasProp = new WzCanvasProperty(name)
                {
                    Parent = parent
                };
                reader.BaseStream.Position++;
                if (reader.ReadByte() == 1)
                {
                    reader.BaseStream.Position += 2;
                    canvasProp.AddProperties(WzImageProperty.ParsePropertyList(offset, reader, canvasProp, imgParent));
                }
                canvasProp.PngProperty = new WzPngProperty(reader, imgParent.ParseEverything)
                {
                    Parent = canvasProp
                };
                return(canvasProp);

            case "Shape2D#Vector2D":
                WzVectorProperty vecProp = new WzVectorProperty(name)
                {
                    Parent = parent
                };
                vecProp.X = new WzIntProperty("X", reader.ReadCompressedInt())
                {
                    Parent = vecProp
                };
                vecProp.Y = new WzIntProperty("Y", reader.ReadCompressedInt())
                {
                    Parent = vecProp
                };
                return(vecProp);

            case "Shape2D#Convex2D":
                WzConvexProperty convexProp = new WzConvexProperty(name)
                {
                    Parent = parent
                };
                int convexEntryCount = reader.ReadCompressedInt();
                convexProp.WzProperties.Capacity = convexEntryCount;
                for (int i = 0; i < convexEntryCount; i++)
                {
                    convexProp.AddProperty(ParseExtendedProp(reader, offset, 0, name, convexProp, imgParent));
                }
                return(convexProp);

            case "Sound_DX8":
                WzBinaryProperty soundProp = new WzBinaryProperty(name, reader, imgParent.ParseEverything)
                {
                    Parent = parent
                };
                return(soundProp);

            case "UOL":
                reader.BaseStream.Position++;
                switch (reader.ReadByte())
                {
                case 0:
                    return(new WzUOLProperty(name, reader.ReadString())
                    {
                        Parent = parent
                    });

                case 1:
                    return(new WzUOLProperty(name, reader.ReadStringAtOffset(offset + reader.ReadInt32()))
                    {
                        Parent = parent
                    });
                }
                throw new Exception("Unsupported UOL type");

            default:
                throw new Exception("Unknown iname: " + iname);
            }
        }
Beispiel #8
0
        internal static List <WzImageProperty> ParsePropertyList(uint offset, WzBinaryReader reader, WzObject parent, WzImage parentImg)
        {
            int entryCount = reader.ReadCompressedInt();
            List <WzImageProperty> properties = new List <WzImageProperty>(entryCount);

            for (int i = 0; i < entryCount; i++)
            {
                string name  = reader.ReadStringBlock(offset);
                byte   ptype = reader.ReadByte();
                switch (ptype) // header value
                {
                case 0:
                    properties.Add(new WzNullProperty(name)
                    {
                        Parent = parent
                    });
                    break;

                case 11:
                case 2:
                    properties.Add(new WzShortProperty(name, reader.ReadInt16())
                    {
                        Parent = parent
                    });
                    break;

                case 3:
                case 19:
                    properties.Add(new WzIntProperty(name, reader.ReadCompressedInt())
                    {
                        Parent = parent
                    });
                    break;

                case 20:
                    properties.Add(new WzLongProperty(name, reader.ReadLong())
                    {
                        Parent = parent
                    });
                    break;

                case 4:
                    byte type = reader.ReadByte();
                    if (type == 0x80)
                    {
                        properties.Add(new WzFloatProperty(name, reader.ReadSingle())
                        {
                            Parent = parent
                        });
                    }
                    else if (type == 0)
                    {
                        properties.Add(new WzFloatProperty(name, 0f)
                        {
                            Parent = parent
                        });
                    }
                    break;

                case 5:
                    properties.Add(new WzDoubleProperty(name, reader.ReadDouble())
                    {
                        Parent = parent
                    });
                    break;

                case 8:
                    properties.Add(new WzStringProperty(name, reader.ReadStringBlock(offset))
                    {
                        Parent = parent
                    });
                    break;

                case 9:
                    int             eob    = (int)(reader.ReadUInt32() + reader.BaseStream.Position);
                    WzImageProperty exProp = ParseExtendedProp(reader, offset, eob, name, parent, parentImg);
                    properties.Add(exProp);
                    if (reader.BaseStream.Position != eob)
                    {
                        reader.BaseStream.Position = eob;
                    }
                    break;

                default:
                    throw new Exception("Unknown property type at ParsePropertyList, ptype = " + ptype);
                }
            }
            return(properties);
        }
Beispiel #9
0
 public static WzImageProperty GetRealProperty(WzImageProperty prop)
 {
     if (prop is WzUOLProperty) return (WzImageProperty)ResolveUOL((WzUOLProperty)prop);
     else return prop;
 }
Beispiel #10
0
 /// <summary>
 /// Removes a property by name
 /// </summary>
 /// <param name="name">The name of the property to remove</param>
 public void RemoveProperty(WzImageProperty prop)
 {
     if (reader != null && !parsed) ParseImage();
     prop.Parent = null;
     properties.Remove(prop);
 }
Beispiel #11
0
 /// <summary>
 /// Adds a property to the image
 /// </summary>
 /// <param name="prop">Property to add</param>
 public void AddProperty(WzImageProperty prop)
 {
     prop.Parent = this;
     if (reader != null && !parsed) ParseImage();
     properties.Add(prop);
 }
Beispiel #12
0
 internal List<string> GetPathsFromProperty(WzImageProperty prop, string curPath)
 {
     List<string> objList = new List<string>();
     switch (prop.PropertyType)
     {
         case WzPropertyType.Canvas:
             foreach (WzImageProperty canvasProp in ((WzCanvasProperty)prop).WzProperties)
             {
                 objList.Add(curPath + "/" + canvasProp.Name);
                 objList.AddRange(GetPathsFromProperty(canvasProp, curPath + "/" + canvasProp.Name));
             }
             objList.Add(curPath + "/PNG");
             break;
         case WzPropertyType.Convex:
             foreach (WzImageProperty exProp in ((WzConvexProperty)prop).WzProperties)
             {
                 objList.Add(curPath + "/" + exProp.Name);
                 objList.AddRange(GetPathsFromProperty(exProp, curPath + "/" + exProp.Name));
             }
             break;
         case WzPropertyType.SubProperty:
             foreach (WzImageProperty subProp in ((WzSubProperty)prop).WzProperties)
             {
                 objList.Add(curPath + "/" + subProp.Name);
                 objList.AddRange(GetPathsFromProperty(subProp, curPath + "/" + subProp.Name));
             }
             break;
         case WzPropertyType.Vector:
             objList.Add(curPath + "/X");
             objList.Add(curPath + "/Y");
             break;
     }
     return objList;
 }
Beispiel #13
0
 public List<WzObject> GetObjectsFromProperty(WzImageProperty prop)
 {
     List<WzObject> objList = new List<WzObject>();
     switch (prop.PropertyType)
     {
         case WzPropertyType.Canvas:
             foreach (WzImageProperty canvasProp in ((WzCanvasProperty)prop).WzProperties)
                 objList.AddRange(GetObjectsFromProperty(canvasProp));
             objList.Add(((WzCanvasProperty)prop).PngProperty);
             break;
         case WzPropertyType.Convex:
             foreach (WzImageProperty exProp in ((WzConvexProperty)prop).WzProperties)
                 objList.AddRange(GetObjectsFromProperty(exProp));
             break;
         case WzPropertyType.SubProperty:
             foreach (WzImageProperty subProp in ((WzSubProperty)prop).WzProperties)
                 objList.AddRange(GetObjectsFromProperty(subProp));
             break;
         case WzPropertyType.Vector:
             objList.Add(((WzVectorProperty)prop).X);
             objList.Add(((WzVectorProperty)prop).Y);
             break;
     }
     return objList;
 }
Beispiel #14
0
 public UserObject(WzImageProperty prop, bool newObj)
 {
     this.prop = prop;
     this.newObj = newObj;
 }