@@ -85,6 +85,7 @@ @interface ScriptCollectionViewController() <UICollectionViewDelegate,
8585@property (nonatomic , strong ) NSIndexPath *variableIndexPath;
8686@property (nonatomic , assign ) BOOL isEditingBrickMode;
8787@property (nonatomic , assign ) BOOL batchUpdateMutex;
88+ @property (nonatomic , assign ) BOOL isBrickMove;
8889@property (nonatomic , strong ) FormulaManager *formulaManager;
8990@end
9091
@@ -304,6 +305,14 @@ - (void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPat
304305 [self reloadData ];
305306 [self .object.scene.project saveToDiskWithNotification: YES ];
306307 }];
308+
309+ [actionSheet addDefaultActionWithTitle: kLocalizedMoveScript handler: ^{
310+ script.animateInsertBrick = YES ;
311+ script.animateMoveBrick = YES ;
312+ [[BrickInsertManager sharedInstance ] setBrickMoveMode: YES ];
313+ [self turnOnInsertingBrickMode ];
314+ [self reloadData ];
315+ }];
307316 }
308317
309318 [[[[actionSheet build ]
@@ -401,17 +410,24 @@ - (void)collectionView:(UICollectionView*)collectionView
401410 } else {
402411 Script *toScript = [self .object.scriptList objectAtIndex: toIndexPath.section];
403412 Script *fromScript = [self .object.scriptList objectAtIndex: fromIndexPath.section];
404- Brick *fromBrick = [fromScript.brickList objectAtIndex: fromIndexPath.item - 1 ];
405- fromBrick.script = toScript;
406- if ([fromScript.brickList count ] == 1 ) {
407- [fromScript.brickList removeAllObjects ];
408- } else {
409- [fromScript.brickList removeObjectAtIndex: fromIndexPath.item - 1 ];
413+ if ([fromScript.brickList count ] > 0 ) {
414+ Brick *fromBrick = [fromScript.brickList objectAtIndex: fromIndexPath.item - 1 ];
415+ fromBrick.script = toScript;
416+ if ([fromScript.brickList count ] == 1 ) {
417+ [fromScript.brickList removeAllObjects ];
418+ } else {
419+ [fromScript.brickList removeObjectAtIndex: fromIndexPath.item - 1 ];
420+ }
421+ if ([toScript.brickList count ] == 0 ) {
422+ [toScript.brickList insertObject: fromBrick atIndex: toIndexPath.item];
423+ }else {
424+ [toScript.brickList insertObject: fromBrick atIndex: toIndexPath.item - 1 ];
425+ }
410426 }
411- if ([toScript.brickList count ] == 0 ) {
412- [toScript.brickList insertObject: fromBrick atIndex: toIndexPath.item] ;
413- } else {
414- [toScript.brickList insertObject: fromBrick atIndex: toIndexPath.item - 1 ];
427+ else {
428+ self. object . scriptList [ toIndexPath.section] = fromScript ;
429+ self. object . scriptList [fromIndexPath.section] = toScript;
430+
415431 }
416432 }
417433}
@@ -433,22 +449,28 @@ - (void)collectionView:(UICollectionView*)collectionView
433449
434450 if ([[BrickInsertManager sharedInstance ] isBrickInsertionMode ]) {
435451 Script *script = [self .object.scriptList objectAtIndex: indexPath.section];
436- if (indexPath.item != 0 ) {
437- Brick *brick;
438- if (script.brickList .count >= 1 ) {
439- brick = [script.brickList objectAtIndex: indexPath.item - 1 ];
452+ if ([script.brickList count ] > 0 ) {
453+ if (indexPath.item != 0 ) {
454+ Brick *brick;
455+ if (script.brickList .count >= 1 ) {
456+ brick = [script.brickList objectAtIndex: indexPath.item - 1 ];
457+ }else {
458+ brick = [script.brickList objectAtIndex: indexPath.item];
459+ }
460+ if (brick.isAnimatedInsertBrick && !brick.isAnimatedMoveBrick ) {
461+ [[BrickInsertManager sharedInstance ] insertBrick: brick IndexPath: indexPath andObject: self .object];
462+ }else if (!brick.isAnimatedInsertBrick && !brick.isAnimatedMoveBrick ){
463+ return ;
464+ }else {
465+ brick.animateInsertBrick = NO ;
466+ brick.animateMoveBrick = NO ;
467+ }
440468 }else {
441- brick = [script.brickList objectAtIndex: indexPath.item];
442- }
443- if (brick.isAnimatedInsertBrick && !brick.isAnimatedMoveBrick ) {
444- [[BrickInsertManager sharedInstance ] insertBrick: brick IndexPath: indexPath andObject: self .object];
445- }else if (!brick.isAnimatedInsertBrick && !brick.isAnimatedMoveBrick ){
446- return ;
447- }else {
448- brick.animateInsertBrick = NO ;
449- brick.animateMoveBrick = NO ;
469+ script.animateInsertBrick = NO ;
450470 }
451- }else {
471+ } else {
472+ script.animateInsertBrick = NO ;
473+ script.animateMoveBrick = NO ;
452474 script.animateInsertBrick = NO ;
453475 }
454476 [self .object.scene.project saveToDiskWithNotification: NO ];
@@ -473,8 +495,12 @@ - (BOOL)collectionView:(UICollectionView*)collectionView itemAtIndexPath:(NSInde
473495 if ([[BrickInsertManager sharedInstance ] isBrickInsertionMode ] && ![[BrickInsertManager sharedInstance ] isBrickMoveMode ]) {
474496 return [[BrickInsertManager sharedInstance ] collectionView: self .collectionView itemAtIndexPath: fromIndexPath canInsertToIndexPath: toIndexPath andObject: self .object];
475497 }
476-
477- return [[BrickMoveManager sharedInstance ] collectionView: self .collectionView itemAtIndexPath: fromIndexPath canMoveToIndexPath: toIndexPath andObject: self .object];
498+ BrickCell *brickCell = (BrickCell*)[collectionView cellForItemAtIndexPath: fromIndexPath];
499+ if (brickCell) {
500+ id scriptOrBrick = brickCell.scriptOrBrick ;
501+ self.isBrickMove = [scriptOrBrick isKindOfClass: [Brick class ]];
502+ }
503+ return [[BrickMoveManager sharedInstance ] collectionView: self .collectionView itemAtIndexPath: fromIndexPath canMoveToIndexPath: toIndexPath andObject: self .object isBrick: self .isBrickMove];
478504}
479505
480506
@@ -487,9 +513,9 @@ - (BOOL)collectionView:(UICollectionView*)collectionView canMoveItemAtIndexPath:
487513 if (indexPath.item != 0 ) {
488514 brick = [script.brickList objectAtIndex: indexPath.item - 1 ];
489515 }
490- return (script.animateInsertBrick || brick.animateMoveBrick || brick.animateInsertBrick );
516+ return (script.animateMoveBrick || script. animateInsertBrick || brick.animateMoveBrick || brick.animateInsertBrick );
491517 }
492- BOOL editable = (( self.isEditing || indexPath. item == 0 ) ? NO : YES );
518+ BOOL editable = (self.isEditing ? NO : YES );
493519 return ((editable || [[BrickInsertManager sharedInstance ] isBrickInsertionMode ]) ? YES : editable);
494520}
495521
0 commit comments