private void comboBoxTemplates_DropDown(object sender, EventArgs e) { if (myRenewTemplates) { myRenewTemplates = false; BINEntry[] entries = myBIN.GetEntriesByDefinition(Definition); comboBoxTemplates.Items.Clear(); foreach (BINEntry entry in entries) { if (entry.Name != "") { comboBoxTemplates.Items.Add(entry.Name); } } entries = null; } }
private void comboBoxTemplate_DropDownClosed(object sender, EventArgs e) { if (comboBoxTemplate.SelectedIndex < 0) { panelTemplate.Visible = false; buttonCreate.Enabled = false; return; } BINEntry entry = myGameBin.GetEntryByName( comboBoxTemplate.SelectedItem.ToString()); myTemplate.Build(entry); panelProgress.Visible = true; panelProgress.Update(); panelTemplate.Visible = false; panelTemplate.Controls.Clear(); panelTemplate.SuspendLayout(); myComboBoxes.Clear(); myRefCheckBoxes.Clear(); int x = labelTemplate.Left; int y = 5; int width = 0; int height = 0; int yspace = 10; CheckBox objCheckBox = new CheckBox(); // This should be the main object type. myComboBoxes.Add( myTemplate.get_Items(0).ID, comboBoxTemplate); myRefCheckBoxes.Add( myTemplate.get_Items(0).ID, objCheckBox); comboBoxTemplate.Tag = 0; // Start from the child items... for (int i = 1; i < myTemplate.ItemCount; ++i) { Label lbl = new Label(); lbl.AutoSize = true; lbl.Text = myTemplate.get_Items(i).Name + ":"; panelTemplate.Controls.Add(lbl); lbl.Left = x; lbl.Top = y; y += lbl.Height + yspace; if (lbl.Width > width) { width = lbl.Width; } if (lbl.Height > height) { height = lbl.Height; } } y = 5; int right = panelTop.Width - comboBoxDefs.Right; progressBar.Value = 0; progressBar.Maximum = myTemplate.ItemCount; progressBar.Update(); for (int i = 1; i < myTemplate.ItemCount; ++i) { BaseTemplate item = myTemplate.get_Items(i); ComboBox comboBox = NewComboBox(item.Name); panelTemplate.Controls.Add(comboBox); comboBox.Left = width + x + 5; comboBox.Top = y; comboBox.Width = comboBoxDefs.Right - comboBox.Left - 80; comboBox.Anchor |= AnchorStyles.Right; comboBox.DropDownStyle = ComboBoxStyle.DropDownList; comboBox.AutoCompleteSource = AutoCompleteSource.ListItems; comboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend; comboBox.Tag = i; comboBox.Sorted = true; //comboBox.Enabled = string.IsNullOrEmpty(item.LinkTo); if (item.GetType() == typeof(DefTypeTemplate)) { DefTypeTemplate def = item as DefTypeTemplate; if (comboBox.Items.Count == 0) { // Fill it up. BINEntry[] entries = myGameBin.GetEntriesByDefinition(def.Type); foreach (BINEntry ent in entries) { comboBox.Items.Add((ent.Name.Length > 0) ? ent.Name : ent.ID.ToString()); } } } else { if (comboBox.Items.Count == 0) { // New combobox. AssetFill(comboBox, (AssetTemplate)item); } } if (comboBox.Items.Count > 0) { comboBox.SelectedIndex = 0; } comboBox.SelectedIndexChanged += new EventHandler(itemComboBox_SelectedIndexChanged); y += height + yspace; // We need to access this later. myComboBoxes.Add(item.ID, comboBox); progressBar.Value++; progressBar.Update(); } // Add ref checkboxes... for (int i = 1; i < myTemplate.ItemCount; ++i) { BaseTemplate item = myTemplate.get_Items(i); CheckBox checkBox = new CheckBox(); panelTemplate.Controls.Add(checkBox); checkBox.Left = myComboBoxes[item.ID].Right + 5; checkBox.Top = myComboBoxes[item.ID].Top; checkBox.Text = "Ref"; checkBox.Checked = item.Ref; checkBox.Anchor = AnchorStyles.Top | AnchorStyles.Right; toolTip.SetToolTip( checkBox, "Use this object as a reference"); // We need to access this later. myRefCheckBoxes.Add(item.ID, checkBox); } // Add the boxes to the pool, so we can use them later. for (int i = 1; i < myTemplate.ItemCount; ++i) { BaseTemplate item = myTemplate.get_Items(i); AddToPool(item.Name, myComboBoxes[item.ID]); } UpdateLinks(comboBoxTemplate); panelTemplate.ResumeLayout(); panelTemplate.Visible = true; panelTemplate.Visible = true; buttonCreate.Enabled = true; panelProgress.Visible = false; panelProgress.Update(); }