Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
        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();
        }