diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index fabfc7b9db..74ccb1628a 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -499,6 +499,9 @@ + + Component + Component @@ -508,6 +511,9 @@ LuaConsole.cs + + Component + Form @@ -622,6 +628,7 @@ LuaBox.cs + UserControl diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs index ff58fa1241..788b87cfa3 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs @@ -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 dropdownItems = items.Values.Cast().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); diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaCheckbox.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaCheckbox.cs new file mode 100644 index 0000000000..0323864d5e --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaCheckbox.cs @@ -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); + } + } +} diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs new file mode 100644 index 0000000000..d0842aa701 --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs @@ -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 items) + : base() + { + Items.AddRange(items.Cast().ToArray()); + SelectedIndex = 0; + DropDownStyle = ComboBoxStyle.DropDownList; + } + } +} diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/Marker.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/Marker.cs new file mode 100644 index 0000000000..f67c6cb31a --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/Marker.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using BizHawk.Client.Common; + +namespace BizHawk.Client.EmuHawk +{ + /// + /// Represents a TasStudio Marker + /// A marker is a tagged frame with a message + /// + 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; + } + } + + /// + /// Specialized Marker that represents the currently emulated frame + /// Frame always points to Global.Emulator.Frame, and settings it isn't possible + /// + 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 + { + private readonly CurrentFrameMarker _current; + public MarkerList() + : base() + { + _current = new CurrentFrameMarker(); + } + + public CurrentFrameMarker CurrentFrame + { + get + { + return _current; + } + } + } +} diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs index 7b66bf52c8..4b0cbcd31f 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs @@ -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); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 332beb9e08..700a7b29b4 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -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();