Lua forms library - implement forms.dropdown(), forms.checkbox(), and forms.ischecked(). Add support for dropdowns in forms.gettext() (returns the string value of the selected item)

This commit is contained in:
adelikat 2013-12-15 02:50:50 +00:00
parent ff4e122310
commit 91063b7ffd
7 changed files with 308 additions and 17 deletions

View File

@ -499,6 +499,9 @@
<Compile Include="tools\Lua\Libraries\EmuLuaLibrary.Gui.cs" />
<Compile Include="tools\Lua\Libraries\EmuLuaLibrary.Input.cs" />
<Compile Include="tools\Lua\Libraries\EmuLuaLibrary.Savestate.cs" />
<Compile Include="tools\Lua\LuaCheckbox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="tools\Lua\LuaButton.cs">
<SubType>Component</SubType>
</Compile>
@ -508,6 +511,9 @@
<Compile Include="tools\Lua\LuaConsole.Designer.cs">
<DependentUpon>LuaConsole.cs</DependentUpon>
</Compile>
<Compile Include="tools\Lua\LuaDropDown.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="tools\Lua\LuaFunctionsForm.cs">
<SubType>Form</SubType>
</Compile>
@ -622,6 +628,7 @@
<Compile Include="tools\TAStudio\LuaBox.Designer.cs">
<DependentUpon>LuaBox.cs</DependentUpon>
</Compile>
<Compile Include="tools\TAStudio\Marker.cs" />
<Compile Include="tools\TAStudio\MarkerControlsBox.cs">
<SubType>UserControl</SubType>
</Compile>

View File

