private void CloneFramesMenuItem_Click(object sender, EventArgs e) { if (TasView.AnyRowsSelected) { var wasPaused = GlobalWin.MainForm.EmulatorPaused; var framesToInsert = TasView.SelectedRows.ToList(); var insertionFrame = Math.Min(TasView.LastSelectedIndex.Value + 1, CurrentTasMovie.InputLogLength); var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; var inputLog = framesToInsert .Select(frame => CurrentTasMovie.GetInputLogEntry(frame)) .ToList(); CurrentTasMovie.InsertInput(insertionFrame, inputLog); if (needsToRollback) { GoToLastEmulatedFrameIfNecessary(insertionFrame); if (wasPaused) { DoAutoRestore(); } else { GlobalWin.MainForm.UnpauseEmulator(); } } else { RefreshDialog(); } } }
private void PasteInsertMenuItem_Click(object sender, EventArgs e) { var wasPaused = GlobalWin.MainForm.EmulatorPaused; if (_tasClipboard.Any()) { var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; CurrentTasMovie.InsertInput(TasView.FirstSelectedIndex.Value, _tasClipboard.Select(x => x.ControllerState)); if (needsToRollback) { GoToLastEmulatedFrameIfNecessary(TasView.FirstSelectedIndex.Value); if (wasPaused) { DoAutoRestore(); } else { GlobalWin.MainForm.UnpauseEmulator(); } } else { RefreshDialog(); } } }
private void PasteInsertMenuItem_Click(object sender, EventArgs e) { var wasPaused = Mainform.EmulatorPaused; // copypaste from PasteMenuItem_Click! IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent(DataFormats.StringFormat)) { string input = (string)data.GetData(DataFormats.StringFormat); if (!string.IsNullOrWhiteSpace(input)) { string[] lines = input.Split('\n'); if (lines.Length > 0) { _tasClipboard.Clear(); for (int i = 0; i < lines.Length - 1; i++) { var line = TasClipboardEntry.SetFromMnemonicStr(lines[i]); if (line == null) { return; } else { _tasClipboard.Add(new TasClipboardEntry(i, line)); } } var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; CurrentTasMovie.InsertInput(TasView.FirstSelectedIndex.Value, _tasClipboard.Select(x => x.ControllerState)); if (needsToRollback) { GoToLastEmulatedFrameIfNecessary(TasView.FirstSelectedIndex.Value); DoAutoRestore(); } else { RefreshDialog(); } } } } }
private bool AutoAdjustInput() { var lagLog = CurrentTasMovie[Emulator.Frame - 1]; // Minus one because get frame is +1; bool isLag = Emulator.AsInputPollable().IsLagFrame; if (lagLog.WasLagged.HasValue) { if (lagLog.WasLagged.Value && !isLag) { // Deleting this frame requires rewinding a frame. CurrentTasMovie.ChangeLog.AddInputBind(Emulator.Frame - 1, true, $"Bind Input; Delete {Emulator.Frame - 1}"); bool wasRecording = CurrentTasMovie.ChangeLog.IsRecording; CurrentTasMovie.ChangeLog.IsRecording = false; CurrentTasMovie.RemoveFrame(Emulator.Frame - 1); CurrentTasMovie.LagLog.RemoveHistoryAt(Emulator.Frame); // Removes from WasLag CurrentTasMovie.ChangeLog.IsRecording = wasRecording; GoToFrame(Emulator.Frame - 1); return(true); } if (!lagLog.WasLagged.Value && isLag) { // (it shouldn't need to rewind, since the inserted input wasn't polled) CurrentTasMovie.ChangeLog.AddInputBind(Emulator.Frame - 1, false, $"Bind Input; Insert {Emulator.Frame - 1}"); bool wasRecording = CurrentTasMovie.ChangeLog.IsRecording; CurrentTasMovie.ChangeLog.IsRecording = false; CurrentTasMovie.InsertInput(Emulator.Frame - 1, CurrentTasMovie.GetInputLogEntry(Emulator.Frame - 2)); CurrentTasMovie.LagLog.InsertHistoryAt(Emulator.Frame, true); CurrentTasMovie.ChangeLog.IsRecording = wasRecording; return(true); } } return(false); }
private void TasView_PointedCellChanged(object sender, InputRoll.CellEventArgs e) { // TODO: think about nullability // For now return if a null because this happens OnEnter which doesn't have any of the below behaviors yet? // Most of these are stupid but I got annoyed at null crashes if (e.OldCell == null || e.OldCell.Column == null || e.OldCell.RowIndex == null || e.NewCell == null || e.NewCell.RowIndex == null || e.NewCell.Column == null) { return; } int startVal, endVal; int frame = e.NewCell.RowIndex.Value; if (e.OldCell.RowIndex.Value < e.NewCell.RowIndex.Value) { startVal = e.OldCell.RowIndex.Value; endVal = e.NewCell.RowIndex.Value; } else { startVal = e.NewCell.RowIndex.Value; endVal = e.OldCell.RowIndex.Value; } if (_startMarkerDrag) { if (e.NewCell.RowIndex.HasValue) { GoToFrame(e.NewCell.RowIndex.Value); } } else if (_startFrameDrag) { if (e.OldCell.RowIndex.HasValue && e.NewCell.RowIndex.HasValue) { for (var i = startVal; i <= endVal; i++) { TasView.SelectRow(i, _frameDragState); } RefreshTasView(); } } else if (_rightClickFrame != -1) { _triggerAutoRestore = true; _supressContextMenu = true; if (frame > CurrentTasMovie.InputLogLength - _rightClickInput.Length) { frame = CurrentTasMovie.InputLogLength - _rightClickInput.Length; } if (_rightClickShift) { if (_rightClickControl) // Insert { // If going backwards, delete! bool shouldInsert = true; if (startVal < _rightClickFrame) { // Cloning to a previous frame makes no sense. startVal = _rightClickFrame - 1; } if (startVal < _rightClickLastFrame) { shouldInsert = false; } if (shouldInsert) { for (int i = startVal + 1; i <= endVal; i++) { CurrentTasMovie.InsertInput(i, _rightClickInput[(i - _rightClickFrame) % _rightClickInput.Length]); } } else { CurrentTasMovie.RemoveFrames(startVal + 1, endVal + 1); } _rightClickLastFrame = frame; } else // Overwrite { for (int i = startVal; i <= endVal; i++) { CurrentTasMovie.SetFrame(i, _rightClickInput[(_rightClickFrame - i) % _rightClickInput.Length]); } if (startVal < _triggerAutoRestoreFromFrame) { _triggerAutoRestoreFromFrame = startVal; } } } else { if (_rightClickControl) { for (int i = 0; i < _rightClickInput.Length; i++) // Re-set initial range, just to verify it's still there. { CurrentTasMovie.SetFrame(_rightClickFrame + i, _rightClickInput[i]); } if (_rightClickOverInput != null) // Restore overwritten input from previous movement { for (int i = 0; i < _rightClickOverInput.Length; i++) { CurrentTasMovie.SetFrame(_rightClickLastFrame + i, _rightClickOverInput[i]); } } else { _rightClickOverInput = new string[_rightClickInput.Length]; } _rightClickLastFrame = frame; // Set new restore log CurrentTasMovie.GetLogEntries().CopyTo(frame, _rightClickOverInput, 0, _rightClickOverInput.Length); for (int i = 0; i < _rightClickInput.Length; i++) // Place copied input { CurrentTasMovie.SetFrame(frame + i, _rightClickInput[i]); } } else { int shiftBy = _rightClickFrame - frame; string[] shiftInput = new string[Math.Abs(shiftBy)]; int shiftFrom = frame; if (shiftBy < 0) { shiftFrom = _rightClickFrame + _rightClickInput.Length; } CurrentTasMovie.GetLogEntries().CopyTo(shiftFrom, shiftInput, 0, shiftInput.Length); int shiftTo = shiftFrom + (_rightClickInput.Length * Math.Sign(shiftBy)); for (int i = 0; i < shiftInput.Length; i++) { CurrentTasMovie.SetFrame(shiftTo + i, shiftInput[i]); } for (int i = 0; i < _rightClickInput.Length; i++) { CurrentTasMovie.SetFrame(frame + i, _rightClickInput[i]); } _rightClickFrame = frame; } if (frame < _triggerAutoRestoreFromFrame) { _triggerAutoRestoreFromFrame = frame; } } RefreshTasView(); } else if (TasView.IsPaintDown && e.NewCell.RowIndex.HasValue && !string.IsNullOrEmpty(_startBoolDrawColumn)) { if (e.OldCell.RowIndex.HasValue && e.NewCell.RowIndex.HasValue) { for (var i = startVal + 1; i <= endVal; i++) // SuuperW: <= so that it will edit the cell you are hovering over. (Inclusive) { bool setVal = _boolPaintState; if (_patternPaint && _boolPaintState) { if (CurrentTasMovie[frame].Lagged.HasValue && CurrentTasMovie[frame].Lagged.Value) { setVal = CurrentTasMovie.BoolIsPressed(i - 1, _startBoolDrawColumn); } else { setVal = BoolPatterns[controllerType.BoolButtons.IndexOf(_startBoolDrawColumn)].GetNextValue(); } } CurrentTasMovie.SetBoolState(i, _startBoolDrawColumn, setVal); // Notice it uses new row, old column, you can only paint across a single column if (TasView.CurrentCell.RowIndex.Value < _triggerAutoRestoreFromFrame) { _triggerAutoRestoreFromFrame = TasView.CurrentCell.RowIndex.Value; } } RefreshTasView(); } } else if (TasView.IsPaintDown && e.NewCell.RowIndex.HasValue && !string.IsNullOrEmpty(_startFloatDrawColumn)) { if (e.OldCell.RowIndex.HasValue && e.NewCell.RowIndex.HasValue) { for (var i = startVal + 1; i <= endVal; i++) // SuuperW: <= so that it will edit the cell you are hovering over. (Inclusive) { float setVal = _floatPaintState; if (_patternPaint) { if (CurrentTasMovie[frame].Lagged.HasValue && CurrentTasMovie[frame].Lagged.Value) { setVal = CurrentTasMovie.GetFloatState(i - 1, _startFloatDrawColumn); } else { setVal = FloatPatterns[controllerType.FloatControls.IndexOf(_startFloatDrawColumn)].GetNextValue(); } } CurrentTasMovie.SetFloatState(i, _startFloatDrawColumn, setVal); // Notice it uses new row, old column, you can only paint across a single column if (TasView.CurrentCell.RowIndex.Value < _triggerAutoRestoreFromFrame) { _triggerAutoRestoreFromFrame = TasView.CurrentCell.RowIndex.Value; } } RefreshTasView(); } } }
private void TasView_PointedCellChanged(object sender, InputRoll.CellEventArgs e) { // TODO: think about nullability // For now return if a null because this happens OnEnter which doesn't have any of the below behaviors yet? // Most of these are stupid but I got annoyed at null crashes if (e.OldCell == null || e.OldCell.Column == null || e.OldCell.RowIndex == null || e.NewCell == null || e.NewCell.RowIndex == null || e.NewCell.Column == null) { return; } // skip rerecord counting on drawing entirely, mouse down is enough // avoid introducing another global bool wasCountingRerecords = Global.MovieSession.Movie.IsCountingRerecords; int startVal, endVal; int frame = e.NewCell.RowIndex.Value; if (e.OldCell.RowIndex.Value < e.NewCell.RowIndex.Value) { startVal = e.OldCell.RowIndex.Value; endVal = e.NewCell.RowIndex.Value; } else { startVal = e.NewCell.RowIndex.Value; endVal = e.OldCell.RowIndex.Value; } if (_startCursorDrag) { if (e.NewCell.RowIndex.HasValue) { GoToFrame(e.NewCell.RowIndex.Value); } } else if (_startSelectionDrag) { if (e.OldCell.RowIndex.HasValue && e.NewCell.RowIndex.HasValue) { for (var i = startVal; i <= endVal; i++) { TasView.SelectRow(i, _selectionDragState); } } } else if (_rightClickFrame != -1) { if (frame > CurrentTasMovie.InputLogLength - _rightClickInput.Length) { frame = CurrentTasMovie.InputLogLength - _rightClickInput.Length; } if (_rightClickShift) { if (_rightClickControl) // Insert { // If going backwards, delete! bool shouldInsert = true; if (startVal < _rightClickFrame) { // Cloning to a previous frame makes no sense. startVal = _rightClickFrame - 1; } if (startVal < _rightClickLastFrame) { shouldInsert = false; } if (shouldInsert) { for (int i = startVal + 1; i <= endVal; i++) { CurrentTasMovie.InsertInput(i, _rightClickInput[(i - _rightClickFrame).Mod(_rightClickInput.Length)]); } } else { CurrentTasMovie.RemoveFrames(startVal + 1, endVal + 1); } _rightClickLastFrame = frame; } else // Overwrite { for (int i = startVal; i <= endVal; i++) { CurrentTasMovie.SetFrame(i, _rightClickInput[(i - _rightClickFrame).Mod(_rightClickInput.Length)]); } } } else { if (_rightClickControl) { for (int i = 0; i < _rightClickInput.Length; i++) // Re-set initial range, just to verify it's still there. { CurrentTasMovie.SetFrame(_rightClickFrame + i, _rightClickInput[i]); } if (_rightClickOverInput != null) // Restore overwritten input from previous movement { for (int i = 0; i < _rightClickOverInput.Length; i++) { CurrentTasMovie.SetFrame(_rightClickLastFrame + i, _rightClickOverInput[i]); } } else { _rightClickOverInput = new string[_rightClickInput.Length]; } _rightClickLastFrame = frame; // Set new restore log CurrentTasMovie.GetLogEntries().CopyTo(frame, _rightClickOverInput, 0, _rightClickOverInput.Length); for (int i = 0; i < _rightClickInput.Length; i++) // Place copied input { CurrentTasMovie.SetFrame(frame + i, _rightClickInput[i]); } } else if (_rightClickAlt) { int shiftBy = _rightClickFrame - frame; string[] shiftInput = new string[Math.Abs(shiftBy)]; int shiftFrom = frame; if (shiftBy < 0) { shiftFrom = _rightClickFrame + _rightClickInput.Length; } CurrentTasMovie.GetLogEntries().CopyTo(shiftFrom, shiftInput, 0, shiftInput.Length); int shiftTo = shiftFrom + (_rightClickInput.Length * Math.Sign(shiftBy)); for (int i = 0; i < shiftInput.Length; i++) { CurrentTasMovie.SetFrame(shiftTo + i, shiftInput[i]); } for (int i = 0; i < _rightClickInput.Length; i++) { CurrentTasMovie.SetFrame(frame + i, _rightClickInput[i]); } _rightClickFrame = frame; } } if (_rightClickAlt || _rightClickControl || _rightClickShift) { JumpToGreenzone(); _triggerAutoRestore = true; _supressContextMenu = true; } } // Left-click else if (TasView.IsPaintDown && e.NewCell.RowIndex.HasValue && !string.IsNullOrEmpty(_startBoolDrawColumn)) { Global.MovieSession.Movie.IsCountingRerecords = false; if (e.OldCell.RowIndex.HasValue && e.NewCell.RowIndex.HasValue) { for (int i = startVal; i <= endVal; i++) // Inclusive on both ends (drawing up or down) { bool setVal = _boolPaintState; if (_patternPaint && _boolPaintState) { if (CurrentTasMovie[frame].Lagged.HasValue && CurrentTasMovie[frame].Lagged.Value) { setVal = CurrentTasMovie.BoolIsPressed(i - 1, _startBoolDrawColumn); } else { setVal = BoolPatterns[controllerType.BoolButtons.IndexOf(_startBoolDrawColumn)].GetNextValue(); } } CurrentTasMovie.SetBoolState(i, _startBoolDrawColumn, setVal); // Notice it uses new row, old column, you can only paint across a single column JumpToGreenzone(); } } } else if (TasView.IsPaintDown && e.NewCell.RowIndex.HasValue && !string.IsNullOrEmpty(_startFloatDrawColumn)) { Global.MovieSession.Movie.IsCountingRerecords = false; if (e.OldCell.RowIndex.HasValue && e.NewCell.RowIndex.HasValue) { for (int i = startVal; i <= endVal; i++) // Inclusive on both ends (drawing up or down) { float setVal = _floatPaintState; if (_patternPaint) { if (CurrentTasMovie[frame].Lagged.HasValue && CurrentTasMovie[frame].Lagged.Value) { setVal = CurrentTasMovie.GetFloatState(i - 1, _startFloatDrawColumn); } else { setVal = FloatPatterns[controllerType.FloatControls.IndexOf(_startFloatDrawColumn)].GetNextValue(); } } CurrentTasMovie.SetFloatState(i, _startFloatDrawColumn, setVal); // Notice it uses new row, old column, you can only paint across a single column JumpToGreenzone(); } } } Global.MovieSession.Movie.IsCountingRerecords = wasCountingRerecords; if (mouseButtonHeld) { TasView.MakeIndexVisible(TasView.CurrentCell.RowIndex.Value); // todo: limit scrolling speed } RefreshTasView(); }