Lua - implement Always on Top and Floating Window

This commit is contained in:
adelikat 2014-01-30 22:32:29 +00:00
parent 5f5677781b
commit f3755975a1
5 changed files with 105 additions and 53 deletions
BizHawk.Client.Common/config
BizHawk.Client.EmuHawk/tools

View File

@ -168,14 +168,10 @@ namespace BizHawk.Client.Common
public int LogWindowHeight = -1;
// Lua Console
public ToolDialogSettings LuaSettings = new ToolDialogSettings();
public RecentFiles RecentLua = new RecentFiles(8);
public RecentFiles RecentLuaSession = new RecentFiles(8);
public bool AutoLoadLuaConsole = false;
public bool LuaConsoleSaveWindowPosition = true;
public int LuaConsoleWndx = -1; // Negative numbers will be ignored even with save window position set
public int LuaConsoleWndy = -1;
public int LuaConsoleWidth = -1;
public int LuaConsoleHeight = -1;
public bool DisableLuaScriptsOnLoad = false;
// RamWatch Settings

View File

@ -413,12 +413,12 @@ namespace BizHawk.Client.EmuHawk
if (Global.Config.HexEditorSettings.UseWindowPosition)
{
Location = new Point(Global.Config.HexEditorSettings.Wndx.Value, Global.Config.HexEditorSettings.Wndy.Value);
Location = Global.Config.HexEditorSettings.WindowPosition;
}
if (Global.Config.HexEditorSettings.UseWindowSize)
{
Size = new Size(Global.Config.HexEditorSettings.Width.Value, Global.Config.HexEditorSettings.Height.Value);
Size = Global.Config.HexEditorSettings.WindowSize;
}
SetMemoryDomainMenu();

View File

@ -97,6 +97,9 @@
this.LuaListView = new BizHawk.Client.EmuHawk.VirtualListView();
this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.PathName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
this.ScriptListContextMenu.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.ConsoleContextMenu.SuspendLayout();
@ -426,10 +429,13 @@
// OptionsSubMenu
//
this.OptionsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveWindowPositionMenuItem,
this.AutoloadConsoleMenuItem,
this.AutoloadSessionMenuItem,
this.DisableScriptsOnLoadMenuItem,
this.toolStripSeparator4,
this.SaveWindowPositionMenuItem,
this.AlwaysOnTopMenuItem,
this.FloatingWindowMenuItem,
this.toolStripSeparator5,
this.RestoreDefaultSettingsMenuItem});
this.OptionsSubMenu.Name = "OptionsSubMenu";
@ -719,6 +725,25 @@
this.PathName.Text = "Path";
this.PathName.Width = 195;
//
// AlwaysOnTopMenuItem
//
this.AlwaysOnTopMenuItem.Name = "AlwaysOnTopMenuItem";
this.AlwaysOnTopMenuItem.Size = new System.Drawing.Size(199, 22);
this.AlwaysOnTopMenuItem.Text = "Always On Top";
this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click);
//
// FloatingWindowMenuItem
//
this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem";
this.FloatingWindowMenuItem.Size = new System.Drawing.Size(199, 22);
this.FloatingWindowMenuItem.Text = "Floating Window";
this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click);
//
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(196, 6);
//
// LuaConsole
//
this.AllowDrop = true;
@ -821,5 +846,8 @@
private System.Windows.Forms.ToolStripButton NewScriptToolbarItem;
private System.Windows.Forms.ToolStripMenuItem RegisteredFunctionsMenuItem;
private System.Windows.Forms.ToolStripMenuItem RegisteredFunctionsContextItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem;
}
}

View File

