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;
}