Skip to content

Commit f1e9f0a

Browse files
committed
Catty-471 Move Scripts
1 parent 757c7c5 commit f1e9f0a

File tree

11 files changed

+499
-244
lines changed

11 files changed

+499
-244
lines changed

src/Catty/Defines/LanguageTranslationDefines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
#define kLocalizedEnableCondition NSLocalizedString(@"Enable condition", nil)
169169
#define kLocalizedEditFormula NSLocalizedString(@"Edit formula", nil)
170170
#define kLocalizedMoveBrick NSLocalizedString(@"Move brick", nil)
171+
#define kLocalizedMoveScript NSLocalizedString(@"Move script", nil)
171172
#define kLocalizedDeleteSounds NSLocalizedString(@"Delete sounds", nil)
172173
#define kLocalizedMoveSounds NSLocalizedString(@"Move sounds",nil)
173174
#define kLocalizedHideDetails NSLocalizedString(@"Hide details", nil)

src/Catty/Defines/LanguageTranslationDefinesSwift.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ let kLocalizedDisableCondition = NSLocalizedString("Disable condition", comment:
168168
let kLocalizedEnableCondition = NSLocalizedString("Enable condition", comment: "")
169169
let kLocalizedEditFormula = NSLocalizedString("Edit formula", comment: "")
170170
let kLocalizedMoveBrick = NSLocalizedString("Move brick", comment: "")
171+
let kLocalizedMoveScript = NSLocalizedString("Move script", comment: "")
171172
let kLocalizedDeleteSounds = NSLocalizedString("Delete sounds", comment: "")
172173
let kLocalizedMoveSounds = NSLocalizedString("Move sounds", comment: "")
173174
let kLocalizedHideDetails = NSLocalizedString("Hide details", comment: "")

src/Catty/Resources/Localization/en.lproj/Localizable.strings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,9 @@
13031303
/* No comment provided by engineer. */
13041304
"Move Phiro motor forward" = "Move Phiro motor forward";
13051305

1306+
/* No comment provided by engineer. */
1307+
"Move script" = "Move script";
1308+
13061309
/* No comment provided by engineer. */
13071310
"Move sounds" = "Move sounds";
13081311

src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
@interface BrickMoveManager : NSObject
2828

2929
+(id)sharedInstance;
30-
3130
- (BOOL)collectionView:(UICollectionView*)collectionView itemAtIndexPath:(NSIndexPath*)fromIndexPath
32-
canMoveToIndexPath:(NSIndexPath*)toIndexPath andObject:(SpriteObject*)object;
31+
canMoveToIndexPath:(NSIndexPath*)toIndexPath andObject:(SpriteObject*)object isBrick:(BOOL)isBrick;
3332

3433
-(void)reset;
3534
-(void)getReadyForNewBrickMovement;

src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/BrickManager/BrickMoveManager.m

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,57 +53,61 @@ + (id)sharedInstance {
5353

5454

5555
- (BOOL)collectionView:(UICollectionView*)collectionView itemAtIndexPath:(NSIndexPath*)fromIndexPath
56-
canMoveToIndexPath:(NSIndexPath*)toIndexPath andObject:(SpriteObject*)object
56+
canMoveToIndexPath:(NSIndexPath*)toIndexPath andObject:(SpriteObject*)object isBrick:(BOOL)isBrick
5757
{
58-
Script *fromScript = [object.scriptList objectAtIndex:fromIndexPath.section];
59-
Brick *fromBrick;
60-
if (fromIndexPath.item == 0) {
61-
fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item];
62-
} else{
63-
fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item - 1];
64-
}
65-
66-
if (toIndexPath.item != 0) {
67-
Script *script;
68-
if (self.moveToOtherScript) {
69-
script = [object.scriptList objectAtIndex:toIndexPath.section];
70-
}else{
71-
script = [object.scriptList objectAtIndex:fromIndexPath.section];
72-
}
73-
Brick *toBrick;
74-
if (script.brickList.count > toIndexPath.item - 1) {
75-
toBrick = [script.brickList objectAtIndex:toIndexPath.item - 1];
76-
} else {
77-
return NO;
58+
if (isBrick) {
59+
Script *fromScript = [object.scriptList objectAtIndex:fromIndexPath.section];
60+
Brick *fromBrick;
61+
if (fromIndexPath.item == 0) {
62+
fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item];
63+
} else{
64+
fromBrick = [fromScript.brickList objectAtIndex:fromIndexPath.item - 1];
7865
}
79-
80-
if ([toBrick isKindOfClass:[LoopEndBrick class]]) {
81-
LoopEndBrick* loopEndBrick = (LoopEndBrick*) toBrick;
82-
if ([loopEndBrick.loopBeginBrick isKindOfClass:[ForeverBrick class]]) {
83-
return [self handleMovementToForeverBrick:loopEndBrick fromIndexPath:fromIndexPath toIndexPath:toIndexPath fromBrick:fromBrick andScript:script];
66+
67+
if (toIndexPath.item != 0) {
68+
Script *script;
69+
if (self.moveToOtherScript) {
70+
script = [object.scriptList objectAtIndex:toIndexPath.section];
71+
}else{
72+
script = [object.scriptList objectAtIndex:fromIndexPath.section];
8473
}
85-
}
86-
if ([fromBrick isKindOfClass:[LoopBeginBrick class]] || [fromBrick isKindOfClass:[LoopEndBrick class]] || [fromBrick isKindOfClass:[IfLogicBeginBrick class]] || [fromBrick isKindOfClass:[IfThenLogicBeginBrick class]] || [fromBrick isKindOfClass:[IfLogicElseBrick class]] || [fromBrick isKindOfClass:[IfLogicEndBrick class]] || [fromBrick isKindOfClass:[IfThenLogicEndBrick class]]){
87-
return [self checkNestedBrickToIndex:toIndexPath FromIndex:fromIndexPath andFromBrick:fromBrick andObject:object];
88-
} else {
89-
//From Below
90-
if (toIndexPath.item < fromIndexPath.item) {
91-
if ([toBrick isKindOfClass:[IfLogicElseBrick class]]||[toBrick isKindOfClass:[IfLogicEndBrick class]]||[toBrick isKindOfClass:[LoopEndBrick class]]) { //check if repeat?!
92-
Brick *checkBeforeEndBrick = [script.brickList objectAtIndex:toIndexPath.item - 2];
93-
if ([checkBeforeEndBrick isKindOfClass:[LoopEndBrick class]]) {
94-
LoopEndBrick *endBrick = (LoopEndBrick*)checkBeforeEndBrick;
95-
if ([endBrick.loopBeginBrick isKindOfClass:[ForeverBrick class]]) {
96-
return NO;
74+
Brick *toBrick;
75+
if (script.brickList.count > toIndexPath.item - 1) {
76+
toBrick = [script.brickList objectAtIndex:toIndexPath.item - 1];
77+
} else {
78+
return NO;
79+
}
80+
81+
if ([toBrick isKindOfClass:[LoopEndBrick class]]) {
82+
LoopEndBrick* loopEndBrick = (LoopEndBrick*) toBrick;
83+
if ([loopEndBrick.loopBeginBrick isKindOfClass:[ForeverBrick class]]) {
84+
return [self handleMovementToForeverBrick:loopEndBrick fromIndexPath:fromIndexPath toIndexPath:toIndexPath fromBrick:fromBrick andScript:script];
85+
}
86+
}
87+
if ([fromBrick isKindOfClass:[LoopBeginBrick class]] || [fromBrick isKindOfClass:[LoopEndBrick class]] || [fromBrick isKindOfClass:[IfLogicBeginBrick class]] || [fromBrick isKindOfClass:[IfThenLogicBeginBrick class]] || [fromBrick isKindOfClass:[IfLogicElseBrick class]] || [fromBrick isKindOfClass:[IfLogicEndBrick class]] || [fromBrick isKindOfClass:[IfThenLogicEndBrick class]]){
88+
return [self checkNestedBrickToIndex:toIndexPath FromIndex:fromIndexPath andFromBrick:fromBrick andObject:object];
89+
} else {
90+
//From Below
91+
if (toIndexPath.item < fromIndexPath.item) {
92+
if ([toBrick isKindOfClass:[IfLogicElseBrick class]]||[toBrick isKindOfClass:[IfLogicEndBrick class]]||[toBrick isKindOfClass:[LoopEndBrick class]]) { //check if repeat?!
93+
Brick *checkBeforeEndBrick = [script.brickList objectAtIndex:toIndexPath.item - 2];
94+
if ([checkBeforeEndBrick isKindOfClass:[LoopEndBrick class]]) {
95+
LoopEndBrick *endBrick = (LoopEndBrick*)checkBeforeEndBrick;
96+
if ([endBrick.loopBeginBrick isKindOfClass:[ForeverBrick class]]) {
97+
return NO;
98+
}
9799
}
98100
}
101+
99102
}
100103

104+
return (toIndexPath.item != 0);
101105
}
102-
103-
return (toIndexPath.item != 0);
106+
} else {
107+
return [self handleMovementToOtherScriptwithIndexPath:toIndexPath fromBrick:fromBrick andObject:object];
104108
}
105109
} else {
106-
return [self handleMovementToOtherScriptwithIndexPath:toIndexPath fromBrick:fromBrick andObject:object];
110+
return fromIndexPath.section != toIndexPath.section && toIndexPath.item == 0;
107111
}
108112
}
109113

src/Catty/ViewController/Continue&New/MaintainObject/MaintainScript/ScriptCollectionViewController.m

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)