public static SaveFrame<Texture2DWithPos> ToTexture2D(this SaveFrame<BitmapWithPos> frame, GraphicsDevice graphicsDevice) { SaveFrame<Texture2DWithPos> newFrame = new SaveFrame<Texture2DWithPos>(frame.Duration); foreach (BitmapWithPos bitmap in frame.Images.BackToFront()) { newFrame.Images.AddToFront(bitmap.ToTexture2D(graphicsDevice)); } return newFrame; }
private PicturePanel getFramePanel(SaveFrame<Texture2DWithPos> saveFrame) { foreach (PicturePanel frame in Controls.OfType<PicturePanel>()) { if (frame.SaveFrame == saveFrame) { return frame; } } return null; }
public PicturePanel(FrameListPanel frameListPanel, SaveFrame<Texture2DWithPos> saveFrame) : base(frameListPanel) { this.SaveFrame = saveFrame; MouseClick += new MouseEventHandler(PictureFrame_MouseClick); BackColor = DefaultBackColor; buttonDelete = new Panel(); buttonDelete.BackgroundImage = global::Mindstep.EasterEgg.MapEditor.Properties.Resources.cross; buttonDelete.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; buttonDelete.Size = buttonDelete.BackgroundImage.Size; buttonDelete.Anchor = AnchorStyles.Right | AnchorStyles.Top; buttonDelete.Left = Size.Width - buttonDelete.Size.Width; buttonDelete.MouseEnter += new EventHandler((sender, e) => buttonDelete.BackColor = SD.Color.DimGray); buttonDelete.MouseLeave += new EventHandler((sender, e) => buttonDelete.BackColor = SD.Color.Transparent); buttonDelete.MouseClick += new MouseEventHandler(buttonDelete_MouseClick); Controls.Add(buttonDelete); }
/// <summary> /// Imports a model from the file /// <code>directoryPath+"/"+modelName+".egg"</code> /// including sub models /// </summary> /// <param name="directoryPath"></param> /// <param name="modelName"></param> /// <returns></returns> public static SaveModel<BitmapWithPos> Load(string directoryPath, string modelName) { SaveModel<BitmapWithPos> model = new SaveModel<BitmapWithPos>(modelName); using (ZipFile modelFile = new ZipFile(directoryPath + "/" + modelName + ".egg")) { using (PackagedBitmapsManager bitmapManager = new PackagedBitmapsManager(modelFile, "textures/")) { ZipEntry xmlEntry = modelFile.GetEntry("model.xml"); Stream xmlStream = modelFile.GetInputStream(xmlEntry); XDocument doc = XDocument.Load(xmlStream); XElement root = doc.Element("model"); // blocks { foreach (XElement blockElement in root.Element("blocks").Elements("block")) { Position pos = blockElement.Attribute("offset").Value.LoadPosition(); SaveBlock block = new SaveBlock(pos); model.Blocks.Add(block); block.Type = blockElement.Attribute("type").Value.LoadBlockType(); XAttribute scriptAttribute = blockElement.Attribute("script"); if (scriptAttribute != null) { block.Script = scriptAttribute.Value; } } } // imports foreach (XElement modelElement in root.Element("imports").Elements("model")) { Position offset = modelElement.Attribute("offset").Value.LoadPosition(); model.SubModels.Add(new SaveSubModel<BitmapWithPos>(Load(directoryPath, modelElement.Value), offset)); } // animations foreach (XElement animationElement in root.Element("animations").Elements("animation")) { SaveAnimation<BitmapWithPos> animation = new SaveAnimation<BitmapWithPos>(animationElement.Attribute("name").Value); animation.Facing = animationElement.Attribute("facing").Value.LoadFacing(); model.Animations.Add(animation); foreach (XElement frameElement in animationElement.Elements("frame")) { SaveFrame<BitmapWithPos> frame = new SaveFrame<BitmapWithPos>(frameElement.Attribute("duration").Value.LoadInt()); animation.Frames.Add(frame); foreach (XElement imageElement in frameElement.Elements("image")) { BitmapWithPos bitmapWithPos = new BitmapWithPos(); frame.Images.AddToFront(bitmapWithPos); bitmapWithPos.Position = imageElement.Attribute("coord").Value.LoadPoint(); bitmapWithPos.name = imageElement.Attribute("name").Value; bitmapWithPos.projectedOnto.AddRange(imageElement.Elements("projectedOnto").Select(e => model.Blocks[e.Value.LoadInt()])); bitmapWithPos.bitmap = bitmapManager[bitmapWithPos.name]; } } } } } return model; }