private void addEntryToolStripMenuItem_Click(object sender, EventArgs e) { FormNewGameBINEntry form = new FormNewGameBINEntry(myBIN); if (form.ShowDialog(this) == DialogResult.OK) { byte[] data = null; BINEntry defEntry = myBIN.GetEntryByName( form.Template); if (defEntry == null) { form.Dispose(); form = null; MessageBox.Show(this, "Default entry not found."); return; } data = defEntry.Data; BINEntry entry = myBIN.AddEntry( form.SymbolName, form.Definition, data); DefinitionType defType = ContentManager.Instance.Definitions.GetDefinition( form.Definition); defType.ReadIn(entry); defType.FixLinks( LinkDestination.GameBINEntryID, defEntry.ID, entry.ID); defType.Write(entry); treeView.SelectedNode = AddEntry(entry); data = null; } form.Dispose(); form = null; }
private void buttonOk_Click(object sender, EventArgs e) { if (textBoxName.Text.Length == 0) { FormMain.Instance.ErrorMessage( "Invalid base name. It can not be empty."); return; } string name = textBoxName.Text; Dictionary <int, BINEntry> binEntries = new Dictionary <int, BINEntry>(); Dictionary <int, AssetEntry> assetEntries = new Dictionary <int, AssetEntry>(); // Build the objects... StringBuilder sb = new StringBuilder(); sb.AppendLine("Created objects:"); for (int i = 0; i < myTemplate.ItemCount; ++i) { BaseTemplate item = myTemplate.get_Items(i); bool isRef = myRefCheckBoxes[item.ID].Checked; object selItem = myComboBoxes[item.ID].SelectedItem; if (selItem == null) { continue; } if (item.GetType() == typeof(DefTypeTemplate)) { DefTypeTemplate defItem = item as DefTypeTemplate; BINEntry defEntry = GetBINEntry(selItem.ToString()); if (defEntry != null) { string objName = defItem.Type + "_" + name; if (!checkBoxNamed.Checked) { // Not on, so check the item flag. if (!item.Named) { objName = ""; } } BINEntry entry = null; if (isRef) { entry = defEntry; } else { entry = myGameBin.AddEntry( objName, defItem.Type, defEntry.Data); entry.Modified = true; if (!string.IsNullOrEmpty(entry.Name)) { sb.AppendFormat(" {0}", entry.Name); } else { sb.AppendFormat(" {0}:{1}", entry.Definition, entry.ID); } sb.AppendLine(""); } binEntries.Add(item.ID, entry); } else { FormMain.Instance.ErrorMessage("Entry not found"); } } else { AssetEntry defEntry = ((AssetComboBoxItem)selItem).Entry; if (defEntry != null) { AssetEntry entry; if (isRef) { entry = defEntry; } else { AssetTemplate assetItem = item as AssetTemplate; entry = defEntry.Bank.NewEntry( GetAssetName( defEntry.Bank, assetItem.Prefix + "_" + name), defEntry.Type); entry.SubHeader = defEntry.SubHeader; entry.Data = defEntry.Data; sb.AppendFormat(" {0}", entry.DevSymbolName); sb.AppendLine(""); } assetEntries.Add(item.ID, entry); } } } // Link objects! for (int i = 0; i < myTemplate.ItemCount; ++i) { BaseTemplate item = myTemplate.get_Items(i); if (item.LinkTo == null) { continue; } DefTypeTemplate defLink = item.LinkTo; if (item.GetType() == typeof(DefTypeTemplate)) { DefTypeLink( binEntries[defLink.ID], binEntries[item.ID], item.Name); } else { AssetEntry assetEntry = null; if (assetEntries.TryGetValue(item.ID, out assetEntry)) { AssetLink( binEntries[defLink.ID], (AssetTemplate)item, assetEntry.ID); } } } DefTypeTemplate baseItem = (DefTypeTemplate)myTemplate.get_Items(0); FixMainEntry(binEntries[baseItem.ID], baseItem.OriginalID); binEntries = null; assetEntries = null; FormMain.Instance.InfoMessage(sb.ToString()); }