@ -4,8 +4,8 @@ using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
@ -40,7 +40,7 @@ namespace BizHawk.Client.EmuHawk
public LuaConsole()
{
_sortReverse = false;
_lastColumnSorted = String.Empty;
_lastColumnSorted = string.Empty;
_luaList = new LuaFileList
{
ChangedCallback = SessionChangedCallback,
@ -60,9 +60,12 @@ namespace BizHawk.Client.EmuHawk
e.Cancel = true;
}
};
LuaListView.QueryItemText += LuaListView_QueryItemText;
LuaListView.QueryItemBkColor += LuaListView_QueryItemBkColor;
LuaListView.VirtualMode = true;
TopMost = Global.Config.LuaSettings.TopMost;
}
private void LuaConsole_Load(object sender, EventArgs e)
@ -89,7 +92,7 @@ namespace BizHawk.Client.EmuHawk
{
if (LuaAlreadyInSession(path) == false)
{
var luaFile = new LuaFile(String.Empty, path);
var luaFile = new LuaFile(string.Empty, path);
_luaList.Add(luaFile);
LuaListView.ItemCount = _luaList.Count;
Global.Config.RecentLua.Add(path);
@ -177,7 +180,7 @@ namespace BizHawk.Client.EmuHawk
private void SessionChangedCallback()
{
OutputMessages.Text =
(_luaList.Changes ? "* " : String.Empty) +
(_luaList.Changes ? "* " : string.Empty) +
Path.GetFileName(_luaList.Filename);
}
@ -204,7 +207,7 @@ namespace BizHawk.Client.EmuHawk
private void LuaListView_QueryItemText(int index, int column, out string text)
{
text = String.Empty;
text = string.Empty;
if (column == 0)
{
@ -219,10 +222,10 @@ namespace BizHawk.Client.EmuHawk
private void SaveConfigSettings()
{
LuaImp.Close();
Global.Config.LuaConsoleWndx = Location.X;
Global.Config.LuaConsoleWndy = Location.Y;
Global.Config.LuaConsoleWidth = Right - Left;
Global.Config.LuaConsoleHeight = Bottom - Top;
Global.Config.LuaSettings.Wndx = Location.X;
Global.Config.LuaSettings.Wndy = Location.Y;
Global.Config.LuaSettings.Width = Right - Left;
Global.Config.LuaSettings.Height = Bottom - Top;
}
private void LoadConfigSettings()
@ -230,15 +233,14 @@ namespace BizHawk.Client.EmuHawk
_defaultWidth = Size.Width;
_defaultHeight = Size.Height;
if (Global.Config.LuaConsoleSaveWindowPosition && Global.Config.LuaConsoleWndx >= 0
&& Global.Config.LuaConsoleWndy >= 0)
if (Global.Config.LuaSettings.UseWindowPosition)
{
Location = new Point(Global.Config.LuaConsoleWndx, Global.Config.LuaConsoleWndy);
Location = Global.Config.LuaSettings.WindowPosition;
}
if (Global.Config.LuaConsoleWidth >= 0 && Global.Config.LuaConsoleHeight >= 0)
if (Global.Config.LuaSettings.UseWindowSize)
{
Size = new Size(Global.Config.LuaConsoleWidth, Global.Config.LuaConsoleHeight);
Size = Global.Config.LuaSettings.WindowSize;
}
}
@ -262,7 +264,7 @@ namespace BizHawk.Client.EmuHawk
private void UpdateNumberOfScripts()
{
var message = String.Empty;
var message = string.Empty;
var total = SelectedFiles.Count();
var active = _luaList.Count(file => file.Enabled);
var paused = _luaList.Count(file => file.Enabled && file.Paused);
@ -317,7 +319,7 @@ namespace BizHawk.Client.EmuHawk
OutputBox.Invoke(() =>
{
OutputBox.Text = String.Empty;
OutputBox.Text = string.Empty;
OutputBox.Refresh();
});
}
@ -419,7 +421,7 @@ namespace BizHawk.Client.EmuHawk
private FileInfo GetSaveFileFromUser()
{
var sfd = new SaveFileDialog();
if (!String.IsNullOrWhiteSpace(_luaList.Filename))
if (!string.IsNullOrWhiteSpace(_luaList.Filename))
{
sfd.FileName = Path.GetFileNameWithoutExtension(_luaList.Filename);
sfd.InitialDirectory = Path.GetDirectoryName(_luaList.Filename);
@ -488,7 +490,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.Sound.StartSound();
if (result == DialogResult.Yes)
{
if (!String.IsNullOrWhiteSpace(_luaList.Filename))
if (!string.IsNullOrWhiteSpace(_luaList.Filename))
{
_luaList.SaveSession();
}
@ -549,6 +551,11 @@ namespace BizHawk.Client.EmuHawk
get { return SelectedItems.Where(x => !x.IsSeparator); }
}
private void RefreshFloatingWindowControl()
{
Owner = Global.Config.LuaSettings.FloatingWindow ? null : GlobalWin.MainForm;
}
#region Events
#region File Menu
@ -602,7 +609,7 @@ namespace BizHawk.Client.EmuHawk
{
if (_luaList.Changes)
{
if (!String.IsNullOrWhiteSpace(_luaList.Filename))
if (!string.IsNullOrWhiteSpace(_luaList.Filename))
{
_luaList.SaveSession();
}
@ -852,15 +859,12 @@ namespace BizHawk.Client.EmuHawk
private void OptionsSubMenu_DropDownOpened(object sender, EventArgs e)
{
SaveWindowPositionMenuItem.Checked = Global.Config.LuaConsoleSaveWindowPosition;
SaveWindowPositionMenuItem.Checked = Global.Config.LuaSettings.SaveWindowPosition;
AutoloadConsoleMenuItem.Checked = Global.Config.AutoLoadLuaConsole;
AutoloadSessionMenuItem.Checked = Global.Config.RecentLuaSession.AutoLoad;
DisableScriptsOnLoadMenuItem.Checked = Global.Config.DisableLuaScriptsOnLoad;
}
private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e)
{
Global.Config.LuaConsoleSaveWindowPosition ^= true;
AlwaysOnTopMenuItem.Checked = Global.Config.LuaSettings.TopMost;
FloatingWindowMenuItem.Checked = Global.Config.LuaSettings.FloatingWindow;
}
private void AutoloadConsoleMenuItem_Click(object sender, EventArgs e)
@ -878,9 +882,30 @@ namespace BizHawk.Client.EmuHawk
Global.Config.DisableLuaScriptsOnLoad ^= true;
}
private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e)
{
Global.Config.LuaSettings.SaveWindowPosition ^= true;
}
private void AlwaysOnTopMenuItem_Click(object sender, EventArgs e)
{
Global.Config.LuaSettings.TopMost ^= true;
TopMost = Global.Config.LuaSettings.TopMost;
}
private void FloatingWindowMenuItem_Click(object sender, EventArgs e)
{
Global.Config.LuaSettings.FloatingWindow ^= true;
RefreshFloatingWindowControl();
}
private void RestoreDefaultSettingsMenuItem_Click(object sender, EventArgs e)
{
Size = new Size(_defaultWidth, _defaultHeight);
Global.Config.LuaSettings.SaveWindowPosition = true;
Global.Config.LuaSettings.TopMost = TopMost = false;
Global.Config.LuaSettings.FloatingWindow = false;
}
#endregion
@ -939,6 +964,12 @@ namespace BizHawk.Client.EmuHawk
#region Dialog, Listview, OutputBox
protected override void OnShown(EventArgs e)
{
RefreshFloatingWindowControl();
base.OnShown(e);
}
private void LuaConsole_DragDrop(object sender, DragEventArgs e)
{
var filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
@ -1008,32 +1039,30 @@ namespace BizHawk.Client.EmuHawk
}
}
/// <summary> -MightyMar
/// <summary>
/// Sorts the column Ascending on the first click and Descending on the second click.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LuaListView_ColumnClick(object sender, ColumnClickEventArgs e)
{
String columnToSort = LuaListView.Columns[e.Column].Text;
List<LuaFile> luaListTemp = new List<LuaFile>();
var columnToSort = LuaListView.Columns[e.Column].Text;
var luaListTemp = new List<LuaFile>();
if (columnToSort != _lastColumnSorted)
{
_sortReverse = false;
}
//For getting the name of the .lua file, for some reason this field is kept blank in LuaFile.cs?
//The Name variable gets emptied again near the end just in case it would break something.
for (int i = 0; i < _luaList.Count; i++)
// For getting the name of the .lua file, for some reason this field is kept blank in LuaFile.cs?
// The Name variable gets emptied again near the end just in case it would break something.
for (var i = 0; i < _luaList.Count; i++)
{
String[] words = Regex.Split(_luaList[i].Path, ".lua");
String[] split = words[0].Split('\\');
var words = Regex.Split(_luaList[i].Path, ".lua");
var split = words[0].Split(Path.DirectorySeparatorChar);
luaListTemp.Add(_luaList[i]);
luaListTemp[i].Name = split[split.Count() - 1];
}
//Script, Path
// Script, Path
switch (columnToSort)
{
case "Script":
@ -1044,8 +1073,8 @@ namespace BizHawk.Client.EmuHawk
else
{
luaListTemp = luaListTemp.OrderBy(x => x.Name).ThenBy(x => x.Path).ToList();
}
break;
case "Path":
if (_sortReverse)
@ -1056,24 +1085,23 @@ namespace BizHawk.Client.EmuHawk
{
luaListTemp = luaListTemp.OrderBy(x => x.Path).ThenBy(x => x.Name).ToList();
}
break;
}
for (int i = 0; i < _luaList.Count; i++)
for (var i = 0; i < _luaList.Count; i++)
{
_luaList[i] = luaListTemp[i];
_luaList[i].Name = String.Empty;
_luaList[i].Name = string.Empty;
}
UpdateDialog();
_lastColumnSorted = columnToSort;
_sortReverse = !_sortReverse;
}
#endregion
#endregion
}
}

View File

@ -369,17 +369,17 @@ namespace BizHawk.Client.EmuHawk
private void LoadConfigSettings()
{
// Size and Positioning
_defaultWidth = Size.Width; // Save these first so that the user can restore to its original size
_defaultWidth = Size.Width;
_defaultHeight = Size.Height;
if (Global.Config.RamWatchSettings.UseWindowPosition)
{
Location = new Point(Global.Config.RamWatchSettings.Wndx.Value, Global.Config.RamWatchSettings.Wndy.Value);
Location = Global.Config.RamWatchSettings.WindowPosition;
}
if (Global.Config.RamWatchSettings.UseWindowSize)
{
Size = new Size(Global.Config.RamWatchSettings.Width.Value, Global.Config.RamWatchSettings.Height.Value);
Size = Global.Config.RamWatchSettings.WindowSize;
}
LoadColumnInfo();