Some more misc code cleanup

This commit is contained in:
adelikat 2013-11-25 00:55:56 +00:00
parent 7b244cc87c
commit 345b628dad
3 changed files with 44 additions and 76 deletions

View File

@ -1,12 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
@ -28,7 +25,7 @@ namespace BizHawk.Client.EmuHawk
public const string ENDIAN = "EndianColumn"; public const string ENDIAN = "EndianColumn";
public const string TYPE = "DisplayTypeColumn"; public const string TYPE = "DisplayTypeColumn";
private readonly Dictionary<string, int> DefaultColumnWidths = new Dictionary<string, int> private readonly Dictionary<string, int> _defaultColumnWidths = new Dictionary<string, int>
{ {
{ NAME, 128 }, { NAME, 128 },
{ ADDRESS, 60 }, { ADDRESS, 60 },
@ -41,10 +38,10 @@ namespace BizHawk.Client.EmuHawk
{ TYPE, 55 }, { TYPE, 55 },
}; };
private int defaultWidth; private int _defaultWidth;
private int defaultHeight; private int _defaultHeight;
private string _sortedColumn = String.Empty; private string _sortedColumn = String.Empty;
private bool _sortReverse = false; private bool _sortReverse;
public bool UpdateBefore { get { return false; } } public bool UpdateBefore { get { return false; } }
@ -119,7 +116,7 @@ namespace BizHawk.Client.EmuHawk
private void UpdateMessageLabel(bool saved = false) private void UpdateMessageLabel(bool saved = false)
{ {
string message = String.Empty; string message;
if (saved) if (saved)
{ {
@ -235,8 +232,8 @@ namespace BizHawk.Client.EmuHawk
private void LoadConfigSettings() private void LoadConfigSettings()
{ {
//Size and Positioning //Size and Positioning
defaultWidth = Size.Width; //Save these first so that the user can restore to its original size _defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = Size.Height; _defaultHeight = Size.Height;
if (Global.Config.CheatsSaveWindowPosition && Global.Config.CheatsWndx >= 0 && Global.Config.CheatsWndy >= 0) if (Global.Config.CheatsSaveWindowPosition && Global.Config.CheatsWndx >= 0 && Global.Config.CheatsWndy >= 0)
{ {
@ -270,7 +267,7 @@ namespace BizHawk.Client.EmuHawk
var width = Global.Config.CheatsColumnWidths[columnName]; var width = Global.Config.CheatsColumnWidths[columnName];
if (width == -1) if (width == -1)
{ {
width = DefaultColumnWidths[columnName]; width = _defaultColumnWidths[columnName];
} }
return width; return width;
@ -310,7 +307,7 @@ namespace BizHawk.Client.EmuHawk
text = Global.CheatList[index].Size.ToString(); text = Global.CheatList[index].Size.ToString();
break; break;
case ENDIAN: case ENDIAN:
text = Global.CheatList[index].BigEndian.Value ? "Big" : "Little"; text = (Global.CheatList[index].BigEndian ?? false) ? "Big" : "Little";
break; break;
case TYPE: case TYPE:
text = Watch.DisplayTypeToString(Global.CheatList[index].Type); text = Watch.DisplayTypeToString(Global.CheatList[index].Type);
@ -333,45 +330,19 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private List<int> SelectedIndices private IEnumerable<int> SelectedIndices
{ {
get get { return CheatListView.SelectedIndices.Cast<int>().ToList(); }
{
var selected = new List<int>();
ListView.SelectedIndexCollection indices = CheatListView.SelectedIndices;
foreach (int index in indices)
{
selected.Add(index);
}
return selected;
}
} }
private List<Cheat> SelectedItems private IEnumerable<Cheat> SelectedItems
{ {
get get { return SelectedIndices.Select(index => Global.CheatList[index]); }
{
var selected = new List<Cheat>();
if (SelectedIndices.Any())
{
foreach (int index in SelectedIndices)
{
if (!Global.CheatList[index].IsSeparator)
{
selected.Add(Global.CheatList[index]);
}
}
}
return selected;
}
} }
private List<Cheat> SelectedCheats private IEnumerable<Cheat> SelectedCheats
{ {
get get { return SelectedItems.Where(x => !x.IsSeparator).ToList(); }
{
return SelectedItems.Where(x => !x.IsSeparator).ToList();
}
} }
private void MoveUp() private void MoveUp()
@ -444,21 +415,21 @@ namespace BizHawk.Client.EmuHawk
private void Remove() private void Remove()
{ {
if (SelectedIndices.Any()) if (SelectedItems.Any())
{ {
foreach (int index in SelectedIndices) foreach (var item in SelectedItems)
{ {
Global.CheatList.Remove(Global.CheatList[SelectedIndices[0]]); //SelectedIndices[0] used since each iteration will make this the correct list index Global.CheatList.Remove(item);
} }
CheatListView.SelectedIndices.Clear();
}
UpdateDialog(); CheatListView.SelectedIndices.Clear();
UpdateDialog();
}
} }
private void Toggle() private void Toggle()
{ {
SelectedCheats.ForEach(x => x.Toggle()); SelectedCheats.ToList().ForEach(x => x.Toggle());
} }
private void SaveColumnInfo() private void SaveColumnInfo()
@ -529,7 +500,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (SelectedCheats.Any()) if (SelectedCheats.Any())
{ {
var cheat = SelectedCheats[0]; var cheat = SelectedCheats.First();
CheatEditor.SetCheat(cheat); CheatEditor.SetCheat(cheat);
CheatGroupBox.Text = "Editing Cheat " + cheat.Name + " - " + cheat.AddressStr; CheatGroupBox.Text = "Editing Cheat " + cheat.Name + " - " + cheat.AddressStr;
} }
@ -564,11 +535,8 @@ namespace BizHawk.Client.EmuHawk
public string GenerateDefaultCheatFilename() public string GenerateDefaultCheatFilename()
{ {
PathEntry pathEntry = Global.Config.PathEntries[Global.Emulator.SystemId, "Cheats"]; PathEntry pathEntry = Global.Config.PathEntries[Global.Emulator.SystemId, "Cheats"] ??
if (pathEntry == null) Global.Config.PathEntries[Global.Emulator.SystemId, "Base"];
{
pathEntry = Global.Config.PathEntries[Global.Emulator.SystemId, "Base"];
}
string path = PathManager.MakeAbsolutePath(pathEntry.Path, Global.Emulator.SystemId); string path = PathManager.MakeAbsolutePath(pathEntry.Path, Global.Emulator.SystemId);
var f = new FileInfo(path); var f = new FileInfo(path);
@ -772,7 +740,7 @@ namespace BizHawk.Client.EmuHawk
private void RestoreWindowSizeMenuItem_Click(object sender, EventArgs e) private void RestoreWindowSizeMenuItem_Click(object sender, EventArgs e)
{ {
Size = new Size(defaultWidth, defaultHeight); Size = new Size(_defaultWidth, _defaultHeight);
Global.Config.CheatsSaveWindowPosition = true; Global.Config.CheatsSaveWindowPosition = true;
Global.Config.CheatsAlwaysOnTop = TopMost = false; Global.Config.CheatsAlwaysOnTop = TopMost = false;
Global.Config.DisableCheatsOnLoad = false; Global.Config.DisableCheatsOnLoad = false;
@ -805,8 +773,8 @@ namespace BizHawk.Client.EmuHawk
{ "DisplayTypeColumn", 8 }, { "DisplayTypeColumn", 8 },
}; };
Global.Config.CheatsColumnShow = new Dictionary<string, bool>() Global.Config.CheatsColumnShow = new Dictionary<string, bool>
{ {
{ "NamesColumn", true }, { "NamesColumn", true },
{ "AddressColumn", true }, { "AddressColumn", true },
{ "ValueColumn", true }, { "ValueColumn", true },

View File

@ -6,14 +6,14 @@ using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public partial class EmuLuaLibrary public class EmuLuaLibrary
{ {
private Lua _lua = new Lua(); private Lua _lua = new Lua();
private readonly LuaConsole _caller; private readonly LuaConsole _caller;
private Lua currThread; private Lua _currThread;
private FormsLuaLibrary _formsLibrary = new FormsLuaLibrary(); private readonly FormsLuaLibrary _formsLibrary = new FormsLuaLibrary();
private EventLuaLibrary _eventLibrary = new EventLuaLibrary(ConsoleLuaLibrary.console_log); private readonly EventLuaLibrary _eventLibrary = new EventLuaLibrary(ConsoleLuaLibrary.console_log);
private GuiLuaLibrary _guiLibrary = new GuiLuaLibrary(); private readonly GuiLuaLibrary _guiLibrary = new GuiLuaLibrary();
public LuaDocumentation Docs = new LuaDocumentation(); public LuaDocumentation Docs = new LuaDocumentation();
public bool IsRunning; public bool IsRunning;
@ -79,8 +79,8 @@ namespace BizHawk.Client.EmuHawk
new EmulatorLuaLibrary( new EmulatorLuaLibrary(
_lua, _lua,
new Action(Frameadvance), Frameadvance,
new Action(EmuYield) EmuYield
).LuaRegister(lua, Docs); ).LuaRegister(lua, Docs);
_eventLibrary.LuaRegister(lua, Docs); _eventLibrary.LuaRegister(lua, Docs);
@ -98,10 +98,10 @@ namespace BizHawk.Client.EmuHawk
Docs.Sort(); Docs.Sort();
} }
public Lua SpawnCoroutine(string File) public Lua SpawnCoroutine(string file)
{ {
Lua lua = _lua.NewThread(); Lua lua = _lua.NewThread();
var main = lua.LoadFile(File); var main = lua.LoadFile(file);
lua.Push(main); //push main function on to stack for subsequent resuming lua.Push(main); //push main function on to stack for subsequent resuming
return lua; return lua;
} }
@ -114,9 +114,9 @@ namespace BizHawk.Client.EmuHawk
public ResumeResult ResumeScript(Lua script) public ResumeResult ResumeScript(Lua script)
{ {
currThread = script; _currThread = script;
int execResult = script.Resume(0); int execResult = script.Resume(0);
currThread = null; _currThread = null;
var result = new ResumeResult(); var result = new ResumeResult();
if (execResult == 0) if (execResult == 0)
{ {
@ -132,7 +132,7 @@ namespace BizHawk.Client.EmuHawk
return result; return result;
} }
public void print(string s) public void Print(string s)
{ {
_caller.AddText(s); _caller.AddText(s);
} }
@ -140,13 +140,13 @@ namespace BizHawk.Client.EmuHawk
private void Frameadvance() private void Frameadvance()
{ {
FrameAdvanceRequested = true; FrameAdvanceRequested = true;
currThread.Yield(0); _currThread.Yield(0);
} }
private void EmuYield() private void EmuYield()
{ {
GlobalWin.DisplayManager.NeedsToPaint = true; GlobalWin.DisplayManager.NeedsToPaint = true;
currThread.Yield(0); _currThread.Yield(0);
} }
} }
} }

View File

@ -639,12 +639,12 @@ namespace BizHawk.Client.EmuHawk
private IEnumerable<int> SelectedIndices private IEnumerable<int> SelectedIndices
{ {
get { return LuaListView.SelectedIndices.Cast<int>().ToList(); } get { return LuaListView.SelectedIndices.Cast<int>(); }
} }
private IEnumerable<LuaFile> SelectedItems private IEnumerable<LuaFile> SelectedItems
{ {
get { return SelectedIndices.Select(index => _luaList[index]).ToList(); } get { return SelectedIndices.Select(index => _luaList[index]); }
} }
private IEnumerable<LuaFile> SelectedFiles private IEnumerable<LuaFile> SelectedFiles