@@ -371,6 +371,78 @@ private bool TasView_QueryFrameLag(int index, bool hideWasLag)
371
371
return ( lag . Lagged . HasValue && lag . Lagged . Value ) || ( hideWasLag && lag . WasLagged . HasValue && lag . WasLagged . Value ) ;
372
372
}
373
373
374
+ /// <param name="selection">
375
+ /// list of row indices sorted ascending, as returned by <c>TasView.SelectedRows</c>,
376
+ /// and must not be empty (so there must be a selection)
377
+ /// </param>
378
+ /// <remarks>fills with <see langword="false"/> (unheld) if held on all selected frames, <see langword="true"/> (held) otherwise</remarks>
379
+ private void ToggleButtonStateOnFrames ( int [ ] selection , string buttonName )
380
+ {
381
+ // nifty taseditor logic
382
+ // your TAS Editor logic failed us (it didn't account for non-contiguous `SelectedRows`) --yoshi
383
+ bool allPressed = true ;
384
+ var contiguous = true ;
385
+ var iSelection = 0 ;
386
+ var lastFrameIndexSeen = selection [ iSelection ] - 1 ;
387
+ while ( iSelection < selection . Length )
388
+ {
389
+ var index = selection [ iSelection ] ;
390
+ if ( index - lastFrameIndexSeen is not 1 )
391
+ {
392
+ contiguous = false ;
393
+ break ;
394
+ }
395
+ lastFrameIndexSeen = index ;
396
+ if ( index == CurrentTasMovie . FrameCount // last movie frame can't have input, but can be selected
397
+ || ! CurrentTasMovie . BoolIsPressed ( index , buttonName ) )
398
+ {
399
+ allPressed = false ;
400
+ break ;
401
+ }
402
+ iSelection ++ ;
403
+ }
404
+ if ( ! allPressed )
405
+ {
406
+ // still need to check for discontinuity
407
+ while ( iSelection < selection . Length )
408
+ {
409
+ var index = selection [ iSelection ] ;
410
+ if ( index - lastFrameIndexSeen is not 1 )
411
+ {
412
+ contiguous = false ;
413
+ break ;
414
+ }
415
+ lastFrameIndexSeen = index ;
416
+ iSelection ++ ;
417
+ }
418
+ }
419
+ else if ( ! contiguous )
420
+ {
421
+ // still need to check for `false` values
422
+ allPressed = allPressed && selection . Skip ( iSelection - 1 ) // break'd before checking the next one, so less 1 (and can't get here if `iSelection` is 0 so that's safe)
423
+ . All ( index => index < CurrentTasMovie . FrameCount // last movie frame can't have input, but can be selected
424
+ && CurrentTasMovie . BoolIsPressed ( index , buttonName ) ) ;
425
+ }
426
+ // else all contiguous and all `true`
427
+
428
+ CurrentTasMovie . SetBoolStates ( frame : selection [ 0 ] , count : iSelection , buttonName , val : ! allPressed ) ;
429
+ var blockStart = iSelection ;
430
+ lastFrameIndexSeen = selection [ iSelection ] - 1 ;
431
+ while ( iSelection < selection . Length )
432
+ {
433
+ var index = selection [ iSelection ] ;
434
+ if ( index - lastFrameIndexSeen is not 1 )
435
+ {
436
+ // discontinuity; split off another block, and this is now the start of the next block
437
+ CurrentTasMovie . SetBoolStates ( frame : selection [ blockStart ] , count : iSelection - blockStart , buttonName , val : ! allPressed ) ;
438
+ blockStart = iSelection ;
439
+ }
440
+ lastFrameIndexSeen = index ;
441
+ iSelection ++ ;
442
+ }
443
+ CurrentTasMovie . SetBoolStates ( frame : selection [ blockStart ] , count : iSelection - blockStart , buttonName , val : ! allPressed ) ;
444
+ }
445
+
374
446
private void TasView_ColumnClick ( object sender , InputRoll . ColumnClickEventArgs e )
375
447
{
376
448
if ( TasView . AnyRowsSelected )
@@ -389,70 +461,7 @@ private void TasView_ColumnClick(object sender, InputRoll.ColumnClickEventArgs e
389
461
{
390
462
if ( ModifierKeys != Keys . Alt )
391
463
{
392
- // nifty taseditor logic
393
- // your TAS Editor logic failed us (it didn't account for non-contiguous `SelectedRows`) --yoshi
394
- var selection = TasView . SelectedRows . ToArray ( ) ; // sorted asc, length >= 1
395
- bool allPressed = true ;
396
- var contiguous = true ;
397
- var iSelection = 0 ;
398
- var lastFrameIndexSeen = selection [ iSelection ] - 1 ;
399
- while ( iSelection < selection . Length )
400
- {
401
- var index = selection [ iSelection ] ;
402
- if ( index - lastFrameIndexSeen is not 1 )
403
- {
404
- contiguous = false ;
405
- break ;
406
- }
407
- lastFrameIndexSeen = index ;
408
- if ( index == CurrentTasMovie . FrameCount // last movie frame can't have input, but can be selected
409
- || ! CurrentTasMovie . BoolIsPressed ( index , buttonName ) )
410
- {
411
- allPressed = false ;
412
- break ;
413
- }
414
- iSelection ++ ;
415
- }
416
- if ( ! allPressed )
417
- {
418
- // still need to check for discontinuity
419
- while ( iSelection < selection . Length )
420
- {
421
- var index = selection [ iSelection ] ;
422
- if ( index - lastFrameIndexSeen is not 1 )
423
- {
424
- contiguous = false ;
425
- break ;
426
- }
427
- lastFrameIndexSeen = index ;
428
- iSelection ++ ;
429
- }
430
- }
431
- else if ( ! contiguous )
432
- {
433
- // still need to check for `false` values
434
- allPressed = allPressed && selection . Skip ( iSelection - 1 ) // break'd before checking the next one, so less 1 (and can't get here if `iSelection` is 0 so that's safe)
435
- . All ( index => index < CurrentTasMovie . FrameCount // last movie frame can't have input, but can be selected
436
- && CurrentTasMovie . BoolIsPressed ( index , buttonName ) ) ;
437
- }
438
- // else all contiguous and all `true`
439
-
440
- CurrentTasMovie . SetBoolStates ( frame : selection [ 0 ] , count : iSelection , buttonName , val : ! allPressed ) ;
441
- var blockStart = iSelection ;
442
- lastFrameIndexSeen = selection [ iSelection ] - 1 ;
443
- while ( iSelection < selection . Length )
444
- {
445
- var index = selection [ iSelection ] ;
446
- if ( index - lastFrameIndexSeen is not 1 )
447
- {
448
- // discontinuity; split off another block, and this is now the start of the next block
449
- CurrentTasMovie . SetBoolStates ( frame : selection [ blockStart ] , count : iSelection - blockStart , buttonName , val : ! allPressed ) ;
450
- blockStart = iSelection ;
451
- }
452
- lastFrameIndexSeen = index ;
453
- iSelection ++ ;
454
- }
455
- CurrentTasMovie . SetBoolStates ( frame : selection [ blockStart ] , count : iSelection - blockStart , buttonName , val : ! allPressed ) ;
464
+ ToggleButtonStateOnFrames ( TasView . SelectedRows . ToArray ( ) , buttonName ) ;
456
465
}
457
466
else
458
467
{
0 commit comments