Some fixes to the ToolManager and make cheats not redraw every frame

This commit is contained in:
adelikat 2013-11-07 20:33:29 +00:00
parent 0adffa65c1
commit 0b71e4d08c
3 changed files with 84 additions and 30 deletions

View File

@ -74,14 +74,7 @@ namespace BizHawk.Client.EmuHawk
public void UpdateValues()
{
if (!IsHandleCreated || IsDisposed)
{
return;
}
else
{
UpdateListView();
}
//Do nothing;
}
public void Restart()
@ -89,7 +82,10 @@ namespace BizHawk.Client.EmuHawk
StartNewList();
}
private void UpdateListView()
/// <summary>
/// Tools that want to refresh the cheats list should call this, not UpdateValues
/// </summary>
public void UpdateDialog()
{
CheatListView.ItemCount = Global.CheatList.Count;
TotalLabel.Text = Global.CheatList.CheatCount.ToString()
@ -115,7 +111,7 @@ namespace BizHawk.Client.EmuHawk
else
{
Global.Config.RecentWatches.Add(path);
UpdateListView();
UpdateDialog();
UpdateMessageLabel();
}
}
@ -180,7 +176,7 @@ namespace BizHawk.Client.EmuHawk
if (result)
{
Global.CheatList.Load(file.FullName, append);
UpdateListView();
UpdateDialog();
UpdateMessageLabel();
Global.Config.RecentCheats.Add(Global.CheatList.CurrentFileName);
}
@ -223,7 +219,7 @@ namespace BizHawk.Client.EmuHawk
private void AddCheat()
{
Global.CheatList.Add(CheatEditor.Cheat);
UpdateListView();
UpdateDialog();
UpdateMessageLabel();
}
@ -407,7 +403,7 @@ namespace BizHawk.Client.EmuHawk
CheatListView.SelectItem(newi, true);
}
UpdateListView();
UpdateDialog();
}
private void MoveDown()
@ -443,7 +439,7 @@ namespace BizHawk.Client.EmuHawk
CheatListView.SelectItem(newi, true);
}
UpdateListView();
UpdateDialog();
}
private void Remove()
@ -457,7 +453,7 @@ namespace BizHawk.Client.EmuHawk
CheatListView.SelectedIndices.Clear();
}
UpdateListView();
UpdateDialog();
}
private void Toggle()
@ -547,7 +543,7 @@ namespace BizHawk.Client.EmuHawk
private void StartNewList()
{
Global.CheatList.NewList(GlobalWin.MainForm.GenerateDefaultCheatFilename());
UpdateListView();
UpdateDialog();
UpdateMessageLabel();
ToggleGameGenieButton();
}
@ -679,7 +675,7 @@ namespace BizHawk.Client.EmuHawk
}
}
UpdateListView();
UpdateDialog();
UpdateMessageLabel();
}
@ -694,7 +690,7 @@ namespace BizHawk.Client.EmuHawk
Global.CheatList.Add(Cheat.Separator);
}
UpdateListView();
UpdateDialog();
UpdateMessageLabel();
}
@ -944,7 +940,7 @@ namespace BizHawk.Client.EmuHawk
_sortedColumn = column.Name;
_sortReverse ^= true;
UpdateListView();
UpdateDialog();
}
private void NewCheatForm_DragDrop(object sender, DragEventArgs e)
@ -953,7 +949,7 @@ namespace BizHawk.Client.EmuHawk
if (Path.GetExtension(filePaths[0]) == (".cht"))
{
LoadFile(new FileInfo(filePaths[0]), append: false);
UpdateListView();
UpdateDialog();
UpdateMessageLabel();
}
}

View File

@ -210,7 +210,12 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.Tools.UpdateValues<RamWatch>();
GlobalWin.Tools.UpdateValues<RamSearch>();
GlobalWin.Tools.UpdateValues<HexEditor>();
GlobalWin.Tools.UpdateValues<Cheats>();
if (GlobalWin.Tools.Has<Cheats>())
{
GlobalWin.Tools.Cheats.UpdateDialog();
}
GlobalWin.MainForm.UpdateCheatStatus();
}

View File

@ -60,17 +60,20 @@ namespace BizHawk.Client.EmuHawk
var existingTool = _tools.FirstOrDefault(x => x is T);
if (existingTool != null)
{
return existingTool;
if (existingTool.IsDisposed)
{
Close<T>();
return CreateInstance<T>();
}
else
{
return existingTool;
}
}
else
{
var tool = Activator.CreateInstance(typeof(T));
//Add to the list and extract it, so it will be strongly typed as T
_tools.Add(tool as IToolForm);
return _tools.FirstOrDefault(x => x is T);
return CreateInstance<T>();
}
}
public void UpdateBefore()
@ -78,7 +81,10 @@ namespace BizHawk.Client.EmuHawk
var beforeList = _tools.Where(x => x.UpdateBefore);
foreach (var tool in beforeList)
{
tool.UpdateValues();
if (!tool.IsDisposed)
{
tool.UpdateValues();
}
}
}
@ -87,7 +93,10 @@ namespace BizHawk.Client.EmuHawk
var afterList = _tools.Where(x => !x.UpdateBefore);
foreach (var tool in afterList)
{
tool.UpdateValues();
if (!tool.IsDisposed)
{
tool.UpdateValues();
}
}
}
@ -96,9 +105,11 @@ namespace BizHawk.Client.EmuHawk
/// </summary>
public void UpdateValues<T>() where T : IToolForm
{
CloseIfDisposed<T>();
var tool = _tools.FirstOrDefault(x => x is T);
if (tool != null)
{
tool.UpdateValues();
}
}
@ -114,6 +125,7 @@ namespace BizHawk.Client.EmuHawk
/// <typeparam name="T"></typeparam>
public void Restart<T>() where T : IToolForm
{
CloseIfDisposed<T>();
var tool = _tools.FirstOrDefault(x => x is T);
if (tool != null)
{
@ -178,6 +190,24 @@ namespace BizHawk.Client.EmuHawk
_tools.Clear();
}
private IToolForm CreateInstance<T>()
{
var tool = Activator.CreateInstance(typeof(T));
//Add to the list and extract it, so it will be strongly typed as T
_tools.Add(tool as IToolForm);
return _tools.FirstOrDefault(x => x is T);
}
private void CloseIfDisposed<T>() where T : IToolForm
{
var existingTool = _tools.FirstOrDefault(x => x is T);
if (existingTool != null && existingTool.IsDisposed)
{
Close<T>();
}
}
//Note: Referencing these properties creates an instance of the tool and persists it. They should be referenced by type if this is not desired
#region Tools
@ -227,6 +257,29 @@ namespace BizHawk.Client.EmuHawk
}
}
public Cheats Cheats
{
get
{
var tool = _tools.FirstOrDefault(x => x is Cheats);
if (tool != null)
{
if (tool.IsDisposed)
{
_tools.Remove(tool);
}
else
{
return tool as Cheats;
}
}
var newTool = new Cheats();
_tools.Add(newTool);
return newTool;
}
}
public HexEditor HexEditor
{
get