Esempio n. 1
0
        /// <summary>
        /// Retrieves the final (exported) texture info, with the final texture
        /// id and rect
        /// </summary>
        /// <param name="textureID"></param>
        /// <returns></returns>
        public FinalTexture GetFinalTexture(int textureID)
        {
            TextureInfo info = GetTextureInfo(textureID);

            if (info == null)
            {
                return(null);
            }

            FinalTexture finalTexture = new FinalTexture();

            finalTexture.mRectangle      = new RectangleF(0.0f, 0.0f, 1.0f, 1.0f);
            finalTexture.mFinalTextureID = GetUniqueTextureID(textureID);
            finalTexture.mTextureInfo    = info;

            foreach (TextureAtlas atlas in TextureAtlasses)
            {
                AtlasNode node = atlas.FindNode(info);
                if (node != null)
                {
                    int padding = (info.AtlasPadding < 0) ? mAtlasPadding : info.AtlasPadding;

                    float x = (node.mRectangle.X + padding) / (float)atlas.mRoot.mRectangle.Width;
                    float y = (node.mRectangle.Y + padding) / (float)atlas.mRoot.mRectangle.Height;
                    float w = (node.mRectangle.Width - (padding * 2)) / (float)atlas.mRoot.mRectangle.Width;
                    float h = (node.mRectangle.Height - (padding * 2)) / (float)atlas.mRoot.mRectangle.Height;

                    finalTexture.mRectangle = new RectangleF(x, y, w, h);

                    finalTexture.mFinalTextureID = atlas.mID;
                    finalTexture.mTextureAtlas   = atlas;
                    return(finalTexture);
                }
            }

            return(finalTexture);
        }
Esempio n. 2
0
        /// <summary>
        /// Exports the GUI Scene to a file
        /// </summary>
        /// <param name="bw"></param>
        public void Export(PlatformBinaryWriter bw)
        {
            FourCCStack fourCCStack = new FourCCStack(bw);

            fourCCStack.Push("GGSC");
            {
                bw.Write(Otter.Properties.Settings.Default.DataVersion);
                bw.Write((uint)this.ID);

                bw.Write(GUIProject.CurrentProject.Fonts.Count);
                bw.Write(Textures.Count + TextureAtlasses.Count);
                bw.Write(Sounds.Count);
                bw.Write(Views.Count);
                bw.Write(Messages.Count);

                int fontOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - font data start

                int textureOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - texture data start

                int soundOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - sound data start

                int viewDataOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - sceneView data start

                int msgDataOffsetPos = (int)bw.BaseStream.Position;
                bw.Write(0); // Placeholder - message data start;

                int dataStartPos = (int)bw.BaseStream.Position;
                int pos          = 0;

                // Fonts
                pos = (int)bw.BaseStream.Position;
                bw.Seek(fontOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (GUIFont font in GUIProject.CurrentProject.Fonts)
                {
                    font.Export(bw);
                }

                // Textures
                pos = (int)bw.BaseStream.Position;
                bw.Seek(textureOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);

                // Write out the texture atlasses first
                foreach (TextureAtlas textureAtlas in TextureAtlasses)
                {
                    char[] textureFile = new char[256];
                    textureAtlas.mFilename.CopyTo(0, textureFile, 0, Math.Min(255, textureAtlas.mFilename.Length));

                    bw.Write(textureAtlas.mID);
                    bw.Write(textureFile);
                    bw.Write(0);  // Placeholder : Reference Count

                    bw.Write((uint)0);
                    bw.Write(0.0f);
                    bw.Write(0.0f);
                    bw.Write(1.0f);
                    bw.Write(1.0f);
                }

                foreach (TextureInfo textureInfo in Textures)
                {
                    char[] textureFile = new char[256];
                    textureInfo.Filename.CopyTo(0, textureFile, 0, Math.Min(255, textureInfo.Filename.Length));

                    bw.Write(GetUniqueTextureID(textureInfo.ID));
                    bw.Write(textureFile);
                    bw.Write(0);  // Placeholder : Reference Count

                    FinalTexture finalTexture = GetFinalTexture(textureInfo.ID);

                    bw.Write(finalTexture.mFinalTextureID);
                    bw.Write(finalTexture.mRectangle.X);
                    bw.Write(finalTexture.mRectangle.Y);
                    bw.Write(finalTexture.mRectangle.X + finalTexture.mRectangle.Width);
                    bw.Write(finalTexture.mRectangle.Y + finalTexture.mRectangle.Height);
                }

                // Sounds
                pos = (int)bw.BaseStream.Position;
                bw.Seek(soundOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (SoundInfo soundInfo in Sounds)
                {
                    char[] soundIdentifier = new char[256];

                    if (soundInfo.Filename != "")
                    {
                        soundInfo.Filename.CopyTo(0, soundIdentifier, 0, Math.Min(255, soundInfo.Filename.Length));
                    }
                    else
                    {
                        soundInfo.Name.CopyTo(0, soundIdentifier, 0, Math.Min(255, soundInfo.Name.Length));
                    }

                    bw.Write(GetUniqueSoundID(soundInfo.ID));
                    bw.Write(soundIdentifier);
                    bw.Write(0);  // Placeholder : Reference Count
                }

                // Views
                pos = (int)bw.BaseStream.Position;
                bw.Seek(viewDataOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (GUIView view in Views)
                {
                    view.Export(bw);
                }

                // Messages
                pos = (int)bw.BaseStream.Position;
                bw.Seek(msgDataOffsetPos, SeekOrigin.Begin);
                bw.Write(pos - dataStartPos);
                bw.Seek(0, SeekOrigin.End);
                foreach (UI.Message msg in Messages)
                {
                    bw.Write(this.GetUniqueMessageID(msg.ID));

                    byte[] bytes = Utils.StringToBytes(msg.Text, 64);
                    bytes[63] = 0;
                    bw.Write(bytes, 0, 64);
                }

                // Write an end-marker for the scene file, to verify all data was loaded properly
                bw.Write((UInt32)0x12344321);
            }
            fourCCStack.Pop();
        }