cleanups in Bookmarks and Marker Controls

This commit is contained in:
adelikat 2019-11-26 14:10:54 -06:00
parent 9a54a461b5
commit ea6b67ac39
3 changed files with 79 additions and 96 deletions

View File

@ -30,25 +30,10 @@ namespace BizHawk.Client.EmuHawk
public Action<int> LoadedCallback { get; set; } public Action<int> LoadedCallback { get; set; }
private void CallLoadedCallback(int index)
{
LoadedCallback?.Invoke(index);
}
public Action<int> SavedCallback { get; set; } public Action<int> SavedCallback { get; set; }
private void CallSavedCallback(int index)
{
SavedCallback?.Invoke(index);
}
public Action<int> RemovedCallback { get; set; } public Action<int> RemovedCallback { get; set; }
private void CallRemovedCallback(int index)
{
RemovedCallback?.Invoke(index);
}
public TAStudio Tastudio { get; set; } public TAStudio Tastudio { get; set; }
public int HoverInterval public int HoverInterval
@ -234,7 +219,7 @@ namespace BizHawk.Client.EmuHawk
private void AddBranchToolStripMenuItem_Click(object sender, EventArgs e) private void AddBranchToolStripMenuItem_Click(object sender, EventArgs e)
{ {
Branch(); Branch();
CallSavedCallback(Movie.Branches.Count - 1); SavedCallback?.Invoke(Movie.Branches.Count - 1);
GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}"); GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}");
} }
@ -242,7 +227,7 @@ namespace BizHawk.Client.EmuHawk
{ {
Branch(); Branch();
EditBranchTextPopUp(Movie.CurrentBranch); EditBranchTextPopUp(Movie.CurrentBranch);
CallSavedCallback(Movie.Branches.Count - 1); SavedCallback?.Invoke(Movie.Branches.Count - 1);
GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}"); GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}");
} }
@ -265,92 +250,100 @@ namespace BizHawk.Client.EmuHawk
if (BranchView.AnyRowsSelected) if (BranchView.AnyRowsSelected)
{ {
LoadSelectedBranch(); LoadSelectedBranch();
CallLoadedCallback(BranchView.SelectedRows.First()); LoadedCallback?.Invoke(BranchView.SelectedRows.First());
} }
} }
private void UpdateBranchToolStripMenuItem_Click(object sender, EventArgs e) private void UpdateBranchToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (SelectedBranch != null) if (SelectedBranch == null)
{ {
Movie.CurrentBranch = BranchView.SelectedRows.First(); return;
_backupBranch = SelectedBranch.Clone();
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
UndoBranchToolStripMenuItem.Text = "Undo Branch Update";
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Update");
_branchUndo = BranchUndo.Update;
UpdateBranch(SelectedBranch);
CallSavedCallback(Movie.CurrentBranch);
GlobalWin.OSD.AddMessage($"Saved branch {Movie.CurrentBranch}");
} }
Movie.CurrentBranch = BranchView.SelectedRows.First();
_backupBranch = SelectedBranch.Clone();
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
UndoBranchToolStripMenuItem.Text = "Undo Branch Update";
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Update");
_branchUndo = BranchUndo.Update;
UpdateBranch(SelectedBranch);
SavedCallback?.Invoke(Movie.CurrentBranch);
GlobalWin.OSD.AddMessage($"Saved branch {Movie.CurrentBranch}");
} }
private void EditBranchTextToolStripMenuItem_Click(object sender, EventArgs e) private void EditBranchTextToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (SelectedBranch != null) if (SelectedBranch == null)
{ {
int index = BranchView.SelectedRows.First(); return;
string oldText = SelectedBranch.UserText; }
if (EditBranchTextPopUp(index)) int index = BranchView.SelectedRows.First();
{ string oldText = SelectedBranch.UserText;
_backupBranch = SelectedBranch.Clone();
_backupBranch.UserText = oldText;
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
UndoBranchToolStripMenuItem.Text = "Undo Branch Text Edit";
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Text Edit");
_branchUndo = BranchUndo.Text;
GlobalWin.OSD.AddMessage($"Edited branch {index}"); if (EditBranchTextPopUp(index))
} {
_backupBranch = SelectedBranch.Clone();
_backupBranch.UserText = oldText;
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
UndoBranchToolStripMenuItem.Text = "Undo Branch Text Edit";
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Text Edit");
_branchUndo = BranchUndo.Text;
GlobalWin.OSD.AddMessage($"Edited branch {index}");
} }
} }
private void JumpToBranchToolStripMenuItem_Click(object sender, EventArgs e) private void JumpToBranchToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (SelectedBranch != null) if (SelectedBranch == null)
{ {
int index = BranchView.SelectedRows.First(); return;
TasBranch branch = Movie.GetBranch(index);
Tastudio.GoToFrame(branch.Frame);
} }
int index = BranchView.SelectedRows.First();
TasBranch branch = Movie.GetBranch(index);
Tastudio.GoToFrame(branch.Frame);
} }
private void RemoveBranchToolStripMenuItem_Click(object sender, EventArgs e) private void RemoveBranchToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (SelectedBranch != null) if (SelectedBranch == null)
{ {
int index = BranchView.SelectedRows.First(); return;
if (index == Movie.CurrentBranch)
{
Movie.CurrentBranch = -1;
}
else if (index < Movie.CurrentBranch)
{
Movie.CurrentBranch--;
}
_backupBranch = SelectedBranch.Clone();
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
UndoBranchToolStripMenuItem.Text = "Undo Branch Removal";
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Removal");
_branchUndo = BranchUndo.Remove;
Movie.RemoveBranch(SelectedBranch);
BranchView.RowCount = Movie.Branches.Count;
if (index == Movie.Branches.Count)
{
BranchView.ClearSelectedRows();
Select(Movie.Branches.Count - 1, true);
}
CallRemovedCallback(index);
Tastudio.RefreshDialog();
GlobalWin.OSD.AddMessage($"Removed branch {index}");
} }
int index = BranchView.SelectedRows.First();
if (index == Movie.CurrentBranch)
{
Movie.CurrentBranch = -1;
}
else if (index < Movie.CurrentBranch)
{
Movie.CurrentBranch--;
}
_backupBranch = SelectedBranch.Clone();
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
UndoBranchToolStripMenuItem.Text = "Undo Branch Removal";
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Removal");
_branchUndo = BranchUndo.Remove;
Movie.RemoveBranch(SelectedBranch);
BranchView.RowCount = Movie.Branches.Count;
if (index == Movie.Branches.Count)
{
BranchView.ClearSelectedRows();
Select(Movie.Branches.Count - 1, true);
}
RemovedCallback?.Invoke(index);
Tastudio.RefreshDialog();
GlobalWin.OSD.AddMessage($"Removed branch {index}");
} }
private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e) private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e)
@ -358,13 +351,13 @@ namespace BizHawk.Client.EmuHawk
if (_branchUndo == BranchUndo.Load) if (_branchUndo == BranchUndo.Load)
{ {
LoadBranch(_backupBranch); LoadBranch(_backupBranch);
CallLoadedCallback(Movie.Branches.IndexOf(_backupBranch)); LoadedCallback?.Invoke(Movie.Branches.IndexOf(_backupBranch));
GlobalWin.OSD.AddMessage("Branch Load canceled"); GlobalWin.OSD.AddMessage("Branch Load canceled");
} }
else if (_branchUndo == BranchUndo.Update) else if (_branchUndo == BranchUndo.Update)
{ {
Movie.UpdateBranch(Movie.GetBranch(_backupBranch.UniqueIdentifier), _backupBranch); Movie.UpdateBranch(Movie.GetBranch(_backupBranch.UniqueIdentifier), _backupBranch);
CallSavedCallback(Movie.Branches.IndexOf(_backupBranch)); SavedCallback?.Invoke(Movie.Branches.IndexOf(_backupBranch));
GlobalWin.OSD.AddMessage("Branch Update canceled"); GlobalWin.OSD.AddMessage("Branch Update canceled");
} }
else if (_branchUndo == BranchUndo.Text) else if (_branchUndo == BranchUndo.Text)
@ -376,7 +369,7 @@ namespace BizHawk.Client.EmuHawk
{ {
Movie.AddBranch(_backupBranch); Movie.AddBranch(_backupBranch);
BranchView.RowCount = Movie.Branches.Count; BranchView.RowCount = Movie.Branches.Count;
CallSavedCallback(Movie.Branches.IndexOf(_backupBranch)); SavedCallback?.Invoke(Movie.Branches.IndexOf(_backupBranch));
GlobalWin.OSD.AddMessage("Branch Removal canceled"); GlobalWin.OSD.AddMessage("Branch Removal canceled");
} }
@ -643,7 +636,7 @@ namespace BizHawk.Client.EmuHawk
private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e) private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e)
{ {
if (e.NewCell != null && e.NewCell.IsDataCell && e.OldCell.RowIndex.Value < Movie.Branches.Count) if (e.NewCell != null && e.NewCell.IsDataCell && e.OldCell.RowIndex < Movie.Branches.Count)
{ {
var guid = Movie.BranchGuidByIndex(Movie.CurrentBranch); var guid = Movie.BranchGuidByIndex(Movie.CurrentBranch);
Movie.SwapBranches(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value); Movie.SwapBranches(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value);
@ -673,7 +666,7 @@ namespace BizHawk.Client.EmuHawk
} }
_screenshot.UpdateValues(branch, location, width, height, _screenshot.UpdateValues(branch, location, width, height,
(int)Graphics.FromHwnd(this.Handle).MeasureString( (int)Graphics.FromHwnd(Handle).MeasureString(
branch.UserText, _screenshot.Font, width).Height); branch.UserText, _screenshot.Font, width).Height);
_screenshot.FadeIn(); _screenshot.FadeIn();

View File

@ -238,7 +238,6 @@
this.Controls.Add(this.MarkersGroupBox); this.Controls.Add(this.MarkersGroupBox);
this.Name = "MarkerControl"; this.Name = "MarkerControl";
this.Size = new System.Drawing.Size(198, 278); this.Size = new System.Drawing.Size(198, 278);
this.Load += new System.EventHandler(this.MarkerControl_Load);
this.MarkerContextMenu.ResumeLayout(false); this.MarkerContextMenu.ResumeLayout(false);
this.MarkersGroupBox.ResumeLayout(false); this.MarkersGroupBox.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -39,10 +39,6 @@ namespace BizHawk.Client.EmuHawk
MarkerView.QueryItemText += MarkerView_QueryItemText; MarkerView.QueryItemText += MarkerView_QueryItemText;
} }
private void MarkerControl_Load(object sender, EventArgs e)
{
}
public InputRoll MarkerInputRoll => MarkerView; public InputRoll MarkerInputRoll => MarkerView;
private void MarkerView_QueryItemBkColor(int index, RollColumn column, ref Color color) private void MarkerView_QueryItemBkColor(int index, RollColumn column, ref Color color)
@ -259,16 +255,11 @@ namespace BizHawk.Client.EmuHawk
MarkerInputRoll.AnyRowsSelected; MarkerInputRoll.AnyRowsSelected;
} }
private List<TasMovieMarker> SelectedMarkers private List<TasMovieMarker> SelectedMarkers => MarkerView
{ .SelectedRows
get .Select(index => Markers[index])
{ .ToList();
return MarkerView
.SelectedRows
.Select(index => Markers[index])
.ToList();
}
}
// SuuperW: Marker renaming can be done with a right-click. // SuuperW: Marker renaming can be done with a right-click.
// A much more useful feature would be to easily jump to it. // A much more useful feature would be to easily jump to it.