From 26569dab5840ca42fbd0c64f74e9474a30281260 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Mon, 4 Jul 2011 19:20:11 +0000 Subject: [PATCH] More work on subtitle maker, implmeent context menu "Add Subtitle" which will open subtitle maker and set frame to the current frame --- BizHawk.MultiClient/MainForm.Designer.cs | 6 +- BizHawk.MultiClient/MainForm.MenuItems.cs | 35 ++++++++++-- .../movie/EditSubtitlesForm.cs | 55 ++++++++++++++++++- BizHawk.MultiClient/movie/SubtitleList.cs | 7 +++ .../movie/SubtitleMaker.Designer.cs | 4 ++ BizHawk.MultiClient/movie/SubtitleMaker.cs | 8 ++- 6 files changed, 103 insertions(+), 12 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.Designer.cs b/BizHawk.MultiClient/MainForm.Designer.cs index 4c5410c9ee..9098f7397e 100644 --- a/BizHawk.MultiClient/MainForm.Designer.cs +++ b/BizHawk.MultiClient/MainForm.Designer.cs @@ -1749,7 +1749,7 @@ this.screenshotToolStripMenuItem1, this.closeROMToolStripMenuItem1}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(179, 330); + this.contextMenuStrip1.Size = new System.Drawing.Size(179, 308); this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening); this.contextMenuStrip1.Closing += new System.Windows.Forms.ToolStripDropDownClosingEventHandler(this.contextMenuStrip1_Closing); // @@ -1832,8 +1832,8 @@ // this.undoLoadstateToolStripMenuItem.Name = "undoLoadstateToolStripMenuItem"; this.undoLoadstateToolStripMenuItem.Size = new System.Drawing.Size(178, 22); - this.undoLoadstateToolStripMenuItem.Text = "Undo Loadstate"; - this.undoLoadstateToolStripMenuItem.Click += new System.EventHandler(this.undoLoadstateToolStripMenuItem_Click); + this.undoLoadstateToolStripMenuItem.Text = "Add Subtitle"; + this.undoLoadstateToolStripMenuItem.Click += new System.EventHandler(this.AddSubtitleToolStripMenuItem_Click); // // undoSavestateToolStripMenuItem // diff --git a/BizHawk.MultiClient/MainForm.MenuItems.cs b/BizHawk.MultiClient/MainForm.MenuItems.cs index 0aa5f3e35d..2811f33414 100644 --- a/BizHawk.MultiClient/MainForm.MenuItems.cs +++ b/BizHawk.MultiClient/MainForm.MenuItems.cs @@ -757,9 +757,34 @@ namespace BizHawk.MultiClient LoadMoviesFromRecent(Global.Config.RecentMovies.GetRecentFileByPosition(0)); } - private void undoLoadstateToolStripMenuItem_Click(object sender, EventArgs e) + private void AddSubtitleToolStripMenuItem_Click(object sender, EventArgs e) { - //TODO + SubtitleMaker s = new SubtitleMaker(); + s.DisableFrame(); + int index = -1; + Subtitle sub = new Subtitle(); + for (int x = 0; x < UserMovie.Subtitles.Count(); x++) + { + sub = UserMovie.Subtitles.GetSubtitleByIndex(x); + if (Global.Emulator.Frame == sub.Frame) + { + index = x; + break; + } + } + if (index < 0) + { + sub = new Subtitle(); + sub.Frame = Global.Emulator.Frame; + } + s.sub = sub; + + if (s.ShowDialog() == DialogResult.OK) + { + if (index >= 0) + UserMovie.Subtitles.Remove(index); + UserMovie.Subtitles.AddSubtitle(s.sub); + } } private void undoSavestateToolStripMenuItem_Click(object sender, EventArgs e) @@ -836,15 +861,16 @@ namespace BizHawk.MultiClient { contextMenuStrip1.Items[8].Text = "View Subtitles"; contextMenuStrip1.Items[9].Text = "View Comments"; + contextMenuStrip1.Items[11].Visible = false; } else { contextMenuStrip1.Items[8].Text = "Edit Subtitles"; contextMenuStrip1.Items[9].Text = "Edit Comments"; + contextMenuStrip1.Items[11].Visible = true; } } - contextMenuStrip1.Items[11].Visible = true; contextMenuStrip1.Items[12].Visible = true; contextMenuStrip1.Items[13].Visible = true; @@ -864,8 +890,7 @@ namespace BizHawk.MultiClient //TODO: - contextMenuStrip1.Items[10].Enabled = false; - contextMenuStrip1.Items[11].Enabled = false; + contextMenuStrip1.Items[12].Enabled = false; } diff --git a/BizHawk.MultiClient/movie/EditSubtitlesForm.cs b/BizHawk.MultiClient/movie/EditSubtitlesForm.cs index 9cdaabe403..cd2352cafd 100644 --- a/BizHawk.MultiClient/movie/EditSubtitlesForm.cs +++ b/BizHawk.MultiClient/movie/EditSubtitlesForm.cs @@ -18,6 +18,7 @@ namespace BizHawk.MultiClient //TODO: Parse hex on color when saving //TODO: try/catch on parsing int //TODO: display color in hex when loading from movie + //TODO: color if color cell = value of color cell public EditSubtitlesForm() { @@ -96,14 +97,62 @@ namespace BizHawk.MultiClient } } + private void ChangeRow(Subtitle s, int index) + { + if (index >= SubGrid.Rows.Count) return; + DataGridViewCell c = SubGrid.Rows[index].Cells[0]; + c.Value = s.Frame; + c = SubGrid.Rows[index].Cells[1]; + c.Value = s.X; + c = SubGrid.Rows[index].Cells[2]; + c.Value = s.Y; + c = SubGrid.Rows[index].Cells[3]; + c.Value = s.Duration; + c = SubGrid.Rows[index].Cells[4]; + c.Value = s.Color; //TODO: view in hex + c = SubGrid.Rows[index].Cells[5]; + c.Value = s.Message; + } + + private Subtitle GetRow(int index) + { + if (index >= SubGrid.Rows.Count) return new Subtitle(); + + Subtitle s = new Subtitle(); + DataGridViewCell c = SubGrid.Rows[index].Cells[0]; + + //Empty catch because it should default to subtitle default value + try { s.Frame = int.Parse(c.Value.ToString()); } + catch { } + c = SubGrid.Rows[index].Cells[1]; + try { s.X = int.Parse(c.Value.ToString()); } + catch { } + c = SubGrid.Rows[index].Cells[2]; + try { s.Y = int.Parse(c.Value.ToString()); } + catch { } + c = SubGrid.Rows[index].Cells[3]; + try { s.Duration = int.Parse(c.Value.ToString()); } + catch { } + c = SubGrid.Rows[index].Cells[4]; + try { s.Color = uint.Parse(c.Value.ToString()); } + catch { } + c = SubGrid.Rows[index].Cells[5]; + try { s.Message = c.Value.ToString(); } + catch { } + selectedMovie.Subtitles.AddSubtitle(s); + + return s; + } + private void SubGrid_MouseDoubleClick(object sender, MouseEventArgs e) { - //TODO: if no index slected, return + DataGridViewSelectedRowCollection c = SubGrid.SelectedRows; + if (c.Count == 0) return; SubtitleMaker s = new SubtitleMaker(); - s.sub = new Subtitle(); //TODO: function that grabs subtitle from selected index + s.sub = GetRow(c[0].Index); if (s.ShowDialog() == DialogResult.OK) { - //selected index, replace (needs new function) + ChangeRow(s.sub, SubGrid.SelectedRows[0].Index); } } } diff --git a/BizHawk.MultiClient/movie/SubtitleList.cs b/BizHawk.MultiClient/movie/SubtitleList.cs index 451a13c116..5e2a513e3f 100644 --- a/BizHawk.MultiClient/movie/SubtitleList.cs +++ b/BizHawk.MultiClient/movie/SubtitleList.cs @@ -195,5 +195,12 @@ namespace BizHawk.MultiClient { subs.Clear(); } + + public void Remove(int index) + { + if (index >= subs.Count) return; + + subs.RemoveAt(index); + } } } diff --git a/BizHawk.MultiClient/movie/SubtitleMaker.Designer.cs b/BizHawk.MultiClient/movie/SubtitleMaker.Designer.cs index 6cd4e1de49..bd75981958 100644 --- a/BizHawk.MultiClient/movie/SubtitleMaker.Designer.cs +++ b/BizHawk.MultiClient/movie/SubtitleMaker.Designer.cs @@ -64,6 +64,7 @@ // Cancel // this.Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.Cancel.Location = new System.Drawing.Point(348, 164); this.Cancel.Name = "Cancel"; this.Cancel.Size = new System.Drawing.Size(75, 23); @@ -166,6 +167,7 @@ this.ColorPanel.Name = "ColorPanel"; this.ColorPanel.Size = new System.Drawing.Size(56, 19); this.ColorPanel.TabIndex = 35; + this.ColorPanel.TabStop = true; this.ColorPanel.DoubleClick += new System.EventHandler(this.ColorPanel_DoubleClick); // // label5 @@ -206,8 +208,10 @@ // // SubtitleMaker // + this.AcceptButton = this.OK; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.Cancel; this.ClientSize = new System.Drawing.Size(435, 199); this.Controls.Add(this.label6); this.Controls.Add(this.FrameNumeric); diff --git a/BizHawk.MultiClient/movie/SubtitleMaker.cs b/BizHawk.MultiClient/movie/SubtitleMaker.cs index 48d9144db0..d214c5bcb4 100644 --- a/BizHawk.MultiClient/movie/SubtitleMaker.cs +++ b/BizHawk.MultiClient/movie/SubtitleMaker.cs @@ -18,6 +18,11 @@ namespace BizHawk.MultiClient InitializeComponent(); } + public void DisableFrame() + { + FrameNumeric.Enabled = false; + } + private void Cancel_Click(object sender, EventArgs e) { this.Close(); @@ -30,6 +35,7 @@ namespace BizHawk.MultiClient sub.X = (int)XNumeric.Value; sub.Duration = (int)DurationNumeric.Value; sub.Color = (uint)colorDialog1.Color.ToArgb(); + this.DialogResult = DialogResult.OK; this.Close(); } @@ -40,9 +46,9 @@ namespace BizHawk.MultiClient XNumeric.Value = sub.X; YNumeric.Value = sub.Y; DurationNumeric.Value = sub.Duration; - Message.Focus(); colorDialog1.Color = Color.FromArgb((int)sub.Color); ColorPanel.BackColor = colorDialog1.Color; + Message.Focus(); } private void ColorPanel_DoubleClick(object sender, EventArgs e)