From 426b59a2863a167fbe6d6b463a63805856ae684b Mon Sep 17 00:00:00 2001 From: amelak9 Date: Mon, 26 Jul 2021 15:35:28 +0200 Subject: [PATCH] CATTY-377 Add new object choose image before title --- .../Continue&New/SceneTableViewController.m | 82 ++++++++++--------- .../Extensions/XCTestCaseExtension.swift | 7 +- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/Catty/ViewController/Continue&New/SceneTableViewController.m b/src/Catty/ViewController/Continue&New/SceneTableViewController.m index 1a11fae382..f5177a9059 100644 --- a/src/Catty/ViewController/Continue&New/SceneTableViewController.m +++ b/src/Catty/ViewController/Continue&New/SceneTableViewController.m @@ -90,41 +90,9 @@ - (void)addObjectAction:(id)sender { [self.tableView setEditing:false animated:YES]; - [[[[[[[AlertControllerBuilder textFieldAlertWithTitle:kLocalizedAddObject message:[NSString stringWithFormat:@"%@:", kLocalizedObjectName]] - placeholder:kLocalizedEnterYourObjectNameHere] - addCancelActionWithTitle:kLocalizedCancel handler:^{ - [self cancelAddingObjectFromScriptEditor]; - }] - addDefaultActionWithTitle:kLocalizedOK handler:^(NSString *name) { - [self addObjectActionWithName:name]; - }] - valueValidator:^InputValidationResult *(NSString *name) { - InputValidationResult *result = [Util validationResultWithName:name - minLength:kMinNumOfObjectNameCharacters - maxlength:kMaxNumOfObjectNameCharacters]; - if (!result.valid) { - return result; - } - // Alert for Objects with same name - if ([[self.scene allObjectNames] containsObject:name]) { - return [InputValidationResult invalidInputWithLocalizedMessage:kLocalizedObjectNameAlreadyExistsDescription]; - } - return [InputValidationResult validInput]; - }] build] - showWithController:self]; -} - --(void)cancelAddingObjectFromScriptEditor -{ - if (self.afterSafeBlock) { - self.afterSafeBlock(nil); - } -} - -- (void)addObjectActionWithName:(NSString*)objectName -{ [self showLoadingView]; - [self.scene addObjectWithName:[Util uniqueName:objectName existingNames:[self.scene allObjectNames]]]; + SpriteObject * object = [SpriteObject alloc]; + [self.scene addObject:object]; NSInteger numberOfRowsInLastSection = [self tableView:self.tableView numberOfRowsInSection:kObjectSectionIndex]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(numberOfRowsInLastSection - 1) inSection:kObjectSectionIndex]; [self.tableView insertRowsAtIndexPaths:@[indexPath] @@ -136,6 +104,42 @@ - (void)addObjectActionWithName:(NSString*)objectName ltvc.showAddLookActionSheetAtStartForScriptEditor = NO; ltvc.afterSafeBlock = ^(Look* look) { [self.navigationController popViewControllerAnimated:YES]; + NSString *initialText = @""; + if (look) { + if (![look.name isEqual: @"look"]) { + initialText = look.name; + } + } + [[[[[[[[AlertControllerBuilder textFieldAlertWithTitle:kLocalizedAddObject message:[NSString stringWithFormat:@"%@:", kLocalizedObjectName]] + placeholder:kLocalizedEnterYourObjectNameHere] + initialText:initialText] + addCancelActionWithTitle:kLocalizedCancel handler:^{ + NSUInteger index = (kBackgroundObjects + indexPath.row); + SpriteObject *object = (SpriteObject*)[self.scene.objects objectAtIndex:index]; + [self.scene removeObject:object]; + [self.scene.project saveToDiskWithNotification:NO]; + [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:((indexPath.row != 0) ? UITableViewRowAnimationTop : UITableViewRowAnimationFade)]; + [self cancelAddingObjectFromScriptEditor]; + }] + addDefaultActionWithTitle:kLocalizedOK handler:^(NSString *name) { + [self renameObjectActionToName:name spriteObject:(SpriteObject*)[self.scene.objects objectAtIndex:(kBackgroundObjectIndex + indexPath.section + indexPath.row)]]; + }] + valueValidator:^InputValidationResult *(NSString *name) { + InputValidationResult *result = [Util validationResultWithName:name + minLength:kMinNumOfObjectNameCharacters + maxlength:kMaxNumOfObjectNameCharacters]; + if (!result.valid) { + return result; + } + // Alert for Objects with same name + if ([[self.scene allObjectNames] containsObject:name]) { + return [InputValidationResult invalidInputWithLocalizedMessage:kLocalizedObjectNameAlreadyExistsDescription]; + } + return [InputValidationResult validInput]; + }] build] + showWithController:self]; + [self showPlaceHolder:!(BOOL)[self.scene numberOfNormalObjects]]; + [self hideLoadingView]; if (!look) { NSUInteger index = (kBackgroundObjects + indexPath.row); SpriteObject *object = (SpriteObject*)[self.scene.objects objectAtIndex:index]; @@ -152,9 +156,13 @@ - (void)addObjectActionWithName:(NSString*)objectName } [self showPlaceHolder:!(BOOL)[self.scene numberOfNormalObjects]]; }; - [self.navigationController pushViewController:ltvc animated:NO]; - [self showPlaceHolder:!(BOOL)[self.scene numberOfNormalObjects]]; - [self hideLoadingView]; + [self.navigationController pushViewController:ltvc animated:NO];} + +-(void)cancelAddingObjectFromScriptEditor +{ + if (self.afterSafeBlock) { + self.afterSafeBlock(nil); + } } - (void)renameProjectActionForProjectWithName:(NSString*)newProjectName diff --git a/src/CattyUITests/Extensions/XCTestCaseExtension.swift b/src/CattyUITests/Extensions/XCTestCaseExtension.swift index 4b0990b61a..cfd108ef6b 100644 --- a/src/CattyUITests/Extensions/XCTestCaseExtension.swift +++ b/src/CattyUITests/Extensions/XCTestCaseExtension.swift @@ -72,10 +72,6 @@ extension XCTestCase { func addObjectAndDrawNewImage(name: String, in app: XCUIApplication) { app.toolbars.buttons[kLocalizedUserListAdd].tap() - let alert = waitForElementToAppear(app.alerts[kLocalizedAddObject]) - alert.textFields[kLocalizedEnterYourObjectNameHere].typeText(name) - alert.buttons[kLocalizedOK].tap() - waitForElementToAppear(app.buttons[kLocalizedDrawNewImage]).tap() XCTAssertNotNil(waitForElementToAppear(app.navigationBars[kLocalizedPaintPocketPaint])) @@ -83,6 +79,9 @@ extension XCTestCase { app.navigationBars.buttons[kLocalizedBack].tap() waitForElementToAppear(app.sheets.firstMatch).buttons[kLocalizedSaveChanges].tap() + let alert = waitForElementToAppear(app.alerts[kLocalizedAddObject]) + alert.textFields[kLocalizedEnterYourObjectNameHere].typeText(name) + alert.buttons[kLocalizedOK].tap() XCTAssertNotNil(waitForElementToAppear(app.navigationBars.buttons[kLocalizedPocketCode])) }