Esempio n. 1
0
        private void loadSkin()
        {
            animation = new List<animationData>();
            bitmapBlocks = new List<bitmapData>();
            textBlocks = new List<textBlockData>();
            BinaryReader br = new BinaryReader(meta.MS);
            BinaryReader br2 = br;

            #region Animation Frames reflexive
            br2 = br;
            br.BaseStream.Position = 20;
            int animationCount = br.ReadInt32();
            int animationOffset = br.ReadInt32() - map.SecondaryMagic;

            // Handles reflexives in other tags (pointers)
            int animationTag = map.Functions.ForMeta.FindMetaByOffset(animationOffset);
            if (animationCount > 0 && animationTag != meta.TagIndex)
            {
                Meta newMeta = Map.GetMetaFromTagIndex(animationTag, meta.Map, false, true);
                br2 = new BinaryReader(newMeta.MS);
                animationOffset -= newMeta.offset;
            }
            else
                animationOffset -= meta.offset;

            for (int list = 0; list < animationCount; list++)
            {
                animationData ad = new animationData(list, meta);
                ad.offset = animationOffset + list * 16;
                ad.Read(br2);
                this.animation.Add(ad);
            }
            #endregion

            #region Text blocks reflexive
            br2 = br;
            br.BaseStream.Position = 28;
            int textBlockCount = br.ReadInt32();
            int textBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            // Handles reflexives in other tags (pointers)
            int textBlockTag = map.Functions.ForMeta.FindMetaByOffset(textBlockOffset);
            if (textBlockCount > 0 && textBlockTag != meta.TagIndex)
            {
                Meta newMeta = Map.GetMetaFromTagIndex(textBlockTag, map, false, true);
                br2 = new BinaryReader(newMeta.MS);
                textBlockOffset -= newMeta.offset;
            }
            else
                textBlockOffset -= meta.offset;

            for (int list = 0; list < textBlockCount; list++)
            {
                textBlockData tbd = new textBlockData(list);
                tbd.offset = textBlockOffset + list * 44;
                tbd.Read(br2);
                this.textBlocks.Add(tbd);
            }
            #endregion

            #region Bitmap block reflexive
            br.BaseStream.Position = 36;
            int bitmapBlockCount = br.ReadInt32();
            int bitmapBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            // Handles reflexives in other tags (pointers)
            int bitmBlockTag = map.Functions.ForMeta.FindMetaByOffset(bitmapBlockOffset);
            if (bitmapBlockCount > 0 && bitmBlockTag != meta.TagIndex)
            {
                Meta newMeta = Map.GetMetaFromTagIndex(bitmBlockTag, map, false, true);
                br2 = new BinaryReader(newMeta.MS);
                bitmapBlockOffset -= newMeta.offset;
            }
            else
                bitmapBlockOffset -= meta.offset;

            // Always add 3 in case of using sub bitmaps
            for (int list = 0; list < bitmapBlockCount; list++)
            {
                bitmapData bd = new bitmapData(list);
                bd.offset = bitmapBlockOffset + list * 56;
                bd.Read(br2);
                int bitmID = map.Functions.ForMeta.FindMetaByID(bd.bitmIdent);
                if (bitmID != -1)
                {
                    bd.meta = Map.GetMetaFromTagIndex(bitmID, map, false, false);
                    ParsedBitmap pm = new ParsedBitmap(ref bd.meta, map);
                    bd.link = pm.FindChunkAndDecode(0, 0, 0, ref bd.meta, map, 0, 0);
                    this.bitmapBlocks.Add(bd);

                    if (pm.Properties.Length > 1)
                    {
                        bd = (bitmapData)bd.Clone();
                        bd.link = pm.FindChunkAndDecode(1, 0, 0, ref bd.meta, map, 0, 0);
                    }
                    this.bitmapBlocks.Add(bd);

                    if (pm.Properties.Length > 2)
                    {
                        bd = (bitmapData)bd.Clone();
                        bd.link = pm.FindChunkAndDecode(2, 0, 0, ref bd.meta, map, 0, 0);
                    }
                    this.bitmapBlocks.Add(bd);
                }
            }
            #endregion

            isLoaded = true;
        }