@ -20,11 +20,14 @@ namespace BizHawk.Client.EmuHawk
{
"addclick",
"button",
"checkbox",
"clearclicks",
"destroy",
"destroyall",
"dropdown",
"getproperty",
"gettext",
"ischecked",
"label",
"newform",
"openfile",
@ -127,6 +130,23 @@ namespace BizHawk.Client.EmuHawk
return (int)button.Handle;
}
public int forms_checkbox(object form_handle, string caption, object X = null, object Y = null)
{
LuaWinform form = GetForm(form_handle);
if (form == null)
{
return 0;
}
LuaCheckbox checkbox = new LuaCheckbox();
form.Controls.Add(checkbox);
SetText(checkbox, caption);
SetLocation(checkbox, X, Y);
return (int)checkbox.Handle;
}
public void forms_clearclicks(object handle)
{
IntPtr ptr = new IntPtr(LuaInt(handle));
@ -170,6 +190,24 @@ namespace BizHawk.Client.EmuHawk
}
}
public int forms_dropdown(object form_handle, LuaTable items, object X = null, object Y = null, object width = null, object height = null)
{
LuaWinform form = GetForm(form_handle);
if (form == null)
{
return 0;
}
List<string> dropdownItems = items.Values.Cast<string>().ToList();
dropdownItems.Sort();
LuaDropDown dropdown = new LuaDropDown(dropdownItems);
form.Controls.Add(dropdown);
SetLocation(dropdown, X, Y);
SetSize(dropdown, width, height);
return (int)dropdown.Handle;
}
public string forms_getproperty(object handle, object property)
{
try
@ -218,7 +256,14 @@ namespace BizHawk.Client.EmuHawk
{
if (control.Handle == ptr)
{
return control.Text;
if (control is LuaDropDown)
{
return (control as LuaDropDown).SelectedItem.ToString();
}
else
{
return control.Text;
}
}
}
}
@ -232,6 +277,44 @@ namespace BizHawk.Client.EmuHawk
return String.Empty;
}
public bool forms_ischecked(object handle)
{
try
{
IntPtr ptr = new IntPtr(LuaInt(handle));
foreach (LuaWinform form in _luaForms)
{
if (form.Handle == ptr)
{
return false;
}
else
{
foreach (Control control in form.Controls)
{
if (control.Handle == ptr)
{
if (control is LuaCheckbox)
{
return (control as LuaCheckbox).Checked;
}
else
{
return false;
}
}
}
}
}
}
catch (Exception ex)
{
ConsoleLuaLibrary.console_output(ex.Message);
}
return false;
}
public int forms_label(object form_handle, object caption, object X = null, object Y = null, object width = null, object height = null)
{
LuaWinform form = GetForm(form_handle);

View File

@ -0,0 +1,23 @@
using System;
using System.Windows.Forms;
namespace BizHawk.Client.EmuHawk
{
public class LuaCheckbox : CheckBox
{
private void DoLuaClick(object sender, EventArgs e)
{
var parent = Parent as LuaWinform;
if (parent != null)
{
parent.DoLuaEvent(Handle);
}
}
protected override void OnClick(EventArgs e)
{
DoLuaClick(this, e);
base.OnClick(e);
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace BizHawk.Client.EmuHawk
{
public class LuaDropDown : ComboBox
{
public LuaDropDown(List<string> items)
: base()
{
Items.AddRange(items.Cast<object>().ToArray());
SelectedIndex = 0;
DropDownStyle = ComboBoxStyle.DropDownList;
}
}
}

View File

@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
/// Represents a TasStudio Marker
/// A marker is a tagged frame with a message
/// </summary>
public class Marker
{
private int _frame;
public Marker(int frame, string message = "")
{
_frame = frame;
Message = message;
}
public virtual int Frame
{
get { return _frame; }
}
public virtual string Message { get; set; }
public override string ToString()
{
return Frame.ToString() + '\t' + Message;
}
public override int GetHashCode()
{
return this.Frame.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if (obj is Marker)
{
return this.Frame == (obj as Marker).Frame;
}
else
{
return false;
}
}
public static bool operator ==(Marker a, Marker b)
{
return a.Frame == b.Frame;
}
public static bool operator !=(Marker a, Marker b)
{
return a.Frame != b.Frame;
}
public static bool operator ==(Marker marker, int frame)
{
return marker.Frame == frame;
}
public static bool operator !=(Marker marker, int frame)
{
return marker.Frame != frame;
}
}
/// <summary>
/// Specialized Marker that represents the currently emulated frame
/// Frame always points to Global.Emulator.Frame, and settings it isn't possible
/// </summary>
public class CurrentFrameMarker : Marker
{
public CurrentFrameMarker()
: base(0)
{
}
public override int Frame
{
get { return Global.Emulator.Frame; }
}
public virtual string Message
{
get { return String.Empty; }
set { return; }
}
}
public class MarkerList : List<Marker>
{
private readonly CurrentFrameMarker _current;
public MarkerList()
: base()
{
_current = new CurrentFrameMarker();
}
public CurrentFrameMarker CurrentFrame
{
get
{
return _current;
}
}
}
}

View File

@ -93,6 +93,7 @@ namespace BizHawk.Client.EmuHawk
this.AutopauseAtEndOfMovieMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SettingsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.AutoloadMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AutoloadProjectMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveWindowPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator12 = new System.Windows.Forms.ToolStripSeparator();
@ -108,7 +109,6 @@ namespace BizHawk.Client.EmuHawk
this.MarkerDescriptionBox = new System.Windows.Forms.TextBox();
this.TopMarkerBox = new System.Windows.Forms.TextBox();
this.TopMarkerLabel = new System.Windows.Forms.Label();
this.AutoloadProjectMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.TASMenu.SuspendLayout();
this.SuspendLayout();
//
@ -596,6 +596,13 @@ namespace BizHawk.Client.EmuHawk
this.AutoloadMenuItem.Text = "Autoload";
this.AutoloadMenuItem.Click += new System.EventHandler(this.AutoloadMenuItem_Click);
//
// AutoloadProjectMenuItem
//
this.AutoloadProjectMenuItem.Name = "AutoloadProjectMenuItem";
this.AutoloadProjectMenuItem.Size = new System.Drawing.Size(199, 22);
this.AutoloadProjectMenuItem.Text = "Autload &Project";
this.AutoloadProjectMenuItem.Click += new System.EventHandler(this.AutoloadProjectMenuItem_Click);
//
// SaveWindowPositionMenuItem
//
this.SaveWindowPositionMenuItem.Name = "SaveWindowPositionMenuItem";
@ -672,6 +679,7 @@ namespace BizHawk.Client.EmuHawk
this.TASView.UseCompatibleStateImageBehavior = false;
this.TASView.View = System.Windows.Forms.View.Details;
this.TASView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TASView_MouseDown);
this.TASView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TASView_MouseUp);
//
// Frame
//
@ -720,13 +728,6 @@ namespace BizHawk.Client.EmuHawk
this.TopMarkerLabel.TabIndex = 4;
this.TopMarkerLabel.Text = "Marker 99999";
//
// AutloadProjectMenuItem
//
this.AutoloadProjectMenuItem.Name = "AutloadProjectMenuItem";
this.AutoloadProjectMenuItem.Size = new System.Drawing.Size(199, 22);
this.AutoloadProjectMenuItem.Text = "Autload &Project";
this.AutoloadProjectMenuItem.Click += new System.EventHandler(this.AutoloadProjectMenuItem_Click);
//
// TAStudio
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -20,9 +20,13 @@ namespace BizHawk.Client.EmuHawk
private int _defaultHeight;
private TasMovie _tas;
private MarkerList _markers = new MarkerList();
// Input Painting
private string StartDrawColumn = String.Empty;
private bool StartOn = false;
private bool StartMarkerDrag = false;
private bool StartFrameDrag = false;
#region API
@ -109,7 +113,11 @@ namespace BizHawk.Client.EmuHawk
private void TASView_QueryItemBkColor(int index, int column, ref Color color)
{
var record = _tas[index];
if (!record.HasState)
if (_markers.CurrentFrame == index + 1)
{
color = Color.LightBlue;
}
else if (!record.HasState)
{
color = BackColor;
}
@ -128,11 +136,18 @@ namespace BizHawk.Client.EmuHawk
if (columnName == MarkerColumnName)
{
text = String.Empty;
if (_markers.CurrentFrame == index + 1)
{
text = ">";
}
else
{
text = String.Empty;
}
}
else if (columnName == FrameColumnName)
{
text = index.ToString().PadLeft(5, '0');
text = (index + 1).ToString().PadLeft(5, '0');
}
else
{
@ -404,17 +419,42 @@ namespace BizHawk.Client.EmuHawk
{
if (TASView.PointedCell.Row.HasValue && !String.IsNullOrEmpty(TASView.PointedCell.Column))
{
_tas.ToggleButton(TASView.PointedCell.Row.Value, TASView.PointedCell.Column);
TASView.Refresh();
if (TASView.PointedCell.Column == MarkerColumnName)
{
StartMarkerDrag = true;
}
else if (TASView.PointedCell.Column == FrameColumnName)
{
// TODO
}
else
{
_tas.ToggleButton(TASView.PointedCell.Row.Value, TASView.PointedCell.Column);
TASView.Refresh();
StartDrawColumn = TASView.PointedCell.Column;
StartOn = _tas.IsPressed(TASView.PointedCell.Row.Value, TASView.PointedCell.Column);
StartDrawColumn = TASView.PointedCell.Column;
StartOn = _tas.IsPressed(TASView.PointedCell.Row.Value, TASView.PointedCell.Column);
}
}
}
private void TASView_MouseUp(object sender, MouseEventArgs e)
{
StartMarkerDrag = false;
StartFrameDrag = false;
StartDrawColumn = String.Empty;
}
private void TASView_PointedCellChanged(object sender, TasListView.CellEventArgs e)
{
if (TASView.IsPaintDown && e.NewCell.Row.HasValue && !String.IsNullOrEmpty(StartDrawColumn))
if (StartMarkerDrag)
{
// TODO e.NewCell.Row
}
else if (StartFrameDrag)
{
}
else if (TASView.IsPaintDown && e.NewCell.Row.HasValue && !String.IsNullOrEmpty(StartDrawColumn))
{
_tas.SetButton(e.NewCell.Row.Value, StartDrawColumn, StartOn); //Notice it uses new row, old column, you can only paint across a single column
TASView.Refresh();