protected PerformanceFile(string _fileName, System.IO.Stream fileStream, CtfEditorGamePage _page) { name = System.IO.Path.GetFileName(_fileName); fileName = _fileName; parentPage = _page; hasChanges = false; }
public CtfFile(string _fileName, System.IO.Stream fileStream, CtfEditorGamePage _page) : base(_fileName, fileStream, _page) { int flag = -1; using (CtfBinaryReader reader = new CtfBinaryReader(EndianBitConverter.Little, fileStream)) { foreach (CtfEntryInfo entryInfo in parentPage.ctfEntryInfo) { try { if (entryInfo.name == "magic") { entry.Add(entryInfo.id, reader.ReadInt32()); } else if (entryInfo.name == "flag") { entry.Add(entryInfo.id, reader.ReadInt32()); flag = (int)entry[entryInfo.id]; } else if (entryInfo.IsUsed(flag)) { if (entryInfo.linkID != -1) { CtfEntryInfo linkedEntryInfo = parentPage.ctfEntryInfo.First(x => x.refID == entryInfo.linkID); if (Convert.ToBoolean(entry[linkedEntryInfo.id])) { entry.Add(entryInfo.id, reader.ReadEntryData(entryInfo.type)); } } else { entry.Add(entryInfo.id, reader.ReadEntryData(entryInfo.type)); } } } catch (Exception ex) { throw new Exception(ex.Message + Environment.NewLine + entryInfo.id + " " + entryInfo.name); } } CtfEntryInfo last = parentPage.ctfEntryInfo.Last(x => x.minFlag == 0); if (!entry.ContainsKey(last.id)) { throw new Exception("Reader did not read last required value"); } // Use -1 For Dirt 3, hopefully won't cause problems with other games //System.Windows.Forms.MessageBox.Show(reader.BaseStream.Position + " " + reader.BaseStream.Length); if (reader.BaseStream.Position < reader.BaseStream.Length - 1) { throw new Exception("Reader did not reach end of file!"); } parentPage.files.Add(this); } }
public DGVListEditor(CtfEditorGamePage page, int rowIndex) { InitializeComponent(); _rowIndex = rowIndex; // DataGridView Setup dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; dataGridView.DefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGridView.AllowUserToAddRows = false; dataGridView.AllowUserToDeleteRows = false; dataGridView.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#E8EDFF"); // Populate DGV for (int i = 0; i < page.files.Count; i++) { dataGridView.Columns.Add(i.ToString(), page.files[i].name); dataGridView.Columns[i].ToolTipText = page.files[i].fileName; dataGridView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; dataGridView.Columns[i].Tag = page.files[i]; if (i == 0) { dataGridView.TopLeftHeaderCell.Value = "Entry Name"; dataGridView.Rows.Add(); dataGridView.Rows.Add(); dataGridView.Rows[0].HeaderCell.Value = "Item Count"; dataGridView.Rows[0].ReadOnly = true; dataGridView.Rows[1].HeaderCell.Value = "Step"; } if (!page.files[i].entry.ContainsKey(rowIndex)) { continue; } dataGridView.Rows[0].Cells[i].Value = ((FloatList)page.files[i].entry[rowIndex]).count; dataGridView.Rows[1].Cells[i].Value = ((FloatList)page.files[i].entry[rowIndex]).step; dataGridView.Rows[1].Cells[i].ValueType = typeof(float); for (int j = 0; j < ((FloatList)page.files[i].entry[rowIndex]).count; j++) { if (dataGridView.Rows.Count - 2 <= j) { dataGridView.Rows.Add(); } dataGridView.Rows[j + 2].Cells[i].Value = ((FloatList)page.files[i].entry[rowIndex]).items[j]; dataGridView.Rows[j + 2].Cells[i].ValueType = typeof(float); dataGridView.Rows[j + 2].HeaderCell.Value = (j*((FloatList)page.files[i].entry[rowIndex]).step).ToString(); } } }
public CsvFile(string _fileName, System.IO.Stream fileStream, CtfEditorGamePage _page) : base(_fileName, fileStream, _page) { using (CsvStreamReader reader = new CsvStreamReader(fileStream)) { lines = reader.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); string[] values = lines[parentPage.lineIndex].Split(','); foreach (CtfEntryInfo entryInfo in parentPage.ctfEntryInfo) { try { entry.Add(entryInfo.id, reader.ReadEntryData(entryInfo.type, values[entryInfo.id], entryInfo.name)); } catch (Exception ex) { throw new Exception(ex.Message + Environment.NewLine + entryInfo.id + " " + entryInfo.name + " " + values[entryInfo.id]); } } parentPage.files.Add(this); } }
private void setupPage() { // Back out if the page has already been SetUp if (currentDgv != null) { ((DataGridView)mainTabControl.SelectedTab.Controls[0]).SelectionMode = DataGridViewSelectionMode.RowHeaderSelect; return; } CtfEditorGamePage page; // Setup Page if (mainTabControl.SelectedIndex == (int)CtfEditorMainTabs.Formula1) { page = new CtfEditorGamePage(File.Open(System.Windows.Forms.Application.StartupPath + "\\ctfSchemaF12012.xml", FileMode.Open), CtfEditorMainTabs.Formula1); } else if (mainTabControl.SelectedIndex == (int)CtfEditorMainTabs.Dirt) { page = new CtfEditorGamePage(File.Open(System.Windows.Forms.Application.StartupPath + "\\ctfSchemaDirt.xml", FileMode.Open), CtfEditorMainTabs.Dirt); } else if (mainTabControl.SelectedIndex == (int)CtfEditorMainTabs.Other) { page = new CtfEditorGamePage(File.Open(System.Windows.Forms.Application.StartupPath + "\\ctfSchemaGrid2.xml", FileMode.Open), CtfEditorMainTabs.Other); } else if (mainTabControl.SelectedIndex == (int)CtfEditorMainTabs.Grid) { page = new CtfEditorGamePage(File.Open(System.Windows.Forms.Application.StartupPath + "\\ctfSchemaGrid.xml", FileMode.Open), CtfEditorMainTabs.Grid); } else { // SHOULD NOT HAPPEN, just doing it to satisfy compiler return; } // Setup DGV DataGridView dgv; dgv = new DataGridView(); dgv.Dock = DockStyle.Fill; //dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; //dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells; dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; //dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; dgv.DefaultCellStyle.WrapMode = DataGridViewTriState.True; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#E8EDFF"); dgv.TopLeftHeaderCell.Value = "ID"; dgv.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect; dgv.CellValueChanged += new DataGridViewCellEventHandler(dgv_CellValueChanged); dgv.CellBeginEdit += new DataGridViewCellCancelEventHandler(dgv_CellBeginEdit); dgv.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(dgv_ColumnHeaderMouseClick); dgv.CellMouseDown += new DataGridViewCellMouseEventHandler(dgv_CellMouseDown); dgv.DataError += new DataGridViewDataErrorEventHandler(dgv_DataError); dgv.CellEnter += new DataGridViewCellEventHandler(dgv_CellEnter); dgv.KeyDown += new KeyEventHandler(dgv_KeyDown); dgv.ColumnHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(dgv_ColumnHeaderMouseDoubleClick); // Load Page Contents mainTabControl.SelectedTab.Tag = page; dgv.Columns.Add("entryName", "Entry Name"); dgv.Columns[0].MinimumWidth = 150; dgv.Columns[0].ValueType = typeof(string); dgv.Columns[0].ReadOnly = true; dgv.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; DGVColumnFilterContextControl colFilter = new DGVColumnFilterContextControl(dgv, 0); dgv.SuspendDrawing(); foreach (CtfEntryInfo entryInfo in page.ctfEntryInfo) { dgv.Rows.Add(entryInfo.name); dgv.Rows[entryInfo.id].HeaderCell.Value = Convert.ToString(entryInfo.id); //entryInfo.id == 0 || entryInfo.id == 1 || entryInfo.refID >= 0 || if (entryInfo.readOnly) { dgv.Rows[entryInfo.id].ReadOnly = true; } } dgv.ResumeDrawing(); mainTabControl.SelectedTab.Controls.Add(dgv); ActiveControl = currentDgv; }