상속: baseData
예제 #1
0
        private void lbScreensList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbScreensList.Focused)
                writePaneToMemory();

            currentScreen = (screenData)lbScreensList.SelectedItem;

            currentScreen.panes.Clear();

            br = new BinaryReader(currentScreen.meta.MS);

            br.BaseStream.Position = 32;    // Panes reflexive
            int panesCount = br.ReadInt32();
            int panesOffset = br.ReadInt32() - map.SecondaryMagic;
            int metaOffset = currentScreen.meta.offset;
            Meta m = currentScreen.meta;

            BinaryReader br2 = br;
            #region Handle pointers to other tags
            int panesTag = map.Functions.ForMeta.FindMetaByOffset(panesOffset);
            if (panesTag != -1 && panesTag != currentScreen.meta.TagIndex)
            {
                m = Map.GetMetaFromTagIndex(panesTag, map, false, true);
                br2 = new BinaryReader(m.MS);
                metaOffset = m.offset;
            }
            #endregion

            for (int panes = 0; panes < panesCount; panes++)
            {
                paneData pd = new paneData(panes);
                pd.meta = m;
                pd.offset = panesOffset - metaOffset + panes * 76;  // Store panes offset for quicker access
                pd.title = panes.ToString() + ": ";

                br2.BaseStream.Position = panesOffset - metaOffset + panes * 76 + 28;  // Text Block
                int textCount = br2.ReadInt32();
                int textOffset = br2.ReadInt32() - map.SecondaryMagic;

                if (textCount > 0)
                {
                    BinaryReader br3 = br2;

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

                    br3.BaseStream.Position = textOffset + 36;  // Text Block
                    short SIDNum = br3.ReadInt16();
                    byte unknown = br3.ReadByte();
                    byte SIDLength = br3.ReadByte();
                    string name = map.Strings.Name[SIDNum];
                    if (name.Length == SIDLength && name.Length != 0)
                        pd.title += name;
                }
                else
                    pd.title += lbScreensList.SelectedItem.ToString();
                currentScreen.panes.Add(pd);
            }
            
            lbPanes.DataSource = currentScreen.panes;
            // Actually update ListBox with data source
            ((CurrencyManager)lbPanes.BindingContext[lbPanes.DataSource]).Refresh();

            if (lbPanes.Items.Count > 0)
            {
                lbPanes.SelectedIndex = -1; // force it to reload, even if same pane is selected
                lbPanes.SelectedIndex = ((baseData)lbScreensList.SelectedItem).offset;
            }
        }
