private void CreateRowFromArchetype(CMapTypes.Item archetype, DataGridView gridView) { var row = gridView.Rows[gridView.Rows.Add(1)]; row.Cells["propModel"].Value = archetype.name; row.Cells["textureDictionary"].Value = archetype.textureDictionary; row.Cells["lodDist"].Value = archetype.lodDist.value; int flagType; switch (archetype.flags.value) { case 12713984: flagType = 0; break; case 32: flagType = 1; break; default: flagType = -1; break; } var dataGridViewComboBoxCell = (DataGridViewComboBoxCell)row.Cells["flags"]; row.Cells["flags"].Value = flagType != -1 ? dataGridViewComboBoxCell.Items[flagType] : dataGridViewComboBoxCell.Items[dataGridViewComboBoxCell.Items.Add(archetype.flags.value.ToString())]; }
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { if (_reading) { return; } if (e.RowIndex == -1 || e.RowCount == 0) { return; } // Add a new archtype to the map. var item = new CMapTypes.Item(); Map.archetypes.Add(item); // Initialize the row with default values. var row = dataGridView1.Rows[e.RowIndex - 1]; row.Cells["propModel"].Value = string.Empty; row.Cells["textureDictionary"].Value = string.Empty; row.Cells["lodDist"].Value = "100.0"; row.Cells["flags"].Value = ((DataGridViewComboBoxCell)row.Cells["flags"]).Items[0]; SetArchetypeDataFromRow(row, ref item); }
private void SetArchetypeDataFromRow(DataGridViewRow row, ref CMapTypes.Item item) { // Model name. item.name = (string)row.Cells["propModel"].EditedFormattedValue; item.assetName = item.name; // Dictionaries. item.textureDictionary = string.IsNullOrEmpty(row.Cells["textureDictionary"].EditedFormattedValue.ToString()) ? item.name : row.Cells["textureDictionary"].EditedFormattedValue.ToString(); item.physicsDictionary = cMapNameTextBox.Text; // Lod distance. var lodDistCellValue = row.Cells["lodDist"].EditedFormattedValue; var lodValueString = lodDistCellValue.ToString(); double dVal; if (double.TryParse(lodValueString, out dVal)) { item.lodDist.value = dVal; } // Collision flag. var flagCell = (DataGridViewComboBoxCell)row.Cells["flags"]; var flagValueString = flagCell.EditedFormattedValue.ToString(); switch (flagValueString) { case "Dynamic": item.flags.value = 12713984; break; case "Static": item.flags.value = 32; break; default: int f; if (int.TryParse(flagValueString, out f)) { item.flags.value = f; } break; } // Set the physics dictionary. item.physicsDictionary = cMapNameTextBox.Text; // Bounds. item.bbMin = new XmlV3 { x = -100, y = -100, z = -100 }; item.bbMax = new XmlV3 { x = 100, y = 100, z = 100 }; }
private void dataGridView1_DragDrop(object sender, DragEventArgs e) { _reading = true; Cursor.Current = Cursors.Default; string[] files = (string[])e?.Data?.GetData(DataFormats.FileDrop, false); if (files == null) { return; } DragDropPresetForm ddpf = new DragDropPresetForm { Owner = this }; var row = ddpf.presetDataGrid.Rows[ddpf.presetDataGrid.Rows.Add(1)]; if (ddpf.ShowDialog() != DialogResult.OK) { return; } if (files.Length == 1 && files[0].EndsWith(".txt")) { var path = files[0]; var lines = File.ReadAllLines(path); foreach (var entry in lines) { var item = new CMapTypes.Item(); Map.archetypes.Add(item); SetArchetypeDataFromRow(row, ref item); item.name = entry; item.textureDictionary = item.name; CreateRowFromArchetype(item, dataGridView1); } return; } foreach (var entry in files) { var item = new CMapTypes.Item(); Map.archetypes.Add(item); SetArchetypeDataFromRow(row, ref item); item.name = Path.GetFileNameWithoutExtension(entry); item.textureDictionary = string.IsNullOrEmpty(row.Cells["textureDictionary"].EditedFormattedValue.ToString()) ? item.name : row.Cells["textureDictionary"].EditedFormattedValue.ToString(); CreateRowFromArchetype(item, dataGridView1); } ddpf.Close(); _reading = false; }