Esempio n. 2
0
        public static bitmapData createText(Map map, textBlockData td, string Text, bool wrapText)
        {
            if (Text == string.Empty || td.customFont == -1)
                return null;
            bitmapData bdt = new bitmapData(td.order);
            int width = (td.right - td.left);
            Bitmap textBitm = new Bitmap( width, Math.Abs(td.top - td.bottom));
            H2FontClass.H2Font H2font = getFont(fontNames[td.customFont]);

            // For Tiny text, just use our default font as it doens't really matter
            if (H2font.isLoaded && !td.tinyText)
            {
                // Replace codes such as <GamerTag>, but not "A button" and medals, etc
                Text = entity.MetaFuncs.MEStringsSelector.ReplaceCodes(Text, false);
                using (Graphics g = Graphics.FromImage(textBitm))
                {
                    Bitmap fontBitm = wrapText ?
                        H2font.writeString(Text, width) :
                        H2font.writeString(Text);
                    if (fontBitm != null)
                    {

                        #region Text alignment

                        int textLeft;
                        if (td.leftAligned)
                            textLeft = 0;
                        else if (td.rightAligned)
                            textLeft = (int)(width - fontBitm.Width);
                        else  // center aligned
                            textLeft = (int)(width / 2 - fontBitm.Width / 2);

                        #endregion

                        if (!wrapText)
                        {
                            g.DrawImage(fontBitm, new Point(textLeft, 0));
                            bdt.top = (short)(td.bottom);
                        }
                        else
                        {
                            g.DrawImage(fontBitm, new Point(textLeft, 0));
                            bdt.top = (short)td.top;
                        }
                        fontBitm.Dispose();
                    }
                }
            }
            else
            {
                // Replace all codes internal and font contained as windows
                // fonts will not contain the special H2 codes
                Text = entity.MetaFuncs.MEStringsSelector.ReplaceCodes(Text, true);
                using (Graphics g = Graphics.FromImage(textBitm))
                {
                    Font font = new Font(FontFamily.GenericMonospace, 5.0f);
                    if (!td.tinyText)
                        switch (td.customFont)
                        {
                            case 0:     // fixedsys-9
                                font = new Font(FontFamily.GenericMonospace, 9.0f);
                                break;
                            case 1:     // conduit-12
                                font = new Font("Arial Narrow", 12.0f);
                                break;
                            case 2:     // handel_gothic-11
                                font = new Font(FontFamily.GenericSerif, 11.0f);
                                break;
                            case 3:     // handel_gothic-24
                                font = new Font(FontFamily.GenericSerif, 24.0f);
                                break;
                            case 4:     // conduit-13
                                font = new Font(FontFamily.GenericMonospace, 13.0f);
                                break;
                            case 5:     // conduit-12
                                font = new Font(FontFamily.GenericMonospace, 12.0f);
                                break;
                            case 6:     // conduit-13
                                font = new Font(FontFamily.GenericMonospace, 13.0f);
                                break;
                            case 7:     // conduit-12
                                font = new Font(FontFamily.GenericMonospace, 12.0f);
                                break;
                            case 8:     // MSLCD-14
                                font = new Font(FontFamily.GenericSerif, 14.0f);
                                break;
                            case 9:     // conduit-16
                                font = new Font(FontFamily.GenericMonospace, 16.0f);
                                break;
                            case 10:     // handel_gothic-13
                                font = new Font(FontFamily.GenericSerif, 13.0f);
                                break;
                        }

                    #region Text alignment

                    SizeF textInfo = g.MeasureString(Text, font);
                    int textLeft;
                    if (td.leftAligned)
                        textLeft = 0;
                    else if (td.rightAligned)
                        textLeft = (int)(width - textInfo.Width);
                    else  // center aligned
                        textLeft = (int)(width / 2 - textInfo.Width / 2);

                    #endregion

                    #region Text color
                    Brush brush = new SolidBrush(
                        Color.FromArgb(
                            (byte)(td.h2color.A == 0 ? 255 : td.h2color.A * byte.MaxValue),
                            (byte)(td.h2color.R * byte.MaxValue),
                            (byte)(td.h2color.G * byte.MaxValue),
                            (byte)(td.h2color.B * byte.MaxValue)
                        ));
                    #endregion

                    if (!wrapText)
                    {
                        g.DrawString(Text, font, brush, textLeft, 0);
                        bdt.top = (short)(td.bottom);// + textInfo.Height);
                    }
                    else
                    {
                        g.DrawString(Text, font, brush, new RectangleF(0, 0, textBitm.Width, textBitm.Height));
                        bdt.top = (short)td.top;
                    }
                }
            }
            bdt.left = td.left;
            bdt.link = textBitm;
            bdt.meta = new Meta(map); // We use a null meta for drawing checks, so  make sure we have something.
            bdt.renderDepth = td.renderDepth;
            return bdt;
        }
