From aac00e5070c75fbc1518cc0233efd58aaf578f83 Mon Sep 17 00:00:00 2001 From: Lucas7yoshi Date: Wed, 12 Jan 2022 14:35:38 -0500 Subject: [PATCH] yvr/ywr form redo --- CodeWalker/Forms/YvrForm.Designer.cs | 202 ++++++++++++++++++++++++--- CodeWalker/Forms/YvrForm.cs | 142 ++++++++++++------- CodeWalker/Forms/YvrForm.resx | 3 + CodeWalker/Forms/YwrForm.Designer.cs | 118 +++++++++++++--- CodeWalker/Forms/YwrForm.cs | 90 ++++++++---- CodeWalker/Forms/YwrForm.resx | 3 + 6 files changed, 448 insertions(+), 110 deletions(-) diff --git a/CodeWalker/Forms/YvrForm.Designer.cs b/CodeWalker/Forms/YvrForm.Designer.cs index be8f66a..386bff3 100644 --- a/CodeWalker/Forms/YvrForm.Designer.cs +++ b/CodeWalker/Forms/YvrForm.Designer.cs @@ -30,13 +30,34 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(YvrForm)); this.CloseButton = new System.Windows.Forms.Button(); - this.MainTextBox = new CodeWalker.WinForms.TextBoxFix(); + this.MainListView = new System.Windows.Forms.ListView(); + this.PosXColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.PosYColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.PosZColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.TimeColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.VelocityXColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.VelocityYColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.VelocityZColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.RightXColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.RightYColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.RightZColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.TopXColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.TopYColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.TopZColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.SteeringAngleColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.GasPedalPowerColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.BrakePedalPowerColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.HandbrakeUsedColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.ExportButton = new System.Windows.Forms.Button(); + this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.CopyClipboardButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // // CloseButton // this.CloseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.CloseButton.Location = new System.Drawing.Point(597, 389); + this.CloseButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.CloseButton.Location = new System.Drawing.Point(845, 389); this.CloseButton.Name = "CloseButton"; this.CloseButton.Size = new System.Drawing.Size(75, 23); this.CloseButton.TabIndex = 5; @@ -44,39 +65,186 @@ this.CloseButton.UseVisualStyleBackColor = true; this.CloseButton.Click += new System.EventHandler(this.CloseButton_Click); // - // MainTextBox + // MainListView // - this.MainTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.MainListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.MainTextBox.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.MainTextBox.HideSelection = false; - this.MainTextBox.Location = new System.Drawing.Point(12, 12); - this.MainTextBox.Multiline = true; - this.MainTextBox.Name = "MainTextBox"; - this.MainTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.MainTextBox.Size = new System.Drawing.Size(660, 371); - this.MainTextBox.TabIndex = 4; - this.MainTextBox.WordWrap = false; + this.MainListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.PosXColumn, + this.PosYColumn, + this.PosZColumn, + this.TimeColumn, + this.VelocityXColumn, + this.VelocityYColumn, + this.VelocityZColumn, + this.RightXColumn, + this.RightYColumn, + this.RightZColumn, + this.TopXColumn, + this.TopYColumn, + this.TopZColumn, + this.SteeringAngleColumn, + this.GasPedalPowerColumn, + this.BrakePedalPowerColumn, + this.HandbrakeUsedColumn}); + this.MainListView.HideSelection = false; + this.MainListView.Location = new System.Drawing.Point(12, 12); + this.MainListView.Name = "MainListView"; + this.MainListView.Size = new System.Drawing.Size(908, 371); + this.MainListView.TabIndex = 6; + this.MainListView.UseCompatibleStateImageBehavior = false; + this.MainListView.View = System.Windows.Forms.View.Details; + // + // PosXColumn + // + this.PosXColumn.Text = "X Pos"; + this.PosXColumn.Width = 72; + // + // PosYColumn + // + this.PosYColumn.Text = "Y Pos"; + this.PosYColumn.Width = 72; + // + // PosZColumn + // + this.PosZColumn.Text = "Z Pos"; + this.PosZColumn.Width = 72; + // + // TimeColumn + // + this.TimeColumn.Text = "Time"; + this.TimeColumn.Width = 55; + // + // VelocityXColumn + // + this.VelocityXColumn.Text = "X Velocity"; + this.VelocityXColumn.Width = 48; + // + // VelocityYColumn + // + this.VelocityYColumn.Text = "Y Velocity"; + this.VelocityYColumn.Width = 48; + // + // VelocityZColumn + // + this.VelocityZColumn.Text = "Z Velocity"; + this.VelocityZColumn.Width = 48; + // + // RightXColumn + // + this.RightXColumn.Text = "Right X"; + this.RightXColumn.Width = 48; + // + // RightYColumn + // + this.RightYColumn.Text = "Right Y"; + this.RightYColumn.Width = 48; + // + // RightZColumn + // + this.RightZColumn.Text = "Right Z"; + this.RightZColumn.Width = 48; + // + // TopXColumn + // + this.TopXColumn.Text = "Top X"; + this.TopXColumn.Width = 44; + // + // TopYColumn + // + this.TopYColumn.Text = "Top Y"; + this.TopYColumn.Width = 44; + // + // TopZColumn + // + this.TopZColumn.Text = "Top Z"; + this.TopZColumn.Width = 44; + // + // SteeringAngleColumn + // + this.SteeringAngleColumn.Text = "Steer Angle"; + this.SteeringAngleColumn.Width = 47; + // + // GasPedalPowerColumn + // + this.GasPedalPowerColumn.Text = "Gas Power"; + this.GasPedalPowerColumn.Width = 42; + // + // BrakePedalPowerColumn + // + this.BrakePedalPowerColumn.Text = "Brake Power"; + this.BrakePedalPowerColumn.Width = 50; + // + // HandbrakeUsedColumn + // + this.HandbrakeUsedColumn.Text = "Handbrake"; + this.HandbrakeUsedColumn.Width = 65; + // + // ExportButton + // + this.ExportButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ExportButton.Enabled = false; + this.ExportButton.Location = new System.Drawing.Point(764, 389); + this.ExportButton.Name = "ExportButton"; + this.ExportButton.Size = new System.Drawing.Size(75, 23); + this.ExportButton.TabIndex = 7; + this.ExportButton.Text = "Export"; + this.ExportButton.UseVisualStyleBackColor = true; + this.ExportButton.Click += new System.EventHandler(this.ExportButton_Click); + // + // CopyClipboardButton + // + this.CopyClipboardButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.CopyClipboardButton.Enabled = false; + this.CopyClipboardButton.Location = new System.Drawing.Point(656, 389); + this.CopyClipboardButton.Name = "CopyClipboardButton"; + this.CopyClipboardButton.Size = new System.Drawing.Size(102, 23); + this.CopyClipboardButton.TabIndex = 8; + this.CopyClipboardButton.Text = "Copy to clipboard"; + this.CopyClipboardButton.UseVisualStyleBackColor = true; + this.CopyClipboardButton.Click += new System.EventHandler(this.CopyClipboardButton_Click); // // YvrForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(684, 421); + this.CancelButton = this.CloseButton; + this.ClientSize = new System.Drawing.Size(932, 421); + this.Controls.Add(this.CopyClipboardButton); + this.Controls.Add(this.ExportButton); + this.Controls.Add(this.MainListView); this.Controls.Add(this.CloseButton); - this.Controls.Add(this.MainTextBox); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "YvrForm"; this.Text = "Vehicle Records Viewer - CodeWalker by dexyfex"; this.ResumeLayout(false); - this.PerformLayout(); } #endregion private System.Windows.Forms.Button CloseButton; - private WinForms.TextBoxFix MainTextBox; + private System.Windows.Forms.ListView MainListView; + private System.Windows.Forms.ColumnHeader PosXColumn; + private System.Windows.Forms.ColumnHeader PosYColumn; + private System.Windows.Forms.ColumnHeader PosZColumn; + private System.Windows.Forms.ColumnHeader TimeColumn; + private System.Windows.Forms.ColumnHeader VelocityXColumn; + private System.Windows.Forms.ColumnHeader VelocityYColumn; + private System.Windows.Forms.ColumnHeader VelocityZColumn; + private System.Windows.Forms.ColumnHeader RightXColumn; + private System.Windows.Forms.ColumnHeader RightYColumn; + private System.Windows.Forms.ColumnHeader RightZColumn; + private System.Windows.Forms.ColumnHeader TopXColumn; + private System.Windows.Forms.ColumnHeader TopYColumn; + private System.Windows.Forms.ColumnHeader TopZColumn; + private System.Windows.Forms.ColumnHeader SteeringAngleColumn; + private System.Windows.Forms.ColumnHeader GasPedalPowerColumn; + private System.Windows.Forms.ColumnHeader BrakePedalPowerColumn; + private System.Windows.Forms.ColumnHeader HandbrakeUsedColumn; + private System.Windows.Forms.Button ExportButton; + private System.Windows.Forms.SaveFileDialog saveFileDialog; + private System.Windows.Forms.Button CopyClipboardButton; } } \ No newline at end of file diff --git a/CodeWalker/Forms/YvrForm.cs b/CodeWalker/Forms/YvrForm.cs index a440696..847aa29 100644 --- a/CodeWalker/Forms/YvrForm.cs +++ b/CodeWalker/Forms/YvrForm.cs @@ -1,5 +1,6 @@ using CodeWalker.GameFiles; using System; +using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -15,6 +16,7 @@ namespace CodeWalker.Forms { private string fileName; + private YvrFile yvr; public string FileName { get { return fileName; } @@ -41,10 +43,9 @@ namespace CodeWalker.Forms Text = fileName + " - Vehicle Records Viewer - CodeWalker by dexyfex"; } - - public void LoadYvr(YvrFile yvr) { + this.yvr = yvr; fileName = yvr?.Name; if (string.IsNullOrEmpty(fileName)) { @@ -53,65 +54,106 @@ namespace CodeWalker.Forms UpdateFormTitle(); - - StringBuilder sb = new StringBuilder(); - if ((yvr != null) && (yvr.Records != null) && (yvr.Records.Entries != null) && (yvr.Records.Entries.data_items != null)) { - sb.AppendLine("PositionX, PositionY, PositionZ, Time, VelocityX, VelocityY, VelocityZ, RightX, RightY, RightZ, TopX, TopY, TopZ, SteeringAngle, GasPedalPower, BrakePedalPower, HandbrakeUsed"); - foreach (var entry in yvr.Records.Entries.data_items) - { - sb.Append(FloatUtil.ToString(entry.PositionX)); - sb.Append(", "); - sb.Append(FloatUtil.ToString(entry.PositionY)); - sb.Append(", "); - sb.Append(FloatUtil.ToString(entry.PositionZ)); - sb.Append(", "); - sb.Append(entry.Time.ToString()); - sb.Append(", "); - sb.Append(entry.VelocityX.ToString()); - sb.Append(", "); - sb.Append(entry.VelocityY.ToString()); - sb.Append(", "); - sb.Append(entry.VelocityZ.ToString()); - sb.Append(", "); - sb.Append(entry.RightX.ToString()); - sb.Append(", "); - sb.Append(entry.RightY.ToString()); - sb.Append(", "); - sb.Append(entry.RightZ.ToString()); - sb.Append(", "); - sb.Append(entry.TopX.ToString()); - sb.Append(", "); - sb.Append(entry.TopY.ToString()); - sb.Append(", "); - sb.Append(entry.TopZ.ToString()); - sb.Append(", "); - sb.Append(entry.SteeringAngle.ToString()); - sb.Append(", "); - sb.Append(entry.GasPedalPower.ToString()); - sb.Append(", "); - sb.Append(entry.BrakePedalPower.ToString()); - sb.Append(", "); - sb.Append(entry.HandbrakeUsed.ToString()); - sb.AppendLine(); - } + ExportButton.Enabled = true; + CopyClipboardButton.Enabled = true; + LoadListView(); } - else - { - sb.AppendLine("Unable to load Vehicle Records."); - } - - MainTextBox.Text = sb.ToString(); - } + private string GenerateText() + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine("PositionX, PositionY, PositionZ, Time, VelocityX, VelocityY, VelocityZ, RightX, RightY, RightZ, TopX, TopY, TopZ, SteeringAngle, GasPedalPower, BrakePedalPower, HandbrakeUsed"); + foreach (var entry in yvr.Records.Entries.data_items) + { + sb.Append(FloatUtil.ToString(entry.PositionX)); + sb.Append(", "); + sb.Append(FloatUtil.ToString(entry.PositionY)); + sb.Append(", "); + sb.Append(FloatUtil.ToString(entry.PositionZ)); + sb.Append(", "); + sb.Append(entry.Time.ToString()); + sb.Append(", "); + sb.Append(entry.VelocityX.ToString()); + sb.Append(", "); + sb.Append(entry.VelocityY.ToString()); + sb.Append(", "); + sb.Append(entry.VelocityZ.ToString()); + sb.Append(", "); + sb.Append(entry.RightX.ToString()); + sb.Append(", "); + sb.Append(entry.RightY.ToString()); + sb.Append(", "); + sb.Append(entry.RightZ.ToString()); + sb.Append(", "); + sb.Append(entry.TopX.ToString()); + sb.Append(", "); + sb.Append(entry.TopY.ToString()); + sb.Append(", "); + sb.Append(entry.TopZ.ToString()); + sb.Append(", "); + sb.Append(entry.SteeringAngle.ToString()); + sb.Append(", "); + sb.Append(entry.GasPedalPower.ToString()); + sb.Append(", "); + sb.Append(entry.BrakePedalPower.ToString()); + sb.Append(", "); + sb.Append(entry.HandbrakeUsed.ToString()); + sb.AppendLine(); + } + return sb.ToString(); + } + public void LoadListView() + { + MainListView.BeginUpdate(); // performance + foreach (var entry in yvr.Records.Entries.data_items) + { + string[] row = + { + FloatUtil.ToString(entry.PositionX), + FloatUtil.ToString(entry.PositionY), + FloatUtil.ToString(entry.PositionZ), + entry.Time.ToString(), + entry.VelocityX.ToString(), + entry.VelocityY.ToString(), + entry.VelocityZ.ToString(), + entry.RightX.ToString(), + entry.RightY.ToString(), + entry.RightZ.ToString(), + entry.TopX.ToString(), + entry.TopY.ToString(), + entry.TopZ.ToString(), + entry.SteeringAngle.ToString(), + entry.GasPedalPower.ToString(), + entry.BrakePedalPower.ToString(), + entry.HandbrakeUsed.ToString(), + }; + MainListView.Items.Add(new ListViewItem(row)); + } + MainListView.EndUpdate(); + } private void CloseButton_Click(object sender, EventArgs e) { Close(); } + + private void ExportButton_Click(object sender, EventArgs e) + { + saveFileDialog.FileName = Path.GetFileNameWithoutExtension(fileName) + ".csv"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + File.WriteAllText(saveFileDialog.FileName, GenerateText()); + } + } + + private void CopyClipboardButton_Click(object sender, EventArgs e) + { + Clipboard.SetText(GenerateText()); + } } } diff --git a/CodeWalker/Forms/YvrForm.resx b/CodeWalker/Forms/YvrForm.resx index 1431f6b..8d4a312 100644 --- a/CodeWalker/Forms/YvrForm.resx +++ b/CodeWalker/Forms/YvrForm.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + diff --git a/CodeWalker/Forms/YwrForm.Designer.cs b/CodeWalker/Forms/YwrForm.Designer.cs index 09245a2..a6c8fa6 100644 --- a/CodeWalker/Forms/YwrForm.Designer.cs +++ b/CodeWalker/Forms/YwrForm.Designer.cs @@ -30,13 +30,24 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(YwrForm)); this.CloseButton = new System.Windows.Forms.Button(); - this.MainTextBox = new CodeWalker.WinForms.TextBoxFix(); + this.MainListView = new System.Windows.Forms.ListView(); + this.ExportButton = new System.Windows.Forms.Button(); + this.CopyClipboardButton = new System.Windows.Forms.Button(); + this.XPosColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.YPosColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.ZPosColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.Unk0Column = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.Unk1Column = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.Unk2Column = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.Unk3Column = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.SuspendLayout(); // // CloseButton // this.CloseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.CloseButton.Location = new System.Drawing.Point(597, 389); + this.CloseButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.CloseButton.Location = new System.Drawing.Point(417, 389); this.CloseButton.Name = "CloseButton"; this.CloseButton.Size = new System.Drawing.Size(75, 23); this.CloseButton.TabIndex = 3; @@ -44,39 +55,112 @@ this.CloseButton.UseVisualStyleBackColor = true; this.CloseButton.Click += new System.EventHandler(this.CloseButton_Click); // - // MainTextBox + // MainListView // - this.MainTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.MainListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.MainTextBox.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.MainTextBox.HideSelection = false; - this.MainTextBox.Location = new System.Drawing.Point(12, 12); - this.MainTextBox.Multiline = true; - this.MainTextBox.Name = "MainTextBox"; - this.MainTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.MainTextBox.Size = new System.Drawing.Size(660, 371); - this.MainTextBox.TabIndex = 2; - this.MainTextBox.WordWrap = false; + this.MainListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.XPosColumn, + this.YPosColumn, + this.ZPosColumn, + this.Unk0Column, + this.Unk1Column, + this.Unk2Column, + this.Unk3Column}); + this.MainListView.HideSelection = false; + this.MainListView.Location = new System.Drawing.Point(13, 13); + this.MainListView.Name = "MainListView"; + this.MainListView.Size = new System.Drawing.Size(479, 370); + this.MainListView.TabIndex = 4; + this.MainListView.UseCompatibleStateImageBehavior = false; + this.MainListView.View = System.Windows.Forms.View.Details; + // + // ExportButton + // + this.ExportButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ExportButton.Enabled = false; + this.ExportButton.Location = new System.Drawing.Point(336, 389); + this.ExportButton.Name = "ExportButton"; + this.ExportButton.Size = new System.Drawing.Size(75, 23); + this.ExportButton.TabIndex = 5; + this.ExportButton.Text = "Export"; + this.ExportButton.UseVisualStyleBackColor = true; + this.ExportButton.Click += new System.EventHandler(this.ExportButton_Click); + // + // CopyClipboardButton + // + this.CopyClipboardButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.CopyClipboardButton.Enabled = false; + this.CopyClipboardButton.Location = new System.Drawing.Point(227, 389); + this.CopyClipboardButton.Name = "CopyClipboardButton"; + this.CopyClipboardButton.Size = new System.Drawing.Size(103, 23); + this.CopyClipboardButton.TabIndex = 6; + this.CopyClipboardButton.Text = "Copy to clipboard"; + this.CopyClipboardButton.UseVisualStyleBackColor = true; + this.CopyClipboardButton.Click += new System.EventHandler(this.CopyClipboardButton_Click); + // + // XPosColumn + // + this.XPosColumn.Text = "Position X"; + this.XPosColumn.Width = 75; + // + // YPosColumn + // + this.YPosColumn.Text = "Position Y"; + this.YPosColumn.Width = 75; + // + // ZPosColumn + // + this.ZPosColumn.Text = "Position Z"; + this.ZPosColumn.Width = 75; + // + // Unk0Column + // + this.Unk0Column.Text = "Unk0"; + // + // Unk1Column + // + this.Unk1Column.Text = "Unk1"; + // + // Unk2Column + // + this.Unk2Column.Text = "Unk2"; + // + // Unk3Column + // + this.Unk3Column.Text = "Unk3"; // // YwrForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(684, 421); + this.CancelButton = this.CloseButton; + this.ClientSize = new System.Drawing.Size(504, 421); + this.Controls.Add(this.CopyClipboardButton); + this.Controls.Add(this.ExportButton); + this.Controls.Add(this.MainListView); this.Controls.Add(this.CloseButton); - this.Controls.Add(this.MainTextBox); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "YwrForm"; this.Text = "Waypoint Records Viewer - CodeWalker by dexyfex"; this.ResumeLayout(false); - this.PerformLayout(); } #endregion private System.Windows.Forms.Button CloseButton; - private WinForms.TextBoxFix MainTextBox; + private System.Windows.Forms.ListView MainListView; + private System.Windows.Forms.Button ExportButton; + private System.Windows.Forms.Button CopyClipboardButton; + private System.Windows.Forms.ColumnHeader XPosColumn; + private System.Windows.Forms.ColumnHeader YPosColumn; + private System.Windows.Forms.ColumnHeader ZPosColumn; + private System.Windows.Forms.ColumnHeader Unk0Column; + private System.Windows.Forms.ColumnHeader Unk1Column; + private System.Windows.Forms.ColumnHeader Unk2Column; + private System.Windows.Forms.ColumnHeader Unk3Column; + private System.Windows.Forms.SaveFileDialog saveFileDialog; } } \ No newline at end of file diff --git a/CodeWalker/Forms/YwrForm.cs b/CodeWalker/Forms/YwrForm.cs index ee9dd68..0010fdb 100644 --- a/CodeWalker/Forms/YwrForm.cs +++ b/CodeWalker/Forms/YwrForm.cs @@ -1,5 +1,6 @@ using CodeWalker.GameFiles; using System; +using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -14,7 +15,7 @@ namespace CodeWalker.Forms public partial class YwrForm : Form { - + private YwrFile ywr; private string fileName; public string FileName { @@ -45,6 +46,7 @@ namespace CodeWalker.Forms public void LoadYwr(YwrFile ywr) { + this.ywr = ywr; fileName = ywr?.Name; if (string.IsNullOrEmpty(fileName)) { @@ -53,42 +55,78 @@ namespace CodeWalker.Forms UpdateFormTitle(); - - StringBuilder sb = new StringBuilder(); - if ((ywr != null) && (ywr.Waypoints != null) && (ywr.Waypoints.Entries != null)) { - sb.AppendLine("PositionX, PositionY, PositionZ, Unk0, Unk1, Unk2, Unk3"); - foreach (var entry in ywr.Waypoints.Entries) - { - sb.Append(FloatUtil.ToString(entry.PositionX)); - sb.Append(", "); - sb.Append(FloatUtil.ToString(entry.PositionY)); - sb.Append(", "); - sb.Append(FloatUtil.ToString(entry.PositionZ)); - sb.Append(", "); - sb.Append(entry.Unk0.ToString()); - sb.Append(", "); - sb.Append(entry.Unk1.ToString()); - sb.Append(", "); - sb.Append(entry.Unk2.ToString()); - sb.Append(", "); - sb.Append(entry.Unk3.ToString()); - sb.AppendLine(); - } + LoadListView(); + ExportButton.Enabled = true; + CopyClipboardButton.Enabled = true; } else { - sb.AppendLine("Unable to load Waypoint Records."); + MessageBox.Show("Error", "Could not load ywr", MessageBoxButtons.OK, MessageBoxIcon.Error); } - - MainTextBox.Text = sb.ToString(); } - + private string GenerateText() + { + var sb = new StringBuilder(); + sb.AppendLine("PositionX, PositionY, PositionZ, Unk0, Unk1, Unk2, Unk3"); + foreach (var entry in ywr.Waypoints.Entries) + { + sb.Append(FloatUtil.ToString(entry.PositionX)); + sb.Append(", "); + sb.Append(FloatUtil.ToString(entry.PositionY)); + sb.Append(", "); + sb.Append(FloatUtil.ToString(entry.PositionZ)); + sb.Append(", "); + sb.Append(entry.Unk0.ToString()); + sb.Append(", "); + sb.Append(entry.Unk1.ToString()); + sb.Append(", "); + sb.Append(entry.Unk2.ToString()); + sb.Append(", "); + sb.Append(entry.Unk3.ToString()); + sb.AppendLine(); + } + return sb.ToString(); + } + private void LoadListView() + { + MainListView.BeginUpdate(); + MainListView.Items.Clear(); + foreach (var entry in ywr.Waypoints.Entries) + { + string[] row = + { + FloatUtil.ToString(entry.PositionX), + FloatUtil.ToString(entry.PositionY), + FloatUtil.ToString(entry.PositionZ), + entry.Unk0.ToString(), + entry.Unk1.ToString(), + entry.Unk2.ToString(), + entry.Unk3.ToString() + }; + MainListView.Items.Add(new ListViewItem(row)); + } + MainListView.EndUpdate(); + } private void CloseButton_Click(object sender, EventArgs e) { Close(); } + + private void CopyClipboardButton_Click(object sender, EventArgs e) + { + Clipboard.SetText(GenerateText()); + } + + private void ExportButton_Click(object sender, EventArgs e) + { + saveFileDialog.FileName = Path.GetFileNameWithoutExtension(fileName) + ".csv"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + File.WriteAllText(saveFileDialog.FileName, GenerateText()); + } + } } } diff --git a/CodeWalker/Forms/YwrForm.resx b/CodeWalker/Forms/YwrForm.resx index 1431f6b..8d4a312 100644 --- a/CodeWalker/Forms/YwrForm.resx +++ b/CodeWalker/Forms/YwrForm.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 +