예제 #2
0
        private bool loadMainMenuData(string mainmenuFileName)
        {
            this.Cursor = Cursors.WaitCursor;
            if (map != null)
            {
                map.CloseMap();
                map = null;
            }
            map = Map.LoadFromFile(mainmenuFileName);
            if (map == null)
            {
                this.Cursor = Cursors.Arrow;
                MessageBox.Show("Load failed! Map not found or inaccessible.\n" + mainmenuFileName);
                return false;
            }

            cbBitmapIdent.DataSource = null;
            cbBitmapIdent.Items.Clear();
            cbBitmapIdent.Items.Add(new baseData(0));
            ((baseData)cbBitmapIdent.Items[0]).title = "<null>";
            int orderCount = 0;
            for (int i = 0; i < map.FileNames.Name.Length; i++)
            {
                if (map.MetaInfo.TagType[i] == "bitm")
                {
                    baseData sd = new baseData(++orderCount);
                    sd.offset = i;
                    sd.title = map.FileNames.Name[i];
                    cbBitmapIdent.Items.Add(sd);
                }
            }

            Meta meta;
            
            // Get the tag index for [matg] globals\\globals
            int matgIndex = map.Functions.ForMeta.FindByNameAndTagType("matg", "globals\\globals");
            meta = Map.GetMetaFromTagIndex(matgIndex, map, false, true);
            br = new BinaryReader(meta.MS);

            br.BaseStream.Position = 272;
            int interfaceItemCount = br.ReadInt32();
            int interfaceItemOffset = br.ReadInt32() - map.SecondaryMagic - meta.offset;

            br.BaseStream.Position = interfaceItemOffset + 128;
            // Mainmenu Menus (Exists in Mainmenu.map)
            char[] wgtzMMTag = br.ReadChars(4);
            int wgtzMMIdent = br.ReadInt32();
            // Single Player Menus (Exists in Shared / SPShared.map)
            char[] wgtzSPTag = br.ReadChars(4);
            int wgtzSPIdent = br.ReadInt32();
            // Multiplayer Menus (Exists in Shared / SPShared.map)
            char[] wgtzMPTag = br.ReadChars(4);
            int wgtzMPIdent = br.ReadInt32();

            int tagIndex = -1;
            // Get the tag index for [wgtz] ui\\main_menu
            if (wgtzMMIdent != -1)
                tagIndex = (int)map.MetaInfo.identHT[wgtzMMIdent];
            else if (wgtzSPIdent != -1)
                tagIndex = (int)map.MetaInfo.identHT[wgtzSPIdent];
            else if (wgtzMPIdent != -1)
                tagIndex = (int)map.MetaInfo.identHT[wgtzMPIdent];
            //int tagIndex = map.Functions.ForMeta.FindByNameAndTagType("wgtz", "ui\\main_menu");
            if (tagIndex == -1)
            {
                map.CloseMap();
                map = null;
                this.Cursor = Cursors.Arrow;
                MessageBox.Show("Load failed! Not a MAINMENU.MAP / SHARED.MAP / SPSHARED.MAP file.\n" + mainmenuFileName);
                return false;
            }

            // [wgzt] ui\\main_menu meta
            meta = Map.GetMetaFromTagIndex(tagIndex, map, false, true);
            br = new BinaryReader(meta.MS);

            #region Skins List Loading Section
            br.BaseStream.Position = 0;
            char[] wiglTag = br.ReadChars(4); 
            int wiglIdent = br.ReadInt32();

            // Should be "ui\ui_shared_globals" by default
            int tagNum = (int)map.MetaInfo.identHT[wiglIdent];
            Meta metaSG = Map.GetMetaFromTagIndex(tagNum, map, false, true);
            BinaryReader brSG = new BinaryReader(metaSG.MS);

            // Get the default header font number
            brSG.BaseStream.Position = 352;
            defaultHeaderFont = brSG.ReadInt16();
            
            // Get the default position of the header text
            brSG.BaseStream.Position = 376;
            short dhTop = brSG.ReadInt16();
            short dhLeft = brSG.ReadInt16();
            short dhBottom = brSG.ReadInt16();
            short dhRight = brSG.ReadInt16();
            defaultHeaderPos = new Rectangle(dhLeft, dhTop, dhRight-dhLeft, dhBottom-dhTop);

            // Get the skin data
            brSG.BaseStream.Position = 312;
            int listItemCount = brSG.ReadInt32();
            int listItemOffset = brSG.ReadInt32() - map.SecondaryMagic - metaSG.offset;

            for (int list = 0; list < listItemCount; list++)
            {
                brSG.BaseStream.Position = listItemOffset + list * 8;
                char[] skinTag = brSG.ReadChars(4);
                int skinIdent = brSG.ReadInt32();

                tagNum = (int)map.MetaInfo.identHT[skinIdent];
                string[] tagData = map.FileNames.Name[tagNum].Split('\\');

                skinData sd = new skinData();
                sd.offset = 0;
                sd.title = "[" + list.ToString("00") + "] " + tagData[tagData.Length - 1];
                sd.meta = Map.GetMetaFromTagIndex(tagNum, map, false, true);
                
                sd.skin  = new Skin(map, skinIdent);

                cbLBSkinIdent.Items.Add(sd);
            }

            #endregion

            #region Graphics Loading Section

            // Load Mainmenu screens tag
            // Offset 8 = Screen Widgets refelxive
            br.BaseStream.Position = 8;
            int screenCount = br.ReadInt32(); // Number of screen widgets
            int screenOffset = br.ReadInt32() - map.SecondaryMagic - meta.offset;

            // Release any memory from previously loaded menus (if any)
            //foreach(screenData sd in lbScreensList.Items)
            //    sd.meta.Dispose();
            //lbScreensList.Items.Clear();

            foreach (screenData sd in screens)
                sd.meta.Dispose();
            screens.Clear();

            // For each tag/ident screen widget entry in [wgzt] ui\\main_menu...
            for (int screen = 0; screen < screenCount; screen++)
            {
                // Offset 0 in each reflexive listing points to screen widget
                br.BaseStream.Position = screenOffset + screen * 8;
                char[] wgitTag = br.ReadChars(4);
                int wgitIdent = br.ReadInt32();

                // Retrieve the screen widget Tag Index & name and read in the [wigt] meta
                // These are all stored into the lbScreenList list box items
                tagNum = (int)map.MetaInfo.identHT[wgitIdent];
                string[] tagData = map.FileNames.Name[tagNum].Split('\\');
                screenData sd = new screenData(screen);
                sd.offset = 0;
                sd.title = tagData[tagData.Length - 1];
                sd.meta = Map.GetMetaFromTagIndex(tagNum, map, false, true);
                sd.meta.MS.Position = 0;
                sd.Read(new BinaryReader(sd.meta.MS));
                sd.getStrings(map);

                //lbScreensList.Items.Add(sd);
                screens.Add(sd);
            }

            //screens.Sort();
            
            lbScreensList.DataSource = screens;
            // Actually update ListBox with data source
            ((CurrencyManager)lbScreensList.BindingContext[lbScreensList.DataSource]).Refresh();
            if (lbScreensList.Items.Count > 0)
            {
                lbScreensList.SelectedIndex = 0;
                // Make sure this is called to update the Panes ListBox on reload
                lbScreensList_SelectedIndexChanged(this, null);
            }
            #endregion

            //br.Close();        

            this.Cursor = Cursors.Arrow;
            return true;
        }