Esempio n. 3
0
        private void lbPanes_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbPanes.Focused)
                writePaneToMemory();

            if (lbPanes.SelectedIndex == -1)
                return;

            paneData pd = (paneData)lbPanes.SelectedItem;
            br = new BinaryReader(pd.meta.MS);

            #region Bitmaps
            // Clear the list of bitmaps
            pd.bitmaps.Clear();
            // Add a default "no selection" to the top of the list
            pd.bitmaps.Add(new bitmapData(0));
            pd.bitmaps[0].title = "<None>";

            br.BaseStream.Position = pd.offset + 36;
            int bitmapCount = br.ReadInt32();
            int bitmapOffset = br.ReadInt32() - map.SecondaryMagic;

            if (bitmapCount > 0)
            {
                BinaryReader br2 = br;

                // Handle pointers to other tags
                int bitmTag = map.Functions.ForMeta.FindMetaByOffset(bitmapOffset);
                if (bitmTag != currentScreen.meta.TagIndex)
                {
                    Meta newMeta = Map.GetMetaFromTagIndex(bitmTag, map, false, true);
                    br2 = new BinaryReader(newMeta.MS);
                    bitmapOffset -= newMeta.offset;
                }
                else
                    bitmapOffset -= currentScreen.meta.offset;

                for (int bitmaps = 0; bitmaps < bitmapCount; bitmaps++)
                {
                    bitmapData bitmSD = new bitmapData(bitmaps);
                    bitmSD.offset = bitmapOffset + bitmaps * 56;
                    bitmSD.Read(br2);

                    int tagNum = bitmSD.bitmIdent != -1 ? (int)map.MetaInfo.identHT[bitmSD.bitmIdent] : -1;

                    if (tagNum != -1)
                    {
                        bitmSD.meta = Map.GetMetaFromTagIndex(tagNum, map, false, true);
                        bitmSD.title = map.FileNames.Name[tagNum].Substring(map.FileNames.Name[tagNum].LastIndexOf('\\') + 1);
                    }
                    else
                    {
                        bitmSD.meta = null;
                        bitmSD.title = string.Empty;
                    }

                    if (bitmSD.meta == null)
                    {
                        bitmSD.link = null;
                        continue;
                    }

                    ParsedBitmap pm = new ParsedBitmap(ref bitmSD.meta, map);
                    Bitmap b = pm.FindChunkAndDecode(bitmSD.bitmNumber, 0, 0, ref bitmSD.meta, map, 0, 0);

                    System.Drawing.Imaging.ImageAttributes imgAttr = new System.Drawing.Imaging.ImageAttributes();

                    // If alpha-blended = 1, invert alpha channel now (way faster to do once!)
                    if (bitmSD.blendMethod == 1)
                    {
                        Bitmap bTemp = new Bitmap(b.Width, b.Height);
                        using (Graphics g = Graphics.FromImage(bTemp))
                        {

                            System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix();
                            cm.Matrix00 = 1.0f;
                            cm.Matrix03 = -1.0f;    // Reverse red alpha
                            cm.Matrix11 = 1.0f;
                            cm.Matrix13 = -1.0f;    // Reverse green alpha
                            cm.Matrix22 = 1.0f;
                            cm.Matrix23 = -1.0f;    // REverse blue alpha
                            cm.Matrix33 = 1.0f;
                            imgAttr.SetColorMatrix(cm);

                            g.Clear(Color.Empty);

                            g.DrawImage(
                                b,
                                new Rectangle(
                                    0,
                                    0,
                                    b.Width,
                                    b.Height),
                                0,
                                0,
                                b.Width,
                                b.Height,
                                GraphicsUnit.Pixel,
                                imgAttr
                                );
                            g.Dispose();
                        }
                        b.Dispose();
                        b = bTemp;
                    }
                    bitmSD.link = b;

                    pd.bitmaps.Add(bitmSD);
                }

                drawBitmap();
            }
            tabControl1.TabPages[0].Text = "Bitmaps [" + bitmapCount.ToString() + "]";
            tabControl1.TabPages[0].Enabled = (bitmapCount > 0);
            
            #endregion

            #region List Blocks
            // Clear the list of List Blocks
            pd.listBlocks.Clear();
            // Always use the first panes Data for list blocks
            br.BaseStream.Position = ((paneData)lbPanes.Items[0]).offset + 12;
            int listBlockCount = br.ReadInt32();
            int listBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            if (listBlockCount > 0)
            {
                BinaryReader br2 = br;

                // Handle pointers to other tags
                int listBlockTag = map.Functions.ForMeta.FindMetaByOffset(listBlockOffset);
                if (listBlockTag != currentScreen.meta.TagIndex)
                {
                    Meta newMeta = Map.GetMetaFromTagIndex(listBlockTag, map, false, true);
                    br2 = new BinaryReader(newMeta.MS);
                    listBlockOffset -= newMeta.offset;
                }
                else
                    listBlockOffset -= currentScreen.meta.offset;

                for (int listBlock = 0; listBlock < listBlockCount; listBlock++)
                {
                    listBlockData ld = new listBlockData(listBlock);
                    br2.BaseStream.Position = ld.offset = listBlockOffset + listBlock * 24;
                    ld.Read(br2);

                    //bitmSD.link = b;

                    pd.listBlocks.Add(ld);
                }
            }
            tabControl1.TabPages[1].Text = "List Boxes [" + listBlockCount.ToString() + "]";
            tabControl1.TabPages[1].Enabled = (listBlockCount > 0);
            #endregion

            #region Text Blocks
            br.BaseStream.Position = pd.offset + 28;
            int textBlockCount = br.ReadInt32();
            int textBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            if (textBlockCount > 0)
            {
                BinaryReader br2 = br;

                // Handle pointers to other tags
                int textBlockTag = map.Functions.ForMeta.FindMetaByOffset(textBlockOffset);
                if (textBlockTag != currentScreen.meta.TagIndex)
                {
                    Meta newMeta = Map.GetMetaFromTagIndex(textBlockTag, map, false, true);
                    br2 = new BinaryReader(newMeta.MS);
                    textBlockOffset -= newMeta.offset;
                }
                else
                    textBlockOffset -= currentScreen.meta.offset;

                pd.textBlocks.Clear();
                for (int textBlock = 0; textBlock < textBlockCount; textBlock++)
                {
                    textBlockData tb = new textBlockData(textBlock);
                    br2.BaseStream.Position = tb.offset = textBlockOffset + textBlock * 44;
                    tb.Read(br2);
                    tb.title = textBlock.ToString("0: ") + sSwap.getStringFromID(tb.stringID.sidIndexer);

                    pd.textBlocks.Add(tb);
                }
            }

            tabControl1.TabPages[2].Text = "Text Blocks [" + textBlockCount.ToString() + "]";
            tabControl1.TabPages[2].Enabled = (textBlockCount > 0);
            #endregion

            #region Model Scenes
            br.BaseStream.Position = pd.offset + 44;
            int modelScenesCount = br.ReadInt32();
            int modelScenesOffset = br.ReadInt32() - map.SecondaryMagic;

            if (modelScenesCount > 0)
            {
            }

            tabControl1.TabPages[3].Text = "Model Scenes [" + modelScenesCount.ToString() + "]";
            tabControl1.TabPages[3].Enabled = (modelScenesCount > 0);
            #endregion

            #region Variable Buttons
            br.BaseStream.Position = pd.offset + 68;
            int variableButtonsCount = br.ReadInt32();
            int variableButtonsOffset = br.ReadInt32() - map.SecondaryMagic;

            if (variableButtonsCount > 0)
            {
            }

            tabControl1.TabPages[4].Text = "Variable Buttons [" + variableButtonsCount.ToString() + "]";
            tabControl1.TabPages[4].Enabled = (variableButtonsCount > 0);
            #endregion

            #region Buttons
            br.BaseStream.Position = pd.offset + 4;
            int buttonsCount = br.ReadInt32();
            int buttonsOffset = br.ReadInt32() - map.SecondaryMagic;

            if (buttonsCount > 0)
            {
            }

            tabControl1.TabPages[5].Text = "Buttons [" + buttonsCount.ToString() + "]";
            tabControl1.TabPages[5].Enabled = (buttonsCount > 0);
            #endregion

            screenData screenSelected = (screenData)lbScreensList.SelectedItem;
            // offset stores the last currently selected pane for that screen
            screenSelected.offset = lbPanes.SelectedIndex;

            #region Set the bitmap list box to display our data in pd.bitmaps
            lbBitmaps.DataSource = pd.bitmaps;
            #endregion
            
            #region Set the skin combo box to display the current skin
            if (pd.listBlocks.Count > 0)
            {
                cbLBSkinIdent.Enabled = true;
                // Change value to be sure skin is created
                cbLBSkinIdent.SelectedIndex = -1;
                cbLBSkinIdent.SelectedIndex = pd.listBlocks[0].skinIndex;
            }
            else
            {
                cbLBSkinIdent.Enabled = false;
                cbLBSkinIdent.SelectedIndex = -1;
            }
            #endregion

            #region Set the text block list box to display our data in pd.textBlocks
            lbTBTextBlocks.DataSource = pd.textBlocks;

            foreach (textBlockData td in pd.textBlocks)
            {
                List<bitmapData> lbd = new List<bitmapData>();

                entity.MetaFuncs.MEStringsSelector.Unicode[] ul = sSwap.getUnicodesFromID(td.stringID.sidIndexer);

                screenData sd = ((screenData)lbScreensList.SelectedItem);
                // Default to first
                string s = ul.Length > 0 ? ul[0].unicode : string.Empty;
                for (int i = 0; i < ul.Length; i++)
                {
                    foreach (entity.MetaFuncs.MEStringsSelector.Unicode uni in sd.strings)
                        if (ul[i].position == uni.position)
                        {
                            s = ul[i].unicode;
                            i = ul.Length;
                            break;
                        }
                }


                // Create bitmap from Text
                if (s != string.Empty)
                {
                    bitmapData bd = Skin.createText(map, td, s, true);
                    if (bd != null)
                        lbd.Add(bd);
                }
                
                td.link = lbd;
            }

            #endregion

            // Transfer List Box Data to text boxes, etc
            showListBoxData();

            // link holds an array of last selected bitmap #s for each pane
            if (screenSelected.link != null)
            {
                int[] paneBitmapSelections = (int[])screenSelected.link;
                lbBitmaps.SelectedIndex = paneBitmapSelections[screenSelected.offset];
            }
            else
                lbBitmaps.SelectedIndex = 0;
            
        }